1 2 3 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
|
require 'spec_helper'
describe Prawn::TransformationStack do
let(:pdf) do
create_pdf do |document|
document.add_to_transformation_stack(2, 0, 0, 2, 100, 100)
end
end
let(:stack) { pdf.instance_variable_get(:@transformation_stack) }
describe '#add_to_transformation_stack' do
it 'creates and adds to the stack' do
pdf.add_to_transformation_stack(1, 0, 0, 1, 20, 20)
expect(stack).to eq [[[2, 0, 0, 2, 100, 100], [1, 0, 0, 1, 20, 20]]]
end
it 'adds to the last stack' do
pdf.save_transformation_stack
pdf.add_to_transformation_stack(1, 0, 0, 1, 20, 20)
expect(stack).to eq [
[[2, 0, 0, 2, 100, 100]],
[[2, 0, 0, 2, 100, 100], [1, 0, 0, 1, 20, 20]]
]
end
end
describe '#save_transformation_stack' do
it 'clones the last stack' do
pdf.save_transformation_stack
expect(stack.length).to eq 2
expect(stack.first).to eq stack.last
expect(stack.first).to_not be stack.last
end
end
describe '#restore_transformation_stack' do
it 'pops off the last stack' do
pdf.save_transformation_stack
pdf.add_to_transformation_stack(1, 0, 0, 1, 20, 20)
pdf.restore_transformation_stack
expect(stack).to eq [[[2, 0, 0, 2, 100, 100]]]
end
end
describe 'current_transformation_matrix_with_translation' do
before do
pdf.add_to_transformation_stack(1, 0, 0, 1, 20, 20)
end
it 'calculates the last transformation' do
expect(pdf.current_transformation_matrix_with_translation)
.to eq [2, 0, 0, 2, 140, 140]
end
it 'adds the supplied x and y coordinates to the transformation stack' do
expect(pdf.current_transformation_matrix_with_translation(15, 15))
.to eq [2, 0, 0, 2, 170, 170]
end
end
end
|