require "sgl"
require "singleton"
-$LOAD_PATH << "../../lib" if $0 == __FILE__
require "chise/kageserver"
#こんな感じのフォーマットになっている。
#</svg>
module StrokeFont
- class QuadraticPath #========================動的な分割に対応できるようにする
+ class QuadraticPath # 動的な分割に対応できるようにする
DEFAULT_DIVIDE = 4
+
def initialize(p1, p2, p3)
@p1, @p2, @p3 = p1, p2, p3
@num = DEFAULT_DIVIDE
end
+
def divide_adaptic #適応的分割数をする。
end
+
def divide()
divide_num(@num)
end
+
def divide_num(num) #分割数を指定できる
#p [num]
x1, y1 = @p1
curve << [x,y]
}
#p curve
- return curve
+ curve
end
+
end
class PathResolver
#M 50,540 950,255
#M 330,50 330,900 M 330,900 Q 330,950 380,950 M 380,950 840,950 M 840,950 Q 890,950 915,850
+
def initialize
reset
end
+
def reset
@lines = []
@px, @py = -1, -1
end
+
def parse(str)
reset
cmd = []
exec_cmd(cmd) if 0 < cmd.length #前のコマンドが残っていたら実行
@lines
end
+
def exec_cmd(cmd)
c = cmd.shift #先頭をとる
case c
quadratic([@px, @py], cmd.shift, cmd.shift)
end
end
+
def moveto(x, y)
@lines << [@px, @py, x, y] if @px != -1
@px, @py = x, y
end
+
def quadratic(p1, p2, p3)
#p ["quadratic", p1, p2, p3]
qp = QuadraticPath.new(p1, p2, p3)
moveto(x, y)
}
end
+
end
class KageParser
end
end
- class KageGlyph #================================================== てなかんじ
+ class KageGlyph # てなかんじ
def initialize(code, svg)
@code = code
@svg = svg
@strokes = nil
end
attr_reader :strokes
+
def parse
return if @strokes
@strokes = KageParser.parse(@svg)
end
+
def init
parse if @strokes.nil?
end
@rend.hsv = [6, 100, 100] #オレンジ
end
attr_reader :cache_list, :server
+
def get(code)
return @glyphs[code] if @glyphs[code]
svg = @server.get(code)
return nil if svg.nil?
@glyphs[code] = KageGlyph.new(code, svg)
end
+
def init(code)
glyph = get(code)
return if glyph.nil?
glyph.parse
@rend.set_strokes(glyph.strokes)
end
+
def draw(code)
glyph = get(code)
return if glyph.nil?
@rend.draw
end
+
def print(code)
char = Character.new(@code)
printf("[%s][%04x]\n", char.nil? ? "nil" : char.map_sjis, code)
end
- end
+ end
end