i
[chise/ruby.git] / chise / kage.rb
index 46c0cbc..9b60ddb 100755 (executable)
@@ -2,7 +2,6 @@
 
 require "sgl"
 require "singleton"
-$LOAD_PATH << "../../lib" if $0 == __FILE__
 require "chise/kageserver"
 
 #こんな感じのフォーマットになっている。
@@ -14,17 +13,21 @@ 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
@@ -39,20 +42,24 @@ module StrokeFont
        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 = []
@@ -69,6 +76,7 @@ module StrokeFont
       exec_cmd(cmd) if 0 < cmd.length #前のコマンドが残っていたら実行
       @lines
     end
+
     def exec_cmd(cmd)
       c = cmd.shift #先頭をとる
       case c
@@ -78,10 +86,12 @@ module StrokeFont
        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)
@@ -90,6 +100,7 @@ module StrokeFont
        moveto(x, y)
       }
     end
+
   end
 
   class KageParser
@@ -111,17 +122,19 @@ module StrokeFont
     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
@@ -140,12 +153,14 @@ module StrokeFont
       @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?
@@ -153,15 +168,17 @@ module StrokeFont
       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