squib 0.15.3 → 0.17.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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +22 -0
- data/CHANGELOG.md +35 -1
- data/Dockerfile +18 -16
- data/Guardfile +8 -0
- data/README.md +3 -9
- data/RELEASE TODO.md +4 -2
- data/Rakefile +3 -0
- data/lib/squib.rb +5 -1
- data/lib/squib/args/arg_loader.rb +109 -106
- data/lib/squib/args/box.rb +52 -48
- data/lib/squib/args/card_range.rb +26 -24
- data/lib/squib/args/color_validator.rb +4 -9
- data/lib/squib/args/coords.rb +39 -25
- data/lib/squib/args/csv_opts.rb +13 -16
- data/lib/squib/args/dir_validator.rb +7 -12
- data/lib/squib/args/draw.rb +69 -68
- data/lib/squib/args/drop_shadow.rb +39 -0
- data/lib/squib/args/embed_adjust.rb +12 -15
- data/lib/squib/args/embed_key.rb +6 -11
- data/lib/squib/args/hand_special.rb +25 -25
- data/lib/squib/args/import.rb +54 -27
- data/lib/squib/args/input_file.rb +22 -26
- data/lib/squib/args/paint.rb +30 -31
- data/lib/squib/args/paragraph.rb +95 -93
- data/lib/squib/args/save_batch.rb +50 -48
- data/lib/squib/args/scale_box.rb +43 -39
- data/lib/squib/args/sheet.rb +142 -149
- data/lib/squib/args/showcase_special.rb +32 -32
- data/lib/squib/args/sprue_file.rb +30 -30
- data/lib/squib/args/svg_special.rb +26 -26
- data/lib/squib/args/transform.rb +48 -54
- data/lib/squib/args/typographer.rb +88 -92
- data/lib/squib/args/unit_conversion.rb +6 -8
- data/lib/squib/args/xywh_shorthands.rb +51 -0
- data/lib/squib/builtin/projects/advanced/config.yml +4 -3
- data/lib/squib/builtin/projects/basic/config.yml +4 -3
- data/lib/squib/conf.rb +5 -0
- data/lib/squib/deck.rb +34 -12
- data/lib/squib/dsl/background.rb +35 -0
- data/lib/squib/dsl/circle.rb +39 -0
- data/lib/squib/dsl/csv.rb +42 -0
- data/lib/squib/dsl/curve.rb +35 -0
- data/lib/squib/dsl/cut_zone.rb +47 -0
- data/lib/squib/dsl/ellipse.rb +37 -0
- data/lib/squib/dsl/grid.rb +35 -0
- data/lib/squib/{api → dsl}/groups.rb +0 -0
- data/lib/squib/dsl/hand.rb +42 -0
- data/lib/squib/dsl/line.rb +35 -0
- data/lib/squib/dsl/png.rb +56 -0
- data/lib/squib/dsl/polygon.rb +36 -0
- data/lib/squib/dsl/rect.rb +37 -0
- data/lib/squib/dsl/safe_zone.rb +48 -0
- data/lib/squib/dsl/save.rb +21 -0
- data/lib/squib/dsl/save_pdf.rb +50 -0
- data/lib/squib/dsl/save_png.rb +48 -0
- data/lib/squib/dsl/save_sheet.rb +53 -0
- data/lib/squib/dsl/showcase.rb +43 -0
- data/lib/squib/dsl/star.rb +37 -0
- data/lib/squib/dsl/svg.rb +62 -0
- data/lib/squib/dsl/text.rb +54 -0
- data/lib/squib/dsl/text_embed.rb +78 -0
- data/lib/squib/dsl/triangle.rb +35 -0
- data/lib/squib/{api → dsl}/units.rb +10 -0
- data/lib/squib/dsl/xlsx.rb +40 -0
- data/lib/squib/dsl/yaml.rb +40 -0
- data/lib/squib/errors_warnings/warn_unexpected_params.rb +14 -0
- data/lib/squib/graphics/cairo_context_wrapper.rb +8 -6
- data/lib/squib/graphics/save_images.rb +54 -15
- data/lib/squib/graphics/save_sprue.rb +14 -2
- data/lib/squib/graphics/text.rb +37 -9
- data/lib/squib/import/csv_importer.rb +45 -0
- data/lib/squib/import/quantity_exploder.rb +18 -0
- data/lib/squib/import/xlsx_importer.rb +28 -0
- data/lib/squib/import/yaml_importer.rb +30 -0
- data/lib/squib/layout_parser.rb +24 -7
- data/lib/squib/sprues/crop_line.rb +6 -6
- data/lib/squib/sprues/crop_line_dash.rb +6 -6
- data/lib/squib/sprues/sprue.rb +16 -14
- data/lib/squib/system_fonts.rb +17 -0
- data/lib/squib/version.rb +2 -1
- data/samples/autoscale_font/_autoscale_font.rb +77 -8
- data/samples/colors/_switch_color.rb +2 -2
- data/samples/data/_excel.rb +1 -1
- data/samples/ranges/_ranges.rb +1 -1
- data/samples/saves/_save_filenames.rb +4 -0
- data/samples/saves/_save_pdf.rb +1 -1
- data/samples/saves/_saves.rb +12 -1
- data/samples/shadows/_shadow.rb +72 -0
- data/samples/shapes/_draw_shapes.rb +2 -2
- data/samples/sprues/_builtin_sprues.rb +1 -0
- data/samples/sprues/_fold_sheet.rb +4 -1
- data/samples/system_font_debug/_list_fonts.rb +14 -0
- data/samples/text/_text.rb +6 -1
- data/samples/text/_text_options.rb +2 -1
- data/samples/units/_cells.rb +51 -0
- data/samples/units/_shorthands.rb +48 -0
- data/samples/units/_units.rb +7 -0
- data/squib.gemspec +14 -8
- metadata +134 -39
- data/.travis.yml +0 -17
- data/appveyor.yml +0 -25
- data/lib/squib/api/background.rb +0 -15
- data/lib/squib/api/data.rb +0 -137
- data/lib/squib/api/image.rb +0 -49
- data/lib/squib/api/save.rb +0 -83
- data/lib/squib/api/shapes.rb +0 -124
- data/lib/squib/api/text.rb +0 -25
- data/lib/squib/api/text_embed.rb +0 -71
|
@@ -9,22 +9,22 @@ module Squib
|
|
|
9
9
|
|
|
10
10
|
attr_reader :pattern
|
|
11
11
|
|
|
12
|
-
def initialize(value, dpi)
|
|
12
|
+
def initialize(value, dpi, cell_px)
|
|
13
13
|
if value == :solid
|
|
14
14
|
@pattern = nil
|
|
15
15
|
elsif value == :dotted
|
|
16
16
|
@pattern = [
|
|
17
|
-
Args::UnitConversion.parse('0.2mm', dpi),
|
|
18
|
-
Args::UnitConversion.parse('0.5mm', dpi)
|
|
17
|
+
Args::UnitConversion.parse('0.2mm', dpi, cell_px),
|
|
18
|
+
Args::UnitConversion.parse('0.5mm', dpi, cell_px)
|
|
19
19
|
]
|
|
20
20
|
elsif value == :dashed
|
|
21
21
|
@pattern = [
|
|
22
|
-
Args::UnitConversion.parse('2mm', dpi),
|
|
23
|
-
Args::UnitConversion.parse('2mm', dpi)
|
|
22
|
+
Args::UnitConversion.parse('2mm', dpi, cell_px),
|
|
23
|
+
Args::UnitConversion.parse('2mm', dpi, cell_px)
|
|
24
24
|
]
|
|
25
25
|
elsif value.is_a? String
|
|
26
26
|
@pattern = value.split(' ').map do |val|
|
|
27
|
-
Args::UnitConversion.parse val, dpi
|
|
27
|
+
Args::UnitConversion.parse val, dpi, cell_px
|
|
28
28
|
end
|
|
29
29
|
else
|
|
30
30
|
raise ArgumentError, 'Unsupported dash style'
|
data/lib/squib/sprues/sprue.rb
CHANGED
|
@@ -18,6 +18,7 @@ module Squib
|
|
|
18
18
|
'card_width' => nil,
|
|
19
19
|
'card_height' => nil,
|
|
20
20
|
'dpi' => 300,
|
|
21
|
+
'cell_px' => 37.5,
|
|
21
22
|
'position_reference' => :topleft,
|
|
22
23
|
'rotate' => 0.0,
|
|
23
24
|
'crop_line' => {
|
|
@@ -32,16 +33,17 @@ module Squib
|
|
|
32
33
|
|
|
33
34
|
attr_reader :dpi
|
|
34
35
|
|
|
35
|
-
def initialize(template_hash, dpi)
|
|
36
|
+
def initialize(template_hash, dpi, cell_px)
|
|
36
37
|
@template_hash = template_hash
|
|
37
38
|
@dpi = dpi
|
|
39
|
+
@cell_px = cell_px
|
|
38
40
|
@crop_line_default = @template_hash['crop_line'].select do |k, _|
|
|
39
41
|
%w[style width color].include? k
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
# Load the template definition file
|
|
44
|
-
def self.load(file, dpi)
|
|
46
|
+
def self.load(file, dpi, cell_px)
|
|
45
47
|
yaml = {}
|
|
46
48
|
thefile = file if File.exist?(file) # use custom first
|
|
47
49
|
thefile = builtin(file) if File.exist?(builtin(file)) # then builtin
|
|
@@ -62,23 +64,23 @@ module Squib
|
|
|
62
64
|
rescue ClassyHash::SchemaViolationError => e
|
|
63
65
|
raise Sprues::InvalidSprueDefinition.new(thefile, e)
|
|
64
66
|
end
|
|
65
|
-
Sprue.new new_hash, dpi
|
|
67
|
+
Sprue.new new_hash, dpi, cell_px
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
def sheet_width
|
|
69
|
-
Args::UnitConversion.parse @template_hash['sheet_width'], @dpi
|
|
71
|
+
Args::UnitConversion.parse @template_hash['sheet_width'], @dpi, @cell_px
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
def sheet_height
|
|
73
|
-
Args::UnitConversion.parse @template_hash['sheet_height'], @dpi
|
|
75
|
+
Args::UnitConversion.parse @template_hash['sheet_height'], @dpi, @cell_px
|
|
74
76
|
end
|
|
75
77
|
|
|
76
78
|
def card_width
|
|
77
|
-
Args::UnitConversion.parse @template_hash['card_width'], @dpi
|
|
79
|
+
Args::UnitConversion.parse @template_hash['card_width'], @dpi, @cell_px
|
|
78
80
|
end
|
|
79
81
|
|
|
80
82
|
def card_height
|
|
81
|
-
Args::UnitConversion.parse @template_hash['card_height'], @dpi
|
|
83
|
+
Args::UnitConversion.parse @template_hash['card_height'], @dpi, @cell_px
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
def card_default_rotation
|
|
@@ -113,8 +115,8 @@ module Squib
|
|
|
113
115
|
# NOTE: There's a baseline of 0.25mm that we can 100% make sure that we
|
|
114
116
|
# can overlap really thin lines on the PDF
|
|
115
117
|
crop_line_width = [
|
|
116
|
-
Args::UnitConversion.parse(@template_hash['crop_line']['width'], @dpi),
|
|
117
|
-
Args::UnitConversion.parse('0.25mm', @dpi)
|
|
118
|
+
Args::UnitConversion.parse(@template_hash['crop_line']['width'], @dpi, @cell_px),
|
|
119
|
+
Args::UnitConversion.parse('0.25mm', @dpi, @cell_px)
|
|
118
120
|
].max
|
|
119
121
|
|
|
120
122
|
parsed_cards = cards
|
|
@@ -149,12 +151,12 @@ module Squib
|
|
|
149
151
|
# Parse crop line definitions from template.
|
|
150
152
|
def parse_crop_line(line)
|
|
151
153
|
new_line = @crop_line_default.merge line
|
|
152
|
-
new_line['width'] = Args::UnitConversion.parse(new_line['width'], @dpi)
|
|
154
|
+
new_line['width'] = Args::UnitConversion.parse(new_line['width'], @dpi, @cell_px)
|
|
153
155
|
new_line['color'] = colorify new_line['color']
|
|
154
156
|
new_line['style_desc'] = new_line['style']
|
|
155
|
-
new_line['style'] = Sprues::CropLineDash.new(new_line['style'], @dpi)
|
|
157
|
+
new_line['style'] = Sprues::CropLineDash.new(new_line['style'], @dpi, @cell_px)
|
|
156
158
|
new_line['line'] = Sprues::CropLine.new(
|
|
157
|
-
new_line['type'], new_line['position'], sheet_width, sheet_height, @dpi
|
|
159
|
+
new_line['type'], new_line['position'], sheet_width, sheet_height, @dpi, @cell_px
|
|
158
160
|
)
|
|
159
161
|
new_line
|
|
160
162
|
end
|
|
@@ -163,8 +165,8 @@ module Squib
|
|
|
163
165
|
def parse_card(card)
|
|
164
166
|
new_card = card.clone
|
|
165
167
|
|
|
166
|
-
x = Args::UnitConversion.parse(card['x'], @dpi)
|
|
167
|
-
y = Args::UnitConversion.parse(card['y'], @dpi)
|
|
168
|
+
x = Args::UnitConversion.parse(card['x'], @dpi, @cell_px)
|
|
169
|
+
y = Args::UnitConversion.parse(card['y'], @dpi, @cell_px)
|
|
168
170
|
if @template_hash['position_reference'] == :center
|
|
169
171
|
# Normalize it to a top-left positional reference
|
|
170
172
|
x -= card_width / 2
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'pango'
|
|
2
|
+
module Squib
|
|
3
|
+
|
|
4
|
+
# List all system fonts that Cairo/Pango can see
|
|
5
|
+
# Wow this call was convoluted...
|
|
6
|
+
# Returns array of strings with the names of fonts
|
|
7
|
+
module_function def system_fonts
|
|
8
|
+
cc = Cairo::Context.new(Cairo::ImageSurface.new(0,0)) # empty image
|
|
9
|
+
cc.create_pango_layout.context.families.map {|f| f.name }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Prints out the system fonts in sorted order
|
|
13
|
+
module_function def print_system_fonts
|
|
14
|
+
puts "== DEBUG: Squib knows about these fonts =="
|
|
15
|
+
puts system_fonts.sort
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/squib/version.rb
CHANGED
|
@@ -1,13 +1,79 @@
|
|
|
1
1
|
require 'squib'
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
3
|
+
# Autoscaling font is handy for a bunch of things:
|
|
4
|
+
# * Picture-perfect text fitting for one-off
|
|
5
|
+
# * Rapid prototyping where you don't have to think about sizes
|
|
6
|
+
#
|
|
7
|
+
# We've got three options...
|
|
8
|
+
# Option 1. Use your data <--- good for picture-perfect
|
|
9
|
+
# Option 2. Use ellipsize: :autoscale <--- good for rapid prototyping
|
|
10
|
+
# Option 3. Use map ranges in your code <--- good for picture-perfect
|
|
11
|
+
# or other weird cases
|
|
12
|
+
|
|
13
|
+
###########################
|
|
14
|
+
# Option 1: Use your data #
|
|
15
|
+
###########################
|
|
16
|
+
# If you want to tweak the font size per-card, you can always make font_size
|
|
17
|
+
# a column and map it from there. This is tedious but leads to perfectly
|
|
18
|
+
# customized results
|
|
19
|
+
my_data = Squib.csv data: <<~CSV
|
|
20
|
+
"Title","Font Size"
|
|
21
|
+
"Short & Big",10
|
|
22
|
+
"Medium Length & Size", 5
|
|
23
|
+
"Super duper long string here, therefore a smaller font.", 4
|
|
24
|
+
CSV
|
|
25
|
+
|
|
26
|
+
Squib::Deck.new(width: 300, height: 75, cards: 3) do
|
|
27
|
+
background color: :white
|
|
28
|
+
rect stroke_color: :black
|
|
29
|
+
|
|
30
|
+
text str: my_data.title, font: 'Arial',
|
|
31
|
+
font_size: my_data.font_size, # <-- key part
|
|
32
|
+
x: 10, y:10, align: :center,
|
|
33
|
+
width: 280, # <-- note how height does NOT need to be set
|
|
34
|
+
ellipsize: false,
|
|
35
|
+
hint: :red
|
|
36
|
+
save_sheet columns: 3, prefix: 'autoscale_w_data_'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#######################################
|
|
40
|
+
# Option 2: Use ellipsize: :autoscale #
|
|
41
|
+
#######################################
|
|
42
|
+
# If set the height, you can set "autoscale" and it will incrementally
|
|
43
|
+
# downgrade the font size until the text does not ellipsize
|
|
44
|
+
#
|
|
45
|
+
# Great for rapid prototyping, set-it-and-forget-it
|
|
46
|
+
#
|
|
47
|
+
# NOTE: You MUST set the height for this to work. Otherwise, the text will
|
|
48
|
+
# never ellipsize and Squib doesn't know when to start autoscaling
|
|
49
|
+
Squib::Deck.new(width: 300, height: 75, cards: 3) do
|
|
50
|
+
background color: :white
|
|
51
|
+
rect stroke_color: :black
|
|
52
|
+
title = ['Short & Big',
|
|
53
|
+
'Medium Length & Size',
|
|
54
|
+
'Super duper long string here, therefore a smaller font.']
|
|
55
|
+
|
|
56
|
+
# Automatically scale the text down from the specified font_size to the largest size that fits
|
|
57
|
+
text str: title, font: 'Arial',
|
|
58
|
+
font_size: 15, # <-- this is the MAX font size. Scale down from here
|
|
59
|
+
ellipsize: :autoscale, # <-- key part
|
|
60
|
+
height: 50, # <-- need this to be set to something
|
|
61
|
+
width: 280, x: 10, y: 10, align: :center, valign: :middle, hint: :red
|
|
62
|
+
|
|
63
|
+
save_sheet columns: 3, prefix: 'autoscale_w_ellipsize_'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
############################################
|
|
67
|
+
# Option 3: Mapping to ranges in your code #
|
|
68
|
+
############################################
|
|
69
|
+
# Here's an in-between option that allows you to programmatically apply font
|
|
70
|
+
# sizes. This allows you a ton of flexibility.Probably more flexibility than
|
|
71
|
+
# you need, frankly. But one advantage is that you don't have to set the height
|
|
6
72
|
def autoscale(str_array)
|
|
7
73
|
str_array.map do | str |
|
|
8
74
|
case str.length
|
|
9
75
|
when 0..15
|
|
10
|
-
|
|
76
|
+
9
|
|
11
77
|
when 16..20
|
|
12
78
|
6
|
|
13
79
|
else
|
|
@@ -16,14 +82,17 @@ def autoscale(str_array)
|
|
|
16
82
|
end
|
|
17
83
|
end
|
|
18
84
|
|
|
19
|
-
Squib::Deck.new(width: 300, height:
|
|
85
|
+
Squib::Deck.new(width: 300, height: 75, cards: 3) do
|
|
20
86
|
background color: :white
|
|
21
|
-
rect
|
|
87
|
+
rect stroke_color: :black
|
|
22
88
|
title = ['Short & Big',
|
|
23
89
|
'Medium Length & Size',
|
|
24
90
|
'Super duper long string here, therefore a smaller font.']
|
|
25
|
-
|
|
91
|
+
|
|
92
|
+
# Scale text based on the string length
|
|
93
|
+
text str: title, font: 'Arial',
|
|
94
|
+
font_size: autoscale(title), # <-- key part
|
|
26
95
|
x: 10, y:10, align: :center, width: 280, ellipsize: false, hint: :red
|
|
27
96
|
|
|
28
|
-
|
|
97
|
+
save_sheet columns: 3, prefix: 'autoscale_w_range_'
|
|
29
98
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative '../../lib/squib'
|
|
2
2
|
|
|
3
3
|
# Choose between black and white color theme for type snake
|
|
4
4
|
# * Allow using white snake cards with black text or
|
|
5
5
|
# black snake cards with white text
|
|
6
6
|
color = 'white'
|
|
7
7
|
|
|
8
|
-
cards = Squib.csv file: '_switch_color_data.csv'
|
|
8
|
+
cards = Squib.csv file: '_switch_color_data.csv'
|
|
9
9
|
|
|
10
10
|
Squib::Deck.new cards: cards['Type'].size do
|
|
11
11
|
|
data/samples/data/_excel.rb
CHANGED
|
@@ -37,7 +37,7 @@ end
|
|
|
37
37
|
# from each value. This is the default behavior in Squib, but the options
|
|
38
38
|
# are here just to make sure.
|
|
39
39
|
|
|
40
|
-
resource_data = Squib.xlsx(file: 'sample.xlsx', sheet: 2, strip: true) do |header, value|
|
|
40
|
+
resource_data = Squib.xlsx(file: 'sample.xlsx', explode: 'Qty', sheet: 2, strip: true) do |header, value|
|
|
41
41
|
case header
|
|
42
42
|
when 'Cost'
|
|
43
43
|
"$#{value}k" # e.g. "3" becomes "$3k"
|
data/samples/ranges/_ranges.rb
CHANGED
|
@@ -16,6 +16,10 @@ Squib::Deck.new(width: 50, height: 50, cards: 2) do
|
|
|
16
16
|
# bar.png
|
|
17
17
|
save_png prefix: ['foo', 'bar'], count_format: ''
|
|
18
18
|
|
|
19
|
+
# foo_00_bar.png
|
|
20
|
+
# foo_01_bar.png
|
|
21
|
+
save_png prefix: 'foo_', suffix: '_bar'
|
|
22
|
+
|
|
19
23
|
# thief.png
|
|
20
24
|
# thug.png
|
|
21
25
|
data = csv data: "filename\nthief\nthug"
|
data/samples/saves/_save_pdf.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'squib'
|
|
|
3
3
|
Squib::Deck.new(cards: 8) do
|
|
4
4
|
background color: :gray
|
|
5
5
|
rect x: 37.5, y: 37.5, width: 750, height: 1050,
|
|
6
|
-
x_radius: 37.5, y_radius: 37.5,
|
|
6
|
+
x_radius: 37.5, y_radius: 37.5, stroke_width: 2.0, dash: '4 4'
|
|
7
7
|
|
|
8
8
|
# Tests for crop marks
|
|
9
9
|
save_pdf file: 'crops-default.pdf', crop_marks: true
|
data/samples/saves/_saves.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'squib'
|
|
|
5
5
|
Squib::Deck.new(width: 825, height: 1125, cards: 16) do
|
|
6
6
|
background color: :gray
|
|
7
7
|
rect x: 38, y: 38, width: 750, height: 1050,
|
|
8
|
-
x_radius: 38, y_radius: 38,
|
|
8
|
+
x_radius: 38, y_radius: 38, stroke_width: 2.0, dash: '4 4'
|
|
9
9
|
|
|
10
10
|
text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 18'
|
|
11
11
|
|
|
@@ -45,7 +45,18 @@ Squib::Deck.new(width: 825, height: 1125, cards: 16) do
|
|
|
45
45
|
|
|
46
46
|
# Sheets can arrange left-to-right and right-to-left
|
|
47
47
|
save_sheet prefix: 'save_sheet_rtl_',
|
|
48
|
+
suffix: '_with_suffix',
|
|
48
49
|
range: 0..1, rtl: true,
|
|
49
50
|
columns: 2, rows: 1,
|
|
50
51
|
margin: 75, gap: 5, trim: 37
|
|
51
52
|
end
|
|
53
|
+
|
|
54
|
+
Squib::Deck.new(width: 100, height: 100, cards: 3) do
|
|
55
|
+
background color: :grey
|
|
56
|
+
text str: 'Hi', font: 'Arial 18'
|
|
57
|
+
|
|
58
|
+
# Test bug 332.
|
|
59
|
+
# When we only have 3 cards but want a 2x4 grid with lots of empty spaces.
|
|
60
|
+
# Buggy behavior was to revert to 1 row and not respect the rows arg.
|
|
61
|
+
save_sheet prefix: 'save_sheet_bug332_', rows: 2, columns: 4
|
|
62
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'squib'
|
|
2
|
+
# The save_png method supports drop shadows on the final save
|
|
3
|
+
# This is useful for when you want to generate images for your rulebook
|
|
4
|
+
|
|
5
|
+
Squib::Deck.new(width: 100, height: 150) do
|
|
6
|
+
background color: '#abc'
|
|
7
|
+
svg file: '../spanner.svg',
|
|
8
|
+
x: 'middle - 25', y: 'middle - 25',
|
|
9
|
+
width: 50, height: 50
|
|
10
|
+
|
|
11
|
+
# Shadows off by default, i.e. shadow_radius is nil
|
|
12
|
+
# So our final dimensions are 100 - 2*15 and 150-2*15
|
|
13
|
+
save_png prefix: 'no_shadow_', trim: 15, trim_radius: 15
|
|
14
|
+
|
|
15
|
+
# Here's a nice-looking drop shadow
|
|
16
|
+
# Defaults are designed to be generally good, so I recommend just
|
|
17
|
+
# trying out a shadow_radius of 3 to 10 and see how it looks first
|
|
18
|
+
save_png prefix: 'with_shadow_', trim: 15, trim_radius: 15,
|
|
19
|
+
shadow_radius: 8,
|
|
20
|
+
shadow_offset_x: 3, shadow_offset_y: 3, # about r / 2.5 looks good
|
|
21
|
+
shadow_trim: 2.5, # about r/ 3 looks good
|
|
22
|
+
shadow_color: '#101010aa' #tip: start the shadow color kinda transparent
|
|
23
|
+
|
|
24
|
+
# Don't want a blur? Use a radius of 0
|
|
25
|
+
save_png prefix: 'no_blur_', trim: 15, trim_radius: 15,
|
|
26
|
+
shadow_radius: 0
|
|
27
|
+
|
|
28
|
+
# Ok this next stop is crazytown, but it does give you ultimate control
|
|
29
|
+
# Remember that all Squib colors can also be gradients.
|
|
30
|
+
# They can be clunky but they do work here.
|
|
31
|
+
# - x,y's are centered in the card itself
|
|
32
|
+
# - stops go from fully empty to fully black
|
|
33
|
+
# - we need to still turn on radius to get the effect
|
|
34
|
+
# - but, this makes the upper-left corner not have a glowing effect and
|
|
35
|
+
# have a harder edge, which (to my eye at least) feels more realistic
|
|
36
|
+
# since the card would obscure the upper-left shadow at that angle
|
|
37
|
+
# - this also allows you have a larger, softer blur without making it look
|
|
38
|
+
# like it's glowing
|
|
39
|
+
#
|
|
40
|
+
# Oh just because it's easier to write we can use a ruby heredoc
|
|
41
|
+
save_png prefix: 'gradient_blur_', trim: 15, trim_radius: 15,
|
|
42
|
+
shadow_radius: 10,
|
|
43
|
+
shadow_color: <<~EOS
|
|
44
|
+
(25,25)
|
|
45
|
+
(175,175)
|
|
46
|
+
#0000@0.0
|
|
47
|
+
#000f@1.0
|
|
48
|
+
EOS
|
|
49
|
+
|
|
50
|
+
# This one looks weird I know but it's for regression testing
|
|
51
|
+
save_png prefix: 'with_shadow_test_',
|
|
52
|
+
trim: 15, trim_radius: 15, rotate: :clockwise,
|
|
53
|
+
shadow_offset_x: 5, shadow_offset_y: 25, shadow_radius: 10,
|
|
54
|
+
shadow_trim: 10,
|
|
55
|
+
shadow_color: '#123'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Squib::Deck.new(width:50, height: 50) do
|
|
59
|
+
|
|
60
|
+
# What if we had a transparent card but just some shapes?
|
|
61
|
+
# Like chits or something
|
|
62
|
+
|
|
63
|
+
# background defaults to fully transparent here
|
|
64
|
+
|
|
65
|
+
png file: 'doodle.png'
|
|
66
|
+
|
|
67
|
+
save_png prefix: 'transparent_bg_shadow_',
|
|
68
|
+
shadow_radius: 2,
|
|
69
|
+
shadow_offset_x: 2, shadow_offset_y: 2,
|
|
70
|
+
shadow_color: :black
|
|
71
|
+
|
|
72
|
+
end
|
|
@@ -3,8 +3,8 @@ require 'squib'
|
|
|
3
3
|
Squib::Deck.new do
|
|
4
4
|
background color: :white
|
|
5
5
|
|
|
6
|
-
grid x: 10, y: 10, width: 50, height: 50, stroke_color: '#0066FF', stroke_width: 1.5
|
|
7
|
-
grid x: 10, y: 10, width: 200, height: 200, stroke_color: '#0066FF', stroke_width: 3
|
|
6
|
+
grid x: 10, y: 10, width: 50, height: 50, stroke_color: '#0066FF', stroke_width: 1.5
|
|
7
|
+
grid x: 10, y: 10, width: 200, height: 200, stroke_color: '#0066FF', stroke_width: 3
|
|
8
8
|
|
|
9
9
|
rect x: 305, y: 105, width: 200, height: 50, dash: '4 2'
|
|
10
10
|
|
|
@@ -22,6 +22,9 @@ Squib::Deck.new(width: '2.5in', height: '3.5in', cards: 8) do
|
|
|
22
22
|
|
|
23
23
|
text str: strings,font: 'Sans 32', align: :center, valign: :middle,
|
|
24
24
|
height: :deck, width: :deck
|
|
25
|
+
|
|
25
26
|
save_sheet prefix: 'foldable_',
|
|
26
|
-
sprue: 'letter_poker_foldable_8up.yml'
|
|
27
|
+
sprue: 'letter_poker_foldable_8up.yml' # built-in sprue
|
|
28
|
+
save_pdf file: 'foldable.pdf',
|
|
29
|
+
sprue: 'letter_poker_foldable_8up.yml' # built-in sprue
|
|
27
30
|
end
|