lib/shogi_koma/painter.rb in shogi_koma-0.0.3 vs lib/shogi_koma/painter.rb in shogi_koma-0.0.4
- old
+ new
@@ -1,20 +1,25 @@
require "cairo"
+require "fontdock"
module ShogiKoma
class Painter
attr_accessor :width, :height, :font
- attr_reader :body_color, :text_color
+ attr_reader :body_color, :frame_color, :text_color
def initialize
@width = 200
@height = 200
@font = "IPAMincho"
set_body_rgb(1, 0.8, 0.2)
set_frame_color(:black)
set_text_color(:black)
end
+ def set_font(part_of_font_name)
+ @font = Fontdock::Local.find(part_of_font_name)
+ end
+
def set_body_color(color)
@body_color = Cairo::Color.parse(color)
end
def set_body_rgba(r, g, b, a=1.0)
@@ -68,29 +73,10 @@
context.fill_preserve
context.set_source_color(@frame_color)
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)
context.set_source_color(@text_color)
text = text[0] if text.is_a?(Array)
context.select_font_face(@font)
context.font_size = 0.6
@@ -104,8 +90,28 @@
context.font_size = 0.4
context.move_to(0.3, 0.49)
context.show_text(text[0])
context.move_to(0.3, 0.85)
context.show_text(text[1])
+ end
+
+ private
+ 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
end
end