squib 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +162 -133
- data/Gemfile +4 -4
- data/README.md +630 -550
- data/RELEASE TODO.md +18 -18
- data/Rakefile +99 -99
- data/lib/squib.rb +32 -32
- data/lib/squib/api/background.rb +20 -19
- data/lib/squib/api/data.rb +100 -99
- data/lib/squib/api/image.rb +90 -76
- data/lib/squib/api/save.rb +149 -103
- data/lib/squib/api/settings.rb +35 -37
- data/lib/squib/api/shapes.rb +230 -228
- data/lib/squib/api/text.rb +65 -66
- data/lib/squib/api/text_embed.rb +96 -66
- data/lib/squib/args/arg_loader.rb +138 -0
- data/lib/squib/args/box.rb +55 -0
- data/lib/squib/args/card_range.rb +32 -0
- data/lib/squib/args/color_validator.rb +12 -0
- data/lib/squib/args/coords.rb +33 -0
- data/lib/squib/args/dir_validator.rb +16 -0
- data/lib/squib/args/draw.rb +92 -0
- data/lib/squib/args/embed_adjust.rb +25 -0
- data/lib/squib/args/embed_key.rb +17 -0
- data/lib/squib/args/hand_special.rb +37 -0
- data/lib/squib/args/input_file.rb +37 -0
- data/lib/squib/args/paint.rb +44 -0
- data/lib/squib/args/paragraph.rb +115 -0
- data/lib/squib/args/save_batch.rb +60 -0
- data/lib/squib/args/scale_box.rb +53 -0
- data/lib/squib/args/sheet.rb +72 -0
- data/lib/squib/args/showcase_special.rb +38 -0
- data/lib/squib/args/svg_special.rb +37 -0
- data/lib/squib/args/transform.rb +25 -0
- data/lib/squib/args/typographer.rb +117 -117
- data/lib/squib/card.rb +67 -67
- data/lib/squib/conf.rb +117 -111
- data/lib/squib/constants.rb +178 -178
- data/lib/squib/deck.rb +113 -111
- data/lib/squib/graphics/cairo_context_wrapper.rb +99 -53
- data/lib/squib/graphics/gradient_regex.rb +46 -46
- data/lib/squib/graphics/hand.rb +42 -43
- data/lib/squib/graphics/image.rb +76 -73
- data/lib/squib/graphics/save_doc.rb +103 -137
- data/lib/squib/graphics/save_images.rb +33 -33
- data/lib/squib/graphics/shapes.rb +119 -152
- data/lib/squib/graphics/showcase.rb +85 -88
- data/lib/squib/graphics/text.rb +176 -216
- data/lib/squib/layout_parser.rb +91 -89
- data/lib/squib/layouts/economy.yml +85 -0
- data/lib/squib/layouts/fantasy.yml +101 -0
- data/lib/squib/layouts/hand.yml +62 -46
- data/lib/squib/layouts/playing-card.yml +35 -18
- data/lib/squib/project_template/config.yml +45 -40
- data/lib/squib/version.rb +10 -10
- data/samples/color_shortcuts.rb +6 -0
- data/samples/csv_import.rb +18 -18
- data/samples/custom-config.yml +5 -5
- data/samples/custom_config.rb +18 -18
- data/samples/draw_shapes.rb +45 -35
- data/samples/embed_text.rb +88 -90
- data/samples/hand.rb +24 -24
- data/samples/layouts.rb +62 -61
- data/samples/layouts_builtin.rb +51 -0
- data/samples/load_images.rb +78 -64
- data/samples/ranges.rb +64 -53
- data/samples/sample.csv +2 -2
- data/samples/text_options.rb +102 -94
- data/spec/api/api_data_spec.rb +57 -50
- data/spec/api/api_settings_spec.rb +37 -17
- data/spec/args/box_spec.rb +127 -0
- data/spec/args/draw_spec.rb +95 -0
- data/spec/args/embed_key_spec.rb +13 -0
- data/spec/args/input_file_spec.rb +21 -0
- data/spec/args/paint_spec.rb +22 -0
- data/spec/args/paragraph_spec.rb +153 -0
- data/spec/args/range_spec.rb +36 -0
- data/spec/args/save_batch_spec.rb +51 -0
- data/spec/args/scale_box_spec.rb +71 -0
- data/spec/args/sheet_spec.rb +58 -0
- data/spec/args/showcase_special_spec.rb +15 -0
- data/spec/data/samples/autoscale_font.rb.txt +84 -87
- data/spec/data/samples/basic.rb.txt +209 -203
- data/spec/data/samples/cairo_access.rb.txt +2 -2
- data/spec/data/samples/config_text_markup.rb.txt +72 -75
- data/spec/data/samples/csv_import.rb.txt +76 -80
- data/spec/data/samples/custom_config.rb.txt +48 -49
- data/spec/data/samples/draw_shapes.rb.txt +100 -42
- data/spec/data/samples/embed_text.rb.txt +283 -295
- data/spec/data/samples/excel.rb.txt +162 -171
- data/spec/data/samples/gradients.rb.txt +79 -67
- data/spec/data/samples/hand.rb.txt +538 -514
- data/spec/data/samples/hello_world.rb.txt +36 -38
- data/spec/data/samples/load_images.rb.txt +41 -5
- data/spec/data/samples/portrait-landscape.rb.txt +49 -51
- data/spec/data/samples/ranges.rb.txt +460 -429
- data/spec/data/samples/saves.rb.txt +801 -785
- data/spec/data/samples/showcase.rb.txt +5910 -5906
- data/spec/data/samples/text_options.rb.txt +1125 -981
- data/spec/data/samples/tgc_proofs.rb.txt +81 -79
- data/spec/data/samples/units.rb.txt +18 -12
- data/spec/data/xlsx/with_macros.xlsm +0 -0
- data/spec/graphics/cairo_context_wrapper_spec.rb +84 -75
- data/spec/graphics/graphics_images_spec.rb +94 -85
- data/spec/graphics/graphics_save_doc_spec.rb +67 -65
- data/spec/samples/expected/hand.png +0 -0
- data/spec/samples/expected/hand_pretty.png +0 -0
- data/spec/samples/expected/layout_00.png +0 -0
- data/spec/samples/expected/load_images_00.png +0 -0
- data/spec/samples/expected/ranges_00.png +0 -0
- data/spec/samples/expected/shape_00.png +0 -0
- data/spec/samples/expected/showcase.png +0 -0
- data/spec/samples/expected/showcase2.png +0 -0
- data/spec/samples/expected/showcase_individual_00.png +0 -0
- data/spec/samples/expected/showcase_individual_01.png +0 -0
- data/spec/samples/expected/showcase_individual_02.png +0 -0
- data/spec/samples/expected/showcase_individual_03.png +0 -0
- data/spec/samples/expected/text_00.png +0 -0
- data/spec/samples/expected/text_01.png +0 -0
- data/spec/samples/expected/text_02.png +0 -0
- data/spec/samples/samples_regression_spec.rb +82 -82
- data/spec/spec_helper.rb +3 -2
- data/squib.gemspec +48 -48
- data/squib.sublime-project +42 -36
- metadata +61 -33
- data/lib/squib/input_helpers.rb +0 -238
- data/spec/api/api_image_spec.rb +0 -38
- data/spec/api/api_text_spec.rb +0 -37
- data/spec/graphics/graphics_shapes_spec.rb +0 -85
- data/spec/graphics/graphics_text_spec.rb +0 -164
- data/spec/input_helpers_spec.rb +0 -238
- data/spec/samples/expected/embed_multi_00.png +0 -0
- data/spec/samples/expected/embed_multi_01.png +0 -0
- data/spec/samples/expected/embed_multi_02.png +0 -0
- data/spec/samples/expected/ranges_01.png +0 -0
- data/spec/samples/expected/ranges_02.png +0 -0
data/lib/squib/api/image.rb
CHANGED
@@ -1,76 +1,90 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# @
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# @option opts
|
18
|
-
# @option opts
|
19
|
-
# @option opts
|
20
|
-
# @option opts
|
21
|
-
# @
|
22
|
-
# @
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# @
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# @option opts
|
56
|
-
# @option opts
|
57
|
-
# @
|
58
|
-
# @
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
data/lib/squib/api/save.rb
CHANGED
@@ -1,103 +1,149 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# @
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# @
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# @
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# @option opts [
|
54
|
-
# @option opts [String
|
55
|
-
# @option opts [
|
56
|
-
# @option opts [
|
57
|
-
# @option opts [
|
58
|
-
# @
|
59
|
-
# @
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
# @
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
# @option opts [
|
82
|
-
# @option opts [
|
83
|
-
# @option opts [
|
84
|
-
# @option opts [
|
85
|
-
# @
|
86
|
-
# @
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
data/lib/squib/api/settings.rb
CHANGED
@@ -1,37 +1,35 @@
|
|
1
|
-
module Squib
|
2
|
-
class Deck
|
3
|
-
|
4
|
-
# Toggle hints globally.
|
5
|
-
#
|
6
|
-
# Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
|
7
|
-
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
|
8
|
-
# @example
|
9
|
-
# hint text: :cyan
|
10
|
-
# hint text: :cyan
|
11
|
-
#
|
12
|
-
# @param [String] text the color of the text hint. To turn off use :off. @see README.md
|
13
|
-
# @return [nil] Returns nothing
|
14
|
-
# @api public
|
15
|
-
def hint(text: :off)
|
16
|
-
conf.text_hint = text
|
17
|
-
end
|
18
|
-
|
19
|
-
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it.
|
20
|
-
# @example
|
21
|
-
# set font: 'Arial 26'
|
22
|
-
# text 'blah' # in Arial 26
|
23
|
-
# text 'blah24', font: 'Arial 24' # in Arial 24
|
24
|
-
# set font: :default # Back to Squib-wide default
|
25
|
-
#
|
26
|
-
# @option opts font: the font string to set as default. Can also be set to `:default` to use the Squib-wide default.
|
27
|
-
# @
|
28
|
-
# @
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
1
|
+
module Squib
|
2
|
+
class Deck
|
3
|
+
|
4
|
+
# Toggle hints globally.
|
5
|
+
#
|
6
|
+
# Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
|
7
|
+
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
|
8
|
+
# @example
|
9
|
+
# hint text: :cyan
|
10
|
+
# hint text: :cyan
|
11
|
+
#
|
12
|
+
# @param [String] text the color of the text hint. To turn off use :off. @see README.md
|
13
|
+
# @return [nil] Returns nothing
|
14
|
+
# @api public
|
15
|
+
def hint(text: :off)
|
16
|
+
conf.text_hint = text
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it.
|
20
|
+
# @example
|
21
|
+
# set font: 'Arial 26'
|
22
|
+
# text 'blah' # in Arial 26
|
23
|
+
# text 'blah24', font: 'Arial 24' # in Arial 24
|
24
|
+
# set font: :default # Back to Squib-wide default
|
25
|
+
#
|
26
|
+
# @option opts font: the font string to set as default. Can also be set to `:default` to use the Squib-wide default.
|
27
|
+
# @return [nil] Returns nothing
|
28
|
+
# @api public
|
29
|
+
def set(opts = {})
|
30
|
+
raise 'DEPRECATED: As of v0.7 img_dir is no longer supported in "set". Use config.yml instead.' if opts.key? :img_dir
|
31
|
+
@font = (opts[:font] == :default) ? Squib::SYSTEM_DEFAULTS[:default_font] : opts[:font]
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|