squib 0.8.0 → 0.9.0

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +14 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +201 -175
  5. data/Gemfile +2 -4
  6. data/README.md +650 -645
  7. data/RELEASE TODO.md +18 -18
  8. data/Rakefile +106 -99
  9. data/appveyor.yml +29 -0
  10. data/lib/squib.rb +32 -32
  11. data/lib/squib/api/background.rb +20 -20
  12. data/lib/squib/api/data.rb +131 -131
  13. data/lib/squib/api/image.rb +108 -90
  14. data/lib/squib/api/save.rb +151 -149
  15. data/lib/squib/api/settings.rb +35 -35
  16. data/lib/squib/api/shapes.rb +255 -230
  17. data/lib/squib/api/text.rb +65 -65
  18. data/lib/squib/api/text_embed.rb +96 -96
  19. data/lib/squib/args/arg_loader.rb +138 -138
  20. data/lib/squib/args/box.rb +54 -54
  21. data/lib/squib/args/card_range.rb +32 -32
  22. data/lib/squib/args/color_validator.rb +11 -11
  23. data/lib/squib/args/coords.rb +32 -32
  24. data/lib/squib/args/dir_validator.rb +16 -16
  25. data/lib/squib/args/draw.rb +92 -92
  26. data/lib/squib/args/embed_adjust.rb +25 -25
  27. data/lib/squib/args/embed_key.rb +17 -17
  28. data/lib/squib/args/hand_special.rb +37 -37
  29. data/lib/squib/args/import.rb +39 -39
  30. data/lib/squib/args/input_file.rb +37 -37
  31. data/lib/squib/args/paint.rb +43 -43
  32. data/lib/squib/args/paragraph.rb +116 -115
  33. data/lib/squib/args/save_batch.rb +63 -60
  34. data/lib/squib/args/scale_box.rb +53 -53
  35. data/lib/squib/args/sheet.rb +72 -72
  36. data/lib/squib/args/showcase_special.rb +38 -38
  37. data/lib/squib/args/svg_special.rb +37 -37
  38. data/lib/squib/args/transform.rb +60 -24
  39. data/lib/squib/args/typographer.rb +117 -117
  40. data/lib/squib/card.rb +66 -67
  41. data/lib/squib/conf.rb +131 -117
  42. data/lib/squib/constants.rb +12 -178
  43. data/lib/squib/deck.rb +113 -113
  44. data/lib/squib/graphics/cairo_context_wrapper.rb +113 -99
  45. data/lib/squib/graphics/gradient_regex.rb +46 -46
  46. data/lib/squib/graphics/hand.rb +42 -42
  47. data/lib/squib/graphics/image.rb +103 -76
  48. data/lib/squib/graphics/save_doc.rb +103 -103
  49. data/lib/squib/graphics/save_images.rb +39 -33
  50. data/lib/squib/graphics/shapes.rb +135 -119
  51. data/lib/squib/graphics/showcase.rb +85 -85
  52. data/lib/squib/graphics/text.rb +176 -176
  53. data/lib/squib/layout_parser.rb +91 -91
  54. data/lib/squib/layouts/economy.yml +85 -85
  55. data/lib/squib/layouts/fantasy.yml +101 -101
  56. data/lib/squib/layouts/hand.yml +62 -62
  57. data/lib/squib/layouts/playing-card.yml +35 -35
  58. data/lib/squib/layouts/tuck_box.yml +45 -45
  59. data/lib/squib/project_template/IDEAS.md +22 -0
  60. data/lib/squib/project_template/PLAYTESTING.md +26 -0
  61. data/lib/squib/project_template/RULES.md +21 -0
  62. data/lib/squib/project_template/config.yml +49 -45
  63. data/lib/squib/sample_helpers.rb +34 -0
  64. data/lib/squib/version.rb +10 -10
  65. data/samples/autoscale_font/_autoscale_font.rb +29 -0
  66. data/samples/color_shortcuts.rb +6 -6
  67. data/samples/csv_import.rb +26 -26
  68. data/samples/custom-config.yml +5 -5
  69. data/samples/custom_config.rb +18 -18
  70. data/samples/draw_shapes.rb +48 -45
  71. data/samples/embed_text.rb +88 -88
  72. data/samples/excel.rb +55 -55
  73. data/samples/hand.rb +24 -24
  74. data/samples/images/_images.rb +104 -0
  75. data/samples/intro/01_hello.rb +9 -0
  76. data/samples/intro/02_options.rb +15 -0
  77. data/samples/intro/03_layout.rb +12 -0
  78. data/samples/intro/04_arrays.rb +16 -0
  79. data/samples/intro/05_excel.rb +15 -0
  80. data/samples/layouts.rb +62 -62
  81. data/samples/layouts_builtin.rb +51 -51
  82. data/samples/load_images.rb +99 -78
  83. data/samples/load_images_config.yml +1 -0
  84. data/samples/quantity_explosion.csv +2 -2
  85. data/samples/ranges.rb +64 -64
  86. data/samples/sample.csv +2 -2
  87. data/samples/saves.rb +9 -1
  88. data/samples/sprites.png +0 -0
  89. data/samples/text/_text.rb +46 -0
  90. data/samples/text_options.rb +102 -102
  91. data/spec/api/api_data_spec.rb +117 -117
  92. data/spec/api/api_settings_spec.rb +37 -37
  93. data/spec/args/box_spec.rb +127 -127
  94. data/spec/args/draw_spec.rb +101 -95
  95. data/spec/args/embed_key_spec.rb +13 -13
  96. data/spec/args/input_file_spec.rb +21 -21
  97. data/spec/args/paint_spec.rb +21 -21
  98. data/spec/args/paragraph_spec.rb +152 -152
  99. data/spec/args/range_spec.rb +40 -40
  100. data/spec/args/save_batch_spec.rb +51 -51
  101. data/spec/args/scale_box_spec.rb +71 -71
  102. data/spec/args/sheet_spec.rb +58 -58
  103. data/spec/args/showcase_special_spec.rb +15 -15
  104. data/spec/args/transform_spec.rb +25 -0
  105. data/spec/card_spec.rb +11 -0
  106. data/spec/conf_spec.rb +13 -3
  107. data/spec/data/conf/unrecognized.yml +4 -0
  108. data/spec/data/csv/qty.csv +2 -2
  109. data/spec/data/csv/qty_named.csv +2 -2
  110. data/spec/data/csv/with_spaces.csv +2 -2
  111. data/spec/data/samples/autoscale_font.rb.txt +84 -84
  112. data/spec/data/samples/basic.rb.txt +227 -209
  113. data/spec/data/samples/config_text_markup.rb.txt +72 -72
  114. data/spec/data/samples/csv_import.rb.txt +213 -213
  115. data/spec/data/samples/custom_config.rb.txt +57 -48
  116. data/spec/data/samples/draw_shapes.rb.txt +555 -3
  117. data/spec/data/samples/embed_text.rb.txt +283 -283
  118. data/spec/data/samples/excel.rb.txt +661 -661
  119. data/spec/data/samples/gradients.rb.txt +77 -79
  120. data/spec/data/samples/hand.rb.txt +538 -538
  121. data/spec/data/samples/hello_world.rb.txt +36 -36
  122. data/spec/data/samples/load_images.rb.txt +170 -0
  123. data/spec/data/samples/portrait-landscape.rb.txt +51 -49
  124. data/spec/data/samples/ranges.rb.txt +472 -460
  125. data/spec/data/samples/saves.rb.txt +810 -801
  126. data/spec/data/samples/showcase.rb.txt +5926 -5910
  127. data/spec/data/samples/text_options.rb.txt +1125 -1125
  128. data/spec/data/samples/tgc_proofs.rb.txt +95 -81
  129. data/spec/graphics/cairo_context_wrapper_spec.rb +104 -84
  130. data/spec/graphics/graphics_save_doc_spec.rb +67 -67
  131. data/spec/samples/diff-with-css.example.html +39 -0
  132. data/spec/samples/expected/load_images_00.png +0 -0
  133. data/spec/samples/expected/shape_00.png +0 -0
  134. data/spec/samples/run_samples_spec.rb +17 -0
  135. data/spec/samples/samples_regression_spec.rb +72 -82
  136. data/spec/spec_helper.rb +9 -1
  137. data/squib.gemspec +49 -48
  138. data/squib.sublime-project +42 -42
  139. metadata +94 -48
  140. data/spec/graphics/graphics_images_spec.rb +0 -94
