[Libreoffice-commits] core.git: vcl/qa vcl/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Sep 12 07:12:34 UTC 2017


 vcl/qa/cppunit/pdfexport/data/tdf108963.odp |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx      |   55 ++++++++++++++++++++++++++++
 vcl/source/gdi/pdfwriter_impl.cxx           |   12 +++++-
 3 files changed, 66 insertions(+), 1 deletion(-)

New commits:
commit da705eff910f512623a689aaf28604270fb8f1c4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 11 22:38:49 2017 +0200

    tdf#108963 PDF export of editeng text highlight: handle rotated text
    
    The highlight rectangle was not rotated, handle it similar to
    PDFWriterImpl::drawStrikeoutChar().
    
    Change-Id: I97a5b1fc05706729c58c92b90d6808629af8ca4c
    Reviewed-on: https://gerrit.libreoffice.org/42180
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf108963.odp b/vcl/qa/cppunit/pdfexport/data/tdf108963.odp
new file mode 100644
index 000000000000..246c0c72ae8f
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf108963.odp differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index f00f21afff55..fecdee085f31 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -66,6 +66,7 @@ public:
     void testTdf107089();
     void testTdf99680();
     void testTdf99680_2();
+    void testTdf108963();
 #endif
 
     CPPUNIT_TEST_SUITE(PdfExportTest);
@@ -83,6 +84,7 @@ public:
     CPPUNIT_TEST(testTdf107089);
     CPPUNIT_TEST(testTdf99680);
     CPPUNIT_TEST(testTdf99680_2);
+    CPPUNIT_TEST(testTdf108963);
 #endif
     CPPUNIT_TEST_SUITE_END();
 };
@@ -674,6 +676,59 @@ void PdfExportTest::testTdf99680_2()
     }
 }
 
+void PdfExportTest::testTdf108963()
+{
+    // Import the bugdoc and export as PDF.
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf108963.odp";
+    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 one page.
+    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(mpPdfPage);
+    int nYellowPathCount = 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_YELLOW)
+        {
+            ++nYellowPathCount;
+            float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0;
+            FPDFPageObj_GetBounds(pPdfPageObject, &fLeft, &fBottom, &fRight, &fTop);
+            int nWidth = fRight - fLeft;
+            int nHeight = fTop - fBottom;
+            // This was 37 and 20, i.e. the bounding rectangle was much smaller
+            // as the highlight polygon wasn't rotated.
+            CPPUNIT_ASSERT_EQUAL(42, nWidth);
+            CPPUNIT_ASSERT_EQUAL(39, nHeight);
+        }
+    }
+
+    CPPUNIT_ASSERT_EQUAL(1, nYellowPathCount);
+}
 #endif
 
 CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 9e3db7068a25..d10671e50cb2 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -6807,7 +6807,17 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool
         aRectangle.SetSize(m_pReferenceDevice->PixelToLogic(Size(rLayout.GetTextWidth(), 0)));
         // This includes ascent / descent.
         aRectangle.setHeight(aRefDevFontMetric.GetLineHeight());
-        drawRectangle(aRectangle);
+
+        LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance;
+        if (pFontInstance->mnOrientation)
+        {
+            // Adapt rectangle for rotated text.
+            tools::Polygon aPolygon(aRectangle);
+            aPolygon.Rotate(m_pReferenceDevice->PixelToLogic(rLayout.GetDrawPosition()), pFontInstance->mnOrientation);
+            drawPolygon(aPolygon);
+        }
+        else
+            drawRectangle(aRectangle);
 
         pop();
     }


More information about the Libreoffice-commits mailing list