summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Melichev <igor.melichev@artifex.com>2005-10-18 20:31:59 +0000
committerIgor Melichev <igor.melichev@artifex.com>2005-10-18 20:31:59 +0000
commit5d7cb18d3e1032191a73000ed87bfe8b319941e3 (patch)
tree413cd98f0814ab4932a8e1d9b79ed26a5bff0ddb
parentf1d44feecbd99213ac8702f54d4ec5392df27656 (diff)
downloadghostpdl-5d7cb18d3e1032191a73000ed87bfe8b319941e3.tar.gz
Fix (pdfwrite) : Suppress floating point number format in pdfmark operands (continued).
DETAILS : Bug 688167 "change of real number fomat from fixed to exponential format". This improves the patch http://ghostscript.com/pipermail/gs-cvs/2005-September/005717.html with writing small reals in a fixed point number format. We did it after Raph's request in Comment #5 of the bug 688167. But we don't see a visible difference against the old implementation with any viewer. Therefore we believe that we shouldn't have done it (as we did before the implementation). Storing it now mainly for archiving purpose. If this change causes a problem, the author has no objection for unwinding it. EXPECTED DIFFERENCES : None. git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@6157 a1074d23-0009-0410-80fe-cf8c14f379e6
-rw-r--r--gs/lib/gs_pdfwr.ps67
1 files changed, 64 insertions, 3 deletions
diff --git a/gs/lib/gs_pdfwr.ps b/gs/lib/gs_pdfwr.ps
index 308bfe552..2a3bea352 100644
--- a/gs/lib/gs_pdfwr.ps
+++ b/gs/lib/gs_pdfwr.ps
@@ -276,6 +276,59 @@
% ---------------- pdfmark and DSC processing ---------------- %
+/.write_small_positive_real % <file> <real> .write_small_positive_real -
+{ % The argument must be grater than 0 and must be strongly samller than 0.1.
+ % The conversion isn't simple due to the low (24 bits) precision
+ % of the floating point arithmetics in Postscript.
+ % For best result we first use the 1e8 factor since its binary
+ % representation 101111101011110000100000000 well rounds into 14 significant
+ % bits : 101111101011110000000000000 .
+ 1 index (.) writestring
+ { dup 100000000 mul
+ dup 10 mul 1 ge {
+ % Will need not greater than 0.1 due to a rounding below.
+ pop exit
+ } if
+ exch pop
+ 1 index (00000000) writestring
+ } loop
+ % Now it is not smaller than 1e-9, use simple digitizing.
+ { dup 10 mul
+ dup 10 mul 1 ge {
+ pop exit
+ } if
+ exch pop
+ 1 index (0) writestring
+ } loop
+ % Now 0.01 <= n < 0.1, but rounding may give 0.1 .
+ % Convert to integer with 7 digits precision :
+ 100000000 % precision factor 1e8 % f n r
+ dup 10 idiv 3 1 roll mul 0.5 add cvi % f r' N
+ 2 copy le {
+ % The rounding overflows, suppress it.
+ % Note it carries out an additional digit,
+ % that's why we needed <0.1 above.
+ pop pop (1) writestring
+ } {
+ % Didn't cary out, put 0.
+ 2 index (0) writestring
+ exch % f N r
+ % Continue the simple digitizing :
+ { 10 idiv dup % f N r' r'
+ 2 index exch idiv % f N r' d
+ (0123456789) exch 1 getinterval % f N r' (d)
+ 3 index exch writestring % f N r'
+ dup 3 2 roll exch mod % f r' N'
+ dup 0 eq {
+ % Don't write trailing zeros.
+ exit
+ } if
+ exch % f N' r'
+ } loop
+ pop pop pop
+ } ifelse
+} bind def
+
% Encode values to pass for the /pdfmark or /DSC pseudo-parameter.
/.pdf===dict mark
/arraytype
@@ -316,9 +369,17 @@
/realtype {
% Prevent using floating point format - see Bug 688167.
dup dup 0 lt { neg } if 0.0000001 lt {
- pop 0
- } if
- write===only
+ dup 0 eq {
+ pop (0) writestring
+ } {
+ dup 0 lt {
+ 1 index (-) writestring neg
+ } if
+ .write_small_positive_real
+ } ifelse
+ } {
+ write===only
+ } ifelse
} bind
.dicttomark readonly def
/pdf===only { % <file> <obj> pdf===only -