diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-09-11 22:38:49 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-09-12 09:12:13 +0200 |
commit | da705eff910f512623a689aaf28604270fb8f1c4 (patch) | |
tree | cf58069487ef5e55446999438593935f811bfb3d /vcl | |
parent | 7281f4a73ec3679798a6271ab5a0ad839f278e37 (diff) |
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@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf108963.odp | bin | 0 -> 10369 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 55 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 12 |
3 files changed, 66 insertions, 1 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf108963.odp b/vcl/qa/cppunit/pdfexport/data/tdf108963.odp Binary files differnew file mode 100644 index 000000000000..246c0c72ae8f --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf108963.odp 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(); } |