[Libreoffice-commits] core.git: 42 commits - external/pdfium include/svx include/vcl sdext/CppunitTest_sdext_pdfimport.mk sdext/Executable_pdf2xml.mk sdext/Executable_pdfunzip.mk sdext/Library_pdfimport.mk sdext/source sd/inc sd/Library_sd.mk sd/qa sd/source sfx2/source svx/Library_svxcore.mk svx/source sw/source vcl/inc vcl/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Jun 7 08:46:39 UTC 2018


 external/pdfium/0001-svx-import-PDF-text-using-PDFium.patch.2                     |  177 +
 external/pdfium/0002-svx-more-accurate-PDF-text-importing.patch.2                 |  173 +
 external/pdfium/0003-svx-import-PDF-images-as-BGRA.patch.2                        |   58 
 external/pdfium/0004-svx-support-PDF-text-color.patch.2                           |  130 +
 external/pdfium/0005-svx-support-Paths-in-PDFs-while-importing.patch.2            |   54 
 external/pdfium/0006-svx-improve-path-importing-from-PDF.patch.2                  |  115 
 external/pdfium/0007-svx-improved-text-importing-from-PDF.patch.2                 |   62 
 external/pdfium/0008-svx-correct-the-positioning-of-PDF-Paths-and-the-str.patch.2 |  103 
 external/pdfium/0009-svx-support-color-text-for-imported-PDFs.patch.2             |  135 +
 external/pdfium/0010-svx-support-importing-forms-from-PDFs.patch.2                |   96 
 external/pdfium/0011-svx-correctly-possition-form-objects-from-PDF.patch.2        |   75 
 external/pdfium/0012-svx-import-processed-PDF-text.patch.2                        |  148 +
 external/pdfium/0013-svx-cleanup-pdfium-importer.patch.2                          |  130 +
 external/pdfium/0014-svx-update-PDFium-patch-and-code.patch.2                     |  137 +
 external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2           |   69 
 external/pdfium/UnpackedTarball_pdfium.mk                                         |   16 
 include/svx/svdograf.hxx                                                          |   10 
 include/svx/xmlgrhlp.hxx                                                          |    2 
 include/vcl/dibtools.hxx                                                          |    8 
 include/vcl/graph.hxx                                                             |   10 
 include/vcl/pdfread.hxx                                                           |   14 
 sd/Library_sd.mk                                                                  |    1 
 sd/inc/sdpdffilter.hxx                                                            |   40 
 sd/qa/unit/import-tests.cxx                                                       |    6 
 sd/source/filter/pdf/sdpdffilter.cxx                                              |  155 +
 sd/source/ui/docshell/docshel4.cxx                                                |    9 
 sd/source/ui/view/drviews2.cxx                                                    |    6 
 sdext/CppunitTest_sdext_pdfimport.mk                                              |    1 
 sdext/Executable_pdf2xml.mk                                                       |    1 
 sdext/Executable_pdfunzip.mk                                                      |    1 
 sdext/Library_pdfimport.mk                                                        |    1 
 sdext/source/pdfimport/wrapper/wrapper.cxx                                        |   40 
 sfx2/source/doc/objstor.cxx                                                       |    7 
 svx/Library_svxcore.mk                                                            |    2 
 svx/source/svdraw/svdedtv.cxx                                                     |   32 
 svx/source/svdraw/svdedtv2.cxx                                                    |   79 
 svx/source/svdraw/svdograf.cxx                                                    |   17 
 svx/source/svdraw/svdpdf.cxx                                                      | 1259 ++++++++++
 svx/source/svdraw/svdpdf.hxx                                                      |  248 +
 svx/source/xml/xmlgrhlp.cxx                                                       |   18 
 svx/source/xoutdev/_xoutbmp.cxx                                                   |    6 
 sw/source/core/graphic/ndgrf.cxx                                                  |    4 
 vcl/inc/impgraph.hxx                                                              |   20 
 vcl/source/filter/graphicfilter.cxx                                               |    2 
 vcl/source/filter/ipdf/pdfread.cxx                                                |   58 
 vcl/source/gdi/dibtools.cxx                                                       |   16 
 vcl/source/gdi/graph.cxx                                                          |   20 
 vcl/source/gdi/impgraph.cxx                                                       |   79 
 vcl/source/gdi/pdfwriter_impl.cxx                                                 |   10 
 49 files changed, 3709 insertions(+), 151 deletions(-)

New commits:
commit d424a5578ae50382ba7062aa9624dae584601c73
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Wed Jun 6 21:56:21 2018 -0400

    svx: fix loplugin errors
    
    Change-Id: Ic13bc488f2c8137eae3687d72732533ba5542998

diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 609a6c0cddd7..6721f463f53c 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -93,9 +93,9 @@ namespace
 /// dimensions are in inches, with 72 points / inch.
 /// Here we effectively render at 96 DPI (to match
 /// the image rendered in vcl::ImportPDF in pdfread.cxx).
-static inline double lcl_PointToPixel(double fPoint) { return fPoint * 96. / 72.; }
+inline double lcl_PointToPixel(double fPoint) { return fPoint * 96. / 72.; }
 /// Convert from pixels to logic (twips).
-static inline long lcl_ToLogic(double value)
+inline long lcl_ToLogic(double value)
 {
     // Convert to integral preserving two dp.
     const long in = static_cast<long>(value * 100.);
@@ -103,12 +103,12 @@ static inline long lcl_ToLogic(double value)
     return out / 100;
 }
 
-static inline double sqrt2(double a, double b) { return sqrt(a * a + b * b); }
+inline double sqrt2(double a, double b) { return sqrt(a * a + b * b); }
 }
 
 struct FPDFBitmapDeleter
 {
-    inline void operator()(FPDF_BITMAP bitmap) { FPDFBitmap_Destroy(bitmap); }
+    void operator()(FPDF_BITMAP bitmap) { FPDFBitmap_Destroy(bitmap); }
 };
 
 using namespace com::sun::star;
@@ -1193,7 +1193,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
     mnLineWidth = lcl_ToLogic(lcl_PointToPixel(dWidth));
 
     int nFillMode = FPDF_FILLMODE_ALTERNATE;
-    FPDF_BOOL bStroke = true;
+    FPDF_BOOL bStroke = 1; // Assume we have to draw, unless told otherwise.
     if (FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke))
     {
         if (nFillMode == FPDF_FILLMODE_ALTERNATE)
@@ -1219,8 +1219,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
     else
         mpVD->SetLineColor(COL_TRANSPARENT);
 
-    if (!mbLastObjWasPolyWithoutLine
-        || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aPolyPoly)))
+    if (!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aPolyPoly))
     {
         SdrPathObj* pPath = new SdrPathObj(*mpModel, OBJ_POLY, aPolyPoly);
         SetAttributes(pPath);
commit d90cc3035443464432bf74538e8a2ad6e3fafe3b
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Wed Jun 6 20:58:18 2018 -0400

    svx: don't re-declare pdfium structs
    
    They aren't needed when fpdfview.h is
    included and clang reservedid plugin complains
    of the double-underscores.
    
    Also, wrap the PDFium importer class in
    HAVE_FEATURE_PDFIUM to avoid build failure
    when PDFium is missing.
    
    Change-Id: Ibc285aea575acf72541866c534ef943e0bb89466

diff --git a/svx/source/svdraw/svdedtv2.cxx b/svx/source/svdraw/svdedtv2.cxx
index ae7fa5414fec..9adec973de3d 100644
--- a/svx/source/svdraw/svdedtv2.cxx
+++ b/svx/source/svdraw/svdedtv2.cxx
@@ -2057,13 +2057,14 @@ void SdrEditView::DoImportMarkedMtf(SvdProgressInfo *pProgrInfo)
             }
             else if (pGraf->isEmbeddedPdfData())
             {
+#if HAVE_FEATURE_PDFIUM
                 aLogicRect = pGraf->GetLogicRect();
                 ImpSdrPdfImport aFilter(*mpModel, pObj->GetLayer(), aLogicRect, pGraf->getEmbeddedPdfData());
                 if (pGraf->getEmbeddedPageNumber() < aFilter.GetPageCount())
                 {
                     nInsAnz = aFilter.DoImport(*pOL, nInsPos, pGraf->getEmbeddedPageNumber(), pProgrInfo);
                 }
-
+#endif // HAVE_FEATURE_PDFIUM
             }
         }
 
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 6347c7dc1352..609a6c0cddd7 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -26,7 +26,6 @@
 #include <fpdf_edit.h>
 #include <fpdf_save.h>
 #include <fpdf_text.h>
-#endif
 
 #include <vcl/bitmapaccess.hxx>
 #include <vcl/graph.hxx>
@@ -207,7 +206,7 @@ ImpSdrPdfImport::~ImpSdrPdfImport()
 }
 
 void ImpSdrPdfImport::DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport,
-                                    int nPageIndex)
+                                int nPageIndex)
 {
     const int nPageCount = FPDF_GetPageCount(mpPdfDocument);
     if (nPageCount > 0 && nPageIndex >= 0 && nPageIndex < nPageCount)
@@ -232,19 +231,19 @@ void ImpSdrPdfImport::DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pAction
         {
             FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage, nPageObjectIndex);
             ImportPdfObject(pPageObject, pTextPage, nPageObjectIndex);
-        if (pProgrInfo && pActionsToReport)
-        {
-            (*pActionsToReport)++;
+            if (pProgrInfo && pActionsToReport)
+            {
+                (*pActionsToReport)++;
 
                 if (*pActionsToReport >= 16)
-            {
-                if (!pProgrInfo->ReportActions(*pActionsToReport))
-                    break;
+                {
+                    if (!pProgrInfo->ReportActions(*pActionsToReport))
+                        break;
 
-                *pActionsToReport = 0;
+                    *pActionsToReport = 0;
+                }
             }
         }
-    }
 
         FPDFText_ClosePage(pTextPage);
         FPDF_ClosePage(pPdfPage);
@@ -1041,8 +1040,8 @@ void ImpSdrPdfImport::MapScaling()
 
 void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/)
 {
-    std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter>
-                        bitmap(FPDFImageObj_GetBitmapBgra(pPageObject));
+    std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter> bitmap(
+        FPDFImageObj_GetBitmapBgra(pPageObject));
     if (!bitmap)
     {
         SAL_WARN("sd.filter", "Failed to get IMAGE");
@@ -1220,7 +1219,8 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
     else
         mpVD->SetLineColor(COL_TRANSPARENT);
 
-    if (!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aPolyPoly)))
+    if (!mbLastObjWasPolyWithoutLine
+        || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aPolyPoly)))
     {
         SdrPathObj* pPath = new SdrPathObj(*mpModel, OBJ_POLY, aPolyPoly);
         SetAttributes(pPath);
@@ -1238,7 +1238,8 @@ Point ImpSdrPdfImport::PointsToLogic(double x, double y) const
     return aPos;
 }
 
-tools::Rectangle ImpSdrPdfImport::PointsToLogic(double left, double right, double top, double bottom) const
+tools::Rectangle ImpSdrPdfImport::PointsToLogic(double left, double right, double top,
+                                                double bottom) const
 {
     top = correctVertOrigin(top);
     bottom = correctVertOrigin(bottom);
@@ -1254,4 +1255,6 @@ tools::Rectangle ImpSdrPdfImport::PointsToLogic(double left, double right, doubl
     return aRect;
 }
 
+#endif // HAVE_FEATURE_PDFIUM
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index dfb4b9ad2946..37f112eeda28 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -20,6 +20,9 @@
 #ifndef INCLUDED_SVX_SOURCE_SVDRAW_SVDPDF_HXX
 #define INCLUDED_SVX_SOURCE_SVDRAW_SVDPDF_HXX
 
+#include <config_features.h>
+
+#if HAVE_FEATURE_PDFIUM
 #include <sal/config.h>
 
 #include <memory>
@@ -32,6 +35,8 @@
 #include <svx/xdash.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 
+#include <fpdfview.h>
+
 // Forward Declarations
 
 class SfxItemSet;
@@ -40,9 +45,6 @@ class SdrModel;
 class SdrPage;
 class SdrObject;
 class SvdProgressInfo;
-typedef struct fpdf_document_t__* FPDF_DOCUMENT;
-typedef struct fpdf_pageobject_t__* FPDF_PAGEOBJECT;  // (text, path, etc.)
-typedef struct fpdf_textpage_t__* FPDF_TEXTPAGE;
 
 // Helper Class to import PDF
 class ImpSdrPdfImport final
@@ -239,6 +241,8 @@ public:
                     SvdProgressInfo* pProgrInfo = nullptr);
 };
 