@@ -1,51 +1,51 @@
1
- require 'squib'
2
-
3
- # This sample demonstrates the built-in layouts for Squib.
4
- # Each card demonstrates a different built-in layout.
5
- Squib::Deck.new(layout: 'fantasy.yml') do
6
- background color: 'white'
7
-
8
- set font: 'Times New Roman,Serif 32'
9
- hint text: '#333' # show extents of text boxes to demo the layout
10
-
11
- text str: 'fantasy.yml', layout: :title
12
- text str: 'ur', layout: :upper_right
13
- text str: 'art', layout: :art
14
- text str: 'type', layout: :type
15
- text str: 'tr', layout: :type_right
16
- text str: 'description', layout: :description
17
- text str: 'lr', layout: :lower_right
18
- text str: 'll', layout: :lower_left
19
- text str: 'credits', layout: :copy
20
-
21
- rect layout: :safe
22
- rect layout: :cut
23
- save_png prefix: 'layouts_builtin_fantasy_'
24
- end
25
-
26
- Squib::Deck.new(layout: 'economy.yml') do
27
- background color: 'white'
28
-
29
- set font: 'Times New Roman,Serif 32'
30
- hint text: '#333' # show extents of text boxes to demo the layout
31
-
32
- text str: 'economy.yml', layout: :title
33
- text str: 'art', layout: :art
34
- text str: 'description', layout: :description
35
- text str: 'type', layout: :type
36
- text str: 'lr', layout: :lower_right
37
- text str: 'll', layout: :lower_left
38
- text str: 'credits', layout: :copy
39
-
40
- rect layout: :safe
41
- rect layout: :cut
42
- save_png prefix: 'layouts_builtin_economy_'
43
- end
44
-
45
- # Stitch together a deck of all the above examples
46
- Squib::Deck.new(cards: 2) do
47
- Dir.glob('_output/layouts_builtin_*.png').each.with_index do |file, i|
48
- png file: file, range: i
49
- end
50
- save_sheet prefix: 'layouts_builtinsheet_'
51
- end
1
+ require 'squib'
2
+
3
+ # This sample demonstrates the built-in layouts for Squib.
4
+ # Each card demonstrates a different built-in layout.
5
+ Squib::Deck.new(layout: 'fantasy.yml') do
6
+ background color: 'white'
7
+
8
+ set font: 'Times New Roman,Serif 32'
9
+ hint text: '#333' # show extents of text boxes to demo the layout
10
+
11
+ text str: 'fantasy.yml', layout: :title
12
+ text str: 'ur', layout: :upper_right
13
+ text str: 'art', layout: :art
14
+ text str: 'type', layout: :type
15
+ text str: 'tr', layout: :type_right
16
+ text str: 'description', layout: :description
17
+ text str: 'lr', layout: :lower_right
18
+ text str: 'll', layout: :lower_left
19
+ text str: 'credits', layout: :copy
20
+
21
+ rect layout: :safe
22
+ rect layout: :cut
23
+ save_png prefix: 'layouts_builtin_fantasy_'
24
+ end
25
+
26
+ Squib::Deck.new(layout: 'economy.yml') do
27
+ background color: 'white'
28
+
29
+ set font: 'Times New Roman,Serif 32'
30
+ hint text: '#333' # show extents of text boxes to demo the layout
31
+
32
+ text str: 'economy.yml', layout: :title
33
+ text str: 'art', layout: :art
34
+ text str: 'description', layout: :description
35
+ text str: 'type', layout: :type
36
+ text str: 'lr', layout: :lower_right
37
+ text str: 'll', layout: :lower_left
38
+ text str: 'credits', layout: :copy
39
+
40
+ rect layout: :safe
41
+ rect layout: :cut
42
+ save_png prefix: 'layouts_builtin_economy_'
43
+ end
44
+
45
+ # Stitch together a deck of all the above examples
46
+ Squib::Deck.new(cards: 2) do
47
+ Dir.glob('_output/layouts_builtin_*.png').each.with_index do |file, i|
48
+ png file: file, range: i
49
+ end
50
+ save_sheet prefix: 'layouts_builtinsheet_'
51
+ end
@@ -1,78 +1,99 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(width: 825, height: 1125, cards: 1) do
4
- background color: '#0b7c8e'
5
- rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
6
-
7
- png file: 'shiny-purse.png', x: 620, y: 75 # no scaling is done by default
8
- svg file: 'spanner.svg', x: 620, y: 218
9
-
10
- # Can be scaled if width and height are set
11
- svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
12
- png file: 'shiny-purse.png', x: 305, y: 50, width: 250, height: 250
13
- #...but PNGs will warn if it's an upscale
14
-
15
- # Can be scaled using just width or height, if one of them is set to :scale
16
- svg file: 'spanner.svg', x: 200, y: 350, width: 35, height: :scale
17
- svg file: 'spanner.svg', x: 200, y: 390, width: :scale, height: 35
18
- png file: 'shiny-purse.png', x: 240, y: 350, width: 35, height: :scale
19
- png file: 'shiny-purse.png', x: 240, y: 390, width: :scale, height: 35
20
-
21
- # We can also limit our rendering to a single object, if the SVG ID is set
22
- svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75
23
- # Squib prepends a #-sign if one is not specified
24
- svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125
25
-
26
- # We can also load SVGs as a string of XML
27
- svg data: File.read('spanner.svg'), x: 50, y: 600, width: 75, height: 75
28
-
29
- # The svg data field works nicely with modifying the SVG XML on-the-fly.
30
- # To run this one, do `gem install game_icons` and uncomment the following
31
- #
32
- # require 'game_icons'
33
- # svg data: GameIcons.get('angler-fish').recolor(fg: '#ccc', bg: '#333').string,
34
- # x: 150, y: 600, width: 75, height: 75
35
- #
36
- # More examples at https://github.com/andymeneely/game_icons
37
- # (or `gem install game_icons`) to get & manipulate art from game-icons.net
38
- # Nokogiri (already included in Squib) is also great for XML manipulation.
39
-
40
- # WARNING! If you choose to use the SVG ID, the x-y coordinates are still
41
- # relative to the SVG page. See this example in an SVG editor
42
- svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
43
-
44
- # Over 15 different blending operators are supported.
45
- # See http://cairographics.org/operators
46
- # Alpha transparency too
47
- png file: 'ball.png', x: 50, y: 700
48
- png file: 'grit.png', x: 70, y: 750, blend: :color_burn, alpha: 0.75
49
-
50
- # Images can be rotated around their upper-left corner
51
- png file: 'shiny-purse.png', x: 300, y: 700, angle: 0.0 # default (no rotate)
52
- png file: 'shiny-purse.png', x: 300, y: 800, angle: Math::PI / 4
53
- svg file: 'spanner.svg', x: 300, y: 900, angle: Math::PI / 2 - 0.1
54
-
55
- # Images can also be used as masks instead of being directly painted.
56
- # This is particularly useful for switching directly over to black-and-white for printing
57
- # Or, if you want the same image to be used but with different colors/gradients
58
- svg mask: '#00ff00',
59
- file: 'glass-heart.svg',
60
- x: 500, y: 600, width: 200, height: 200
61
- svg mask: '(0,0)(0,500) #ccc@0.0 #333@1.0',
62
- file: 'glass-heart.svg',
63
- x: 500, y: 800, width: 200, height: 200
64
-
65
- # Masks are based on the alpha channel, so this is just a magenta square
66
- png mask: :magenta, file: 'shiny-purse.png',
67
- x: 650, y: 950
68
-
69
- # Note that this method does nothing, even though it would normally fill up
70
- # the card. force_id: true looks to the id field to be non-empty to render.
71
- # This is useful if you have multiple different icons in one SVG file,
72
- # but sometimes want to use none.
73
- # e.g. id: [:attack, :defend, nil]
74
- svg file: 'spanner.svg', width: :deck, height: :deck,
75
- force_id: true, id: '' # <-- the important part
76
-
77
- save prefix: 'load_images_', format: :png
78
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(width: 825, height: 1125, cards: 1, config: 'load_images_config.yml') do
4
+ background color: '#0b7c8e'
5
+ rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
6
+
7
+ png file: 'shiny-purse.png', x: 620, y: 75 # no scaling is done by default
8
+ svg file: 'spanner.svg', x: 620, y: 218
9
+
10
+ # Can be scaled if width and height are set
11
+ svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
12
+ png file: 'shiny-purse.png', x: 305, y: 50, width: 250, height: 250
13
+ #...but PNGs will warn if it's an upscale, unless you disable them in config.yml
14
+
15
+ # Can be scaled using just width or height, if one of them is set to :scale
16
+ svg file: 'spanner.svg', x: 200, y: 350, width: 35, height: :scale
17
+ svg file: 'spanner.svg', x: 200, y: 390, width: :scale, height: 35
18
+ png file: 'shiny-purse.png', x: 240, y: 350, width: 35, height: :scale
19
+ png file: 'shiny-purse.png', x: 240, y: 390, width: :scale, height: 35
20
+
21
+ # You can also crop the loaded images, so you can work from a sprite sheet
22
+ png file: 'sprites.png', x: 300, y: 350 # entire sprite sheet
23
+ png file: 'sprites.png', x: 300, y: 425, # just the robot golem image
24
+ crop_x: 0, crop_y: 0, crop_corner_radius: 10,
25
+ crop_width: 64, crop_height: 64
26
+ png file: 'sprites.png', x: 400, y: 425, # just the drakkar ship image
27
+ crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
28
+ crop_width: 64, crop_height: 64
29
+ png file: 'sprites.png', x: 500, y: 415, # just the drakkar ship image, rotated
30
+ crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
31
+ crop_width: 64, crop_height: 64, angle: Math::PI / 6
32
+
33
+ # Cropping also works on SVGs too
34
+ svg file: 'spanner.svg', x: 300, y: 500, width: 64, height: 64,
35
+ crop_x: 32, crop_y: 32, crop_width: 32, crop_height:32
36
+
37
+ # We can flip our images too
38
+ png file: 'sprites.png', x: 300, y: 535, flip_vertical: true, flip_horizontal: true
39
+ svg file: 'spanner.svg', x: 300, y: 615, width: 64, height: 64,
40
+ flip_vertical: true, flip_horizontal: true
41
+
42
+ # We can also limit our rendering to a single object, if the SVG ID is set
43
+ svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75
44
+ # Squib prepends a #-sign if one is not specified
45
+ svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125
46
+
47
+ # We can also load SVGs as a string of XML
48
+ svg data: File.read('spanner.svg'), x: 50, y: 600, width: 75, height: 75
49
+
50
+ # The svg data field works nicely with modifying the SVG XML on-the-fly.
51
+ # To run this one, do `gem install game_icons` and uncomment the following
52
+ #
53
+ # require 'game_icons'
54
+ # svg data: GameIcons.get('angler-fish').recolor(fg: '#ccc', bg: '#333').string,
55
+ # x: 150, y: 600, width: 75, height: 75
56
+ #
57
+ # More examples at https://github.com/andymeneely/game_icons
58
+ # (or `gem install game_icons`) to get & manipulate art from game-icons.net
59
+ # Nokogiri (already included in Squib) is also great for XML manipulation.
60
+
61
+ # WARNING! If you choose to use the SVG ID, the x-y coordinates are still
62
+ # relative to the SVG page. See this example in an SVG editor
63
+ svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
64
+
65
+ # Over 15 different blending operators are supported.
66
+ # See http://cairographics.org/operators
67
+ # Alpha transparency too
68
+ png file: 'ball.png', x: 50, y: 700
69
+ png file: 'grit.png', x: 70, y: 750, blend: :color_burn, alpha: 0.75
70
+
71
+ # Images can be rotated around their upper-left corner
72
+ png file: 'shiny-purse.png', x: 300, y: 700, angle: 0.0 # default (no rotate)
73
+ png file: 'shiny-purse.png', x: 300, y: 800, angle: Math::PI / 4
74
+ svg file: 'spanner.svg', x: 300, y: 900, angle: Math::PI / 2 - 0.1
75
+
76
+ # Images can also be used as masks instead of being directly painted.
77
+ # This is particularly useful for switching directly over to black-and-white for printing
78
+ # Or, if you want the same image to be used but with different colors/gradients
79
+ svg mask: '#00ff00',
80
+ file: 'glass-heart.svg',
81
+ x: 500, y: 600, width: 200, height: 200
82
+ svg mask: '(0,0)(0,500) #ccc@0.0 #333@1.0',
83
+ file: 'glass-heart.svg',
84
+ x: 500, y: 800, width: 200, height: 200
85
+
86
+ # Masks are based on the alpha channel, so this is just a magenta square
87
+ png mask: :magenta, file: 'shiny-purse.png',
88
+ x: 650, y: 950
89
+
90
+ # Note that this method does nothing, even though it would normally fill up
91
+ # the card. force_id: true looks to the id field to be non-empty to render.
92
+ # This is useful if you have multiple different icons in one SVG file,
93
+ # but sometimes want to use none.
94
+ # e.g. id: [:attack, :defend, nil]
95
+ svg file: 'spanner.svg', width: :deck, height: :deck,
96
+ force_id: true, id: '' # <-- the important part
97
+
98
+ save prefix: 'load_images_', format: :png
99
+ end
@@ -0,0 +1 @@
1
+ warn_png_scale: false
@@ -1,3 +1,3 @@
1
- Name,Qty
2
- Basilisk,3
1
+ Name,Qty
2
+ Basilisk,3
3
3
  High Templar,1
