summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/vcl/filter/PDFiumLibrary.hxx3
-rw-r--r--include/vcl/pdf/PDFPageObjectType.hxx27
-rw-r--r--svx/source/svdraw/svdpdf.cxx18
-rw-r--r--vcl/qa/cppunit/PDFiumLibraryTest.cxx2
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx54
-rw-r--r--vcl/source/pdf/PDFiumLibrary.cxx22
6 files changed, 82 insertions, 44 deletions
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index eb5cf3b9c769..0eb2373a4400 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -28,6 +28,7 @@
#include <vcl/checksum.hxx>
#include <vcl/Scanline.hxx>
#include <vcl/pdf/PDFAnnotationSubType.hxx>
+#include <vcl/pdf/PDFPageObjectType.hxx>
#include <fpdf_doc.h>
@@ -149,7 +150,7 @@ public:
FPDF_PAGEOBJECT getPointer() { return mpPageObject; }
- int getType();
+ PDFPageObjectType getType();
OUString getText(std::unique_ptr<PDFiumTextPage> const& pTextPage);
int getFormObjectCount();
diff --git a/include/vcl/pdf/PDFPageObjectType.hxx b/include/vcl/pdf/PDFPageObjectType.hxx
new file mode 100644
index 000000000000..68e763e64b40
--- /dev/null
+++ b/include/vcl/pdf/PDFPageObjectType.hxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+namespace vcl::pdf
+{
+enum class PDFPageObjectType
+{
+ Unknown = 0,
+ Text = 1,
+ Path = 2,
+ Image = 3,
+ Shading = 4,
+ Form = 5
+};
+
+} // namespace vcl::pdf
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 3a8b60951d4a..c7e6f223b10f 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -669,27 +669,27 @@ void ImpSdrPdfImport::ImportPdfObject(
if (!pPageObject)
return;
- const int nPageObjectType = pPageObject->getType();
- switch (nPageObjectType)
+ const vcl::pdf::PDFPageObjectType ePageObjectType = pPageObject->getType();
+ switch (ePageObjectType)
{
- case FPDF_PAGEOBJ_TEXT:
+ case vcl::pdf::PDFPageObjectType::Text:
ImportText(pPageObject, pTextPage, nPageObjectIndex);
break;
- case FPDF_PAGEOBJ_PATH:
+ case vcl::pdf::PDFPageObjectType::Path:
ImportPath(pPageObject, nPageObjectIndex);
break;
- case FPDF_PAGEOBJ_IMAGE:
+ case vcl::pdf::PDFPageObjectType::Image:
ImportImage(pPageObject, nPageObjectIndex);
break;
- case FPDF_PAGEOBJ_SHADING:
+ case vcl::pdf::PDFPageObjectType::Shading:
SAL_WARN("sd.filter", "Got page object SHADING: " << nPageObjectIndex);
break;
- case FPDF_PAGEOBJ_FORM:
+ case vcl::pdf::PDFPageObjectType::Form:
ImportForm(pPageObject, pTextPage, nPageObjectIndex);
break;
default:
- SAL_WARN("sd.filter", "Unknown PDF page object #" << nPageObjectIndex
- << " of type: " << nPageObjectType);
+ SAL_WARN("sd.filter", "Unknown PDF page object #" << nPageObjectIndex << " of type: "
+ << static_cast<int>(ePageObjectType));
break;
}
}
diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
index 6b4dbedff185..577f73ed1130 100644
--- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx
+++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
@@ -136,7 +136,7 @@ void PDFiumLibraryTest::testPageObjects()
auto pPageObject = pPage->getObject(0);
auto pTextPage = pPage->getTextPage();
- CPPUNIT_ASSERT_EQUAL(1, pPageObject->getType()); // FPDF_PAGEOBJ_TEXT
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Text, pPageObject->getType());
CPPUNIT_ASSERT_EQUAL(OUString("The quick, brown fox jumps over a lazy dog. DJs flock by when "
"MTV ax quiz prog. Junk MTV quiz "),
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 762bdf0dbce1..484e2c355461 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -257,7 +257,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf105461)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPdfPageObject = pPdfPage->getObject(i);
- if (pPdfPageObject->getType() != FPDF_PAGEOBJ_PATH)
+ if (pPdfPageObject->getType() != vcl::pdf::PDFPageObjectType::Path)
continue;
if (pPdfPageObject->getFillColor() == COL_YELLOW)
@@ -313,7 +313,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf107868)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPdfPageObject = pPdfPage->getObject(i);
- if (pPdfPageObject->getType() != FPDF_PAGEOBJ_PATH)
+ if (pPdfPageObject->getType() != vcl::pdf::PDFPageObjectType::Path)
continue;
if (pPdfPageObject->getFillColor() == COL_WHITE)
@@ -577,7 +577,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testSofthyphenPos)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPdfPageObject = pPdfPage->getObject(i);
- CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_TEXT, pPdfPageObject->getType());
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Text, pPdfPageObject->getType());
haveText = true;
double const size = pPdfPageObject->getFontSize();
CPPUNIT_ASSERT_DOUBLES_EQUAL(11.05, size, 1E-06);
@@ -819,7 +819,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf108963)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPdfPageObject = pPdfPage->getObject(i);
- if (pPdfPageObject->getType() != FPDF_PAGEOBJ_PATH)
+ if (pPdfPageObject->getType() != vcl::pdf::PDFPageObjectType::Path)
continue;
if (pPdfPageObject->getFillColor() == COL_YELLOW)
@@ -1445,7 +1445,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf128630)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
- if (pPageObject->getType() != FPDF_PAGEOBJ_IMAGE)
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Image)
continue;
std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap();
@@ -1479,7 +1479,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf106702)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
- if (pPageObject->getType() != FPDF_PAGEOBJ_IMAGE)
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Image)
continue;
float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0;
@@ -1496,7 +1496,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf106702)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
- if (pPageObject->getType() != FPDF_PAGEOBJ_IMAGE)
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Image)
continue;
float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0;
@@ -1537,7 +1537,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf113143)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
- if (pPageObject->getType() != FPDF_PAGEOBJ_IMAGE)
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Image)
continue;
float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0;
@@ -1554,7 +1554,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf113143)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
- if (pPageObject->getType() != FPDF_PAGEOBJ_IMAGE)
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Image)
continue;
float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0;
@@ -1602,11 +1602,11 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115262)
float fLeft = 0, fBottom = 0, fRight = 0, fTop = 0;
FPDFPageObj_GetBounds(pPageObject->getPointer(), &fLeft, &fBottom, &fRight, &fTop);
- if (pPageObject->getType() == FPDF_PAGEOBJ_IMAGE)
+ if (pPageObject->getType() == vcl::pdf::PDFPageObjectType::Image)
{
nFirstImageTop = fTop;
}
- else if (pPageObject->getType() == FPDF_PAGEOBJ_TEXT)
+ else if (pPageObject->getType() == vcl::pdf::PDFPageObjectType::Text)
{
OUString sText = pPageObject->getText(pTextPage);
if (sText == "400")
@@ -1637,7 +1637,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf121962)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
- if (pPageObject->getType() != FPDF_PAGEOBJ_TEXT)
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Text)
continue;
OUString sText = pPageObject->getText(pTextPage);
CPPUNIT_ASSERT(sText != "** Expression is faulty **");
@@ -1664,7 +1664,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115967)
for (int i = 0; i < nPageObjectCount; ++i)
{
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
- if (pPageObject->getType() != FPDF_PAGEOBJ_TEXT)
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Text)
continue;
OUString sChar = pPageObject->getText(pTextPage);
sText += sChar.trim();
@@ -1785,7 +1785,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testReduceSmallImage)
CPPUNIT_ASSERT(pPdfPage);
CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(0);
- CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_IMAGE, pPageObject->getType());
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Image, pPageObject->getType());
// Make sure we don't scale down a tiny bitmap.
std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap();
@@ -1840,7 +1840,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testReduceImage)
CPPUNIT_ASSERT(pPdfPage);
CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(0);
- CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_IMAGE, pPageObject->getType());
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Image, pPageObject->getType());
// Make sure we don't scale down a bitmap.
std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap();
@@ -1947,27 +1947,25 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageResourceInlineXObjectRef)
CPPUNIT_ASSERT(pPdfPage);
CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(0);
- CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, pPageObject->getType());
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, pPageObject->getType());
// 2: white background and the actual object.
- CPPUNIT_ASSERT_EQUAL(2, FPDFFormObj_CountObjects(pPageObject->getPointer()));
- FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(pPageObject->getPointer(), 1);
- CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(pFormObject));
+ CPPUNIT_ASSERT_EQUAL(2, pPageObject->getFormObjectCount());
+ std::unique_ptr<vcl::pdf::PDFiumPageObject> pFormObject = pPageObject->getFormObject(1);
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, pFormObject->getType());
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1
// - Actual : 0
// i.e. the sub-form was missing its image.
- CPPUNIT_ASSERT_EQUAL(1, FPDFFormObj_CountObjects(pFormObject));
+ CPPUNIT_ASSERT_EQUAL(1, pFormObject->getFormObjectCount());
// Check if the inner form object (original page object in the pdf image) has the correct
// rotation.
- FPDF_PAGEOBJECT pInnerFormObject = FPDFFormObj_GetObject(pFormObject, 0);
- CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(pInnerFormObject));
- CPPUNIT_ASSERT_EQUAL(1, FPDFFormObj_CountObjects(pInnerFormObject));
- FPDF_PAGEOBJECT pImage = FPDFFormObj_GetObject(pInnerFormObject, 0);
- CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(pImage));
- FS_MATRIX aMatrix;
- FPDFFormObj_GetMatrix(pInnerFormObject, &aMatrix);
- basegfx::B2DHomMatrix aMat{ aMatrix.a, aMatrix.c, aMatrix.e, aMatrix.b, aMatrix.d, aMatrix.f };
+ std::unique_ptr<vcl::pdf::PDFiumPageObject> pInnerFormObject = pFormObject->getFormObject(0);
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, pInnerFormObject->getType());
+ CPPUNIT_ASSERT_EQUAL(1, pInnerFormObject->getFormObjectCount());
+ std::unique_ptr<vcl::pdf::PDFiumPageObject> pImage = pInnerFormObject->getFormObject(0);
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Image, pImage->getType());
+ basegfx::B2DHomMatrix aMat = pInnerFormObject->getMatrix();
basegfx::B2DTuple aScale;
basegfx::B2DTuple aTranslate;
double fRotate = 0;
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index 69facd1bf001..ae1588e4a268 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -26,6 +26,19 @@
#include <bitmapwriteaccess.hxx>
+static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Unknown) == FPDF_PAGEOBJ_UNKNOWN,
+ "PDFPageObjectType::Unknown value mismatch");
+static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Text) == FPDF_PAGEOBJ_TEXT,
+ "PDFPageObjectType::Text value mismatch");
+static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Path) == FPDF_PAGEOBJ_PATH,
+ "PDFPageObjectType::Path value mismatch");
+static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Image) == FPDF_PAGEOBJ_IMAGE,
+ "PDFPageObjectType::Image value mismatch");
+static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Shading) == FPDF_PAGEOBJ_SHADING,
+ "PDFPageObjectType::Shading value mismatch");
+static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Form) == FPDF_PAGEOBJ_FORM,
+ "PDFPageObjectType::Form value mismatch");
+
namespace
{
/// Callback class to be used with FPDF_SaveWithVersion().
@@ -310,14 +323,13 @@ OUString PDFiumPageObject::getText(std::unique_ptr<PDFiumTextPage> const& pTextP
return sReturnText;
}
-int PDFiumPageObject::getType() { return FPDFPageObj_GetType(mpPageObject); }
-
-int PDFiumPageObject::getFormObjectCount()
+PDFPageObjectType PDFiumPageObject::getType()
{
- return FPDFFormObj_CountObjects(mpPageObject);
- ;
+ return static_cast<PDFPageObjectType>(FPDFPageObj_GetType(mpPageObject));
}
+int PDFiumPageObject::getFormObjectCount() { return FPDFFormObj_CountObjects(mpPageObject); }
+
std::unique_ptr<PDFiumPageObject> PDFiumPageObject::getFormObject(int nIndex)
{
std::unique_ptr<PDFiumPageObject> pPDFiumFormObject;