+#endif // HAVE_FEATURE_PDFIUM
+
 #endif // INCLUDED_SVX_SOURCE_SVDRAW_SVDFMTF_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit b10bc896bdceeb3f24269c485272fde2e669922f
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Wed Jun 6 00:51:10 2018 -0400

    vcl: svx: misc improvements to pdfium importing
    
    Change-Id: I58f2fd973a731b148f40b37139cd74bac097a7d2

diff --git a/include/svx/xmlgrhlp.hxx b/include/svx/xmlgrhlp.hxx
index d6973104f72e..4d9fa58a1b49 100644
--- a/include/svx/xmlgrhlp.hxx
+++ b/include/svx/xmlgrhlp.hxx
@@ -25,6 +25,7 @@
 #include <vcl/GraphicObject.hxx>
 #include <vector>
 #include <set>
+#include <unordered_map>
 #include <utility>
 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index cd2e48c273f7..24c3f4e796a2 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -231,7 +231,7 @@ public:
     const VectorGraphicDataPtr& getVectorGraphicData() const;
 
     void setPdfData(const std::shared_ptr<css::uno::Sequence<sal_Int8>>& rPdfData);
-    std::shared_ptr<css::uno::Sequence<sal_Int8>> getPdfData() const;
+    const std::shared_ptr<css::uno::Sequence<sal_Int8>>& getPdfData() const;
     bool hasPdfData() const;
 
     /// Set the page number of the multi-page source this Graphic is rendered from.
diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx
index 0e1b546daa36..0fc3249cd6a3 100644
--- a/include/vcl/pdfread.hxx
+++ b/include/vcl/pdfread.hxx
@@ -10,6 +10,7 @@
 #ifndef INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
 #define INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
 
+#include <vector>
 #include <tools/stream.hxx>
 
 namespace com
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index ad00ae0ba0ba..7f58ba6c8d1f 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -144,7 +144,7 @@ bool SdPdfFilter::Import()
         Point aPos(0, 0);
 
         pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), aGraphic,
-                                           ::tools::Rectangle(aPos, aGrfSize)));
+                                           tools::Rectangle(aPos, aGrfSize)));
     }
 
     return true;
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index affd350a6a8c..d34573d65ee6 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -1009,7 +1009,7 @@ public:
 };
 
 bool xpdf_ImportFromFile(const OUString& rURL,
-                             const ContentSinkSharedPtr& rSink,
+                         const ContentSinkSharedPtr& rSink,
                          const uno::Reference<task::XInteractionHandler>& xIHdl,
                          const OUString& rPwd,
                          const uno::Reference<uno::XComponentContext>& xContext,
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index be4ef4377859..6347c7dc1352 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -971,7 +971,7 @@ void ImpSdrPdfImport::ImportText(const Point& rPos, const Size& rSize, const OUS
     Size aSize(FRound(rSize.Width() * mfScaleX), FRound(rSize.Height() * mfScaleY));
 
     if (eAlg == ALIGN_BASELINE)
-        aPos.AdjustY(-(FRound(aFontMetric.GetAscent() * mfScaleY)));
+        aPos.AdjustY(-FRound(aFontMetric.GetAscent() * mfScaleY));
     else if (eAlg == ALIGN_BOTTOM)
         aPos.AdjustY(-nTextHeight);
 
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index 238b8dda3c91..988341d528e1 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -764,10 +764,11 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X
             std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(aStream.xStream));
             if (bUseGfxLink && aGfxLink.GetDataSize() && aGfxLink.GetData())
             {
-                if (aGraphic.hasPdfData())
+                const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData = aGraphic.getPdfData();
+                if (rPdfData && rPdfData->hasElements())
                 {
                     // See if we have this PDF already, and avoid duplicate storage.
-                    auto aIt = maExportPdf.find(aGraphic.getPdfData().get());
+                    auto aIt = maExportPdf.find(rPdfData.get());
                     if (aIt != maExportPdf.end())
                     {
                         auto const& aURLAndMimePair = aIt->second;
@@ -779,8 +780,7 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X
                     // vcl::ImportPDF() possibly downgraded the PDF data from a
                     // higher PDF version, while aGfxLink still contains the
                     // original data provided by the user.
-                    std::shared_ptr<uno::Sequence<sal_Int8>> pPdfData = aGraphic.getPdfData();
-                    pStream->WriteBytes(pPdfData->getConstArray(), pPdfData->getLength());
+                    pStream->WriteBytes(rPdfData->getConstArray(), rPdfData->getLength());
                 }
                 else
                 {
diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx
index a37508c2fcd1..05998009e14a 100644
--- a/svx/source/xoutdev/_xoutbmp.cxx
+++ b/svx/source/xoutdev/_xoutbmp.cxx
@@ -182,8 +182,8 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName,
             SfxMedium aMedium(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE|StreamMode::SHARE_DENYNONE|StreamMode::TRUNC);
             if (SvStream* pOutStream = aMedium.GetOutStream())
             {
-                std::shared_ptr<uno::Sequence<sal_Int8>> pPdfData = rGraphic.getPdfData();
-                pOutStream->WriteBytes(pPdfData->getConstArray(), pPdfData->getLength());
+                const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData = rGraphic.getPdfData();
+                pOutStream->WriteBytes(rPdfData->getConstArray(), rPdfData->getLength());
                 aMedium.Commit();
                 if (!aMedium.GetError())
                     nErr = ERRCODE_NONE;
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 9ee9e69011b3..3101056824ad 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -60,7 +60,7 @@ inline double pointToPixel(const double fPoint, const double fResolutionDPI)
 
 /// Does PDF to bitmap conversion using pdfium.
 size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, sal_uInt64 nPos,
-                       sal_uInt64 nSize, const size_t nFirstPage = 0, int nPages = 1,
+                       sal_uInt64 nSize, const size_t nFirstPage, int nPages,
                        const double fResolutionDPI = 96.)
 {
     FPDF_LIBRARY_CONFIG aConfig;
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index adc7d771c94d..52e4e9e74ae8 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -563,7 +563,7 @@ void Graphic::setPdfData(const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfDat
     mxImpGraphic->setPdfData(rPdfData);
 }
 
-std::shared_ptr<uno::Sequence<sal_Int8>> Graphic::getPdfData() const
+const std::shared_ptr<uno::Sequence<sal_Int8>>& Graphic::getPdfData() const
 {
     return mxImpGraphic->getPdfData();
 }
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 32c8dfee44a8..87a7bd64a398 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -242,7 +242,8 @@ ImpGraphic::ImpGraphic(GraphicExternalLink const & rGraphicExternalLink) :
         mbDummyContext  ( false ),
         maGraphicExternalLink(rGraphicExternalLink),
         maLastUsed (std::chrono::high_resolution_clock::now()),
-        mbPrepared (false)
+        mbPrepared (false),
+        mnPageNumber(-1)
 {
 }
 
commit 17b95a2cb577731687e87126f22e6e64784e782c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 28 08:02:06 2018 -0400

    vcl: fix pdf rendering regression
    
    Change-Id: I6c2c48c033facb317b4ca7ed2af07348d6386b98
    Reviewed-on: https://gerrit.libreoffice.org/54921
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index bd48443df88a..9ee9e69011b3 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -243,7 +243,8 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic, const double fResolutionDPI
 {
     uno::Sequence<sal_Int8> aPdfData;
     Bitmap aBitmap;
-    const bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData, fResolutionDPI);
+    const bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData, STREAM_SEEK_TO_BEGIN,
+                                STREAM_SEEK_TO_END, fResolutionDPI);
     rGraphic = aBitmap;
     rGraphic.setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(aPdfData));
     rGraphic.setPageNumber(0); // We currently import only the first page.
commit 6d8ce5b1d608d2e8e4dc36dec43328e9380a8bc9
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu May 24 23:01:15 2018 -0400

    pdf: preserve the original page dimensions on import
    
    Also allow for rendering PDFs to images at custom
    resolution, instead of hard-coded (old hard-coded
    value of 96 dpi is now default arguments).
    
    Change-Id: Ia5b52f72d6ce7130a2debc7c6f86504aa041bdc8
    Reviewed-on: https://gerrit.libreoffice.org/54786
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx
index 1ffabf5ce0d4..0e1b546daa36 100644
--- a/include/vcl/pdfread.hxx
+++ b/include/vcl/pdfread.hxx
@@ -34,11 +34,15 @@ namespace vcl
 VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex,
                              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);
+                             sal_uInt64 nSize = STREAM_SEEK_TO_END,
+                             const double fResolutionDPI = 96.);
+
+VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic,
+                             const double fResolutionDPI = 96.);
 
 VCL_DLLPUBLIC size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
-                               css::uno::Sequence<sal_Int8>& rPdfData);
+                               css::uno::Sequence<sal_Int8>& rPdfData,
+                               const double fResolutionDPI = 96.);
 }
 
 #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 a52a6aea3353..ad00ae0ba0ba 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -100,9 +100,12 @@ bool SdPdfFilter::Import()
     const OUString aFileName(
         mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE));
 
+    // Rendering resolution.
+    const double dResolutionDPI = 96.;
+
     uno::Sequence<sal_Int8> aPdfData;
     std::vector<Bitmap> aBitmaps;
-    if (vcl::ImportPDF(aFileName, aBitmaps, aPdfData) == 0)
+    if (vcl::ImportPDF(aFileName, aBitmaps, aPdfData, dResolutionDPI) == 0)
         return false;
 
     // Prepare the link with the PDF stream.
@@ -129,8 +132,12 @@ bool SdPdfFilter::Import()
 
         // Create the page and insert the Graphic.
         SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
-        const Size aGrfSize(OutputDevice::LogicToLogic(
-            aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)));
+        Size aGrfSize(OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(),
+                                                 MapMode(MapUnit::Map100thMM)));
+
+        // Resize to original size based on 72 dpi to preserve page size.
+        aGrfSize = Size(aGrfSize.Width() * 72. / dResolutionDPI,
+                        aGrfSize.Height() * 72. / dResolutionDPI);
 
         // Make the page size match the rendered image.
         pPage->SetSize(aGrfSize);
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index b5fa067a324a..bd48443df88a 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -53,11 +53,15 @@ int CompatibleWriter::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void*
 }
 
 /// Convert to inch, then assume 96 DPI.
-double pointToPixel(double fPoint) { return fPoint / 72 * 96; }
+inline double pointToPixel(const double fPoint, const double fResolutionDPI)
+{
+    return fPoint * fResolutionDPI / 72.;
+}
 
 /// Does PDF to bitmap conversion using pdfium.
 size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, sal_uInt64 nPos,
-                       sal_uInt64 nSize, const size_t nFirstPage, int nPages)
+                       sal_uInt64 nSize, const size_t nFirstPage = 0, int nPages = 1,
+                       const double fResolutionDPI = 96.)
 {
     FPDF_LIBRARY_CONFIG aConfig;
     aConfig.version = 2;
@@ -89,8 +93,8 @@ size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, sal_uIn
             break;
 
         // Returned unit is points, convert that to pixel.
-        const size_t nPageWidth = pointToPixel(FPDF_GetPageWidth(pPdfPage));
-        const size_t nPageHeight = pointToPixel(FPDF_GetPageHeight(pPdfPage));
+        const size_t nPageWidth = pointToPixel(FPDF_GetPageWidth(pPdfPage), fResolutionDPI);
+        const size_t nPageHeight = pointToPixel(FPDF_GetPageHeight(pPdfPage), fResolutionDPI);
         FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1);
         if (!pPdfBitmap)
             break;
@@ -192,7 +196,8 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n
     return rOutStream.good();
 }
 #else
-size_t generatePreview(SvStream&, std::vector<Bitmap>&, sal_uInt64, sal_uInt64, size_t, int)
+size_t generatePreview(SvStream&, std::vector<Bitmap>&, sal_uInt64, sal_uInt64, size_t, int,
+                       const double)
 {
     return 0;
 }
@@ -210,11 +215,13 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n
 namespace vcl
 {
 bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex,
-               css::uno::Sequence<sal_Int8>& rPdfData, sal_uInt64 nPos, sal_uInt64 nSize)
+               css::uno::Sequence<sal_Int8>& rPdfData, sal_uInt64 nPos, sal_uInt64 nSize,
+               const double fResolutionDPI)
 {
     // Get the preview of the first page.
     std::vector<Bitmap> aBitmaps;
-    if (generatePreview(rStream, aBitmaps, nPos, nSize, nPageIndex, 1) != 1 || aBitmaps.empty())
+    if (generatePreview(rStream, aBitmaps, nPos, nSize, nPageIndex, 1, fResolutionDPI) != 1
+        || aBitmaps.empty())
         return false;
 
     rBitmap = aBitmaps[0];
@@ -232,11 +239,11 @@ bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex,
     return true;
 }
 
-bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
+bool ImportPDF(SvStream& rStream, Graphic& rGraphic, const double fResolutionDPI)
 {
     uno::Sequence<sal_Int8> aPdfData;
     Bitmap aBitmap;
-    const bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData);
+    const bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData, fResolutionDPI);
     rGraphic = aBitmap;
     rGraphic.setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(aPdfData));
     rGraphic.setPageNumber(0); // We currently import only the first page.
@@ -244,12 +251,14 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
 }
 
 size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
-                 css::uno::Sequence<sal_Int8>& rPdfData)
+                 css::uno::Sequence<sal_Int8>& rPdfData, const double fResolutionDPI)
 {
     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)
+    if (generatePreview(*xStream, rBitmaps, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END, 0, -1,
+                        fResolutionDPI)
+        == 0)
         return 0;
 
     // Save the original PDF stream for later use.
commit 47505ae5c26d8a93e28d86d236b07eeb57651b53
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu May 24 06:59:39 2018 -0400

    sd: make the imported PDF page exactly as original
    
    i.e. no borders or larger page than rendered PDF
    
    Change-Id: I1f356cceeec1d5d9f1728f0e29160fdd9241a221
    Reviewed-on: https://gerrit.libreoffice.org/54764
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 9ad401287131..a52a6aea3353 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -129,37 +129,12 @@ bool SdPdfFilter::Import()
 
         // Create the page and insert the Graphic.
         SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
-        Size aGrfSize(OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(),
-                                                 MapMode(MapUnit::Map100thMM)));
-
-        Size aPagSize(pPage->GetSize());
-        aPagSize.AdjustWidth(-(pPage->GetLeftBorder() + pPage->GetRightBorder()));
-        aPagSize.AdjustHeight(-(pPage->GetUpperBorder() + pPage->GetLowerBorder()));
-
-        // scale to fit page
-        if (((aGrfSize.Height() > aPagSize.Height()) || (aGrfSize.Width() > aPagSize.Width()))
-            && aGrfSize.Height() && aPagSize.Height())
-        {
-            const double fGrfWH = static_cast<double>(aGrfSize.Width()) / aGrfSize.Height();
-            const double fWinWH = static_cast<double>(aPagSize.Width()) / aPagSize.Height();
-
-            // adjust graphic to page size (scales)
-            if (fGrfWH < fWinWH)
-            {
-                aGrfSize.setWidth(static_cast<long>(aPagSize.Height() * fGrfWH));
-                aGrfSize.setHeight(aPagSize.Height());
-            }
-            else if (fGrfWH > 0.F)
-            {
-                aGrfSize.setWidth(aPagSize.Width());
-                aGrfSize.setHeight(static_cast<long>(aPagSize.Width() / fGrfWH));
-            }
-        }
-
-        // set output rectangle for graphic
-        Point aPos;
-        aPos.setX(((aPagSize.Width() - aGrfSize.Width()) >> 1) + pPage->GetLeftBorder());
-        aPos.setY(((aPagSize.Height() - aGrfSize.Height()) >> 1) + pPage->GetUpperBorder());
+        const Size aGrfSize(OutputDevice::LogicToLogic(
+            aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)));
+
+        // Make the page size match the rendered image.
+        pPage->SetSize(aGrfSize);
+        Point aPos(0, 0);
 
         pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), aGraphic,
                                            ::tools::Rectangle(aPos, aGrfSize)));
commit 925967f4c884c05379d58e75e3eb5538a053a4e8
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu May 24 01:33:50 2018 -0400

    sd: render the correct PDF page on swapping in
    
    Change-Id: I81225e228d9cf2b9849110715dbfdeb59f2805dd
    Reviewed-on: https://gerrit.libreoffice.org/54746
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx
index 9f2797768646..1ffabf5ce0d4 100644
--- a/include/vcl/pdfread.hxx
+++ b/include/vcl/pdfread.hxx
@@ -31,7 +31,7 @@ class Graphic;
 namespace vcl
 {
 /// Imports a PDF stream into rGraphic as a GDIMetaFile.
-VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap,
+VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex,
                              css::uno::Sequence<sal_Int8>& rPdfData,
                              sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN,
                              sal_uInt64 nSize = STREAM_SEEK_TO_END);
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index dc03d1965aa7..9ad401287131 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -129,11 +129,8 @@ bool SdPdfFilter::Import()
 
         // Create the page and insert the Graphic.
         SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
-
-        SAL_WARN("sd.filter", "Graphic PrefSize: " << aGraphic.GetPrefSize());
         Size aGrfSize(OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(),
                                                  MapMode(MapUnit::Map100thMM)));
-        SAL_WARN("sd.filter", "Graphic Logic Size: " << aGrfSize);
 
         Size aPagSize(pPage->GetSize());
         aPagSize.AdjustWidth(-(pPage->GetLeftBorder() + pPage->GetRightBorder()));
@@ -164,8 +161,6 @@ bool SdPdfFilter::Import()
         aPos.setX(((aPagSize.Width() - aGrfSize.Width()) >> 1) + pPage->GetLeftBorder());
         aPos.setY(((aPagSize.Height() - aGrfSize.Height()) >> 1) + pPage->GetUpperBorder());
 
-        SAL_WARN("sd.filter", "Graphic Pos: " << aPos);
-        SAL_WARN("sd.filter", "Graphic Logic Size: " << aGrfSize);
         pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), aGraphic,
                                            ::tools::Rectangle(aPos, aGrfSize)));
     }
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 4d272720fdcf..b5fa067a324a 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -209,12 +209,12 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n
 
 namespace vcl
 {
-bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, css::uno::Sequence<sal_Int8>& rPdfData,
-               sal_uInt64 nPos, sal_uInt64 nSize)
+bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex,
+               css::uno::Sequence<sal_Int8>& rPdfData, sal_uInt64 nPos, sal_uInt64 nSize)
 {
     // Get the preview of the first page.
     std::vector<Bitmap> aBitmaps;
-    if (generatePreview(rStream, aBitmaps, nPos, nSize, 0, 1) != 1)
+    if (generatePreview(rStream, aBitmaps, nPos, nSize, nPageIndex, 1) != 1 || aBitmaps.empty())
         return false;
 
     rBitmap = aBitmaps[0];
@@ -236,7 +236,7 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
 {
     uno::Sequence<sal_Int8> aPdfData;
     Bitmap aBitmap;
-    const bool bRet = ImportPDF(rStream, aBitmap, aPdfData);
+    const bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData);
     rGraphic = aBitmap;
     rGraphic.setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(aPdfData));
     rGraphic.setPageNumber(0); // We currently import only the first page.
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 331f7927e4d2..32c8dfee44a8 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1891,7 +1891,8 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
                     if (!rImpGraphic.mpPdfData)
                         rImpGraphic.mpPdfData.reset(new uno::Sequence<sal_Int8>());
 
-                    if (vcl::ImportPDF(rIStm, aBitmap, *rImpGraphic.mpPdfData,
+                    if (vcl::ImportPDF(rIStm, aBitmap, rImpGraphic.mnPageNumber,
+                                       *rImpGraphic.mpPdfData,
                                        rIStm.Tell(), nPdfDataLength))
                     {
                         rImpGraphic.maEx = aBitmap;
commit 93307b07a2e0f1ff6637a739217b3aa951856e3d
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue May 22 10:47:46 2018 +0200

    Introduce a LO_IMPORT_USE_PDFIUM envvar to force PDFium for PDF import.
    
    Change-Id: Ibb7734430b955dad4aefec22260ba8694ccb9183

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 7eb2824636c7..9bc418f8f53a 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -749,7 +749,7 @@ bool SfxObjectShell::DoLoad( SfxMedium *pMed )
         {
             // Experimental PDF importing using PDFium. This is currently enabled for LOK only and
             // we handle it not via XmlFilterAdaptor but a new SdPdfFiler.
-            const bool bPdfiumImport = comphelper::LibreOfficeKit::isActive() && pMedium->GetFilter() &&
+            const bool bPdfiumImport = (comphelper::LibreOfficeKit::isActive() || getenv("LO_IMPORT_USE_PDFIUM")) && pMedium->GetFilter() &&
                                        (pMedium->GetFilter()->GetFilterName() == "draw_pdf_import");
             pImpl->nLoadedFlags = SfxLoadedFlags::NONE;
             pImpl->bModelInitialized = false;
commit f03ca93665fa974c5be2d9ca7082cb64ceafd7f8
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun May 20 22:31:36 2018 -0400

    sd: disable pdf import tests
    
    Change-Id: Iaee679d2ff322c67d081185588103d5685fa970a

diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 7e37d3c6ad0b..5fdb232625ef 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -138,7 +138,7 @@ public:
     void testTableBorderLineStyle();
     void testBnc862510_6();
     void testBnc862510_7();
-#if ENABLE_PDFIMPORT
+#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS)
     void testPDFImport();
     void testPDFImportSkipImages();
 #endif
@@ -221,7 +221,7 @@ public:
     CPPUNIT_TEST(testTableBorderLineStyle);
     CPPUNIT_TEST(testBnc862510_6);
     CPPUNIT_TEST(testBnc862510_7);
-#if ENABLE_PDFIMPORT
+#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS)
     CPPUNIT_TEST(testPDFImport);
     CPPUNIT_TEST(testPDFImportSkipImages);
 #endif
@@ -1205,7 +1205,7 @@ void SdImportTest::testBnc862510_7()
     xDocShRef->DoClose();
 }
 
-#if ENABLE_PDFIMPORT
+#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS)
 
 void SdImportTest::testPDFImport()
 {
commit 43ade4368f270594e9dd2bfd6ebab972859046df
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun May 20 15:17:16 2018 -0400

    svx: set the font name of imported PDF text
    
    Change-Id: I79dde3c8983a70311de2d2a46093fac2722fb372

diff --git a/external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2 b/external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2
new file mode 100644
index 000000000000..798b2b6c1ef8
--- /dev/null
+++ b/external/pdfium/0015-svx-set-the-font-name-of-imported-PDF-text.patch.2
@@ -0,0 +1,69 @@
+From 04f9899ddf5f9691ffaca5091082183f167e95d3 Mon Sep 17 00:00:00 2001
+From: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
+Date: Wed, 6 Jun 2018 06:34:56 +0200
+Subject: [PATCH] svx: set the font name of imported PDF text
+
+---
+ pdfium/fpdfsdk/fpdf_editpage.cpp | 23 +++++++++++++++++++++++
+ pdfium/public/fpdf_edit.h        | 11 +++++++++++
+ 2 files changed, 34 insertions(+)
+
+diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
+index a52e1a9..9daffc0 100644
+--- a/pdfium/fpdfsdk/fpdf_editpage.cpp
++++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
+@@ -648,6 +648,29 @@ FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object)
+   return pTxtObj->GetFontSize();
+ }
+ 
++FPDF_EXPORT int FPDF_CALLCONV
++FPDFTextObj_GetFontName(FPDF_PAGEOBJECT text_object, char* result)
++{
++  if (!text_object)
++    return 0;
++
++  CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
++  CPDF_Font* pPdfFont = pTxtObj->GetFont();
++  if (!pPdfFont)
++    return 0;
++
++  CFX_Font* pFont = pPdfFont->GetFont();
++  if (!pFont)
++    return 0;
++
++  ByteString byte_str = pFont->GetFamilyName();
++  const size_t byte_str_len = byte_str.GetLength();
++
++  memcpy(result, byte_str.GetBuffer(byte_str_len).data(), byte_str_len);
++  result[byte_str_len] = '\0';
++  return byte_str_len;
++}
++
+ FPDF_EXPORT void FPDF_CALLCONV
+ FPDFTextObj_GetMatrix(FPDF_PAGEOBJECT text_object,
+                       double* a,
+diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
+index 4351649..f858ab2 100644
+--- a/pdfium/public/fpdf_edit.h
++++ b/pdfium/public/fpdf_edit.h
+@@ -1030,6 +1030,17 @@ FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object);
+ FPDF_EXPORT int FPDF_CALLCONV
+ FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object);
+ 
++// Get the font name of a text object.
++//
++// text_object - Handle of text object returned by FPDFPageObj_NewTextObj
++//               or FPDFPageObj_NewTextObjEx.
++// result - The result in ascii.
++//
++// Return Value:
++// The number of characters / bytes written in result.
++FPDF_EXPORT int FPDF_CALLCONV
++FPDFTextObj_GetFontName(FPDF_PAGEOBJECT text_object, char* result);
++
+ // Get the matrix of a particular text object.
+ //
+ // text_object - Handle of text object returned by FPDFPageObj_NewTextObj
+-- 
+2.16.3
+
diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk
index 294a6498898e..c73da438821d 100644
--- a/external/pdfium/UnpackedTarball_pdfium.mk
+++ b/external/pdfium/UnpackedTarball_pdfium.mk
@@ -28,6 +28,7 @@ pdfium_patches += 0011-svx-correctly-possition-form-objects-from-PDF.patch.2
 pdfium_patches += 0012-svx-import-processed-PDF-text.patch.2
 pdfium_patches += 0013-svx-cleanup-pdfium-importer.patch.2
 pdfium_patches += 0014-svx-update-PDFium-patch-and-code.patch.2
+pdfium_patches += 0015-svx-set-the-font-name-of-imported-PDF-text.patch.2
 
 $(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium))
 
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 73dca53d545c..be4ef4377859 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -562,7 +562,8 @@ void ImpSdrPdfImport::InsertObj(SdrObject* pObj, bool bScale)
                         SdrObject* pCandidate = aIter.Next();
                         OSL_ENSURE(pCandidate && dynamic_cast<SdrObjGroup*>(pCandidate) == nullptr,
                                    "SdrObjListIter with SdrIterMode::DeepNoGroups error (!)");
