squib 0.14.2 → 0.14.3.pre1

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.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +41 -41
  3. data/.travis.yml +19 -19
  4. data/CHANGELOG.md +366 -357
  5. data/CONTRIBUTING.md +40 -40
  6. data/Gemfile +2 -2
  7. data/LICENSE.txt +22 -22
  8. data/README.md +121 -121
  9. data/RELEASE TODO.md +21 -21
  10. data/Rakefile +48 -48
  11. data/appveyor.yml +24 -24
  12. data/bin/squib +4 -4
  13. data/lib/squib.rb +32 -32
  14. data/lib/squib/api/background.rb +15 -15
  15. data/lib/squib/api/data.rb +137 -137
  16. data/lib/squib/api/groups.rb +54 -54
  17. data/lib/squib/api/image.rb +49 -49
  18. data/lib/squib/api/save.rb +83 -83
  19. data/lib/squib/api/settings.rb +21 -21
  20. data/lib/squib/api/shapes.rb +124 -124
  21. data/lib/squib/api/text.rb +25 -25
  22. data/lib/squib/api/text_embed.rb +71 -71
  23. data/lib/squib/api/units.rb +27 -27
  24. data/lib/squib/args/arg_loader.rb +126 -126
  25. data/lib/squib/args/box.rb +55 -55
  26. data/lib/squib/args/card_range.rb +32 -32
  27. data/lib/squib/args/color_validator.rb +12 -12
  28. data/lib/squib/args/coords.rb +35 -35
  29. data/lib/squib/args/csv_opts.rb +25 -25
  30. data/lib/squib/args/dir_validator.rb +16 -16
  31. data/lib/squib/args/draw.rb +92 -92
  32. data/lib/squib/args/embed_adjust.rb +25 -25
  33. data/lib/squib/args/embed_key.rb +17 -17
  34. data/lib/squib/args/hand_special.rb +37 -37
  35. data/lib/squib/args/import.rb +40 -40
  36. data/lib/squib/args/input_file.rb +37 -37
  37. data/lib/squib/args/paint.rb +44 -44
  38. data/lib/squib/args/paragraph.rb +116 -116
  39. data/lib/squib/args/save_batch.rb +63 -63
  40. data/lib/squib/args/scale_box.rb +53 -53
  41. data/lib/squib/args/sheet.rb +172 -172
  42. data/lib/squib/args/showcase_special.rb +38 -38
  43. data/lib/squib/args/sprue_file.rb +44 -44
  44. data/lib/squib/args/svg_special.rb +37 -37
  45. data/lib/squib/args/transform.rb +61 -61
  46. data/lib/squib/args/typographer.rb +119 -119
  47. data/lib/squib/args/unit_conversion.rb +29 -29
  48. data/lib/squib/builtin/layouts/economy.yml +85 -85
  49. data/lib/squib/builtin/layouts/fantasy.yml +101 -101
  50. data/lib/squib/builtin/layouts/hand.yml +62 -62
  51. data/lib/squib/builtin/layouts/party.yml +94 -94
  52. data/lib/squib/builtin/layouts/playing-card.yml +35 -35
  53. data/lib/squib/builtin/layouts/tuck_box.yml +46 -46
  54. data/lib/squib/builtin/projects/advanced/.gitignore +4 -4
  55. data/lib/squib/builtin/projects/advanced/ABOUT.md +19 -19
  56. data/lib/squib/builtin/projects/advanced/Gemfile +11 -11
  57. data/lib/squib/builtin/projects/advanced/Guardfile +21 -21
  58. data/lib/squib/builtin/projects/advanced/IDEAS.md +22 -22
  59. data/lib/squib/builtin/projects/advanced/PLAYTESTING.md +26 -26
  60. data/lib/squib/builtin/projects/advanced/Rakefile +27 -27
  61. data/lib/squib/builtin/projects/advanced/config.yml +53 -49
  62. data/lib/squib/builtin/projects/advanced/docs/PNP NOTES.md +3 -3
  63. data/lib/squib/builtin/projects/advanced/docs/RULES.md +21 -21
  64. data/lib/squib/builtin/projects/advanced/img/example.svg +60 -60
  65. data/lib/squib/builtin/projects/advanced/layouts/deck.yml +27 -27
  66. data/lib/squib/builtin/projects/advanced/src/deck.rb +34 -34
  67. data/lib/squib/builtin/projects/advanced/src/version.rb +3 -3
  68. data/lib/squib/builtin/projects/basic/.gitignore +4 -4
  69. data/lib/squib/builtin/projects/basic/ABOUT.md +19 -19
  70. data/lib/squib/builtin/projects/basic/Gemfile +3 -3
  71. data/lib/squib/builtin/projects/basic/IDEAS.md +22 -22
  72. data/lib/squib/builtin/projects/basic/PLAYTESTING.md +26 -26
  73. data/lib/squib/builtin/projects/basic/PNP NOTES.md +3 -3
  74. data/lib/squib/builtin/projects/basic/RULES.md +21 -21
  75. data/lib/squib/builtin/projects/basic/Rakefile +7 -7
  76. data/lib/squib/builtin/projects/basic/config.yml +53 -49
  77. data/lib/squib/builtin/projects/basic/deck.rb +6 -6
  78. data/lib/squib/builtin/sprues/a4_euro_card.yml +42 -42
  79. data/lib/squib/builtin/sprues/a4_poker_card_8up.yml +40 -40
  80. data/lib/squib/builtin/sprues/a4_poker_card_9up.yml +42 -42
  81. data/lib/squib/builtin/sprues/a4_usa_card.yml +42 -42
  82. data/lib/squib/builtin/sprues/drivethrucards_1up.yml +10 -10
  83. data/lib/squib/builtin/sprues/letter_poker_card_9up.yml +25 -25
  84. data/lib/squib/builtin/sprues/letter_poker_foldable_8up.yml +52 -52
  85. data/lib/squib/builtin/sprues/printplaygames_18up.yml +68 -68
  86. data/lib/squib/card.rb +75 -75
  87. data/lib/squib/commands/cli.rb +39 -39
  88. data/lib/squib/commands/data/template_option.rb +109 -109
  89. data/lib/squib/commands/make_sprue.rb +275 -275
  90. data/lib/squib/commands/new.rb +77 -77
  91. data/lib/squib/conf.rb +144 -139
  92. data/lib/squib/constants.rb +17 -17
  93. data/lib/squib/deck.rb +116 -116
  94. data/lib/squib/graphics/background.rb +14 -14
  95. data/lib/squib/graphics/cairo_context_wrapper.rb +113 -113
  96. data/lib/squib/graphics/embedding_utils.rb +28 -28
  97. data/lib/squib/graphics/gradient_regex.rb +47 -47
  98. data/lib/squib/graphics/hand.rb +42 -42
  99. data/lib/squib/graphics/image.rb +129 -108
  100. data/lib/squib/graphics/save_doc.rb +61 -61
  101. data/lib/squib/graphics/save_images.rb +52 -52
  102. data/lib/squib/graphics/save_pdf.rb +90 -90
  103. data/lib/squib/graphics/save_sprue.rb +204 -204
  104. data/lib/squib/graphics/shapes.rb +143 -143
  105. data/lib/squib/graphics/showcase.rb +85 -85
  106. data/lib/squib/graphics/text.rb +174 -174
  107. data/lib/squib/import/data_frame.rb +108 -108
  108. data/lib/squib/layout_parser.rb +138 -138
  109. data/lib/squib/progress.rb +38 -38
  110. data/lib/squib/sample_helpers.rb +34 -34
  111. data/lib/squib/sprues/crop_line.rb +28 -28
  112. data/lib/squib/sprues/crop_line_dash.rb +35 -35
  113. data/lib/squib/sprues/invalid_sprue_definition.rb +9 -9
  114. data/lib/squib/sprues/sprue.rb +203 -203
  115. data/lib/squib/sprues/sprue_schema.rb +48 -48
  116. data/lib/squib/version.rb +10 -10
  117. data/samples/autoscale_font/_autoscale_font.rb +29 -29
  118. data/samples/backend/_backend.rb +26 -26
  119. data/samples/basic.rb +19 -19
  120. data/samples/bug256/_bug256.rb +13 -0
  121. data/samples/build_groups/build_groups.rb +36 -36
  122. data/samples/colors/_colors.rb +38 -38
  123. data/samples/colors/_gradients.rb +34 -34
  124. data/samples/config/config_text_markup.rb +20 -20
  125. data/samples/config/custom_config.rb +18 -18
  126. data/samples/data/_csv.rb +33 -33
  127. data/samples/data/_excel.rb +55 -55
  128. data/samples/data/_yaml.rb +12 -12
  129. data/samples/hello_world.rb +6 -6
  130. data/samples/images/_cairo_access.rb +39 -39
  131. data/samples/images/_images.rb +104 -104
  132. data/samples/images/_more_load_images.rb +102 -102
  133. data/samples/intro/01_hello.rb +8 -8
  134. data/samples/intro/02_options.rb +14 -14
  135. data/samples/intro/03_layout.rb +11 -11
  136. data/samples/intro/04_arrays.rb +15 -15
  137. data/samples/intro/05_excel.rb +14 -14
  138. data/samples/layouts/builtin_layouts.rb +97 -97
  139. data/samples/layouts/layouts.rb +71 -71
  140. data/samples/project/src/characters.rb +8 -8
  141. data/samples/project/src/skills.rb +7 -7
  142. data/samples/proofs/_tgc_proofs.rb +16 -16
  143. data/samples/ranges/_ranges.rb +64 -64
  144. data/samples/saves/_hand.rb +23 -23
  145. data/samples/saves/_portrait_landscape.rb +23 -23
  146. data/samples/saves/_save_pdf.rb +29 -29
  147. data/samples/saves/_saves.rb +51 -51
  148. data/samples/saves/_showcase.rb +25 -25
  149. data/samples/shapes/_draw_shapes.rb +60 -60
  150. data/samples/shapes/_proofs.rb +22 -22
  151. data/samples/sprues/_advanced_sprues.rb +24 -24
  152. data/samples/sprues/_builtin_sprues.rb +21 -21
  153. data/samples/sprues/_fold_sheet.rb +27 -27
  154. data/samples/sprues/_hex_tiles.rb +15 -15
  155. data/samples/sprues/_mints.rb +11 -11
  156. data/samples/sprues/_sprue_example.rb +11 -11
  157. data/samples/text/_embed_text.rb +128 -128
  158. data/samples/text/_text.rb +47 -47
  159. data/samples/text/_text_options.rb +102 -102
  160. data/samples/text/bug134.rb +14 -14
  161. data/samples/units/_units.rb +32 -32
  162. data/squib.gemspec +52 -52
  163. metadata +51 -48
