squib 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/CHANGELOG.md +10 -0
  4. data/README.md +44 -21
  5. data/Rakefile +74 -1
  6. data/benchmarks/shiny-purse.png +0 -0
  7. data/benchmarks/spanner.svg +91 -0
  8. data/benchmarks/tons_of_png.rb +6 -0
  9. data/benchmarks/tons_of_svg.rb +7 -0
  10. data/benchmarks/tons_of_text.rb +8 -0
  11. data/lib/squib/api/background.rb +1 -1
  12. data/lib/squib/api/image.rb +6 -4
  13. data/lib/squib/api/save.rb +4 -3
  14. data/lib/squib/api/shapes.rb +7 -7
  15. data/lib/squib/api/text.rb +1 -1
  16. data/lib/squib/args/unit_conversion.rb +21 -0
  17. data/lib/squib/card.rb +2 -1
  18. data/lib/squib/constants.rb +8 -0
  19. data/lib/squib/deck.rb +14 -12
  20. data/lib/squib/graphics/background.rb +1 -1
  21. data/lib/squib/graphics/cairo_context_wrapper.rb +42 -0
  22. data/lib/squib/graphics/gradient_regex.rb +46 -0
  23. data/lib/squib/graphics/image.rb +17 -7
  24. data/lib/squib/graphics/save_doc.rb +16 -13
  25. data/lib/squib/graphics/save_images.rb +4 -4
  26. data/lib/squib/graphics/shapes.rb +7 -7
  27. data/lib/squib/graphics/text.rb +1 -1
  28. data/lib/squib/input_helpers.rb +8 -8
  29. data/lib/squib/version.rb +1 -1
  30. data/samples/colors.rb +22 -1
  31. data/samples/glass-heart.svg +52 -0
  32. data/samples/gradients.rb +34 -0
  33. data/samples/load_images.rb +14 -0
  34. data/samples/saves.rb +5 -0
  35. data/spec/api/api_image_spec.rb +2 -2
  36. data/spec/args/unit_conversion_spec.rb +22 -0
  37. data/spec/data/samples/autoscale_font.rb.txt +9 -9
  38. data/spec/data/samples/basic.rb.txt +24 -24
  39. data/spec/data/samples/cairo_access.rb.txt +4 -4
  40. data/spec/data/samples/csv_import.rb.txt +10 -10
  41. data/spec/data/samples/custom_config.rb.txt +3 -3
  42. data/spec/data/samples/draw_shapes.rb.txt +8 -8
  43. data/spec/data/samples/excel.rb.txt +15 -15
  44. data/spec/data/samples/gradients.rb.txt +65 -0
  45. data/spec/data/samples/hello_world.rb.txt +4 -4
  46. data/spec/data/samples/load_images.rb.txt +30 -4
  47. data/spec/data/samples/portrait-landscape.rb.txt +6 -6
  48. data/spec/data/samples/ranges.rb.txt +30 -30
  49. data/spec/data/samples/saves.rb.txt +74 -70
  50. data/spec/data/samples/showcase.rb.txt +20 -20
  51. data/spec/data/samples/text_options.rb.txt +63 -63
  52. data/spec/data/samples/tgc_proofs.rb.txt +8 -8
  53. data/spec/data/samples/units.rb.txt +8 -8
  54. data/spec/deck_spec.rb +6 -0
  55. data/spec/graphics/cairo_context_wrapper_spec.rb +75 -0
  56. data/spec/graphics/graphics_images_spec.rb +5 -6
  57. data/spec/input_helpers_spec.rb +11 -9
  58. data/spec/samples/samples_regression_spec.rb +3 -1
  59. data/spec/spec_helper.rb +1 -0
  60. metadata +20 -5
  61. data/spec/data/samples/colors.rb.txt +0 -124
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c3a21f564c6f39f4cdd9ac84826e2dd76df1c9e
4
- data.tar.gz: dd923de21db270d9e71b5a06752a0a55390feffd
3
+ metadata.gz: b78f6ac8982e7aec43208726ad1e5160a9417a39
4
+ data.tar.gz: a22fe5b8bb4347867c89f2d675c410166f104633
5
5
  SHA512:
6
- metadata.gz: 0eab4d96556c539261b0ca346d56af96331d968a3a828826d1172315821ffe3364a5070cf868a4b837775b70ca902e51fd2f9bc194069f10bb99d1675a005549
7
- data.tar.gz: c654ed7a07aa5958861b4033066fd64b1cf2e3a114a1e372fca0b58c8b8b40ec6a454fc461e5ba7d5eb60a871e677564bed71466f31f59245e5fec5062aaeca9
6
+ metadata.gz: 86637107259a7b2051c8d85624070859e7084b0830979acc8a537f32f0a9ba38d9c2ed2718b4b5b8b20a5b41e71ee864ec39beea28b4eeb21f785054c1a224cb
7
+ data.tar.gz: 77f4a6dbc532038583ad321f47795fc0452af6e310b327d5302493fb5d567fe30b469e42984b3a34e1b8c7883592508b998ad5df1ec238c3e13ffacb61d13822
data/.gitignore CHANGED
@@ -27,4 +27,6 @@ samples/_img
27
27
  samples/_output/*.png
28
28
  samples/_output/*.pdf
29
29
  samples/_output/foo
30
- rubocop.txt
30
+ rubocop.txt
31
+ benchmarks/_output/*.png
32
+ benchmarks/_output/*.pdf
@@ -1,5 +1,15 @@
1
1
  # Squib CHANGELOG
2
2
 
3
+ ## v0.3.0a
4
+ * Masks! The `png` and `svg` commands can be used as if they are a mask, so you can color the icon with any color you like. Can be handy for switching to black-and-white, or for reusing the same image but different colors across cards.
5
+ * Gradients! Can now specify linear or radial gradients anywhere you specify colors. See README and `samples/gradients.rb` for more details.
6
+ * Number padding! `save_png` will now pad zeros on the filenames for friendlier sorting. You can also specify your own with `count_format` using the classical format string from Ruby's `Kernel::sprintf` (mostly just C-style format strings). Default: `'%02d'. The `prefix:` option is still there too.
7
+ * Added unit conversion to `Squib::New` and `save_pdf`
8
+ * Added arbitrary paper sizes to `save_pdf`
9
+ * Added new sample table for color viewing constants in `samples/colors.rb`
10
+
11
+ Special thanks to [Shalom Craimer](https://github.com/scraimer) for the idea and proof-of-concept on gradient and mask features!
12
+
3
13
  ## v0.2.0
4
14
  * Added `showcase` feature to create a fancy-looking 3D reflection to showcase your cards. Documented, tested, and added a sample for it.
5
15
  * Added a basic Rakefile, documented in README.
data/README.md CHANGED
@@ -151,15 +151,35 @@ By default, Squib thinks in pixels. This decision was made so that we can have p
151
151
 
152
152
  {include:file:samples/units.rb}
153
153
 
154
- Note: we do not support unit conversion on `save_pdf` and `Squib::Deck.new()`, [yet](https://github.com/andymeneely/squib/issues/21)
154
+ Note: we do not support unit conversion on `save_pdf` and `Squib::Deck.new()`, [yet](https://github.com/andymeneely/squib/issues/21). We are also working on support for unit conversion within layout parsing, so using it as a part of `extends` is not yet supported.
155
155
 
156
- ## Specifying Colors
156
+ ## Specifying Colors & Gradients
157
157
 
158
158
  Colors can be specified in a wide variety of ways, mostly in a hex-string. Take a look at the examples from `samples/colors.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
159
159
 
160
160
  {include:file:samples/colors.rb}
161
161
 
162
- Under the hood, Squib uses the `rcairo` [color parser](https://github.com/rcairo/rcairo/blob/master/lib/cairo/color.rb) to accept a variety of color specifications, along with over [300 pre-defined constants](https://github.com/rcairo/rcairo/blob/master/lib/cairo/colors.rb).
162
+ Under the hood, Squib uses the `rcairo` [color parser](https://github.com/rcairo/rcairo/blob/master/lib/cairo/color.rb) to accept a variety of color specifications, along with over [300 pre-defined constants](https://github.com/rcairo/rcairo/blob/master/lib/cairo/colors.rb). The above sample will generate a table of such constants.
163
+
164
+ Additionally, in most places where colors are allowed, you may also supply a string that defines a gradient. Squib supports two flavors of gradients: linear and radial. Gradients are specified by supplying some xy coordinates, which are relative to the card (not the command). Each stop must be between 0.0 and 1.0, and you can supply as many as you like. Colors can be specified as above (in any of the hex notations or built-in constant). If you add two (or more) colors at the same stop, then the gradient keeps the colors in the in order specified and treats it like sharp transition.
165
+
166
+ The format for gradient strings look like this:
167
+
168
+ Linear:
169
+ ```
170
+ (x1,y1)(x2,y2) color1@stop1 color2@stop2
171
+ ```
172
+ The xy coordinates define the angle of the gradient.
173
+
174
+ Radial:
175
+ ```
176
+ (x1,y1,radius1)(x2,y2,radius2) color1@stop1 color2@stop2
177
+ ```
178
+ The coordinates specify an inner circle first, then an outer circle.
179
+
180
+ Check out the following sample from `samples/gradients.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
181
+
182
+ {include:file:samples/gradients.rb}
163
183
 
164
184
  ## Specifying Files
165
185
 
@@ -183,30 +203,19 @@ Layouts also allow merging, extending, and combining layouts. The sample demonst
183
203
 
184
204
  {include:file:samples/layouts.rb}
185
205
 
186
- ### Merge Keys and `extends`
187
-
188
- Since Layouts are in Yaml, we have the full power of that data format. One particular feature you should look into are ["merge keys"](http://www.yaml.org/YAML_for_ruby.html#merge_key). With merge keys, you can define base styles in one entry, then include those keys elsewhere. For example:
189
-
190
- ```yaml
191
- icon: &icon
192
- width: 50
193
- height: 50
194
- icon_left
195
- <<: *icon
196
- x: 100
197
- # The layout for icon_left will have the width/height from icon!
198
- ```
206
+ ### Special key: `extends`
199
207
 
200
- Also!! Squib provides a more feature-rich way of merging: the `extends` key in layouts. When defining an extends key, we can merge in another key and modify data coming in if we want to. This allows us to do things like set an inner object that changes its location based on its parent.
208
+ Squib provides a way of reusing layouts with the special `extends` key. When defining an `extends` key, we can merge in another key and modify data coming in if we want to. This allows us to do things like set an inner object that changes its location based on its parent.
201
209
 
202
210
  ```yaml
203
- yin:
211
+ attack:
204
212
  x: 100
205
213
  y: 100
206
214
  radius: 100
207
- yang:
208
- extends: yin
215
+ defend:
216
+ extends: attack
209
217
  x: += 50
218
+ #defend now is {:x => 150, :y => 100}
210
219
  ```
211
220
 
212
221
  Furthermore, if you want to extend multiple parents, it looks like this:
@@ -214,7 +223,7 @@ Furthermore, if you want to extend multiple parents, it looks like this:
214
223
  ```yaml
215
224
  socrates:
216
225
  x: 100
217
- aristotle:
226
+ plato:
218
227
  y: 200
219
228
  aristotle:
220
229
  extends:
@@ -223,6 +232,20 @@ aristotle:
223
232
  x: += 50
224
233
  ```
225
234
 
235
+ Note that extends keys are similar to Yaml's ["merge keys"](http://www.yaml.org/YAML_for_ruby.html#merge_key). With merge keys, you can define base styles in one entry, then include those keys elsewhere. For example:
236
+
237
+ ```yaml
238
+ icon: &icon
239
+ width: 50
240
+ height: 50
241
+ icon_left
242
+ <<: *icon
243
+ x: 100
244
+ # The layout for icon_left will have the width/height from icon!
245
+ ```
246
+
247
+ If you use both `extends` and Yaml merge keys, the Yaml merge keys are processed first, then extends. For clarity, however, you're probably just better off using `extends` instead.
248
+
226
249
  ### Multiple layout files
227
250
 
228
251
  Squib also supports the combination of multiple layout files. As shown in the above example, if you provide an `Array` of files then Squib will merge them sequentially. Colliding keys will be completely re-defined by the later file. Extends is processed after _each file_. YAML merge keys are NOT supported across multiple files - use extends instead. Here's a demonstrative example:
data/Rakefile CHANGED
@@ -1,12 +1,85 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'yard'
4
+ require 'benchmark'
4
5
 
5
6
  task default: [:install, :spec]
6
7
 
8
+ # Useful for hooking up with SublimeText.
9
+ # e.g. rake sample[basic.rb]
10
+ task :run,[:file] => :install do |t, args|
11
+ args.with_defaults(file: 'basic.rb')
12
+ Dir.chdir('samples') do
13
+ puts "Running samples/#{args[:file]}"
14
+ load args[:file]
15
+ end
16
+ end
17
+
18
+
7
19
  RSpec::Core::RakeTask.new(:spec)
8
20
 
9
- YARD::Rake::YardocTask.new(:doc) do |t|
21
+ task doc: [:yarddoc, :apply_google_analytics]
22
+
23
+ YARD::Rake::YardocTask.new(:yarddoc) do |t|
10
24
  t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional
11
25
  #t.options = ['--any', '--extra', '--opts'] # optional
12
26
  end
27
+
28
+ task benchmark: [:install] do
29
+ Squib::logger.level = Logger::ERROR #silence warnings
30
+ Dir.chdir('benchmarks') do
31
+ Benchmark.bm(15) do |bm|
32
+ Dir['*.rb'].each do | script |
33
+ GC.start
34
+ bm.report(script) { load script }
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ task :apply_google_analytics do
41
+ # The string to replace in the html document. This is chosen to be the end
42
+ # body </body> tag. So the script can be injected as the last thing in the
43
+ # document body.
44
+ string_to_replace = "</body>"
45
+ # This is the string to replace with. It include the google analytics script
46
+ # as well as the end </body> tag.
47
+ string_to_replace_with = <<-EOF
48
+ <script>
49
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
50
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
51
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
52
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
53
+
54
+ ga('create', 'UA-54811605-1', 'auto');
55
+ ga('send', 'pageview');
56
+
57
+ </script>
58
+ </body>
59
+ EOF
60
+
61
+ files = Dir.glob("doc/**/*.html")
62
+
63
+ files.each do |html_file|
64
+ puts "Processing file: #{html_file}"
65
+ contents = ""
66
+ # Read the file contents
67
+ file = File.open(html_file)
68
+ file.each { |line| contents << line }
69
+ file.close
70
+
71
+ # If the file already has google analytics tracking info, skip it.
72
+ if contents.include?(string_to_replace_with)
73
+ puts "Skipped..."
74
+ next
75
+ end
76
+
77
+ # Apply google analytics tracking info to the html file
78
+ contents.gsub!(string_to_replace, string_to_replace_with)
79
+
80
+ # Write the contents with the google analytics info to the file
81
+ file = File.open(html_file, "w")
82
+ file.write(contents)
83
+ file.close
84
+ end
85
+ end
@@ -0,0 +1,91 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg
3
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
4
+ xmlns:cc="http://creativecommons.org/ns#"
5
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6
+ xmlns:svg="http://www.w3.org/2000/svg"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
9
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
10
+ viewBox="0 0 128 128"
11
+ id="svg2"
12
+ version="1.1"
13
+ inkscape:version="0.48.3.1 r9886"
14
+ width="100%"
15
+ height="100%"
16
+ sodipodi:docname="spanner.svg">
17
+ <metadata
18
+ id="metadata18">
19
+ <rdf:RDF>
20
+ <cc:Work
21
+ rdf:about="">
22
+ <dc:format>image/svg+xml</dc:format>
23
+ <dc:type
24
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
25
+ </cc:Work>
26
+ </rdf:RDF>
27
+ </metadata>
28
+ <defs
29
+ id="defs16" />
30
+ <sodipodi:namedview
31
+ pagecolor="#ffffff"
32
+ bordercolor="#666666"
33
+ borderopacity="1"
34
+ objecttolerance="10"
35
+ gridtolerance="10"
36
+ guidetolerance="10"
37
+ inkscape:pageopacity="0"
38
+ inkscape:pageshadow="2"
39
+ inkscape:window-width="1280"
40
+ inkscape:window-height="1002"
41
+ id="namedview14"
42
+ showgrid="false"
43
+ inkscape:zoom="2.8284271"
44
+ inkscape:cx="98.928938"
45
+ inkscape:cy="62.194589"
46
+ inkscape:window-x="1912"
47
+ inkscape:window-y="-8"
48
+ inkscape:window-maximized="1"
49
+ inkscape:current-layer="g3767"
50
+ inkscape:document-units="in"
51
+ units="px"
52
+ showguides="true"
53
+ inkscape:guide-bbox="true" />
54
+ <g
55
+ id="g3767"
56
+ transform="matrix(0.24961486,0,0,0.24961486,0.197194,96.049335)">
57
+ <rect
58
+ ry="67.108368"
59
+ y="-378.68747"
60
+ x="5.3126979"
61
+ height="501.3746"
62
+ width="501.3746"
63
+ id="backdrop"
64
+ style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10.62539577;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
65
+ inkscape:label="#rect3765" />
66
+ <path
67
+ style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
68
+ d="M 36.267098,-7.709219 C 16.393265,5.1318032 3.2161811,27.462365 3.2161811,52.884128 c 0,39.825874 32.2852369,72.111092 72.1110909,72.111092 23.870397,0 44.964938,-11.67699 58.089488,-29.545518 -11.26063,7.275808 -24.65607,11.517748 -39.060173,11.517748 -39.825853,0 -72.11109,-32.285221 -72.11109,-72.111095 0,-15.95546 5.248882,-30.6218942 14.021601,-42.565574 z"
69
+ id="path3790"
70
+ inkscape:connector-curvature="0" />
71
+ <g
72
+ id="g6"
73
+ transform="matrix(18.68858,0,0,18.68858,-3385.6437,-2608.3849)">
74
+ <path
75
+ style="fill:#ffffff"
76
+ inkscape:connector-curvature="0"
77
+ id="path8"
78
+ d="m 192.2325,129.3203 -10,10 v 5.5625 h 5.375 l 10.0938,-10.0938 -5.4688,-5.4688 z" />
79
+ <path
80
+ style="fill:#ffffff;stroke:#000000"
81
+ inkscape:connector-curvature="0"
82
+ id="path10"
83
+ d="m 181.7796,141.8591 15.6196,-15.6178 m 3.349,3.3486 -15.8051,15.8032" />
84
+ <path
85
+ style="fill:#ffffff"
86
+ inkscape:connector-curvature="0"
87
+ id="path12"
88
+ d="m 201.2023,119.7104 c -2.8283,-0.73 -5.9623,-0.004 -8.1759,2.2097 -3.3293,3.3292 -3.3293,8.7358 -2e-5,12.065 3.32928,3.3292 8.7358,3.3292 12.065,0 2.216,-2.216 2.9436,-5.3452 2.2097,-8.1759 l -5.6348,5.6348 -4.8172,-1.2816 -1.2816,-4.8171 5.6348,-5.6348 z" />
89
+ </g>
90
+ </g>
91
+ </svg>
@@ -0,0 +1,6 @@
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 200) do
4
+ png file: 'shiny-purse.png'
5
+ save_png prefix: 'tons_of_png_'
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 200) do
4
+ svg file: 'spanner.svg',
5
+ width: 400, height: 400
6
+ save_png prefix: 'tons_of_svg_'
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 200) do
4
+ text str: 'tweedle beetle battle ' * 250,
5
+ font: 'Sans bold 12', width: 825,
6
+ ellipsize: false
7
+ save_png prefix: 'tons_of_text_'
8
+ end
@@ -7,7 +7,7 @@ module Squib
7
7
  # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