@@ -1,64 +1,64 @@
1
- require 'squib'
2
-
3
- data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
4
- 'type' => ['Thug', 'Thinker', 'Thinker'],
5
- 'level' => [1,2,3]}
6
-
7
- Squib::Deck.new(width: 825, height: 1125, cards: 3) do
8
- # Default range is :all
9
- background color: :white
10
- text str: data['name'], x: 250, y: 55, font: 'Arial 54'
11
- text str: data['level'], x: 65, y: 40, font: 'Arial 72'
12
-
13
- # Could be explicit about using :all, too
14
- text range: :all,
15
- str: data['type'], x: 40, y: 128, font: 'Arial 18',
16
- width: 100, align: :center
17
-
18
- # Ranges are inclusive, zero-based
19
- text range: 0..1, str: 'Thief and Grifter only!!', x: 25, y:200
20
-
21
- # Integers are also allowed
22
- text range: 0, str: 'Thief only!', x: 25, y: 250
23
-
24
- # Negatives go from the back of the deck
25
- text range: -1, str: 'Mastermind only!', x: 25, y: 250
26
- text range: -2..-1, str: 'Grifter and Mastermind only!', x: 25, y: 650
27
-
28
- # We can use Arrays too!
29
- text range: [0,2], str: 'Thief and Mastermind only!!', x: 25, y:300
30
-
31
- # Just about everything in Squib can be given an array that
32
- # corresponds to the deck's cards. This allows for each card to be styled differently
33
- # This renders three cards, with three strings that had three different colors at three different locations.
34
- text str: %w(red green blue),
35
- color: [:red, :green, :blue],
36
- x: [40, 80, 120],
37
- y: [700, 750, 800]
38
-
39
- # Useful idiom: construct a hash from card names back to its index (ID),
40
- # then use a range. No need to memorize IDs, and you can add cards easily
41
- id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
42
- text range: id['Thief']..id['Grifter'],
43
- str: 'Thief through Grifter with id lookup!!',
44
- x:25, y: 400
45
-
46
- # Useful idiom: generate arrays from a column called 'type'
47
- type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
48
- text range: type['Thinker'],
49
- str: 'Only for Thinkers!',
50
- x:25, y: 500
51
-
52
- # Useful idiom: draw a different number of images for different cards
53
- hearts = [nil, 1, 2] #i.e. card 0 has no hearts, card 2 has 2 hearts drawn
54
- 1.upto(2).each do |n|
55
- range = hearts.each_index.select { |i| hearts[i] == n}
56
- n.times do |i|
57
- svg file: 'glass-heart.svg', range: range,
58
- x: 150, y: 55 + i*42, width: 40, height: 40
59
- end
60
- end
61
-
62
- rect color: 'black' # just a border
63
- save_sheet prefix: 'ranges_', columns: 3
64
- end
1
+ require 'squib'
2
+
3
+ data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
4
+ 'type' => ['Thug', 'Thinker', 'Thinker'],
5
+ 'level' => [1,2,3]}
6
+
7
+ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
8
+ # Default range is :all
9
+ background color: :white
10
+ text str: data['name'], x: 250, y: 55, font: 'Arial 54'
11
+ text str: data['level'], x: 65, y: 40, font: 'Arial 72'
12
+
13
+ # Could be explicit about using :all, too
14
+ text range: :all,
15
+ str: data['type'], x: 40, y: 128, font: 'Arial 18',
16
+ width: 100, align: :center
17
+
18
+ # Ranges are inclusive, zero-based
19
+ text range: 0..1, str: 'Thief and Grifter only!!', x: 25, y:200
20
+
21
+ # Integers are also allowed
22
+ text range: 0, str: 'Thief only!', x: 25, y: 250
23
+
24
+ # Negatives go from the back of the deck
25
+ text range: -1, str: 'Mastermind only!', x: 25, y: 250
26
+ text range: -2..-1, str: 'Grifter and Mastermind only!', x: 25, y: 650
27
+
28
+ # We can use Arrays too!
29
+ text range: [0,2], str: 'Thief and Mastermind only!!', x: 25, y:300
30
+
31
+ # Just about everything in Squib can be given an array that
32
+ # corresponds to the deck's cards. This allows for each card to be styled differently
33
+ # This renders three cards, with three strings that had three different colors at three different locations.
34
+ text str: %w(red green blue),
35
+ color: [:red, :green, :blue],
36
+ x: [40, 80, 120],
37
+ y: [700, 750, 800]
38
+
39
+ # Useful idiom: construct a hash from card names back to its index (ID),
40
+ # then use a range. No need to memorize IDs, and you can add cards easily
41
+ id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
42
+ text range: id['Thief']..id['Grifter'],
43
+ str: 'Thief through Grifter with id lookup!!',
44
+ x:25, y: 400
45
+
46
+ # Useful idiom: generate arrays from a column called 'type'
47
+ type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
48
+ text range: type['Thinker'],
49
+ str: 'Only for Thinkers!',
50
+ x:25, y: 500
51
+
52
+ # Useful idiom: draw a different number of images for different cards
53
+ hearts = [nil, 1, 2] #i.e. card 0 has no hearts, card 2 has 2 hearts drawn
54
+ 1.upto(2).each do |n|
55
+ range = hearts.each_index.select { |i| hearts[i] == n}
56
+ n.times do |i|
57
+ svg file: 'glass-heart.svg', range: range,
58
+ x: 150, y: 55 + i*42, width: 40, height: 40
59
+ end
60
+ end
61
+
62
+ rect color: 'black' # just a border
63
+ save_sheet prefix: 'ranges_', columns: 3
64
+ end
@@ -1,3 +1,3 @@
1
- Type,"Level"
2
- Thief,1
1
+ Type,"Level"
2
+ Thief,1
3
3
  Mastermind,2
