[poppler] goo/GooString.cc goo/GooString.h poppler/PSOutputDev.cc
Albert Astals Cid
aacid at kemper.freedesktop.org
Sun Aug 16 11:51:33 PDT 2009
goo/GooString.cc | 27 +++++++++++++++++++++++++--
goo/GooString.h | 4 +++-
poppler/PSOutputDev.cc | 4 ++--
3 files changed, 30 insertions(+), 5 deletions(-)
New commits:
commit 914bf7677a14494b69857b1d8070092a9999fe79
Author: Albert Astals Cid <aacid at kde.org>
Date: Sun Aug 16 20:50:02 2009 +0200
When writing the cm matrix write 4 significant digits not 4 decimals
This fixes bug 23332
Maybe we want to make this the default behaviour of 'g' instead of
a new 'gs' case, but i prefer to be on the safe side for the moment
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 3cff060..6105966 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -18,7 +18,7 @@
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
// Copyright (C) 2007 Jeff Muizelaar <jeff at infidigm.net>
-// Copyright (C) 2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008, 2009 Albert Astals Cid <aacid at kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -40,6 +40,8 @@
#include "gmem.h"
#include "GooString.h"
+static const int MAXIMUM_DOUBLE_PREC = 16;
+
//------------------------------------------------------------------------
union GooStringFormatArg {
@@ -71,6 +73,7 @@ enum GooStringFormatType {
fmtULongOctal,
fmtULongBinary,
fmtDouble,
+ fmtDoubleTrimSmallAware,
fmtDoubleTrim,
fmtChar,
fmtString,
@@ -81,7 +84,7 @@ enum GooStringFormatType {
static char *formatStrings[] = {
"d", "x", "o", "b", "ud", "ux", "uo", "ub",
"ld", "lx", "lo", "lb", "uld", "ulx", "ulo", "ulb",
- "f", "g",
+ "f", "gs", "g",
"c",
"s",
"t",
@@ -379,6 +382,7 @@ GooString *GooString::appendfv(char *fmt, va_list argList) {
break;
case fmtDouble:
case fmtDoubleTrim:
+ case fmtDoubleTrimSmallAware:
args[argsLen].f = va_arg(argList, double);
break;
case fmtChar:
@@ -455,6 +459,9 @@ GooString *GooString::appendfv(char *fmt, va_list argList) {
case fmtDoubleTrim:
formatDouble(arg.f, buf, sizeof(buf), prec, gTrue, &str, &len);
break;
+ case fmtDoubleTrimSmallAware:
+ formatDoubleSmallAware(arg.f, buf, sizeof(buf), prec, gTrue, &str, &len);
+ break;
case fmtChar:
buf[0] = arg.c;
str = buf;
@@ -605,6 +612,22 @@ void GooString::formatDouble(double x, char *buf, int bufSize, int prec,
*len = bufSize - i;
}
+void GooString::formatDoubleSmallAware(double x, char *buf, int bufSize, int prec,
+ GBool trim, char **p, int *len)
+{
+ double absX = fabs(x);
+ if (absX >= 0.1) {
+ formatDouble(x, buf, bufSize, prec, trim, p, len);
+ } else {
+ while (absX < 0.1 && prec < MAXIMUM_DOUBLE_PREC)
+ {
+ absX = absX * 10;
+ prec++;
+ }
+ formatDouble(x, buf, bufSize, prec, trim, p, len);
+ }
+}
+
GooString *GooString::insert(int i, char c) {
return insert(i, (const char*)&c, 1);
}
diff --git a/goo/GooString.h b/goo/GooString.h
index 6194555..731f640 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -17,7 +17,7 @@
//
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
-// Copyright (C) 2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008, 2009 Albert Astals Cid <aacid at kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -169,6 +169,8 @@ private:
char **p, int *len);
static void formatDouble(double x, char *buf, int bufSize, int prec,
GBool trim, char **p, int *len);
+ static void formatDoubleSmallAware(double x, char *buf, int bufSize, int prec,
+ GBool trim, char **p, int *len);
};
#endif
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 6dcf06b..9967892 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2904,7 +2904,7 @@ void PSOutputDev::setupForm(Ref id, Object *strObj) {
writePSFmt("/f_{0:d}_{1:d} {{\n", id.num, id.gen);
writePS("q\n");
- writePSFmt("[{0:.4g} {1:.4g} {2:.4g} {3:.4g} {4:.4g} {5:.4g}] cm\n",
+ writePSFmt("[{0:.4gs} {1:.4gs} {2:.4gs} {3:.4gs} {4:.4gs} {5:.4gs}] cm\n",
m[0], m[1], m[2], m[3], m[4], m[5]);
box.x1 = bbox[0];
@@ -3390,7 +3390,7 @@ void PSOutputDev::restoreState(GfxState *state) {
void PSOutputDev::updateCTM(GfxState *state, double m11, double m12,
double m21, double m22, double m31, double m32) {
- writePSFmt("[{0:.4g} {1:.4g} {2:.4g} {3:.4g} {4:.4g} {5:.4g}] cm\n",
+ writePSFmt("[{0:.4gs} {1:.4gs} {2:.4gs} {3:.4gs} {4:.4gs} {5:.4gs}] cm\n",
m11, m12, m21, m22, m31, m32);
}
More information about the poppler
mailing list