[Libreoffice-commits] core.git: vcl/qa vcl/source
Caolán McNamara
caolanm at redhat.com
Tue Feb 6 09:27:19 UTC 2018
vcl/qa/cppunit/pdfexport/pdfexport.cxx | 20 ++++++++++----------
vcl/source/gdi/pdfwriter_impl.cxx | 23 +++++++++++++++--------
2 files changed, 25 insertions(+), 18 deletions(-)
New commits:
commit 2113de51158a6e6c14931109bb9a4e27303c0eab
Author: Caolán McNamara <caolanm at redhat.com>
Date: Mon Feb 5 10:23:27 2018 +0000
tdf#96892 higher precision pdf fixed ints
reverts
commit 5f6065f980756fdb81c7018bedbb7f54e2b8214a
Date: Thu Mar 3 20:44:47 2016 +0000
coverity#1355126 Logically dead code
maybe we should be using more precision, but we haven't
been in the past
and...
commit cd5cc12d4330d68d0a233a82eda30e983ce202a4
Date: Thu Mar 3 20:42:52 2016 +0000
nLog10Divisor is 1
and then fix the original appendFixedInt bug wrt higher precision settings
and then bump those settings from 1 decimal place to 3 and adjust our
pdf export test for the new precision
Change-Id: Ib1b4c41ce2e651d5343919b253ffd46895c764ac
Reviewed-on: https://gerrit.libreoffice.org/49227
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index a904a5dc638d..cb03680a4703 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -724,36 +724,36 @@ void PdfExportTest::testTdf108963()
float fX = 0;
float fY = 0;
FPDFPathSegment_GetPoint(pSegment, &fX, &fY);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(245.4), fX);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(244.2), fY);
+ CPPUNIT_ASSERT_EQUAL(245395, static_cast<int>(round(fX * 1000)));
+ CPPUNIT_ASSERT_EQUAL(244233, static_cast<int>(round(fY * 1000)));
CPPUNIT_ASSERT(!FPDFPathSegment_GetClose(pSegment));
pSegment = FPDFPath_GetPathSegment(pPdfPageObject, 1);
CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(pSegment));
FPDFPathSegment_GetPoint(pSegment, &fX, &fY);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(275.1), fX);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(267.6), fY);
+ CPPUNIT_ASSERT_EQUAL(275102, static_cast<int>(round(fX * 1000)));
+ CPPUNIT_ASSERT_EQUAL(267590, static_cast<int>(round(fY * 1000)));
CPPUNIT_ASSERT(!FPDFPathSegment_GetClose(pSegment));
pSegment = FPDFPath_GetPathSegment(pPdfPageObject, 2);
CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(pSegment));
FPDFPathSegment_GetPoint(pSegment, &fX, &fY);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(287.5), fX);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(251.8), fY);
+ CPPUNIT_ASSERT_EQUAL(287518, static_cast<int>(round(fX * 1000)));
+ CPPUNIT_ASSERT_EQUAL(251801, static_cast<int>(round(fY * 1000)));
CPPUNIT_ASSERT(!FPDFPathSegment_GetClose(pSegment));
pSegment = FPDFPath_GetPathSegment(pPdfPageObject, 3);
CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(pSegment));
FPDFPathSegment_GetPoint(pSegment, &fX, &fY);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(257.8), fX);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(228.4), fY);
+ CPPUNIT_ASSERT_EQUAL(257839, static_cast<int>(round(fX * 1000)));
+ CPPUNIT_ASSERT_EQUAL(228444, static_cast<int>(round(fY * 1000)));
CPPUNIT_ASSERT(!FPDFPathSegment_GetClose(pSegment));
pSegment = FPDFPath_GetPathSegment(pPdfPageObject, 4);
CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(pSegment));
FPDFPathSegment_GetPoint(pSegment, &fX, &fY);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(245.4), fX);
- CPPUNIT_ASSERT_EQUAL(static_cast<float>(244.2), fY);
+ CPPUNIT_ASSERT_EQUAL(245395, static_cast<int>(round(fX * 1000)));
+ CPPUNIT_ASSERT_EQUAL(244233, static_cast<int>(round(fY * 1000)));
CPPUNIT_ASSERT(FPDFPathSegment_GetClose(pSegment));
}
}
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 6435a6a18dd5..fcb30130d3c4 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -505,8 +505,8 @@ void doTestCode()
}
#endif
-static const sal_Int32 nLog10Divisor = 1;
-static const double fDivisor = 10.0;
+static const sal_Int32 nLog10Divisor = 3;
+static const double fDivisor = 1000.0;
static inline double pixelToPoint( double px ) { return px/fDivisor; }
static inline sal_Int32 pointToPixel( double pt ) { return sal_Int32(pt*fDivisor); }
@@ -837,14 +837,21 @@ static void appendFixedInt( sal_Int32 nValue, OStringBuffer& rBuffer )
rBuffer.append( '-' );
nValue = -nValue;
}
- const sal_Int32 nFactor = 10;
- const sal_Int32 nInt = nValue / nFactor;
+ sal_Int32 nFactor = 1, nDiv = nLog10Divisor;
+ while( nDiv-- )
+ nFactor *= 10;
+
+ sal_Int32 nInt = nValue / nFactor;
rBuffer.append( nInt );
- sal_Int32 nDecimal = nValue % nFactor;
- if (nDecimal)
+ if (nFactor > 1 && nValue % nFactor)
{
- rBuffer.append('.');
- rBuffer.append(nDecimal);
+ rBuffer.append( '.' );
+ do
+ {
+ nFactor /= 10;
+ rBuffer.append((nValue / nFactor) % 10);
+ }
+ while (nFactor > 1 && nValue % nFactor); // omit trailing zeros
}
}
More information about the Libreoffice-commits
mailing list