shogi_koma 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f8e07e418e69de63dbb9e27029c2d7210052c07
4
- data.tar.gz: 69753235e3eb0e50c558f23a2175b6dcb191399c
3
+ metadata.gz: 08e065ded06c5abbed80e87904b93d531cde1787
4
+ data.tar.gz: caf3312d2cc5e8f22705c90b329bed7a16fa1fcd
5
5
  SHA512:
6
- metadata.gz: a6ee0a1bb7f0869970187e1e4a681126d3938285f55711a765dc7ab6abee937a0961f1aa9d52e9967df97c754e199b16d78299f992b0dba605773a36628b8ddf
7
- data.tar.gz: 264f9dc354890b3ba9b6d7bd9d78ac2a47699d3ec85f284e2ee8bd3e296adaf94b68d2fb3932ae6f2815093471111648dbac988434dbbfc59911a75a183ee5e7
6
+ metadata.gz: ed620bdbaf3e918b8c1b0c8e72fe5e14b5fab4f1733eb7fd5774d5f20145b4e3ad69bd6f8ab6048486941f32486a5c355292d9087ba6effab5324af96763d82d
7
+ data.tar.gz: 6e410a3931fde4077e06541af0356be95b0e2dab55cf1b65b49d4095c2eaea2202ad85724a00e5dbb42f88f1debf72fa2784f221925d10b934e6f895c24a7126
data/NEWS.md ADDED
@@ -0,0 +1,28 @@
1
+ # NEWS
2
+
3
+ ## 0.0.3: 2013-12-14
4
+
5
+ Supported customizing colors!
6
+
7
+ ### Changes
8
+
9
+ * Improvements
10
+ * Supported customizing colors (body, frame and text).
11
+ [Patch by Seiichi Yonezawa]
12
+
13
+ ### Thanks
14
+
15
+ * Seiichi Yonezawa
16
+
17
+ ## 0.0.2: 2013-12-08
18
+
19
+ ASCII characters support release!
20
+
21
+ ### Changes
22
+
23
+ * Improvements
24
+ * Supported ASCII characters.
25
+
26
+ ## 0.0.1: 2013-12-06
27
+
28
+ Initial release!
@@ -3,12 +3,43 @@ require "cairo"
3
3
  module ShogiKoma
4
4
  class Painter
5
5
  attr_accessor :width, :height, :font
6
+ attr_reader :body_color, :text_color
6
7
  def initialize
7
8
  @width = 200
8
9
  @height = 200
9
10
  @font = "IPAMincho"
11
+ set_body_rgb(1, 0.8, 0.2)
12
+ set_frame_color(:black)
13
+ set_text_color(:black)
10
14
  end
11
15
 
16
+ def set_body_color(color)
17
+ @body_color = Cairo::Color.parse(color)
18
+ end
19
+
20
+ def set_body_rgba(r, g, b, a=1.0)
21
+ @body_color = Cairo::Color.parse([:rgba, r, g, b, a])
22
+ end
23
+ alias :set_body_rgb :set_body_rgba
24
+
25
+ def set_frame_color(color)
26
+ @frame_color = Cairo::Color.parse(color)
27
+ end
28
+
29
+ def set_frame_rgba(r, g, b, a=1.0)
30
+ @frame_color = Cairo::Color.parse([:rgba, r, g, b, a])
31
+ end
32
+ alias :set_frame_rgb :set_frame_rgba
33
+
34
+ def set_text_color(color)
35
+ @text_color = Cairo::Color.parse(color)
36
+ end
37
+
38
+ def set_text_rgba(r, g, b, a=1.0)
39
+ @text_color = Cairo::Color.parse([:rgba, r, g, b, a])
40
+ end
41
+ alias :set_text_rgb :set_text_rgba
42
+
12
43
  def write_to_png(text, output_path)
13
44
  Cairo::ImageSurface.new(:argb32, @width, @height) do |surface|
14
45
  Cairo::Context.new(surface) do |context|
