Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for issues #67 and #35 #68

Closed
wants to merge 1 commit into from

2 participants

xk Devon Govett
xk
xk commented

The PDF 1.3 Reference Manual says (4.3 numbers, page 37):
Exponential format for numbers (such as 1.0E3) is not supported.

xk xk fix for issues #67 and #35
The PDF 1.3 Reference Manual says (4.3 numbers, page 37):
Exponential format for numbers (such as 1.0E3) is not supported.
dfc37fe
Devon Govett devongovett referenced this pull request from a commit
Devon Govett Fix transformation issues. Closes #67, #68 and #35.
I think 5 decimal places is probably enough.
2e457ac
Devon Govett devongovett closed this
Devon Govett
Owner

Thanks for looking to this. I implemented something similar in 2e457ac. I think 5 decimal places is probably enough. :)

xk
xk commented

Hi Devon, I'm glad to contribute to this awesome module.

You patch is shorter, yes, but it adds to 0 and any integer a ~useless .00000 , mine takes care to do that only for numbers < 1 and > -1, and to print zeros as 0 not as 0.00000 ... :-)

Also, note that it's not only transform who writes reals, this conversion from exponential to fixed should be done anywhere a real is written to the .pdf.

Devon Govett
Owner

Ah but mine does as well! That's what the + is for in +v.toFixed(5). First it generates a string rounded to 5 decimal places and including extra 0s but the + converts it back to a number, which discards the extra 0s. Try it: (0).toFixed(5) evaluates to "0.00000" but +(0).toFixed(5) evaluates to just 0.

As for the rest of the PDF, I don't think there is anywhere else that exponential notation would reasonably be used so just doing this for transforms seems fine to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2012
  1. xk

    fix for issues #67 and #35

    xk authored
    The PDF 1.3 Reference Manual says (4.3 numbers, page 37):
    Exponential format for numbers (such as 1.0E3) is not supported.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 2 deletions.
  1. +10 −2 lib/mixins/vector.coffee
12 lib/mixins/vector.coffee
View
@@ -144,9 +144,17 @@ module.exports =
clip: (rule) ->
@addContent 'W' + @_windingRule(rule) + ' n'
-
+
transform: (m11, m12, m21, m22, dx, dy) ->
- values = [m11, m12, m21, m22, dx, dy].join ' '
+ values = [m11, m12, m21, m22, dx, dy].map (v) ->
+ str = v.toFixed(20);
+ v = +str;
+ if (v >= 1 || v <= -1 || v == 0)
+ return v.toString();
+ else
+ return str;
+
+ values = values.join ' '
@addContent "#{values} cm"
translate: (x, y) ->
Something went wrong with that request. Please try again.