shogi_koma 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bd0db93a6a3bdb7dc48112a7cf5355e7a7091f9
4
- data.tar.gz: aafc6b72752343ec90383b99fd8c1ba1dfe2fbc7
3
+ metadata.gz: 9f8e07e418e69de63dbb9e27029c2d7210052c07
4
+ data.tar.gz: 69753235e3eb0e50c558f23a2175b6dcb191399c
5
5
  SHA512:
6
- metadata.gz: 5dee3ba859709d9a5aa60b78f22d1b312b084c52f2ed7df8fa099debe001e5e861d47f47990f7c6a7abe961295ccbc3530fd429c1af93f002d345912344dfbbd
7
- data.tar.gz: 5dcceba0267cb2da71c63d9829dbb37c2fa97f8c0f2a765d22b36cdc9a63cb5fa603fd9e3fd4a74245e6b844de80af72129d5618c8e24fa75a59209c94ad161f
6
+ metadata.gz: a6ee0a1bb7f0869970187e1e4a681126d3938285f55711a765dc7ab6abee937a0961f1aa9d52e9967df97c754e199b16d78299f992b0dba605773a36628b8ddf
7
+ data.tar.gz: 264f9dc354890b3ba9b6d7bd9d78ac2a47699d3ec85f284e2ee8bd3e296adaf94b68d2fb3932ae6f2815093471111648dbac988434dbbfc59911a75a183ee5e7
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  An image generator for Shogi's pieces (it's "ko-ma" in Japanese) for Ruby by cairo.
4
4
 
5
+ It supports one or two characters.
6
+
7
+ ![fu1](http://myokoym.net/public/shogi_koma-fu1.png)
8
+ ![fu2](http://myokoym.net/public/shogi_koma-fu2.png)
9
+
5
10
  ## Requirements
6
11
 
7
12
  * [Ruby](https://www.ruby-lang.org/)
@@ -33,7 +38,8 @@ painter = ShogiKoma::Painter.new
33
38
  #painter.width = 200 # as default
34
39
  #painter.height = 200 # as default
35
40
  #painter.font = "IPAMincho" # as default
36
- painter.write_to_png("歩", "fu.png")
41
+ painter.write_to_png("歩", "shogi_koma-fu1.png")
42
+ painter.write_to_png("歩兵", "shogi_koma-fu2.png")
37
43
  ```
38
44
 
39
45
  ### Draw to Cairo::Context
@@ -42,8 +48,12 @@ painter.write_to_png("歩", "fu.png")
42
48
  require "cairo"
43
49
  require "shogi_koma"
44
50
 
45
- Cairo::ImageSurface.new(:argb32, 40, 40) do |surface|
51
+ width = 200
52
+ height = 200
53
+
54
+ Cairo::ImageSurface.new(:argb32, width, height) do |surface|
46
55
  Cairo::Context.new(surface) do |context|
56
+ context.scale(width, height)
47
57
  painter = ShogiKoma::Painter.new
48
58
  #painter.font = "IPAMincho" # as default
49
59
  painter.draw(context, "歩")
@@ -21,6 +21,7 @@ module ShogiKoma
21
21
 
22
22
  def draw(context, text)
23
23
  draw_body(context)
24
+ text = divide(text)
24
25
  send("draw_text#{text.length}", context, text)
25
26
  end
26
27
 
@@ -38,7 +39,27 @@ module ShogiKoma
38
39
  context.stroke
39
40
  end
40
41
 
42
+ def divide(text)
43
+ case text.length
44
+ when 1
45
+ text
46
+ when 2
47
+ if text.bytes.to_a.length == 2
48
+ [text]
49
+ else
50
+ text
51
+ end
52
+ else
53
+ if text[0].bytes.to_a.length == 1 && text[1].bytes.to_a.length == 1
54
+ [text[0..1], text[2..-1]]
55
+ else
56
+ [text[0], text[1..-1]]
57
+ end
58
+ end
59
+ end
60
+
41
61
  def draw_text1(context, text)
62
+ text = text[0] if text.is_a?(Array)
42
63
  context.select_font_face(@font)
43
64
  context.font_size = 0.6
44
65
  context.move_to(0.2, 0.75)
@@ -1,3 +1,3 @@
1
1
  module ShogiKoma
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/sample/shogikoma.rb CHANGED
@@ -4,7 +4,8 @@
4
4
  require "shogi_koma"
5
5
 
6
6
  painter = ShogiKoma::Painter.new
7
- painter.width = 100
8
- painter.height = 100
7
+ painter.width = 200
8
+ painter.height = 200
9
9
  painter.font = "IPAMincho"
10
- painter.write_to_png("歩", "fu.png")
10
+ painter.write_to_png("歩", "shogi_koma-fu1.png")
11
+ painter.write_to_png("歩兵", "shogi_koma-fu2.png")
data/test/test-painter.rb CHANGED
@@ -6,11 +6,29 @@ class PainterTest < Test::Unit::TestCase
6
6
  @painter = ShogiKoma::Painter.new
7
7
  end
8
8
 
9
- def test_draw
10
- assert_nothing_raised do
11
- Cairo::ImageSurface.new(:argb32, 100, 100) do |surface|
12
- Cairo::Context.new(surface) do |context|
13
- @painter.draw(context, "A")
9
+ class DrawTest < self
10
+ def test_one_character
11
+ assert_nothing_raised_in_draw("A")
12
+ end
13
+
14
+ def test_two_characters
15
+ assert_nothing_raised_in_draw("AB")
16
+ end
17
+
18
+ def test_three_characters
19
+ assert_nothing_raised_in_draw("ABC")
20
+ end
21
+
22
+ private
23
+ def assert_nothing_raised_in_draw(text)
24
+ width = 200
25
+ height = 200
26
+ assert_nothing_raised do
27
+ Cairo::ImageSurface.new(:argb32, width, height) do |surface|
28
+ Cairo::Context.new(surface) do |context|
29
+ context.scale(width, height)
30
+ @painter.draw(context, text)
31
+ end
14
32
  end
15
33
  end
16
34
  end
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.1
4
+ version: 0.0.2
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-06 00:00:00.000000000 Z
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cairo