8
8
  #
9
9
  # @option opts range [Enumerable] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
10
- # @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors Specifying Colors}.
10
+ # @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
11
11
  # @return [nil] nothing
12
12
  # @api public
13
13
  def background(opts = {})
@@ -17,16 +17,17 @@ module Squib
17
17
  # @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}
18
18
  # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
19
19
  # @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}
20
+ # @option opts mask [String] (nil) If specified, the image will be used as a mask for the given color/gradient. Transparent pixels are ignored, opaque pixels are the given color.
20
21
  # @return [nil] Returns nil
21
22
  # @api public
22
23
  def png(opts = {})
23
- opts = needs(opts, [:range, :files, :x, :y, :width, :height, :alpha, :layout, :blend, :angle])
24
+ opts = needs(opts, [:range, :files, :x, :y, :width, :height, :alpha, :layout, :blend, :angle, :mask])
24
25
  Dir.chdir(@img_dir) do
25
26
  @progress_bar.start('Loading PNG(s)', opts[:range].size) do |bar|
26
27
  opts[:range].each do |i|
27
28
  @cards[i].png(opts[:file][i],
28
29
  opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
29
- opts[:alpha][i], opts[:blend][i], opts[:angle][i])
30
+ opts[:alpha][i], opts[:blend][i], opts[:angle][i], opts[:mask][i])
30
31
  bar.increment