@@ -22,7 +53,7 @@ module ShogiKoma
22
53
  def draw(context, text)
23
54
  draw_body(context)
24
55
  text = divide(text)
25
- send("draw_text#{text.length}", context, text)
56
+ __send__("draw_text#{text.length}", context, text)
26
57
  end
27
58
 
28
59
  def draw_body(context)
@@ -33,9 +64,9 @@ module ShogiKoma
33
64
  context.line_to(0.9, 0.9)
34
65
  context.line_to(0.1, 0.9)
35
66
  context.close_path
36
- context.set_source_rgb(1, 0.8, 0.2)
67
+ context.set_source_color(@body_color)
37
68
  context.fill_preserve
38
- context.set_source_color(:black)
69
+ context.set_source_color(@frame_color)
39
70
  context.stroke
40
71
  end
41
72
 
@@ -59,6 +90,7 @@ module ShogiKoma
59
90
  end
60
91
 
61
92
  def draw_text1(context, text)
93
+ context.set_source_color(@text_color)
62
94
  text = text[0] if text.is_a?(Array)
63
95
  context.select_font_face(@font)
64
96
  context.font_size = 0.6
@@ -67,6 +99,7 @@ module ShogiKoma
67
99
  end
68
100
 
69
101
  def draw_text2(context, text)
102
+ context.set_source_color(@text_color)
70
103
  context.select_font_face(@font)
71
104
  context.font_size = 0.4
72
105
  context.move_to(0.3, 0.49)
@@ -1,3 +1,3 @@
1
1
  module ShogiKoma
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/sample/shogikoma.rb CHANGED
@@ -9,3 +9,10 @@ painter.height = 200
9
9
  painter.font = "IPAMincho"
10
10
  painter.write_to_png("歩", "shogi_koma-fu1.png")
11
11
  painter.write_to_png("歩兵", "shogi_koma-fu2.png")
12
+
13
+ painter.set_text_color(:red)
14
+ painter.write_to_png("と", "shogi_koma-fu3.png")
15
+
16
+ painter.set_body_rgba(0.2, 0.2, 0.9, 0.1)
17
+ painter.set_frame_color("#CC00FF")
18
+ painter.write_to_png("と", "shogi_koma-fu4.png")
data/test/test-painter.rb CHANGED
@@ -19,6 +19,21 @@ class PainterTest < Test::Unit::TestCase
19
19
  assert_nothing_raised_in_draw("ABC")
20
20
  end
21
21
 
22
+ def test_body_color_with_rgb
23
+ @painter.set_body_rgb(0.2, 0.2, 0.2)
24
+ assert_nothing_raised_in_draw("D")
25
+ end
26
+
27
+ def test_text_color_with_name
28
+ @painter.set_text_color(:deep_pink)
29
+ assert_nothing_raised_in_draw("E")
30
+ end
31
+
32
+ def test_text_color_with_hex
33
+ @painter.set_text_color("#ACE")
34
+ assert_nothing_raised_in_draw("G")
35
+ end
36
+
22
37
  private
23
38
  def assert_nothing_raised_in_draw(text)
24
39
  width = 200
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shogi_koma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-08 00:00:00.000000000 Z
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cairo
@@ -106,6 +106,7 @@ files:
106
106
  - .travis.yml
107
107
  - Gemfile
108
108
  - LICENSE.txt
109
+ - NEWS.md
109
110
  - README.md
110
111
  - Rakefile
111
112
  - lib/shogi_koma.rb
@@ -135,11 +136,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  version: '0'
136
137
  requirements: []
137
138
  rubyforge_project:
138
- rubygems_version: 2.0.3
139
+ rubygems_version: 2.0.14
139
140
  signing_key:
140
141
  specification_version: 4
141
142
  summary: An image generater for Shogi's pieces
142
143
  test_files:
143
144
  - test/run-test.rb
144
145
  - test/test-painter.rb
145
- has_rdoc: