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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Oct 14 06:41:19 UTC 2020


 include/vcl/filter/PDFiumLibrary.hxx   |    3 +
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   52 +++------------------------------
 vcl/source/pdf/PDFiumLibrary.cxx       |    7 ++++
 3 files changed, 16 insertions(+), 46 deletions(-)

New commits:
commit 7c88c0089af36bc8075b87480669e78385d6b878
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Oct 13 21:03:46 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Oct 14 08:40:40 2020 +0200

    pdfium: add an FPDFImageObj_GetImageMetadata() wrapper
    
    And in general use more pdfium wrappers in CppunitTest_vcl_pdfexport, so
    all the '#if defined OSL_BIGENDIAN' checks can be removed.
    
    Change-Id: Id05e6ecf3dbb103a263d6068085eede847be320f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104254
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index 2664d2bccb39..877308d7d40b 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -24,6 +24,7 @@
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <rtl/ustring.hxx>
 #include <tools/color.hxx>
+#include <tools/gen.hxx>
 #include <vcl/checksum.hxx>
 #include <vcl/pdf/PDFAnnotationSubType.hxx>
 
@@ -81,6 +82,7 @@ public:
     std::vector<basegfx::B2DPoint> getVertices();
 };
 
+class PDFiumPage;
 class PDFiumTextPage;
 
 class VCL_DLLPUBLIC PDFiumPathSegment final
@@ -131,6 +133,7 @@ public:
     // Path
     int getPathSegmentCount();
     std::unique_ptr<PDFiumPathSegment> getPathSegment(int index);
+    Size getImageSize(PDFiumPage& rPage);
 };
 
 class VCL_DLLPUBLIC PDFiumTextPage final
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index d4195b1844ce..8dab51e76805 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -29,7 +29,6 @@
 #include <comphelper/scopeguard.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/propertysequence.hxx>
-#include <osl/endian.h>
 #include <test/bootstrapfixture.hxx>
 #include <unotest/macros_test.hxx>
 #include <unotools/mediadescriptor.hxx>
@@ -1422,11 +1421,10 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf105954)
 
     // Check width of the image.
     std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(/*index=*/0);
-    FPDF_IMAGEOBJ_METADATA aMeta;
-    CPPUNIT_ASSERT(FPDFImageObj_GetImageMetadata(pPageObject->getPointer(), pPdfPage->getPointer(), &aMeta));
+    Size aMeta = pPageObject->getImageSize(*pPdfPage);
     // This was 2000, i.e. the 'reduce to 300 DPI' request was ignored.
     // This is now around 238 (228 on macOS).
-    CPPUNIT_ASSERT_LESS(static_cast<unsigned int>(250), aMeta.width);
+    CPPUNIT_ASSERT_LESS(static_cast<long>(250), aMeta.getWidth());
 }
 
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf128630)
@@ -1611,16 +1609,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115262)
         }
         else if (pPageObject->getType() == FPDF_PAGEOBJ_TEXT)
         {
-            unsigned long nTextSize = FPDFTextObj_GetText(pPageObject->getPointer(), pTextPage->getPointer(), nullptr, 0);
-            std::vector<sal_Unicode> aText(nTextSize);
-            FPDFTextObj_GetText(pPageObject->getPointer(), pTextPage->getPointer(), aText.data(), nTextSize);
-#if defined OSL_BIGENDIAN
-            // The data returned by FPDFTextObj_GetText is documented to always be UTF-16LE:
-            for (auto & j: aText) {
-                j = OSL_SWAPWORD(j);
-            }
-#endif
-            OUString sText(aText.data(), nTextSize / 2 - 1);
+            OUString sText = pPageObject->getText(pTextPage);
             if (sText == "400")
                 nRowTop = fTop;
         }
@@ -1651,16 +1640,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf121962)
         std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
         if (pPageObject->getType() != FPDF_PAGEOBJ_TEXT)
             continue;
-        unsigned long nTextSize = FPDFTextObj_GetText(pPageObject->getPointer(), pTextPage->getPointer(), nullptr, 0);
-        std::vector<sal_Unicode> aText(nTextSize);
-        FPDFTextObj_GetText(pPageObject->getPointer(), pTextPage->getPointer(), aText.data(), nTextSize);
-#if defined OSL_BIGENDIAN
-        // The data returned by FPDFTextObj_GetText is documented to always be UTF-16LE:
-        for (auto & j: aText) {
-            j = OSL_SWAPWORD(j);
-        }
-#endif
-        OUString sText(aText.data(), nTextSize / 2 - 1);
+        OUString sText = pPageObject->getText(pTextPage);
         CPPUNIT_ASSERT(sText != "** Expression is faulty **");
     }
 }
@@ -1687,16 +1667,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115967)
         std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
         if (pPageObject->getType() != FPDF_PAGEOBJ_TEXT)
             continue;
-        unsigned long nTextSize = FPDFTextObj_GetText(pPageObject->getPointer(), pTextPage->getPointer(), nullptr, 2);
-        std::vector<sal_Unicode> aText(nTextSize);
-        FPDFTextObj_GetText(pPageObject->getPointer(), pTextPage->getPointer(), aText.data(), nTextSize);
-#if defined OSL_BIGENDIAN
-        // The data returned by FPDFTextObj_GetText is documented to always be UTF-16LE:
-        for (auto & j: aText) {
-            j = OSL_SWAPWORD(j);
-        }
-#endif
-        OUString sChar(aText.data(), nTextSize / 2 - 1);
+        OUString sChar = pPageObject->getText(pTextPage);
         sText += sChar.trim();
     }
     CPPUNIT_ASSERT_EQUAL(OUString("m=750abc"), sText);
@@ -2227,18 +2198,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testFormFontName)
     // Examine the default appearance.
     CPPUNIT_ASSERT(pAnnot->hasKey("DA"));
     CPPUNIT_ASSERT_EQUAL(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(pAnnot->getPointer(), "DA"));
-    size_t nDALength = FPDFAnnot_GetStringValue(pAnnot->getPointer(), "DA", nullptr, 0);
-    CPPUNIT_ASSERT_EQUAL(std::size_t(0), nDALength % 2);
-    std::vector<sal_Unicode> aDABuf(nDALength / 2);
-    FPDFAnnot_GetStringValue(
-        pAnnot->getPointer(), "DA", reinterpret_cast<FPDF_WCHAR *>(aDABuf.data()), nDALength);
-#if defined OSL_BIGENDIAN
-    // The data returned by FPDFAnnot_GetStringValue is documented to always be UTF-16LE:
-    for (auto & i: aDABuf) {
-        i = OSL_SWAPWORD(i);
-    }
-#endif
-    OUString aDA(reinterpret_cast<sal_Unicode*>(aDABuf.data()));
+    OUString aDA = pAnnot->getString("DA");
 
     // Without the accompanying fix in place, this test would have failed with:
     // - Expected: 0 0 0 rg /TiRo 12 Tf
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index a0668d0c6048..b8d0cb536be7 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -355,6 +355,13 @@ std::unique_ptr<PDFiumPathSegment> PDFiumPageObject::getPathSegment(int index)
     return pPDFiumPathSegment;
 }
 
+Size PDFiumPageObject::getImageSize(PDFiumPage& rPage)
+{
+    FPDF_IMAGEOBJ_METADATA aMeta;
+    FPDFImageObj_GetImageMetadata(mpPageObject, rPage.getPointer(), &aMeta);
+    return Size(aMeta.width, aMeta.height);
+}
+
 BitmapChecksum PDFiumPage::getChecksum()
 {
     size_t nPageWidth = getWidth();


More information about the Libreoffice-commits mailing list