sugar_png 0.0.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +4 -4
- data/README.md +105 -0
- data/README.md.tpl +99 -0
- data/Rakefile +41 -6
- data/VERSION +1 -1
- data/data/1-dump-hex.rb +22 -0
- data/data/2-marshal-test.rb +22 -0
- data/data/3-hex2marshal.rb +71 -0
- data/data/font/00 +0 -0
- data/data/font/01 +0 -0
- data/data/font/02 +0 -0
- data/data/font/03 +0 -0
- data/data/font/04 +0 -0
- data/data/font/05 +0 -0
- data/data/font/06 +0 -0
- data/data/font/07 +0 -0
- data/data/font/09 +0 -0
- data/data/font/0a +0 -0
- data/data/font/0b +0 -0
- data/data/font/0c +0 -0
- data/data/font/0d +0 -0
- data/data/font/0e +0 -0
- data/data/font/0f +0 -0
- data/data/font/10 +0 -0
- data/data/font/11 +0 -0
- data/data/font/12 +0 -0
- data/data/font/13 +0 -0
- data/data/font/14 +0 -0
- data/data/font/15 +0 -0
- data/data/font/16 +0 -0
- data/data/font/17 +0 -0
- data/data/font/18 +0 -0
- data/data/font/19 +0 -0
- data/data/font/1a +0 -0
- data/data/font/1b +0 -0
- data/data/font/1c +0 -0
- data/data/font/1d +0 -0
- data/data/font/1e +0 -0
- data/data/font/1f +0 -0
- data/data/font/20 +0 -0
- data/data/font/21 +0 -0
- data/data/font/22 +0 -0
- data/data/font/23 +0 -0
- data/data/font/24 +0 -0
- data/data/font/25 +0 -0
- data/data/font/26 +0 -0
- data/data/font/27 +0 -0
- data/data/font/28 +0 -0
- data/data/font/29 +0 -0
- data/data/font/2a +0 -0
- data/data/font/2b +0 -0
- data/data/font/2c +0 -0
- data/data/font/2d +0 -0
- data/data/font/2e +0 -0
- data/data/font/2f +0 -0
- data/data/font/30 +0 -0
- data/data/font/31 +0 -0
- data/data/font/32 +0 -0
- data/data/font/33 +0 -0
- data/data/font/34 +0 -0
- data/data/font/35 +0 -0
- data/data/font/36 +0 -0
- data/data/font/37 +0 -0
- data/data/font/38 +0 -0
- data/data/font/39 +0 -0
- data/data/font/3a +0 -0
- data/data/font/3b +0 -0
- data/data/font/3c +0 -0
- data/data/font/3d +0 -0
- data/data/font/3e +0 -0
- data/data/font/3f +0 -0
- data/data/font/40 +0 -0
- data/data/font/41 +0 -0
- data/data/font/42 +0 -0
- data/data/font/43 +0 -0
- data/data/font/44 +0 -0
- data/data/font/45 +0 -0
- data/data/font/46 +0 -0
- data/data/font/47 +0 -0
- data/data/font/48 +0 -0
- data/data/font/49 +0 -0
- data/data/font/4a +0 -0
- data/data/font/4b +0 -0
- data/data/font/4c +0 -0
- data/data/font/4d +0 -0
- data/data/font/4e +0 -0
- data/data/font/4f +0 -0
- data/data/font/50 +0 -0
- data/data/font/51 +0 -0
- data/data/font/52 +0 -0
- data/data/font/53 +0 -0
- data/data/font/54 +0 -0
- data/data/font/55 +0 -0
- data/data/font/56 +0 -0
- data/data/font/57 +0 -0
- data/data/font/58 +0 -0
- data/data/font/59 +0 -0
- data/data/font/5a +0 -0
- data/data/font/5b +0 -0
- data/data/font/5c +0 -0
- data/data/font/5d +0 -0
- data/data/font/5e +0 -0
- data/data/font/5f +0 -0
- data/data/font/60 +0 -0
- data/data/font/61 +0 -0
- data/data/font/62 +0 -0
- data/data/font/63 +0 -0
- data/data/font/64 +0 -0
- data/data/font/65 +0 -0
- data/data/font/66 +0 -0
- data/data/font/67 +0 -0
- data/data/font/68 +0 -0
- data/data/font/69 +0 -0
- data/data/font/6a +0 -0
- data/data/font/6b +0 -0
- data/data/font/6c +0 -0
- data/data/font/6d +0 -0
- data/data/font/6e +0 -0
- data/data/font/6f +0 -0
- data/data/font/70 +0 -0
- data/data/font/71 +0 -0
- data/data/font/72 +0 -0
- data/data/font/73 +0 -0
- data/data/font/74 +0 -0
- data/data/font/75 +0 -0
- data/data/font/76 +0 -0
- data/data/font/77 +0 -0
- data/data/font/78 +0 -0
- data/data/font/79 +0 -0
- data/data/font/7a +0 -0
- data/data/font/7b +0 -0
- data/data/font/7c +0 -0
- data/data/font/7d +0 -0
- data/data/font/7e +0 -0
- data/data/font/7f +0 -0
- data/data/font/80 +0 -0
- data/data/font/81 +0 -0
- data/data/font/82 +0 -0
- data/data/font/83 +0 -0
- data/data/font/84 +0 -0
- data/data/font/85 +0 -0
- data/data/font/86 +0 -0
- data/data/font/87 +0 -0
- data/data/font/88 +0 -0
- data/data/font/89 +0 -0
- data/data/font/8a +0 -0
- data/data/font/8b +0 -0
- data/data/font/8c +0 -0
- data/data/font/8d +0 -0
- data/data/font/8e +0 -0
- data/data/font/8f +0 -0
- data/data/font/90 +0 -0
- data/data/font/91 +0 -0
- data/data/font/92 +0 -0
- data/data/font/93 +0 -0
- data/data/font/94 +0 -0
- data/data/font/95 +0 -0
- data/data/font/96 +0 -0
- data/data/font/97 +0 -0
- data/data/font/98 +0 -0
- data/data/font/99 +0 -0
- data/data/font/9a +0 -0
- data/data/font/9b +0 -0
- data/data/font/9c +0 -0
- data/data/font/9d +0 -0
- data/data/font/9e +0 -0
- data/data/font/9f +0 -0
- data/data/font/a0 +0 -0
- data/data/font/a1 +0 -0
- data/data/font/a2 +0 -0
- data/data/font/a3 +0 -0
- data/data/font/a4 +0 -0
- data/data/font/a5 +0 -0
- data/data/font/a6 +0 -0
- data/data/font/a7 +0 -0
- data/data/font/a8 +0 -0
- data/data/font/a9 +0 -0
- data/data/font/aa +0 -0
- data/data/font/ac +0 -0
- data/data/font/ad +0 -0
- data/data/font/ae +0 -0
- data/data/font/af +0 -0
- data/data/font/b0 +0 -0
- data/data/font/b1 +0 -0
- data/data/font/b2 +0 -0
- data/data/font/b3 +0 -0
- data/data/font/b4 +0 -0
- data/data/font/b5 +0 -0
- data/data/font/b6 +0 -0
- data/data/font/b7 +0 -0
- data/data/font/b8 +0 -0
- data/data/font/b9 +0 -0
- data/data/font/ba +0 -0
- data/data/font/bb +0 -0
- data/data/font/bc +0 -0
- data/data/font/bd +0 -0
- data/data/font/be +0 -0
- data/data/font/bf +0 -0
- data/data/font/c0 +0 -0
- data/data/font/c1 +0 -0
- data/data/font/c2 +0 -0
- data/data/font/c3 +0 -0
- data/data/font/c4 +0 -0
- data/data/font/c5 +0 -0
- data/data/font/c6 +0 -0
- data/data/font/c7 +0 -0
- data/data/font/c8 +0 -0
- data/data/font/c9 +0 -0
- data/data/font/ca +0 -0
- data/data/font/cb +0 -0
- data/data/font/cc +0 -0
- data/data/font/cd +0 -0
- data/data/font/ce +0 -0
- data/data/font/cf +0 -0
- data/data/font/d0 +0 -0
- data/data/font/d1 +0 -0
- data/data/font/d2 +0 -0
- data/data/font/d3 +0 -0
- data/data/font/d4 +0 -0
- data/data/font/d5 +0 -0
- data/data/font/d6 +0 -0
- data/data/font/d7 +0 -0
- data/data/font/f9 +0 -0
- data/data/font/fa +0 -0
- data/data/font/fb +0 -0
- data/data/font/fc +0 -0
- data/data/font/fd +0 -0
- data/data/font/fe +0 -0
- data/data/font/ff +0 -0
- data/data/unifont-5.1.20080820.7z +0 -0
- data/data/unused-4-read-tar.rb +49 -0
- data/lib/sugar_png.rb +164 -2
- data/lib/sugar_png/border.rb +20 -0
- data/lib/sugar_png/color.rb +118 -0
- data/lib/sugar_png/datastream.rb +2 -17
- data/lib/sugar_png/dyn_accessor.rb +28 -0
- data/lib/sugar_png/font.rb +44 -0
- data/lib/sugar_png/glyph.rb +36 -0
- data/lib/sugar_png/image.rb +104 -0
- data/samples/damaged_chunk.png +0 -0
- data/samples/png_suite/f00n0g08_reference.png +0 -0
- data/samples/png_suite/f00n2c08_reference.png +0 -0
- data/samples/png_suite/f01n0g08_reference.png +0 -0
- data/samples/png_suite/f01n2c08_reference.png +0 -0
- data/samples/png_suite/f02n0g08_reference.png +0 -0
- data/samples/png_suite/f02n2c08_reference.png +0 -0
- data/samples/png_suite/f03n0g08_reference.png +0 -0
- data/samples/png_suite/f03n2c08_reference.png +0 -0
- data/samples/png_suite/f04n0g08_reference.png +0 -0
- data/samples/png_suite/f04n2c08_reference.png +0 -0
- data/samples/readme/explicit_image_dimensions_bg_color.png +0 -0
- data/samples/readme/hello_world.png +0 -0
- data/samples/readme/japanese_text_with_rainbow_borders_zoomed_4x.png +0 -0
- data/samples/readme/pixels_can_be_set_using_ranges_enumerators_arrays.png +0 -0
- data/samples/readme/playing_with_transparency_16_bit_color_depth.png +0 -0
- data/samples/readme/white_noise.png +0 -0
- data/samples/rgba.tar.bz2 +0 -0
- data/samples/text_chunk.png +0 -0
- data/samples/ztxt_chunk.png +0 -0
- data/spec/color_spec.rb +81 -0
- data/spec/font_spec.rb +82 -0
- data/spec/magic/border_spec.rb +49 -0
- data/spec/magic/create_spec.rb +42 -0
- data/spec/magic/pixels_spec.rb +73 -0
- data/spec/magic/text_spec.rb +113 -0
- data/spec/magic/zoom_spec.rb +38 -0
- data/spec/png_suite_spec.rb +145 -0
- data/spec/spec_helper.rb +43 -1
- data/spec/sugar_png/datastream_spec.rb +32 -0
- data/spec/support/png_suite.rb +43 -0
- data/sugar_png.gemspec +275 -6
- metadata +287 -5
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/spec/color_spec.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SugarPNG::Color do
|
4
|
+
it "creates color from string" do
|
5
|
+
SugarPNG::Color.new('blue').should == SugarPNG::Color::BLUE
|
6
|
+
SugarPNG::Color.new('Blue').should == SugarPNG::Color::BLUE
|
7
|
+
SugarPNG::Color.new('BLUE').should == SugarPNG::Color::BLUE
|
8
|
+
end
|
9
|
+
it "creates color from symbol" do
|
10
|
+
SugarPNG::Color.new(:blue).should == SugarPNG::Color::BLUE
|
11
|
+
SugarPNG::Color.new(:blue, :depth => 16).should == SugarPNG::Color::BLUE.to_depth(16)
|
12
|
+
end
|
13
|
+
it "creates color from hex" do
|
14
|
+
SugarPNG::Color.new(0x0000ff).should == SugarPNG::Color::BLUE
|
15
|
+
SugarPNG::Color.new(0x00f, :depth => 4).should == SugarPNG::Color::BLUE.to_depth(4)
|
16
|
+
end
|
17
|
+
it "creates color from html" do
|
18
|
+
SugarPNG::Color.new("#0000ff").should == SugarPNG::Color::BLUE
|
19
|
+
SugarPNG::Color.new("#00f").should == SugarPNG::Color::BLUE
|
20
|
+
end
|
21
|
+
it "creates color from r,g,b" do
|
22
|
+
SugarPNG::Color.new(0,0,255).should == SugarPNG::Color::BLUE
|
23
|
+
end
|
24
|
+
it "creates color from long hash" do
|
25
|
+
SugarPNG::Color.new(:red => 0, :green => 0, :blue => 0xff).should == SugarPNG::Color::BLUE
|
26
|
+
end
|
27
|
+
it "creates color from short hash" do
|
28
|
+
SugarPNG::Color.new(:r => 0, :g => 0, :b => 0xff).should == SugarPNG::Color::BLUE
|
29
|
+
end
|
30
|
+
|
31
|
+
it "raises exception on invalid number of params" do
|
32
|
+
lambda{
|
33
|
+
SugarPNG::Color.new(1,2,3,4,5,6)
|
34
|
+
}.should raise_error(SugarPNG::ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises exception on invalid number of params" do
|
38
|
+
lambda{
|
39
|
+
SugarPNG::Color.new(1,2)
|
40
|
+
}.should raise_error(SugarPNG::ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises exception on invalid key" do
|
44
|
+
lambda{
|
45
|
+
SugarPNG::Color.new( :foo => :bar )
|
46
|
+
}.should raise_error(SugarPNG::ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "raises exception on invalid HTML color" do
|
50
|
+
lambda{ SugarPNG::Color.new( "#12" ) }.should raise_error(SugarPNG::ArgumentError)
|
51
|
+
lambda{ SugarPNG::Color.new( "#1234" ) }.should raise_error(SugarPNG::ArgumentError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raises exception on invalid color name" do
|
55
|
+
lambda{ SugarPNG::Color.new( "bzzz" ) }.should raise_error(SugarPNG::ArgumentError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "raises exception on invalid depth" do
|
59
|
+
expect{ SugarPNG::Color.new( :depth => 0 ) }.to raise_error(SugarPNG::ArgumentError)
|
60
|
+
end
|
61
|
+
it "raises exception on invalid depth" do
|
62
|
+
expect{ SugarPNG::Color.new( :depth => -1 ) }.to raise_error(SugarPNG::ArgumentError)
|
63
|
+
end
|
64
|
+
it "raises exception on invalid depth" do
|
65
|
+
expect{ SugarPNG::Color.new( :depth => 17 ) }.to raise_error(SugarPNG::ArgumentError)
|
66
|
+
end
|
67
|
+
it "raises exception on invalid depth" do
|
68
|
+
expect{ SugarPNG::Color.new( :depth => "foo" ) }.to raise_error(SugarPNG::ArgumentError)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "raises exception on invalid channel value" do
|
72
|
+
expect{ SugarPNG::Color.new( :red => 1000 ) }.to raise_error(SugarPNG::ArgumentError)
|
73
|
+
expect{ SugarPNG::Color.new( :red => -1 ) }.to raise_error(SugarPNG::ArgumentError)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "raises exception on invalid argument type" do
|
77
|
+
expect{ SugarPNG::Color.new( 1.25 ) }.to raise_error(SugarPNG::ArgumentError)
|
78
|
+
expect{ SugarPNG::Color.new( false ) }.to raise_error(SugarPNG::ArgumentError)
|
79
|
+
expect{ SugarPNG::Color.new( true ) }.to raise_error(SugarPNG::ArgumentError)
|
80
|
+
end
|
81
|
+
end
|
data/spec/font_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SugarPNG::Font do
|
5
|
+
subject(:font){ SugarPNG::Font.new }
|
6
|
+
|
7
|
+
it "should get 'R'" do
|
8
|
+
char = <<-EOF.strip.split("\n").map(&:strip).join("\n")
|
9
|
+
........
|
10
|
+
........
|
11
|
+
........
|
12
|
+
........
|
13
|
+
.#####..
|
14
|
+
.#....#.
|
15
|
+
.#....#.
|
16
|
+
.#....#.
|
17
|
+
.#####..
|
18
|
+
.#..#...
|
19
|
+
.#...#..
|
20
|
+
.#...#..
|
21
|
+
.#....#.
|
22
|
+
.#....#.
|
23
|
+
........
|
24
|
+
........
|
25
|
+
EOF
|
26
|
+
font['R'].to_s(".#").should == char
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get '水'" do
|
30
|
+
char = <<-EOF.strip.split("\n").map(&:strip).join("\n")
|
31
|
+
.......#........
|
32
|
+
.......#........
|
33
|
+
.......#........
|
34
|
+
.......#....#...
|
35
|
+
.......#....#...
|
36
|
+
.#####.##..#....
|
37
|
+
.....#.##.#.....
|
38
|
+
....#..#.#......
|
39
|
+
....#..#.#......
|
40
|
+
...#...#..#.....
|
41
|
+
...#...#...#....
|
42
|
+
..#....#....#...
|
43
|
+
.#.....#.....##.
|
44
|
+
#......#........
|
45
|
+
.....#.#........
|
46
|
+
......#.........
|
47
|
+
EOF
|
48
|
+
font['水'].to_s(".#").should == char
|
49
|
+
font['水'].width.should == 16
|
50
|
+
font['水'].ord.should == '水'.ord
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should get identical glyphs from int/string" do
|
54
|
+
font['A'].should == font['A'.ord]
|
55
|
+
end
|
56
|
+
|
57
|
+
%w'A Z 0 Ж'.each do |char|
|
58
|
+
describe "glyph '#{char}'" do
|
59
|
+
subject(:glyph){ font[char] }
|
60
|
+
|
61
|
+
it { should_not be_nil }
|
62
|
+
it { should_not be_blank }
|
63
|
+
|
64
|
+
its(:width) { should == 8 }
|
65
|
+
its(:height){ should == 16 }
|
66
|
+
its(:data) { should_not be_empty }
|
67
|
+
its(:ord) { should == char.ord }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "glyph ' ' (space)" do
|
72
|
+
subject(:glyph){ font[' '] }
|
73
|
+
|
74
|
+
it { should_not be_nil }
|
75
|
+
it { should be_blank }
|
76
|
+
|
77
|
+
its(:width) { should == 8 }
|
78
|
+
its(:height){ should == 16 }
|
79
|
+
its(:data) { should_not be_empty }
|
80
|
+
its(:ord) { should == ' '.ord }
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SugarPNG do
|
4
|
+
describe "border" do
|
5
|
+
it "draws image entirely of border" do
|
6
|
+
SugarPNG.new do |img|
|
7
|
+
img.border 10
|
8
|
+
|
9
|
+
img = ZPNG::Image.new(img.to_s)
|
10
|
+
img.width.should == 20
|
11
|
+
img.height.should == 20
|
12
|
+
img.pixels.each do |c|
|
13
|
+
c.should == ZPNG::Color::BLACK # SugarPNG::DEFAULT_FG
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "draws image entirely of padding" do
|
19
|
+
SugarPNG.new do |img|
|
20
|
+
img.padding 10
|
21
|
+
|
22
|
+
img = ZPNG::Image.new(img.to_s)
|
23
|
+
img.width.should == 20
|
24
|
+
img.height.should == 20
|
25
|
+
img.pixels.each do |c|
|
26
|
+
c.should == ZPNG::Color::TRANSPARENT # SugarPNG::DEFAULT_BG
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "draws image of 2 borders" do
|
32
|
+
SugarPNG.new do |img|
|
33
|
+
img.border 1, :red
|
34
|
+
img.border 1, :blue
|
35
|
+
|
36
|
+
img = ZPNG::Image.new(img.to_s)
|
37
|
+
img.width.should == 4
|
38
|
+
img.height.should == 4
|
39
|
+
img.each_pixel do |c,x,y|
|
40
|
+
if x==0 || x==3 || y == 0 || y == 3
|
41
|
+
c.should == ZPNG::Color::RED
|
42
|
+
else
|
43
|
+
c.should == ZPNG::Color::BLUE
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SugarPNG do
|
4
|
+
it "has some yield magic" do
|
5
|
+
r = SugarPNG.new do |img|
|
6
|
+
img.width = 200
|
7
|
+
img.height = 100
|
8
|
+
img.background = :red
|
9
|
+
img.bg = :blue
|
10
|
+
10.times do |i|
|
11
|
+
img[i,i] = :green
|
12
|
+
end
|
13
|
+
end
|
14
|
+
r.width.should == 200
|
15
|
+
r.height.should == 100
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has some instance_eval magic" do
|
19
|
+
r = SugarPNG.new do
|
20
|
+
width 200
|
21
|
+
height 100
|
22
|
+
background "#ffeeff"
|
23
|
+
background_color "#ff0000"
|
24
|
+
dot 10, 10, 'red'
|
25
|
+
color '#ffee00'
|
26
|
+
pixel 0, 12
|
27
|
+
point 0, 0, 0
|
28
|
+
end
|
29
|
+
r.width.should == 200
|
30
|
+
r.height.should == 100
|
31
|
+
r.bg.should == "#ff0000"
|
32
|
+
|
33
|
+
img = ZPNG::Image.new(r.export)
|
34
|
+
img.pixels.uniq.map(&:to_html).sort.should == ["#000000", "#FF0000", "#FFEE00"]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can also eat boring non-magic hash" do
|
38
|
+
r = SugarPNG.new :width => 55, :height => 111, :bg => :transparent
|
39
|
+
r.width.should == 55
|
40
|
+
r.height.should == 111
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SugarPNG do
|
4
|
+
it "accept(s) range(s) as pixel(s) method(s)" do
|
5
|
+
data = SugarPNG.new do
|
6
|
+
dot 0..10, 0, :red
|
7
|
+
end.to_s
|
8
|
+
img = ZPNG::Image.new data
|
9
|
+
img.width.should == 11
|
10
|
+
img.height.should == 1
|
11
|
+
img.each_pixel do |c|
|
12
|
+
c.should == ZPNG::Color::RED
|
13
|
+
end
|
14
|
+
|
15
|
+
SugarPNG.new do
|
16
|
+
pixels 10..20, 20..30, :blue
|
17
|
+
save "out.png"
|
18
|
+
end
|
19
|
+
img = ZPNG::Image.load("out.png")
|
20
|
+
img.width.should == 21
|
21
|
+
img.height.should == 31
|
22
|
+
img.each_pixel do |c,x,y|
|
23
|
+
if (10..20).include?(x) && (20..30).include?(y)
|
24
|
+
c.should == ZPNG::Color::BLUE
|
25
|
+
else
|
26
|
+
c.should == ZPNG::Color::TRANSPARENT
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "accept(s) array(s) as pixel(s) method(s)" do
|
32
|
+
data = SugarPNG.new do
|
33
|
+
bg 'white'
|
34
|
+
dot [1,3,5,10], 0, :red
|
35
|
+
end.to_s
|
36
|
+
|
37
|
+
img = ZPNG::Image.new data
|
38
|
+
img.width.should == 11
|
39
|
+
img.height.should == 1
|
40
|
+
img.each_pixel do |c,x,y|
|
41
|
+
if [1,3,5,10].include?(x)
|
42
|
+
c.should == ZPNG::Color::RED
|
43
|
+
else
|
44
|
+
c.should == ZPNG::Color::WHITE
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "accept(s) enum(s) as pixel(s) method(s)" do
|
50
|
+
data = SugarPNG.new do
|
51
|
+
dot 0.step(50,5), 0.step(30,3), :black
|
52
|
+
end.to_s
|
53
|
+
|
54
|
+
img = ZPNG::Image.new data
|
55
|
+
img.width.should == 51
|
56
|
+
img.height.should == 31
|
57
|
+
img.each_pixel do |c,x,y|
|
58
|
+
if 0.step(50,5).include?(x) && 0.step(30,3).include?(y)
|
59
|
+
c.should == ZPNG::Color::BLACK
|
60
|
+
else
|
61
|
+
c.should == ZPNG::Color::TRANSPARENT
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not accept []= with one arg" do
|
67
|
+
SugarPNG.new do |img|
|
68
|
+
lambda{
|
69
|
+
img[5] = :red
|
70
|
+
}.should raise_error
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SugarPNG do
|
4
|
+
describe "text" do
|
5
|
+
it "greets me" do
|
6
|
+
text = "Hello world!"
|
7
|
+
ascii = <<-EOF.strip.split("\n").map(&:strip).join("\n")
|
8
|
+
.............................................................................................
|
9
|
+
.............................................................................................
|
10
|
+
.............................................................................................
|
11
|
+
......................................................................................#......
|
12
|
+
.#....#............##......##..............................................##.........#.....#
|
13
|
+
.#....#.............#.......#...............................................#.........#.....#
|
14
|
+
.#....#...####......#.......#.....####...........#.....#..####...#.###......#.....###.#.....#
|
15
|
+
.#....#..#....#.....#.......#....#....#..........#..#..#.#....#..##...#.....#....#...##.....#
|
16
|
+
.######..#....#.....#.......#....#....#..........#..#..#.#....#..#....#.....#....#....#.....#
|
17
|
+
.#....#..######.....#.......#....#....#..........#..#..#.#....#..#..........#....#....#.....#
|
18
|
+
.#....#..#..........#.......#....#....#..........#..#..#.#....#..#..........#....#....#.....#
|
19
|
+
.#....#..#..........#.......#....#....#..........#..#..#.#....#..#..........#....#....#......
|
20
|
+
.#....#..#....#.....#.......#....#....#..........#..#..#.#....#..#..........#....#...##.....#
|
21
|
+
.#....#...####....#####...#####...####............##.##...####...#........#####...###.#.....#
|
22
|
+
EOF
|
23
|
+
SugarPNG.new do |img|
|
24
|
+
img.text text, :color => :white
|
25
|
+
|
26
|
+
img = ZPNG::Image.new(img.to_s)
|
27
|
+
img.to_ascii('.#').should == ascii
|
28
|
+
img.width.should == 93
|
29
|
+
img.height.should == 14
|
30
|
+
img.pixels.uniq.sort.should == [SugarPNG::Color::WHITE, SugarPNG::Color::TRANSPARENT].sort
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "offsets" do
|
35
|
+
text = "Hello"
|
36
|
+
ascii = <<-EOF.strip.split("\n").map(&:strip).join("\n")
|
37
|
+
............................................
|
38
|
+
............................................
|
39
|
+
............................................
|
40
|
+
............................................
|
41
|
+
............................................
|
42
|
+
............................................
|
43
|
+
............................................
|
44
|
+
......#....#............##......##..........
|
45
|
+
......#....#.............#.......#..........
|
46
|
+
......#....#...####......#.......#.....####.
|
47
|
+
......#....#..#....#.....#.......#....#....#
|
48
|
+
......######..#....#.....#.......#....#....#
|
49
|
+
......#....#..######.....#.......#....#....#
|
50
|
+
......#....#..#..........#.......#....#....#
|
51
|
+
......#....#..#..........#.......#....#....#
|
52
|
+
......#....#..#....#.....#.......#....#....#
|
53
|
+
......#....#...####....#####...#####...####.
|
54
|
+
EOF
|
55
|
+
SugarPNG.new do |img|
|
56
|
+
img.text text, :color => :white, :x => 5, :y => 3
|
57
|
+
|
58
|
+
img = ZPNG::Image.new(img.to_s)
|
59
|
+
img.to_ascii('.#').should == ascii
|
60
|
+
img.width.should == 44
|
61
|
+
img.height.should == 17
|
62
|
+
img.pixels.uniq.sort.should == [SugarPNG::Color::WHITE, SugarPNG::Color::TRANSPARENT].sort
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "multilines" do
|
67
|
+
ascii = <<-EOF.strip.split("\n").map(&:strip).join("\n")
|
68
|
+
.............................................
|
69
|
+
.............................................
|
70
|
+
.............................................
|
71
|
+
.............................................
|
72
|
+
.#....#............##......##................
|
73
|
+
.#....#.............#.......#................
|
74
|
+
.#....#...####......#.......#.....####.......
|
75
|
+
.#....#..#....#.....#.......#....#....#......
|
76
|
+
.######..#....#.....#.......#....#....#......
|
77
|
+
.#....#..######.....#.......#....#....#......
|
78
|
+
.#....#..#..........#.......#....#....#......
|
79
|
+
.#....#..#..........#.......#....#....#......
|
80
|
+
.#....#..#....#.....#.......#....#....#......
|
81
|
+
.#....#...####....#####...#####...####.......
|
82
|
+
.............................................
|
83
|
+
.............................................
|
84
|
+
.............................................
|
85
|
+
.............................................
|
86
|
+
.............................................
|
87
|
+
......................................#......
|
88
|
+
...........................##.........#.....#
|
89
|
+
............................#.........#.....#
|
90
|
+
.#.....#..####...#.###......#.....###.#.....#
|
91
|
+
.#..#..#.#....#..##...#.....#....#...##.....#
|
92
|
+
.#..#..#.#....#..#....#.....#....#....#.....#
|
93
|
+
.#..#..#.#....#..#..........#....#....#.....#
|
94
|
+
.#..#..#.#....#..#..........#....#....#.....#
|
95
|
+
.#..#..#.#....#..#..........#....#....#......
|
96
|
+
.#..#..#.#....#..#..........#....#...##.....#
|
97
|
+
..##.##...####...#........#####...###.#.....#
|
98
|
+
EOF
|
99
|
+
|
100
|
+
data = SugarPNG.new do
|
101
|
+
color :red
|
102
|
+
text "Hello\nworld!"
|
103
|
+
end.export
|
104
|
+
|
105
|
+
img = ZPNG::Image.new(data)
|
106
|
+
img.to_ascii('.####').should == ascii
|
107
|
+
img.save "out.png"
|
108
|
+
img.width.should == 45
|
109
|
+
img.height.should == 30
|
110
|
+
img.pixels.uniq.sort.should == [SugarPNG::Color::RED, SugarPNG::Color::TRANSPARENT].sort
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|