-                        SdrObject* pNewClone = pCandidate->Clone();
+                        SdrObject* pNewClone(
+                            pCandidate->CloneSdrObject(pCandidate->getSdrModelFromSdrObject()));
 
                         if (pNewClone)
                         {
@@ -927,6 +928,20 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
         mbFntDirty = true;
     }
 
+    std::unique_ptr<char[]> pFontName(new char[80 + 1]); // + terminating null
+    char* pCharFontName = reinterpret_cast<char*>(pFontName.get());
+    int nFontNameChars = FPDFTextObj_GetFontName(pPageObject, pCharFontName);
+    if (nFontNameChars > 0)
+    {
+        OUString sFontName = OUString::createFromAscii(pFontName.get());
+        if (sFontName != aFnt.GetFamilyName())
+        {
+            aFnt.SetFamilyName(sFontName);
+            mpVD->SetFont(aFnt);
+            mbFntDirty = true;
+        }
+    }
+
     Color aTextColor(COL_TRANSPARENT);
     unsigned int nR, nG, nB, nA;
     if (FPDFTextObj_GetColor(pPageObject, &nR, &nG, &nB, &nA))
commit 92550f9b04785f83ee7229c815e88e847db194dc
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat May 19 21:28:31 2018 -0400

    svx: update PDFium patch and code
    
    Change-Id: I07c6a7c65d5631b70da64927a35d7a3b371eff25

diff --git a/external/pdfium/0014-svx-update-PDFium-patch-and-code.patch.2 b/external/pdfium/0014-svx-update-PDFium-patch-and-code.patch.2
new file mode 100644
index 000000000000..6974739862a3
--- /dev/null
+++ b/external/pdfium/0014-svx-update-PDFium-patch-and-code.patch.2
@@ -0,0 +1,137 @@
+From f701ff3ce04a4e7e757a9f3ee62b4967749455dd Mon Sep 17 00:00:00 2001
+From: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
+Date: Tue, 5 Jun 2018 14:27:55 +0200
+Subject: [PATCH 14/14] svx: update PDFium patch and code
+
+---
+ pdfium/fpdfsdk/cpdfsdk_helpers.h |  2 ++
+ pdfium/fpdfsdk/fpdf_editimg.cpp  |  2 +-
+ pdfium/fpdfsdk/fpdf_editpage.cpp | 19 ++++++++++++-------
+ pdfium/public/fpdf_edit.h        | 16 ++++++++--------
+ 4 files changed, 23 insertions(+), 16 deletions(-)
+
+diff --git a/pdfium/fpdfsdk/cpdfsdk_helpers.h b/pdfium/fpdfsdk/cpdfsdk_helpers.h
+index 477bb74..c907ad8 100644
+--- a/pdfium/fpdfsdk/cpdfsdk_helpers.h
++++ b/pdfium/fpdfsdk/cpdfsdk_helpers.h
+@@ -40,6 +40,8 @@ class CPDF_TextPage;
+ class CPDF_TextPageFind;
+ class IPDFSDK_PauseAdapter;
+ class FX_PATHPOINT;
++class CPDF_TextObject;
++class CPDF_FormObject;
+ 
+ #ifdef PDF_ENABLE_XFA
+ class CPDFXFA_Context;
+diff --git a/pdfium/fpdfsdk/fpdf_editimg.cpp b/pdfium/fpdfsdk/fpdf_editimg.cpp
+index 3f400c7..968b84a 100644
+--- a/pdfium/fpdfsdk/fpdf_editimg.cpp
++++ b/pdfium/fpdfsdk/fpdf_editimg.cpp
+@@ -203,7 +203,7 @@ FPDFImageObj_GetBitmapBgra(FPDF_PAGEOBJECT image_object) {
+   RetainPtr<CFX_DIBitmap> pBitmap;
+   pBitmap = pSource->CloneConvert(FXDIB_Argb);
+ 
+-  return pBitmap.Leak();
++  return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
+ }
+ 
+ FPDF_EXPORT unsigned long FPDF_CALLCONV
+diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
+index 29c8b01..a52e1a9 100644
+--- a/pdfium/fpdfsdk/fpdf_editpage.cpp
++++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
+@@ -718,7 +718,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
+   int ret_count = byte_str_len / sizeof(unsigned short);
+ 
+   ASSERT(ret_count <= char_count + 1);  // +1 to account for the NUL terminator.
+-  memcpy(result, byte_str.GetBuffer(byte_str_len), byte_str_len);
++  memcpy(result, byte_str.GetBuffer(byte_str_len).data(), byte_str_len);
+   return ret_count;
+ }
+ 
+@@ -758,7 +758,7 @@ FPDFTextObj_GetTextProcessed(FPDF_PAGEOBJECT text_object,
+   int ret_count = byte_str_len / kBytesPerCharacter;
+ 
+   ASSERT(ret_count <= char_count + 1);  // +1 to account for the NUL terminator.
+-  memcpy(result, byte_str.GetBuffer(byte_str_len), byte_str_len);
++  memcpy(result, byte_str.GetBuffer(byte_str_len).data(), byte_str_len);
+   return ret_count;
+ }
+ 
+@@ -801,10 +801,15 @@ FPDFTextObj_GetColor(FPDF_PAGEOBJECT text_object,
+       return false;
+   }
+ 
+-  const uint32_t RGB = bStroke ? pTxtObj->m_ColorState.GetStrokeRGB() : pTxtObj->m_ColorState.GetFillRGB();
+-  *R = FXSYS_GetRValue(RGB);
+-  *G = FXSYS_GetGValue(RGB);
+-  *B = FXSYS_GetBValue(RGB);
++  const CPDF_Color* pColor = bStroke ? pTxtObj->m_ColorState.GetStrokeColor() : pTxtObj->m_ColorState.GetFillColor();
++  if (pColor == nullptr)
++    return false;
++
++  int r, g, b;
++  pColor->GetRGB(&r, &g, &b);
++  *R = r;
++  *G = g;
++  *B = b;
+   *A = static_cast<unsigned int>(
+       (pTxtObj->m_GeneralState.GetStrokeAlpha() * 255.f) + 0.5f);
+ 
+@@ -834,7 +839,7 @@ FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index)
+     const CFX_Matrix& matrix = pFrmObj->form_matrix();
+     const CPDF_PageObjectList* pObjectList = pFrmObj->form()->GetPageObjectList();
+     if (pObjectList)
+-        return pObjectList->GetPageObjectByIndex(index);
++        return FPDFPageObjectFromCPDFPageObject(pObjectList->GetPageObjectByIndex(index));
+   }
+ 
+   return nullptr;
+diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
+index e14b2a5..4351649 100644
+--- a/pdfium/public/fpdf_edit.h
++++ b/pdfium/public/fpdf_edit.h
+@@ -660,32 +660,32 @@ FPDFPageObj_GetStrokeColor(FPDF_PAGEOBJECT page_object,
+                            unsigned int* B,
+                            unsigned int* A);
+ 
+-// Set the stroke width of a path.
++// Get the stroke width of a path.
+ //
+ // path   - the handle to the path object.
+ // width  - the width of the stroke.
+ //
+ // Returns TRUE on success
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+-FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width);
++FPDFPath_GetStrokeWidth(FPDF_PAGEOBJECT path, float* width);
+ 
+-// Set the stroke width of a page object.
++// Set the stroke width of a path.
+ //
+-// path   - the handle to the page object.
++// path   - the handle to the path object.
+ // width  - the width of the stroke.
+ //
+ // Returns TRUE on success
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+-FPDFPageObj_SetStrokeWidth(FPDF_PAGEOBJECT page_object, float width);
++FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width);
+ 
+-// Get the stroke width of a path.
++// Set the stroke width of a page object.
+ //
+-// path   - the handle to the path object.
++// path   - the handle to the page object.
+ // width  - the width of the stroke.
+ //
+ // Returns TRUE on success
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+-FPDFPath_GetStrokeWidth(FPDF_PAGEOBJECT path, float* width);
++FPDFPageObj_SetStrokeWidth(FPDF_PAGEOBJECT page_object, float width);
+ 
+ // Set the line join of |page_object|.
+ //
+-- 
+2.16.3
+
diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk
index 333150d016a0..294a6498898e 100644
--- a/external/pdfium/UnpackedTarball_pdfium.mk
+++ b/external/pdfium/UnpackedTarball_pdfium.mk
@@ -27,6 +27,7 @@ pdfium_patches += 0010-svx-support-importing-forms-from-PDFs.patch.2
 pdfium_patches += 0011-svx-correctly-possition-form-objects-from-PDF.patch.2
 pdfium_patches += 0012-svx-import-processed-PDF-text.patch.2
 pdfium_patches += 0013-svx-cleanup-pdfium-importer.patch.2
