[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - include/vcl sd/source vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sun Jun 7 19:15:43 UTC 2020


 include/vcl/pdfread.hxx              |   18 +++---------------
 sd/source/filter/pdf/sdpdffilter.cxx |   17 ++++-------------
 vcl/source/filter/ipdf/pdfread.cxx   |   14 ++++++++------
 3 files changed, 15 insertions(+), 34 deletions(-)

New commits:
commit ef4f5a6433259e441dbf0e0295a9d07644b43e2c
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Mar 29 16:30:19 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Jun 7 21:15:13 2020 +0200

    pdfium: fix setting the size of the document when opening PDF
    
    When loading the pages of PDF, the size of the document was
    set to the wrong value. Size returned by ImportPDFUnloaded was
    in pixels, which is not really useful considering the svx and
    sd core uses 100th mm as the unit and converting it to a device
    dependent pixel will just bring grief. Also we don't need to know
    the size in pixels until we actually render.
    This change removes DPI as the parameter to the ImportPDFUnloaded
    and changes the code to get the size of the page from the PDF as
    points and converts that to 100th mm.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91330
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 489b18edd6dc87287f260ba87d95abcc95d87932)
    
    Change-Id: I0c0db23d2775e2897ba7621ef6320a974c0b9275
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95641
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx
index b56e8139447d..ba0eb1ca85be 100644
--- a/include/vcl/pdfread.hxx
+++ b/include/vcl/pdfread.hxx
@@ -14,19 +14,10 @@
 #include <tools/gen.hxx>
 #include <tools/stream.hxx>
 
-namespace com
-{
-namespace sun
-{
-namespace star
-{
-namespace uno
+namespace com::sun::star::uno
 {
 template <typename> class Sequence;
 }
-}
-}
-}
 class Bitmap;
 class Graphic;
 
@@ -40,13 +31,10 @@ VCL_DLLPUBLIC size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vecto
 /// Imports a PDF stream into rGraphic as VectorGraphicData.
 VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic);
 
-/// Import PDF as Graphic images (1 per page), all unloaded.
-/// Since Graphic is unloaded, we need to return the page size (in pixels) separately.
-/// Does not set rPdfData if no conversion is done.
+/// Import PDF as Graphic images (1 per page), but not loaded yet.
 /// Returns the number of pages read.
 VCL_DLLPUBLIC size_t ImportPDFUnloaded(const OUString& rURL,
-                                       std::vector<std::pair<Graphic, Size>>& rGraphics,
-                                       double fResolutionDPI = 96.);
+                                       std::vector<std::pair<Graphic, Size>>& rGraphics);
 }
 
 #endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 8980e902ec73..c1069da58233 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -40,11 +40,8 @@ bool SdPdfFilter::Import()
     const OUString aFileName(
         mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE));
 
-    // Rendering resolution.
-    const double dResolutionDPI = 96.0;
-
     std::vector<std::pair<Graphic, Size>> aGraphics;
-    if (vcl::ImportPDFUnloaded(aFileName, aGraphics, dResolutionDPI) == 0)
+    if (vcl::ImportPDFUnloaded(aFileName, aGraphics) == 0)
         return false;
 
     // Add as many pages as we need up-front.
@@ -57,26 +54,20 @@ bool SdPdfFilter::Import()
     for (const std::pair<Graphic, Size>& aPair : aGraphics)
     {
         const Graphic& rGraphic = aPair.first;
-        const Size& aSize = aPair.second;
+        const Size& aSizeHMM = aPair.second;
 
         const sal_Int32 nPageNumber = rGraphic.getPageNumber();
         assert(nPageNumber >= 0 && static_cast<size_t>(nPageNumber) < aGraphics.size());
 
         // Create the page and insert the Graphic.
         SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard);
-        Size aGraphicSize(OutputDevice::LogicToLogic(aSize, rGraphic.GetPrefMapMode(),
-                                                     MapMode(MapUnit::Map100thMM)));
-
-        // Resize to original size based on 72 dpi to preserve page size.
-        aGraphicSize = Size(aGraphicSize.Width() * 72.0 / dResolutionDPI,
-                            aGraphicSize.Height() * 72.0 / dResolutionDPI);
 
         // Make the page size match the rendered image.
-        pPage->SetSize(aGraphicSize);
+        pPage->SetSize(aSizeHMM);
         Point aPosition(0, 0);
 
         SdrGrafObj* pSdrGrafObj = new SdrGrafObj(pPage->getSdrModelFromSdrPage(), rGraphic,
-                                                 tools::Rectangle(aPosition, aGraphicSize));
+                                                 tools::Rectangle(aPosition, aSizeHMM));
         pPage->InsertObject(pSdrGrafObj);
     }
 
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index b734a7bc4420..091b4cd37850 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -234,8 +234,7 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
     return true;
 }
 
-size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Size>>& rGraphics,
-                         const double fResolutionDPI)
+size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Size>>& rGraphics)
 {
 #if HAVE_FEATURE_PDFIUM
     std::unique_ptr<SvStream> xStream(
@@ -279,9 +278,13 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
         if (FPDF_GetPageSizeByIndex(pPdfDocument, nPageIndex, &fPageWidth, &fPageHeight) == 0)
             continue;
 
-        // Returned unit is points, convert that to pixel.
-        const size_t nPageWidth = pointToPixel(fPageWidth, fResolutionDPI);
-        const size_t nPageHeight = pointToPixel(fPageHeight, fResolutionDPI);
+        // Returned unit is points, convert that to 100th mm (hmm).
+        // 1 pt = 20 twips, 1 twip = 1.7638888888888889 hmm
+        // TODO: use some conversion class for that
+        constexpr double pointToHMMconversionRatio = 20.0 * 1.7638888888888889;
+
+        long nPageWidth = fPageWidth * pointToHMMconversionRatio;
+        long nPageHeight = fPageHeight * pointToHMMconversionRatio;
 
         auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(
             aPdfDataArray, OUString(), VectorGraphicDataType::Pdf, nPageIndex);
@@ -302,7 +305,6 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
 #else
     (void)rURL;
     (void)rGraphics;
-    (void)fResolutionDPI;
     return 0;
 #endif // HAVE_FEATURE_PDFIUM
 }


More information about the Libreoffice-commits mailing list