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/card.rb
CHANGED
@@ -1,67 +1,67 @@
|
|
1
|
-
require 'cairo'
|
2
|
-
require 'squib/
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@svgfile = "#{deck.dir}/#{deck.prefix}#{deck.count_format % index}.svg"
|
25
|
-
@cairo_surface = make_surface(@svgfile, @backend)
|
26
|
-
@cairo_context = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(@cairo_surface))
|
27
|
-
@cairo_context.antialias = deck.antialias
|
28
|
-
end
|
29
|
-
|
30
|
-
# :nodoc:
|
31
|
-
# @api private
|
32
|
-
def make_surface(svgfile, backend)
|
33
|
-
case backend.downcase.to_sym
|
34
|
-
when :memory
|
35
|
-
Cairo::ImageSurface.new(@width, @height)
|
36
|
-
when :svg
|
37
|
-
Dir.mkdir @deck.dir unless Dir.exists?(@deck.dir)
|
38
|
-
Cairo::SVGSurface.new(svgfile, @width, @height)
|
39
|
-
else
|
40
|
-
Squib.logger.fatal "Back end not recognized: '#{backend}'"
|
41
|
-
abort
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
# A save/restore wrapper for using Cairo
|
47
|
-
# :nodoc:
|
48
|
-
# @api private
|
49
|
-
def use_cairo(&block)
|
50
|
-
@cairo_context.save
|
51
|
-
block.yield(@cairo_context)
|
52
|
-
@cairo_context.restore
|
53
|
-
end
|
54
|
-
|
55
|
-
########################
|
56
|
-
### BACKEND GRAPHICS ###
|
57
|
-
########################
|
58
|
-
require 'squib/graphics/background'
|
59
|
-
require 'squib/graphics/image'
|
60
|
-
require 'squib/graphics/save_doc'
|
61
|
-
require 'squib/graphics/save_images'
|
62
|
-
require 'squib/graphics/shapes'
|
63
|
-
require 'squib/graphics/showcase'
|
64
|
-
require 'squib/graphics/text'
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
1
|
+
require 'cairo'
|
2
|
+
require 'squib/graphics/cairo_context_wrapper'
|
3
|
+
|
4
|
+
module Squib
|
5
|
+
# Back end graphics. Private.
|
6
|
+
class Card
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
# @api private
|
10
|
+
attr_reader :width, :height, :backend, :svgfile, :index
|
11
|
+
|
12
|
+
# :nodoc:
|
13
|
+
# @api private
|
14
|
+
attr_accessor :cairo_surface, :cairo_context
|
15
|
+
|
16
|
+
# :nodoc:
|
17
|
+
# @api private
|
18
|
+
def initialize(deck, width, height, index=-1)
|
19
|
+
@deck = deck
|
20
|
+
@width = width
|
21
|
+
@height = height
|
22
|
+
@backend = deck.backend
|
23
|
+
@index = index
|
24
|
+
@svgfile = "#{deck.dir}/#{deck.prefix}#{deck.count_format % index}.svg"
|
25
|
+
@cairo_surface = make_surface(@svgfile, @backend)
|
26
|
+
@cairo_context = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(@cairo_surface))
|
27
|
+
@cairo_context.antialias = deck.antialias
|
28
|
+
end
|
29
|
+
|
30
|
+
# :nodoc:
|
31
|
+
# @api private
|
32
|
+
def make_surface(svgfile, backend)
|
33
|
+
case backend.downcase.to_sym
|
34
|
+
when :memory
|
35
|
+
Cairo::ImageSurface.new(@width, @height)
|
36
|
+
when :svg
|
37
|
+
Dir.mkdir @deck.dir unless Dir.exists?(@deck.dir)
|
38
|
+
Cairo::SVGSurface.new(svgfile, @width, @height)
|
39
|
+
else
|
40
|
+
Squib.logger.fatal "Back end not recognized: '#{backend}'"
|
41
|
+
abort
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# A save/restore wrapper for using Cairo
|
47
|
+
# :nodoc:
|
48
|
+
# @api private
|
49
|
+
def use_cairo(&block)
|
50
|
+
@cairo_context.save
|
51
|
+
block.yield(@cairo_context)
|
52
|
+
@cairo_context.restore
|
53
|
+
end
|
54
|
+
|
55
|
+
########################
|
56
|
+
### BACKEND GRAPHICS ###
|
57
|
+
########################
|
58
|
+
require 'squib/graphics/background'
|
59
|
+
require 'squib/graphics/image'
|
60
|
+
require 'squib/graphics/save_doc'
|
61
|
+
require 'squib/graphics/save_images'
|
62
|
+
require 'squib/graphics/shapes'
|
63
|
+
require 'squib/graphics/showcase'
|
64
|
+
require 'squib/graphics/text'
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
data/lib/squib/conf.rb
CHANGED
@@ -1,111 +1,117 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'squib/args/typographer'
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
def
|
107
|
-
@config_hash['
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
|
1
|
+
require 'forwardable'
|
2
|
+
require 'squib'
|
3
|
+
require 'squib/args/typographer'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Squib
|
7
|
+
# @api private
|
8
|
+
class Conf
|
9
|
+
|
10
|
+
DEFAULTS = {
|
11
|
+
'antialias' => 'best',
|
12
|
+
'backend' => 'memory',
|
13
|
+
'count_format' => SYSTEM_DEFAULTS[:count_format],
|
14
|
+
'custom_colors' => {},
|
15
|
+
'dir' => SYSTEM_DEFAULTS[:dir],
|
16
|
+
'hint' => :none,
|
17
|
+
'img_dir' => '.',
|
18
|
+
'progress_bars' => false,
|
19
|
+
'ldquote' => "\u201C", # UTF8 chars
|
20
|
+
'rdquote' => "\u201D",
|
21
|
+
'lsquote' => "\u2018",
|
22
|
+
'rsquote' => "\u2019",
|
23
|
+
'em_dash' => "\u2014",
|
24
|
+
'en_dash' => "\u2013",
|
25
|
+
'ellipsis' => "\u2026",
|
26
|
+
'smart_quotes' => true,
|
27
|
+
'text_hint' => 'off',
|
28
|
+
'warn_ellipsize'=> true,
|
29
|
+
}
|
30
|
+
|
31
|
+
#Translate the hints to the methods.
|
32
|
+
ANTIALIAS_OPTS = {
|
33
|
+
nil => 'subpixel',
|
34
|
+
'best' => 'subpixel',
|
35
|
+
'good' => 'gray',
|
36
|
+
'fast' => 'gray',
|
37
|
+
'gray' => 'gray',
|
38
|
+
'subpixel' => 'subpixel'
|
39
|
+
}
|
40
|
+
|
41
|
+
def initialize(config_hash = DEFAULTS)
|
42
|
+
@config_hash = config_hash
|
43
|
+
@typographer = Args::Typographer.new(config_hash)
|
44
|
+
normalize_antialias
|
45
|
+
end
|
46
|
+
|
47
|
+
# Load the configuration file, if exists, overriding hardcoded defaults
|
48
|
+
# @api private
|
49
|
+
def self.load(file)
|
50
|
+
yaml = {}
|
51
|
+
if File.exists? file
|
52
|
+
Squib::logger.info { " using config: #{file}" }
|
53
|
+
yaml = YAML.load_file(file) || {}
|
54
|
+
end
|
55
|
+
Conf.new(DEFAULTS.merge(yaml))
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
"Conf: #{@config_hash.to_s}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def img_dir
|
63
|
+
@config_hash['img_dir']
|
64
|
+
end
|
65
|
+
|
66
|
+
def text_hint
|
67
|
+
@config_hash['text_hint']
|
68
|
+
end
|
69
|
+
|
70
|
+
def text_hint=(hint)
|
71
|
+
@config_hash['text_hint'] = hint
|
72
|
+
end
|
73
|
+
|
74
|
+
def progress_bars
|
75
|
+
@config_hash['progress_bars']
|
76
|
+
end
|
77
|
+
|
78
|
+
def typographer
|
79
|
+
@typographer
|
80
|
+
end
|
81
|
+
|
82
|
+
def dir
|
83
|
+
@config_hash['dir']
|
84
|
+
end
|
85
|
+
|
86
|
+
def prefix
|
87
|
+
@config_hash['prefix']
|
88
|
+
end
|
89
|
+
|
90
|
+
def count_format
|
91
|
+
@config_hash['count_format']
|
92
|
+
end
|
93
|
+
|
94
|
+
def antialias
|
95
|
+
@config_hash['antialias']
|
96
|
+
end
|
97
|
+
|
98
|
+
def backend
|
99
|
+
@config_hash['backend']
|
100
|
+
end
|
101
|
+
|
102
|
+
def custom_colors
|
103
|
+
@config_hash['custom_colors']
|
104
|
+
end
|
105
|
+
|
106
|
+
def warn_ellipsize?
|
107
|
+
@config_hash['warn_ellipsize']
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def normalize_antialias
|
113
|
+
@config_hash['antialias'] = ANTIALIAS_OPTS[@config_hash['antialias'].downcase.strip]
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
data/lib/squib/constants.rb
CHANGED
@@ -1,178 +1,178 @@
|
|
1
|
-
module Squib
|
2
|
-
# Squib's defaults for when arguments are not specified in the command nor layouts.
|
3
|
-
#
|
4
|
-
# @api public
|
5
|
-
SYSTEM_DEFAULTS = {
|
6
|
-
:align => :left,
|
7
|
-
:alpha => 1.0,
|
8
|
-
:angle => 0,
|
9
|
-
:angle_range => (Math::PI / -4.0)..(Math::PI / 4),
|
10
|
-
:blend => :none,
|
11
|
-
:color => :black,
|
12
|
-
:columns => 5,
|
13
|
-
:count_format => '%02d',
|
14
|
-
:cx1 => 0,
|
15
|
-
:cx2 => 0,
|
16
|
-
:cy1 => 0,
|
17
|
-
:cy2 => 0,
|
18
|
-
:data => nil,
|
19
|
-
:default_font => 'Arial 36',
|
20
|
-
:dir => '_output',
|
21
|
-
:dx => 0, # delta
|
22
|
-
:dy => 0, # delta
|
23
|
-
:ellipsize => :end,
|
24
|
-
:face => :left,
|
25
|
-
:fill_color => '#0000',
|
26
|
-
:force_id => false,
|
27
|
-
:font => :use_set,
|
28
|
-
:font_size => nil,
|
29
|
-
:format => :png,
|
30
|
-
:gap => 0,
|
31
|
-
:height => :native,
|
32
|
-
:hint => :off,
|
33
|
-
:inner_radius => 50,
|
34
|
-
:img_dir => '.',
|
35
|
-
:justify => false,
|
36
|
-
:key => '*',
|
37
|
-
:margin => 75,
|
38
|
-
:markup => false,
|
39
|
-
:mask => nil,
|
40
|
-
:n => 5,
|
41
|
-
:offset => 1.1,
|
42
|
-
:outer_radius => 100,
|
43
|
-
:prefix => 'card_',
|
44
|
-
:progress_bar => false,
|
45
|
-
:quotes => :dumb,
|
46
|
-
:reflect_offset => 15,
|
47
|
-
:reflect_percent => 0.25,
|
48
|
-
:reflect_strength => 0.2,
|
49
|
-
:range => :all,
|
50
|
-
:rotate => false,
|
51
|
-
:rows => :infinite,
|
52
|
-
:scale => 0.85,
|
53
|
-
:sheet => 0,
|
54
|
-
:spacing => 0,
|
55
|
-
:str => '',
|
56
|
-
:stroke_color => :black,
|
57
|
-
:stroke_width => 2.0,
|
58
|
-
:trim => 0,
|
59
|
-
:trim_radius => 38,
|
60
|
-
:valign => :top,
|
61
|
-
:width => :native,
|
62
|
-
:wrap => true,
|
63
|
-
:x => 0,
|
64
|
-
:x1 => 100,
|
65
|
-
:x2 => 150,
|
66
|
-
:x3 => 100,
|
67
|
-
:x_radius => 0,
|
68
|
-
:y => 0,
|
69
|
-
:y1 => 100,
|
70
|
-
:y2 => 150,
|
71
|
-
:y3 => 150,
|
72
|
-
:y_radius => 0,
|
73
|
-
}
|
74
|
-
|
75
|
-
# These are parameters that are intended to be "expanded" across
|
76
|
-
# range if they are singletons.
|
77
|
-
#
|
78
|
-
# For example: using a different font for each card, using one `text` command
|
79
|
-
#
|
80
|
-
# key: the internal name of the param (e.g. :files)
|
81
|
-
# value: the user-facing API key (e.g. file: 'abc.png')
|
82
|
-
#
|
83
|
-
# @api private
|
84
|
-
EXPANDING_PARAMS = {
|
85
|
-
:align => :align,
|
86
|
-
:alpha => :alpha,
|
87
|
-
:angle => :angle,
|
88
|
-
:blend => :blend,
|
89
|
-
:circle_radius => :radius,
|
90
|
-
:color => :color,
|
91
|
-
:cx1 => :cx1,
|
92
|
-
:cx2 => :cx2,
|
93
|
-
:cy1 => :cy1,
|
94
|
-
:cy2 => :cy2,
|
95
|
-
:dx => :dx,
|
96
|
-
:dy => :dy,
|
97
|
-
:ellipsize => :ellipsize,
|
98
|
-
:files => :file,
|
99
|
-
:fill_color => :fill_color,
|
100
|
-
:force_svgid => :force_id,
|
101
|
-
:font => :font,
|
102
|
-
:font_size => :font_size,
|
103
|
-
:height => :height,
|
104
|
-
:hint => :hint,
|
105
|
-
:inner_radius => :inner_radius,
|
106
|
-
:justify => :justify,
|
107
|
-
:layout => :layout,
|
108
|
-
:markup => :markup,
|
109
|
-
:mask => :mask,
|
110
|
-
:n => :n,
|
111
|
-
:outer_radius => :outer_radius,
|
112
|
-
:quotes => :quotes,
|
113
|
-
:rect_radius => :radius,
|
114
|
-
:spacing => :spacing,
|
115
|
-
:str => :str,
|
116
|
-
:stroke_color => :stroke_color,
|
117
|
-
:stroke_width => :stroke_width,
|
118
|
-
:svgdata => :data,
|
119
|
-
:svgid => :id,
|
120
|
-
:valign => :valign,
|
121
|
-
:width => :width,
|
122
|
-
:wrap => :wrap,
|
123
|
-
:x => :x,
|
124
|
-
:x1 => :x1,
|
125
|
-
:x2 => :x2,
|
126
|
-
:x3 => :x3,
|
127
|
-
:x_radius => :x_radius,
|
128
|
-
:y => :y,
|
129
|
-
:y1 => :y1,
|
130
|
-
:y2 => :y2,
|
131
|
-
:y3 => :y3,
|
132
|
-
:y_radius => :y_radius,
|
133
|
-
}
|
134
|
-
|
135
|
-
# These parameters are considered for unit conversion
|
136
|
-
#
|
137
|
-
# For example
|
138
|
-
# text str: 'Hello, World', x: '1in'
|
139
|
-
#
|
140
|
-
# key: the internal name of the param (e.g. :circle_radius)
|
141
|
-
# value: the user-facing API key (e.g. radius: '1in')
|
142
|
-
UNIT_CONVERSION_PARAMS = {
|
143
|
-
:circle_radius => :radius,
|
144
|
-
:cx1 => :cx1,
|
145
|
-
:cx2 => :cx2,
|
146
|
-
:cy1 => :cy1,
|
147
|
-
:cy2 => :cy2,
|
148
|
-
:dx => :dx, # delta
|
149
|
-
:dy => :dx, # delta
|
150
|
-
:gap => :gap,
|
151
|
-
:height => :height,
|
152
|
-
:inner_radius => :inner_radius,
|
153
|
-
:margin => :margin,
|
154
|
-
:outer_radius => :outer_radius,
|
155
|
-
:paper_width => :width,
|
156
|
-
:paper_height => :height,
|
157
|
-
:rect_radius => :radius,
|
158
|
-
:spacing => :spacing,
|
159
|
-
:stroke_width => :stroke_width,
|
160
|
-
:trim => :trim,
|
161
|
-
:width => :width,
|
162
|
-
:x => :x,
|
163
|
-
:x1 => :x1,
|
164
|
-
:x2 => :x2,
|
165
|
-
:x3 => :x3,
|
166
|
-
:x_radius => :x_radius,
|
167
|
-
:y => :y,
|
168
|
-
:y1 => :y1,
|
169
|
-
:y2 => :y2,
|
170
|
-
:y3 => :y3,
|
171
|
-
:y_radius => :y_radius,
|
172
|
-
}
|
173
|
-
|
174
|
-
# Used for inch-cm conversion
|
175
|
-
# :nodoc:
|
176
|
-
# @api private
|
177
|
-
INCHES_IN_CM = 0.393700787
|
178
|
-
end
|
1
|
+
module Squib
|
2
|
+
# Squib's defaults for when arguments are not specified in the command nor layouts.
|
3
|
+
#
|
4
|
+
# @api public
|
5
|
+
SYSTEM_DEFAULTS = {
|
6
|
+
:align => :left,
|
7
|
+
:alpha => 1.0,
|
8
|
+
:angle => 0,
|
9
|
+
:angle_range => (Math::PI / -4.0)..(Math::PI / 4),
|
10
|
+
:blend => :none,
|
11
|
+
:color => :black,
|
12
|
+
:columns => 5,
|
13
|
+
:count_format => '%02d',
|
14
|
+
:cx1 => 0,
|
15
|
+
:cx2 => 0,
|
16
|
+
:cy1 => 0,
|
17
|
+
:cy2 => 0,
|
18
|
+
:data => nil,
|
19
|
+
:default_font => 'Arial 36',
|
20
|
+
:dir => '_output',
|
21
|
+
:dx => 0, # delta
|
22
|
+
:dy => 0, # delta
|
23
|
+
:ellipsize => :end,
|
24
|
+
:face => :left,
|
25
|
+
:fill_color => '#0000',
|
26
|
+
:force_id => false,
|
27
|
+
:font => :use_set,
|
28
|
+
:font_size => nil,
|
29
|
+
:format => :png,
|
30
|
+
:gap => 0,
|
31
|
+
:height => :native,
|
32
|
+
:hint => :off,
|
33
|
+
:inner_radius => 50,
|
34
|
+
:img_dir => '.',
|
35
|
+
:justify => false,
|
36
|
+
:key => '*',
|
37
|
+
:margin => 75,
|
38
|
+
:markup => false,
|
39
|
+
:mask => nil,
|
40
|
+
:n => 5,
|
41
|
+
:offset => 1.1,
|
42
|
+
:outer_radius => 100,
|
43
|
+
:prefix => 'card_',
|
44
|
+
:progress_bar => false,
|
45
|
+
:quotes => :dumb,
|
46
|
+
:reflect_offset => 15,
|
47
|
+
:reflect_percent => 0.25,
|
48
|
+
:reflect_strength => 0.2,
|
49
|
+
:range => :all,
|
50
|
+
:rotate => false,
|
51
|
+
:rows => :infinite,
|
52
|
+
:scale => 0.85,
|
53
|
+
:sheet => 0,
|
54
|
+
:spacing => 0,
|
55
|
+
:str => '',
|
56
|
+
:stroke_color => :black,
|
57
|
+
:stroke_width => 2.0,
|
58
|
+
:trim => 0,
|
59
|
+
:trim_radius => 38,
|
60
|
+
:valign => :top,
|
61
|
+
:width => :native,
|
62
|
+
:wrap => true,
|
63
|
+
:x => 0,
|
64
|
+
:x1 => 100,
|
65
|
+
:x2 => 150,
|
66
|
+
:x3 => 100,
|
67
|
+
:x_radius => 0,
|
68
|
+
:y => 0,
|
69
|
+
:y1 => 100,
|
70
|
+
:y2 => 150,
|
71
|
+
:y3 => 150,
|
72
|
+
:y_radius => 0,
|
73
|
+
}
|
74
|
+
|
75
|
+
# These are parameters that are intended to be "expanded" across
|
76
|
+
# range if they are singletons.
|
77
|
+
#
|
78
|
+
# For example: using a different font for each card, using one `text` command
|
79
|
+
#
|
80
|
+
# key: the internal name of the param (e.g. :files)
|
81
|
+
# value: the user-facing API key (e.g. file: 'abc.png')
|
82
|
+
#
|
83
|
+
# @api private
|
84
|
+
EXPANDING_PARAMS = {
|
85
|
+
:align => :align,
|
86
|
+
:alpha => :alpha,
|
87
|
+
:angle => :angle,
|
88
|
+
:blend => :blend,
|
89
|
+
:circle_radius => :radius,
|
90
|
+
:color => :color,
|
91
|
+
:cx1 => :cx1,
|
92
|
+
:cx2 => :cx2,
|
93
|
+
:cy1 => :cy1,
|
94
|
+
:cy2 => :cy2,
|
95
|
+
:dx => :dx,
|
96
|
+
:dy => :dy,
|
97
|
+
:ellipsize => :ellipsize,
|
98
|
+
:files => :file,
|
99
|
+
:fill_color => :fill_color,
|
100
|
+
:force_svgid => :force_id,
|
101
|
+
:font => :font,
|
102
|
+
:font_size => :font_size,
|
103
|
+
:height => :height,
|
104
|
+
:hint => :hint,
|
105
|
+
:inner_radius => :inner_radius,
|
106
|
+
:justify => :justify,
|
107
|
+
:layout => :layout,
|
108
|
+
:markup => :markup,
|
109
|
+
:mask => :mask,
|
110
|
+
:n => :n,
|
111
|
+
:outer_radius => :outer_radius,
|
112
|
+
:quotes => :quotes,
|
113
|
+
:rect_radius => :radius,
|
114
|
+
:spacing => :spacing,
|
115
|
+
:str => :str,
|
116
|
+
:stroke_color => :stroke_color,
|
117
|
+
:stroke_width => :stroke_width,
|
118
|
+
:svgdata => :data,
|
119
|
+
:svgid => :id,
|
120
|
+
:valign => :valign,
|
121
|
+
:width => :width,
|
122
|
+
:wrap => :wrap,
|
123
|
+
:x => :x,
|
124
|
+
:x1 => :x1,
|
125
|
+
:x2 => :x2,
|
126
|
+
:x3 => :x3,
|
127
|
+
:x_radius => :x_radius,
|
128
|
+
:y => :y,
|
129
|
+
:y1 => :y1,
|
130
|
+
:y2 => :y2,
|
131
|
+
:y3 => :y3,
|
132
|
+
:y_radius => :y_radius,
|
133
|
+
}
|
134
|
+
|
135
|
+
# These parameters are considered for unit conversion
|
136
|
+
#
|
137
|
+
# For example
|
138
|
+
# text str: 'Hello, World', x: '1in'
|
139
|
+
#
|
140
|
+
# key: the internal name of the param (e.g. :circle_radius)
|
141
|
+
# value: the user-facing API key (e.g. radius: '1in')
|
142
|
+
UNIT_CONVERSION_PARAMS = {
|
143
|
+
:circle_radius => :radius,
|
144
|
+
:cx1 => :cx1,
|
145
|
+
:cx2 => :cx2,
|
146
|
+
:cy1 => :cy1,
|
147
|
+
:cy2 => :cy2,
|
148
|
+
:dx => :dx, # delta
|
149
|
+
:dy => :dx, # delta
|
150
|
+
:gap => :gap,
|
151
|
+
:height => :height,
|
152
|
+
:inner_radius => :inner_radius,
|
153
|
+
:margin => :margin,
|
154
|
+
:outer_radius => :outer_radius,
|
155
|
+
:paper_width => :width,
|
156
|
+
:paper_height => :height,
|
157
|
+
:rect_radius => :radius,
|
158
|
+
:spacing => :spacing,
|
159
|
+
:stroke_width => :stroke_width,
|
160
|
+
:trim => :trim,
|
161
|
+
:width => :width,
|
162
|
+
:x => :x,
|
163
|
+
:x1 => :x1,
|
164
|
+
:x2 => :x2,
|
165
|
+
:x3 => :x3,
|
166
|
+
:x_radius => :x_radius,
|
167
|
+
:y => :y,
|
168
|
+
:y1 => :y1,
|
169
|
+
:y2 => :y2,
|
170
|
+
:y3 => :y3,
|
171
|
+
:y_radius => :y_radius,
|
172
|
+
}
|
173
|
+
|
174
|
+
# Used for inch-cm conversion
|
175
|
+
# :nodoc:
|
176
|
+
# @api private
|
177
|
+
INCHES_IN_CM = 0.393700787
|
178
|
+
end
|