[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - vcl/qa vcl/source

Miklos Vajna vmiklos at collabora.co.uk
Tue May 23 10:04:41 UTC 2017


 vcl/qa/cppunit/pdfexport/data/tdf107868.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx      |  104 ++++++++++++++++++++++------
 vcl/source/gdi/pdfwriter_impl.cxx           |    5 +
 3 files changed, 89 insertions(+), 20 deletions(-)

New commits:
commit 98a5f3929af349beee2866e558922f9a3fb19923
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon May 22 21:41:31 2017 +0200

    tdf#105461 PDF export of editeng fill color: restrict to logic map modes
    
    The original use case was Writer/Impress shape text, but when the map
    mode is pixels, the reference device gives bogus values for the
    PixelToLogic() calls, affecting e.g. form controls.
    
    Just go back to the old way of not painting the background for those.
    
    (cherry picked from commit 919a4ef592b6026a7533a93682f39118fef29ce8)
    
    Change-Id: I52f1901af15732274915fa3c77c06909b5164afb
    Reviewed-on: https://gerrit.libreoffice.org/37939
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf107868.odt b/vcl/qa/cppunit/pdfexport/data/tdf107868.odt
new file mode 100644
index 000000000000..8309f4b878d6
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf107868.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 2e2d0f5b4972..b3661281d473 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -11,9 +11,11 @@
 
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/view/XPrintable.hpp>
 
 #include <comphelper/processfactory.hxx>
 #include <comphelper/propertyvalue.hxx>
+#include <comphelper/propertysequence.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <test/bootstrapfixture.hxx>
 #include <unotest/macros_test.hxx>
@@ -38,6 +40,10 @@ 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;
@@ -48,6 +54,7 @@ public:
     void testTdf106059();
     /// Tests that text highlight from Impress is not lost.
     void testTdf105461();
+    void testTdf107868();
     /// Tests that embedded video from Impress is not exported as a linked one.
     void testTdf105093();
     /// Tests export of non-PDF images.
@@ -65,6 +72,7 @@ public:
 #if HAVE_FEATURE_PDFIUM
     CPPUNIT_TEST(testTdf106059);
     CPPUNIT_TEST(testTdf105461);
+    CPPUNIT_TEST(testTdf107868);
     CPPUNIT_TEST(testTdf105093);
     CPPUNIT_TEST(testTdf106206);
     CPPUNIT_TEST(testTdf106693);
@@ -83,10 +91,25 @@ 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();
 
@@ -197,14 +220,6 @@ void PdfExportTest::testTdf106693()
 
 void PdfExportTest::testTdf105461()
 {
-    // Setup.
-    FPDF_LIBRARY_CONFIG config;
-    config.version = 2;
-    config.m_pUserFontPaths = nullptr;
-    config.m_pIsolate = nullptr;
-    config.m_v8EmbedderSlot = 0;
-    FPDF_InitLibraryWithConfig(&config);
-
     // Import the bugdoc and export as PDF.
     OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf105461.odp";
     mxComponent = loadFromDesktop(aURL);
@@ -221,20 +236,20 @@ void PdfExportTest::testTdf105461()
     SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ);
     SvMemoryStream aMemory;
     aMemory.WriteStream(aFile);
-    FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr);
-    CPPUNIT_ASSERT(pPdfDocument);
+    mpPdfDocument = FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr);
+    CPPUNIT_ASSERT(mpPdfDocument);
 
     // The document has one page.
-    CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument));
-    FPDF_PAGE pPdfPage = FPDF_LoadPage(pPdfDocument, /*page_index=*/0);
-    CPPUNIT_ASSERT(pPdfPage);
+    CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(mpPdfDocument));
+    mpPdfPage = FPDF_LoadPage(mpPdfDocument, /*page_index=*/0);
+    CPPUNIT_ASSERT(mpPdfPage);
 
     // Make sure there is a filled rectangle inside.
