vcl/Library_vcl.mk                         |    1 +
 vcl/inc/graphic/VectorGraphicLoader.hxx    |   24 ++++++++++++++++++++++++
 vcl/source/gdi/impgraph.cxx                |   29 ++++++++++++++++++++++-------
 vcl/source/graphic/VectorGraphicLoader.cxx |   26 ++++++++++++++++++++++++++
 4 files changed, 73 insertions(+), 7 deletions(-)

New commits:
commit 9ae99dd8bcb682ca86e51ea89744f3a1c1de1d03
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Jan 1 23:44:57 2021 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jan 22 07:48:28 2021 +0100

    vcl: create PDF from DataContainer, use that when swapping in
    
    VectorGraphicLoader is a set of functions that "load" a vector
    graphic (starting with PDF) from a BinaryDataContainer. Usually
    this only needs to create VectorGraphicData and set the correct
    type, as loading will be done on-demand.
    
    Use the VectorGraphicLoader function when swapping-in so this is
    an alternative to calling LoadNative on GfxLink, which loads
    into a new Graphic via. GraphicFilter, which is something we
    really want to avoid.
    
    Change-Id: If529c8ddca2b31660da4ea28d8e75bb20bf3c778
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109598
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index e58e6b8b3d17..a27af8f6d031 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -337,6 +337,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/graphic/UnoGraphicProvider \
     vcl/source/graphic/UnoGraphicTransformer \
     vcl/source/graphic/VectorGraphicSearch \
+    vcl/source/graphic/VectorGraphicLoader \
     vcl/source/bitmap/impvect \
     vcl/source/bitmap/bitmap \
     vcl/source/bitmap/BitmapEx \
diff --git a/vcl/inc/graphic/VectorGraphicLoader.hxx 
b/vcl/inc/graphic/VectorGraphicLoader.hxx
new file mode 100644
index 000000000000..b6f38120885c
--- /dev/null
+++ b/vcl/inc/graphic/VectorGraphicLoader.hxx
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <tools/stream.hxx>
+#include <vcl/vectorgraphicdata.hxx>
+#include <vcl/BinaryDataContainer.hxx>
+#include <memory>
+
+namespace vcl
+{
+std::shared_ptr<VectorGraphicData>
+loadPdfFromDataContainer(BinaryDataContainer const& rDataContainer);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 794d5ca68a22..6fe065896d3f 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -46,6 +46,7 @@
 #include <vcl/gdimetafiletools.hxx>
 #include <vcl/TypeSerializer.hxx>
 #include <vcl/pdfread.hxx>
+#include <graphic/VectorGraphicLoader.hxx>
 
 #define GRAPHIC_MTFTOBMP_MAXEXT     2048
 #define GRAPHIC_STREAMBUFSIZE       8192UL
@@ -1422,16 +1423,30 @@ bool ImpGraphic::swapIn()
     }
     else if (mpGfxLink && mpGfxLink->IsNative())
     {
-        Graphic aGraphic;
-        if (!mpGfxLink->LoadNative(aGraphic))
-            return false;
+        if (mpGfxLink->GetType() == GfxLinkType::NativePdf)
+        {
+            maVectorGraphicData = 
vcl::loadPdfFromDataContainer(mpGfxLink->getDataContainer());
 
-        ImpGraphic* pImpGraphic = aGraphic.ImplGetImpGraphic();
+            // Set to 0, to force recalculation
+            mnSizeBytes = 0;
+            mnChecksum = 0;
 
-        if (meType != pImpGraphic->meType)
-            return false;
+            restoreFromSwapInfo();
 
-        updateFromLoadedGraphic(pImpGraphic);
+            mbSwapOut = false;
+        }
+        else
+        {
+            Graphic aGraphic;
+            if (!mpGfxLink->LoadNative(aGraphic))
+                return false;
+
+            ImpGraphic* pImpGraphic = aGraphic.ImplGetImpGraphic();
+            if (meType != pImpGraphic->meType)
+                return false;
+
+            updateFromLoadedGraphic(pImpGraphic);
+        }
 
         maLastUsed = std::chrono::high_resolution_clock::now();
         bReturn = true;
diff --git a/vcl/source/graphic/VectorGraphicLoader.cxx 
b/vcl/source/graphic/VectorGraphicLoader.cxx
new file mode 100644
index 000000000000..988c3db803be
--- /dev/null
+++ b/vcl/source/graphic/VectorGraphicLoader.cxx
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <tools/stream.hxx>
+#include <graphic/VectorGraphicLoader.hxx>
+
+namespace vcl
+{
+std::shared_ptr<VectorGraphicData>
+loadPdfFromDataContainer(BinaryDataContainer const& rDataContainer)
+{
+    if (rDataContainer.isEmpty())
+        return std::shared_ptr<VectorGraphicData>();
+
+    return std::make_shared<VectorGraphicData>(rDataContainer, 
VectorGraphicDataType::Pdf);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to