2 # KageFont library by eto 2003-0311
10 #<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
11 #<svg viewBox="0 0 1000 1000">
12 #<path d="M 50,540 950,255 " style="fill: none; stroke: black; stroke-width: 10; stroke-linecap: round;"/>
13 #<path d="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 " style="fill: none; stroke: black; stroke-width: 10; stroke-linecap: round;"/>
17 class KageParser #======================================================================
19 @strokes = Strokes.new
20 lines = svg.split(/\n/)
22 next unless line =~ /^<path/
23 if line =~ /d=\"([a-zA-Z0-9, ]+)\"/
24 KageParser.parse_path($1)
29 def self.parse_path(str)
31 #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
34 next if par.length == 1 #一文字はとばします。本来はちゃんとベジェを展開する。
36 sx, sy = par.split(/,/)
37 x, y = sx.to_i, (1000 - sy.to_i)
39 @strokes.add_line(px, py, x, y)
47 class KageGlyph #====================================================================== てなかんじ
48 def initialize(code, svg)
56 @strokes = KageParser.parse(@svg)
59 parse if @strokes.nil?
63 class KageFont #======================================================================
65 @server = KageServer.instance
67 @cache_list = @server.list_cache
69 @rend = StrokesRenderer.new
70 #@rend.hsv = [13, 100, 100]
71 @rend.hsv = [0, 0, 100]
73 attr_reader :cache_list, :server
75 return @glyphs[code] if @glyphs[code]
76 svg = @server.get(code)
77 return nil if svg.nil?
78 @glyphs[code] = KageGlyph.new(code, svg)
85 @rend.set_strokes(glyph.strokes)
93 char = Character.new(@code)
94 printf("[%s][%04x]\n", char.nil? ? "nil" : char.map_sjis, code)
100 #----------------------------------------------------------------------end.