@@ -1,20 +1,20 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(config: 'config_text_markup.yml') do
4
- background color: :white
5
- text str: %{"'Yaml ain't markup', he says"},
6
- x: 10, y: 10, width: 300, height: 200, font: 'Serif 7',
7
- markup: true, hint: :cyan
8
-
9
- text str: 'Notice also the antialiasing method.',
10
- x: 320, y: 10, width: 300, height: 200, font: 'Arial Bold 7'
11
-
12
- save_png prefix: 'config_text_'
13
- end
14
-
15
- Squib::Deck.new(config: 'config_disable_quotes.yml') do
16
- text str: %{This has typographic sugar --- and ``explicit'' quotes --- but the quotes are "dumb"},
17
- x: 10, y: 10, width: 300, height: 200, font: 'Serif 7',
18
- markup: true, hint: :cyan
19
- save_png prefix: 'config_disable_text_'
20
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(config: 'config_text_markup.yml') do
4
+ background color: :white
5
+ text str: %{"'Yaml ain't markup', he says"},
6
+ x: 10, y: 10, width: 300, height: 200, font: 'Serif 7',
7
+ markup: true, hint: :cyan
8
+
9
+ text str: 'Notice also the antialiasing method.',
10
+ x: 320, y: 10, width: 300, height: 200, font: 'Arial Bold 7'
11
+
12
+ save_png prefix: 'config_text_'
13
+ end
14
+
15
+ Squib::Deck.new(config: 'config_disable_quotes.yml') do
16
+ text str: %{This has typographic sugar --- and ``explicit'' quotes --- but the quotes are "dumb"},
17
+ x: 10, y: 10, width: 300, height: 200, font: 'Serif 7',
18
+ markup: true, hint: :cyan
19
+ save_png prefix: 'config_disable_text_'
20
+ end
@@ -1,18 +1,18 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(config: 'custom-config.yml') do
4
- # Custom color defined in our config
5
- background color: :foo
6
-
7
- # Hints can be turned on in the config file
8
- text str: 'The Title', x: 0, y: 78, width: 825,
9
- font: 'Arial 24', align: :center
10
-
11
- # Progress bars are shown for these commands
12
- # And images are taken from img_dir, not the cwd.
13
- png file: 'shiny-purse2.png', x: 620, y: 75
14
- svg file: 'spanner2.svg', x: 620, y: 218
15
- save_png prefix: 'custom-config_'
16
- save_pdf file: 'custom-config-out.pdf'
17
-
18
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(config: 'custom-config.yml') do
4
+ # Custom color defined in our config
5
+ background color: :foo
6
+
7
+ # Hints can be turned on in the config file
8
+ text str: 'The Title', x: 0, y: 78, width: 825,
9
+ font: 'Arial 24', align: :center
10
+
11
+ # Progress bars are shown for these commands
12
+ # And images are taken from img_dir, not the cwd.
13
+ png file: 'shiny-purse2.png', x: 620, y: 75
14
+ svg file: 'spanner2.svg', x: 620, y: 218
15
+ save_png prefix: 'custom-config_'
16
+ save_pdf file: 'custom-config-out.pdf'
17
+
18
+ end
@@ -1,33 +1,33 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(cards: 2) do
4
- background color: :white
5
-
6
- # Outputs a hash of arrays with the header names as keys
7
- data = csv file: 'sample.csv'
8
- text str: data['Type'], x: 250, y: 55, font: 'Arial 18'
9
- text str: data['Level'], x: 65, y: 65, font: 'Arial 24'
10
-
11
- save format: :png, prefix: 'sample_csv_'
12
-
13
- # You can also specify the sheet, starting at 0
14
- data = xlsx file: 'sample.xlsx', sheet: 2
15
- end
16
-
17
- # CSV is also a Squib-module-level function, so this also works:
18
- data = Squib.csv file: 'quantity_explosion.csv' # 2 rows...
19
- num_cards = data['Name'].size # ...but 4 cards!
20
-
21
- Squib::Deck.new(cards: num_cards) do
22
- background color: :white
23
- rect # card border
24
- text str: data['Name'], font: 'Arial 18'
25
- save_sheet prefix: 'sample_csv_qty_', columns: 4
26
- end
27
-
28
- # Additionally, CSV supports inline data specifically
29
- data = Squib.csv data: <<-EOCSV
30
- Name,Cost
31
- Knight,3
32
- Orc,1
33
- EOCSV
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 2) do
4
+ background color: :white
5
+
6
+ # Outputs a hash of arrays with the header names as keys
7
+ data = csv file: 'sample.csv'
8
+ text str: data['Type'], x: 250, y: 55, font: 'Arial 18'
9
+ text str: data['Level'], x: 65, y: 65, font: 'Arial 24'
10
+
11
+ save format: :png, prefix: 'sample_csv_'
12
+
13
+ # You can also specify the sheet, starting at 0
14
+ data = xlsx file: 'sample.xlsx', sheet: 2
15
+ end
16
+
17
+ # CSV is also a Squib-module-level function, so this also works:
18
+ data = Squib.csv file: 'quantity_explosion.csv' # 2 rows...
19
+ num_cards = data['Name'].size # ...but 4 cards!
20
+
21
+ Squib::Deck.new(cards: num_cards) do
22
+ background color: :white
23
+ rect # card border
24
+ text str: data['Name'], font: 'Arial 18'
25
+ save_sheet prefix: 'sample_csv_qty_', columns: 4
26
+ end
27
+
28
+ # Additionally, CSV supports inline data specifically
29
+ data = Squib.csv data: <<-EOCSV
30
+ Name,Cost
31
+ Knight,3
32
+ Orc,1
33
+ EOCSV
@@ -1,55 +1,55 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(cards: 3) do
4
- background color: :white
5
-
6
- # Reads the first sheet by default (sheet 0)
7
- # Outputs a hash of arrays with the header names as keys
8
- data = xlsx file: 'sample.xlsx'
9
-
10
- text str: data['Name'], x: 250, y: 55, font: 'Arial 18'
11
- text str: data['Level'], x: 65, y: 65, font: 'Arial 24'
12
- text str: data['Description'], x: 65, y: 600, font: 'Arial 12'
13
-
14
- save format: :png, prefix: 'sample_excel_' # save to individual pngs
15
- end
16
-
17
- # xlsx is also a Squib-module-level function, so this also works:
18
- data = Squib.xlsx file: 'explode_quantities.xlsx' # 2 rows...
19
- num_cards = data['Name'].size # ...but 4 cards!
20
-
21
- Squib::Deck.new(cards: num_cards) do
22
- background color: :white
23
- rect # card border
24
- text str: data['Name'], font: 'Arial 18'
25
- save_sheet prefix: 'sample_xlsx_qty_', columns: 4
26
- end
27
-
28
-
29
- # Here's another example, a bit more realistic. Here's what's going on:
30
- # * We call xlsx from Squib directly - BEFORE Squib::Deck creation. This
31
- # allows us to infer the number of cards based on the size of the "Name"
32
- # field
33
- # * We make use of quantity explosion. Fields named "Qty" or "Quantity"
34
- # (any capitalization), or any other in the "qty_header" get expanded by the
35
- # number given
36
- # * We also make sure that trailing and leading whitespace is stripped
37
- # from each value. This is the default behavior in Squib, but the options
38
- # are here just to make sure.
39
-
40
- resource_data = Squib.xlsx(file: 'sample.xlsx', sheet: 2, strip: true) do |header, value|
41
- case header
42
- when 'Cost'
43
- "$#{value}k" # e.g. "3" becomes "$3k"
44
- else
45
- value # always return the original value if you didn't do anything to it
46
- end
47
- end
48
-
49
- Squib::Deck.new(cards: resource_data['Name'].size) do
50
- background color: :white
51
- rect width: :deck, height: :deck
52
- text str: resource_data['Name'], align: :center, width: :deck, hint: 'red'
53
- text str: resource_data['Cost'], align: :right, width: :deck, hint: 'red'
54
- save_sheet prefix: 'sample_excel_resources_', columns: 3
55
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 3) do
4
+ background color: :white
5
+
6
+ # Reads the first sheet by default (sheet 0)
7
+ # Outputs a hash of arrays with the header names as keys
8
+ data = xlsx file: 'sample.xlsx'
9
+
10
+ text str: data['Name'], x: 250, y: 55, font: 'Arial 18'
11
+ text str: data['Level'], x: 65, y: 65, font: 'Arial 24'
12
+ text str: data['Description'], x: 65, y: 600, font: 'Arial 12'
13
+
14
+ save format: :png, prefix: 'sample_excel_' # save to individual pngs
15
+ end
16
+
17
+ # xlsx is also a Squib-module-level function, so this also works:
18
+ data = Squib.xlsx file: 'explode_quantities.xlsx' # 2 rows...
19
+ num_cards = data['Name'].size # ...but 4 cards!
20
+
21
+ Squib::Deck.new(cards: num_cards) do
22
+ background color: :white
23
+ rect # card border
24
+ text str: data['Name'], font: 'Arial 18'
25
+ save_sheet prefix: 'sample_xlsx_qty_', columns: 4
26
+ end
27
+
28
+
29
+ # Here's another example, a bit more realistic. Here's what's going on:
30
+ # * We call xlsx from Squib directly - BEFORE Squib::Deck creation. This
31
+ # allows us to infer the number of cards based on the size of the "Name"
32
+ # field
33
+ # * We make use of quantity explosion. Fields named "Qty" or "Quantity"
34
+ # (any capitalization), or any other in the "qty_header" get expanded by the
35
+ # number given
36
+ # * We also make sure that trailing and leading whitespace is stripped
37
+ # from each value. This is the default behavior in Squib, but the options
38
+ # are here just to make sure.
39
+
40
+ resource_data = Squib.xlsx(file: 'sample.xlsx', sheet: 2, strip: true) do |header, value|
41
+ case header
42
+ when 'Cost'
43
+ "$#{value}k" # e.g. "3" becomes "$3k"
44
+ else
45
+ value # always return the original value if you didn't do anything to it
46
+ end
47
+ end
48
+
49
+ Squib::Deck.new(cards: resource_data['Name'].size) do
50
+ background color: :white
51
+ rect width: :deck, height: :deck
52
+ text str: resource_data['Name'], align: :center, width: :deck, hint: 'red'
53
+ text str: resource_data['Cost'], align: :right, width: :deck, hint: 'red'
54
+ save_sheet prefix: 'sample_excel_resources_', columns: 3
55
+ end
@@ -1,12 +1,12 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(cards: 2) do
4
- background color: :white
5
-
6
- # Outputs a hash of arrays with the header names as keys
7
- data = yaml file: 'sample.yaml'
8
- text str: data['Type'], x: 250, y: 55, font: 'Arial 18'
9
- text str: data['Level'], x: 65, y: 65, font: 'Arial 24'
10
-
11
- save format: :png, prefix: 'sample_yaml_'
12
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 2) do
4
+ background color: :white
5
+
6
+ # Outputs a hash of arrays with the header names as keys
7
+ data = yaml file: 'sample.yaml'
8
+ text str: data['Type'], x: 250, y: 55, font: 'Arial 18'
9
+ text str: data['Level'], x: 65, y: 65, font: 'Arial 24'
10
+
11
+ save format: :png, prefix: 'sample_yaml_'
12
+ end
@@ -1,6 +1,6 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(cards: 2) do
4
- text str: %w(Hello World!)
5
- save_png
6
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 2) do
4
+ text str: %w(Hello World!)
5
+ save_png
6
+ end
@@ -1,39 +1,39 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(cards: 2) do
4
- background color: :white
5
- # If you really need something custom-made, the underlying cairo context
6
- # can be accessed directly via each Squib::Card
7
- #
8
- # WARNING! Input validation is not done on Squib::Cards. Proceed at your own risk.
9
-
10
- # The recommended approach is to use Deck's Enumerable, which iterates over Squib::Cards
11
- # I also recommend wrapping it in a Cairo save/restore, which Squib calls "use_cairo"
12
- each do |card|
13
- card.use_cairo do |cairo_context|
14
- cairo_context.set_source_color(:blue)
15
- cairo_context.circle(150, 150, 150)
16
- cairo_context.fill
17
- end
18
- end
19
-
20
- # Or the square bracket accessors []
21
- self[1].use_cairo do |cairo_context|
22
- cairo_context.circle(50, 50, 50)
23
- cairo_context.set_source_color(:red)
24
- cairo_context.fill
25
- end
26
-
27
- # Or modify the coordinate system for all (most?) future calls
28
- # Could be handy for a dynamic bleed
29
- each do |card|
30
- # note how this does NOT use save/restore.
31
- # again... this "feature" lives in the Land of Undefined Behavior
32
- card.cairo_context.translate(500, 500)
33
- end
34
- rect x: 0, y: 0, # actually 500, 500
35
- width: 50, height: 50, fill_color: :red
36
-
37
-
38
- save_png prefix: 'cairo_access_'
39
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 2) do
4
+ background color: :white
5
+ # If you really need something custom-made, the underlying cairo context
6
+ # can be accessed directly via each Squib::Card
7
+ #
8
+ # WARNING! Input validation is not done on Squib::Cards. Proceed at your own risk.
9
+
10
+ # The recommended approach is to use Deck's Enumerable, which iterates over Squib::Cards
11
+ # I also recommend wrapping it in a Cairo save/restore, which Squib calls "use_cairo"
12
+ each do |card|
13
+ card.use_cairo do |cairo_context|
14
+ cairo_context.set_source_color(:blue)
15
+ cairo_context.circle(150, 150, 150)
16
+ cairo_context.fill
17
+ end
18
+ end
19
+
20
+ # Or the square bracket accessors []
21
+ self[1].use_cairo do |cairo_context|
22
+ cairo_context.circle(50, 50, 50)
23
+ cairo_context.set_source_color(:red)
24
+ cairo_context.fill
25
+ end
26
+
27
+ # Or modify the coordinate system for all (most?) future calls
28
+ # Could be handy for a dynamic bleed
29
+ each do |card|
30
+ # note how this does NOT use save/restore.
31
+ # again... this "feature" lives in the Land of Undefined Behavior
32
+ card.cairo_context.translate(500, 500)
33
+ end
34
+ rect x: 0, y: 0, # actually 500, 500
35
+ width: 50, height: 50, fill_color: :red
36
+
37
+
38
+ save_png prefix: 'cairo_access_'
39
+ end
@@ -1,104 +1,104 @@
1
- require 'squib'
2
- require 'squib/sample_helpers'
3
-
4
- Squib::Deck.new(width: 1000, height: 3000) do
5
- draw_graph_paper width, height
6
-
7
- sample "This a PNG.\nNo scaling is done by default." do |x, y|
8
- png file: 'angler-fish.png', x: x, y: y
9
- end
10
-
11
- sample 'PNGs can be upscaled, but they will emit an antialias warning (unless you turn it off in the config.yml)' do |x,y|
12
- png file: 'angler-fish.png', x: x, y: y, width: 150, height: 150
13
- end
14
-
15
- sample 'SVGs can be loaded from a file (left) or from straight XML (right). They can also be scaled to any size.' do |x,y|
16
- svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100
17
- svg data: File.read('robot-golem.svg'), width: 100, height: 100,
18
- x: x + 200, y: y
19
- end
20
-
21
- sample 'PNG and SVG can be auto-scaled by one side and setting the other to :scale' do |x,y|
22
- svg file: 'robot-golem.svg', x: x, y: y, width: 50, height: :scale
23
- svg file: 'robot-golem.svg', x: x + 50, y: y, width: :scale, height: 50
24
-
25
- png file: 'angler-fish.png', x: x + 200, y: y, width: 50, height: :scale
26
- png file: 'angler-fish.png', x: x + 250, y: y, width: :scale, height: 50
27
- end
28
-
29
- sample 'PNGs can be cropped. To work from sprite sheets, you can set crop coordinates to PNG images. Rounded corners supported too.' do |x,y|
30
- png file: 'sprites.png', x: x - 50, y: y - 50 # entire sprite sheet
31
- rect x: x - 50, y: y - 50, width: 100, height: 100, # draw the crop line
32
- radius: 15, dash: '3 3', stroke_color: 'red', stroke_width: 3
33
- text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y - 35
34
- png file: 'sprites.png', x: x + 200, y: y - 50, # just the robot golem image
35
- crop_x: 0, crop_y: 0, crop_corner_radius: 15,
36
- crop_width: 100, crop_height: 100
37
-
38
- png file: 'sprites.png', x: x - 50, y: y + 50 # entire sprite sheet again
39
- rect x: x + 14, y: y + 50, width: 65, height: 65, # highlight the crop
40
- radius: 25, dash: '3 3', stroke_color: 'red', stroke_width: 3
41
- text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y + 50
42
- png file: 'sprites.png', x: x + 225, y: y + 50, # just the drakkar ship image, rotated
43
- crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
44
- crop_width: 64, crop_height: 64, angle: Math::PI / 6
45
- end
46
-
47
- sample 'SVGs can be cropped too.' do |x,y|
48
- svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100,
49
- crop_x: 40, crop_y: 0, crop_width: 50, crop_height: 50
50
- end
51
-
52
- sample 'Images can be flipped about their center.' do |x,y|
53
- png file: 'angler-fish.png', x: x, y: y, flip_vertical: true, flip_horizontal: true
54
- svg file: 'robot-golem.svg', x: x + 200, y: y, width: 100, height: 100,
55
- flip_horizontal: true
56
- end
57
-
58
- sample 'SVG can be limited to rendering to a single object if the SVG ID is set. If you look in this SVG file, the black backdrop has ID #backdrop.' do |x,y|
59
- svg file: 'robot-golem.svg', id: 'backdrop', x: x, y: y, width: 100, height: 100
60
- end
61
-
62
- sample "The SVG force_id option allows use of an ID only when specified, and render nothing if empty. Useful for multiple icons in one SVG file.\nThis should show nothing." do |x,y|
63
- svg file: 'robot-golem.svg', x: x, y: y,
64
- force_id: true, id: '' # <-- the important parts
65
- end
66
-
67
- sample 'NOTE! If you render a single object in an SVG, its placement is still relative to the SVG document.' do |x,y|
68
- svg file: 'offset.svg', x: x, y: y
69
- rect x: x, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
70
-
71
- svg file: 'offset.svg', id: 'thing', x: x + 200, y: y, width: 100, height: 100
72
- rect x: x + 200, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
73
- end
74
-
75
- sample 'PNGs can be blended onto each other with 15 different blending operators. Alpha transparency supported too. See http://cairographics.org/operators' do |x,y|
76
- png file: 'ball.png', x: x, y: y
77
- png file: 'grit.png', x: x + 20, y: y + 20, blend: :color_burn, alpha: 0.75
78
- end
79
-
80
- sample 'Rotation is around the upper-left corner of the image. Unit is radians.' do |x,y|
81
- rect x: x, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
82
- png x: x, y: y, width: 100, height: 100, angle: Math::PI / 4, file: 'angler-fish.png'
83
-
84
- rect x: x + 250, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
85
- svg x: x + 250, y: y, width: 100, height: 100, file: 'robot-golem.svg',
86
- angle: Math::PI / 2 - 0.2
87
- end
88
-
89
- sample 'SVGs and PNGs can be used as masks for colors instead of being directly rendered.' do |x,y|
90
- svg mask: '#00ff00', file: 'glass-heart.svg', x: x - 50, y: y - 50, width: 200, height: 200
91
- svg mask: '(0,0)(500,0) #eee@0.0 #111@1.0', file: 'glass-heart.svg', x: x + 150, y: y - 50, width: 200, height: 200
92
- end
93
-
94
- sample 'PNG masks are based on the alpha channel. Gradient coordinates are relative to the card.' do |x,y|
95
- png file: 'with-alpha.png', x: x - 50, y: y
96
- png file: 'with-alpha.png', mask: :magenta, x: x + 50, y: y
97
-
98
- mask = "(#{x+150+75}, #{y+75}, 0)(#{x+150+75}, #{y+75}, 100) #f00@0.0 #000@1.0"
99
- png file: 'with-alpha.png', mask: mask, x: x + 150, y: y, width: 150, height: :scale
100
- end
101
-
102
-
103
- save_png prefix: '_images_'
104
- end
1
+ require 'squib'
2
+ require 'squib/sample_helpers'
3
+
4
+ Squib::Deck.new(width: 1000, height: 3000) do
5
+ draw_graph_paper width, height
6
+
7
+ sample "This a PNG.\nNo scaling is done by default." do |x, y|
8
+ png file: 'angler-fish.png', x: x, y: y
9
+ end
10
+
11
+ sample 'PNGs can be upscaled, but they will emit an antialias warning (unless you turn it off in the config.yml)' do |x,y|
12
+ png file: 'angler-fish.png', x: x, y: y, width: 150, height: 150
13
+ end
14
+
15
+ sample 'SVGs can be loaded from a file (left) or from straight XML (right). They can also be scaled to any size.' do |x,y|
16
+ svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100
17
+ svg data: File.read('robot-golem.svg'), width: 100, height: 100,
18
+ x: x + 200, y: y
19
+ end
20
+
21
+ sample 'PNG and SVG can be auto-scaled by one side and setting the other to :scale' do |x,y|
22
+ svg file: 'robot-golem.svg', x: x, y: y, width: 50, height: :scale
23
+ svg file: 'robot-golem.svg', x: x + 50, y: y, width: :scale, height: 50
24
+
25
+ png file: 'angler-fish.png', x: x + 200, y: y, width: 50, height: :scale
26
+ png file: 'angler-fish.png', x: x + 250, y: y, width: :scale, height: 50
27
+ end
28
+
29
+ sample 'PNGs can be cropped. To work from sprite sheets, you can set crop coordinates to PNG images. Rounded corners supported too.' do |x,y|
30
+ png file: 'sprites.png', x: x - 50, y: y - 50 # entire sprite sheet
31
+ rect x: x - 50, y: y - 50, width: 100, height: 100, # draw the crop line
32
+ radius: 15, dash: '3 3', stroke_color: 'red', stroke_width: 3
33
+ text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y - 35
34
+ png file: 'sprites.png', x: x + 200, y: y - 50, # just the robot golem image
35
+ crop_x: 0, crop_y: 0, crop_corner_radius: 15,
36
+ crop_width: 100, crop_height: 100
37
+
38
+ png file: 'sprites.png', x: x - 50, y: y + 50 # entire sprite sheet again
39
+ rect x: x + 14, y: y + 50, width: 65, height: 65, # highlight the crop
40
+ radius: 25, dash: '3 3', stroke_color: 'red', stroke_width: 3
41
+ text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y + 50
42
+ png file: 'sprites.png', x: x + 225, y: y + 50, # just the drakkar ship image, rotated
43
+ crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
44
+ crop_width: 64, crop_height: 64, angle: Math::PI / 6
45
+ end
46
+
47
+ sample 'SVGs can be cropped too.' do |x,y|
48
+ svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100,
49
+ crop_x: 40, crop_y: 0, crop_width: 50, crop_height: 50
50
+ end
51
+
52
+ sample 'Images can be flipped about their center.' do |x,y|
53
+ png file: 'angler-fish.png', x: x, y: y, flip_vertical: true, flip_horizontal: true
54
+ svg file: 'robot-golem.svg', x: x + 200, y: y, width: 100, height: 100,
55
+ flip_horizontal: true
56
+ end
57
+
58
+ sample 'SVG can be limited to rendering to a single object if the SVG ID is set. If you look in this SVG file, the black backdrop has ID #backdrop.' do |x,y|
59
+ svg file: 'robot-golem.svg', id: 'backdrop', x: x, y: y, width: 100, height: 100
60
+ end
61
+
62
+ sample "The SVG force_id option allows use of an ID only when specified, and render nothing if empty. Useful for multiple icons in one SVG file.\nThis should show nothing." do |x,y|
63
+ svg file: 'robot-golem.svg', x: x, y: y,
64
+ force_id: true, id: '' # <-- the important parts
65
+ end
66
+
67
+ sample 'NOTE! If you render a single object in an SVG, its placement is still relative to the SVG document.' do |x,y|
68
+ svg file: 'offset.svg', x: x, y: y
69
+ rect x: x, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
70
+
71
+ svg file: 'offset.svg', id: 'thing', x: x + 200, y: y, width: 100, height: 100
72
+ rect x: x + 200, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
73
+ end
74
+
75
+ sample 'PNGs can be blended onto each other with 15 different blending operators. Alpha transparency supported too. See http://cairographics.org/operators' do |x,y|
76
+ png file: 'ball.png', x: x, y: y
77
+ png file: 'grit.png', x: x + 20, y: y + 20, blend: :color_burn, alpha: 0.75
78
+ end
79
+
80
+ sample 'Rotation is around the upper-left corner of the image. Unit is radians.' do |x,y|
81
+ rect x: x, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
82
+ png x: x, y: y, width: 100, height: 100, angle: Math::PI / 4, file: 'angler-fish.png'
83
+
84
+ rect x: x + 250, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
85
+ svg x: x + 250, y: y, width: 100, height: 100, file: 'robot-golem.svg',
86
+ angle: Math::PI / 2 - 0.2
87
+ end
88
+
89
+ sample 'SVGs and PNGs can be used as masks for colors instead of being directly rendered.' do |x,y|
90
+ svg mask: '#00ff00', file: 'glass-heart.svg', x: x - 50, y: y - 50, width: 200, height: 200
91
+ svg mask: '(0,0)(500,0) #eee@0.0 #111@1.0', file: 'glass-heart.svg', x: x + 150, y: y - 50, width: 200, height: 200
92
+ end
93
+
94
+ sample 'PNG masks are based on the alpha channel. Gradient coordinates are relative to the card.' do |x,y|
95
+ png file: 'with-alpha.png', x: x - 50, y: y
96
+ png file: 'with-alpha.png', mask: :magenta, x: x + 50, y: y
97
+
98
+ mask = "(#{x+150+75}, #{y+75}, 0)(#{x+150+75}, #{y+75}, 100) #f00@0.0 #000@1.0"
99
+ png file: 'with-alpha.png', mask: mask, x: x + 150, y: y, width: 150, height: :scale
100
+ end
101
+
102
+
103
+ save_png prefix: '_images_'
104
+ end