Browse Source

new methods: safe_zone and cut_zone

dev
Andy Meneely 8 years ago
parent
commit
2362e189d7
  1. 1
      CHANGELOG.md
  2. 37
      lib/squib/api/shapes.rb
  3. 22
      samples/shapes/_proofs.rb
  4. BIN
      samples/shapes/proof_poker_00_expected.png
  5. BIN
      samples/shapes/proof_tiny_00_expected.png
  6. 102
      spec/data/samples/shapes/_proofs.rb.txt
  7. 3
      spec/samples/samples_regression_spec.rb

1
CHANGELOG.md

@ -10,6 +10,7 @@ Features:
* `yaml` method for reading in data, much like `csv` and `xlsx` by @blinks
* Layouts now support `*=` and `/=` operators in addition to `+=` and `-=` (#200).
* `save_pdf` method also supports `rtl` by @vador
* New DSL methods `safe_zone` and `cut_zone` will draw a rectangle inset from the margins for quick proof checking
Compatibility:
* DPI is correctly respected with font sizes now. To convert to Squib v0.14+, divide your old font sizes by 3. By @felixleong

37
lib/squib/api/shapes.rb

@ -83,5 +83,42 @@ module Squib
range.each { |i| @cards[i].polygon(coords[i], trans[i], draw[i]) }
end
# DSL method. See http://squib.readthedocs.io
def safe_zone(opts = {})
safe_defaults = {
margin: '0.25in',
radius: '0.125in',
stroke_color: :blue,
fill_color: '#0000',
stroke_width: 1.0,
dash: '3 3',
}
new_opts = safe_defaults.merge(opts)
margin = Args::UnitConversion.parse new_opts[:margin]
new_opts[:x] = margin
new_opts[:y] = margin
new_opts[:width] = width - (2 * margin)
new_opts[:height] = height - (2 * margin)
rect new_opts
end
# DSL method. See http://squib.readthedocs.io
def cut_zone(opts = {})
safe_defaults = {
margin: '0.125in',
radius: '0.125in',
stroke_color: :red,
fill_color: '#0000',
stroke_width: 2.0,
}
new_opts = safe_defaults.merge(opts)
margin = Args::UnitConversion.parse new_opts[:margin]
new_opts[:x] = margin
new_opts[:y] = margin
new_opts[:width] = width - (2 * margin)
new_opts[:height] = height - (2 * margin)
rect new_opts
end
end
end

22
samples/shapes/_proofs.rb

@ -0,0 +1,22 @@
require 'squib'
Squib::Deck.new do
background color: :white
safe_zone # defaults TheGameCrafter 0.25in around the edge, rounded corners
cut_zone # defaults TheGameCrafter 0.125in around the edge
text str: 'Poker card with proof lines', x: '0.25in', y: '0.25in'
save_png prefix: 'proof_poker_'
end
Squib::Deck.new(width:'2in', height: '1in')do
background color: :white
safe_zone stroke_color: :purple, margin: '0.1in'
safe_zone stroke_color: :purple, margin: '0.05in'
text str: 'Small card with proof lines', x: '0.1in', y: '0.1in',
font: 'Arial 10'
save_png prefix: 'proof_tiny_'
end

BIN
samples/shapes/proof_poker_00_expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
samples/shapes/proof_tiny_00_expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

102
spec/data/samples/shapes/_proofs.rb.txt

@ -0,0 +1,102 @@
cairo: antialias=(["subpixel"])
cairo: save([])
cairo: set_source_color(["white"])
cairo: paint([])
cairo: restore([])
cairo: save([])
cairo: translate([75.0, 75.0])
cairo: rotate([0])
cairo: translate([-75.0, -75.0])
cairo: rounded_rectangle([75.0, 75.0, 675.0, 975.0, 37.5, 37.5])
cairo: set_source_color(["#0000"])
cairo: fill_preserve([])
cairo: set_source_color(["blue"])
cairo: set_line_width([1.0])
cairo: set_line_join([0])
cairo: set_line_cap([0])
cairo: set_dash([[3.0, 3.0]])
cairo: stroke([])
cairo: restore([])
cairo: save([])
cairo: translate([37.5, 37.5])
cairo: rotate([0])
cairo: translate([-37.5, -37.5])
cairo: rounded_rectangle([37.5, 37.5, 750.0, 1050.0, 37.5, 37.5])
cairo: set_source_color(["#0000"])
cairo: fill_preserve([])
cairo: set_source_color(["red"])
cairo: set_line_width([2.0])
cairo: set_line_join([0])
cairo: set_line_cap([0])
cairo: set_dash([[]])
cairo: stroke([])
cairo: restore([])
cairo: save([])
cairo: set_source_color(["black"])
cairo: translate([75.0, 75.0])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["Poker card with proof lines"])
pango: wrap=([#<Pango::WrapMode word-char>])
pango: ellipsize=([#<Pango::EllipsizeMode end>])
pango: alignment=([#<Pango::Alignment left>])
pango: justify=([false])
cairo: move_to([0, 0])
cairo: move_to([0, 0])
cairo: show_pango_layout([MockDouble])
pango: ellipsized?([])
cairo: restore([])
surface: write_to_png(["_output/proof_poker_00.png"])
surface: finish([])
cairo: antialias=(["subpixel"])
cairo: save([])
cairo: set_source_color(["white"])
cairo: paint([])
cairo: restore([])
cairo: save([])
cairo: translate([30.0, 30.0])
cairo: rotate([0])
cairo: translate([-30.0, -30.0])
cairo: rounded_rectangle([30.0, 30.0, 540.0, 240.0, 37.5, 37.5])
cairo: set_source_color(["#0000"])
cairo: fill_preserve([])
cairo: set_source_color(["purple"])
cairo: set_line_width([1.0])
cairo: set_line_join([0])
cairo: set_line_cap([0])
cairo: set_dash([[3.0, 3.0]])
cairo: stroke([])
cairo: restore([])
cairo: save([])
cairo: translate([15.0, 15.0])
cairo: rotate([0])
cairo: translate([-15.0, -15.0])
cairo: rounded_rectangle([15.0, 15.0, 570.0, 270.0, 37.5, 37.5])
cairo: set_source_color(["#0000"])
cairo: fill_preserve([])
cairo: set_source_color(["purple"])
cairo: set_line_width([1.0])
cairo: set_line_join([0])
cairo: set_line_cap([0])
cairo: set_dash([[3.0, 3.0]])
cairo: stroke([])
cairo: restore([])
cairo: save([])
cairo: set_source_color(["black"])
cairo: translate([30.0, 30.0])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["Small card with proof lines"])
pango: wrap=([#<Pango::WrapMode word-char>])
pango: ellipsize=([#<Pango::EllipsizeMode end>])
pango: alignment=([#<Pango::Alignment left>])
pango: justify=([false])
cairo: move_to([0, 0])
cairo: move_to([0, 0])
cairo: show_pango_layout([MockDouble])
pango: ellipsized?([])
cairo: restore([])
surface: write_to_png(["_output/proof_tiny_00.png"])
surface: finish([])

3
spec/samples/samples_regression_spec.rb

@ -51,6 +51,7 @@ describe 'Squib samples' do
saves/_saves.rb
saves/_showcase.rb
shapes/_draw_shapes.rb
shapes/_proofs.rb
text/_embed_text.rb
text/_text_options.rb
units/_units.rb
@ -62,7 +63,7 @@ describe 'Squib samples' do
Dir.chdir(File.dirname("#{samples_dir}/#{sample}")) do
load full_sample_path
end
overwrite_sample(sample, log) # Use TEMPORARILY once happy with the new sample log
# overwrite_sample(sample, log) # Use TEMPORARILY once happy with the new sample log
test_file_str = File.open(sample_regression_file(sample), 'r:UTF-8').read
expect(log.string).to eq(test_file_str)
end

Loading…
Cancel
Save