31
32
  end
32
33
  end
@@ -51,16 +52,17 @@ module Squib
51
52
  # @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}
52
53
  # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
53
54
  # @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}
55
+ # @option opts mask [String] (nil) If specified, the image will be used as a mask for the given color/gradient. Transparent pixels are ignored, opaque pixels are the given color.
54
56
  # @return [nil] Returns nil
55
57
  # @api public
56
58
  def svg(opts = {})
57
- p = needs(opts,[:range, :files, :svgid, :force_svgid, :x, :y, :width, :height, :layout, :alpha, :blend, :angle])
59
+ p = needs(opts,[:range, :files, :svgid, :force_svgid, :x, :y, :width, :height, :layout, :alpha, :blend, :angle, :mask])
58
60
  Dir.chdir(@img_dir) do
59
61
  @progress_bar.start('Loading SVG(s)', p[:range].size) do |bar|
60
62
  p[:range].each do |i|
61
63
  unless p[:force_id][i] && p[:id][i].to_s.empty?
62
64
  @cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
63
- p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i], p[:angle][i])
65
+ p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i], p[:angle][i],p[:mask][i])
64
66
  end
65
67
  bar.increment
66
68
  end
@@ -25,14 +25,15 @@ module Squib
25
25
  # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
26
26
  # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
