squib 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +162 -133
- data/Gemfile +4 -4
- data/README.md +630 -550
- data/RELEASE TODO.md +18 -18
- data/Rakefile +99 -99
- data/lib/squib.rb +32 -32
- data/lib/squib/api/background.rb +20 -19
- data/lib/squib/api/data.rb +100 -99
- data/lib/squib/api/image.rb +90 -76
- data/lib/squib/api/save.rb +149 -103
- data/lib/squib/api/settings.rb +35 -37
- data/lib/squib/api/shapes.rb +230 -228
- data/lib/squib/api/text.rb +65 -66
- data/lib/squib/api/text_embed.rb +96 -66
- data/lib/squib/args/arg_loader.rb +138 -0
- data/lib/squib/args/box.rb +55 -0
- data/lib/squib/args/card_range.rb +32 -0
- data/lib/squib/args/color_validator.rb +12 -0
- data/lib/squib/args/coords.rb +33 -0
- data/lib/squib/args/dir_validator.rb +16 -0
- data/lib/squib/args/draw.rb +92 -0
- data/lib/squib/args/embed_adjust.rb +25 -0
- data/lib/squib/args/embed_key.rb +17 -0
- data/lib/squib/args/hand_special.rb +37 -0
- data/lib/squib/args/input_file.rb +37 -0
- data/lib/squib/args/paint.rb +44 -0
- data/lib/squib/args/paragraph.rb +115 -0
- data/lib/squib/args/save_batch.rb +60 -0
- data/lib/squib/args/scale_box.rb +53 -0
- data/lib/squib/args/sheet.rb +72 -0
- data/lib/squib/args/showcase_special.rb +38 -0
- data/lib/squib/args/svg_special.rb +37 -0
- data/lib/squib/args/transform.rb +25 -0
- data/lib/squib/args/typographer.rb +117 -117
- data/lib/squib/card.rb +67 -67
- data/lib/squib/conf.rb +117 -111
- data/lib/squib/constants.rb +178 -178
- data/lib/squib/deck.rb +113 -111
- data/lib/squib/graphics/cairo_context_wrapper.rb +99 -53
- data/lib/squib/graphics/gradient_regex.rb +46 -46
- data/lib/squib/graphics/hand.rb +42 -43
- data/lib/squib/graphics/image.rb +76 -73
- data/lib/squib/graphics/save_doc.rb +103 -137
- data/lib/squib/graphics/save_images.rb +33 -33
- data/lib/squib/graphics/shapes.rb +119 -152
- data/lib/squib/graphics/showcase.rb +85 -88
- data/lib/squib/graphics/text.rb +176 -216
- data/lib/squib/layout_parser.rb +91 -89
- data/lib/squib/layouts/economy.yml +85 -0
- data/lib/squib/layouts/fantasy.yml +101 -0
- data/lib/squib/layouts/hand.yml +62 -46
- data/lib/squib/layouts/playing-card.yml +35 -18
- data/lib/squib/project_template/config.yml +45 -40
- data/lib/squib/version.rb +10 -10
- data/samples/color_shortcuts.rb +6 -0
- data/samples/csv_import.rb +18 -18
- data/samples/custom-config.yml +5 -5
- data/samples/custom_config.rb +18 -18
- data/samples/draw_shapes.rb +45 -35
- data/samples/embed_text.rb +88 -90
- data/samples/hand.rb +24 -24
- data/samples/layouts.rb +62 -61
- data/samples/layouts_builtin.rb +51 -0
- data/samples/load_images.rb +78 -64
- data/samples/ranges.rb +64 -53
- data/samples/sample.csv +2 -2
- data/samples/text_options.rb +102 -94
- data/spec/api/api_data_spec.rb +57 -50
- data/spec/api/api_settings_spec.rb +37 -17
- data/spec/args/box_spec.rb +127 -0
- data/spec/args/draw_spec.rb +95 -0
- data/spec/args/embed_key_spec.rb +13 -0
- data/spec/args/input_file_spec.rb +21 -0
- data/spec/args/paint_spec.rb +22 -0
- data/spec/args/paragraph_spec.rb +153 -0
- data/spec/args/range_spec.rb +36 -0
- data/spec/args/save_batch_spec.rb +51 -0
- data/spec/args/scale_box_spec.rb +71 -0
- data/spec/args/sheet_spec.rb +58 -0
- data/spec/args/showcase_special_spec.rb +15 -0
- data/spec/data/samples/autoscale_font.rb.txt +84 -87
- data/spec/data/samples/basic.rb.txt +209 -203
- data/spec/data/samples/cairo_access.rb.txt +2 -2
- data/spec/data/samples/config_text_markup.rb.txt +72 -75
- data/spec/data/samples/csv_import.rb.txt +76 -80
- data/spec/data/samples/custom_config.rb.txt +48 -49
- data/spec/data/samples/draw_shapes.rb.txt +100 -42
- data/spec/data/samples/embed_text.rb.txt +283 -295
- data/spec/data/samples/excel.rb.txt +162 -171
- data/spec/data/samples/gradients.rb.txt +79 -67
- data/spec/data/samples/hand.rb.txt +538 -514
- data/spec/data/samples/hello_world.rb.txt +36 -38
- data/spec/data/samples/load_images.rb.txt +41 -5
- data/spec/data/samples/portrait-landscape.rb.txt +49 -51
- data/spec/data/samples/ranges.rb.txt +460 -429
- data/spec/data/samples/saves.rb.txt +801 -785
- data/spec/data/samples/showcase.rb.txt +5910 -5906
- data/spec/data/samples/text_options.rb.txt +1125 -981
- data/spec/data/samples/tgc_proofs.rb.txt +81 -79
- data/spec/data/samples/units.rb.txt +18 -12
- data/spec/data/xlsx/with_macros.xlsm +0 -0
- data/spec/graphics/cairo_context_wrapper_spec.rb +84 -75
- data/spec/graphics/graphics_images_spec.rb +94 -85
- data/spec/graphics/graphics_save_doc_spec.rb +67 -65
- data/spec/samples/expected/hand.png +0 -0
- data/spec/samples/expected/hand_pretty.png +0 -0
- data/spec/samples/expected/layout_00.png +0 -0
- data/spec/samples/expected/load_images_00.png +0 -0
- data/spec/samples/expected/ranges_00.png +0 -0
- data/spec/samples/expected/shape_00.png +0 -0
- data/spec/samples/expected/showcase.png +0 -0
- data/spec/samples/expected/showcase2.png +0 -0
- data/spec/samples/expected/showcase_individual_00.png +0 -0
- data/spec/samples/expected/showcase_individual_01.png +0 -0
- data/spec/samples/expected/showcase_individual_02.png +0 -0
- data/spec/samples/expected/showcase_individual_03.png +0 -0
- data/spec/samples/expected/text_00.png +0 -0
- data/spec/samples/expected/text_01.png +0 -0
- data/spec/samples/expected/text_02.png +0 -0
- data/spec/samples/samples_regression_spec.rb +82 -82
- data/spec/spec_helper.rb +3 -2
- data/squib.gemspec +48 -48
- data/squib.sublime-project +42 -36
- metadata +61 -33
- data/lib/squib/input_helpers.rb +0 -238
- data/spec/api/api_image_spec.rb +0 -38
- data/spec/api/api_text_spec.rb +0 -37
- data/spec/graphics/graphics_shapes_spec.rb +0 -85
- data/spec/graphics/graphics_text_spec.rb +0 -164
- data/spec/input_helpers_spec.rb +0 -238
- data/spec/samples/expected/embed_multi_00.png +0 -0
- data/spec/samples/expected/embed_multi_01.png +0 -0
- data/spec/samples/expected/embed_multi_02.png +0 -0
- data/spec/samples/expected/ranges_01.png +0 -0
- data/spec/samples/expected/ranges_02.png +0 -0
@@ -1,79 +1,81 @@
|
|
1
|
-
cairo: antialias=(["subpixel"])
|
2
|
-
cairo: save([])
|
3
|
-
cairo: set_source_color([
|
4
|
-
cairo: paint([])
|
5
|
-
cairo: restore([])
|
6
|
-
cairo: save([])
|
7
|
-
cairo: rounded_rectangle([38, 38, 750, 1050, 38, 38])
|
8
|
-
cairo: set_source_color([
|
9
|
-
cairo:
|
10
|
-
cairo:
|
11
|
-
cairo:
|
12
|
-
cairo:
|
13
|
-
cairo:
|
14
|
-
cairo:
|
15
|
-
cairo:
|
16
|
-
cairo:
|
17
|
-
cairo:
|
18
|
-
cairo:
|
19
|
-
cairo:
|
20
|
-
cairo:
|
21
|
-
cairo: set_source_color(["
|
22
|
-
cairo:
|
23
|
-
cairo:
|
24
|
-
cairo:
|
25
|
-
cairo:
|
26
|
-
cairo:
|
27
|
-
cairo:
|
28
|
-
cairo:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
pango:
|
34
|
-
pango:
|
35
|
-
pango:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
cairo:
|
40
|
-
cairo:
|
41
|
-
cairo:
|
42
|
-
|
43
|
-
cairo:
|
44
|
-
cairo:
|
45
|
-
cairo:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
pango:
|
50
|
-
pango:
|
51
|
-
pango:
|
52
|
-
pango:
|
53
|
-
pango:
|
54
|
-
|
55
|
-
|
56
|
-
cairo:
|
57
|
-
cairo:
|
58
|
-
cairo:
|
59
|
-
|
60
|
-
cairo:
|
61
|
-
cairo:
|
62
|
-
cairo: translate([
|
63
|
-
cairo:
|
64
|
-
cairo:
|
65
|
-
cairo:
|
66
|
-
cairo:
|
67
|
-
cairo:
|
68
|
-
cairo:
|
69
|
-
cairo:
|
70
|
-
cairo:
|
71
|
-
cairo:
|
72
|
-
cairo:
|
73
|
-
cairo:
|
74
|
-
cairo:
|
75
|
-
cairo: translate([0, 0])
|
76
|
-
cairo:
|
77
|
-
cairo:
|
78
|
-
cairo:
|
79
|
-
|
1
|
+
cairo: antialias=(["subpixel"])
|
2
|
+
cairo: save([])
|
3
|
+
cairo: set_source_color(["white"])
|
4
|
+
cairo: paint([])
|
5
|
+
cairo: restore([])
|
6
|
+
cairo: save([])
|
7
|
+
cairo: rounded_rectangle([38, 38, 750, 1050, 38, 38])
|
8
|
+
cairo: set_source_color(["#0000"])
|
9
|
+
cairo: fill_preserve([])
|
10
|
+
cairo: set_source_color(["black"])
|
11
|
+
cairo: set_line_width([2.0])
|
12
|
+
cairo: set_line_join([0])
|
13
|
+
cairo: set_line_cap([0])
|
14
|
+
cairo: set_dash([[]])
|
15
|
+
cairo: stroke([])
|
16
|
+
cairo: restore([])
|
17
|
+
cairo: save([])
|
18
|
+
cairo: rounded_rectangle([75, 75, 128, 128, 25, 25])
|
19
|
+
cairo: set_source_color(["#0000"])
|
20
|
+
cairo: fill_preserve([])
|
21
|
+
cairo: set_source_color(["black"])
|
22
|
+
cairo: set_line_width([2.0])
|
23
|
+
cairo: set_line_join([0])
|
24
|
+
cairo: set_line_cap([0])
|
25
|
+
cairo: set_dash([[]])
|
26
|
+
cairo: stroke([])
|
27
|
+
cairo: restore([])
|
28
|
+
cairo: save([])
|
29
|
+
cairo: set_source_color(["black"])
|
30
|
+
cairo: translate([220, 78])
|
31
|
+
cairo: rotate([0])
|
32
|
+
cairo: move_to([0, 0])
|
33
|
+
pango: font_description=([MockDouble])
|
34
|
+
pango: text=(["Mastermind"])
|
35
|
+
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
|
36
|
+
pango: ellipsize=([#<Pango::Layout::EllipsizeMode end>])
|
37
|
+
pango: alignment=([#<Pango::Layout::Alignment left>])
|
38
|
+
pango: justify=([false])
|
39
|
+
cairo: move_to([0, 0])
|
40
|
+
cairo: move_to([0, 0])
|
41
|
+
cairo: show_pango_layout([MockDouble])
|
42
|
+
pango: ellipsized?([])
|
43
|
+
cairo: restore([])
|
44
|
+
cairo: save([])
|
45
|
+
cairo: set_source_color(["black"])
|
46
|
+
cairo: translate([75, 85])
|
47
|
+
cairo: rotate([0])
|
48
|
+
cairo: move_to([0, 0])
|
49
|
+
pango: font_description=([MockDouble])
|
50
|
+
pango: text=(["3"])
|
51
|
+
pango: width=([131072])
|
52
|
+
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
|
53
|
+
pango: ellipsize=([#<Pango::Layout::EllipsizeMode end>])
|
54
|
+
pango: alignment=([#<Pango::Layout::Alignment center>])
|
55
|
+
pango: justify=([false])
|
56
|
+
cairo: move_to([0, 0])
|
57
|
+
cairo: move_to([0, 0])
|
58
|
+
cairo: show_pango_layout([MockDouble])
|
59
|
+
pango: ellipsized?([])
|
60
|
+
cairo: restore([])
|
61
|
+
cairo: save([])
|
62
|
+
cairo: translate([620, 75])
|
63
|
+
cairo: rotate([0])
|
64
|
+
cairo: translate([-620, -75])
|
65
|
+
cairo: set_source([ImageSurface, 620, 75])
|
66
|
+
cairo: paint([1.0])
|
67
|
+
cairo: restore([])
|
68
|
+
cairo: save([])
|
69
|
+
cairo: translate([620, 218])
|
70
|
+
cairo: rotate([0])
|
71
|
+
cairo: scale([1.0, 1.0])
|
72
|
+
cairo: render_rsvg_handle([RSVG::Handle, nil])
|
73
|
+
cairo: restore([])
|
74
|
+
cairo: save([])
|
75
|
+
cairo: translate([0, 0])
|
76
|
+
cairo: rotate([0])
|
77
|
+
cairo: translate([0, 0])
|
78
|
+
cairo: set_source([ImageSurface, 0, 0])
|
79
|
+
cairo: paint([0.5])
|
80
|
+
cairo: restore([])
|
81
|
+
surface: write_to_png(["_output/tgc_sample_00.png"])
|
@@ -5,29 +5,35 @@ cairo: paint([])
|
|
5
5
|
cairo: restore([])
|
6
6
|
cairo: save([])
|
7
7
|
cairo: rounded_rectangle([37.5, 37.5, 750.0, 1050.0, 25, 25])
|
8
|
-
cairo: set_source_color([
|
8
|
+
cairo: set_source_color(["#0000"])
|
9
|
+
cairo: fill_preserve([])
|
10
|
+
cairo: set_source_color(["black"])
|
9
11
|
cairo: set_line_width([2.0])
|
12
|
+
cairo: set_line_join([0])
|
13
|
+
cairo: set_line_cap([0])
|
14
|
+
cairo: set_dash([[]])
|
10
15
|
cairo: stroke([])
|
11
|
-
cairo: rounded_rectangle([37.5, 37.5, 750.0, 1050.0, 25, 25])
|
12
|
-
cairo: set_source_color(["#0000"])
|
13
|
-
cairo: fill([])
|
14
16
|
cairo: restore([])
|
15
17
|
cairo: save([])
|
16
18
|
cairo: rounded_rectangle([75.0, 75.0, 675.0, 975.0, 25, 25])
|
17
|
-
cairo: set_source_color([
|
19
|
+
cairo: set_source_color(["#0000"])
|
20
|
+
cairo: fill_preserve([])
|
21
|
+
cairo: set_source_color(["black"])
|
18
22
|
cairo: set_line_width([2.0])
|
23
|
+
cairo: set_line_join([0])
|
24
|
+
cairo: set_line_cap([0])
|
25
|
+
cairo: set_dash([[]])
|
19
26
|
cairo: stroke([])
|
20
|
-
cairo: rounded_rectangle([75.0, 75.0, 675.0, 975.0, 25, 25])
|
21
|
-
cairo: set_source_color(["#0000"])
|
22
|
-
cairo: fill([])
|
23
27
|
cairo: restore([])
|
24
28
|
cairo: save([])
|
25
29
|
cairo: rounded_rectangle([472.4409444, 472.4409444, 100, 100, 0, 0])
|
26
|
-
cairo: set_source_color([
|
30
|
+
cairo: set_source_color(["#0000"])
|
31
|
+
cairo: fill_preserve([])
|
32
|
+
cairo: set_source_color(["black"])
|
27
33
|
cairo: set_line_width([2.0])
|
34
|
+
cairo: set_line_join([0])
|
35
|
+
cairo: set_line_cap([0])
|
36
|
+
cairo: set_dash([[]])
|
28
37
|
cairo: stroke([])
|
29
|
-
cairo: rounded_rectangle([472.4409444, 472.4409444, 100, 100, 0, 0])
|
30
|
-
cairo: set_source_color(["#0000"])
|
31
|
-
cairo: fill([])
|
32
38
|
cairo: restore([])
|
33
39
|
surface: write_to_png(["_output/units_00.png"])
|
Binary file
|
@@ -1,75 +1,84 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'squib/graphics/cairo_context_wrapper'
|
3
|
-
|
4
|
-
describe Squib::Graphics::CairoContextWrapper do
|
5
|
-
|
6
|
-
let(:cairo) { double(Cairo::Context) }
|
7
|
-
subject { Squib::Graphics::CairoContextWrapper.new(cairo) }
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
expect(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
it 'on
|
66
|
-
dbl = double(Cairo::
|
67
|
-
expect(Cairo::
|
68
|
-
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
69
|
-
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
70
|
-
expect(cairo).to receive(:set_source).with(dbl)
|
71
|
-
subject.set_source_squibcolor('(1,2) (3,4) #def@0 #112233@1')
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'squib/graphics/cairo_context_wrapper'
|
3
|
+
|
4
|
+
describe Squib::Graphics::CairoContextWrapper do
|
5
|
+
|
6
|
+
let(:cairo) { double(Cairo::Context) }
|
7
|
+
subject { Squib::Graphics::CairoContextWrapper.new(cairo) }
|
8
|
+
|
9
|
+
context '#set_source_squibcolor' do
|
10
|
+
|
11
|
+
it 'passes on colors as normal' do
|
12
|
+
expect(cairo).to receive(:set_source_color).with('blue')
|
13
|
+
subject.set_source_squibcolor('blue')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'passes on color symbols as normal' do
|
17
|
+
expect(cairo).to receive(:set_source_color).with(:blue)
|
18
|
+
subject.set_source_squibcolor(:blue)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'passes on color hashes' do
|
22
|
+
expect(cairo).to receive(:set_source_color)
|
23
|
+
.with('#aabbccdd')
|
24
|
+
subject.set_source_squibcolor('#aabbccdd')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raises on nil' do
|
28
|
+
expect { subject.set_source_squibcolor(nil) }.to raise_error('nil is not a valid color')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
context 'regex variations for linear gradients' do
|
35
|
+
before(:each) do
|
36
|
+
dbl = double(Cairo::LinearPattern)
|
37
|
+
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
38
|
+
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
39
|
+
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
40
|
+
expect(cairo).to receive(:set_source).with(dbl)
|
41
|
+
end
|
42
|
+
|
43
|
+
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2) (3,4) blue@0 red@1') }
|
44
|
+
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0) (3.0,4.0) blue@0 red@1') }
|
45
|
+
it('handles no whitespace') { subject.set_source_squibcolor('(1,2)(3,4)blue@0red@1') }
|
46
|
+
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 ) ( 3 , 4 ) blue@0 red@1 ') }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'regex variations for radial gradients' do
|
50
|
+
before(:each) do
|
51
|
+
dbl = double(Cairo::RadialPattern)
|
52
|
+
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
53
|
+
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
54
|
+
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
55
|
+
expect(cairo).to receive(:set_source).with(dbl)
|
56
|
+
end
|
57
|
+
|
58
|
+
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2,5) (3,4,6) blue@0 red@1') }
|
59
|
+
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0,5.0) (3.0,4.0,6.0) blue@0 red@1') }
|
60
|
+
it('handles no whitespace') { subject.set_source_squibcolor('(1,2,5)(3,4,6)blue@0red@1') }
|
61
|
+
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 , 5 ) ( 3 , 4 , 6 ) blue@0 red@1 ') }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'regex handles hash notation' do
|
65
|
+
it 'on radial patterns' do
|
66
|
+
dbl = double(Cairo::RadialPattern)
|
67
|
+
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
68
|
+
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
69
|
+
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
70
|
+
expect(cairo).to receive(:set_source).with(dbl)
|
71
|
+
subject.set_source_squibcolor('(1,2,5) (3,4,6) #def@0 #112233@1')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'on linear patterns' do
|
75
|
+
dbl = double(Cairo::LinearPattern)
|
76
|
+
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
77
|
+
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
78
|
+
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
79
|
+
expect(cairo).to receive(:set_source).with(dbl)
|
80
|
+
subject.set_source_squibcolor('(1,2) (3,4) #def@0 #112233@1')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -1,85 +1,94 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'squib'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
allow(
|
17
|
-
allow(
|
18
|
-
allow(
|
19
|
-
allow(
|
20
|
-
allow(deck).to receive(:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
expect(context).to receive(:
|
30
|
-
expect(context).to receive(:
|
31
|
-
expect(context).to receive(:
|
32
|
-
expect(context).to receive(:
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
expect(
|
58
|
-
expect(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'squib'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
describe Squib::Card do
|
6
|
+
|
7
|
+
let(:deck) { double(Squib::Deck) }
|
8
|
+
let(:context) { double(Cairo::Context) }
|
9
|
+
let(:svg) { double(RSVG::Handle) }
|
10
|
+
let(:png) { double(Cairo::ImageSurface) }
|
11
|
+
let(:box) { OpenStruct.new({x: 37, y: 38, width: :native, height: :native})}
|
12
|
+
let(:paint) { OpenStruct.new({alpha: 0.9, blend: :none, mask: '' })}
|
13
|
+
let(:trans) { OpenStruct.new({angle: 0.0})}
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
allow(Cairo::Context).to receive(:new).and_return(context)
|
17
|
+
allow(Cairo::ImageSurface).to receive(:from_png).and_return(png)
|
18
|
+
allow(Cairo::ImageSurface).to receive(:new).and_return(png)
|
19
|
+
allow(RSVG::Handle).to receive(:new_from_data).and_return(svg)
|
20
|
+
allow(deck).to receive(:dir).and_return('_output')
|
21
|
+
allow(deck).to receive(:count_format).and_return('%02d')
|
22
|
+
allow(deck).to receive(:prefix).and_return('card_')
|
23
|
+
allow(deck).to receive(:antialias).and_return('subpixel')
|
24
|
+
allow(deck).to receive(:backend).and_return('memory')
|
25
|
+
end
|
26
|
+
|
27
|
+
context '#png' do
|
28
|
+
it 'makes all the expected calls on a smoke test' do
|
29
|
+
expect(context).to receive(:antialias=).with('subpixel')
|
30
|
+
expect(context).to receive(:save).once
|
31
|
+
expect(context).to receive(:translate).with(-37, -38).once
|
32
|
+
expect(context).to receive(:rotate).with(0.0).once
|
33
|
+
expect(context).to receive(:translate).with(37, 38).once
|
34
|
+
expect(context).to receive(:set_source).with(png, 37, 38).once
|
35
|
+
expect(context).to receive(:paint).with(0.9).once
|
36
|
+
expect(context).to receive(:restore).once
|
37
|
+
|
38
|
+
card = Squib::Card.new(deck, 100, 150)
|
39
|
+
# png(file, x, y, alpha, blend, angle)
|
40
|
+
card.png('foo.png', box, paint, trans)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sets blend when needed' do
|
44
|
+
context.as_null_object
|
45
|
+
expect(context).to receive(:operator=).with(:overlay).once
|
46
|
+
|
47
|
+
card = Squib::Card.new(deck, 100, 150)
|
48
|
+
paint.blend = :overlay
|
49
|
+
card.png('foo.png', box, paint, trans)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context '#svg' do
|
54
|
+
let(:svg_args) { OpenStruct.new({data: '<svg></svg>', id: 'id'}) }
|
55
|
+
|
56
|
+
it 'makes all the expected calls on a smoke test' do
|
57
|
+
expect(svg).to receive(:width).and_return(100).twice
|
58
|
+
expect(svg).to receive(:height).and_return(100).twice
|
59
|
+
expect(context).to receive(:antialias=).with('subpixel').once
|
60
|
+
expect(context).to receive(:save).once
|
61
|
+
expect(context).to receive(:rotate).with(0.0).once
|
62
|
+
expect(context).to receive(:translate).with(37, 38).once
|
63
|
+
expect(context).to receive(:scale).with(1.0, 1.0).once
|
64
|
+
expect(context).to receive(:render_rsvg_handle).with(svg, 'id').once
|
65
|
+
expect(context).to receive(:restore).once
|
66
|
+
|
67
|
+
card = Squib::Card.new(deck, 100, 150)
|
68
|
+
card.svg(nil, svg_args, box, paint, trans)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'sets blend when needed' do
|
72
|
+
context.as_null_object
|
73
|
+
svg.as_null_object
|
74
|
+
expect(context).to receive(:operator=).with(:overlay).once
|
75
|
+
|
76
|
+
card = Squib::Card.new(deck, 100, 150)
|
77
|
+
paint.blend = :overlay
|
78
|
+
card.svg(nil, svg_args, box, paint, trans)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets width & height when needed' do
|
82
|
+
context.as_null_object
|
83
|
+
expect(svg).to receive(:width).and_return(100).once
|
84
|
+
expect(svg).to receive(:height).and_return(100).once
|
85
|
+
expect(context).to receive(:scale).with(2.0, 3.0).once
|
86
|
+
|
87
|
+
card = Squib::Card.new(deck, 100, 150)
|
88
|
+
box.width = 200
|
89
|
+
box.height = 300
|
90
|
+
card.svg(nil, svg_args, box, paint, trans)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|