Unit conversion feature added, tested, documented
This commit is contained in:
@@ -721,7 +721,7 @@ cairo: move_to([65, 700])
|
||||
pango: font_description=([])
|
||||
pango: text=(["This is left-justified text.\nWhat do you know about tweetle beetles? well... \nWhen tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle."])
|
||||
pango: width=([691200.0])
|
||||
pango: height=([307200])
|
||||
pango: height=([307200.0])
|
||||
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
|
||||
pango: ellipsize=([#<Pango::Layout::EllipsizeMode end>])
|
||||
pango: alignment=([#<Pango::Layout::Alignment left>])
|
||||
@@ -740,7 +740,7 @@ cairo: move_to([65, 700])
|
||||
pango: font_description=([])
|
||||
pango: text=(["This is left-justified text.\nWhat do you know about tweetle beetles? well... \nWhen tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle."])
|
||||
pango: width=([691200.0])
|
||||
pango: height=([307200])
|
||||
pango: height=([307200.0])
|
||||
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
|
||||
pango: ellipsize=([#<Pango::Layout::EllipsizeMode end>])
|
||||
pango: alignment=([#<Pango::Layout::Alignment left>])
|
||||
@@ -759,7 +759,7 @@ cairo: move_to([65, 700])
|
||||
pango: font_description=([])
|
||||
pango: text=(["This is left-justified text.\nWhat do you know about tweetle beetles? well... \nWhen tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle."])
|
||||
pango: width=([691200.0])
|
||||
pango: height=([307200])
|
||||
pango: height=([307200.0])
|
||||
pango: wrap=([#<Pango::Layout::WrapMode word-char>])
|
||||
pango: ellipsize=([#<Pango::Layout::EllipsizeMode end>])
|
||||
pango: alignment=([#<Pango::Layout::Alignment left>])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
cairo: save([])
|
||||
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=1.0, @green=1.0, @blue=1.0>])
|
||||
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=0.8666666666666667, @green=0.8666666666666667, @blue=0.8666666666666667>])
|
||||
cairo: paint([])
|
||||
cairo: restore([])
|
||||
cairo: save([])
|
||||
@@ -11,4 +11,22 @@ cairo: rounded_rectangle([37.5, 37.5, 750.0, 1050.0, 25, 25])
|
||||
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=0.0, @red=0.0, @green=0.0, @blue=0.0>])
|
||||
cairo: fill([])
|
||||
cairo: restore([])
|
||||
cairo: save([])
|
||||
cairo: rounded_rectangle([75.0, 75.0, 675.0, 975.0, 25, 25])
|
||||
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=0.0, @green=0.0, @blue=0.0>])
|
||||
cairo: set_line_width([2.0])
|
||||
cairo: stroke([])
|
||||
cairo: rounded_rectangle([75.0, 75.0, 675.0, 975.0, 25, 25])
|
||||
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=0.0, @red=0.0, @green=0.0, @blue=0.0>])
|
||||
cairo: fill([])
|
||||
cairo: restore([])
|
||||
cairo: save([])
|
||||
cairo: rounded_rectangle([472.4409444, 472.4409444, 100, 100, 0, 0])
|
||||
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=0.0, @green=0.0, @blue=0.0>])
|
||||
cairo: set_line_width([2.0])
|
||||
cairo: stroke([])
|
||||
cairo: rounded_rectangle([472.4409444, 472.4409444, 100, 100, 0, 0])
|
||||
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=0.0, @red=0.0, @green=0.0, @blue=0.0>])
|
||||
cairo: fill([])
|
||||
cairo: restore([])
|
||||
surface: write_to_png(["_output/units_0.png"])
|
||||
|
||||
@@ -25,7 +25,7 @@ describe Squib::Deck, '#save_pdf' do
|
||||
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
||||
mock_squib_logger(@old_logger) do
|
||||
expect(Squib.logger).to receive(:debug).thrice
|
||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(num_cards + 1).times
|
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||
|
||||
@@ -49,7 +49,7 @@ describe Squib::Deck, '#save_pdf' do
|
||||
args = { range: 2..4, file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
||||
mock_squib_logger(@old_logger) do
|
||||
expect(Squib.logger).to receive(:debug).thrice
|
||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(4).times
|
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'squib/input_helpers'
|
||||
|
||||
class DummyDeck
|
||||
include Squib::InputHelpers
|
||||
attr_accessor :layout, :cards, :custom_colors
|
||||
attr_accessor :layout, :cards, :custom_colors, :width, :height, :dpi
|
||||
end
|
||||
|
||||
describe Squib::InputHelpers do
|
||||
@@ -18,6 +18,9 @@ describe Squib::InputHelpers do
|
||||
}
|
||||
@deck.cards = %w(a b)
|
||||
@deck.custom_colors = {}
|
||||
@deck.width = 100
|
||||
@deck.height = 200
|
||||
@deck.dpi = 300
|
||||
end
|
||||
|
||||
context '#layoutify' do
|
||||
@@ -135,4 +138,42 @@ describe Squib::InputHelpers do
|
||||
end
|
||||
end
|
||||
|
||||
context '#convert_units' do
|
||||
it 'does not touch arrays integers' do
|
||||
args = {x: [156]}
|
||||
needed_params = [:x]
|
||||
opts = @deck.send(:convert_units, args, needed_params)
|
||||
expect(opts).to eq({ :x => [156] })
|
||||
end
|
||||
|
||||
it 'does not touch arrays floats' do
|
||||
args = {x: [156.2]}
|
||||
needed_params = [:x]
|
||||
opts = @deck.send(:convert_units, args, needed_params)
|
||||
expect(opts).to eq({ :x => [156.2] })
|
||||
end
|
||||
|
||||
it 'converts array of all inches' do
|
||||
args = {x: ['1in', '2in']}
|
||||
needed_params = [:x]
|
||||
opts = @deck.send(:convert_units, args, needed_params)
|
||||
expect(opts).to eq({:x => [300.0, 600.0] }) #assume 300dpi default
|
||||
end
|
||||
|
||||
it 'converts array of some inches' do
|
||||
args = {x: [156, '2in']}
|
||||
needed_params = [:x]
|
||||
opts = @deck.send(:convert_units, args, needed_params)
|
||||
expect(opts).to eq({:x => [156.0, 600.0]}) #assume 300dpi default
|
||||
end
|
||||
|
||||
it 'converts centimeters' do
|
||||
args = {x: ['2cm']}
|
||||
needed_params = [:x]
|
||||
opts = @deck.send(:convert_units, args, needed_params)
|
||||
expect(opts).to eq({:x => [236.2204722] }) #assume 300dpi default
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user