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
@@ -0,0 +1,32 @@
|
|
1
|
+
module Squib
|
2
|
+
# @api private
|
3
|
+
module Args
|
4
|
+
class CardRange
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(input, deck_size: 1)
|
8
|
+
@range = validate(input, deck_size)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Hook into enumerable by delegating to @range
|
12
|
+
def each(&block)
|
13
|
+
@range.each { |i| block.call(i) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def size
|
17
|
+
@range.size
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def validate(input, deck_size)
|
22
|
+
input ||= :all # default
|
23
|
+
input = 0..(deck_size - 1) if input == :all
|
24
|
+
input = (input.to_i)..(input.to_i) if input.respond_to? :to_i
|
25
|
+
raise ArgumentError.new("#{input} must be Enumerable (i.e. respond_to :each).") unless input.respond_to? :each
|
26
|
+
raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size-1}") if input.max > (deck_size - 1)
|
27
|
+
input
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'squib/args/arg_loader'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
# @api private
|
5
|
+
module Args
|
6
|
+
|
7
|
+
class Coords
|
8
|
+
include ArgLoader
|
9
|
+
|
10
|
+
def self.parameters
|
11
|
+
{ x: 0, y: 0,
|
12
|
+
x1: 100, y1: 100,
|
13
|
+
x2: 150, y2: 150,
|
14
|
+
x3: 100, y3: 150,
|
15
|
+
cx1: 0 , cy1: 0,
|
16
|
+
cx2: 0 , cy2: 0,
|
17
|
+
inner_radius: 50, outer_radius: 100,
|
18
|
+
radius: 100,
|
19
|
+
n: 5, }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.expanding_parameters
|
23
|
+
parameters.keys # all of them
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.params_with_units
|
27
|
+
parameters.keys # all of them
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Squib
|
2
|
+
#@api private
|
3
|
+
module Args
|
4
|
+
module DirValidator
|
5
|
+
|
6
|
+
def ensure_dir_created(dir)
|
7
|
+
unless Dir.exists?(dir)
|
8
|
+
Squib.logger.warn "Dir '#{dir}' does not exist, creating it."
|
9
|
+
Dir.mkdir dir
|
10
|
+
end
|
11
|
+
return dir
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'cairo'
|
2
|
+
require 'squib/args/arg_loader'
|
3
|
+
require 'squib/args/color_validator'
|
4
|
+
|
5
|
+
module Squib
|
6
|
+
# @api private
|
7
|
+
module Args
|
8
|
+
|
9
|
+
class Draw
|
10
|
+
include ArgLoader
|
11
|
+
include ColorValidator
|
12
|
+
|
13
|
+
def initialize(custom_colors, dsl_method_defaults = {})
|
14
|
+
@custom_colors = custom_colors
|
15
|
+
@dsl_method_defaults = dsl_method_defaults
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parameters
|
19
|
+
{ color: :black,
|
20
|
+
fill_color: '#0000',
|
21
|
+
stroke_color: :black,
|
22
|
+
stroke_width: 2.0,
|
23
|
+
stroke_strategy: :fill_first,
|
24
|
+
join: :miter,
|
25
|
+
cap: 'butt',
|
26
|
+
dash: ''
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.expanding_parameters
|
31
|
+
parameters.keys # all of them are expandable
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.params_with_units
|
35
|
+
[:stroke_width]
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_join(arg, _i)
|
39
|
+
case arg.to_s.strip.downcase
|
40
|
+
when 'miter'
|
41
|
+
Cairo::LINE_JOIN_MITER
|
42
|
+
when 'round'
|
43
|
+
Cairo::LINE_JOIN_ROUND
|
44
|
+
when 'bevel'
|
45
|
+
Cairo::LINE_JOIN_BEVEL
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_cap(arg, _i)
|
50
|
+
case arg.to_s.strip.downcase
|
51
|
+
when 'butt'
|
52
|
+
Cairo::LINE_CAP_BUTT
|
53
|
+
when 'round'
|
54
|
+
Cairo::LINE_CAP_ROUND
|
55
|
+
when 'square'
|
56
|
+
Cairo::LINE_CAP_SQUARE
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_dash(arg, _i)
|
61
|
+
arg.to_s.split.collect do |x|
|
62
|
+
convert_unit(x, @dpi).to_f
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_fill_color(arg, _i)
|
67
|
+
colorify(arg, @custom_colors)
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate_stroke_color(arg, _i)
|
71
|
+
colorify(arg, @custom_colors)
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate_color(arg, _i)
|
75
|
+
colorify(arg, @custom_colors)
|
76
|
+
end
|
77
|
+
|
78
|
+
def validate_stroke_strategy(arg, _i)
|
79
|
+
case arg.to_s.downcase.strip
|
80
|
+
when 'fill_first'
|
81
|
+
:fill_first
|
82
|
+
when 'stroke_first'
|
83
|
+
:stroke_first
|
84
|
+
else
|
85
|
+
raise "Only 'stroke_first' or 'fill_first' allowed"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'squib/args/arg_loader'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
# @api private
|
5
|
+
module Args
|
6
|
+
|
7
|
+
class EmbedAdjust
|
8
|
+
include ArgLoader
|
9
|
+
|
10
|
+
def self.parameters
|
11
|
+
{ dx: 0, dy: 0 }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.expanding_parameters
|
15
|
+
parameters.keys # all of them
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.params_with_units
|
19
|
+
parameters.keys # all of them
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'cairo'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
# @api private
|
5
|
+
module Args
|
6
|
+
|
7
|
+
class HandSpecial
|
8
|
+
include ArgLoader
|
9
|
+
|
10
|
+
def initialize(card_height)
|
11
|
+
@card_height = card_height
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.parameters
|
15
|
+
{
|
16
|
+
angle_range: (Math::PI / -4.0)..(Math::PI / 4),
|
17
|
+
radius: :auto
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.expanding_parameters
|
22
|
+
[] # none of them
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.params_with_units
|
26
|
+
[ :radius ]
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_radius(arg)
|
30
|
+
return 0.3 * @card_height if arg.to_s.downcase.strip == 'auto'
|
31
|
+
arg
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'squib/args/arg_loader'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
# @api private
|
5
|
+
module Args
|
6
|
+
|
7
|
+
class InputFile
|
8
|
+
include ArgLoader
|
9
|
+
|
10
|
+
def initialize(dsl_method_default = {})
|
11
|
+
@dsl_method_default = dsl_method_default
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.parameters
|
15
|
+
{ file: nil,
|
16
|
+
sheet: 0,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.expanding_parameters
|
21
|
+
parameters.keys # all of them
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.params_with_units
|
25
|
+
[] # none of them
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate_file(arg, _i)
|
29
|
+
return nil if arg.nil?
|
30
|
+
raise "File #{File.expand_path(arg)} does not exist!" unless File.exists?(arg)
|
31
|
+
File.expand_path(arg)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'cairo'
|
2
|
+
require 'squib/args/arg_loader'
|
3
|
+
require 'squib/args/color_validator'
|
4
|
+
|
5
|
+
module Squib
|
6
|
+
# @api private
|
7
|
+
module Args
|
8
|
+
class Paint
|
9
|
+
include ArgLoader
|
10
|
+
include ColorValidator
|
11
|
+
|
12
|
+
def self.parameters
|
13
|
+
{ alpha: 1.0,
|
14
|
+
blend: :none,
|
15
|
+
mask: nil,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def self.expanding_parameters
|
21
|
+
parameters.keys # all of them are expandable
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.params_with_units
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(custom_colors)
|
29
|
+
@custom_colors = custom_colors
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate_alpha(arg, _i)
|
33
|
+
raise 'alpha must respond to to_f' unless arg.respond_to? :to_f
|
34
|
+
arg.to_f
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_mask(arg, _i)
|
38
|
+
colorify(arg, @custom_colors)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'squib/args/arg_loader'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
# @api private
|
5
|
+
module Args
|
6
|
+
|
7
|
+
class Paragraph
|
8
|
+
include ArgLoader
|
9
|
+
|
10
|
+
|
11
|
+
def self.parameters
|
12
|
+
{ align: :left,
|
13
|
+
str: 'Hello, World!',
|
14
|
+
font: :use_set,
|
15
|
+
font_size: nil,
|
16
|
+
markup: false,
|
17
|
+
justify: false,
|
18
|
+
wrap: true,
|
19
|
+
ellipsize: :end,
|
20
|
+
spacing: nil,
|
21
|
+
valign: :top,
|
22
|
+
hint: :off
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.expanding_parameters
|
27
|
+
parameters.keys # all of them
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.params_with_units
|
31
|
+
[] # none of them
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(deck_font)
|
35
|
+
@deck_font = deck_font
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_str(arg, _i)
|
39
|
+
arg.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
def validate_font(arg, _i)
|
43
|
+
arg = @deck_font if arg == :use_set
|
44
|
+
arg = Squib::SYSTEM_DEFAULTS[:default_font] if arg == :default
|
45
|
+
arg
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_align(arg, _i)
|
49
|
+
case arg.to_s.downcase.strip
|
50
|
+
when 'left'
|
51
|
+
Pango::ALIGN_LEFT
|
52
|
+
when 'right'
|
53
|
+
Pango::ALIGN_RIGHT
|
54
|
+
when 'center'
|
55
|
+
Pango::ALIGN_CENTER
|
56
|
+
else
|
57
|
+
raise ArgumentError, 'align must be one of: center, left, right'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def validate_wrap(arg, _i)
|
62
|
+
case arg.to_s.downcase.strip
|
63
|
+
when 'word'
|
64
|
+
Pango::Layout::WRAP_WORD
|
65
|
+
when 'char', 'false'
|
66
|
+
Pango::Layout::WRAP_CHAR
|
67
|
+
when 'word_char', 'true'
|
68
|
+
Pango::Layout::WRAP_WORD_CHAR
|
69
|
+
else
|
70
|
+
raise ArgumentError, 'wrap must be one of: word, char, word_char, true, or false'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate_ellipsize(arg, _i)
|
75
|
+
case arg.to_s.downcase.strip
|
76
|
+
when 'none', 'false'
|
77
|
+
Pango::Layout::ELLIPSIZE_NONE
|
78
|
+
when 'start'
|
79
|
+
Pango::Layout::ELLIPSIZE_START
|
80
|
+
when 'middle'
|
81
|
+
Pango::Layout::ELLIPSIZE_MIDDLE
|
82
|
+
when 'end', 'true'
|
83
|
+
Pango::Layout::ELLIPSIZE_END
|
84
|
+
else
|
85
|
+
raise ArgumentError, 'ellipsize must be one of: none, start, middle, end, true, or false'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def validate_justify(arg, _i)
|
90
|
+
case arg
|
91
|
+
when nil, true, false
|
92
|
+
arg
|
93
|
+
else
|
94
|
+
raise ArgumentError, 'justify must be one of: nil, true, or false'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def validate_spacing(arg, _i)
|
99
|
+
return nil if arg.nil?
|
100
|
+
raise ArgumentError, 'spacing must be a number or nil' unless arg.respond_to? :to_f
|
101
|
+
arg.to_f * Pango::SCALE
|
102
|
+
end
|
103
|
+
|
104
|
+
def validate_valign(arg, _i)
|
105
|
+
if %w(top middle bottom).include? arg.to_s.downcase
|
106
|
+
arg.to_s.downcase
|
107
|
+
else
|
108
|
+
raise ArgumentError, 'valign must be one of: top, middle, bottom'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|