Skip to content

Commit

Permalink
Fix transformation matrix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pointlessone committed Oct 27, 2020
1 parent 844190e commit 1dd1169
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/prawn/graphics/transformation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ def transformation_matrix(*matrix)
raise ArgumentError,
'Transformation matrix must have exacty 6 elements'
end
values = matrix.map { |x| x.to_f.round(5) }.join(' ')
save_graphics_state if block_given?

add_to_transformation_stack(*matrix)

values = PDF::Core.real_params(matrix)
renderer.add_content "#{values} cm"
if block_given?
yield
Expand Down
10 changes: 10 additions & 0 deletions spec/prawn/graphics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,16 @@
expect(pdf).to have_received(:restore_graphics_state).with(no_args)
.ordered
end

it 'properly serializes the matrix', issue: 1178 do
pdf.transformation_matrix 1, 0, 0, 1, 0.0, 1.8977874316715393e-05
rendered_document = pdf.render

expect(rendered_document).to_not include('2.0e-05')

matrices = PDF::Inspector::Graphics::Matrix.analyze(rendered_document)
expect(matrices.matrices).to eq([[1, 0, 0, 1, 0.0, 0.00002]])
end
end

describe 'When using transformations shortcuts' do
Expand Down
8 changes: 4 additions & 4 deletions spec/prawn_manual_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
MANUAL_HASH =
case RUBY_ENGINE
when 'ruby'
'59c0acffd3c75588de2f1df60bb6af857a7c8b50c9e551bdc930af32e6a4eee6'\
'061561812a17384a5345f06ff770d7022d1f1d1f1da7d9ac0d01e805532c1287'
'bcba28d39698ac349a626e1bc3d6a354d20bd7da340190bc8843cec1be3caefb'\
'88fc9591edba9cf21d7f2e08faf40a40d269b26b5c5ac6afb8c7fb61cba8c544'
when 'jruby'
'f4e45385bfebe797d97c46046ea585434d45de3e70e7f6a2f9d77445daadf5be'\
'aaa3c6bf52664280334356e01bfa275b0184a7bb18d2f2499286b00c99df2741'
'fc28a61d956326664aba40e2fa41bda2ffc112ce95c6b689be01f5e909038b09'\
'6b93f6445cf4b324b2d13dc794edc88ee2116db556dd6ae5c7d350e963d1f45a'
end

RSpec.describe Prawn do
Expand Down

0 comments on commit 1dd1169

Please sign in to comment.