squib 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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,90 +1,108 @@
1
- require 'squib/args/card_range'
2
- require 'squib/args/paint'
3
- require 'squib/args/scale_box'
4
- require 'squib/args/transform'
5
- require 'squib/args/input_file'
6
- require 'squib/args/svg_special'
7
-
8
- module Squib
9
- class Deck
10
-
11
- # Renders a png file at the given location.
12
- #
13
- # See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
14
- # @example
15
- # png file: 'img.png', x: 50, y: 50
16
- #
17
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
18
- # @option opts file [String] ((empty)) file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
19
- # @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
20
- # @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
21
- # @option opts width [Integer, :native, :scale, :deck] (:native) the pixel width that the image should scale to. :deck will scale to the deck width. :scale will use the height to scale and keep native the aspect ratio. Scaling PNGs is not recommended for professional-looking cards. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
22
- # @option opts height [Integer, :native, :scale, :deck] (:native) the pixel width that the image should scale to. :deck will scale to the deck height. :scale will use the width to scale and keep native the aspect ratio. Scaling PNGs is not recommended for professional-looking cards. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
23
- # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
24
- # @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
25
- # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
26
- # @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
27
- # @option opts mask [String] (nil) If specified, the image will be used as a mask for the given color/gradient. Transparent pixels are ignored, opaque pixels are the given color. Note: the origin for gradient coordinates is at the given x,y, not at 0,0 as it is most other places.
28
- # @return [nil] Returns nil
29
- # @api public
30
- def png(opts = {})
31
- Dir.chdir(img_dir) do
32
- range = Args::CardRange.new(opts[:range], deck_size: size)
33
- paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
34
- box = Args::ScaleBox.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
35
- trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
36
- ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
37
- @progress_bar.start('Loading PNG(s)', range.size) do |bar|
38
- range.each do |i|
39
- @cards[i].png(ifile[i].file, box[i], paint[i], trans[i])
40
- bar.increment
41
- end
42
- end
43
- end
44
- end
45
-
46
- # Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height. If neither data nor file are specified for a given card, this method does nothing.
47
- #
48
- # See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
49
- #
50
- # Note: if alpha transparency is desired, set that in the SVG.
51
- #
52
- # @example
53
- # svg range: 1..2, file: 'icon.svg', id: '#stone', x: 50, y:50
54
- #
55
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
56
- # @option opts file [String] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
57
- # @option opts data [String] (nil) render from an SVG XML string. Overrides file if both are specified (a warning is shown) . If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}.
58
- # @option opts id [String] (nil) if set, then only render the SVG element with the given id. Prefix '#' is optional. Note: the x-y coordinates are still relative to the SVG document's page. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
59
- # @option opts force_id [Boolean] (false) if set, then this svg will not be rendered at all if the id is empty or nil. If not set, the entire SVG is rendered. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
60
- # @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
61
- # @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
62
- # @option opts width [Integer] (:native) the pixel width that the image should scale to. :deck will scale to the deck height. :scale will use the width to scale and keep native the aspect ratio. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
63
- # @option opts height [Integer] (:native) the pixel width that the image should scale to. :deck will scale to the deck height. :scale will use the width to scale and keep native the aspect ratio. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
64
- # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
65
- # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
66
- # @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
67
- # @option opts mask [String] (nil) If specified, the image will be used as a mask for the given color/gradient. Transparent pixels are ignored, opaque pixels are the given color. Note: the origin for gradient coordinates is at the given x,y, not at 0,0 as it is most other places.
68
- # @return [nil] Returns nil
69
- # @api public
70
- def svg(opts = {})
71
- Dir.chdir(img_dir) do
72
- range = Args::CardRange.new(opts[:range], deck_size: size)
73
- paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
74
- box = Args::ScaleBox.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
75
- trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
76
- ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
77
- svg_args = Args::SvgSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
78
- @progress_bar.start('Loading SVG(s)', range.size) do |bar|
79
- range.each do |i|
80
- if svg_args.render?(i)
81
- @cards[i].svg(ifile[i].file, svg_args[i], box[i], paint[i], trans[i])
82
- end
83
- bar.increment
84
- end
85
- end
86
- end
87
- end
88
-
89
- end
90
- end
1
+ require 'squib/args/card_range'
2
+ require 'squib/args/paint'
3
+ require 'squib/args/scale_box'
4
+ require 'squib/args/transform'
5
+ require 'squib/args/input_file'
6
+ require 'squib/args/svg_special'
7
+
8
+ module Squib
9
+ class Deck
10
+
11
+ # Renders a png file at the given location.
12
+ #
13
+ # See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
14
+ # @example
15
+ # png file: 'img.png', x: 50, y: 50
16
+ #
17
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
18
+ # @option opts file [String] ((empty)) file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
19
+ # @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
20
+ # @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
21
+ # @option opts width [Integer, :native, :scale, :deck] (:native) the pixel width that the image should scale to. :deck will scale to the deck width. :scale will use the height to scale and keep native the aspect ratio. Scaling PNGs is not recommended for professional-looking cards. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
22
+ # @option opts height [Integer, :native, :scale, :deck] (:native) the pixel width that the image should scale to. :deck will scale to the deck height. :scale will use the width to scale and keep native the aspect ratio. Scaling PNGs is not recommended for professional-looking cards. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
23
+ # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
24
+ # @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
25
+ # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
26
+ # @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
27
+ # @option opts mask [String] (nil) If specified, the image will be used as a mask for the given color/gradient. Transparent pixels are ignored, opaque pixels are the given color. Note: the origin for gradient coordinates is at the given x,y, not at 0,0 as it is most other places.
28
+ # @option opts crop_x [Integer] (0) Crop the loaded image at this x coordinate. Supports Unit Conversion, see {file:README.md#Units Units}.
29
+ # @option opts crop_y [Integer] (0) Crop the loaded image at this y coordinate. Supports Unit Conversion, see {file:README.md#Units Units}.
30
+ # @option opts crop_corner_radius [Integer] (0): Radius for rounded corners, both x and y. When set, overrides crop_corner_x_radius and crop_corner_y_radius. Supports Unit Conversion, see {file:README.md#Units Units}.
31
+ # @option opts crop_corner_x_radius [Integer] (0): x radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
32
+ # @option opts crop_corner_y_radius [Integer] (0): y radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
33
+ # @option opts crop_width [Integer] (:native): Width of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
34
+ # @option opts crop_height [Integer] (:native): Height of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
35
+ # @option opts flip_horiztonal [Boolean] (false): Flip this image about its center horizontally (i.e. left becomes right and vice versa).
36
+ # @option opts flip_vertical [Boolean] (false): Flip this image about its center verticall (i.e. top becomes bottom and vice versa).
37
+ # @return [nil] Returns nil
38
+ # @api public
39
+ def png(opts = {})
40
+ Dir.chdir(img_dir) do
41
+ range = Args::CardRange.new(opts[:range], deck_size: size)
42
+ paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
43
+ box = Args::ScaleBox.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
44
+ trans = Args::Transform.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
45
+ ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
46
+ @progress_bar.start('Loading PNG(s)', range.size) do |bar|
47
+ range.each do |i|
48
+ @cards[i].png(ifile[i].file, box[i], paint[i], trans[i])
49
+ bar.increment
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ # Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height. If neither data nor file are specified for a given card, this method does nothing.
56
+ #
57
+ # See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
58
+ #
59
+ # Note: if alpha transparency is desired, set that in the SVG.
60
+ #
61
+ # @example
62
+ # svg range: 1..2, file: 'icon.svg', id: '#stone', x: 50, y:50
63
+ #
64
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
65
+ # @option opts file [String] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
66
+ # @option opts data [String] (nil) render from an SVG XML string. Overrides file if both are specified (a warning is shown) . If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}.
67
+ # @option opts id [String] (nil) if set, then only render the SVG element with the given id. Prefix '#' is optional. Note: the x-y coordinates are still relative to the SVG document's page. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
68
+ # @option opts force_id [Boolean] (false) if set, then this svg will not be rendered at all if the id is empty or nil. If not set, the entire SVG is rendered. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
69
+ # @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
70
+ # @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
71
+ # @option opts width [Integer] (:native) the pixel width that the image should scale to. :deck will scale to the deck height. :scale will use the width to scale and keep native the aspect ratio. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
72
+ # @option opts height [Integer] (:native) the pixel width that the image should scale to. :deck will scale to the deck height. :scale will use the width to scale and keep native the aspect ratio. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
73
+ # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
74
+ # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
75
+ # @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
76
+ # @option opts mask [String] (nil) If specified, the image will be used as a mask for the given color/gradient. Transparent pixels are ignored, opaque pixels are the given color. Note: the origin for gradient coordinates is at the given x,y, not at 0,0 as it is most other places.
77
+ # @option opts crop_x [Integer] (0) Crop the loaded image at this x coordinate. Supports Unit Conversion, see {file:README.md#Units Units}.
78
+ # @option opts crop_y [Integer] (0) Crop the loaded image at this y coordinate. Supports Unit Conversion, see {file:README.md#Units Units}.
79
+ # @option opts crop_corner_radius [Integer] (0): Radius for rounded corners, both x and y. When set, overrides crop_corner_x_radius and crop_corner_y_radius. Supports Unit Conversion, see {file:README.md#Units Units}.
80
+ # @option opts crop_corner_x_radius [Integer] (0): x radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
81
+ # @option opts crop_corner_y_radius [Integer] (0): y radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
82
+ # @option opts crop_width [Integer] (:native): Width of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
83
+ # @option opts crop_height [Integer] (:native): Height of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
84
+ # @option opts flip_horiztonal [Boolean] (false): Flip this image about its center horizontally (i.e. left becomes right and vice versa).
85
+ # @option opts flip_vertical [Boolean] (false): Flip this image about its center verticall (i.e. top becomes bottom and vice versa).
86
+ # @return [nil] Returns nil
87
+ # @api public
88
+ def svg(opts = {})
89
+ Dir.chdir(img_dir) do
90
+ range = Args::CardRange.new(opts[:range], deck_size: size)
91
+ paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
92
+ box = Args::ScaleBox.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
93
+ trans = Args::Transform.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
94
+ ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
95
+ svg_args = Args::SvgSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
96
+ @progress_bar.start('Loading SVG(s)', range.size) do |bar|
97
+ range.each do |i|
98
+ if svg_args.render?(i)
99
+ @cards[i].svg(ifile[i].file, svg_args[i], box[i], paint[i], trans[i])
100
+ end
101
+ bar.increment
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -1,149 +1,151 @@
1
- require 'squib/args/card_range'
2
- require 'squib/args/hand_special'
3
- require 'squib/args/save_batch'
4
- require 'squib/args/sheet'
5
- require 'squib/args/showcase_special'
6
-
7
- module Squib
8
- class Deck
9
-
10
- # Saves the given range of cards to either PNG or PDF
11
- #
12
- #
13
- # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
14
- # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
15
- # @option opts [Symbol] format (:png) the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]`
16
- # @option opts [String] prefix (card_) the prefix of the file name to be printed
17
- # @option opts [Boolean] rotate (false) PNG saving only. If true, the saved cards will be rotated 90 degrees clockwise. Intended to rendering landscape instead of portrait.
18
- # @return self
19
- # @api public
20
- def save(opts = {})
21
- save_png(opts) if Array(opts[:format]).include? :png
22
- save_pdf(opts) if Array(opts[:format]).include? :pdf
23
- self
24
- end
25
-
26
- # Lays out the cards in range and renders a PDF
27
- #
28
- # @example
29
- # save_pdf file: 'deck.pdf', margin: 75, gap: 5, trim: 37
30
- #
31
- # @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files}
32
- # @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
33
- # @option opts width [Integer] (3300) the height of the page in pixels. Default is 11in * 300dpi. Supports unit conversion.
34
- # @option opts height [Integer] (2550) the height of the page in pixels. Default is 8.5in * 300dpi. Supports unit conversion.
35
- # @option opts margin [Integer] (75) the margin around the outside of the page. Supports unit conversion.
36
- # @option opts gap [Integer] (0) the space in pixels between the cards. Supports unit conversion.
37
- # @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports unit conversion.
38
- # @return [nil]
39
- # @api public
40
- def save_pdf(opts = {})
41
- range = Args::CardRange.new(opts[:range], deck_size: size)
42
- sheet = Args::Sheet.new(custom_colors, {file: 'output.pdf'}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
43
- render_pdf(range, sheet)
44
- end
45
-
46
- # Saves the given range of cards to a PNG
47
- #
48
- # @example
49
- # save range: 1..8, dir: '_pnp', prefix: 'bw_'
50
- #
51
- # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
52
- #
53
- # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
54
- # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
55
- # @option opts [String] prefix (card_) the prefix of the file name to be printed.
56
- # @option opts [String] count_format (%02d) the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for Kernel::sprintf for specifics)
57
- # @option opts [Boolean, :clockwise, :counterclockwise] rotate (false) if true, the saved cards will be rotated 90 degrees clockwise. Or, rotate by the number of radians. Intended to rendering landscape instead of portrait.
58
- # @return [nil] Returns nothing
59
- # @api public
60
- def save_png(opts = {})
61
- range = Args::CardRange.new(opts[:range], deck_size: size)
62
- batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
63
- @progress_bar.start("Saving PNGs to #{batch.summary}", size) do |bar|
64
- range.each do |i|
65
- @cards[i].save_png(batch[i])
66
- bar.increment
67
- end
68
- end
69
- end
70
-
71
- # Lays out the cards in range and renders a stitched PNG sheet
72
- #
73
- # @example
74
- # save_sheet prefix: 'sheet_', margin: 75, gap: 5, trim: 37
75
- #
76
- # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
77
- # @option opts columns [Integer] (5) the number of columns in the grid. Must be an integer
78
- # @option opts rows [Integer] (:infinite) the number of rows in the grid. When set to :infinite, the sheet scales to the rows needed. If there are more cards than rows*columns, new sheets are started.
79
- # @option opts [String] prefix (card_) the prefix of the file name(s)
80
- # @option opts [String] count_format (%02d) the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for Kernel::sprintf for specifics)
81
- # @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
82
- # @option opts margin [Integer] (0) the margin around the outside of the sheet.
83
- # @option opts gap [Integer] (0) the space in pixels between the cards
84
- # @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
85
- # @return [nil]
86
- # @api public
87
- def save_sheet(opts = {})
88
- range = Args::CardRange.new(opts[:range], deck_size: size)
89
- batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
90
- sheet = Args::Sheet.new(custom_colors, {margin: 0}, size).load!(opts, expand_by: size, layout: layout, dpi: dpi)
91
- render_sheet(range, batch, sheet)
92
- end
93
-
94
- # Renders a range of cards in a showcase as if they are sitting in 3D on a reflective surface
95
- # See {file:samples/showcase.rb} for full example
96
- #
97
- # @example
98
- # showcase file: 'showcase_output.png', trim: 78, trim_radius: 32
99
- #
100
- # @option opts [Enumerable, :all] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
101
- # @option opts [Fixnum] trim (0) the margin around the card to trim before putting into the showcase
102
- # @option opts [Fixnum] trim_radius (38) the rounded rectangle radius around the card to trim before putting into the showcase
103
- # @option opts [Fixnum] margin (75) the margin around the entire showcase
104
- # @option opts [Fixnum] scale (0.8) percentage of original width of each (trimmed) card to scale to. Must be between 0.0 and 1.0, but starts looking bad around 0.6.
105
- # @option opts [Fixnum] offset (1.1) percentage of the scaled width of each card to shift each offset. e.g. 1.1 is a 10% shift, and 0.95 is overlapping by 5%
106
- # @option opts [String, Color] fill_color (:white) backdrop color. Usually black or white. Supports gradients.
107
- # @option opts [Fixnum] reflect_offset (15) the number of pixels between the bottom of the card and the reflection. Supports Unit Conversion, see {file:README.md#Units Units}.
108
- # @option opts [Fixnum] reflect_strength (0.2) the starting alpha transparency of the reflection (at the top of the card). Percentage between 0 and 1. Looks more realistic at low values since even shiny surfaces lose a lot of light.
109
- # @option opts [Fixnum] reflect_percent (0.25) the length of the reflection in percentage of the card. Larger values tend to make the reflection draw just as much attention as the card, which is not good.
110
- # @option opts [:left, :right] face (:left) which direction the cards face. Anything but `:right` will face left
111
- # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
112
- # @option opts [String] file ('showcase.png') the file to save in dir. Will be overwritten.
113
- # @return [nil] Returns nothing.
114
- # @api public
115
- def showcase(opts = {})
116
- range = Args::CardRange.new(opts[:range], deck_size: size)
117
- showcase = Args::ShowcaseSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
118
- sheet = Args::Sheet.new(custom_colors, {file: 'showcase.png'}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
119
- render_showcase(range, sheet, showcase)
120
- end
121
-
122
- # Renders a range of cards fanned out as if in a hand. Saves as PNG.
123
- # See {file:samples/hand.rb} for full example
124
- #
125
- # @example
126
- # hand range: :all, radius: :auto, margin: 20, fill_color: :white,
127
- # angle_range: (Math::PI / -4.0)..(Math::PI / 2),
128
- # dir: '_output', file: 'hand1.png'
129
- #
130
- # @option opts [Enumerable, :all] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
131
- # @option opts [Fixnum] radius (:auto) the distance from the bottom of each card to the center of the fan. If set to `:auto`, then it is computed as 30% of the card's height.
132
- # @option opts [Range] angle_range: ((Math::PI / -4.0)..(Math::PI / 2)). The overall width of the fan, in radians. Angle of zero is a vertical card. Further negative angles widen the fan counter-clockwise and positive angles widen the fan clockwise.
133
- # @option opts [Fixnum] trim (0) the margin around the card to trim before putting into the image
134
- # @option opts [Fixnum] trim_radius (0) the rounded rectangle radius around the card to trim before putting into the showcase
135
- # @option opts [Fixnum] margin (75) the margin around the entire image
136
- # @option opts [String, Color] fill_color (:white) backdrop color. Usually black or white. Supports gradients.
137
- # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
138
- # @option opts [String] file ('hand.png') the file to save in dir. Will be overwritten.
139
- # @return [nil] Returns nothing.
140
- # @api public
141
- def hand(opts = {})
142
- range = Args::CardRange.new(opts[:range], deck_size: size)
143
- hand = Args::HandSpecial.new(height).load!(opts, expand_by: size, layout: layout, dpi: dpi)
144
- sheet = Args::Sheet.new(custom_colors, {file: 'hand.png', trim_radius: 0}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
145
- render_hand(range, sheet, hand)
146
- end
147
-
148
- end
149
- end
1
+ require 'squib/args/card_range'
2
+ require 'squib/args/hand_special'
3
+ require 'squib/args/save_batch'
4
+ require 'squib/args/sheet'
5
+ require 'squib/args/showcase_special'
6
+
7
+ module Squib
8
+ class Deck
9
+
10
+ # Saves the given range of cards to either PNG or PDF
11
+ #
12
+ #
13
+ # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
14
+ # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
15
+ # @option opts [Symbol] format (:png) the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]`
16
+ # @option opts [String] prefix (card_) the prefix of the file name to be printed
17
+ # @option opts [Boolean] rotate (false) PNG saving only. If true, the saved cards will be rotated 90 degrees clockwise. Intended to rendering landscape instead of portrait.
18
+ # @return self
19
+ # @api public
20
+ def save(opts = {})
21
+ save_png(opts) if Array(opts[:format]).include? :png
22
+ save_pdf(opts) if Array(opts[:format]).include? :pdf
23
+ self
24
+ end
25
+
26
+ # Lays out the cards in range and renders a PDF
27
+ #
28
+ # @example
29
+ # save_pdf file: 'deck.pdf', margin: 75, gap: 5, trim: 37
30
+ #
31
+ # @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files}
32
+ # @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
33
+ # @option opts width [Integer] (3300) the height of the page in pixels. Default is 11in * 300dpi. Supports unit conversion.
34
+ # @option opts height [Integer] (2550) the height of the page in pixels. Default is 8.5in * 300dpi. Supports unit conversion.
35
+ # @option opts margin [Integer] (75) the margin around the outside of the page. Supports unit conversion.
36
+ # @option opts gap [Integer] (0) the space in pixels between the cards. Supports unit conversion.
37
+ # @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports unit conversion.
38
+ # @return [nil]
39
+ # @api public
40
+ def save_pdf(opts = {})
41
+ range = Args::CardRange.new(opts[:range], deck_size: size)
42
+ sheet = Args::Sheet.new(custom_colors, {file: 'output.pdf'}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
43
+ render_pdf(range, sheet)
44
+ end
45
+
46
+ # Saves the given range of cards to a PNG
47
+ #
48
+ # @example
49
+ # save range: 1..8, dir: '_pnp', prefix: 'bw_'
50
+ #
51
+ # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
52
+ #
53
+ # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
54
+ # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
55
+ # @option opts [String] prefix (card_) the prefix of the file name to be printed.
56
+ # @option opts [String] count_format (%02d) the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for Kernel::sprintf for specifics)
57
+ # @option opts [Boolean, :clockwise, :counterclockwise] rotate (false) if true, the saved cards will be rotated 90 degrees clockwise. Or, rotate by the number of radians. Intended to rendering landscape instead of portrait.
58
+ # @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports unit conversion.
59
+ # @option opts trim_radius [Integer] (38) the rounded rectangle radius around the card to trim before putting into the showcase
60
+ # @return [nil] Returns nothing
61
+ # @api public
62
+ def save_png(opts = {})
63
+ range = Args::CardRange.new(opts[:range], deck_size: size)
64
+ batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
65
+ @progress_bar.start("Saving PNGs to #{batch.summary}", size) do |bar|
66
+ range.each do |i|
67
+ @cards[i].save_png(batch[i])
68
+ bar.increment
69
+ end
70
+ end
71
+ end
72
+
73
+ # Lays out the cards in range and renders a stitched PNG sheet
74
+ #
75
+ # @example
76
+ # save_sheet prefix: 'sheet_', margin: 75, gap: 5, trim: 37
77
+ #
78
+ # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
79
+ # @option opts columns [Integer] (5) the number of columns in the grid. Must be an integer
80
+ # @option opts rows [Integer] (:infinite) the number of rows in the grid. When set to :infinite, the sheet scales to the rows needed. If there are more cards than rows*columns, new sheets are started.
81
+ # @option opts [String] prefix (card_) the prefix of the file name(s)
82
+ # @option opts [String] count_format (%02d) the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for Kernel::sprintf for specifics)
83
+ # @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
84
+ # @option opts margin [Integer] (0) the margin around the outside of the sheet.
85
+ # @option opts gap [Integer] (0) the space in pixels between the cards
86
+ # @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
87
+ # @return [nil]
88
+ # @api public
89
+ def save_sheet(opts = {})
90
+ range = Args::CardRange.new(opts[:range], deck_size: size)
91
+ batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
92
+ sheet = Args::Sheet.new(custom_colors, {margin: 0}, size).load!(opts, expand_by: size, layout: layout, dpi: dpi)
93
+ render_sheet(range, batch, sheet)
94
+ end
95
+
96
+ # Renders a range of cards in a showcase as if they are sitting in 3D on a reflective surface
97
+ # See {file:samples/showcase.rb} for full example
98
+ #
99
+ # @example
100
+ # showcase file: 'showcase_output.png', trim: 78, trim_radius: 32
101
+ #
102
+ # @option opts [Enumerable, :all] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
103
+ # @option opts [Fixnum] trim (0) the margin around the card to trim before putting into the showcase
104
+ # @option opts [Fixnum] trim_radius (38) the rounded rectangle radius around the card to trim before putting into the showcase
105
+ # @option opts [Fixnum] margin (75) the margin around the entire showcase
106
+ # @option opts [Fixnum] scale (0.8) percentage of original width of each (trimmed) card to scale to. Must be between 0.0 and 1.0, but starts looking bad around 0.6.
107
+ # @option opts [Fixnum] offset (1.1) percentage of the scaled width of each card to shift each offset. e.g. 1.1 is a 10% shift, and 0.95 is overlapping by 5%
108
+ # @option opts [String, Color] fill_color (:white) backdrop color. Usually black or white. Supports gradients.
109
+ # @option opts [Fixnum] reflect_offset (15) the number of pixels between the bottom of the card and the reflection. Supports Unit Conversion, see {file:README.md#Units Units}.
110
+ # @option opts [Fixnum] reflect_strength (0.2) the starting alpha transparency of the reflection (at the top of the card). Percentage between 0 and 1. Looks more realistic at low values since even shiny surfaces lose a lot of light.
111
+ # @option opts [Fixnum] reflect_percent (0.25) the length of the reflection in percentage of the card. Larger values tend to make the reflection draw just as much attention as the card, which is not good.
112
+ # @option opts [:left, :right] face (:left) which direction the cards face. Anything but `:right` will face left
113
+ # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
114
+ # @option opts [String] file ('showcase.png') the file to save in dir. Will be overwritten.
115
+ # @return [nil] Returns nothing.
116
+ # @api public
117
+ def showcase(opts = {})
118
+ range = Args::CardRange.new(opts[:range], deck_size: size)
119
+ showcase = Args::ShowcaseSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
120
+ sheet = Args::Sheet.new(custom_colors, {file: 'showcase.png'}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
121
+ render_showcase(range, sheet, showcase)
122
+ end
123
+
124
+ # Renders a range of cards fanned out as if in a hand. Saves as PNG.
125
+ # See {file:samples/hand.rb} for full example
126
+ #
127
+ # @example
128
+ # hand range: :all, radius: :auto, margin: 20, fill_color: :white,
129
+ # angle_range: (Math::PI / -4.0)..(Math::PI / 2),
130
+ # dir: '_output', file: 'hand1.png'
131
+ #
132
+ # @option opts [Enumerable, :all] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
133
+ # @option opts [Fixnum] radius (:auto) the distance from the bottom of each card to the center of the fan. If set to `:auto`, then it is computed as 30% of the card's height.
134
+ # @option opts [Range] angle_range: ((Math::PI / -4.0)..(Math::PI / 2)). The overall width of the fan, in radians. Angle of zero is a vertical card. Further negative angles widen the fan counter-clockwise and positive angles widen the fan clockwise.
135
+ # @option opts [Fixnum] trim (0) the margin around the card to trim before putting into the image
136
+ # @option opts [Fixnum] trim_radius (0) the rounded rectangle radius around the card to trim before putting into the showcase
137
+ # @option opts [Fixnum] margin (75) the margin around the entire image
138
+ # @option opts [String, Color] fill_color (:white) backdrop color. Usually black or white. Supports gradients.
139
+ # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
140
+ # @option opts [String] file ('hand.png') the file to save in dir. Will be overwritten.
141
+ # @return [nil] Returns nothing.
142
+ # @api public
143
+ def hand(opts = {})
144
+ range = Args::CardRange.new(opts[:range], deck_size: size)
145
+ hand = Args::HandSpecial.new(height).load!(opts, expand_by: size, layout: layout, dpi: dpi)
146
+ sheet = Args::Sheet.new(custom_colors, {file: 'hand.png', trim_radius: 0}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
147
+ render_hand(range, sheet, hand)
148
+ end
149
+
150
+ end
151
+ end