diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2024-06-13 14:25:21 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-06-18 12:21:58 +0200 |
commit | 6490cf00f733d620a4f224197b478a6100df0fb7 (patch) | |
tree | ac97bdc870748cbaf719a05db1759533afce4561 /vcl | |
parent | 110b5685a3f3f2709d692976c48f5742c3550d0d (diff) |
annot: add support to import Stamp annotation from PDF
Stamp annotation shows an arbitrary bitmap in the document, where
the most common bitmaps are stamps like "Approved", "Confidential",
"Expired", "Sold",...
Change-Id: I332e34cbb346a686ee16eac7ca437ec4048e65ed
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168760
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 66a68fcb5639c3f0e42385fcdb08f16b9c96f243)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168844
Tested-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 21 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 64 |
2 files changed, 84 insertions, 1 deletions
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index c19a6939b486..b2e97a519ed5 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -182,7 +182,8 @@ findAnnotations(const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D || eSubtype == vcl::pdf::PDFAnnotationSubType::Square || eSubtype == vcl::pdf::PDFAnnotationSubType::Ink || eSubtype == vcl::pdf::PDFAnnotationSubType::Highlight - || eSubtype == vcl::pdf::PDFAnnotationSubType::Line) + || eSubtype == vcl::pdf::PDFAnnotationSubType::Line + || eSubtype == vcl::pdf::PDFAnnotationSubType::Stamp) { OUString sAuthor = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); OUString sText = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); @@ -330,6 +331,24 @@ findAnnotations(const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerFreeText>(); rPDFGraphicAnnotation.mpMarker = pMarker; } + else if (eSubtype == vcl::pdf::PDFAnnotationSubType::Stamp) + { + auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerStamp>(); + rPDFGraphicAnnotation.mpMarker = pMarker; + + auto nObjects = pAnnotation->getObjectCount(); + + for (int nIndex = 0; nIndex < nObjects; nIndex++) + { + auto pPageObject = pAnnotation->getObject(nIndex); + if (pPageObject->getType() == vcl::pdf::PDFPageObjectType::Image) + { + std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap + = pPageObject->getImageBitmap(); + pMarker->maBitmapEx = pBitmap->createBitmapFromBuffer(); + } + } + } } } } diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 553be738c8f5..4c3872979d1d 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -28,6 +28,8 @@ #include <o3tl/string_view.hxx> #include <vcl/BitmapWriteAccess.hxx> +#include <vcl/bitmapex.hxx> +#include <vcl/dibtools.hxx> using namespace com::sun::star; @@ -214,6 +216,7 @@ public: int getWidth() override; int getHeight() override; PDFBitmapType getFormat() override; + BitmapEx createBitmapFromBuffer() override; }; class PDFiumPathSegmentImpl final : public PDFiumPathSegment @@ -1097,6 +1100,67 @@ PDFBitmapType PDFiumBitmapImpl::getFormat() return static_cast<PDFBitmapType>(FPDFBitmap_GetFormat(mpBitmap)); } +BitmapEx PDFiumBitmapImpl::createBitmapFromBuffer() +{ + BitmapEx aBitmapEx; + + const vcl::pdf::PDFBitmapType eFormat = getFormat(); + if (eFormat == vcl::pdf::PDFBitmapType::Unknown) + return aBitmapEx; + + const int nWidth = getWidth(); + const int nHeight = getHeight(); + const int nStride = getStride(); + + switch (eFormat) + { + case vcl::pdf::PDFBitmapType::BGR: + { + aBitmapEx = BitmapEx(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); + ReadRawDIB(aBitmapEx, getBuffer(), ScanlineFormat::N24BitTcBgr, nHeight, nStride); + } + break; + + case vcl::pdf::PDFBitmapType::BGRx: + { + aBitmapEx = BitmapEx(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); + ReadRawDIB(aBitmapEx, getBuffer(), ScanlineFormat::N32BitTcRgba, nHeight, nStride); + } + break; + + case vcl::pdf::PDFBitmapType::BGRA: + { + Bitmap aBitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); + AlphaMask aMask(Size(nWidth, nHeight)); + { + BitmapScopedWriteAccess pWriteAccess(aBitmap); + BitmapScopedWriteAccess pMaskAccess(aMask); + ConstScanline pBuffer = getBuffer(); + std::vector<sal_uInt8> aScanlineAlpha(nWidth); + for (int nRow = 0; nRow < nHeight; ++nRow) + { + ConstScanline pLine = pBuffer + (nStride * nRow); + pWriteAccess->CopyScanline(nRow, pLine, ScanlineFormat::N32BitTcBgra, nStride); + for (int nCol = 0; nCol < nWidth; ++nCol) + { + aScanlineAlpha[nCol] = pLine[3]; + pLine += 4; + } + pMaskAccess->CopyScanline(nRow, aScanlineAlpha.data(), ScanlineFormat::N8BitPal, + nWidth); + } + } + aBitmapEx = BitmapEx(aBitmap, aMask); + } + break; + + default: + break; + } + + return aBitmapEx; +} + PDFiumAnnotationImpl::PDFiumAnnotationImpl(FPDF_ANNOTATION pAnnotation) : mpAnnotation(pAnnotation) { |