+pdfium_patches += 0014-svx-update-PDFium-patch-and-code.patch.2
 
 $(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium))
 
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 0c1a02aef0de..73dca53d545c 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1026,7 +1026,8 @@ void ImpSdrPdfImport::MapScaling()
 
 void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/)
 {
-    std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmapBgra(pPageObject));
+    std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter>
+                        bitmap(FPDFImageObj_GetBitmapBgra(pPageObject));
     if (!bitmap)
     {
         SAL_WARN("sd.filter", "Failed to get IMAGE");
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index 226051aadd83..dfb4b9ad2946 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -40,9 +40,9 @@ class SdrModel;
 class SdrPage;
 class SdrObject;
 class SvdProgressInfo;
-typedef void* FPDF_DOCUMENT;
-typedef void* FPDF_PAGEOBJECT;
-typedef void* FPDF_TEXTPAGE;
+typedef struct fpdf_document_t__* FPDF_DOCUMENT;
+typedef struct fpdf_pageobject_t__* FPDF_PAGEOBJECT;  // (text, path, etc.)
+typedef struct fpdf_textpage_t__* FPDF_TEXTPAGE;
 
 // Helper Class to import PDF
 class ImpSdrPdfImport final
commit 80ae4c7a2a6ff336e3bb7462d62fe01b5cb514b8
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri May 18 09:15:36 2018 -0400

    svx: cleanup pdfium importer
    
    Change-Id: Id925ba7734a2c73270e40f19d3fc50552441c34e

diff --git a/external/pdfium/0013-svx-cleanup-pdfium-importer.patch.2 b/external/pdfium/0013-svx-cleanup-pdfium-importer.patch.2
new file mode 100644
index 000000000000..91fb38d2825b
--- /dev/null
+++ b/external/pdfium/0013-svx-cleanup-pdfium-importer.patch.2
@@ -0,0 +1,130 @@
+From 2f56db06360e547f995c6b20050974d5f4c6f7c6 Mon Sep 17 00:00:00 2001
+From: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
+Date: Tue, 5 Jun 2018 11:36:05 +0200
+Subject: [PATCH 13/14] svx: cleanup pdfium importer
+
+---
+ pdfium/core/fpdfapi/page/cpdf_imageobject.cpp    |  1 -
+ pdfium/core/fpdfapi/page/cpdf_page.cpp           |  3 ---
+ pdfium/core/fpdfapi/page/cpdf_pageobject.cpp     |  2 --
+ pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp |  1 -
+ pdfium/core/fxge/cfx_pathdata.cpp                |  2 --
+ pdfium/fpdfsdk/fpdf_editpage.cpp                 | 12 ------------
+ 6 files changed, 21 deletions(-)
+
+diff --git a/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp b/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp
+index 416d82d..3b5a740 100644
+--- a/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp
++++ b/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp
+@@ -43,7 +43,6 @@ const CPDF_ImageObject* CPDF_ImageObject::AsImage() const {
+ void CPDF_ImageObject::CalcBoundingBox() {
+   std::tie(m_Left, m_Right, m_Top, m_Bottom) =
+       m_Matrix.TransformRect(0.f, 1.f, 1.f, 0.f);
+-    // fprintf(stderr, "Image BB: %f, %f, %f, %f\n", m_Left, m_Right, m_Top, m_Bottom);
+ }
+ 
+ void CPDF_ImageObject::SetImage(const RetainPtr<CPDF_Image>& pImage) {
+diff --git a/pdfium/core/fpdfapi/page/cpdf_page.cpp b/pdfium/core/fpdfapi/page/cpdf_page.cpp
+index 00657d6..eee6673 100644
+--- a/pdfium/core/fpdfapi/page/cpdf_page.cpp
++++ b/pdfium/core/fpdfapi/page/cpdf_page.cpp
+@@ -37,14 +37,12 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument,
+   CFX_FloatRect mediabox = GetBox("MediaBox");
+   if (mediabox.IsEmpty())
+     mediabox = CFX_FloatRect(0, 0, 612, 792);
+-  fprintf(stderr, "Page mediabox: %f, %f, %f, %f\n", mediabox.left, mediabox.right, mediabox.top, mediabox.bottom);
+ 
+   m_BBox = GetBox("CropBox");
+   if (m_BBox.IsEmpty())
+     m_BBox = mediabox;
+   else
+     m_BBox.Intersect(mediabox);
+-  fprintf(stderr, "Page cropbox: %f, %f, %f, %f\n", m_BBox.left, m_BBox.right, m_BBox.top, m_BBox.bottom);
+ 
+   m_PageSize.width = m_BBox.Width();
+   m_PageSize.height = m_BBox.Height();
+@@ -52,7 +50,6 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument,
+   int rotate = GetPageRotation();
+   if (rotate % 2)
+     std::swap(m_PageSize.width, m_PageSize.height);
+-  fprintf(stderr, "Page rotate: %d, Page Width: %f, Page Height: %f\n", rotate, m_PageSize.width, m_PageSize.height);
+ 
+   switch (rotate) {
+     case 0:
+diff --git a/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp b/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp
+index 9b5e2ce..8bb5bf5 100644
+--- a/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp
++++ b/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp
+@@ -98,7 +98,5 @@ FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const {
+   if (pMatrix)
+     rect = pMatrix->TransformRect(rect);
+ 
+-  FX_RECT rc = rect.GetOuterRect();
+-  fprintf(stderr, "PageObject BB: %f, %f, %f, %f\n", rc.left, rc.right, rc.top, rc.bottom);
+   return rect.GetOuterRect();
+ }
+diff --git a/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp b/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp
+index bf82d55..565be85 100644
+--- a/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp
++++ b/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp
+@@ -1767,7 +1767,6 @@ bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj,
+     return true;
+ 
+   float font_size = textobj->m_TextState.GetFontSize();
+-//   fprintf(stderr, "Font size: %f, matrix a: %f, b: %f, c: %f, d: %f, e: %f, f: %f\n", font_size, text_matrix.a, text_matrix.b, text_matrix.c, text_matrix.d, text_matrix.e, text_matrix.f);
+   if (bPattern) {
+     DrawTextPathWithPattern(textobj, pObj2Device, pFont, font_size,
+                             &text_matrix, bFill, bStroke);
+diff --git a/pdfium/core/fxge/cfx_pathdata.cpp b/pdfium/core/fxge/cfx_pathdata.cpp
+index 13e2cdb..ac1ff42 100644
+--- a/pdfium/core/fxge/cfx_pathdata.cpp
++++ b/pdfium/core/fxge/cfx_pathdata.cpp
+@@ -199,7 +199,6 @@ void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix) {
+ void CFX_PathData::AppendPoint(const CFX_PointF& point,
+                                FXPT_TYPE type,
+                                bool closeFigure) {
+-//   fprintf(stderr, "Append: %f, %f (%s)\n", point.x, point.y, closeFigure ? "CLOSE" : "OPEN");
+   m_Points.push_back(FX_PATHPOINT(point, type, closeFigure));
+ }
+ 
+@@ -295,7 +294,6 @@ CFX_FloatRect CFX_PathData::GetBoundingBox(float line_width,
+ void CFX_PathData::Transform(const CFX_Matrix* pMatrix) {
+   if (!pMatrix)
+     return;
+-//   fprintf(stderr, "XForm: %f, %f %f, %f, %f, %f\n", pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, pMatrix->e, pMatrix->f);
+   for (auto& point : m_Points)
+     point.m_Point = pMatrix->Transform(point.m_Point);
+ }
+diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
+index f34d3b5..29c8b01 100644
+--- a/pdfium/fpdfsdk/fpdf_editpage.cpp
++++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
+@@ -711,17 +711,6 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
+       str += pFont->UnicodeFromCharCode(charcode);
+   }
+ 
+-//   CFX_WideTextBuf m_TextBuf;
+-//   WideString str = textpage->GetPageText(char_start, char_count);
+-//   return WideString(m_TextBuf.AsStringView().Mid(
+-//       static_cast<size_t>(text_start), static_cast<size_t>(text_count)));
+-
+-//   if (str.GetLength() > static_cast<size_t>(char_count))
+-//     str = str.Left(static_cast<size_t>(char_count));
+-
+-  // Reincode in UTF-16.
+-//   WideString str = text.UTF8Decode();
+-
+   // UFT16LE_Encode doesn't handle surrogate pairs properly, so it is expected
+   // the number of items to stay the same.
+   ByteString byte_str = str.UTF16LE_Encode();
+@@ -843,7 +832,6 @@ FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index)
+   if (pFrmObj)
+   {
+     const CFX_Matrix& matrix = pFrmObj->form_matrix();
+-    fprintf(stderr, "Form matrix a: %f, b: %f, c: %f, d: %f, e: %f, f: %f\n", matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
+     const CPDF_PageObjectList* pObjectList = pFrmObj->form()->GetPageObjectList();
+     if (pObjectList)
+         return pObjectList->GetPageObjectByIndex(index);
+-- 
+2.16.3
+
diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk
index 5525e9ddf65d..333150d016a0 100644
--- a/external/pdfium/UnpackedTarball_pdfium.mk
+++ b/external/pdfium/UnpackedTarball_pdfium.mk
@@ -26,6 +26,7 @@ pdfium_patches += 0009-svx-support-color-text-for-imported-PDFs.patch.2
 pdfium_patches += 0010-svx-support-importing-forms-from-PDFs.patch.2
 pdfium_patches += 0011-svx-correctly-possition-form-objects-from-PDF.patch.2
 pdfium_patches += 0012-svx-import-processed-PDF-text.patch.2
+pdfium_patches += 0013-svx-cleanup-pdfium-importer.patch.2
 
 $(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium))
 
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index c556b1bb3af6..0c1a02aef0de 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -198,7 +198,6 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools:
     }
 
     mnPageCount = FPDF_GetPageCount(mpPdfDocument);
-    SAL_WARN("sd.filter", "Scale Rect: " << maScaleRect);
 }
 
 ImpSdrPdfImport::~ImpSdrPdfImport()
@@ -207,11 +206,10 @@ ImpSdrPdfImport::~ImpSdrPdfImport()
     FPDF_DestroyLibrary();
 }
 
-void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport,
+void ImpSdrPdfImport::DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport,
                                     int nPageIndex)
 {
     const int nPageCount = FPDF_GetPageCount(mpPdfDocument);
-    SAL_WARN("sd.filter", "Importing page " << nPageIndex << " of " << nPageCount);
     if (nPageCount > 0 && nPageIndex >= 0 && nPageIndex < nPageCount)
     {
         // Render next page.
@@ -221,187 +219,24 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
 
         const double dPageWidth = FPDF_GetPageWidth(pPdfPage);
         const double dPageHeight = FPDF_GetPageHeight(pPdfPage);
-        SAL_WARN("sd.filter", "Loaded page: " << nPageIndex << ", width: " << dPageWidth
-                                              << ", height: " << dPageHeight);
         SetupPageScale(dPageWidth, dPageHeight);
 
         // Load the page text to extract it when we get text elements.
         FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage);
 
         const int nPageObjectCount = FPDFPage_CountObject(pPdfPage);
+        if (pProgrInfo)
+            pProgrInfo->SetActionCount(nPageObjectCount);
+
         for (int nPageObjectIndex = 0; nPageObjectIndex < nPageObjectCount; ++nPageObjectIndex)
         {
             FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage, nPageObjectIndex);
             ImportPdfObject(pPageObject, pTextPage, nPageObjectIndex);
-        }
-
-        FPDFText_ClosePage(pTextPage);
-
-#if 0
-        // Now do the text.
-        FPDF_TEXTPAGE pTextPage = FPDFText_LoadPage(pPdfPage);
-        if (pTextPage != nullptr)
-        {
-            SAL_WARN("sd.filter", "TEXT TEXT TEXT");
-
-            const int nChars = FPDFText_CountChars(pTextPage);
-            SAL_WARN("sd.filter", "Got page chars: " << nChars);
-
-            const int nRects = FPDFText_CountRects(pTextPage, 0, nChars);
-            SAL_WARN("sd.filter", "Got Rects: " << nRects);
-
-            std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars + 1]); // + terminating null
-            for (int nRectIndex = 0; nRectIndex < nRects; ++nRectIndex)
-            {
-                SAL_WARN("sd.filter",
-                         "Processing Text Rect #" << nRectIndex + 1 << " of " << nRects);
-
-                double left = 0;
-                double top = 0;
-                double right = 0;
-                double bottom = 0;
-                FPDFText_GetRect(pTextPage, nRectIndex, &left, &top, &right, &bottom);
-                SAL_WARN("sd.filter", "Got Text Rect: " << left << ", " << right << ", " << top
-                                                        << ", " << bottom);
-                tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
-
-                if (right < left)
-                    std::swap(right, left);
-                if (bottom < top)
-                    std::swap(bottom, top);
-
-                SAL_WARN("sd.filter", "Got Text Rect: " << left << ", " << right << ", " << top
-                                                        << ", " << bottom);
-                SAL_WARN("sd.filter", "Logic Text Rect: " << aRect);
-
-                unsigned short* pShortText = reinterpret_cast<unsigned short*>(pText.get());
-                const int nBoundedChars = FPDFText_GetBoundedText(pTextPage, left, top, right,
-                                                                  bottom, pShortText, nChars);
-                OUString sText(pText.get(), nBoundedChars);
-                SAL_WARN("sd.filter", "Got Text #" << nRectIndex + 1 << " (" << nBoundedChars
-                                                   << "): [" << sText << "].");
-
-                const double dHalfCharWidth = (right - left) / nBoundedChars / 2.0;
-                SAL_WARN("sd.filter", "Half Char Width: " << dHalfCharWidth);
-                const int nCharIndex = FPDFText_GetCharIndexAtPos(pTextPage, left + dHalfCharWidth,
-                                                                  top + dHalfCharWidth,
-                                                                  dHalfCharWidth, dHalfCharWidth);
-                SAL_WARN("sd.filter", "Got Char Index: " << nCharIndex);
-
-                // FPDF_FONT pFont = FPDFText_GetFont(pTextPage, nCharIndex);
-                // const int nFontAscent = FPDFFont_GetAscent(pFont);
-                // const int nFontDescent = FPDFFont_GetDescent(pFont);
-                // FPDF_BYTESTRING sFontName = FPDFFont_GetName(pFont);
-                // SAL_WARN("sd.filter", "Char #" << nCharIndex << ", Got Font [" << sFontName <<
-                //                       "], Ascent: "<< nFontAscent << ", Descent: " << nFontDescent);
-
-                // FontMetric aFontMetric = mpVD->GetFontMetric();
-                // aFontMetric.SetAscent(nFontAscent);
-                // aFontMetric.SetDescent(nFontDescent);
-
-                double dFontScale = 1.0;
-                geometry::Matrix2D aMatrix;
-                if (!FPDFText_GetMatrix(pTextPage, nCharIndex, &aMatrix.m00, &aMatrix.m01,
-                                        &aMatrix.m10, &aMatrix.m11))
-                {
-                    SAL_WARN("sd.filter", "No font scale matrix, will use heuristic height of "
-                                              << aRect.GetHeight() << ".");
-                    dFontScale = aRect.GetHeight();
-                }
-                else if (aMatrix.m00 != aMatrix.m11 || aMatrix.m00 <= 0)
-                {
-                    SAL_WARN("sd.filter", "Bogus font scale matrix ("
-                                              << aMatrix.m00 << ',' << aMatrix.m11
-                                              << "), will use heuristic height of "
-                                              << aRect.GetHeight() << ".");
-                    dFontScale = aRect.GetHeight();
-                }
-                else
-                    dFontScale = aMatrix.m00;
-
-                double dFontSize = FPDFText_GetFontSize(pTextPage, nCharIndex);
-                SAL_WARN("sd.filter", "Got Font Size: " << dFontSize);
-                dFontSize *= dFontScale;
-                SAL_WARN("sd.filter", "Got Font Size Scaled: " << dFontSize);
-                dFontSize = lcl_PointToPixel(dFontSize);
-                SAL_WARN("sd.filter", "Got Font Pixel Size: " << dFontSize);
-                dFontSize = lcl_ToLogic(dFontSize);
-                SAL_WARN("sd.filter", "Got Font Logic Size: " << dFontSize);
-                vcl::Font aFnt = mpVD->GetFont();
-                aFnt.SetFontSize(Size(dFontSize, dFontSize));
-                mpVD->SetFont(aFnt);
-
-                double x = 0;
-                double y = 0;
-                FPDFText_GetCharOrigin(pTextPage, nCharIndex, &x, &y);
-                SAL_WARN("sd.filter", "Got Char Origin: " << x << ", " << y);
-                Point aPos = PointsToLogic(x, y);
-                SAL_WARN("sd.filter", "Got Char Origin Logic: " << aPos);
-                // aRect.Move(aPos.X(), aPos.Y());
-
-                // geometry::RealRectangle2D aRect;
-                // aRect.X1 = left;
-                // aRect.Y1 = top;
-                // aRect.X2 = right;
-                // aRect.Y2 = bottom;
-
-                // geometry::Matrix2D aMatrix;
-                // FPDFText_GetMatrix(pTextPage, nCharIndex, &aMatrix.m00, &aMatrix.m01, &aMatrix.m10, &aMatrix.m11);
-
-                // basegfx::B2DHomMatrix fontMatrix(
-                //     aMatrix.m00, aMatrix.m01, 0.0,
-                //     aMatrix.m10, aMatrix.m11, 0.0);
-                // fontMatrix.scale(dFontSize, dFontSize);
-
-                // x = fontMatrix.get(0, 0) * x + fontMatrix.get(1, 0) * y + x;
-                // y = fontMatrix.get(0, 1) * x + fontMatrix.get(1, 1) * y + y;
-                // SAL_WARN("sd.filter", "Char Origin after xform: " << x << ", " << y);
-
-                // basegfx::B2DHomMatrix totalTextMatrix1(fontMatrix);
-                // basegfx::B2DHomMatrix totalTextMatrix2(fontMatrix);
-                // totalTextMatrix1.translate(rRect.X1, rRect.Y1);
-                // totalTextMatrix2.translate(rRect.X2, rRect.Y2);
-
-                // basegfx::B2DHomMatrix corrMatrix;
-                // corrMatrix.scale(1.0, -1.0);
-                // // corrMatrix.translate(0.0, ascent);
-                // totalTextMatrix1 = totalTextMatrix1 * corrMatrix;
-                // totalTextMatrix2 = totalTextMatrix2 * corrMatrix;
-
-                // totalTextMatrix1 *= getCurrentContext().Transformation;
-                // totalTextMatrix2 *= getCurrentContext().Transformation;
-
-                // basegfx::B2DHomMatrix invMatrix(totalTextMatrix1);
-                // basegfx::B2DHomMatrix invPrevMatrix(prevTextMatrix);
-                // invMatrix.invert();
-                // invPrevMatrix.invert();
-                // basegfx::B2DHomMatrix offsetMatrix1(totalTextMatrix1);
-                // basegfx::B2DHomMatrix offsetMatrix2(totalTextMatrix2);
-                // offsetMatrix1 *= invPrevMatrix;
-                // offsetMatrix2 *= invMatrix;
-
-                // double charWidth = offsetMatrix2.get(0, 2);
-                // double prevSpaceWidth = offsetMatrix1.get(0, 2) - prevCharWidth;
-
-                ImportText(aRect.TopLeft(), sText);
-            }
-
-            FPDFText_ClosePage(pTextPage);
-        }
-#endif
-
-        FPDF_ClosePage(pPdfPage);
-    }
-
-    // const sal_uLong nCount(rMtf.GetActionSize());
-
-    for (sal_uLong a(0); a < 0UL; a++)
-    {
         if (pProgrInfo && pActionsToReport)
         {
             (*pActionsToReport)++;
 
-            if (*pActionsToReport >= 16) // update all 16 actions
+                if (*pActionsToReport >= 16)
             {
                 if (!pProgrInfo->ReportActions(*pActionsToReport))
                     break;
@@ -410,6 +245,10 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
             }
         }
     }
