squib 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +62 -14
- data/Gemfile +1 -1
- data/README.md +16 -10
- data/RELEASE TODO.md +2 -1
- data/Rakefile +11 -0
- data/lib/squib/api/data.rb +3 -3
- data/lib/squib/api/image.rb +7 -5
- data/lib/squib/api/save.rb +31 -2
- data/lib/squib/api/settings.rb +1 -1
- data/lib/squib/api/shapes.rb +86 -0
- data/lib/squib/api/text.rb +6 -2
- data/lib/squib/api/text_embed.rb +7 -5
- data/lib/squib/args/typographer.rb +22 -16
- data/lib/squib/card.rb +5 -5
- data/lib/squib/conf.rb +111 -0
- data/lib/squib/constants.rb +11 -31
- data/lib/squib/deck.rb +15 -48
- data/lib/squib/graphics/cairo_context_wrapper.rb +3 -1
- data/lib/squib/graphics/gradient_regex.rb +1 -0
- data/lib/squib/graphics/hand.rb +43 -0
- data/lib/squib/graphics/image.rb +5 -3
- data/lib/squib/graphics/save_doc.rb +1 -1
- data/lib/squib/graphics/shapes.rb +74 -0
- data/lib/squib/graphics/showcase.rb +5 -2
- data/lib/squib/graphics/text.rb +18 -7
- data/lib/squib/input_helpers.rb +2 -2
- data/lib/squib/version.rb +1 -1
- data/samples/csv_import.rb +3 -5
- data/samples/custom-config.yml +0 -1
- data/samples/custom_config.rb +1 -1
- data/samples/draw_shapes.rb +11 -0
- data/samples/embed_text.rb +1 -1
- data/samples/hand.rb +24 -0
- data/samples/load_images.rb +14 -0
- data/samples/sample.csv +3 -3
- data/samples/text_options.rb +4 -0
- data/spec/api/api_data_spec.rb +19 -0
- data/spec/api/api_image_spec.rb +1 -1
- data/spec/api/api_settings_spec.rb +18 -0
- data/spec/api/api_text_spec.rb +3 -3
- data/spec/conf_spec.rb +29 -0
- data/spec/data/conf/basic.yml +0 -0
- data/spec/data/conf/empty.yml +1 -0
- data/spec/data/samples/csv_import.rb.txt +4 -38
- data/spec/data/samples/custom_config.rb.txt +4 -0
- data/spec/data/samples/draw_shapes.rb.txt +57 -0
- data/spec/data/samples/hand.rb.txt +514 -0
- data/spec/data/samples/load_images.rb.txt +6 -0
- data/spec/data/samples/text_options.rb.txt +81 -0
- data/spec/data/xlsx/basic.xlsx +0 -0
- data/spec/data/xlsx/formulas.xlsx +0 -0
- data/spec/graphics/graphics_images_spec.rb +49 -48
- data/spec/graphics/graphics_shapes_spec.rb +43 -41
- data/spec/graphics/graphics_text_spec.rb +25 -11
- data/spec/samples/_diffs/gitkeep.txt +0 -0
- data/spec/samples/expected/autoscale_00.png +0 -0
- data/spec/samples/expected/autoscale_01.png +0 -0
- data/spec/samples/expected/autoscale_02.png +0 -0
- data/spec/samples/expected/backend_00.png +0 -0
- data/spec/samples/expected/backend_00.svg +78 -0
- data/spec/samples/expected/backend_01.png +0 -0
- data/spec/samples/expected/backend_01.svg +78 -0
- data/spec/samples/expected/basic_00.png +0 -0
- data/spec/samples/expected/basic_01.png +0 -0
- data/spec/samples/expected/basic_02.png +0 -0
- data/spec/samples/expected/cairo_access_00.png +0 -0
- data/spec/samples/expected/cairo_access_01.png +0 -0
- data/spec/samples/expected/card_00.png +0 -0
- data/spec/samples/expected/card_01.png +0 -0
- data/spec/samples/expected/colors_00.png +0 -0
- data/spec/samples/expected/config_disable_text_00.png +0 -0
- data/spec/samples/expected/config_text_00.png +0 -0
- data/spec/samples/expected/custom-config_00.png +0 -0
- data/spec/samples/expected/embed_00.png +0 -0
- 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/embed_multisheet_00.png +0 -0
- data/spec/samples/expected/gitkeep.txt +0 -0
- data/spec/samples/expected/gradient_00.png +0 -0
- data/spec/samples/expected/hand.png +0 -0
- data/spec/samples/expected/hand_pretty.png +0 -0
- data/spec/samples/expected/landscape_00.png +0 -0
- data/spec/samples/expected/layout2_00.png +0 -0
- data/spec/samples/expected/layout_00.png +0 -0
- data/spec/samples/expected/layout_builtin_hand_00.png +0 -0
- data/spec/samples/expected/layout_builtin_playing_card_00.png +0 -0
- data/spec/samples/expected/load_images_00.png +0 -0
- data/spec/samples/expected/portrait_00.png +0 -0
- data/spec/samples/expected/ranges_00.png +0 -0
- data/spec/samples/expected/ranges_01.png +0 -0
- data/spec/samples/expected/ranges_02.png +0 -0
- data/spec/samples/expected/sample_csv_00.png +0 -0
- data/spec/samples/expected/sample_csv_01.png +0 -0
- data/spec/samples/expected/sample_excel_00.png +0 -0
- data/spec/samples/expected/sample_excel_01.png +0 -0
- data/spec/samples/expected/sample_excel_02.png +0 -0
- data/spec/samples/expected/save_sheet_00.png +0 -0
- data/spec/samples/expected/save_sheet_01.png +0 -0
- data/spec/samples/expected/save_sheet_range_00.png +0 -0
- data/spec/samples/expected/save_sheet_range_01.png +0 -0
- data/spec/samples/expected/save_single_sheet_00.png +0 -0
- data/spec/samples/expected/saves_notrim_01.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/expected/tgc_sample_00.png +0 -0
- data/spec/samples/expected/units_00.png +0 -0
- data/spec/samples/samples_regression_spec.rb +7 -5
- data/spec/samples/sanity.html.erb +28 -0
- data/spec/samples/sanity.rb +70 -0
- data/spec/spec_helper.rb +15 -1
- data/squib.gemspec +3 -1
- data/squib.sublime-project +27 -40
- metadata +177 -4
data/lib/squib/api/text.rb
CHANGED
@@ -37,13 +37,16 @@ module Squib
|
|
37
37
|
# @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the ink extents of the text.
|
38
38
|
# @option opts ellipsize [:none, :start, :middle, :end, true, false] (:end) When width and height are set, determines the behavior of overflowing text. Also: `true` maps to `:end` and `false` maps to `:none`. Default `:end`
|
39
39
|
# @option opts angle [FixNum] (0) Rotation of the text in radians. Note that this rotates around the upper-left corner of the text box, making the placement of x-y coordinates slightly tricky.
|
40
|
+
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle. {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
|
41
|
+
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
|
40
42
|
# @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
|
41
43
|
# @return [Array] Returns an Array of hashes keyed by :width and :height that mark the ink extents of the text rendered.
|
42
44
|
# @api public
|
43
45
|
def text(opts = {})
|
46
|
+
opts = { stroke_width: 0 }.merge(opts)
|
44
47
|
opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :wrap,
|
45
48
|
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout,
|
46
|
-
:angle, :quotes])
|
49
|
+
:angle, :quotes, :stroke_color, :stroke_width])
|
47
50
|
embed = TextEmbed.new
|
48
51
|
yield(embed) if block_given? #store the opts for later use
|
49
52
|
extents = Array.new(@cards.size)
|
@@ -53,7 +56,8 @@ module Squib
|
|
53
56
|
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
54
57
|
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
|
55
58
|
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
|
56
|
-
opts[:valign][i], opts[:hint][i], opts[:angle][i]
|
59
|
+
opts[:valign][i], opts[:hint][i], opts[:angle][i],
|
60
|
+
opts[:stroke_color][i], opts[:stroke_width][i] )
|
57
61
|
end
|
58
62
|
return extents
|
59
63
|
end
|
data/lib/squib/api/text_embed.rb
CHANGED
@@ -17,8 +17,8 @@ module Squib
|
|
17
17
|
# @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}
|
18
18
|
# @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}
|
19
19
|
# @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}
|
20
|
-
# @option opts width [Integer
|
21
|
-
# @option opts height [Integer
|
20
|
+
# @option opts width [Integer] (32) the width of the image rendered.
|
21
|
+
# @option opts height [Integer] (32) the height the height of the image rendered.
|
22
22
|
# @option opts dx [Integer] (0) "delta x", or adjust the icon horizontally by x pixels
|
23
23
|
# @option opts dy [Integer] (0) "delta y", or adjust the icon vertically by y pixels
|
24
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}
|
@@ -26,11 +26,12 @@ module Squib
|
|
26
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
27
|
# @api public
|
28
28
|
def svg(opts)
|
29
|
+
opts = { width: 32, height: 32 }.merge(opts)
|
29
30
|
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
30
31
|
# TODO: add input validation here. We need the key for example.
|
31
32
|
rule = {type: :svg}.merge(opts)
|
32
33
|
rule[:draw] = Proc.new do |card, x,y|
|
33
|
-
card.svg(rule[:file], rule[:id], x, y, rule[:width], rule[:height],
|
34
|
+
card.svg(rule[:file], rule[:data], rule[:id], x, y, rule[:width], rule[:height],
|
34
35
|
rule[:alpha], rule[:blend], rule[:angle], rule[:mask])
|
35
36
|
end
|
36
37
|
@rules[opts[:key]] = rule
|
@@ -41,8 +42,8 @@ module Squib
|
|
41
42
|
# @option opts key [String] ('*') the string to replace with the graphic. Can be multiple letters, e.g. ':tool:'
|
42
43
|
# @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}
|
43
44
|
# @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}
|
44
|
-
# @option opts width [
|
45
|
-
# @option opts height [
|
45
|
+
# @option opts width [Fixnum] (32) the width of the image rendered
|
46
|
+
# @option opts height [Fixnum] (32) the height of the image rendered
|
46
47
|
# @option opts dx [Integer] (0) "delta x", or adjust the icon horizontally by x pixels
|
47
48
|
# @option opts dy [Integer] (0) "delta y", or adjust the icon vertically by y pixels
|
48
49
|
# @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}
|
@@ -50,6 +51,7 @@ module Squib
|
|
50
51
|
# @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}
|
51
52
|
# @api public
|
52
53
|
def png(opts)
|
54
|
+
opts = { width: 32, height: 32 }.merge(opts)
|
53
55
|
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
54
56
|
# TODO: add input validation here. We need the key for example.
|
55
57
|
rule = {type: :png}.merge(opts)
|
@@ -1,15 +1,21 @@
|
|
1
1
|
require 'squib/constants'
|
2
2
|
module Squib
|
3
|
+
#@api private
|
3
4
|
module Args
|
5
|
+
# Internal class for handling arguments
|
6
|
+
#@api private
|
4
7
|
class Typographer
|
5
8
|
|
6
|
-
def initialize(config =
|
7
|
-
|
9
|
+
def initialize(config = Conf::DEFAULTS)
|
10
|
+
%w(lsquote ldquote rsquote rdquote smart_quotes
|
11
|
+
em_dash en_dash ellipsis).each do |var|
|
12
|
+
instance_variable_set("@#{var}", config[var])
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
def process(str)
|
11
|
-
str = explicit_replacements(str)
|
12
|
-
str = smart_quotes(str) if @
|
17
|
+
str = explicit_replacements(str.to_s)
|
18
|
+
str = smart_quotes(str) if @smart_quotes
|
13
19
|
str
|
14
20
|
end
|
15
21
|
|
@@ -53,58 +59,58 @@ module Squib
|
|
53
59
|
|
54
60
|
# Straightforward replace
|
55
61
|
def left_curly(str)
|
56
|
-
str.gsub('``', @
|
62
|
+
str.gsub('``', @ldquote)
|
57
63
|
end
|
58
64
|
|
59
65
|
# Straightforward replace
|
60
66
|
def right_curly(str)
|
61
|
-
str.gsub(%{''}, @
|
67
|
+
str.gsub(%{''}, @rdquote)
|
62
68
|
end
|
63
69
|
|
64
70
|
# A quote between two letters is an apostraphe
|
65
71
|
def apostraphize(str)
|
66
|
-
str.gsub(/(\w)(\')(\w)/, '\1' + @
|
72
|
+
str.gsub(/(\w)(\')(\w)/, '\1' + @rsquote + '\3')
|
67
73
|
end
|
68
74
|
|
69
75
|
# Straightforward replace
|
70
76
|
def ellipsificate(str)
|
71
|
-
str.gsub('...', @
|
77
|
+
str.gsub('...', @ellipsis)
|
72
78
|
end
|
73
79
|
|
74
80
|
# Straightforward replace
|
75
81
|
def en_dash(str)
|
76
|
-
str.gsub('--', @
|
82
|
+
str.gsub('--', @en_dash)
|
77
83
|
end
|
78
84
|
|
79
85
|
# Straightforward replace
|
80
86
|
def em_dash(str)
|
81
|
-
str.gsub('---', @
|
87
|
+
str.gsub('---', @em_dash)
|
82
88
|
end
|
83
89
|
|
84
90
|
# Quote next to non-whitespace curls
|
85
91
|
def right_double_quote(str)
|
86
|
-
str.gsub(/(\S)(\")/, '\1' + @
|
92
|
+
str.gsub(/(\S)(\")/, '\1' + @rdquote)
|
87
93
|
end
|
88
94
|
|
89
95
|
# Quote next to non-whitespace curls
|
90
96
|
def left_double_quote(str)
|
91
|
-
str.gsub(/(\")(\S)/, @
|
97
|
+
str.gsub(/(\")(\S)/, @ldquote + '\2')
|
92
98
|
end
|
93
99
|
|
94
100
|
# Handle the cases where a double quote is next to a single quote
|
95
101
|
def single_inside_double_quote(str)
|
96
|
-
str.gsub(/(\")(\')(\S)/, @
|
97
|
-
.gsub(/(\")(\')(\S)/, '\1' + @
|
102
|
+
str.gsub(/(\")(\')(\S)/, @ldquote + @lsquote + '\3')
|
103
|
+
.gsub(/(\")(\')(\S)/, '\1' + @rsquote + @rdquote)
|
98
104
|
end
|
99
105
|
|
100
106
|
# Quote next to non-whitespace curls
|
101
107
|
def right_single_quote(str)
|
102
|
-
str.gsub(/(\S)(\')/, '\1' + @
|
108
|
+
str.gsub(/(\S)(\')/, '\1' + @rsquote)
|
103
109
|
end
|
104
110
|
|
105
111
|
# Quote next to non-whitespace curls
|
106
112
|
def left_single_quote(str)
|
107
|
-
str.gsub(/(\')(\S)/, @
|
113
|
+
str.gsub(/(\')(\S)/, @lsquote + '\2')
|
108
114
|
end
|
109
115
|
|
110
116
|
end
|
data/lib/squib/card.rb
CHANGED
@@ -16,21 +16,21 @@ module Squib
|
|
16
16
|
|
17
17
|
# :nodoc:
|
18
18
|
# @api private
|
19
|
-
def initialize(deck, width, height,
|
19
|
+
def initialize(deck, width, height, index=-1)
|
20
20
|
@deck = deck
|
21
21
|
@width = width
|
22
22
|
@height = height
|
23
|
-
@backend = backend
|
23
|
+
@backend = deck.backend
|
24
24
|
@svgfile = "#{deck.dir}/#{deck.prefix}#{deck.count_format % index}.svg"
|
25
|
-
@cairo_surface = make_surface(@svgfile, backend)
|
25
|
+
@cairo_surface = make_surface(@svgfile, @backend)
|
26
26
|
@cairo_context = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(@cairo_surface))
|
27
|
-
@cairo_context.antialias =
|
27
|
+
@cairo_context.antialias = deck.antialias
|
28
28
|
end
|
29
29
|
|
30
30
|
# :nodoc:
|
31
31
|
# @api private
|
32
32
|
def make_surface(svgfile, backend)
|
33
|
-
case backend
|
33
|
+
case backend.downcase.to_sym
|
34
34
|
when :memory
|
35
35
|
Cairo::ImageSurface.new(@width, @height)
|
36
36
|
when :svg
|
data/lib/squib/conf.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'squib'
|
2
|
+
require 'forwardable'
|
3
|
+
require 'squib/args/typographer'
|
4
|
+
|
5
|
+
module Squib
|
6
|
+
# @api private
|
7
|
+
class Conf
|
8
|
+
|
9
|
+
DEFAULTS = {
|
10
|
+
'antialias' => 'best',
|
11
|
+
'backend' => 'memory',
|
12
|
+
'count_format' => SYSTEM_DEFAULTS[:count_format],
|
13
|
+
'custom_colors' => {},
|
14
|
+
'dir' => SYSTEM_DEFAULTS[:dir],
|
15
|
+
'hint' => :none,
|
16
|
+
'img_dir' => '.',
|
17
|
+
'progress_bars' => false,
|
18
|
+
'ldquote' => "\u201C", # UTF8 chars
|
19
|
+
'rdquote' => "\u201D",
|
20
|
+
'lsquote' => "\u2018",
|
21
|
+
'rsquote' => "\u2019",
|
22
|
+
'em_dash' => "\u2014",
|
23
|
+
'en_dash' => "\u2013",
|
24
|
+
'ellipsis' => "\u2026",
|
25
|
+
'smart_quotes' => true,
|
26
|
+
'text_hint' => 'off',
|
27
|
+
}
|
28
|
+
|
29
|
+
#Translate the hints to the methods.
|
30
|
+
ANTIALIAS_OPTS = {
|
31
|
+
nil => 'subpixel',
|
32
|
+
'best' => 'subpixel',
|
33
|
+
'good' => 'gray',
|
34
|
+
'fast' => 'gray',
|
35
|
+
'gray' => 'gray',
|
36
|
+
'subpixel' => 'subpixel'
|
37
|
+
}
|
38
|
+
|
39
|
+
def initialize(config_hash = DEFAULTS)
|
40
|
+
@config_hash = config_hash
|
41
|
+
@typographer = Args::Typographer.new(config_hash)
|
42
|
+
normalize_antialias
|
43
|
+
end
|
44
|
+
|
45
|
+
# Load the configuration file, if exists, overriding hardcoded defaults
|
46
|
+
# @api private
|
47
|
+
def self.load(file)
|
48
|
+
yaml = {}
|
49
|
+
if File.exists? file
|
50
|
+
Squib::logger.info { " using config: #{file}" }
|
51
|
+
yaml = YAML.load_file(file) || {}
|
52
|
+
end
|
53
|
+
Conf.new(DEFAULTS.merge(yaml))
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
"Conf: #{@config_hash.to_s}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def img_dir
|
61
|
+
@config_hash['img_dir']
|
62
|
+
end
|
63
|
+
|
64
|
+
def text_hint
|
65
|
+
@config_hash['text_hint']
|
66
|
+
end
|
67
|
+
|
68
|
+
def text_hint=(hint)
|
69
|
+
@config_hash['text_hint'] = hint
|
70
|
+
end
|
71
|
+
|
72
|
+
def progress_bars
|
73
|
+
@config_hash['progress_bars']
|
74
|
+
end
|
75
|
+
|
76
|
+
def typographer
|
77
|
+
@typographer
|
78
|
+
end
|
79
|
+
|
80
|
+
def dir
|
81
|
+
@config_hash['dir']
|
82
|
+
end
|
83
|
+
|
84
|
+
def prefix
|
85
|
+
@config_hash['prefix']
|
86
|
+
end
|
87
|
+
|
88
|
+
def count_format
|
89
|
+
@config_hash['count_format']
|
90
|
+
end
|
91
|
+
|
92
|
+
def antialias
|
93
|
+
@config_hash['antialias']
|
94
|
+
end
|
95
|
+
|
96
|
+
def backend
|
97
|
+
@config_hash['backend']
|
98
|
+
end
|
99
|
+
|
100
|
+
def custom_colors
|
101
|
+
@config_hash['custom_colors']
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def normalize_antialias
|
107
|
+
@config_hash['antialias'] = ANTIALIAS_OPTS[@config_hash['antialias'].downcase.strip]
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
data/lib/squib/constants.rb
CHANGED
@@ -6,6 +6,7 @@ module Squib
|
|
6
6
|
:align => :left,
|
7
7
|
:alpha => 1.0,
|
8
8
|
:angle => 0,
|
9
|
+
:angle_range => (Math::PI / -4.0)..(Math::PI / 4),
|
9
10
|
:blend => :none,
|
10
11
|
:color => :black,
|
11
12
|
:columns => 5,
|
@@ -14,6 +15,7 @@ module Squib
|
|
14
15
|
:cx2 => 0,
|
15
16
|
:cy1 => 0,
|
16
17
|
:cy2 => 0,
|
18
|
+
:data => nil,
|
17
19
|
:default_font => 'Arial 36',
|
18
20
|
:dir => '_output',
|
19
21
|
:dx => 0, # delta
|
@@ -28,13 +30,16 @@ module Squib
|
|
28
30
|
:gap => 0,
|
29
31
|
:height => :native,
|
30
32
|
:hint => :off,
|
33
|
+
:inner_radius => 50,
|
31
34
|
:img_dir => '.',
|
32
35
|
:justify => false,
|
33
36
|
:key => '*',
|
34
37
|
:margin => 75,
|
35
38
|
:markup => false,
|
36
39
|
:mask => nil,
|
40
|
+
:n => 5,
|
37
41
|
:offset => 1.1,
|
42
|
+
:outer_radius => 100,
|
38
43
|
:prefix => 'card_',
|
39
44
|
:progress_bar => false,
|
40
45
|
:quotes => :dumb,
|
@@ -67,37 +72,6 @@ module Squib
|
|
67
72
|
:y_radius => 0,
|
68
73
|
}
|
69
74
|
|
70
|
-
# Squib's configuration defaults
|
71
|
-
#
|
72
|
-
# @api public
|
73
|
-
CONFIG_DEFAULTS = {
|
74
|
-
'antialias' => 'best',
|
75
|
-
'backend' => 'memory',
|
76
|
-
'count_format' => SYSTEM_DEFAULTS[:count_format],
|
77
|
-
'custom_colors' => {},
|
78
|
-
'dir' => SYSTEM_DEFAULTS[:dir],
|
79
|
-
'dpi' => 300,
|
80
|
-
'hint' => :none,
|
81
|
-
'img_dir' => '.',
|
82
|
-
'progress_bar' => false,
|
83
|
-
'ldquote' => "\u201C", # UTF8 chars
|
84
|
-
'rdquote' => "\u201D",
|
85
|
-
'lsquote' => "\u2018",
|
86
|
-
'rsquote' => "\u2019",
|
87
|
-
'em_dash' => "\u2014",
|
88
|
-
'en_dash' => "\u2013",
|
89
|
-
'ellipsis' => "\u2026",
|
90
|
-
'smart_quotes' => true,
|
91
|
-
}
|
92
|
-
|
93
|
-
#Translate the hints to the methods.
|
94
|
-
ANTIALIAS_OPTS = {
|
95
|
-
'best' => 'subpixel',
|
96
|
-
'good' => 'gray',
|
97
|
-
'fast' => 'gray',
|
98
|
-
'gray' => 'gray',
|
99
|
-
'subpixel' => 'subpixel'
|
100
|
-
}
|
101
75
|
# These are parameters that are intended to be "expanded" across
|
102
76
|
# range if they are singletons.
|
103
77
|
#
|
@@ -128,16 +102,20 @@ module Squib
|
|
128
102
|
:font_size => :font_size,
|
129
103
|
:height => :height,
|
130
104
|
:hint => :hint,
|
105
|
+
:inner_radius => :inner_radius,
|
131
106
|
:justify => :justify,
|
132
107
|
:layout => :layout,
|
133
108
|
:markup => :markup,
|
134
109
|
:mask => :mask,
|
110
|
+
:n => :n,
|
111
|
+
:outer_radius => :outer_radius,
|
135
112
|
:quotes => :quotes,
|
136
113
|
:rect_radius => :radius,
|
137
114
|
:spacing => :spacing,
|
138
115
|
:str => :str,
|
139
116
|
:stroke_color => :stroke_color,
|
140
117
|
:stroke_width => :stroke_width,
|
118
|
+
:svgdata => :data,
|
141
119
|
:svgid => :id,
|
142
120
|
:valign => :valign,
|
143
121
|
:width => :width,
|
@@ -171,7 +149,9 @@ module Squib
|
|
171
149
|
:dy => :dx, # delta
|
172
150
|
:gap => :gap,
|
173
151
|
:height => :height,
|
152
|
+
:inner_radius => :inner_radius,
|
174
153
|
:margin => :margin,
|
154
|
+
:outer_radius => :outer_radius,
|
175
155
|
:paper_width => :width,
|
176
156
|
:paper_height => :height,
|
177
157
|
:rect_radius => :radius,
|
data/lib/squib/deck.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'pp'
|
3
|
+
require 'forwardable'
|
3
4
|
require 'squib'
|
4
5
|
require 'squib/card'
|
5
6
|
require 'squib/progress'
|
@@ -7,6 +8,9 @@ require 'squib/input_helpers'
|
|
7
8
|
require 'squib/constants'
|
8
9
|
require 'squib/layout_parser'
|
9
10
|
require 'squib/args/unit_conversion'
|
11
|
+
require 'squib/conf'
|
12
|
+
require 'squib/graphics/showcase'
|
13
|
+
require 'squib/graphics/hand'
|
10
14
|
|
11
15
|
# The project module
|
12
16
|
#
|
@@ -19,24 +23,19 @@ module Squib
|
|
19
23
|
class Deck
|
20
24
|
include Enumerable
|
21
25
|
include Squib::InputHelpers
|
26
|
+
extend Forwardable
|
22
27
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
attr_reader :width, :height
|
26
|
-
|
27
|
-
# :nodoc:
|
28
|
-
# @api private
|
29
|
-
attr_reader :cards
|
30
|
-
|
31
|
-
# :nodoc:
|
28
|
+
# Attributes for the width, height (in pixels) and number of cards
|
29
|
+
# These are expected to be immuatble for the life of Deck
|
32
30
|
# @api private
|
33
|
-
attr_reader :
|
31
|
+
attr_reader :width, :height, :cards
|
34
32
|
|
33
|
+
# Delegate these configuration options to the Squib::Conf object
|
34
|
+
def_delegators :conf, :antialias, :backend, :count_format, :custom_colors, :dir,
|
35
|
+
:img_dir, :prefix, :text_hint, :typographer
|
35
36
|
# :nodoc:
|
36
37
|
# @api private
|
37
|
-
attr_reader :layout, :
|
38
|
-
|
39
|
-
attr_reader :dir, :prefix, :count_format
|
38
|
+
attr_reader :layout, :conf
|
40
39
|
|
41
40
|
# Squib's constructor that sets the immutable properties.
|
42
41
|
#
|
@@ -58,24 +57,15 @@ module Squib
|
|
58
57
|
# @param block [Block] the main body of the script.
|
59
58
|
# @api public
|
60
59
|
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
|
61
|
-
@antialias = CONFIG_DEFAULTS['antialias']
|
62
60
|
@dpi = dpi
|
63
61
|
@font = SYSTEM_DEFAULTS[:default_font]
|
64
62
|
@cards = []
|
65
|
-
@
|
66
|
-
@
|
67
|
-
@progress_bar = Progress.new(false)
|
68
|
-
@text_hint = :off
|
69
|
-
@backend = :memory
|
70
|
-
@dir = SYSTEM_DEFAULTS[:dir]
|
71
|
-
@prefix = SYSTEM_DEFAULTS[:prefix]
|
72
|
-
@count_format = SYSTEM_DEFAULTS[:count_format]
|
73
|
-
@quote_chars = CONFIG_DEFAULTS.select {|k,v| %w(lsquote rsquote ldquote rdquote em_dash en_dash ellipsis smart_quotes).include?(k) }
|
63
|
+
@conf = Conf.load(config)
|
64
|
+
@progress_bar = Progress.new(@conf.progress_bars) # FIXME this is evil. Using something different with @ and non-@
|
74
65
|
show_info(config, layout)
|
75
|
-
load_config(config)
|
76
66
|
@width = Args::UnitConversion.parse width, dpi
|
77
67
|
@height = Args::UnitConversion.parse height, dpi
|
78
|
-
cards.times{ |i| @cards << Squib::Card.new(self, @width, @height,
|
68
|
+
cards.times{ |i| @cards << Squib::Card.new(self, @width, @height, i) }
|
79
69
|
@layout = LayoutParser.load_layout(layout)
|
80
70
|
if block_given?
|
81
71
|
instance_eval(&block) # here we go. wheeeee!
|
@@ -96,29 +86,6 @@ module Squib
|
|
96
86
|
@cards.each { |card| block.call(card) }
|
97
87
|
end
|
98
88
|
|
99
|
-
# Load the configuration file, if exists, overriding hardcoded defaults
|
100
|
-
# @api private
|
101
|
-
def load_config(file)
|
102
|
-
if File.exists?(file) && config = YAML.load_file(file)
|
103
|
-
Squib::logger.info { " using config: #{file}" }
|
104
|
-
config = CONFIG_DEFAULTS.merge(config)
|
105
|
-
@dpi = config['dpi'].to_i
|
106
|
-
@text_hint = config['text_hint']
|
107
|
-
@progress_bar.enabled = config['progress_bars']
|
108
|
-
@custom_colors = config['custom_colors']
|
109
|
-
@img_dir = config['img_dir']
|
110
|
-
@backend = (config['backend'].to_s.downcase.strip == 'svg') ? :svg : :memory
|
111
|
-
@dir = config['dir']
|
112
|
-
@prefix = config['prefix']
|
113
|
-
@count_format = config['count_format']
|
114
|
-
@antialias = config['antialias']
|
115
|
-
@quote_chars ||= {}
|
116
|
-
%w(lsquote rsquote ldquote rdquote smart_quotes em_dash en_dash ellipsis).each do |key|
|
117
|
-
@quote_chars[key] = config[key]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
89
|
# Use Logger to show more detail on the run
|
123
90
|
# :nodoc:
|
124
91
|
# @api private
|