-    int nPageObjectCount = FPDFPage_CountObject(pPdfPage);
+    int nPageObjectCount = FPDFPage_CountObject(mpPdfPage);
     int nYellowPathCount = 0;
     for (int i = 0; i < nPageObjectCount; ++i)
     {
-        FPDF_PAGEOBJECT pPdfPageObject = FPDFPage_GetObject(pPdfPage, i);
+        FPDF_PAGEOBJECT pPdfPageObject = FPDFPage_GetObject(mpPdfPage, i);
         if (FPDFPageObj_GetType(pPdfPageObject) != FPDF_PAGEOBJ_PATH)
             continue;
 
@@ -246,11 +261,62 @@ void PdfExportTest::testTdf105461()
 
     // This was 0, the page contained no yellow paths.
     CPPUNIT_ASSERT_EQUAL(1, nYellowPathCount);
+}
 
-    // Cleanup.
-    FPDF_ClosePage(pPdfPage);
-    FPDF_CloseDocument(pPdfDocument);
-    FPDF_DestroyLibrary();
+void PdfExportTest::testTdf107868()
+{
+    // FIXME why does this fail on macOS?
+#ifndef MACOSX
+    // Import the bugdoc and print to PDF.
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf107868.odt";
+    mxComponent = loadFromDesktop(aURL);
+    CPPUNIT_ASSERT(mxComponent.is());
+
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    utl::TempFile aTempFile;
+    aTempFile.EnableKillingFile();
+    uno::Reference<view::XPrintable> xPrintable(mxComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xPrintable.is());
+    uno::Sequence<beans::PropertyValue> aOptions(comphelper::InitPropertySequence(
+    {
+        {"FileName", uno::makeAny(aTempFile.GetURL())},
+        {"Wait", uno::makeAny(true)}
+    }));
+    xPrintable->print(aOptions);
+
+    // 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);
+    if (!mpPdfDocument)
+        // Printing to PDF failed in a non-interesting way, e.g. CUPS is not
+        // running, there is no printer defined, etc.
+        return;
+
+    // The document has one page.
+    CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(mpPdfDocument));
+    mpPdfPage = FPDF_LoadPage(mpPdfDocument, /*page_index=*/0);
+    CPPUNIT_ASSERT(mpPdfPage);
+
+    // Make sure there is no filled rectangle inside.
+    int nPageObjectCount = FPDFPage_CountObject(mpPdfPage);
+    int nWhitePathCount = 0;
+    for (int i = 0; i < nPageObjectCount; ++i)
+    {
+        FPDF_PAGEOBJECT pPdfPageObject = FPDFPage_GetObject(mpPdfPage, i);
+        if (FPDFPageObj_GetType(pPdfPageObject) != FPDF_PAGEOBJ_PATH)
+            continue;
+
+        unsigned int nRed = 0, nGreen = 0, nBlue = 0, nAlpha = 0;
+        FPDFPath_GetFillColor(pPdfPageObject, &nRed, &nGreen, &nBlue, &nAlpha);
+        if (RGB_COLORDATA(nRed, nGreen, nBlue) == COL_WHITE)
+            ++nWhitePathCount;
+    }
+
+    // This was 4, the page contained 4 white paths at problematic positions.
+    CPPUNIT_ASSERT_EQUAL(0, nWhitePathCount);
+#endif
 }
 
 void PdfExportTest::testTdf105093()
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index d97948b666a6..3ee96131e070 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8715,7 +8715,10 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool
         }
     }
 
-    if (m_aCurrentPDFState.m_aFont.GetFillColor() != Color(COL_TRANSPARENT))
+    // Avoid fill color when map mode is in pixels, the below code assumes
+    // logic map mode.
+    bool bPixel = m_aCurrentPDFState.m_aMapMode.GetMapUnit() == MapUnit::MapPixel;
+    if (m_aCurrentPDFState.m_aFont.GetFillColor() != Color(COL_TRANSPARENT) && !bPixel)
     {
         // PDF doesn't have a text fill color, so draw a rectangle before
         // drawing the actual text.


More information about the Libreoffice-commits mailing list