+
+        FPDFText_ClosePage(pTextPage);
+        FPDF_ClosePage(pPdfPage);
+    }
 }
 
 void ImpSdrPdfImport::SetupPageScale(const double dPageWidth, const double dPageHeight)
@@ -422,8 +261,6 @@ void ImpSdrPdfImport::SetupPageScale(const double dPageWidth, const double dPage
 
     Size aPageSize(lcl_ToLogic(lcl_PointToPixel(dPageWidth)),
                    lcl_ToLogic(lcl_PointToPixel(dPageHeight)));
-    SAL_WARN("sd.filter", "Logical Page Size: " << aPageSize);
-    SAL_WARN("sd.filter", "Scale Rect: " << maScaleRect);
 
     if (aPageSize.Width() && aPageSize.Height() && (!maScaleRect.IsEmpty()))
     {
@@ -458,23 +295,15 @@ void ImpSdrPdfImport::SetupPageScale(const double dPageWidth, const double dPage
         maScaleY = Fraction(maScaleRect.GetHeight() - 1, aPageSize.Height());
         mbSize = true;
     }
-
-    SAL_WARN("sd.filter", "ScaleX: " << maScaleX << "(" << mfScaleX << "), ScaleY: " << maScaleY
-                                     << "(" << mfScaleY << ")");
 }
 
 size_t ImpSdrPdfImport::DoImport(SdrObjList& rOL, size_t nInsPos, int nPageNumber,
                                  SvdProgressInfo* pProgrInfo)
 {
-    if (pProgrInfo)
-    {
-        // pProgrInfo->SetActionCount(rMtf.GetActionSize());
-    }
-
     sal_uInt32 nActionsToReport(0);
 
     // execute
-    DoLoopActions(pProgrInfo, &nActionsToReport, nPageNumber);
+    DoObjects(pProgrInfo, &nActionsToReport, nPageNumber);
 
     if (pProgrInfo)
     {
@@ -615,7 +444,6 @@ void ImpSdrPdfImport::SetAttributes(SdrObject* pObj, bool bForceTextAttr)
     {
         vcl::Font aFnt(mpVD->GetFont());
         const sal_uInt32 nHeight(FRound(aFnt.GetFontSize().Height() * mfScaleY));
-        SAL_WARN("sd.filter", "Font Height: " << nHeight);
 
         mpTextAttr->Put(SvxFontItem(aFnt.GetFamilyType(), aFnt.GetFamilyName(), aFnt.GetStyleName(),
                                     aFnt.GetPitch(), aFnt.GetCharSet(), EE_CHAR_FONTINFO));
@@ -1027,10 +855,8 @@ void ImpSdrPdfImport::ImportPdfObject(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE
 }
 
 void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage,
-                                 int nPageObjectIndex)
+                                 int /*nPageObjectIndex*/)
 {
-    SAL_WARN("sd.filter", "Got page object FORM: " << nPageObjectIndex);
-
     // Get the form matrix to perform correct translation/scaling of the form sub-objects.
     const Matrix aOldMatrix = mCurMatrix;
 
@@ -1050,9 +876,8 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
 }
 
 void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage,
-                                 int nPageObjectIndex)
+                                 int /*nPageObjectIndex*/)
 {
-    SAL_WARN("sd.filter", "Got page object TEXT: " << nPageObjectIndex);
     float left;
     float bottom;
     float right;
@@ -1063,30 +888,14 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
     }
 
     if (left == right || top == bottom)
-    {
-        SAL_WARN("sd.filter", "Skipping empty TEXT #" << nPageObjectIndex << " left: " << left
-                                                      << ", right: " << right << ", top: " << top
-                                                      << ", bottom: " << bottom);
         return;
-    }
 
     double a, b, c, d, e, f;
     FPDFTextObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
-    // Matrix aTextMatrix(a, b, c, d, e, f);
     Matrix aTextMatrix(mCurMatrix);
-    SAL_WARN("sd.filter", "Got text matrix " << aTextMatrix.toString());
-    SAL_WARN("sd.filter", "Context matrix " << mCurMatrix.toString());
-    // aTextMatrix.Concatinate(mCurMatrix);
-    // SAL_WARN("sd.filter", "Got text matrix concat " << aTextMatrix.toString());
-
-    Point aPos = PointsToLogic(aTextMatrix.e(), aTextMatrix.f());
-    SAL_WARN("sd.filter", "Got TEXT origin: " << aPos);
 
-    const tools::Rectangle aRect2 = PointsToLogic(left, right, top, bottom);
-    SAL_WARN("sd.filter", "Untransformed TEXT Bounds: " << aRect2);
     aTextMatrix.Transform(left, right, top, bottom);
     const tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
-    SAL_WARN("sd.filter", "Transformed TEXT Bounds: " << aRect);
 
     const int nChars = FPDFTextObj_CountChars(pPageObject) * 2;
     std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars + 1]); // + terminating null
@@ -1096,24 +905,18 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
         = FPDFTextObj_GetTextProcessed(pPageObject, pTextPage, 0, nChars, pShortText);
     if (nActualChars <= 0)
     {
-        SAL_WARN("sd.filter", "Got no TEXT");
         return;
     }
 
     OUString sText(pText.get(), nActualChars);
-    SAL_WARN("sd.filter", "Got Text (" << nChars << "): [" << sText << "].");
 
     const double dFontSize = FPDFTextObj_GetFontSize(pPageObject);
     double dFontSizeH = fabs(sqrt2(a, c) * dFontSize);
     double dFontSizeV = fabs(sqrt2(b, d) * dFontSize);
-    SAL_WARN("sd.filter", "Got Font Size: " << dFontSize << ", Scaled Font Size H: " << dFontSizeH
-                                            << ", V: " << dFontSizeV);
     dFontSizeH = lcl_PointToPixel(dFontSizeH);
     dFontSizeV = lcl_PointToPixel(dFontSizeV);
-    SAL_WARN("sd.filter", "Got Pixel Font Size H: " << dFontSizeH << ", V: " << dFontSizeV);
     dFontSizeH = lcl_ToLogic(dFontSizeH);
     dFontSizeV = lcl_ToLogic(dFontSizeV);
-    SAL_WARN("sd.filter", "Got Logic Font Size H: " << dFontSizeH << ", V: " << dFontSizeV);
 
     const Size aFontSize(dFontSizeH, dFontSizeV);
     vcl::Font aFnt = mpVD->GetFont();
@@ -1146,26 +949,18 @@ void ImpSdrPdfImport::ImportText(const Point& rPos, const Size& rSize, const OUS
     vcl::Font aFnt(mpVD->GetFont());
     FontAlign eAlg(aFnt.GetAlignment());
 
-    sal_Int32 nTextWidth = static_cast<sal_Int32>(mpVD->GetTextWidth(rStr) * mfScaleX);
+    // sal_Int32 nTextWidth = static_cast<sal_Int32>(mpVD->GetTextWidth(rStr) * mfScaleX);
     sal_Int32 nTextHeight = static_cast<sal_Int32>(mpVD->GetTextHeight() * mfScaleY);
-    SAL_WARN("sd.filter",
-             "Unscaled text size: " << mpVD->GetTextWidth(rStr) << 'x' << mpVD->GetTextHeight()
-                                    << ", Scaled: " << nTextWidth << 'x' << nTextHeight);
 
     Point aPos(FRound(rPos.X() * mfScaleX + maOfs.X()), FRound(rPos.Y() * mfScaleY + maOfs.Y()));
-    Size bSize(FRound(rSize.Width() * mfScaleX), FRound(rSize.Height() * mfScaleY));
-    Size aSize(nTextWidth, nTextHeight);
+    Size aSize(FRound(rSize.Width() * mfScaleX), FRound(rSize.Height() * mfScaleY));
 
     if (eAlg == ALIGN_BASELINE)
         aPos.AdjustY(-(FRound(aFontMetric.GetAscent() * mfScaleY)));
     else if (eAlg == ALIGN_BOTTOM)
         aPos.AdjustY(-nTextHeight);
 
-    SAL_WARN("sd.filter", "Final POS: " << aPos);
-    SAL_WARN("sd.filter", "Final Text Size: " << aSize);
-    SAL_WARN("sd.filter", "Final Bound Size: " << bSize);
-    tools::Rectangle aTextRect(aPos, bSize);
-    // SAL_WARN("sd.filter", "Text Rect: " << aTextRect);
+    tools::Rectangle aTextRect(aPos, aSize);
     SdrRectObj* pText = new SdrRectObj(*mpModel, OBJ_TEXT, aTextRect);
 
     pText->SetMergedItem(makeSdrTextUpperDistItem(0));
@@ -1229,9 +1024,8 @@ void ImpSdrPdfImport::MapScaling()
     mnMapScalingOfs = nCount;
 }
 
