lib/shogi_koma/painter.rb in shogi_koma-0.0.1 vs lib/shogi_koma/painter.rb in shogi_koma-0.0.2

- old
+ new

@@ -19,10 +19,11 @@ end end def draw(context, text) draw_body(context) + text = divide(text) send("draw_text#{text.length}", context, text) end def draw_body(context) context.set_line_width(0.01) @@ -36,10 +37,30 @@ context.fill_preserve context.set_source_color(:black) context.stroke end + def divide(text) + case text.length + when 1 + text + when 2 + if text.bytes.to_a.length == 2 + [text] + else + text + end + else + if text[0].bytes.to_a.length == 1 && text[1].bytes.to_a.length == 1 + [text[0..1], text[2..-1]] + else + [text[0], text[1..-1]] + end + end + end + def draw_text1(context, text) + text = text[0] if text.is_a?(Array) context.select_font_face(@font) context.font_size = 0.6 context.move_to(0.2, 0.75) context.show_text(text) end