diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2019-01-23 16:25:09 +0100 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2019-01-24 10:25:39 +0100 |
commit | fddd956c0cf3b2c22a152bbb30554def1336b466 (patch) | |
tree | 9711913e7c7027865e0d83bc015f8d91790b57b6 /vcl | |
parent | c8dd1c22d7512d4922461350c6cb804cd0864e0b (diff) |
tdf#96892 vcl: add unit test for misplaced soft-hyphen ...
... due to incorrectly exported font size.
Change-Id: If06dccc000530427be767fc7a5031f5ebe6fd431
Reviewed-on: https://gerrit.libreoffice.org/66803
Tested-by: Jenkins
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/softhyphen_pdf.odt | bin | 0 -> 9071 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 61 |
2 files changed, 61 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/softhyphen_pdf.odt b/vcl/qa/cppunit/pdfexport/data/softhyphen_pdf.odt Binary files differnew file mode 100644 index 000000000000..ecd779537788 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/softhyphen_pdf.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 023c8ed261e0..92f1bf0cd89e 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -88,6 +88,7 @@ public: void testForcePoint71(); void testTdf106972(); void testTdf106972Pdf17(); + void testSofthyphenPos(); void testTdf107013(); void testTdf107018(); void testTdf107089(); @@ -128,6 +129,7 @@ public: CPPUNIT_TEST(testForcePoint71); CPPUNIT_TEST(testTdf106972); CPPUNIT_TEST(testTdf106972Pdf17); + CPPUNIT_TEST(testSofthyphenPos); CPPUNIT_TEST(testTdf107013); CPPUNIT_TEST(testTdf107018); CPPUNIT_TEST(testTdf107089); @@ -599,6 +601,65 @@ void PdfExportTest::testTdf106972Pdf17() CPPUNIT_ASSERT(pXObject->Lookup("Resources")); } +void PdfExportTest::testSofthyphenPos() +{ + // No need to run it on Windows, since it would use GDI printing, and not + // trigger PDF export which is the intent of the test. + // FIXME: Why does this fail on macOS? +#if !defined MACOSX && !defined _WIN32 + // Import the bugdoc and print to PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "softhyphen_pdf.odt"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); + + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + uno::Reference<view::XPrintable> xPrintable(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xPrintable.is()); + uno::Sequence<beans::PropertyValue> aOptions(comphelper::InitPropertySequence( + { + {"FileName", uno::makeAny(maTempFile.GetURL())}, + {"Wait", uno::makeAny(true)} + })); + xPrintable->print(aOptions); + + // Parse the export result with pdfium. + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + if (aFile.bad()) + { + // Printing to PDF failed in a non-interesting way, e.g. CUPS is not + // running, there is no printer defined, etc. + return; + } + DocumentHolder pPdfDocument(FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr)); + CPPUNIT_ASSERT(pPdfDocument); + + // The document has one page. + CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get())); + PageHolder pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0)); + CPPUNIT_ASSERT(pPdfPage.get()); + + // tdf#96892 incorrect fractional part of font size caused soft-hyphen to + // be positioned inside preceding text (incorrect = 11.1, correct = 11.05) + + // there are 3 texts currently, for line 1, soft-hyphen, line 2 + bool haveText(false); + + int nPageObjectCount = FPDFPage_CountObjects(pPdfPage.get()); + for (int i = 0; i < nPageObjectCount; ++i) + { + FPDF_PAGEOBJECT pPdfPageObject = FPDFPage_GetObject(pPdfPage.get(), i); + CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(pPdfPageObject)); + haveText = true; + double const size(FPDFTextObj_GetFontSize(pPdfPageObject)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(11.05, size, 1E-06); + } + + CPPUNIT_ASSERT(haveText); +#endif +} + void PdfExportTest::testTdf107013() { vcl::filter::PDFDocument aDocument; |