-void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex)
+void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/)
 {
-    SAL_WARN("sd.filter", "Got page object IMAGE: " << nPageObjectIndex);
     std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmapBgra(pPageObject));
     if (!bitmap)
     {
@@ -1255,28 +1049,13 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
 
     switch (format)
     {
-        case FPDFBitmap_Gray:
-            SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
-                                                        << ", height: " << nHeight
-                                                        << ", stride: " << nStride
-                                                        << ", format: Gray");
-            break;
         case FPDFBitmap_BGR:
-            SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight
-                                                      << ", stride: " << nStride
-                                                      << ", format: BGR");
             ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N24BitTcBgr, nHeight, nStride);
             break;
         case FPDFBitmap_BGRx:
-            SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight
-                                                      << ", stride: " << nStride
-                                                      << ", format: BGRx");
             ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcRgba, nHeight, nStride);
             break;
         case FPDFBitmap_BGRA:
-            SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight
-                                                      << ", stride: " << nStride
-                                                      << ", format: BGRA");
             ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcBgra, nHeight, nStride);
             break;
         default:
@@ -1286,18 +1065,6 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
             break;
     }
 
-    // double a, b, c, d, e, f;
-    // if (!FPDFImageObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f))
-    // {
-    //     SAL_WARN("sd.filter", "FAILED to get image Matrix");
-    // }
-    // SAL_WARN("sd.filter", "Got image Matrix: " << a << ", " << b << ", " << c << ", " << d << ", " << e << ", " << f);
-
-    // if (!FPDFImageObj_SetMatrix(pPageObject, a, b, c, d, e, f))
-    // {
-    //     SAL_WARN("sd.filter", "FAILED to set image Matrix");
-    // }
-
     float left;
     float bottom;
     float right;
@@ -1307,12 +1074,9 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
         SAL_WARN("sd.filter", "FAILED to get image bounds");
     }
 
-    SAL_WARN("sd.filter", "Got IMAGE bounds left: " << left << ", right: " << right
-                                                    << ", top: " << top << ", bottom: " << bottom);
     tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
     aRect.AdjustRight(1);
     aRect.AdjustBottom(1);
-    SAL_WARN("sd.filter", "IMAGE Logical Rect FINAL: " << aRect);
 
     SdrGrafObj* pGraf = new SdrGrafObj(*mpModel, Graphic(aBitmap), aRect);
 
@@ -1322,7 +1086,7 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
     InsertObj(pGraf);
 }
 
-void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex)
+void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/)
 {
     double a, b, c, d, e, f;
     FPDFPath_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
@@ -1334,9 +1098,6 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
     std::vector<basegfx::B2DPoint> aBezier;
 
     const int nSegments = FPDFPath_CountSegments(pPageObject);
-    SAL_WARN("sd.filter",
-             "Got page object PATH: " << nPageObjectIndex << " with " << nSegments << " segments.");
-
     for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex)
     {
         FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(pPageObject, nSegmentIndex);
@@ -1356,11 +1117,6 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
             if (bClose)
                 aPoly.setClosed(bClose); // TODO: Review
 
-            SAL_WARN("sd.filter", "Got " << (bClose ? "CLOSE" : "OPEN") << " point (" << fx << ", "
-                                         << fy << ") matrix (" << a << ", " << b << ", " << c
-                                         << ", " << d << ", " << e << ", " << f << ") -> (" << x
-                                         << ", " << y << ")");
-
             Point aPoint = PointsToLogic(x, y);
             x = aPoint.X();
             y = aPoint.Y();
@@ -1369,12 +1125,10 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
             switch (nSegmentType)
             {
                 case FPDF_SEGMENT_LINETO:
-                    SAL_WARN("sd.filter", "Got LineTo Segment.");
                     aPoly.append(basegfx::B2DPoint(x, y));
                     break;
 
                 case FPDF_SEGMENT_BEZIERTO:
-                    SAL_WARN("sd.filter", "Got BezierTo Segment.");
                     aBezier.emplace_back(x, y);
                     if (aBezier.size() == 3)
                     {
@@ -1384,7 +1138,6 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
                     break;
 
                 case FPDF_SEGMENT_MOVETO:
-                    SAL_WARN("sd.filter", "Got MoveTo Segment.");
                     // New Poly.
                     if (aPoly.count() > 0)
                     {
@@ -1423,15 +1176,11 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
     FPDFPath_GetStrokeWidth(pPageObject, &fWidth);
     const double dWidth = 0.5 * fabs(sqrt2(aPathMatrix.a(), aPathMatrix.c()) * fWidth);
     mnLineWidth = lcl_ToLogic(lcl_PointToPixel(dWidth));
-    // mnLineWidth /= 2;
-    SAL_WARN("sd.filter", "Path Stroke Width: " << fWidth << ",  scaled: " << dWidth
-                                                << ", Logical: " << mnLineWidth);
 
     int nFillMode = FPDF_FILLMODE_ALTERNATE;
     FPDF_BOOL bStroke = true;
     if (FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke))
     {
-        SAL_WARN("sd.filter", "Got PATH FillMode: " << nFillMode << ", Storke: " << bStroke);
         if (nFillMode == FPDF_FILLMODE_ALTERNATE)
             mpVD->SetDrawMode(DrawModeFlags::Default);
         else if (nFillMode == FPDF_FILLMODE_WINDING)
@@ -1445,38 +1194,31 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
     unsigned int nB;
     unsigned int nA;
     FPDFPath_GetFillColor(pPageObject, &nR, &nG, &nB, &nA);
-    SAL_WARN("sd.filter", "Got PATH fill color: " << nR << ", " << nG << ", " << nB << ", " << nA);
     mpVD->SetFillColor(Color(nR, nG, nB));
 
     if (bStroke)
     {
         FPDFPath_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA);
-        SAL_WARN("sd.filter",
-                 "Got PATH stroke color: " << nR << ", " << nG << ", " << nB << ", " << nA);
         mpVD->SetLineColor(Color(nR, nG, nB));
     }
     else
         mpVD->SetLineColor(COL_TRANSPARENT);
 
-    // if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))
-
-    SdrPathObj* pPath = new SdrPathObj(*mpModel, OBJ_POLY, aPolyPoly);
-    SetAttributes(pPath);
-    InsertObj(pPath, false);
+    if (!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aPolyPoly)))
+    {
+        SdrPathObj* pPath = new SdrPathObj(*mpModel, OBJ_POLY, aPolyPoly);
+        SetAttributes(pPath);
+        InsertObj(pPath, false);
+    }
 }
 
 Point ImpSdrPdfImport::PointsToLogic(double x, double y) const
 {
     y = correctVertOrigin(y);
-    // SAL_WARN("sd.filter", "Corrected point x: " << x << ", y: " << y);
     x = lcl_PointToPixel(x);
     y = lcl_PointToPixel(y);
 
-    // SAL_WARN("sd.filter", "Pixel point x: " << x << ", y: " << y);
-
     Point aPos(lcl_ToLogic(x), lcl_ToLogic(y));
-    // SAL_WARN("sd.filter", "Logical Pos: " << aPos);
-
     return aPos;
 }
 
@@ -1484,21 +1226,15 @@ tools::Rectangle ImpSdrPdfImport::PointsToLogic(double left, double right, doubl
 {
     top = correctVertOrigin(top);
     bottom = correctVertOrigin(bottom);
-    // SAL_WARN("sd.filter", "Corrected bounds left: " << left << ", right: " << right
-    //                                                 << ", top: " << top << ", bottom: " << bottom);
+
     left = lcl_PointToPixel(left);
     right = lcl_PointToPixel(right);
     top = lcl_PointToPixel(top);
     bottom = lcl_PointToPixel(bottom);
 
-    // SAL_WARN("sd.filter", "Pixel bounds left: " << left << ", right: " << right << ", top: " << top
-    //                                             << ", bottom: " << bottom);
-
     Point aPos(lcl_ToLogic(left), lcl_ToLogic(top));
     Size aSize(lcl_ToLogic(right - left), lcl_ToLogic(bottom - top));
     tools::Rectangle aRect(aPos, aSize);
-    // SAL_WARN("sd.filter", "Logical BBox: " << aRect);
-
     return aRect;
 }
 
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index ac8ce9625364..226051aadd83 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -109,44 +109,34 @@ class ImpSdrPdfImport final
         /// Transform the rectangle (left, right, top, bottom) by this Matrix.
         template <typename T> void Transform(T& left, T& right, T& top, T& bottom)
         {
-            SAL_WARN("sd.filter",
-                     "Transforming: " << left << ", " << right << ", " << top << ", " << bottom);
             T leftTopX = left;
             T leftTopY = top;
             Transform(leftTopX, leftTopY);
-            SAL_WARN("sd.filter", "Left-Top: " << leftTopX << ", " << leftTopY);
 
             T leftBottomX = left;
             T leftBottomY = bottom;
             Transform(leftBottomX, leftBottomY);
-            SAL_WARN("sd.filter", "Left-Bottom: " << leftBottomX << ", " << leftBottomY);
 
             T rightTopX = right;
             T rightTopY = top;
             Transform(rightTopX, rightTopY);
-            SAL_WARN("sd.filter", "Right-Top: " << rightTopX << ", " << rightTopY);
 
             T rightBottomX = right;
             T rightBottomY = bottom;
             Transform(rightBottomX, rightBottomY);
-            SAL_WARN("sd.filter", "Right-Bottom: " << rightBottomX << ", " << rightBottomY);
 
             left = std::min(leftTopX, leftBottomX);
-            SAL_WARN("sd.filter", "left: " << left);
             right = std::max(rightTopX, rightBottomX);
-            SAL_WARN("sd.filter", "right: " << right);
 
             if (top > bottom)
                 top = std::max(leftTopY, rightTopY);
             else
                 top = std::min(leftTopY, rightTopY);
-            SAL_WARN("sd.filter", "top: " << top);
 
             if (top > bottom)
                 bottom = std::max(leftBottomY, rightBottomY);
             else
                 bottom = std::max(leftBottomY, rightBottomY);
-            SAL_WARN("sd.filter", "bottom: " << bottom);
         }
 
         std::string toString() const
@@ -233,7 +223,7 @@ class ImpSdrPdfImport final
     bool CheckLastLineMerge(const basegfx::B2DPolygon& rSrcPoly);
     bool CheckLastPolyLineAndFillMerge(const basegfx::B2DPolyPolygon& rPolyPolygon);
 
-    void DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport, int nPageIndex);
+    void DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport, int nPageIndex);
 
     // Copy assignment is forbidden and not implemented.
     ImpSdrPdfImport(const ImpSdrPdfImport&) = delete;
commit 3e3f4a7240e2e1fd041f68246171f34ce950311f
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 14 19:57:15 2018 -0400

    svx: transform PDF text rectangles while importing
    
    Change-Id: I7675a183bfb691a8783950f33dc34826f91cb768

diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index a4cdaad5ba52..c556b1bb3af6 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1070,17 +1070,23 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
         return;
     }
 
-    const tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
-
     double a, b, c, d, e, f;
     FPDFTextObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
-    Matrix aTextMatrix(a, b, c, d, e, f);
-    aTextMatrix.Concatinate(mCurMatrix);
-    SAL_WARN("sd.filter", "Got font scale matrix (" << a << ", " << b << ", " << c << ", " << d
-                                                    << ", " << e << ", " << f << ')');
-    Point aPos = PointsToLogic(e, f);
+    // Matrix aTextMatrix(a, b, c, d, e, f);
+    Matrix aTextMatrix(mCurMatrix);
+    SAL_WARN("sd.filter", "Got text matrix " << aTextMatrix.toString());
+    SAL_WARN("sd.filter", "Context matrix " << mCurMatrix.toString());
+    // aTextMatrix.Concatinate(mCurMatrix);
+    // SAL_WARN("sd.filter", "Got text matrix concat " << aTextMatrix.toString());
+
+    Point aPos = PointsToLogic(aTextMatrix.e(), aTextMatrix.f());
     SAL_WARN("sd.filter", "Got TEXT origin: " << aPos);
-    SAL_WARN("sd.filter", "Got TEXT Bounds: " << aRect);
+
+    const tools::Rectangle aRect2 = PointsToLogic(left, right, top, bottom);
+    SAL_WARN("sd.filter", "Untransformed TEXT Bounds: " << aRect2);
+    aTextMatrix.Transform(left, right, top, bottom);
+    const tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
+    SAL_WARN("sd.filter", "Transformed TEXT Bounds: " << aRect);
 
     const int nChars = FPDFTextObj_CountChars(pPageObject) * 2;
     std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars + 1]); // + terminating null
