diff options
author | Jan Holesovsky <kendy@collabora.com> | 2018-06-22 12:58:12 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2019-04-03 17:54:01 +0200 |
commit | 8aca771675f7f76c84bbbd117b9dc1cc9c5ada8b (patch) | |
tree | 75fc8d4ba7cd5f1ad922534b843a0a24daa5f829 | |
parent | pdfium: Avoid unnecessary copying + some warning fixes. (diff) | |
download | core-8aca771675f7f76c84bbbd117b9dc1cc9c5ada8b.tar.gz core-8aca771675f7f76c84bbbd117b9dc1cc9c5ada8b.zip |
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 |
3 files changed, 28 insertions, 7 deletions
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx index d78ccaa328b0..6f8b4ca2c0b3 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, tools::Rectangle(aPos, aGrfSize))); + SdrGrafObj* pSdrGrafObj = new SdrGrafObj(rGraphic, tools::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 443cfa91aa90..0bb04b0c5d56 100644 --- a/svtools/source/graphic/grfcache.cxx +++ b/svtools/source/graphic/grfcache.cxx @@ -80,6 +80,16 @@ GraphicID::GraphicID( const GraphicObject& rObj ) mnID3 = basegfx::fround(rRange.getHeight()); mnID4 = vcl_get_checksum(0, rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()); } + 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 3a058bb36b57..8240c4af3217 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -330,6 +330,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; @@ -341,9 +344,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); |