shogi_koma 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/lib/shogi_koma/painter.rb +21 -0
- data/lib/shogi_koma/version.rb +1 -1
- data/sample/shogikoma.rb +4 -3
- data/test/test-painter.rb +23 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8e07e418e69de63dbb9e27029c2d7210052c07
|
4
|
+
data.tar.gz: 69753235e3eb0e50c558f23a2175b6dcb191399c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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("歩", "
|
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
|
-
|
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, "歩")
|
data/lib/shogi_koma/painter.rb
CHANGED
@@ -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)
|
data/lib/shogi_koma/version.rb
CHANGED
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 =
|
8
|
-
painter.height =
|
7
|
+
painter.width = 200
|
8
|
+
painter.height = 200
|
9
9
|
painter.font = "IPAMincho"
|
10
|
-
painter.write_to_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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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.
|
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-
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cairo
|