@@ -1415,9 +1421,9 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
 
     float fWidth = 1;
     FPDFPath_GetStrokeWidth(pPageObject, &fWidth);
-    const double dWidth = 0.5 * fabs(sqrt2(mCurMatrix.a(), mCurMatrix.c()) * fWidth);
+    const double dWidth = 0.5 * fabs(sqrt2(aPathMatrix.a(), aPathMatrix.c()) * fWidth);
     mnLineWidth = lcl_ToLogic(lcl_PointToPixel(dWidth));
-    mnLineWidth /= 2;
+    // mnLineWidth /= 2;
     SAL_WARN("sd.filter", "Path Stroke Width: " << fWidth << ",  scaled: " << dWidth
                                                 << ", Logical: " << mnLineWidth);
 
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index da54b9a40fa8..ac8ce9625364 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -87,6 +87,7 @@ class ImpSdrPdfImport final
         double d() const { return md; }
         double e() const { return me; }
         double f() const { return mf; }
+
         /// Mutliply this * other.
         void Concatinate(const Matrix& other)
         {
@@ -99,12 +100,63 @@ class ImpSdrPdfImport final
         }
 
         /// Transform the point (x, y) by this Matrix.
-        void Transform(double& x, double& y)
+        template <typename T> void Transform(T& x, T& y)
         {
             x = ma * x + mc * y + me;
             y = mb * x + md * y + mf;
         }
 
+        /// Transform the rectangle (left, right, top, bottom) by this Matrix.
+        template <typename T> void Transform(T& left, T& right, T& top, T& bottom)
+        {
+            SAL_WARN("sd.filter",
+                     "Transforming: " << left << ", " << right << ", " << top << ", " << bottom);
+            T leftTopX = left;
+            T leftTopY = top;
+            Transform(leftTopX, leftTopY);
+            SAL_WARN("sd.filter", "Left-Top: " << leftTopX << ", " << leftTopY);
+
+            T leftBottomX = left;
+            T leftBottomY = bottom;
+            Transform(leftBottomX, leftBottomY);
+            SAL_WARN("sd.filter", "Left-Bottom: " << leftBottomX << ", " << leftBottomY);
+
+            T rightTopX = right;
+            T rightTopY = top;
+            Transform(rightTopX, rightTopY);
+            SAL_WARN("sd.filter", "Right-Top: " << rightTopX << ", " << rightTopY);
+
+            T rightBottomX = right;
+            T rightBottomY = bottom;
+            Transform(rightBottomX, rightBottomY);
+            SAL_WARN("sd.filter", "Right-Bottom: " << rightBottomX << ", " << rightBottomY);
+
+            left = std::min(leftTopX, leftBottomX);
+            SAL_WARN("sd.filter", "left: " << left);
+            right = std::max(rightTopX, rightBottomX);
+            SAL_WARN("sd.filter", "right: " << right);
+
+            if (top > bottom)
+                top = std::max(leftTopY, rightTopY);
+            else
+                top = std::min(leftTopY, rightTopY);
+            SAL_WARN("sd.filter", "top: " << top);
+
+            if (top > bottom)
+                bottom = std::max(leftBottomY, rightBottomY);
+            else
+                bottom = std::max(leftBottomY, rightBottomY);
+            SAL_WARN("sd.filter", "bottom: " << bottom);
+        }
+
+        std::string toString() const
+        {
+            std::ostringstream oss;
+            oss << '(' << ma << ", " << mb << ", " << mc << ", " << md << ", " << me << ", " << mf
+                << ')';
+            return oss.str();
+        }
+
     private:
         double ma, mb, mc, md, me, mf;
     };
commit 7181931acd7d7612eb26d7fc43feb743a3972a08
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Apr 22 17:21:30 2018 -0400

    svx: support no fill and no stroke paths in PDF import
    
    Change-Id: Ida5daa71d469805fd52e08e804fb9fa182d7d008

diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 1350a61acec4..a4cdaad5ba52 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1415,11 +1415,24 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
 
     float fWidth = 1;
     FPDFPath_GetStrokeWidth(pPageObject, &fWidth);
-    SAL_WARN("sd.filter", "Path Stroke Width: " << fWidth);
-    const double dWidth = fabs(sqrt2(a, c) * fWidth);
-    SAL_WARN("sd.filter", "Path Stroke Width scaled: " << dWidth);
+    const double dWidth = 0.5 * fabs(sqrt2(mCurMatrix.a(), mCurMatrix.c()) * fWidth);
     mnLineWidth = lcl_ToLogic(lcl_PointToPixel(dWidth));
     mnLineWidth /= 2;
+    SAL_WARN("sd.filter", "Path Stroke Width: " << fWidth << ",  scaled: " << dWidth
+                                                << ", Logical: " << mnLineWidth);
+
+    int nFillMode = FPDF_FILLMODE_ALTERNATE;
+    FPDF_BOOL bStroke = true;
+    if (FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke))
+    {
+        SAL_WARN("sd.filter", "Got PATH FillMode: " << nFillMode << ", Storke: " << bStroke);
+        if (nFillMode == FPDF_FILLMODE_ALTERNATE)
+            mpVD->SetDrawMode(DrawModeFlags::Default);
+        else if (nFillMode == FPDF_FILLMODE_WINDING)
+            mpVD->SetDrawMode(DrawModeFlags::Default);
+        else
+            mpVD->SetDrawMode(DrawModeFlags::NoFill);
+    }
 
     unsigned int nR;
     unsigned int nG;
@@ -1429,15 +1442,15 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
     SAL_WARN("sd.filter", "Got PATH fill color: " << nR << ", " << nG << ", " << nB << ", " << nA);
     mpVD->SetFillColor(Color(nR, nG, nB));
 
-    FPDFPath_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA);
-    SAL_WARN("sd.filter",
-             "Got PATH stroke color: " << nR << ", " << nG << ", " << nB << ", " << nA);
-    mpVD->SetLineColor(Color(nR, nG, nB));
-
-    // int nFillMode = 0; // No fill.
-    // bool bStroke = false;
-    // FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke);
-    // mpVD->Setstroke(Color(r, g, b));
+    if (bStroke)
+    {
+        FPDFPath_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA);
+        SAL_WARN("sd.filter",
+                 "Got PATH stroke color: " << nR << ", " << nG << ", " << nB << ", " << nA);
+        mpVD->SetLineColor(Color(nR, nG, nB));
+    }
+    else
+        mpVD->SetLineColor(COL_TRANSPARENT);
 
     // if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))
 
commit 42c7a7607562bc7afc06cdb3ccb7b6293cf4f10c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Apr 22 17:01:18 2018 -0400

    svx: support sub-paths in PDF import
    
    Change-Id: Ibcfd30383db6846e791aea7609ab196c4f3f2da4

diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 1946b61c29bb..1350a61acec4 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1318,17 +1318,19 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
 
 void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex)
 {
-    SAL_WARN("sd.filter", "Got page object PATH: " << nPageObjectIndex);
-
     double a, b, c, d, e, f;
     FPDFPath_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
     Matrix aPathMatrix(a, b, c, d, e, f);
     aPathMatrix.Concatinate(mCurMatrix);
 
+    basegfx::B2DPolyPolygon aPolyPoly;
     basegfx::B2DPolygon aPoly;
     std::vector<basegfx::B2DPoint> aBezier;
 
     const int nSegments = FPDFPath_CountSegments(pPageObject);
+    SAL_WARN("sd.filter",
+             "Got page object PATH: " << nPageObjectIndex << " with " << nSegments << " segments.");
+
     for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex)
     {
         FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(pPageObject, nSegmentIndex);
@@ -1343,16 +1345,16 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
 
             double x = fx;
             double y = fy;
-            SAL_WARN("sd.filter", "Got point (" << x << ", " << y << ") matrix (" << a << ", " << b
-                                                << ", " << c << ", " << d << ", " << e << ", " << f
-                                                << ')');
             aPathMatrix.Transform(x, y);
-
             const bool bClose = FPDFPathSegment_GetClose(pPathSegment);
             if (bClose)
                 aPoly.setClosed(bClose); // TODO: Review
-            SAL_WARN("sd.filter",
-                     "Point corrected (" << x << ", " << y << "): " << (bClose ? "CLOSE" : "OPEN"));
+
+            SAL_WARN("sd.filter", "Got " << (bClose ? "CLOSE" : "OPEN") << " point (" << fx << ", "
+                                         << fy << ") matrix (" << a << ", " << b << ", " << c
+                                         << ", " << d << ", " << e << ", " << f << ") -> (" << x
+                                         << ", " << y << ")");
+
             Point aPoint = PointsToLogic(x, y);
             x = aPoint.X();
             y = aPoint.Y();
@@ -1377,6 +1379,13 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
 
                 case FPDF_SEGMENT_MOVETO:
                     SAL_WARN("sd.filter", "Got MoveTo Segment.");
+                    // New Poly.
+                    if (aPoly.count() > 0)
+                    {
+                        aPolyPoly.append(aPoly, 1);
+                        aPoly.clear();
+                    }
+
                     aPoly.append(basegfx::B2DPoint(x, y));
                     break;
 
@@ -1394,9 +1403,15 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
         aBezier.clear();
     }
 
+    if (aPoly.count() > 0)
+    {
+        aPolyPoly.append(aPoly, 1);
+        aPoly.clear();
+    }
+
     const basegfx::B2DHomMatrix aTransform(
         basegfx::utils::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
-    aPoly.transform(aTransform);
+    aPolyPoly.transform(aTransform);
 
     float fWidth = 1;
     FPDFPath_GetStrokeWidth(pPageObject, &fWidth);
@@ -1426,7 +1441,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
 
     // if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))
 
-    SdrPathObj* pPath = new SdrPathObj(*mpModel, OBJ_POLY, basegfx::B2DPolyPolygon(aPoly));
+    SdrPathObj* pPath = new SdrPathObj(*mpModel, OBJ_POLY, aPolyPoly);
     SetAttributes(pPath);
     InsertObj(pPath, false);
 }
commit 67bdfba807b257ce977d61239568877f2bff1429
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Apr 22 10:48:51 2018 -0400

    svx: import processed PDF text
    
    Some PDFs don't include spaces in the text.
    Instead, they rely on the explicit positioning
    of each character to render visually separated words.
    Latex seems to be prone to this approach, though not
    exclusively.
    
    Luckily, PDFium does process text and inserts
    "generated" spaces where necessary, which is what
    we retrieve and use as the text string while importing.
    
    Change-Id: Ic21fe6c8416ecaba66f06b6260f1d6b040ff12af

diff --git a/external/pdfium/0012-svx-import-processed-PDF-text.patch.2 b/external/pdfium/0012-svx-import-processed-PDF-text.patch.2
new file mode 100644
index 000000000000..cae9ec808aba
--- /dev/null
+++ b/external/pdfium/0012-svx-import-processed-PDF-text.patch.2
@@ -0,0 +1,148 @@
+From 7e8ecec81f102993e3fe73256415dcf049c09e29 Mon Sep 17 00:00:00 2001
+From: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
+Date: Tue, 5 Jun 2018 11:35:39 +0200
+Subject: [PATCH 12/14] svx: import processed PDF text
+
+---
+ pdfium/core/fpdftext/cpdf_textpage.cpp | 29 ++++++++++++++++++++++++
+ pdfium/core/fpdftext/cpdf_textpage.h   |  2 ++
+ pdfium/fpdfsdk/fpdf_editpage.cpp       | 41 ++++++++++++++++++++++++++++++++++
+ pdfium/public/fpdf_edit.h              | 13 +++++++++++
+ 4 files changed, 85 insertions(+)
+
+diff --git a/pdfium/core/fpdftext/cpdf_textpage.cpp b/pdfium/core/fpdftext/cpdf_textpage.cpp
+index 5690698..4d7c48a 100644
+--- a/pdfium/core/fpdftext/cpdf_textpage.cpp
++++ b/pdfium/core/fpdftext/cpdf_textpage.cpp
+@@ -1464,3 +1464,32 @@ Optional<PAGECHAR_INFO> CPDF_TextPage::GenerateCharInfo(wchar_t unicode) {
+                                  info.m_Origin.x, info.m_Origin.y);
+   return info;
+ }
++
++WideString CPDF_TextPage::GetTextObjectText(CPDF_TextObject* pTextObj)
++{
++  if (!m_bIsParsed)
++    return WideString();
++
++  float posy = 0;
++  bool IsContainPreChar = false;
++  bool IsAddLineFeed = false;
++  WideString strText;
++  for (const auto& charinfo : m_CharList) {
++    if (charinfo.m_pTextObj == pTextObj) {
++      IsContainPreChar = true;
++      IsAddLineFeed = false;
++      if (charinfo.m_Unicode)
++        strText += charinfo.m_Unicode;
++    } else if (charinfo.m_Unicode == 32) {

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list