17#include <fpdf_annot.h>
21#include <fpdf_signature.h>
22#include <fpdf_formfill.h>
24#include <osl/endian.h>
35 "PDFPageObjectType::Unknown value mismatch");
37 "PDFPageObjectType::Text value mismatch");
39 "PDFPageObjectType::Path value mismatch");
41 "PDFPageObjectType::Image value mismatch");
43 "PDFPageObjectType::Shading value mismatch");
45 "PDFPageObjectType::Form value mismatch");
48 "PDFSegmentType::Unknown value mismatch");
50 "PDFSegmentType::Lineto value mismatch");
52 "PDFSegmentType::Bezierto value mismatch");
54 "PDFSegmentType::Moveto value mismatch");
57 "PDFBitmapType::Unknown value mismatch");
59 "PDFBitmapType::Gray value mismatch");
61 "PDFBitmapType::BGR value mismatch");
63 "PDFBitmapType::BGRx value mismatch");
65 "PDFBitmapType::BGRA value mismatch");
68 "PDFObjectType::Unknown value mismatch");
70 "PDFObjectType::Boolean value mismatch");
72 "PDFObjectType::Number value mismatch");
74 "PDFObjectType::String value mismatch");
76 "PDFObjectType::Name value mismatch");
78 "PDFObjectType::Array value mismatch");
80 "PDFObjectType::Dictionary value mismatch");
82 "PDFObjectType::Stream value mismatch");
84 "PDFObjectType::Nullobj value mismatch");
86 "PDFObjectType::Reference value mismatch");
89 "PDFTextRenderMode::Unknown value mismatch");
91 "PDFTextRenderMode::Fill value mismatch");
93 "PDFTextRenderMode::Stroke value mismatch");
95 == FPDF_TEXTRENDERMODE_FILL_STROKE,
96 "PDFTextRenderMode::FillStroke value mismatch");
98 == FPDF_TEXTRENDERMODE_INVISIBLE,
99 "PDFTextRenderMode::Invisible value mismatch");
101 == FPDF_TEXTRENDERMODE_FILL_CLIP,
102 "PDFTextRenderMode::FillClip value mismatch");
104 == FPDF_TEXTRENDERMODE_STROKE_CLIP,
105 "PDFTextRenderMode::StrokeClip value mismatch");
107 == FPDF_TEXTRENDERMODE_FILL_STROKE_CLIP,
108 "PDFTextRenderMode::FillStrokeClip value mismatch");
110 "PDFTextRenderMode::Clip value mismatch");
113 "PDFFillMode::None value mismatch");
115 "PDFFillMode::Alternate value mismatch");
117 "PDFFillMode::Winding value mismatch");
120 "PDFFindFlags::MatchCase value mismatch");
122 "PDFFindFlags::MatchWholeWord value mismatch");
124 "PDFFindFlags::Consecutive value mismatch");
127 "PDFErrorType::Success value mismatch");
129 "PDFErrorType::Unknown value mismatch");
131 "PDFErrorType::File value mismatch");
133 "PDFErrorType::Format value mismatch");
135 "PDFErrorType::Password value mismatch");
137 "PDFErrorType::Security value mismatch");
139 "PDFErrorType::Page value mismatch");
142 "PDFFormFieldType::Unknown value mismatch");
144 "PDFFormFieldType::PushButton value mismatch");
146 "PDFFormFieldType::CheckBox value mismatch");
148 == FPDF_FORMFIELD_RADIOBUTTON,
149 "PDFFormFieldType::RadioButton value mismatch");
151 "PDFFormFieldType::ComboBox value mismatch");
153 "PDFFormFieldType::ListBox value mismatch");
155 "PDFFormFieldType::TextField value mismatch");
157 "PDFFormFieldType::Signature value mismatch");
160 == FPDF_ANNOT_AACTION_KEY_STROKE,
161 "PDFAnnotAActionType::KeyStroke) value mismatch");
163 "PDFAnnotAActionType::Format) value mismatch");
165 == FPDF_ANNOT_AACTION_VALIDATE,
166 "PDFAnnotAActionType::Validate) value mismatch");
168 == FPDF_ANNOT_AACTION_CALCULATE,
169 "PDFAnnotAActionType::Calculate) value mismatch");
174struct CompatibleWriter :
public FPDF_FILEWRITE
184int CompatibleWriterCallback(FPDF_FILEWRITE* pFileWrite,
const void* pData,
unsigned long nSize)
186 auto pImpl =
static_cast<CompatibleWriter*
>(pFileWrite);
196class PDFiumBitmapImpl final :
public PDFiumBitmap
201 PDFiumBitmapImpl(
const PDFiumBitmapImpl&) =
delete;
202 PDFiumBitmapImpl& operator=(
const PDFiumBitmapImpl&) =
delete;
205 PDFiumBitmapImpl(FPDF_BITMAP pBitmap);
206 ~PDFiumBitmapImpl()
override;
207 FPDF_BITMAP getPointer() {
return mpBitmap; }
209 void fillRect(
int left,
int top,
int width,
int height, sal_uInt32 nColor)
override;
210 void renderPageBitmap(PDFiumDocument* pDoc, PDFiumPage* pPage,
int nStartX,
int nStartY,
211 int nSizeX,
int nSizeY)
override;
213 int getStride()
override;
214 int getWidth()
override;
215 int getHeight()
override;
219class PDFiumPathSegmentImpl final :
public PDFiumPathSegment
224 PDFiumPathSegmentImpl(
const PDFiumPathSegmentImpl&) =
delete;
225 PDFiumPathSegmentImpl& operator=(
const PDFiumPathSegmentImpl&) =
delete;
228 PDFiumPathSegmentImpl(FPDF_PATHSEGMENT pPathSegment);
231 bool isClosed()
const override;
235class PDFiumAnnotationImpl final :
public PDFiumAnnotation
240 PDFiumAnnotationImpl(
const PDFiumAnnotationImpl&) =
delete;
241 PDFiumAnnotationImpl& operator=(
const PDFiumAnnotationImpl&) =
delete;
244 PDFiumAnnotationImpl(FPDF_ANNOTATION pAnnotation);
245 ~PDFiumAnnotationImpl();
250 bool hasKey(OString
const& rKey)
override;
252 OUString
getString(OString
const& rKey)
override;
253 std::unique_ptr<PDFiumAnnotation> getLinked(OString
const& rKey)
override;
254 int getObjectCount()
override;
255 std::unique_ptr<PDFiumPageObject> getObject(
int nIndex)
override;
256 std::vector<std::vector<basegfx::B2DPoint>> getInkStrokes()
override;
257 std::vector<basegfx::B2DPoint> getVertices()
override;
259 Color getInteriorColor()
override;
260 float getBorderWidth()
override;
262 size_t getAttachmentPointsCount()
override;
263 std::vector<basegfx::B2DPoint> getAttachmentPoints(
size_t nIndex)
override;
264 std::vector<basegfx::B2DPoint> getLineGeometry()
override;
266 float getFontSize(PDFiumDocument* pDoc)
override;
267 OUString getFormFieldAlternateName(PDFiumDocument* pDoc)
override;
268 int getFormFieldFlags(PDFiumDocument* pDoc)
override;
269 OUString getFormAdditionalActionJavaScript(PDFiumDocument* pDoc,
271 OUString getFormFieldValue(PDFiumDocument* pDoc)
override;
274class PDFiumPageObjectImpl final :
public PDFiumPageObject
279 PDFiumPageObjectImpl(
const PDFiumPageObjectImpl&) =
delete;
280 PDFiumPageObjectImpl& operator=(
const PDFiumPageObjectImpl&) =
delete;
283 PDFiumPageObjectImpl(FPDF_PAGEOBJECT pPageObject);
286 OUString getText(std::unique_ptr<PDFiumTextPage>
const& pTextPage)
override;
288 int getFormObjectCount()
override;
289 std::unique_ptr<PDFiumPageObject> getFormObject(
int nIndex)
override;
293 double getFontSize()
override;
294 OUString getFontName()
override;
296 Color getFillColor()
override;
297 Color getStrokeColor()
override;
298 double getStrokeWidth()
override;
300 int getPathSegmentCount()
override;
301 std::unique_ptr<PDFiumPathSegment> getPathSegment(
int index)
override;
302 Size getImageSize(PDFiumPage& rPage)
override;
303 std::unique_ptr<PDFiumBitmap> getImageBitmap()
override;
304 bool getDrawMode(
PDFFillMode& eFillMode,
bool& bStroke)
override;
307class PDFiumSearchHandleImpl final :
public PDFiumSearchHandle
312 PDFiumSearchHandleImpl(
const PDFiumSearchHandleImpl&) =
delete;
313 PDFiumSearchHandleImpl& operator=(
const PDFiumSearchHandleImpl&) =
delete;
316 PDFiumSearchHandleImpl(FPDF_SCHHANDLE pSearchHandle);
317 ~PDFiumSearchHandleImpl();
319 bool findNext()
override;
320 bool findPrev()
override;
321 int getSearchResultIndex()
override;
322 int getSearchCount()
override;
325class PDFiumTextPageImpl final :
public PDFiumTextPage
330 PDFiumTextPageImpl(
const PDFiumTextPageImpl&) =
delete;
331 PDFiumTextPageImpl& operator=(
const PDFiumTextPageImpl&) =
delete;
334 PDFiumTextPageImpl(FPDF_TEXTPAGE pTextPage);
335 ~PDFiumTextPageImpl();
337 FPDF_TEXTPAGE getPointer() {
return mpTextPage; }
339 int countChars()
override;
340 unsigned int getUnicode(
int index)
override;
341 std::unique_ptr<PDFiumSearchHandle> findStart(
const OUString& rFindWhat,
PDFFindFlags nFlags,
342 sal_Int32 nStartIndex)
override;
348class PDFiumSignatureImpl final :
public PDFiumSignature
352 PDFiumSignatureImpl(
const PDFiumSignatureImpl&) =
delete;
353 PDFiumSignatureImpl& operator=(
const PDFiumSignatureImpl&) =
delete;
356 PDFiumSignatureImpl(FPDF_SIGNATURE pSignature);
358 std::vector<int> getByteRange()
override;
359 int getDocMDPPermission()
override;
360 std::vector<unsigned char> getContents()
override;
361 OString getSubFilter()
override;
362 OUString getReason()
override;
363 css::util::DateTime getTime()
override;
366class PDFiumPageImpl final :
public PDFiumPage
372 PDFiumPageImpl(
const PDFiumPageImpl&) =
delete;
373 PDFiumPageImpl& operator=(
const PDFiumPageImpl&) =
delete;
376 PDFiumPageImpl(FPDF_PAGE pPage)
381 ~PDFiumPageImpl()
override
387 FPDF_PAGE getPointer() {
return mpPage; }
389 int getObjectCount()
override;
390 std::unique_ptr<PDFiumPageObject> getObject(
int nIndex)
override;
392 int getAnnotationCount()
override;
393 int getAnnotationIndex(std::unique_ptr<PDFiumAnnotation>
const& rAnnotation)
override;
395 std::unique_ptr<PDFiumAnnotation> getAnnotation(
int nIndex)
override;
397 std::unique_ptr<PDFiumTextPage> getTextPage()
override;
401 double getWidth()
override;
402 double getHeight()
override;
404 bool hasTransparency()
override;
406 bool hasLinks()
override;
408 void onAfterLoadPage(PDFiumDocument* pDoc)
override;
412class PDFiumFormHandle final
417 PDFiumFormHandle(
const PDFiumFormHandle&) =
delete;
418 PDFiumFormHandle& operator=(
const PDFiumFormHandle&) =
delete;
421 PDFiumFormHandle(FPDF_FORMHANDLE pHandle);
423 FPDF_FORMHANDLE getPointer();
426class PDFiumDocumentImpl :
public PDFiumDocument
434 PDFiumDocumentImpl(
const PDFiumDocumentImpl&) =
delete;
435 PDFiumDocumentImpl& operator=(
const PDFiumDocumentImpl&) =
delete;
438 PDFiumDocumentImpl(FPDF_DOCUMENT pPdfDocument);
439 ~PDFiumDocumentImpl()
override;
440 FPDF_FORMHANDLE getFormHandlePointer();
445 int getSignatureCount()
override;
446 int getFileVersion()
override;
447 bool saveWithVersion(
SvMemoryStream& rStream,
int nFileVersion)
override;
449 std::unique_ptr<PDFiumPage> openPage(
int nIndex)
override;
450 std::unique_ptr<PDFiumSignature> getSignature(
int nIndex)
override;
451 std::vector<unsigned int> getTrailerEnds()
override;
454class PDFiumImpl :
public PDFium
457 PDFiumImpl(
const PDFiumImpl&) =
delete;
458 PDFiumImpl& operator=(
const PDFiumImpl&) =
delete;
464 ~PDFiumImpl()
override;
466 const OUString& getLastError()
const override {
return maLastError; }
468 std::unique_ptr<PDFiumDocument> openDocument(
const void* pData,
int nSize,
469 const OString& rPassword)
override;
472 std::unique_ptr<PDFiumBitmap> createBitmap(
int& nWidth,
int& nHeight,
int nAlpha)
override;
476PDFiumImpl::PDFiumImpl()
478 FPDF_LIBRARY_CONFIG aConfig;
480 aConfig.m_pUserFontPaths =
nullptr;
481 aConfig.m_pIsolate =
nullptr;
482 aConfig.m_v8EmbedderSlot = 0;
483 FPDF_InitLibraryWithConfig(&aConfig);
486PDFiumImpl::~PDFiumImpl() { FPDF_DestroyLibrary(); }
488std::unique_ptr<PDFiumDocument> PDFiumImpl::openDocument(
const void* pData,
int nSize,
489 const OString& rPassword)
492 std::unique_ptr<PDFiumDocument> pPDFiumDocument;
494 FPDF_BYTESTRING pPassword =
nullptr;
495 if (!rPassword.isEmpty())
497 pPassword = rPassword.getStr();
499 FPDF_DOCUMENT pDocument = FPDF_LoadMemDocument(pData, nSize, pPassword);
503 switch (FPDF_GetLastError())
505 case FPDF_ERR_SUCCESS:
508 case FPDF_ERR_UNKNOWN:
514 case FPDF_ERR_FORMAT:
517 case FPDF_ERR_PASSWORD:
518 maLastError =
"Incorrect password or password is required";
520 case FPDF_ERR_SECURITY:
532 pPDFiumDocument = std::make_unique<PDFiumDocumentImpl>(pDocument);
535 return pPDFiumDocument;
543std::unique_ptr<PDFiumBitmap> PDFiumImpl::createBitmap(
int& nWidth,
int& nHeight,
int nAlpha)
545 std::unique_ptr<PDFiumBitmap> pPDFiumBitmap;
547 FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nWidth, nHeight, nAlpha);
550 int nOriginal = nHeight;
557 nWidth = 16384.0 / nOriginal * nWidth;
560 if (nWidth * nHeight > 16384 * 16384)
563 nHeight = 16384.0 / nOriginal * nHeight;
566 pPdfBitmap = FPDFBitmap_Create(nWidth, nHeight, nAlpha);
572 SAL_WARN(
"vcl.filter",
"PDFiumImpl: " << getLastError());
576 pPDFiumBitmap = std::make_unique<PDFiumBitmapImpl>(pPdfBitmap);
578 return pPDFiumBitmap;
581PDFiumSignatureImpl::PDFiumSignatureImpl(FPDF_SIGNATURE pSignature)
586std::vector<int> PDFiumSignatureImpl::getByteRange()
588 int nByteRangeLen = FPDFSignatureObj_GetByteRange(
mpSignature,
nullptr, 0);
589 std::vector<int> aByteRange(nByteRangeLen);
590 if (nByteRangeLen <= 0)
595 FPDFSignatureObj_GetByteRange(
mpSignature, aByteRange.data(), aByteRange.size());
599int PDFiumSignatureImpl::getDocMDPPermission()
601 return FPDFSignatureObj_GetDocMDPPermission(
mpSignature);
604std::vector<unsigned char> PDFiumSignatureImpl::getContents()
606 int nContentsLen = FPDFSignatureObj_GetContents(
mpSignature,
nullptr, 0);
607 std::vector<unsigned char> aContents(nContentsLen);
608 if (aContents.empty())
613 FPDFSignatureObj_GetContents(
mpSignature, aContents.data(), aContents.size());
617OString PDFiumSignatureImpl::getSubFilter()
619 int nSubFilterLen = FPDFSignatureObj_GetSubFilter(
mpSignature,
nullptr, 0);
620 std::vector<char> aSubFilterBuf(nSubFilterLen);
621 FPDFSignatureObj_GetSubFilter(
mpSignature, aSubFilterBuf.data(), aSubFilterBuf.size());
623 OString aSubFilter(aSubFilterBuf.data(), aSubFilterBuf.size() - 1);
627OUString PDFiumSignatureImpl::getReason()
629 int nReasonLen = FPDFSignatureObj_GetReason(
mpSignature,
nullptr, 0);
633 std::vector<char16_t> aReasonBuf(nReasonLen);
634 FPDFSignatureObj_GetReason(
mpSignature, aReasonBuf.data(), aReasonBuf.size());
635 aRet = OUString(aReasonBuf.data(), aReasonBuf.size() - 1);
641util::DateTime PDFiumSignatureImpl::getTime()
644 int nTimeLen = FPDFSignatureObj_GetTime(
mpSignature,
nullptr, 0);
651 std::vector<char> aTimeBuf(nTimeLen);
652 FPDFSignatureObj_GetTime(
mpSignature, aTimeBuf.data(), aTimeBuf.size());
653 OString aM(aTimeBuf.data(), aTimeBuf.size() - 1);
654 if (aM.startsWith(
"D:") && aM.getLength() >= 16)
666PDFiumDocumentImpl::PDFiumDocumentImpl(FPDF_DOCUMENT pPdfDocument)
675PDFiumDocumentImpl::~PDFiumDocumentImpl()
682FPDF_FORMHANDLE PDFiumDocumentImpl::getFormHandlePointer() {
return m_pFormHandle->getPointer(); }
684std::unique_ptr<PDFiumPage> PDFiumDocumentImpl::openPage(
int nIndex)
686 std::unique_ptr<PDFiumPage> pPDFiumPage;
690 pPDFiumPage = std::make_unique<PDFiumPageImpl>(pPage);
695std::unique_ptr<PDFiumSignature> PDFiumDocumentImpl::getSignature(
int nIndex)
697 std::unique_ptr<PDFiumSignature> pPDFiumSignature;
698 FPDF_SIGNATURE pSignature = FPDF_GetSignatureObject(
mpPdfDocument, nIndex);
701 pPDFiumSignature = std::make_unique<PDFiumSignatureImpl>(pSignature);
703 return pPDFiumSignature;
706std::vector<unsigned int> PDFiumDocumentImpl::getTrailerEnds()
708 int nNumTrailers = FPDF_GetTrailerEnds(
mpPdfDocument,
nullptr, 0);
709 std::vector<unsigned int> aTrailerEnds(nNumTrailers);
710 FPDF_GetTrailerEnds(
mpPdfDocument, aTrailerEnds.data(), aTrailerEnds.size());
718 if (FPDF_GetPageSizeByIndexF(
mpPdfDocument, nIndex, &aPDFSize))
725int PDFiumDocumentImpl::getPageCount() {
return FPDF_GetPageCount(
mpPdfDocument); }
727int PDFiumDocumentImpl::getSignatureCount() {
return FPDF_GetSignatureCount(
mpPdfDocument); }
729int PDFiumDocumentImpl::getFileVersion()
731 int nFileVersion = 0;
736bool PDFiumDocumentImpl::saveWithVersion(
SvMemoryStream& rStream,
int nFileVersion)
738 CompatibleWriter aWriter(rStream);
740 aWriter.WriteBlock = &CompatibleWriterCallback;
741 if (!FPDF_SaveWithVersion(
mpPdfDocument, &aWriter, 0, nFileVersion))
749int PDFiumPageImpl::getObjectCount() {
return FPDFPage_CountObjects(
mpPage); }
751std::unique_ptr<PDFiumPageObject> PDFiumPageImpl::getObject(
int nIndex)
753 std::unique_ptr<PDFiumPageObject> pPDFiumPageObject;
754 FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(
mpPage, nIndex);
757 pPDFiumPageObject = std::make_unique<PDFiumPageObjectImpl>(pPageObject);
759 return pPDFiumPageObject;
762int PDFiumPageImpl::getAnnotationCount() {
return FPDFPage_GetAnnotCount(
mpPage); }
764int PDFiumPageImpl::getAnnotationIndex(std::unique_ptr<PDFiumAnnotation>
const& rAnnotation)
766 auto pAnnotation =
static_cast<PDFiumAnnotationImpl*
>(rAnnotation.get());
767 return FPDFPage_GetAnnotIndex(
mpPage, pAnnotation->getPointer());
770std::unique_ptr<PDFiumAnnotation> PDFiumPageImpl::getAnnotation(
int nIndex)
772 std::unique_ptr<PDFiumAnnotation> pPDFiumAnnotation;
773 FPDF_ANNOTATION pAnnotation = FPDFPage_GetAnnot(
mpPage, nIndex);
776 pPDFiumAnnotation = std::make_unique<PDFiumAnnotationImpl>(pAnnotation);
778 return pPDFiumAnnotation;
781std::unique_ptr<PDFiumTextPage> PDFiumPageImpl::getTextPage()
783 std::unique_ptr<PDFiumTextPage> pPDFiumTextPage;
784 FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(
mpPage);
787 pPDFiumTextPage = std::make_unique<PDFiumTextPageImpl>(pTextPage);
789 return pPDFiumTextPage;
792bool PDFiumPageImpl::hasLinks()
797 FPDF_LINK pLinkAnnot =
nullptr;
798 return FPDFLink_Enumerate(
mpPage, &nStartPos, &pLinkAnnot);
801void PDFiumPageImpl::onAfterLoadPage(PDFiumDocument* pDoc)
803 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
804 FORM_OnAfterLoadPage(
mpPage, pDocImpl->getFormHandlePointer());
807PDFiumPageObjectImpl::PDFiumPageObjectImpl(FPDF_PAGEOBJECT pPageObject)
812OUString PDFiumPageObjectImpl::getText(std::unique_ptr<PDFiumTextPage>
const& rTextPage)
814 OUString sReturnText;
816 auto pTextPage =
static_cast<PDFiumTextPageImpl*
>(rTextPage.get());
817 int nBytes = FPDFTextObj_GetText(
mpPageObject, pTextPage->getPointer(),
nullptr, 0);
818 assert(nBytes % 2 == 0);
821 std::unique_ptr<sal_Unicode[]> pText(
new sal_Unicode[nBytes]);
823 int nActualBytes = FPDFTextObj_GetText(
mpPageObject, pTextPage->getPointer(),
824 reinterpret_cast<FPDF_WCHAR*
>(pText.get()), nBytes * 2);
825 assert(nActualBytes % 2 == 0);
827 if (nActualBytes > 1)
829#if defined OSL_BIGENDIAN
831 for (
int i = 0;
i != nActualBytes; ++
i)
833 pText[
i] = OSL_SWAPWORD(pText[i]);
836 sReturnText = OUString(pText.get());
847int PDFiumPageObjectImpl::getFormObjectCount() {
return FPDFFormObj_CountObjects(
mpPageObject); }
849std::unique_ptr<PDFiumPageObject> PDFiumPageObjectImpl::getFormObject(
int nIndex)
851 std::unique_ptr<PDFiumPageObject> pPDFiumFormObject;
852 FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(
mpPageObject, nIndex);
855 pPDFiumFormObject = std::make_unique<PDFiumPageObjectImpl>(pFormObject);
857 return pPDFiumFormObject;
878 if (FPDFPageObj_GetBounds(
mpPageObject, &left, &bottom, &right, &top))
882 return aB2DRectangle;
885double PDFiumPageObjectImpl::getFontSize()
892OUString PDFiumPageObjectImpl::getFontName()
895 const int nFontName = 80 + 1;
896 std::unique_ptr<char[]> pFontName(
new char[nFontName]);
897 FPDF_FONT pFontObject = FPDFTextObj_GetFont(
mpPageObject);
898 int nFontNameChars = FPDFFont_GetFontName(pFontObject, pFontName.get(), nFontName);
899 if (nFontName >= nFontNameChars)
901 sFontName = OUString::createFromAscii(pFontName.get());
911Color PDFiumPageObjectImpl::getFillColor()
914 unsigned int nR, nG, nB, nA;
915 if (FPDFPageObj_GetFillColor(
mpPageObject, &nR, &nG, &nB, &nA))
917 aColor =
Color(ColorAlpha, nA, nR, nG, nB);
922Color PDFiumPageObjectImpl::getStrokeColor()
925 unsigned int nR, nG, nB, nA;
926 if (FPDFPageObj_GetStrokeColor(
mpPageObject, &nR, &nG, &nB, &nA))
928 aColor =
Color(ColorAlpha, nA, nR, nG, nB);
933double PDFiumPageObjectImpl::getStrokeWidth()
940int PDFiumPageObjectImpl::getPathSegmentCount() {
return FPDFPath_CountSegments(
mpPageObject); }
942std::unique_ptr<PDFiumPathSegment> PDFiumPageObjectImpl::getPathSegment(
int index)
944 std::unique_ptr<PDFiumPathSegment> pPDFiumPathSegment;
945 FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(
mpPageObject, index);
948 pPDFiumPathSegment = std::make_unique<PDFiumPathSegmentImpl>(pPathSegment);
950 return pPDFiumPathSegment;
953Size PDFiumPageObjectImpl::getImageSize(PDFiumPage& rPage)
955 FPDF_IMAGEOBJ_METADATA aMeta;
956 auto& rPageImpl =
static_cast<PDFiumPageImpl&
>(rPage);
957 FPDFImageObj_GetImageMetadata(
mpPageObject, rPageImpl.getPointer(), &aMeta);
958 return Size(aMeta.width, aMeta.height);
961std::unique_ptr<PDFiumBitmap> PDFiumPageObjectImpl::getImageBitmap()
963 std::unique_ptr<PDFiumBitmap> pPDFiumBitmap;
964 FPDF_BITMAP pBitmap = FPDFImageObj_GetBitmap(
mpPageObject);
967 pPDFiumBitmap = std::make_unique<PDFiumBitmapImpl>(pBitmap);
969 return pPDFiumBitmap;
972bool PDFiumPageObjectImpl::getDrawMode(
PDFFillMode& rFillMode,
bool& rStroke)
974 auto nFillMode =
static_cast<int>(rFillMode);
975 auto bStroke =
static_cast<FPDF_BOOL
>(rStroke);
976 bool bRet = FPDFPath_GetDrawMode(
mpPageObject, &nFillMode, &bStroke);
978 rStroke =
static_cast<bool>(bStroke);
984 int nPageWidth = getWidth();
985 int nPageHeight = getHeight();
986 std::unique_ptr<PDFiumBitmap> pPdfBitmap
987 = PDFiumLibrary::get()->createBitmap(nPageWidth, nPageHeight, 1);
991 PDFiumBitmapImpl* pBitmapImpl =
static_cast<PDFiumBitmapImpl*
>(pPdfBitmap.get());
999 FPDF_RenderPageBitmap(pBitmapImpl->getPointer(),
mpPage, 0, 0,
1000 nPageWidth, nPageHeight,
1005 const auto pPdfBuffer
1006 =
static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pBitmapImpl->getPointer()));
1007 const int nStride = FPDFBitmap_GetStride(pBitmapImpl->getPointer());
1008 for (
int nRow = 0; nRow < nPageHeight; ++nRow)
1014 return aBitmap.GetChecksum();
1017double PDFiumPageImpl::getWidth() {
return FPDF_GetPageWidth(
mpPage); }
1019double PDFiumPageImpl::getHeight() {
return FPDF_GetPageHeight(
mpPage); }
1021bool PDFiumPageImpl::hasTransparency() {
return FPDFPage_HasTransparency(
mpPage); }
1023PDFiumPathSegmentImpl::PDFiumPathSegmentImpl(FPDF_PATHSEGMENT pPathSegment)
1037bool PDFiumPathSegmentImpl::isClosed()
const {
return FPDFPathSegment_GetClose(
mpPathSegment); }
1044PDFiumFormHandle::PDFiumFormHandle(FPDF_FORMHANDLE pHandle)
1049PDFiumFormHandle::~PDFiumFormHandle() { FPDFDOC_ExitFormFillEnvironment(
mpHandle); }
1051FPDF_FORMHANDLE PDFiumFormHandle::getPointer() {
return mpHandle; }
1053PDFiumBitmapImpl::PDFiumBitmapImpl(FPDF_BITMAP pBitmap)
1058PDFiumBitmapImpl::~PDFiumBitmapImpl()
1066void PDFiumBitmapImpl::fillRect(
int left,
int top,
int width,
int height, sal_uInt32 nColor)
1068 FPDFBitmap_FillRect(
mpBitmap, left, top, width, height, nColor);
1071void PDFiumBitmapImpl::renderPageBitmap(PDFiumDocument* pDoc, PDFiumPage* pPage,
int nStartX,
1072 int nStartY,
int nSizeX,
int nSizeY)
1074 auto pPageImpl =
static_cast<PDFiumPageImpl*
>(pPage);
1075 FPDF_RenderPageBitmap(
mpBitmap, pPageImpl->getPointer(), nStartX, nStartY, nSizeX, nSizeY,
1079 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
1080 FPDF_FFLDraw(pDocImpl->getFormHandlePointer(),
mpBitmap, pPageImpl->getPointer(), nStartX,
1081 nStartY, nSizeX, nSizeY, 0, 0);
1089int PDFiumBitmapImpl::getStride() {
return FPDFBitmap_GetStride(
mpBitmap); }
1091int PDFiumBitmapImpl::getWidth() {
return FPDFBitmap_GetWidth(
mpBitmap); }
1093int PDFiumBitmapImpl::getHeight() {
return FPDFBitmap_GetHeight(
mpBitmap); }
1100PDFiumAnnotationImpl::PDFiumAnnotationImpl(FPDF_ANNOTATION pAnnotation)
1105PDFiumAnnotationImpl::~PDFiumAnnotationImpl()
1124 return aB2DRectangle;
1129 unsigned int nR, nG, nB, nA;
1130 if (FPDFAnnot_GetColor(
mpAnnotation, FPDFANNOT_COLORTYPE_Color, &nR, &nG, &nB, &nA))
1132 return Color(ColorAlpha, nA, nR, nG, nB);
1136 for (
int i = 0;
i < getObjectCount(); ++
i)
1138 if (getObject(i)->getType() == PDFPageObjectType::Path)
1139 return getObject(i)->getStrokeColor();
1144Color PDFiumAnnotationImpl::getInteriorColor()
1146 unsigned int nR, nG, nB, nA;
1147 if (FPDFAnnot_GetColor(
mpAnnotation, FPDFANNOT_COLORTYPE_InteriorColor, &nR, &nG, &nB, &nA))
1149 return Color(ColorAlpha, nA, nR, nG, nB);
1153 for (
int i = 0;
i < getObjectCount(); ++
i)
1155 if (getObject(i)->getType() == PDFPageObjectType::Path)
1156 return getObject(i)->getFillColor();
1161size_t PDFiumAnnotationImpl::getAttachmentPointsCount()
1166std::vector<basegfx::B2DPoint> PDFiumAnnotationImpl::getAttachmentPoints(
size_t nIndex)
1168 std::vector<basegfx::B2DPoint> aQuads;
1170 FS_QUADPOINTSF aQuadpoints;
1171 if (FPDFAnnot_GetAttachmentPoints(
mpAnnotation, nIndex, &aQuadpoints))
1173 aQuads.emplace_back(aQuadpoints.x1, aQuadpoints.y1);
1174 aQuads.emplace_back(aQuadpoints.x2, aQuadpoints.y2);
1175 aQuads.emplace_back(aQuadpoints.x3, aQuadpoints.y3);
1176 aQuads.emplace_back(aQuadpoints.x4, aQuadpoints.y4);
1181std::vector<basegfx::B2DPoint> PDFiumAnnotationImpl::getLineGeometry()
1183 std::vector<basegfx::B2DPoint> aLine;
1188 aLine.emplace_back(aStart.x, aStart.y);
1189 aLine.emplace_back(aEnd.x, aEnd.y);
1194PDFFormFieldType PDFiumAnnotationImpl::getFormFieldType(PDFiumDocument* pDoc)
1196 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
1198 FPDFAnnot_GetFormFieldType(pDocImpl->getFormHandlePointer(),
mpAnnotation));
1201int PDFiumAnnotationImpl::getFormFieldFlags(PDFiumDocument* pDoc)
1203 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
1204 return FPDFAnnot_GetFormFieldFlags(pDocImpl->getFormHandlePointer(),
mpAnnotation);
1207float PDFiumAnnotationImpl::getFontSize(PDFiumDocument* pDoc)
1209 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
1211 if (!FPDFAnnot_GetFontSize(pDocImpl->getFormHandlePointer(),
mpAnnotation, &fRet))
1219OUString PDFiumAnnotationImpl::getFormFieldAlternateName(PDFiumDocument* pDoc)
1221 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
1223 unsigned long nSize = FPDFAnnot_GetFormFieldAlternateName(pDocImpl->getFormHandlePointer(),
1225 assert(nSize % 2 == 0);
1229 std::unique_ptr<sal_Unicode[]> pText(
new sal_Unicode[nSize]);
1230 unsigned long nStringSize = FPDFAnnot_GetFormFieldAlternateName(
1232 reinterpret_cast<FPDF_WCHAR*
>(pText.get()), nSize * 2);
1233 assert(nStringSize % 2 == 0);
1235 if (nStringSize > 0)
1237#if defined OSL_BIGENDIAN
1238 for (
unsigned long i = 0;
i != nStringSize; ++
i)
1240 pText[
i] = OSL_SWAPWORD(pText[i]);
1243 aString = OUString(pText.get());
1249OUString PDFiumAnnotationImpl::getFormFieldValue(PDFiumDocument* pDoc)
1251 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
1254 = FPDFAnnot_GetFormFieldValue(pDocImpl->getFormHandlePointer(),
mpAnnotation,
nullptr, 0);
1255 assert(nSize % 2 == 0);
1259 std::unique_ptr<sal_Unicode[]> pText(
new sal_Unicode[nSize]);
1260 unsigned long nStringSize
1261 = FPDFAnnot_GetFormFieldValue(pDocImpl->getFormHandlePointer(),
mpAnnotation,
1262 reinterpret_cast<FPDF_WCHAR*
>(pText.get()), nSize * 2);
1263 assert(nStringSize % 2 == 0);
1265 if (nStringSize > 0)
1267#if defined OSL_BIGENDIAN
1268 for (
unsigned long i = 0;
i != nStringSize; ++
i)
1270 pText[
i] = OSL_SWAPWORD(pText[i]);
1273 aString = OUString(pText.get());
1279OUString PDFiumAnnotationImpl::getFormAdditionalActionJavaScript(PDFiumDocument* pDoc,
1282 auto pDocImpl =
static_cast<PDFiumDocumentImpl*
>(pDoc);
1284 unsigned long nSize = FPDFAnnot_GetFormAdditionalActionJavaScript(
1285 pDocImpl->getFormHandlePointer(),
mpAnnotation,
static_cast<int>(eEvent),
nullptr, 0);
1286 assert(nSize % 2 == 0);
1290 std::unique_ptr<sal_Unicode[]> pText(
new sal_Unicode[nSize]);
1291 unsigned long nStringSize = FPDFAnnot_GetFormAdditionalActionJavaScript(
1292 pDocImpl->getFormHandlePointer(),
mpAnnotation,
static_cast<int>(eEvent),
1293 reinterpret_cast<FPDF_WCHAR*
>(pText.get()), nSize * 2);
1294 assert(nStringSize % 2 == 0);
1296 if (nStringSize > 0)
1298#if defined OSL_BIGENDIAN
1299 for (
unsigned long i = 0;
i != nStringSize; ++
i)
1301 pText[
i] = OSL_SWAPWORD(pText[i]);
1304 aString = OUString(pText.get());
1312bool getBorderProperties(FPDF_ANNOTATION
mpAnnotation,
float& rHorizontalCornerRadius,
1313 float& rVerticalCornerRadius,
float& rBorderWidth)
1315 float fHoriRadius = 0.0f;
1316 float fVertRadius = 0.0f;
1317 float fWidth = 0.0f;
1319 if (!FPDFAnnot_GetBorder(
mpAnnotation, &fHoriRadius, &fVertRadius, &fWidth))
1322 rHorizontalCornerRadius = fHoriRadius;
1323 rVerticalCornerRadius = fVertRadius;
1324 rBorderWidth = fWidth;
1329float PDFiumAnnotationImpl::getBorderWidth()
1331 float fHorizontalCornerRadius;
1332 float fVerticalCornerRadius;
1335 if (!getBorderProperties(
mpAnnotation, fHorizontalCornerRadius, fVerticalCornerRadius,
1338 return fBorderWidth;
1343 float fHorizontalCornerRadius;
1344 float fVerticalCornerRadius;
1347 if (!getBorderProperties(
mpAnnotation, fHorizontalCornerRadius, fVerticalCornerRadius,
1353bool PDFiumAnnotationImpl::hasKey(OString
const& rKey)
1358PDFObjectType PDFiumAnnotationImpl::getValueType(OString
const& rKey)
1363OUString PDFiumAnnotationImpl::getString(OString
const& rKey)
1366 unsigned long nSize = FPDFAnnot_GetStringValue(
mpAnnotation, rKey.getStr(),
nullptr, 0);
1367 assert(nSize % 2 == 0);
1371 std::unique_ptr<sal_Unicode[]> pText(
new sal_Unicode[nSize]);
1372 unsigned long nStringSize = FPDFAnnot_GetStringValue(
1373 mpAnnotation, rKey.getStr(),
reinterpret_cast<FPDF_WCHAR*
>(pText.get()), nSize * 2);
1374 assert(nStringSize % 2 == 0);
1376 if (nStringSize > 0)
1378#if defined OSL_BIGENDIAN
1380 for (
unsigned long i = 0;
i != nStringSize; ++
i)
1382 pText[
i] = OSL_SWAPWORD(pText[i]);
1385 rString = OUString(pText.get());
1391std::vector<std::vector<basegfx::B2DPoint>> PDFiumAnnotationImpl::getInkStrokes()
1393 std::vector<std::vector<basegfx::B2DPoint>> aB2DPointList;
1394 int nInkStrokes = FPDFAnnot_GetInkListCount(
mpAnnotation);
1395 for (
int i = 0;
i < nInkStrokes;
i++)
1397 std::vector<basegfx::B2DPoint> aB2DPoints;
1398 int nPoints = FPDFAnnot_GetInkListPath(
mpAnnotation, i,
nullptr, 0);
1401 std::vector<FS_POINTF> aPoints(nPoints);
1402 if (FPDFAnnot_GetInkListPath(
mpAnnotation, i, aPoints.data(), aPoints.size()))
1404 for (
auto const& rPoint : aPoints)
1406 aB2DPoints.emplace_back(rPoint.x, rPoint.y);
1408 aB2DPointList.push_back(aB2DPoints);
1412 return aB2DPointList;
1415std::vector<basegfx::B2DPoint> PDFiumAnnotationImpl::getVertices()
1417 std::vector<basegfx::B2DPoint> aB2DPoints;
1418 int nPoints = FPDFAnnot_GetVertices(
mpAnnotation,
nullptr, 0);
1421 std::vector<FS_POINTF> aPoints(nPoints);
1422 if (FPDFAnnot_GetVertices(
mpAnnotation, aPoints.data(), aPoints.size()))
1424 for (
auto const& rPoint : aPoints)
1425 aB2DPoints.emplace_back(rPoint.x, rPoint.y);
1431std::unique_ptr<PDFiumAnnotation> PDFiumAnnotationImpl::getLinked(OString
const& rKey)
1433 std::unique_ptr<PDFiumAnnotation> pPDFiumAnnotation;
1434 FPDF_ANNOTATION pAnnotation = FPDFAnnot_GetLinkedAnnot(
mpAnnotation, rKey.getStr());
1437 pPDFiumAnnotation = std::make_unique<PDFiumAnnotationImpl>(pAnnotation);
1439 return pPDFiumAnnotation;
1442int PDFiumAnnotationImpl::getObjectCount() {
return FPDFAnnot_GetObjectCount(
mpAnnotation); }
1444std::unique_ptr<PDFiumPageObject> PDFiumAnnotationImpl::getObject(
int nIndex)
1446 std::unique_ptr<PDFiumPageObject> pPDFiumPageObject;
1447 FPDF_PAGEOBJECT pPageObject = FPDFAnnot_GetObject(
mpAnnotation, nIndex);
1450 pPDFiumPageObject = std::make_unique<PDFiumPageObjectImpl>(pPageObject);
1452 return pPDFiumPageObject;
1455PDFiumTextPageImpl::PDFiumTextPageImpl(FPDF_TEXTPAGE pTextPage)
1460PDFiumTextPageImpl::~PDFiumTextPageImpl()
1466int PDFiumTextPageImpl::countChars() {
return FPDFText_CountChars(
mpTextPage); }
1475 if (FPDFText_GetCharBox(
mpTextPage, nIndex, &left, &right, &bottom, &top))
1488unsigned int PDFiumTextPageImpl::getUnicode(
int index)
1490 return FPDFText_GetUnicode(
mpTextPage, index);
1493std::unique_ptr<PDFiumSearchHandle>
1494PDFiumTextPageImpl::findStart(
const OUString& rFindWhat,
PDFFindFlags nFlags, sal_Int32 nStartIndex)
1496 FPDF_WIDESTRING pFindWhat =
reinterpret_cast<FPDF_WIDESTRING
>(rFindWhat.getStr());
1497 return std::make_unique<vcl::pdf::PDFiumSearchHandleImpl>(
1498 FPDFText_FindStart(
mpTextPage, pFindWhat,
static_cast<sal_uInt32
>(nFlags), nStartIndex));
1501PDFiumSearchHandleImpl::PDFiumSearchHandleImpl(FPDF_SCHHANDLE pSearchHandle)
1506PDFiumSearchHandleImpl::~PDFiumSearchHandleImpl()
1512bool PDFiumSearchHandleImpl::findNext() {
return FPDFText_FindNext(
mpSearchHandle); }
1514bool PDFiumSearchHandleImpl::findPrev() {
return FPDFText_FindPrev(
mpSearchHandle); }
1516int PDFiumSearchHandleImpl::getSearchResultIndex()
1521int PDFiumSearchHandleImpl::getSearchCount() {
return FPDFText_GetSchCount(
mpSearchHandle); }
1523std::shared_ptr<PDFium>& PDFiumLibrary::get()
1525 static std::shared_ptr<PDFium> pInstance = std::make_shared<PDFiumImpl>();
FPDF_DOCUMENT mpPdfDocument
FPDF_ANNOTATION mpAnnotation
FPDF_SIGNATURE mpSignature
FPDF_PAGEOBJECT mpPageObject
FPDF_PATHSEGMENT mpPathSegment
std::unique_ptr< PDFiumFormHandle > m_pFormHandle
FPDF_SCHHANDLE mpSearchHandle
FPDF_FORMFILLINFO m_aFormCallbacks
const sal_uInt8 * ConstScanline
constexpr auto convertPointToMm100(N n)
static BitmapColor getColor(const BitmapReadAccess *pReadAcc, tools::Long nZ)
sal_uInt64 BitmapChecksum
std::size_t WriteBytes(const void *pData, std::size_t nSize)
static B2DHomMatrix abcdef(double da, double db, double dc, double dd, double de, double df)
This template handles BitmapAccess the RAII way.
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define SAL_WARN(area, stream)
OUString getString(const Any &_rAny)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
sal_Int32 getPageCount(const uno::Reference< frame::XModel > &xModel)
void fillRect(const ::cppcanvas::CanvasSharedPtr &rCanvas, const ::basegfx::B2DRectangle &rRect, ::cppcanvas::IntSRGBA aFillColor)
bool getType(BSTR name, Type &type)