@@ -4,10 +4,18 @@ require 'squib'
4
4
 
5
5
  Squib::Deck.new(width: 825, height: 1125, cards: 16) do
6
6
  background color: :gray
7
- rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
7
+ rect x: 38, y: 38, width: 750, height: 1050,
8
+ x_radius: 38, y_radius: 38, stroke: 3.0, dash: '4 4'
8
9
 
9
10
  text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 54'
10
11
 
12
+ # Here's what a regular save_png looks like for just the first card
13
+ save_png range: 0, prefix: 'save_png_'
14
+
15
+ # save_png supports trim and trim_radius
16
+ save_png trim: 30, trim_radius: 38,
17
+ range: 0, prefix: 'save_png_trimmed_'
18
+
11
19
  # Place on multiple pages over the PDF, with bleed beeing trimmed off
12
20
  save_pdf file: 'save-pdf.pdf', margin: 75, gap: 5, trim: 37
13
21
 
Binary file
@@ -0,0 +1,46 @@
1
+ require 'squib'
2
+ require 'squib/sample_helpers'
3
+
4
+ Squib::Deck.new(width: 1000, height: 2000) do
5
+ draw_graph_paper width, height
6
+
7
+ sample 'Font strings are quite expressive. Specify family, modifiers, then size. Font names with spaces in them should also have a backup afterward to help with parsing.' do |x, y|
8
+ text font: 'Arial bold italic 32', str: 'Bold and italic!', x: x, y: y - 50
9
+ text font: 'Arial weight=300 32', str: 'Light bold!', x: x, y: y
10
+ text font: 'Times New Roman,Arial 32', str: 'Times New Roman', x: x, y: y + 50
11
+ end
12
+
13
+ sample 'Specify width and height to see a text box. Also: set "hint" to see the extents of your text box' do |x, y|
14
+ text str: 'This has fixed width and height.', x: x, y: y,
15
+ hint: :red, width: 300, height: 100, font: 'Serif bold 24'
16
+ end
17
+
18
+ sample 'If you specify the width only, the text will ellipsize.' do |x, y|
19
+ text str: 'The meaning of life is 42', x: x - 50, y: y,
20
+ hint: :red, width: 350, font: 'Serif bold 22'
21
+ end
22
+
23
+ sample 'If you specify the width only, and turn off ellipsize, the height will auto-stretch.' do |x, y|
24
+ text str: 'This has fixed width, but not fixed height.', x: x, y: y,
25
+ hint: :red, width: 300, ellipsize: false, font: 'Serif bold 24'
26
+ end
27
+
28
+ sample 'The text method returns the ink extents of each card\'s rendered text. So you can custom-fit a shape around it.' do |x, y|
29
+ ['Auto fit!', 'Auto fit!!!!' ].each.with_index do |str, i|
30
+ text_y = y + i * 50
31
+ extents = text str: str, x: x, y: text_y, font: 'Sans Bold 24'
32
+
33
+ # Extents come back as an array of hashes, which can get split out like this
34
+ text_width = extents[0][:width]
35
+ text_height = extents[0][:height]
36
+ rect x: x, y: text_y, width: text_width, height: text_height, radius: 10,
37
+ stroke_color: :purple, stroke_width: 3
38
+ end
39
+ end
40
+
41
+ sample 'Text can be rotated about the upper-left corner of the text box. Unit is in radians.' do |x, y|
42
+ text str: 'Rotated', hint: :red, x: x, y: y, angle: Math::PI / 6
43
+ end
44
+
45
+ save_png prefix: '_text_', dir: '.'
46
+ end