squib 0.6.0 → 0.7.0

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