diff options
author | Jan Holesovsky <kendy@collabora.com> | 2018-06-22 12:58:12 +0200 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2018-06-22 14:44:25 +0200 |
commit | 89626f5f52a80e719cb0fdbf533a4b21697db66a (patch) | |
tree | 3a6ca59b1ed93d4ff1a96f8ef8616ebde395fd3f | |
parent | 3d2b4942214f586f22640e84f6d48fee475521fb (diff) |
pdfium: Delay the swap out.
If we swap out too early, the constructor of GraphicObject forces a swap
in, so we'd render everything during the load anyway.
Change-Id: I0ea1a755242fd57ef28d082ce4bf534a32199f87
Reviewed-on: https://gerrit.libreoffice.org/56286
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r-- | sd/source/filter/pdf/sdpdffilter.cxx | 14 | ||||
-rw-r--r-- | svtools/source/graphic/grfcache.cxx | 10 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 11 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 7 |
4 files changed, 28 insertions, 14 deletions
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx index e157bef79de8..fab51f432060 100644 --- a/sd/source/filter/pdf/sdpdffilter.cxx +++ b/sd/source/filter/pdf/sdpdffilter.cxx @@ -115,15 +115,15 @@ bool SdPdfFilter::Import() for (std::pair<Graphic, Size>& aPair : aGraphics) { - const Graphic& aGraphic = aPair.first; + const Graphic& rGraphic = aPair.first; const Size& aSize = aPair.second; - const sal_Int32 nPageNumber = aGraphic.getPageNumber(); + const sal_Int32 nPageNumber = rGraphic.getPageNumber(); assert(nPageNumber >= 0 && nPageNumber < static_cast<sal_Int32>(aGraphics.size())); // Create the page and insert the Graphic. SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard); - Size aGrfSize(OutputDevice::LogicToLogic(aSize, aGraphic.GetPrefMapMode(), + Size aGrfSize(OutputDevice::LogicToLogic(aSize, rGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM))); // Resize to original size based on 72 dpi to preserve page size. @@ -134,7 +134,13 @@ bool SdPdfFilter::Import() pPage->SetSize(aGrfSize); Point aPos(0, 0); - pPage->InsertObject(new SdrGrafObj(aGraphic, Rectangle(aPos, aGrfSize))); + SdrGrafObj* pSdrGrafObj = new SdrGrafObj(rGraphic, Rectangle(aPos, aGrfSize)); + pPage->InsertObject(pSdrGrafObj); + + // we know that the initial bitmap we provided was just a placeholder, + // we need to swap it out, so that on the next swap in, we render the + // correct one + const_cast<GraphicObject&>(pSdrGrafObj->GetGraphicObject()).SwapOut(); } return true; diff --git a/svtools/source/graphic/grfcache.cxx b/svtools/source/graphic/grfcache.cxx index 8def38eca49f..ec6bc39457b8 100644 --- a/svtools/source/graphic/grfcache.cxx +++ b/svtools/source/graphic/grfcache.cxx @@ -83,6 +83,16 @@ GraphicID::GraphicID( const GraphicObject& rObj ) mnID3 = basegfx::fround(rRange.getHeight()); mnID4 = vcl_get_checksum(0, rSvgDataPtr->getSvgDataArray().getConstArray(), rSvgDataPtr->getSvgDataArrayLength()); } + else if (rGraphic.hasPdfData()) + { + std::shared_ptr<css::uno::Sequence<sal_Int8>> pPdfData = rGraphic.getPdfData(); + const BitmapEx& rBmpEx = rGraphic.GetBitmapEx(); + + mnID1 |= (rGraphic.getPageNumber() & 0x0fffffff); + mnID2 = rBmpEx.GetSizePixel().Width(); + mnID3 = rBmpEx.GetSizePixel().Height(); + mnID4 = vcl_get_checksum(0, pPdfData->getConstArray(), pPdfData->getLength()); + } else if( rGraphic.IsAnimated() ) { const Animation aAnimation( rGraphic.GetAnimation() ); diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 53008ea5e958..da36c3433350 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -346,6 +346,9 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si if (nPageCount <= 0) return 0; + // dummy Bitmap + Bitmap aBitmap(Size(1, 1), 24); + for (size_t nPageIndex = 0; nPageIndex < static_cast<size_t>(nPageCount); ++nPageIndex) { double fPageWidth = 0; @@ -357,9 +360,11 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si const size_t nPageWidth = pointToPixel(fPageWidth, fResolutionDPI); const size_t nPageHeight = pointToPixel(fPageHeight, fResolutionDPI); - // Create the Graphic and link the original PDF stream. - Graphic aGraphic; - aGraphic.setPdfData(pPdfData); // TODO: Skip if unchanged. + // Create the Graphic with a dummy Bitmap and link the original PDF stream. + // We swap out this Graphic as soon as possible, and a later swap in + // actually renders the correct Bitmap on demand. + Graphic aGraphic(aBitmap); + aGraphic.setPdfData(pPdfData); aGraphic.setPageNumber(nPageIndex); aGraphic.SetSharedLink(pGfxLink); diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index cdad0f51e457..d2106041f9cd 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1371,14 +1371,7 @@ void ImpGraphic::ImplSetSharedLink(const std::shared_ptr<GfxLink>& pGfxLink) mpGfxLink = pGfxLink; if (mpGfxLink->IsNative()) - { mpGfxLink->SwapOut(); - - // Swap out the graphic as well. - //FIXME: move to own function, such as SetPrepared(). - meType = GraphicType::Bitmap; - ImplSwapOut(); - } } GfxLink ImpGraphic::ImplGetLink() |