27
27
  # @option opts [String] prefix (card_) the prefix of the file name to be printed.
28
+ # @option opts [String] count_format (%02d) the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for Kernel::sprintf for specifics)
28
29
  # @option opts [Boolean, :clockwise, :counterclockwise] rotate (false) if true, the saved cards will be rotated 90 degrees clockwise. Or, rotate by the number of radians. Intended to rendering landscape instead of portrait.
29
30
  # @return [nil] Returns nothing
30
31
  # @api public
31
32
  def save_png(opts = {})
32
- opts = needs(opts,[:range, :creatable_dir, :prefix, :rotate])
33
+ opts = needs(opts,[:range, :creatable_dir, :prefix, :count_format, :rotate])
33
34
  @progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*", @cards.size) do |bar|
34
35
  opts[:range].each do |i|
35
- @cards[i].save_png(i, opts[:dir], opts[:prefix], opts[:rotate], opts[:angle])
36
+ @cards[i].save_png(i, opts[:dir], opts[:prefix], opts[:count_format], opts[:rotate], opts[:angle])
36
37
  bar.increment
37
38
  end
38
39
  end
@@ -61,7 +62,7 @@ module Squib
61
62
  # @api public
62
63
  def showcase(opts = {})
63
64
  opts = {file: 'showcase.png', fill_color: :white}.merge(opts)
