Skip to content

Commit

Permalink
resolves #1983 prevent scientific notation ending up in generated PDF…
Browse files Browse the repository at this point in the history
… (PR #1984)
  • Loading branch information
rillbert authored Dec 31, 2021
1 parent 71a9ddf commit 8865b14
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Enhancements::
* show URL of link for any media type when show-link-uri is set (#951)
* do not show URL of link when media type is screen or prepress when show-link-uri is unset (#951)

Bug Fixes::

* update patches for `PDF::Core.real` and `PDF::Core.real_params` to prevent scientific notation ending up in PDF (#1983) (@rillbert)

== 1.6.1 (2021-09-04) - @mojavelinux

Enhancements::
Expand Down
8 changes: 5 additions & 3 deletions lib/asciidoctor/pdf/ext/pdf-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
module PDF::Core
class << self
alias _initial_real real
def real num
num.to_f.round 4

# NOTE Makes v1.6.x work with the modified precision settings (0.5f) in Prawn 2.4 while preserving existing behavior
def real num, precision = 4
("%.#{precision}f" % num).sub(/((?<!\.)0)+\z/, '')
end

alias _initial_real_params real_params
def real_params array
return array.map {|it| it.to_f.round 5 }.join ' ' if (caller_locations 1, 1)[0].base_label == 'transformation_matrix'
return array.map {|e| real e, 5 }.join(' ') if (caller_locations 1, 1)[0].base_label == 'transformation_matrix'
_initial_real_params array
end
end
Expand Down
45 changes: 45 additions & 0 deletions spec/fixtures/green-bar-width-diff.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@
(expect to_file).to visually_match 'image-svg-scale-to-fit-bounds.pdf'
end

it 'should output fixed precision numbers even when set width differs to viewBox with small amount', visual: true do
to_file = to_pdf_file 'image::green-bar-width-diff.svg[]', 'image-svg-fixed-precision.pdf'

(expect to_file).to visually_match 'image-svg-fixed-precision.pdf'
end

it 'should display text inside link' do
pdf = to_pdf <<~'EOS', analyze: true
image::svg-with-link.svg[]
Expand Down
Binary file added spec/reference/image-svg-fixed-precision.pdf
Binary file not shown.
Binary file modified spec/reference/running-content-alt-layouts.pdf
Binary file not shown.
Binary file modified spec/reference/running-content-image-alignment.pdf
Binary file not shown.
Binary file modified spec/reference/running-content-image-fit.pdf
Binary file not shown.

0 comments on commit 8865b14

Please sign in to comment.