goo/GooString.cc | 19 ++++++++---- goo/GooString.h | 10 ++++-- poppler/CMap.cc | 3 + poppler/Function.cc | 3 + poppler/Object.h | 4 +- poppler/StructElement.cc | 2 - qt4/tests/check_goostring.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++ qt5/tests/check_goostring.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++ utils/pdftocairo.cc | 2 - 9 files changed, 160 insertions(+), 15 deletions(-)
New commits: commit 64100e7f1f6b550e952838fce38615ec3788e17c Author: Fabio D'Urso <[email protected]> Date: Sat Dec 28 12:11:47 2013 +0100 Simplify some calls to GooString::format-family functions diff --git a/poppler/Object.h b/poppler/Object.h index a299624..15bea15 100644 --- a/poppler/Object.h +++ b/poppler/Object.h @@ -45,14 +45,14 @@ #define OBJECT_TYPE_CHECK(wanted_type) \ if (unlikely(type != wanted_type)) { \ - error(errInternal, 0, (char *) "Call to Object where the object was type {0:d}, " \ + error(errInternal, 0, "Call to Object where the object was type {0:d}, " \ "not the expected type {1:d}", type, wanted_type); \ abort(); \ } #define OBJECT_3TYPES_CHECK(wanted_type1, wanted_type2, wanted_type3) \ if (unlikely(type != wanted_type1) && unlikely(type != wanted_type2) && unlikely(type != wanted_type3)) { \ - error(errInternal, 0, (char *) "Call to Object where the object was type {0:d}, " \ + error(errInternal, 0, "Call to Object where the object was type {0:d}, " \ "not the expected type {1:d}, {2:d} or {3:d}", type, wanted_type1, wanted_type2, wanted_type3); \ abort(); \ } diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 6c677bd..f67007f 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -674,7 +674,7 @@ static GooString *getImageFileName(GooString *outputFileName, int numDigits, int GooString *imageName = new GooString(outputFileName); if (!singleFile) { snprintf(buf, sizeof(buf), "-%0*d", numDigits, page); - imageName->appendf(buf); + imageName->append(buf); } if (png) imageName->append(".png"); commit 0abde34d0f7ba0fc04a30dbfd78373ec9d9d0695 Author: Fabio D'Urso <[email protected]> Date: Sat Dec 28 12:11:05 2013 +0100 Fixed some GooString format markers diff --git a/poppler/CMap.cc b/poppler/CMap.cc index 13f293a..6731ab5 100644 --- a/poppler/CMap.cc +++ b/poppler/CMap.cc @@ -15,6 +15,7 @@ // // Copyright (C) 2008 Koji Otani <[email protected]> // Copyright (C) 2008, 2009 Albert Astals Cid <[email protected]> +// Copyright (C) 2013 Fabio D'Urso <[email protected]> // // 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 @@ -420,7 +421,7 @@ void CMap::addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID) { for (byte = (int)(start & 0xff); byte <= (int)(end & 0xff); ++byte) { if (vec[byte].isVector) { error(errSyntaxError, -1, - "Invalid CID ({0:x} - {1:x} [{2:d} bytes]) in CMap", + "Invalid CID ({0:ux} - {1:ux} [{2:ud} bytes]) in CMap", start, end, nBytes); } else { vec[byte].cid = cid; diff --git a/poppler/Function.cc b/poppler/Function.cc index 2f94a54..81829ec 100644 --- a/poppler/Function.cc +++ b/poppler/Function.cc @@ -19,6 +19,7 @@ // Copyright (C) 2011 Andrea Canciani <[email protected]> // Copyright (C) 2012 Thomas Freitag <[email protected]> // Copyright (C) 2012 Adam Reichold <[email protected]> +// Copyright (C) 2013 Fabio D'Urso <[email protected]> // // 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 @@ -1194,7 +1195,7 @@ PostScriptFunction::PostScriptFunction(Object *funcObj, Dict *dict) { codeString = new GooString(); str->reset(); if (!(tok = getToken(str)) || tok->cmp("{")) { - error(errSyntaxError, -1, "Expected '{' at start of PostScript function"); + error(errSyntaxError, -1, "Expected '{{' at start of PostScript function"); if (tok) { delete tok; } diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc index 3a98658..6392433 100644 --- a/poppler/StructElement.cc +++ b/poppler/StructElement.cc @@ -1260,7 +1260,7 @@ StructElement *StructElement::parseChild(Object *ref, child = new StructElement(childObj->getDict(), treeRoot, this, seen); } else { error(errSyntaxWarning, -1, - "Loop detected in structure tree, skipping subtree at object {0:i}:{0:i}", + "Loop detected in structure tree, skipping subtree at object {0:d}:{1:d}", ref->getRefNum(), ref->getRefGen()); } } else { commit a7da4c6ac2b13308803806009c3437332b140586 Author: Fabio D'Urso <[email protected]> Date: Fri Dec 27 17:09:39 2013 +0100 GooString format: fixed bug with printing LLONG_MIN ( -LLONG_MIN doesn't fit in a signed long long ) diff --git a/goo/GooString.cc b/goo/GooString.cc index e27f158..8591d95 100644 --- a/goo/GooString.cc +++ b/goo/GooString.cc @@ -20,7 +20,7 @@ // Copyright (C) 2007 Jeff Muizelaar <[email protected]> // Copyright (C) 2008-2011 Albert Astals Cid <[email protected]> // Copyright (C) 2011 Kenji Uno <[email protected]> -// Copyright (C) 2012 Fabio D'Urso <[email protected]> +// Copyright (C) 2012, 2013 Fabio D'Urso <[email protected]> // Copyright (C) 2012 Adrian Johnson <[email protected]> // Copyright (C) 2012 Pino Toscano <[email protected]> // Copyright (C) 2013 Jason Crain <[email protected]> @@ -651,18 +651,25 @@ void GooString::formatInt(long x, char *buf, int bufSize, const char *vals = upperCase ? upperCaseDigits : lowerCaseDigits; GBool neg; int start, i, j; +#ifdef LLONG_MAX + unsigned long long abs_x; +#else + unsigned long abs_x; +#endif i = bufSize; if ((neg = x < 0)) { - x = -x; + abs_x = -x; + } else { + abs_x = x; } start = neg ? 1 : 0; - if (x == 0) { + if (abs_x == 0) { buf[--i] = '0'; } else { - while (i > start && x) { - buf[--i] = vals[x % base]; - x /= base; + while (i > start && abs_x) { + buf[--i] = vals[abs_x % base]; + abs_x /= base; } } if (zeroFill) { commit fe88f20cc565b4cf4765fed56c821989148ef454 Author: Fabio D'Urso <[email protected]> Date: Fri Dec 27 17:08:50 2013 +0100 GooString format: Added some tests + improved documentation diff --git a/goo/GooString.h b/goo/GooString.h index e92a889..6bdcf06 100644 --- a/goo/GooString.h +++ b/goo/GooString.h @@ -18,7 +18,7 @@ // Copyright (C) 2006 Kristian Høgsberg <[email protected]> // Copyright (C) 2006 Krzysztof Kowalczyk <[email protected]> // Copyright (C) 2008-2010, 2012 Albert Astals Cid <[email protected]> -// Copyright (C) 2012 Fabio D'Urso <[email protected]> +// Copyright (C) 2012, 2013 Fabio D'Urso <[email protected]> // Copyright (C) 2013 Jason Crain <[email protected]> // // To see a description of the changes please see the Changelog file that @@ -87,8 +87,12 @@ public: // ld, lx, lX, lo, lb, uld, ulx, ulX, ulo, ulb -- long, unsigned long // lld, llx, llX, llo, llb, ulld, ullx, ullX, ullo, ullb // -- long long, unsigned long long - // f, g -- double - // c -- char + // f, g, gs -- floating point (float or double) + // f -- always prints trailing zeros (eg 1.0 with .2f will print 1.00) + // g -- omits trailing zeros and, if possible, the dot (eg 1.0 shows up as 1) + // gs -- is like g, but treats <precision> as number of significant + // digits to show (eg 0.0123 with .2gs will print 0.012) + // c -- character (char, short or int) // s -- string (char *) // t -- GooString * // w -- blank space; arg determines width diff --git a/qt4/tests/check_goostring.cpp b/qt4/tests/check_goostring.cpp index 07999b5..69f7cdc 100644 --- a/qt4/tests/check_goostring.cpp +++ b/qt4/tests/check_goostring.cpp @@ -1,3 +1,4 @@ +#include <QtCore/QScopedPointer> #include <QtTest/QtTest> #include "goo/GooString.h" @@ -9,6 +10,7 @@ private slots: void testInsertData_data(); void testInsertData(); void testInsert(); + void testFormat(); }; void TestGooString::testInsertData_data() @@ -56,6 +58,70 @@ void TestGooString::testInsert() } } +void TestGooString::testFormat() +{ + { + const QScopedPointer<GooString> goo(GooString::format("{0:d},{1:x}", 1, 0xF)); + QCOMPARE(goo->getCString(), "1,f"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b},{0:w}", 0xA)); + QCOMPARE(goo->getCString(), "10,a,A,12,1010, "); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b}", -0xA)); + QCOMPARE(goo->getCString(), "-10,-a,-A,-12,-1010"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:c}{1:c}{2:c}{3:c}", + 'T', (char)'E', (short)'S', (int)'T')); + QCOMPARE(goo->getCString(), "TEST"); + + const QScopedPointer<GooString> goo2(GooString::format("{0:s} {1:t}", "TEST", goo.data())); + QCOMPARE(goo2->getCString(), "TEST TEST"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:ud} {1:d} {2:d}", + UINT_MAX, INT_MAX, INT_MIN)); + const QByteArray expected = QString("%1 %2 %3").arg(UINT_MAX).arg(INT_MAX).arg(INT_MIN).toLatin1(); + QCOMPARE(goo->getCString(), expected.constData()); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:uld} {1:ld} {2:ld}", + ULONG_MAX, LONG_MAX, LONG_MIN)); + const QByteArray expected = QString("%1 %2 %3").arg(ULONG_MAX).arg(LONG_MAX).arg(LONG_MIN).toLatin1(); + QCOMPARE(goo->getCString(), expected.constData()); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:ulld} {1:lld} {2:lld}", + ULLONG_MAX, LLONG_MAX, LLONG_MIN)); + const QByteArray expected = QString("%1 %2 %3").arg(ULLONG_MAX).arg(LLONG_MAX).arg(LLONG_MIN).toLatin1(); + QCOMPARE(goo->getCString(), expected.constData()); + } + { + const QScopedPointer<GooString> gooD(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1., .012)); + const QScopedPointer<GooString> gooF(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1.f, .012f)); + QCOMPARE(gooD->getCString(), "1.0 1 1 | 0.0 0 0.01"); + QCOMPARE(gooF->getCString(), "1.0 1 1 | 0.0 0 0.01"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:.4f} {0:.4g} {0:.4gs}", .012)); + QCOMPARE(goo->getCString(), "0.0120 0.012 0.012"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{{ SomeText {0:d} }}", 1)); + QCOMPARE(goo->getCString(), "{ SomeText 1 }"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{{{{ {{ SomeText {0:d}", 2)); + QCOMPARE(goo->getCString(), "{{ { SomeText 2"); + } + { + const QScopedPointer<GooString> goo(GooString::format("SomeText {0:d} }} }}}}", 3)); + QCOMPARE(goo->getCString(), "SomeText 3 } }}"); + } +} + QTEST_MAIN(TestGooString) #include "check_goostring.moc" diff --git a/qt5/tests/check_goostring.cpp b/qt5/tests/check_goostring.cpp index 07999b5..69f7cdc 100644 --- a/qt5/tests/check_goostring.cpp +++ b/qt5/tests/check_goostring.cpp @@ -1,3 +1,4 @@ +#include <QtCore/QScopedPointer> #include <QtTest/QtTest> #include "goo/GooString.h" @@ -9,6 +10,7 @@ private slots: void testInsertData_data(); void testInsertData(); void testInsert(); + void testFormat(); }; void TestGooString::testInsertData_data() @@ -56,6 +58,70 @@ void TestGooString::testInsert() } } +void TestGooString::testFormat() +{ + { + const QScopedPointer<GooString> goo(GooString::format("{0:d},{1:x}", 1, 0xF)); + QCOMPARE(goo->getCString(), "1,f"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b},{0:w}", 0xA)); + QCOMPARE(goo->getCString(), "10,a,A,12,1010, "); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b}", -0xA)); + QCOMPARE(goo->getCString(), "-10,-a,-A,-12,-1010"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:c}{1:c}{2:c}{3:c}", + 'T', (char)'E', (short)'S', (int)'T')); + QCOMPARE(goo->getCString(), "TEST"); + + const QScopedPointer<GooString> goo2(GooString::format("{0:s} {1:t}", "TEST", goo.data())); + QCOMPARE(goo2->getCString(), "TEST TEST"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:ud} {1:d} {2:d}", + UINT_MAX, INT_MAX, INT_MIN)); + const QByteArray expected = QString("%1 %2 %3").arg(UINT_MAX).arg(INT_MAX).arg(INT_MIN).toLatin1(); + QCOMPARE(goo->getCString(), expected.constData()); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:uld} {1:ld} {2:ld}", + ULONG_MAX, LONG_MAX, LONG_MIN)); + const QByteArray expected = QString("%1 %2 %3").arg(ULONG_MAX).arg(LONG_MAX).arg(LONG_MIN).toLatin1(); + QCOMPARE(goo->getCString(), expected.constData()); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:ulld} {1:lld} {2:lld}", + ULLONG_MAX, LLONG_MAX, LLONG_MIN)); + const QByteArray expected = QString("%1 %2 %3").arg(ULLONG_MAX).arg(LLONG_MAX).arg(LLONG_MIN).toLatin1(); + QCOMPARE(goo->getCString(), expected.constData()); + } + { + const QScopedPointer<GooString> gooD(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1., .012)); + const QScopedPointer<GooString> gooF(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1.f, .012f)); + QCOMPARE(gooD->getCString(), "1.0 1 1 | 0.0 0 0.01"); + QCOMPARE(gooF->getCString(), "1.0 1 1 | 0.0 0 0.01"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{0:.4f} {0:.4g} {0:.4gs}", .012)); + QCOMPARE(goo->getCString(), "0.0120 0.012 0.012"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{{ SomeText {0:d} }}", 1)); + QCOMPARE(goo->getCString(), "{ SomeText 1 }"); + } + { + const QScopedPointer<GooString> goo(GooString::format("{{{{ {{ SomeText {0:d}", 2)); + QCOMPARE(goo->getCString(), "{{ { SomeText 2"); + } + { + const QScopedPointer<GooString> goo(GooString::format("SomeText {0:d} }} }}}}", 3)); + QCOMPARE(goo->getCString(), "SomeText 3 } }}"); + } +} + QTEST_MAIN(TestGooString) #include "check_goostring.moc"
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
