summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-06-28 12:34:19 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-06-29 14:35:56 +0200
commitb5b8da80439419a2daa6a80c9d3979173fe2887a (patch)
tree70c16aa6bc6682d289d03400b131d67e7973062d
parent440cb3fb80d9fd356871eac410b9797f23433722 (diff)
pdf: support PDF Form object and getMatrix
Change-Id: I61f2004df7f9c9ac37959e0b50ea1ff83387c77a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97365 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--include/vcl/filter/PDFiumLibrary.hxx6
-rw-r--r--svx/source/inc/svdpdf.hxx7
-rw-r--r--svx/source/svdraw/svdpdf.cxx30
-rw-r--r--vcl/source/pdf/PDFiumLibrary.cxx25
4 files changed, 51 insertions, 17 deletions
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index 501f964f395d..9f34bdb92ad6 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -20,6 +20,7 @@
#include <rtl/instance.hxx>
#include <basegfx/vector/b2dsize.hxx>
#include <basegfx/range/b2drectangle.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
#include <rtl/ustring.hxx>
#include <fpdf_doc.h>
@@ -87,6 +88,11 @@ public:
int getType();
OUString getText(std::unique_ptr<PDFiumTextPage> const& pTextPage);
+
+ int getFormObjectCount();
+ std::unique_ptr<PDFiumPageObject> getFormObject(int nIndex);
+
+ basegfx::B2DHomMatrix getMatrix();
};
class VCL_DLLPUBLIC PDFiumTextPage final
diff --git a/svx/source/inc/svdpdf.hxx b/svx/source/inc/svdpdf.hxx
index 71e66ff3deac..0bfdb2b3e6ef 100644
--- a/svx/source/inc/svdpdf.hxx
+++ b/svx/source/inc/svdpdf.hxx
@@ -107,9 +107,12 @@ class SVXCORE_DLLPUBLIC ImpSdrPdfImport final
void checkClip();
bool isClip() const;
- void ImportPdfObject(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage,
+ void ImportPdfObject(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
int nPageObjectIndex);
- void ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage, int nPageObjectIndex);
+ void ImportForm(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
+ int nPageObjectIndex);
void ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
void ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
void ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage, int nPageObjectIndex);
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 9fa8c82f722b..79693be693e1 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -169,7 +169,7 @@ void ImpSdrPdfImport::DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pAction
for (int nPageObjectIndex = 0; nPageObjectIndex < nPageObjectCount; ++nPageObjectIndex)
{
auto pPageObject = pPdfPage->getObject(nPageObjectIndex);
- ImportPdfObject(pPageObject->getPointer(), pTextPage->getPointer(), nPageObjectIndex);
+ ImportPdfObject(pPageObject, pTextPage, nPageObjectIndex);
if (pProgrInfo && pActionsToReport)
{
(*pActionsToReport)++;
@@ -666,23 +666,24 @@ void ImpSdrPdfImport::checkClip()
}
bool ImpSdrPdfImport::isClip() const { return !maClip.getB2DRange().isEmpty(); }
-void ImpSdrPdfImport::ImportPdfObject(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage,
- int nPageObjectIndex)
+void ImpSdrPdfImport::ImportPdfObject(
+ std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage, int nPageObjectIndex)
{
- if (pPageObject == nullptr)
+ if (!pPageObject)
return;
- const int nPageObjectType = FPDFPageObj_GetType(pPageObject);
+ const int nPageObjectType = pPageObject->getType();
switch (nPageObjectType)
{
case FPDF_PAGEOBJ_TEXT:
- ImportText(pPageObject, pTextPage, nPageObjectIndex);
+ ImportText(pPageObject->getPointer(), pTextPage->getPointer(), nPageObjectIndex);
break;
case FPDF_PAGEOBJ_PATH:
- ImportPath(pPageObject, nPageObjectIndex);
+ ImportPath(pPageObject->getPointer(), nPageObjectIndex);
break;
case FPDF_PAGEOBJ_IMAGE:
- ImportImage(pPageObject, nPageObjectIndex);
+ ImportImage(pPageObject->getPointer(), nPageObjectIndex);
break;
case FPDF_PAGEOBJ_SHADING:
SAL_WARN("sd.filter", "Got page object SHADING: " << nPageObjectIndex);
@@ -697,21 +698,20 @@ void ImpSdrPdfImport::ImportPdfObject(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE
}
}
-void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage,
+void ImpSdrPdfImport::ImportForm(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
int /*nPageObjectIndex*/)
{
// Get the form matrix to perform correct translation/scaling of the form sub-objects.
const basegfx::B2DHomMatrix aOldMatrix = maCurrentMatrix;
- FS_MATRIX matrix;
- FPDFFormObj_GetMatrix(pPageObject, &matrix);
- maCurrentMatrix
- = basegfx::B2DHomMatrix::abcdef(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
+ maCurrentMatrix = pPageObject->getMatrix();
- const int nCount = FPDFFormObj_CountObjects(pPageObject);
+ const int nCount = pPageObject->getFormObjectCount();
for (int nIndex = 0; nIndex < nCount; ++nIndex)
{
- FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(pPageObject, nIndex);
+ auto pFormObject = pPageObject->getFormObject(nIndex);
+
ImportPdfObject(pFormObject, pTextPage, -1);
}
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index 92d0cf84a201..0dc36d94b7d0 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -234,6 +234,31 @@ OUString PDFiumPageObject::getText(std::unique_ptr<PDFiumTextPage> const& pTextP
int PDFiumPageObject::getType() { return FPDFPageObj_GetType(mpPageObject); }
+int PDFiumPageObject::getFormObjectCount()
+{
+ return FPDFFormObj_CountObjects(mpPageObject);
+ ;
+}
+
+std::unique_ptr<PDFiumPageObject> PDFiumPageObject::getFormObject(int nIndex)
+{
+ std::unique_ptr<PDFiumPageObject> pPDFiumFormObject;
+ FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(mpPageObject, nIndex);
+ if (pFormObject)
+ {
+ pPDFiumFormObject = std::make_unique<PDFiumPageObject>(pFormObject);
+ }
+ return pPDFiumFormObject;
+}
+
+basegfx::B2DHomMatrix PDFiumPageObject::getMatrix()
+{
+ FS_MATRIX matrix;
+ FPDFFormObj_GetMatrix(mpPageObject, &matrix);
+ return basegfx::B2DHomMatrix::abcdef(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e,
+ matrix.f);
+}
+
PDFiumAnnotation::PDFiumAnnotation(FPDF_ANNOTATION pAnnotation)
: mpAnnotation(pAnnotation)
{