diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-03-13 23:55:26 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-06-01 08:59:10 +0200 |
commit | 52a0b46bfdc32e5c37b3d7343a42c6388f3d569d (patch) | |
tree | e4939d36f57dfe06aad329350630b5e960ebb5ea /vcl | |
parent | 32817f930580b6b378dd470ccbdf967c06540db2 (diff) |
sd: import PDFs as images using Pdfium new SdPdfFilter
LOK now opens PDFs as images using Pdfium,
which has a superior accuracy and support
to poppler, the default pdf reader.
(cherry picked from commit 0e8f4f45b44935c7c8002d606b97a48e60e37b23)
Change-Id: Ifbbecf7f048f001836fb98886705cba47e6bed4e
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/impgraph.hxx | 12 | ||||
-rw-r--r-- | vcl/inc/pdfread.hxx | 30 | ||||
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 2 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 27 | ||||
-rw-r--r-- | vcl/source/gdi/graph.cxx | 10 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 2 |
6 files changed, 48 insertions, 35 deletions
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx index 46d5fa55a8b6..1414eb8640a8 100644 --- a/vcl/inc/impgraph.hxx +++ b/vcl/inc/impgraph.hxx @@ -51,11 +51,21 @@ private: bool mbSwapOut; bool mbDummyContext; VectorGraphicDataPtr maVectorGraphicData; + + /// The PDF stream from which this Graphic is rendered, + /// as converted (version downgraded) from the original, + /// which should be in GfxLink. std::shared_ptr<css::uno::Sequence<sal_Int8>> mpPdfData; OUString msOriginURL; GraphicExternalLink maGraphicExternalLink; -private: + /// Used with GfxLink and/or PdfData when they store original media + /// which might be multi-page (PDF, f.e.) and we need to re-render + /// this Graphic (a page) from the source in GfxLink or PdfData. + sal_Int32 mnPageNumber; + + std::chrono::high_resolution_clock::time_point maLastUsed; + bool mbPrepared; ImpGraphic(); ImpGraphic( const ImpGraphic& rImpGraphic ); diff --git a/vcl/inc/pdfread.hxx b/vcl/inc/pdfread.hxx deleted file mode 100644 index 986b257878f5..000000000000 --- a/vcl/inc/pdfread.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- 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/. - */ - -#ifndef INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX -#define INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX - -#include <tools/stream.hxx> -#include <vcl/graph.hxx> - -namespace vcl -{ - -/// Imports a PDF stream into rGraphic as a GDIMetaFile. -VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, - css::uno::Sequence<sal_Int8>& rPdfData, - sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN, - sal_uInt64 nSize = STREAM_SEEK_TO_END); -VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic); - -} - -#endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 062f5ee3701d..b30b8afbe130 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -44,7 +44,7 @@ #include <vcl/wmf.hxx> #include <vcl/settings.hxx> #include "igif/gifread.hxx" -#include <pdfread.hxx> +#include <vcl/pdfread.hxx> #include "jpeg/jpeg.hxx" #include "ixbm/xbmread.hxx" #include "ixpm/xpmread.hxx" diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index a38d21174ce6..1ffe96123444 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <pdfread.hxx> +#include <vcl/pdfread.hxx> #include <config_features.h> @@ -18,6 +18,8 @@ #endif #include <vcl/bitmapaccess.hxx> +#include <vcl/graph.hxx> +#include <unotools/ucbstreamhelper.hxx> using namespace com::sun::star; @@ -239,10 +241,31 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic) Bitmap aBitmap; bool bRet = ImportPDF(rStream, aBitmap, aPdfData); rGraphic = aBitmap; - rGraphic.setPdfData(aPdfData); + rGraphic.setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(aPdfData)); return bRet; } +size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps, + css::uno::Sequence<sal_Int8>& rPdfData) +{ + std::unique_ptr<SvStream> xStream( + ::utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ | StreamMode::SHARE_DENYNONE)); + + if (generatePreview(*xStream, rBitmaps, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END, 0, -1) == 0) + return 0; + + // Save the original PDF stream for later use. + SvMemoryStream aMemoryStream; + if (!getCompatibleStream(*xStream, aMemoryStream, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END)) + return 0; + + aMemoryStream.Seek(STREAM_SEEK_TO_END); + rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.Tell()); + aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN); + aMemoryStream.ReadBytes(rPdfData.getArray(), rPdfData.getLength()); + + return rBitmaps.size(); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index df12a03ef9c4..c0e9bb444a4b 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -608,6 +608,16 @@ bool Graphic::hasPdfData() const return pPdfData && pPdfData->hasElements(); } +void Graphic::setPageNumber(sal_Int32 nPageNumber) +{ + mxImpGraphic->mnPageNumber = nPageNumber; +} + +sal_Int32 Graphic::getPageNumber() const +{ + return mxImpGraphic->mnPageNumber; +} + OUString Graphic::getOriginURL() const { if (mxImpGraphic) diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index af293c76faae..d11818eb57ab 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -41,7 +41,7 @@ #include <o3tl/make_unique.hxx> #include <vcl/gdimetafiletools.hxx> -#include <pdfread.hxx> +#include <vcl/pdfread.hxx> #define GRAPHIC_MTFTOBMP_MAXEXT 2048 #define GRAPHIC_STREAMBUFSIZE 8192UL |