64
- opts = needs(opts,[:range, :trim, :trim_radius, :creatable_dir, :file_to_save, :face])
65
+ opts = needs(opts,[:range, :margin, :trim, :trim_radius, :creatable_dir, :file_to_save, :face])
65
66
  render_showcase(opts[:range], opts[:trim], opts[:trim_radius],
66
67
  opts[:scale], opts[:offset], opts[:fill_color],
67
68
  opts[:reflect_offset], opts[:reflect_percent], opts[:reflect_strength],
@@ -16,8 +16,8 @@ module Squib
16
16
  # @option opts x_radius [Integer] (0) the radius of the rounded corner horiztonally. Zero is a non-rounded corner. Supports Unit Conversion, see {file:README.md#Units Units}.
17
17
  # @option opts y_radius [Integer] (0) the radius of the rounded corner vertically. Zero is a non-rounded corner. Supports Unit Conversion, see {file:README.md#Units Units}.
18
18
  # @option opts radius [Integer] (nil) when set, overrides both x_radius and y_radius. Supports Unit Conversion, see {file:README.md#Units Units}.
19
- # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
20
- # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
19
+ # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
20
+ # @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}
21
21
  # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
22
22
  # @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}
23
23
  # @return [nil] intended to be void
@@ -44,8 +44,8 @@ module Squib
44
44
  # @option opts x [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
45
45
  # @option opts y [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
46
46
  # @option opts radius [Integer] (100) radius of the circle. Supports Unit Conversion, see {file:README.md#Units Units}.
47
- # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
48
- # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
47
+ # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
48
+ # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
49
49
  # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
50
50
  # @return [nil] intended to be void
51
51
  # @api public
@@ -73,8 +73,8 @@ module Squib
73
73
  # @option opts y2 [Integer] (50) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
74
74
  # @option opts x3 [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
75
75
  # @option opts y3 [Integer] (50) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
76
- # @option opts fill_color [String] ('#0000') the color with which to fill the triangle
77
- # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the triangle
76
+ # @option opts fill_color [String] ('#0000') the color with which to fill the triangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
77
+ # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the triangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
78
78
  # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
79
79
  # @return [nil] intended to be void
80
80
  # @api public
@@ -100,7 +100,7 @@ module Squib
100
100
  # @option opts y1 [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
101
101
  # @option opts x2 [Integer] (50) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
102
102
  # @option opts y2 [Integer] (50) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
103
- # @option opts stroke_color [String] (:black) the color with which to stroke the line
103
+ # @option opts stroke_color [String] (:black) the color with which to stroke the line. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
104
104
  # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
105
105
  # @return [nil] intended to be void
106
106
  # @api public