1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
5 $LOAD_PATH << "../../lib" if $0 == __FILE__
6 require "chise/kageserver"
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 QuadraticPath #========================動的な分割に対応できるようにする
19 def initialize(p1, p2, p3)
20 @p1, @p2, @p3 = p1, p2, p3
23 def divide_adaptic #適応的分割数をする。
28 def divide_num(num) #分割数を指定できる
33 #2次のbezier曲線の計算式、 P(t) = (1-t)^2*P1 + 2*t*(1-t)*P2 + t^2*P3
35 (num+1).times {|i| #ここで最後の点を含めないのがポイント。これによって次の曲線との重複が無いようにしている。
37 x = (1-t)*(1-t)*x1 + 2*t*(1-t)*x2 + t*t*x3
38 y = (1-t)*(1-t)*y1 + 2*t*(1-t)*y2 + t*t*y3
48 #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
60 if par.length == 1 #コマンドである
61 exec_cmd(cmd) if 0 < cmd.length #前のコマンドが残っていたら実行
63 elsif par =~ /[,0-9]+/ #座標値である
64 sx, sy = par.split(/,/)
65 x, y = sx.to_i, sy.to_i
66 cmd << [x, y] #cmdへのargを追加
69 exec_cmd(cmd) if 0 < cmd.length #前のコマンドが残っていたら実行
76 cmd.each {|x, y| moveto(x, y) }
78 quadratic([@px, @py], cmd.shift, cmd.shift)
82 @lines << [@px, @py, x, y] if @px != -1
85 def quadratic(p1, p2, p3)
86 #p ["quadratic", p1, p2, p3]
87 qp = QuadraticPath.new(p1, p2, p3)
97 @strokes = Strokes.new
99 lines = svg.split(/\n/)
101 next unless line =~ /^<path/
102 if line =~ /d=\"([a-zA-Z0-9, ]+)\"/
103 #lines = KageParser.parse_path($1)
105 lines.each {|px, py, x, y|
106 @strokes.add_line(px, 1000-py, x, 1000-y)
114 class KageGlyph #================================================== てなかんじ
115 def initialize(code, svg)
123 @strokes = KageParser.parse(@svg)
126 parse if @strokes.nil?
132 @server = KageServer.instance
134 @cache_list = @server.list_cache
136 @rend = StrokesRenderer.new
137 # @rend.hsv = [13, 100, 100]
138 # @rend.hsv = [0, 0, 0]
139 # @rend.hsv = [13, 100, 100] #黄色
140 @rend.hsv = [6, 100, 100] #オレンジ
142 attr_reader :cache_list, :server
144 return @glyphs[code] if @glyphs[code]
145 svg = @server.get(code)
146 return nil if svg.nil?
147 @glyphs[code] = KageGlyph.new(code, svg)
154 @rend.set_strokes(glyph.strokes)
162 char = Character.new(@code)
163 printf("[%s][%04x]\n", char.nil? ? "nil" : char.map_sjis, code)