squib 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +22 -0
- data/.gitignore +41 -41
- data/CHANGELOG.md +422 -387
- data/CONTRIBUTING.md +40 -40
- data/Dockerfile +27 -25
- data/Gemfile +2 -2
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -22
- data/README.md +139 -121
- data/RELEASE TODO.md +22 -21
- data/Rakefile +51 -48
- data/bin/squib +4 -4
- data/lib/squib.rb +34 -32
- data/lib/squib/api/settings.rb +21 -21
- data/lib/squib/args/arg_loader.rb +129 -126
- data/lib/squib/args/box.rb +59 -55
- data/lib/squib/args/card_range.rb +34 -32
- data/lib/squib/args/color_validator.rb +7 -12
- data/lib/squib/args/coords.rb +49 -35
- data/lib/squib/args/csv_opts.rb +22 -25
- data/lib/squib/args/dir_validator.rb +11 -16
- data/lib/squib/args/draw.rb +93 -92
- data/lib/squib/args/embed_adjust.rb +22 -25
- data/lib/squib/args/embed_key.rb +12 -17
- data/lib/squib/args/hand_special.rb +37 -37
- data/lib/squib/args/import.rb +67 -40
- data/lib/squib/args/input_file.rb +33 -37
- data/lib/squib/args/paint.rb +43 -44
- data/lib/squib/args/paragraph.rb +118 -116
- data/lib/squib/args/save_batch.rb +65 -63
- data/lib/squib/args/scale_box.rb +57 -53
- data/lib/squib/args/sheet.rb +170 -172
- data/lib/squib/args/showcase_special.rb +41 -41
- data/lib/squib/args/sprue_file.rb +44 -44
- data/lib/squib/args/svg_special.rb +37 -37
- data/lib/squib/args/transform.rb +55 -61
- data/lib/squib/args/typographer.rb +115 -119
- data/lib/squib/args/unit_conversion.rb +27 -29
- data/lib/squib/args/xywh_shorthands.rb +51 -0
- data/lib/squib/builtin/layouts/economy.yml +85 -85
- data/lib/squib/builtin/layouts/fantasy.yml +101 -101
- data/lib/squib/builtin/layouts/hand.yml +62 -62
- data/lib/squib/builtin/layouts/party.yml +94 -94
- data/lib/squib/builtin/layouts/playing-card.yml +35 -35
- data/lib/squib/builtin/layouts/tuck_box.yml +46 -46
- data/lib/squib/builtin/projects/advanced/.gitignore +4 -4
- data/lib/squib/builtin/projects/advanced/ABOUT.md +19 -19
- data/lib/squib/builtin/projects/advanced/Gemfile +11 -11
- data/lib/squib/builtin/projects/advanced/Guardfile +21 -21
- data/lib/squib/builtin/projects/advanced/IDEAS.md +22 -22
- data/lib/squib/builtin/projects/advanced/PLAYTESTING.md +26 -26
- data/lib/squib/builtin/projects/advanced/Rakefile +27 -27
- data/lib/squib/builtin/projects/advanced/config.yml +50 -49
- data/lib/squib/builtin/projects/advanced/docs/PNP NOTES.md +3 -3
- data/lib/squib/builtin/projects/advanced/docs/RULES.md +21 -21
- data/lib/squib/builtin/projects/advanced/img/example.svg +60 -60
- data/lib/squib/builtin/projects/advanced/layouts/deck.yml +27 -27
- data/lib/squib/builtin/projects/advanced/src/deck.rb +34 -34
- data/lib/squib/builtin/projects/advanced/src/version.rb +3 -3
- data/lib/squib/builtin/projects/basic/.gitignore +4 -4
- data/lib/squib/builtin/projects/basic/ABOUT.md +19 -19
- data/lib/squib/builtin/projects/basic/Gemfile +3 -3
- data/lib/squib/builtin/projects/basic/IDEAS.md +22 -22
- data/lib/squib/builtin/projects/basic/PLAYTESTING.md +26 -26
- data/lib/squib/builtin/projects/basic/PNP NOTES.md +3 -3
- data/lib/squib/builtin/projects/basic/RULES.md +21 -21
- data/lib/squib/builtin/projects/basic/Rakefile +7 -7
- data/lib/squib/builtin/projects/basic/config.yml +50 -49
- data/lib/squib/builtin/projects/basic/deck.rb +6 -6
- data/lib/squib/builtin/sprues/a4_euro_card.yml +42 -42
- data/lib/squib/builtin/sprues/a4_poker_card_8up.yml +40 -40
- data/lib/squib/builtin/sprues/a4_poker_card_9up.yml +42 -42
- data/lib/squib/builtin/sprues/a4_usa_card.yml +42 -42
- data/lib/squib/builtin/sprues/drivethrucards_1up.yml +10 -10
- data/lib/squib/builtin/sprues/letter_poker_card_9up.yml +25 -25
- data/lib/squib/builtin/sprues/letter_poker_foldable_8up.yml +52 -52
- data/lib/squib/builtin/sprues/printplaygames_18up.yml +68 -68
- data/lib/squib/card.rb +75 -75
- data/lib/squib/commands/cli.rb +39 -39
- data/lib/squib/commands/data/template_option.rb +109 -109
- data/lib/squib/commands/make_sprue.rb +277 -277
- data/lib/squib/commands/new.rb +77 -77
- data/lib/squib/conf.rb +144 -139
- data/lib/squib/constants.rb +17 -17
- data/lib/squib/deck.rb +138 -116
- 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 +54 -54
- 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 +44 -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 +37 -27
- 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/background.rb +14 -14
- data/lib/squib/graphics/cairo_context_wrapper.rb +113 -113
- data/lib/squib/graphics/embedding_utils.rb +28 -28
- data/lib/squib/graphics/gradient_regex.rb +47 -47
- data/lib/squib/graphics/hand.rb +42 -42
- data/lib/squib/graphics/image.rb +123 -123
- data/lib/squib/graphics/save_doc.rb +61 -61
- data/lib/squib/graphics/save_images.rb +52 -52
- data/lib/squib/graphics/save_pdf.rb +90 -90
- data/lib/squib/graphics/save_sprue.rb +231 -219
- data/lib/squib/graphics/shapes.rb +143 -143
- data/lib/squib/graphics/showcase.rb +85 -85
- data/lib/squib/graphics/text.rb +202 -174
- data/lib/squib/import/csv_importer.rb +45 -0
- data/lib/squib/import/data_frame.rb +108 -108
- 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 +155 -138
- data/lib/squib/progress.rb +38 -38
- data/lib/squib/sample_helpers.rb +34 -34
- data/lib/squib/sprues/crop_line.rb +28 -28
- data/lib/squib/sprues/crop_line_dash.rb +35 -35
- data/lib/squib/sprues/invalid_sprue_definition.rb +9 -9
- data/lib/squib/sprues/sprue.rb +208 -206
- data/lib/squib/sprues/sprue_schema.rb +50 -50
- data/lib/squib/version.rb +11 -10
- data/samples/autoscale_font/_autoscale_font.rb +98 -29
- data/samples/backend/_backend.rb +26 -26
- data/samples/basic.rb +19 -19
- data/samples/build_groups/build_groups.rb +36 -36
- data/samples/colors/_colors.rb +44 -44
- data/samples/colors/_gradients.rb +34 -34
- data/samples/colors/_switch_color.rb +33 -33
- data/samples/config/config_text_markup.rb +20 -20
- data/samples/config/custom_config.rb +18 -18
- data/samples/data/_csv.rb +33 -33
- data/samples/data/_excel.rb +55 -55
- data/samples/data/_yaml.rb +12 -12
- data/samples/hello_world.rb +6 -6
- data/samples/images/_cairo_access.rb +39 -39
- data/samples/images/_images.rb +104 -104
- data/samples/images/_more_load_images.rb +102 -102
- data/samples/intro/01_hello.rb +8 -8
- data/samples/intro/02_options.rb +14 -14
- data/samples/intro/03_layout.rb +11 -11
- data/samples/intro/04_arrays.rb +15 -15
- data/samples/intro/05_excel.rb +14 -14
- data/samples/layouts/builtin_layouts.rb +97 -97
- data/samples/layouts/layouts.rb +71 -71
- data/samples/project/src/characters.rb +8 -8
- data/samples/project/src/skills.rb +7 -7
- data/samples/proofs/_tgc_proofs.rb +16 -16
- data/samples/ranges/_ranges.rb +64 -64
- data/samples/saves/_hand.rb +23 -23
- data/samples/saves/_portrait_landscape.rb +23 -23
- data/samples/saves/_save_filenames.rb +28 -24
- data/samples/saves/_save_pdf.rb +29 -29
- data/samples/saves/_saves.rb +52 -51
- data/samples/saves/_showcase.rb +25 -25
- data/samples/shapes/_draw_shapes.rb +60 -60
- data/samples/shapes/_proofs.rb +22 -22
- data/samples/sprues/_advanced_sprues.rb +25 -25
- data/samples/sprues/_builtin_sprues.rb +22 -21
- data/samples/sprues/_fold_sheet.rb +30 -27
- data/samples/sprues/_hex_tiles.rb +15 -15
- data/samples/sprues/_mints.rb +11 -11
- data/samples/sprues/_sprue_example.rb +11 -11
- data/samples/text/_embed_text.rb +128 -128
- data/samples/text/_text.rb +52 -47
- data/samples/text/_text_options.rb +103 -102
- data/samples/text/bug134.rb +14 -14
- data/samples/units/_cells.rb +51 -0
- data/samples/units/_shorthands.rb +48 -0
- data/samples/units/_units.rb +39 -32
- data/squib.gemspec +58 -52
- metadata +177 -91
- 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
@@ -1,50 +1,50 @@
|
|
1
|
-
module Squib
|
2
|
-
module Sprues
|
3
|
-
UNIT_REGEX = /^(\d*[.])?\d+(in|cm|mm)$/
|
4
|
-
ROTATE_REGEX = /^(\d*[.])?\d+(deg|rad)?$/
|
5
|
-
SCHEMA = {
|
6
|
-
'sheet_width' => UNIT_REGEX,
|
7
|
-
'sheet_height' => UNIT_REGEX,
|
8
|
-
'card_width' => UNIT_REGEX,
|
9
|
-
'card_height' => UNIT_REGEX,
|
10
|
-
'position_reference' => ClassyHash::G.enum(:topleft, :center),
|
11
|
-
'rotate' => [
|
12
|
-
:optional, Numeric,
|
13
|
-
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
|
14
|
-
ROTATE_REGEX
|
15
|
-
],
|
16
|
-
'crop_line' => {
|
17
|
-
'style' => [
|
18
|
-
ClassyHash::G.enum(:solid, :dotted, :dashed),
|
19
|
-
Sprues::CropLineDash::VALIDATION_REGEX
|
20
|
-
],
|
21
|
-
'width' => UNIT_REGEX,
|
22
|
-
'color' => [String, Symbol],
|
23
|
-
'overlay' => ClassyHash::G.enum(
|
24
|
-
:on_margin, :overlay_on_cards, :beneath_cards
|
25
|
-
),
|
26
|
-
'lines' => [[{
|
27
|
-
'type' => ClassyHash::G.enum(:horizontal, :vertical),
|
28
|
-
'position' => UNIT_REGEX,
|
29
|
-
'style' => [
|
30
|
-
:optional, ClassyHash::G.enum(:solid, :dotted, :dashed)
|
31
|
-
],
|
32
|
-
'width' => [:optional, UNIT_REGEX],
|
33
|
-
'color' => [:optional, String, Symbol],
|
34
|
-
'overlay_on_cards' => [:optional, TrueClass]
|
35
|
-
}]]
|
36
|
-
},
|
37
|
-
'cards' => [[{
|
38
|
-
'x' => UNIT_REGEX,
|
39
|
-
'y' => UNIT_REGEX,
|
40
|
-
'rotate' => [
|
41
|
-
:optional, Numeric,
|
42
|
-
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
|
43
|
-
ROTATE_REGEX
|
44
|
-
],
|
45
|
-
'flip_vertical' => [ :optional, FalseClass ],
|
46
|
-
'flip_horizontal' => [ :optional, FalseClass ],
|
47
|
-
}]]
|
48
|
-
}.freeze
|
49
|
-
end
|
50
|
-
end
|
1
|
+
module Squib
|
2
|
+
module Sprues
|
3
|
+
UNIT_REGEX = /^(\d*[.])?\d+(in|cm|mm)$/
|
4
|
+
ROTATE_REGEX = /^(\d*[.])?\d+(deg|rad)?$/
|
5
|
+
SCHEMA = {
|
6
|
+
'sheet_width' => UNIT_REGEX,
|
7
|
+
'sheet_height' => UNIT_REGEX,
|
8
|
+
'card_width' => UNIT_REGEX,
|
9
|
+
'card_height' => UNIT_REGEX,
|
10
|
+
'position_reference' => ClassyHash::G.enum(:topleft, :center),
|
11
|
+
'rotate' => [
|
12
|
+
:optional, Numeric,
|
13
|
+
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
|
14
|
+
ROTATE_REGEX
|
15
|
+
],
|
16
|
+
'crop_line' => {
|
17
|
+
'style' => [
|
18
|
+
ClassyHash::G.enum(:solid, :dotted, :dashed),
|
19
|
+
Sprues::CropLineDash::VALIDATION_REGEX
|
20
|
+
],
|
21
|
+
'width' => UNIT_REGEX,
|
22
|
+
'color' => [String, Symbol],
|
23
|
+
'overlay' => ClassyHash::G.enum(
|
24
|
+
:on_margin, :overlay_on_cards, :beneath_cards
|
25
|
+
),
|
26
|
+
'lines' => [[{
|
27
|
+
'type' => ClassyHash::G.enum(:horizontal, :vertical),
|
28
|
+
'position' => UNIT_REGEX,
|
29
|
+
'style' => [
|
30
|
+
:optional, ClassyHash::G.enum(:solid, :dotted, :dashed)
|
31
|
+
],
|
32
|
+
'width' => [:optional, UNIT_REGEX],
|
33
|
+
'color' => [:optional, String, Symbol],
|
34
|
+
'overlay_on_cards' => [:optional, TrueClass]
|
35
|
+
}]]
|
36
|
+
},
|
37
|
+
'cards' => [[{
|
38
|
+
'x' => UNIT_REGEX,
|
39
|
+
'y' => UNIT_REGEX,
|
40
|
+
'rotate' => [
|
41
|
+
:optional, Numeric,
|
42
|
+
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
|
43
|
+
ROTATE_REGEX
|
44
|
+
],
|
45
|
+
'flip_vertical' => [ :optional, FalseClass ],
|
46
|
+
'flip_horizontal' => [ :optional, FalseClass ],
|
47
|
+
}]]
|
48
|
+
}.freeze
|
49
|
+
end
|
50
|
+
end
|
data/lib/squib/version.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
module Squib
|
2
|
-
|
3
|
-
# The next version to be released.
|
4
|
-
# Uses semantic versioning: http://semver.org/
|
5
|
-
#
|
6
|
-
# Most of the time this is in the alpha of the next release.
|
7
|
-
# e.g. v0.0.5a is on its way to becoming v0.0.5
|
8
|
-
#
|
9
|
-
VERSION = '0.
|
10
|
-
end
|
1
|
+
module Squib
|
2
|
+
|
3
|
+
# The next version to be released.
|
4
|
+
# Uses semantic versioning: http://semver.org/
|
5
|
+
#
|
6
|
+
# Most of the time this is in the alpha of the next release.
|
7
|
+
# e.g. v0.0.5a is on its way to becoming v0.0.5
|
8
|
+
#
|
9
|
+
VERSION = '0.16.0'
|
10
|
+
end
|
11
|
+
|
@@ -1,29 +1,98 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
Squib
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
require 'squib'
|
2
|
+
|
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
|
72
|
+
def autoscale(str_array)
|
73
|
+
str_array.map do | str |
|
74
|
+
case str.length
|
75
|
+
when 0..15
|
76
|
+
9
|
77
|
+
when 16..20
|
78
|
+
6
|
79
|
+
else
|
80
|
+
4
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Squib::Deck.new(width: 300, height: 75, cards: 3) do
|
86
|
+
background color: :white
|
87
|
+
rect stroke_color: :black
|
88
|
+
title = ['Short & Big',
|
89
|
+
'Medium Length & Size',
|
90
|
+
'Super duper long string here, therefore a smaller font.']
|
91
|
+
|
92
|
+
# Scale text based on the string length
|
93
|
+
text str: title, font: 'Arial',
|
94
|
+
font_size: autoscale(title), # <-- key part
|
95
|
+
x: 10, y:10, align: :center, width: 280, ellipsize: false, hint: :red
|
96
|
+
|
97
|
+
save_sheet columns: 3, prefix: 'autoscale_w_range_'
|
98
|
+
end
|
data/samples/backend/_backend.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
# Our SVGs are auto-saved after each step using the configuration parameters
|
4
|
-
Squib::Deck.new(cards: 2, config: '_backend-config.yml') do
|
5
|
-
|
6
|
-
# These are all supported by the SVG backend
|
7
|
-
background color: :gray
|
8
|
-
text str: 'Hello, world!', y: 500, width: 825, font: 'Sans bold 24', align: :center
|
9
|
-
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
|
10
|
-
circle x: 100, y: 400, radius: 25
|
11
|
-
triangle x1: 100, y1: 425, x2: 125, y2: 475, x3: 75, y3: 475
|
12
|
-
line x1: 100, y1: 620, x2: 720, y2: 620, stroke_width: 15.0
|
13
|
-
svg file: 'spanner.svg', x: 100, y: 75
|
14
|
-
png file: 'shiny-purse.png', x: 250, y: 75 # raster can still be used too
|
15
|
-
png file: 'shiny-purse.png', x: 250, y: 250, mask: :red # still renders as raster
|
16
|
-
# We can still rasterize whenever we want
|
17
|
-
save_png prefix: 'backend_'
|
18
|
-
|
19
|
-
showcase file: 'showcase.png', fill_color: 'white'
|
20
|
-
|
21
|
-
# And our PDFs will be vectorized .
|
22
|
-
save_pdf file: 'backend_vectorized.pdf', gap: 5
|
23
|
-
|
24
|
-
# This one is a known issue. Masking an SVG onto an SVG backend is still buggy.
|
25
|
-
# svg file: 'glass-heart.svg', x: 100, y: 200, width: 100, height: 100, mask: :sangria
|
26
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
# Our SVGs are auto-saved after each step using the configuration parameters
|
4
|
+
Squib::Deck.new(cards: 2, config: '_backend-config.yml') do
|
5
|
+
|
6
|
+
# These are all supported by the SVG backend
|
7
|
+
background color: :gray
|
8
|
+
text str: 'Hello, world!', y: 500, width: 825, font: 'Sans bold 24', align: :center
|
9
|
+
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
|
10
|
+
circle x: 100, y: 400, radius: 25
|
11
|
+
triangle x1: 100, y1: 425, x2: 125, y2: 475, x3: 75, y3: 475
|
12
|
+
line x1: 100, y1: 620, x2: 720, y2: 620, stroke_width: 15.0
|
13
|
+
svg file: 'spanner.svg', x: 100, y: 75
|
14
|
+
png file: 'shiny-purse.png', x: 250, y: 75 # raster can still be used too
|
15
|
+
png file: 'shiny-purse.png', x: 250, y: 250, mask: :red # still renders as raster
|
16
|
+
# We can still rasterize whenever we want
|
17
|
+
save_png prefix: 'backend_'
|
18
|
+
|
19
|
+
showcase file: 'showcase.png', fill_color: 'white'
|
20
|
+
|
21
|
+
# And our PDFs will be vectorized .
|
22
|
+
save_pdf file: 'backend_vectorized.pdf', gap: 5
|
23
|
+
|
24
|
+
# This one is a known issue. Masking an SVG onto an SVG backend is still buggy.
|
25
|
+
# svg file: 'glass-heart.svg', x: 100, y: 200, width: 100, height: 100, mask: :sangria
|
26
|
+
end
|
data/samples/basic.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
data = { 'name' => ['Thief', 'Grifter', 'Mastermind'],
|
4
|
-
'level' => [1, 2, 3] }
|
5
|
-
|
6
|
-
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
7
|
-
background color: :white
|
8
|
-
rect x: 38, y: 38, width: 750, height: 1050, radius: 38
|
9
|
-
rect x: 75, y: 75, width: 128, height: 128, radius: 25
|
10
|
-
|
11
|
-
text str: data['name'], x: 220, y: 78, font: 'Arial 18'
|
12
|
-
text str: data['level'], x: 75, y: 85, width: 128,
|
13
|
-
font: 'Arial 24', align: :center
|
14
|
-
|
15
|
-
png range: [0, 2], file: 'shiny-purse.png', x: 620, y: 75
|
16
|
-
svg range: 1..2, file: 'spanner.svg', x: 620, y: 218
|
17
|
-
|
18
|
-
save prefix: 'basic_', format: :png
|
19
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
data = { 'name' => ['Thief', 'Grifter', 'Mastermind'],
|
4
|
+
'level' => [1, 2, 3] }
|
5
|
+
|
6
|
+
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
7
|
+
background color: :white
|
8
|
+
rect x: 38, y: 38, width: 750, height: 1050, radius: 38
|
9
|
+
rect x: 75, y: 75, width: 128, height: 128, radius: 25
|
10
|
+
|
11
|
+
text str: data['name'], x: 220, y: 78, font: 'Arial 18'
|
12
|
+
text str: data['level'], x: 75, y: 85, width: 128,
|
13
|
+
font: 'Arial 24', align: :center
|
14
|
+
|
15
|
+
png range: [0, 2], file: 'shiny-purse.png', x: 620, y: 75
|
16
|
+
svg range: 1..2, file: 'spanner.svg', x: 620, y: 218
|
17
|
+
|
18
|
+
save prefix: 'basic_', format: :png
|
19
|
+
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
Squib::Deck.new(width: 75, height: 75, cards: 2) do
|
4
|
-
# puts "Groups enabled by environment: #{groups.to_a}"
|
5
|
-
|
6
|
-
text str: ['A', 'B']
|
7
|
-
|
8
|
-
build :print_n_play do
|
9
|
-
rect
|
10
|
-
save_sheet prefix: 'build_groups_bw_'
|
11
|
-
end
|
12
|
-
|
13
|
-
build :color do
|
14
|
-
rect stroke_color: :red, dash: '5 5'
|
15
|
-
save_png prefix: 'build_groups_color_'
|
16
|
-
end
|
17
|
-
|
18
|
-
build :test do
|
19
|
-
save_png range: 0, prefix: 'build_groups_'
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
# Here's how you can run this on the command line:
|
25
|
-
#
|
26
|
-
# --- OSX/Linux (bash or similar shells) ---
|
27
|
-
# $ ruby build_groups.rb
|
28
|
-
# $ SQUIB_BUILD=color ruby build_groups.rb
|
29
|
-
# $ SQUIB_BUILD=print_n_play,test ruby build_groups.rb
|
30
|
-
#
|
31
|
-
# --- Windows CMD ---
|
32
|
-
# $ ruby build_groups.rb
|
33
|
-
# $ set SQUIB_BUILD=color && ruby build_groups.rb
|
34
|
-
# $ set SQUIB_BUILD=print_n_play,test && ruby build_groups.rb
|
35
|
-
#
|
36
|
-
# Or, better yet... use a Rakefile like the one provided in this gist!
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new(width: 75, height: 75, cards: 2) do
|
4
|
+
# puts "Groups enabled by environment: #{groups.to_a}"
|
5
|
+
|
6
|
+
text str: ['A', 'B']
|
7
|
+
|
8
|
+
build :print_n_play do
|
9
|
+
rect
|
10
|
+
save_sheet prefix: 'build_groups_bw_'
|
11
|
+
end
|
12
|
+
|
13
|
+
build :color do
|
14
|
+
rect stroke_color: :red, dash: '5 5'
|
15
|
+
save_png prefix: 'build_groups_color_'
|
16
|
+
end
|
17
|
+
|
18
|
+
build :test do
|
19
|
+
save_png range: 0, prefix: 'build_groups_'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
# Here's how you can run this on the command line:
|
25
|
+
#
|
26
|
+
# --- OSX/Linux (bash or similar shells) ---
|
27
|
+
# $ ruby build_groups.rb
|
28
|
+
# $ SQUIB_BUILD=color ruby build_groups.rb
|
29
|
+
# $ SQUIB_BUILD=print_n_play,test ruby build_groups.rb
|
30
|
+
#
|
31
|
+
# --- Windows CMD ---
|
32
|
+
# $ ruby build_groups.rb
|
33
|
+
# $ set SQUIB_BUILD=color && ruby build_groups.rb
|
34
|
+
# $ set SQUIB_BUILD=print_n_play,test && ruby build_groups.rb
|
35
|
+
#
|
36
|
+
# Or, better yet... use a Rakefile like the one provided in this gist!
|
data/samples/colors/_colors.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
Squib::Deck.new(width: 825, height: 1125, cards: 1) do
|
4
|
-
background color: :white
|
5
|
-
|
6
|
-
y = 0
|
7
|
-
text color: '#f00', str: '3-hex', x: 50, y: y += 50
|
8
|
-
text color: '#f00', str: '3-hex (alpha)', x: 50, y: y += 50
|
9
|
-
text color: '#ff0000', str: '6-hex', x: 50, y: y += 50
|
10
|
-
text color: '#ff000099', str: '8-hex(alpha)', x: 50, y: y += 50
|
11
|
-
text color: '#ffff00000000', str: '12-hex', x: 50, y: y += 50
|
12
|
-
text color: '#ffff000000009999', str: '12-hex (alpha)', x: 50, y: y += 50
|
13
|
-
text color: :burnt_orange, str: 'Symbols of constants too', x: 50, y: y += 50
|
14
|
-
text color: '(0,0)(400,0) blue@0.0 red@1.0', str: 'Linear gradients!', x: 50, y: y += 50
|
15
|
-
text color: '(200,500,10)(200,500,100) blue@0.0 red@1.0', str: 'Radial gradients!', x: 50, y: y += 50
|
16
|
-
# see gradients.rb sample for more on gradients
|
17
|
-
|
18
|
-
save_png prefix: 'colors_'
|
19
|
-
end
|
20
|
-
|
21
|
-
# This script generates a table of the built-in constants
|
22
|
-
colors = (Cairo::Color.constants - %i(HEX_RE Base RGB CMYK HSV X11))
|
23
|
-
colors.sort_by! do |c|
|
24
|
-
hsv = Cairo::Color.parse(c).to_hsv
|
25
|
-
[(hsv.hue / 16.0).to_i, hsv.value, hsv.saturation]
|
26
|
-
end
|
27
|
-
w, h = 300, 50
|
28
|
-
deck_height = 4000
|
29
|
-
deck_width = (colors.size / ((deck_height / h) + 1)) * w
|
30
|
-
Squib::Deck.new(width: deck_width, height: deck_height) do
|
31
|
-
background color: :white
|
32
|
-
x, y = 0, 0
|
33
|
-
colors.each_with_index do |color, i|
|
34
|
-
rect x: x, y: y, width: w, height: h, fill_color: color
|
35
|
-
text str: color.to_s, x: x + 5, y: y + 13, font: 'Sans Bold 5',
|
36
|
-
color: (Cairo::Color.parse(color).to_hsv.v > 0.9) ? '#000' : '#fff'
|
37
|
-
y += h
|
38
|
-
if y > deck_height
|
39
|
-
x += w
|
40
|
-
y = 0
|
41
|
-
end
|
42
|
-
end
|
43
|
-
save_png prefix: 'color_constants_'
|
44
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new(width: 825, height: 1125, cards: 1) do
|
4
|
+
background color: :white
|
5
|
+
|
6
|
+
y = 0
|
7
|
+
text color: '#f00', str: '3-hex', x: 50, y: y += 50
|
8
|
+
text color: '#f00', str: '3-hex (alpha)', x: 50, y: y += 50
|
9
|
+
text color: '#ff0000', str: '6-hex', x: 50, y: y += 50
|
10
|
+
text color: '#ff000099', str: '8-hex(alpha)', x: 50, y: y += 50
|
11
|
+
text color: '#ffff00000000', str: '12-hex', x: 50, y: y += 50
|
12
|
+
text color: '#ffff000000009999', str: '12-hex (alpha)', x: 50, y: y += 50
|
13
|
+
text color: :burnt_orange, str: 'Symbols of constants too', x: 50, y: y += 50
|
14
|
+
text color: '(0,0)(400,0) blue@0.0 red@1.0', str: 'Linear gradients!', x: 50, y: y += 50
|
15
|
+
text color: '(200,500,10)(200,500,100) blue@0.0 red@1.0', str: 'Radial gradients!', x: 50, y: y += 50
|
16
|
+
# see gradients.rb sample for more on gradients
|
17
|
+
|
18
|
+
save_png prefix: 'colors_'
|
19
|
+
end
|
20
|
+
|
21
|
+
# This script generates a table of the built-in constants
|
22
|
+
colors = (Cairo::Color.constants - %i(HEX_RE Base RGB CMYK HSV X11))
|
23
|
+
colors.sort_by! do |c|
|
24
|
+
hsv = Cairo::Color.parse(c).to_hsv
|
25
|
+
[(hsv.hue / 16.0).to_i, hsv.value, hsv.saturation]
|
26
|
+
end
|
27
|
+
w, h = 300, 50
|
28
|
+
deck_height = 4000
|
29
|
+
deck_width = (colors.size / ((deck_height / h) + 1)) * w
|
30
|
+
Squib::Deck.new(width: deck_width, height: deck_height) do
|
31
|
+
background color: :white
|
32
|
+
x, y = 0, 0
|
33
|
+
colors.each_with_index do |color, i|
|
34
|
+
rect x: x, y: y, width: w, height: h, fill_color: color
|
35
|
+
text str: color.to_s, x: x + 5, y: y + 13, font: 'Sans Bold 5',
|
36
|
+
color: (Cairo::Color.parse(color).to_hsv.v > 0.9) ? '#000' : '#fff'
|
37
|
+
y += h
|
38
|
+
if y > deck_height
|
39
|
+
x += w
|
40
|
+
y = 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
save_png prefix: 'color_constants_'
|
44
|
+
end
|