diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-05-22 16:20:18 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-05-22 19:30:25 +0200 |
commit | 4c2172a3e973bc6351107a3a1b554c77b40b75dd (patch) | |
tree | 23f46863d12dd137b9d8f40190328c517c66c974 /vcl/qa | |
parent | 2c1fb32e0b3f0c51edcbb861977d372ae4eaf5e4 (diff) |
tdf#106702 PDF export: fix missing images from Writer headers/footers
Position of an image is determined by the relevant bitmap scale metafile
action when recompressing images.
The same position was determined by PDFExtOutDevData "meta" info when
not recompressing images. This second rectangle was never correct for
images repeated in Writer headers/footers on non-first pages: the
position was relative to the page, while PDF export sets the map mode
(origin) of the output device during export, so such positions are
expected to be absolute ones.
The root of the problem seems to be that header images in Writer are
both repeated (as the user sees it) and unrepeated (as the doc model
sees it), and by the time we want to get its position, we only see the
unrepeated SdrObject.
Fix the problem by using the correct position from the scale action and
not from PDFExtOutDevData if possible.
(Also give up on running CppunitTest_vcl_pdfexport in the non-pdfium
case, most of the tests there do require pdfium anyway, and the growing
ifdef forest in that file just made it hard to read the code.)
Change-Id: I31c14d4bd223b2804859982542ebd6d5f9abd312
Reviewed-on: https://gerrit.libreoffice.org/54674
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf106702.odt | bin | 0 -> 42158 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 81 |
2 files changed, 66 insertions, 15 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf106702.odt b/vcl/qa/cppunit/pdfexport/data/tdf106702.odt Binary files differnew file mode 100644 index 000000000000..da3b7e81456e --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf106702.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 585b968d76d2..28803f0fd1b2 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -23,11 +23,9 @@ #include <unotools/tempfile.hxx> #include <vcl/filter/pdfdocument.hxx> #include <tools/zcodec.hxx> -#if HAVE_FEATURE_PDFIUM #include <fpdf_edit.h> #include <fpdf_text.h> #include <fpdfview.h> -#endif using namespace ::com::sun::star; @@ -39,15 +37,12 @@ class PdfExportTest : public test::BootstrapFixture, public unotest::MacrosTest { uno::Reference<uno::XComponentContext> mxComponentContext; uno::Reference<lang::XComponent> mxComponent; -#if HAVE_FEATURE_PDFIUM FPDF_PAGE mpPdfPage = nullptr; FPDF_DOCUMENT mpPdfDocument = nullptr; -#endif public: virtual void setUp() override; virtual void tearDown() override; -#if HAVE_FEATURE_PDFIUM void load(const OUString& rFile, vcl::filter::PDFDocument& rDocument); /// Tests that a pdf image is roundtripped back to PDF as a vector format. void testTdf106059(); @@ -86,10 +81,9 @@ public: #endif void testTdf109143(); void testTdf105954(); -#endif + void testTdf106702(); CPPUNIT_TEST_SUITE(PdfExportTest); -#if HAVE_FEATURE_PDFIUM CPPUNIT_TEST(testTdf106059); CPPUNIT_TEST(testTdf105461); CPPUNIT_TEST(testTdf107868); @@ -115,7 +109,7 @@ public: #endif CPPUNIT_TEST(testTdf109143); CPPUNIT_TEST(testTdf105954); -#endif + CPPUNIT_TEST(testTdf106702); CPPUNIT_TEST_SUITE_END(); }; @@ -126,23 +120,19 @@ void PdfExportTest::setUp() mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory())); mxDesktop.set(frame::Desktop::create(mxComponentContext)); -#if HAVE_FEATURE_PDFIUM FPDF_LIBRARY_CONFIG config; config.version = 2; config.m_pUserFontPaths = nullptr; config.m_pIsolate = nullptr; config.m_v8EmbedderSlot = 0; FPDF_InitLibraryWithConfig(&config); -#endif } void PdfExportTest::tearDown() { -#if HAVE_FEATURE_PDFIUM FPDF_ClosePage(mpPdfPage); FPDF_CloseDocument(mpPdfDocument); FPDF_DestroyLibrary(); -#endif if (mxComponent.is()) mxComponent->dispose(); @@ -150,8 +140,6 @@ void PdfExportTest::tearDown() test::BootstrapFixture::tearDown(); } -#if HAVE_FEATURE_PDFIUM - char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/pdfexport/data/"; void PdfExportTest::load(const OUString& rFile, vcl::filter::PDFDocument& rDocument) @@ -1343,7 +1331,70 @@ void PdfExportTest::testTdf105954() CPPUNIT_ASSERT_LESS(static_cast<unsigned int>(250), aMeta.width); } -#endif +void PdfExportTest::testTdf106702() +{ + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf106702.odt"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); + + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Parse the export result with pdfium. + SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + mpPdfDocument + = FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr); + CPPUNIT_ASSERT(mpPdfDocument); + + // The document has two pages. + CPPUNIT_ASSERT_EQUAL(2, FPDF_GetPageCount(mpPdfDocument)); + + // First page already has the correct image position. + mpPdfPage = FPDF_LoadPage(mpPdfDocument, /*page_index=*/0); + CPPUNIT_ASSERT(mpPdfPage); + int nExpected = 0; + int nPageObjectCount = FPDFPage_CountObjects(mpPdfPage); + for (int i = 0; i < nPageObjectCount; ++i) + { + FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(mpPdfPage, i); + if (FPDFPageObj_GetType(pPageObject) != FPDF_PAGEOBJ_IMAGE) + continue; + + float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0; + FPDFPageObj_GetBounds(pPageObject, &fLeft, &fBottom, &fRight, &fTop); + nExpected = fTop; + break; + } + + // Second page had an incorrect image position. + FPDF_ClosePage(mpPdfPage); + mpPdfPage = FPDF_LoadPage(mpPdfDocument, /*page_index=*/1); + CPPUNIT_ASSERT(mpPdfPage); + int nActual = 0; + nPageObjectCount = FPDFPage_CountObjects(mpPdfPage); + for (int i = 0; i < nPageObjectCount; ++i) + { + FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(mpPdfPage, i); + if (FPDFPageObj_GetType(pPageObject) != FPDF_PAGEOBJ_IMAGE) + continue; + + float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0; + FPDFPageObj_GetBounds(pPageObject, &fLeft, &fBottom, &fRight, &fTop); + nActual = fTop; + break; + } + + // This failed, vertical pos is 818 points, was 1674 (outside visible page + // bounds). + CPPUNIT_ASSERT_EQUAL(nExpected, nActual); +} CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest); |