Kaydet (Commit) 2113de51 authored tarafından Caolán McNamara's avatar Caolán McNamara

tdf#96892 higher precision pdf fixed ints

reverts

commit 5f6065f9
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 cd5cc12d
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/49227Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 4a95c38e
......@@ -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));
}
}
......
......@@ -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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment