Rebased ref, commits from common ancestor:
commit 9f430c6147effeeddd373176155e2769db66ff26
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jun 28 22:27:37 2022 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:01 2022 +0200

    svx: move SdrDropMarkerOverlay into it's own file
    
    Change-Id: Ia09dcba2b7b469912f4f3b72a3cc60ded05a03ca

diff --git a/include/svx/sdr/view/DropMarkerOverlay.hxx 
b/include/svx/sdr/view/DropMarkerOverlay.hxx
new file mode 100644
index 000000000000..03f1419c7413
--- /dev/null
+++ b/include/svx/sdr/view/DropMarkerOverlay.hxx
@@ -0,0 +1,42 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <svx/svxdllapi.h>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <svx/svdview.hxx>
+#include <svx/sdr/overlay/overlaymanager.hxx>
+
+// helper class for all D&D overlays
+class SVXCORE_DLLPUBLIC SdrDropMarkerOverlay
+{
+    // The OverlayObjects
+    sdr::overlay::OverlayObjectList maObjects;
+
+    void ImplCreateOverlays(const SdrView& rView, const 
basegfx::B2DPolyPolygon& rLinePolyPolygon);
+
+public:
+    SdrDropMarkerOverlay(const SdrView& rView, const SdrObject& rObject);
+    SdrDropMarkerOverlay(const SdrView& rView, const tools::Rectangle& 
rRectangle);
+    SdrDropMarkerOverlay(const SdrView& rView, const Point& rStart, const 
Point& rEnd);
+    ~SdrDropMarkerOverlay();
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/svdview.hxx b/include/svx/svdview.hxx
index 03afde95b00e..1e2627dc8807 100644
--- a/include/svx/svdview.hxx
+++ b/include/svx/svdview.hxx
@@ -52,24 +52,6 @@
 
 namespace sdr::contact { class ObjectContact; }
 
-// helper class for all D&D overlays
-class SVXCORE_DLLPUBLIC SdrDropMarkerOverlay
-{
-    // The OverlayObjects
-    sdr::overlay::OverlayObjectList maObjects;
-
-    void ImplCreateOverlays(
-        const SdrView& rView,
-        const basegfx::B2DPolyPolygon& rLinePolyPolygon);
-
-public:
-    SdrDropMarkerOverlay(const SdrView& rView, const SdrObject& rObject);
-    SdrDropMarkerOverlay(const SdrView& rView, const tools::Rectangle& 
rRectangle);
-    SdrDropMarkerOverlay(const SdrView& rView, const Point& rStart, const 
Point& rEnd);
-    ~SdrDropMarkerOverlay();
-};
-
-
 class SVXCORE_DLLPUBLIC SdrView : public SdrCreateView, public tools::WeakBase
 {
     friend class SdrPageView;
diff --git a/sc/source/ui/inc/drawview.hxx b/sc/source/ui/inc/drawview.hxx
index 816a3428aacf..669f12969ba6 100644
--- a/sc/source/ui/inc/drawview.hxx
+++ b/sc/source/ui/inc/drawview.hxx
@@ -22,6 +22,7 @@
 #include <svx/fmview.hxx>
 
 #include <global.hxx>
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
 
 namespace com::sun::star::datatransfer { class XTransferable; }
 
diff --git a/sd/source/ui/inc/View.hxx b/sd/source/ui/inc/View.hxx
index 4e530e3f9227..d26c5b261c38 100644
--- a/sd/source/ui/inc/View.hxx
+++ b/sd/source/ui/inc/View.hxx
@@ -26,6 +26,7 @@
 #include <svx/fmview.hxx>
 #include <svx/svdpage.hxx>
 #include <vcl/idle.hxx>
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
 
 #include "smarttag.hxx"
 #include "fusearch.hxx"
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 5cacdf82ebcc..440ef4dc69aa 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -463,6 +463,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
     svx/source/unodraw/unoshtxt \
     svx/source/unodraw/unottabl \
     svx/source/unodraw/XPropertyTable \
+    svx/source/view/DropMarkerOverlay \
     svx/source/xml/xmleohlp \
     svx/source/xml/xmlexport \
     svx/source/xml/xmlgrhlp \
diff --git a/svx/source/svdraw/svdview.cxx b/svx/source/svdraw/svdview.cxx
index 7dc8ae174fc5..48850c6974c2 100644
--- a/svx/source/svdraw/svdview.cxx
+++ b/svx/source/svdraw/svdview.cxx
@@ -38,8 +38,6 @@
 #include <svx/svddrgmt.hxx>
 #include <svx/svdotable.hxx>
 #include <tools/debug.hxx>
-#include <svx/sdr/overlay/overlaypolypolygon.hxx>
-#include <svx/sdr/overlay/overlaymanager.hxx>
 #include <svx/sdrpaintwindow.hxx>
 #include <svx/sdrpagewindow.hxx>
 #include <svx/sdrhittesthelper.hxx>
@@ -51,70 +49,7 @@
 #include <vcl/ptrstyle.hxx>
 #include <vcl/window.hxx>
 #include <comphelper/lok.hxx>
-
-// helper class for all D&D overlays
-
-void SdrDropMarkerOverlay::ImplCreateOverlays(
-    const SdrView& rView,
-    const basegfx::B2DPolyPolygon& rLinePolyPolygon)
-{
-    for(sal_uInt32 a(0); a < rView.PaintWindowCount(); a++)
-    {
-        SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
-        const rtl::Reference< sdr::overlay::OverlayManager >& xTargetOverlay = 
pCandidate->GetOverlayManager();
-
-        if (xTargetOverlay.is())
-        {
-            std::unique_ptr<sdr::overlay::OverlayPolyPolygonStripedAndFilled> 
pNew(new sdr::overlay::OverlayPolyPolygonStripedAndFilled(
-                rLinePolyPolygon));
-
-            xTargetOverlay->add(*pNew);
-            maObjects.append(std::move(pNew));
-        }
-    }
-}
-
-SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const 
SdrObject& rObject)
-{
-    ImplCreateOverlays(
-        rView,
-        rObject.TakeXorPoly());
-}
-
-SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const 
tools::Rectangle& rRectangle)
-{
-    basegfx::B2DPolygon aB2DPolygon;
-
-    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()));
-    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Right(), 
rRectangle.Top()));
-    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Right(), 
rRectangle.Bottom()));
-    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Left(), 
rRectangle.Bottom()));
-    aB2DPolygon.setClosed(true);
-
-    ImplCreateOverlays(
-        rView,
-        basegfx::B2DPolyPolygon(aB2DPolygon));
-}
-
-SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const Point& 
rStart, const Point& rEnd)
-{
-    basegfx::B2DPolygon aB2DPolygon;
-
-    aB2DPolygon.append(basegfx::B2DPoint(rStart.X(), rStart.Y()));
-    aB2DPolygon.append(basegfx::B2DPoint(rEnd.X(), rEnd.Y()));
-    aB2DPolygon.setClosed(true);
-
-    ImplCreateOverlays(
-        rView,
-        basegfx::B2DPolyPolygon(aB2DPolygon));
-}
-
-SdrDropMarkerOverlay::~SdrDropMarkerOverlay()
-{
-    // The OverlayObjects are cleared using the destructor of 
OverlayObjectList.
-    // That destructor calls clear() at the list which removes all objects 
from the
-    // OverlayManager and deletes them.
-}
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
 
 SdrView::SdrView(
     SdrModel& rSdrModel,
diff --git a/svx/source/view/DropMarkerOverlay.cxx 
b/svx/source/view/DropMarkerOverlay.cxx
new file mode 100644
index 000000000000..3b0c7ee873b9
--- /dev/null
+++ b/svx/source/view/DropMarkerOverlay.cxx
@@ -0,0 +1,84 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
+#include <svx/svdobj.hxx>
+#include <svx/sdr/overlay/overlaypolypolygon.hxx>
+#include <svx/sdrpaintwindow.hxx>
+
+// helper class for all D&D overlays
+
+void SdrDropMarkerOverlay::ImplCreateOverlays(const SdrView& rView,
+                                              const basegfx::B2DPolyPolygon& 
rLinePolyPolygon)
+{
+    for (sal_uInt32 a(0); a < rView.PaintWindowCount(); a++)
+    {
+        SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
+        const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay
+            = pCandidate->GetOverlayManager();
+
+        if (xTargetOverlay.is())
+        {
+            std::unique_ptr<sdr::overlay::OverlayPolyPolygonStripedAndFilled> 
pNew(
+                new 
sdr::overlay::OverlayPolyPolygonStripedAndFilled(rLinePolyPolygon));
+
+            xTargetOverlay->add(*pNew);
+            maObjects.append(std::move(pNew));
+        }
+    }
+}
+
+SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const 
SdrObject& rObject)
+{
+    ImplCreateOverlays(rView, rObject.TakeXorPoly());
+}
+
+SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const 
tools::Rectangle& rRectangle)
+{
+    basegfx::B2DPolygon aB2DPolygon;
+
+    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()));
+    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Right(), 
rRectangle.Top()));
+    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Right(), 
rRectangle.Bottom()));
+    aB2DPolygon.append(basegfx::B2DPoint(rRectangle.Left(), 
rRectangle.Bottom()));
+    aB2DPolygon.setClosed(true);
+
+    ImplCreateOverlays(rView, basegfx::B2DPolyPolygon(aB2DPolygon));
+}
+
+SdrDropMarkerOverlay::SdrDropMarkerOverlay(const SdrView& rView, const Point& 
rStart,
+                                           const Point& rEnd)
+{
+    basegfx::B2DPolygon aB2DPolygon;
+
+    aB2DPolygon.append(basegfx::B2DPoint(rStart.X(), rStart.Y()));
+    aB2DPolygon.append(basegfx::B2DPoint(rEnd.X(), rEnd.Y()));
+    aB2DPolygon.setClosed(true);
+
+    ImplCreateOverlays(rView, basegfx::B2DPolyPolygon(aB2DPolygon));
+}
+
+SdrDropMarkerOverlay::~SdrDropMarkerOverlay()
+{
+    // The OverlayObjects are cleared using the destructor of 
OverlayObjectList.
+    // That destructor calls clear() at the list which removes all objects 
from the
+    // OverlayManager and deletes them.
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/frmedt/feshview.cxx 
b/sw/source/core/frmedt/feshview.cxx
index 8369004ac3c5..d8efce1a9048 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -43,6 +43,7 @@
 #include <svx/svdpage.hxx>
 #include <svx/svdpagv.hxx>
 #include <svx/dialmgr.hxx>
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
 #include <tools/globname.hxx>
 #include <sot/exchange.hxx>
 #include <IDocumentDrawModelAccess.hxx>
diff --git a/sw/source/core/frmedt/fews.cxx b/sw/source/core/frmedt/fews.cxx
index 0e9a0a2ca18e..130b4b0b0291 100644
--- a/sw/source/core/frmedt/fews.cxx
+++ b/sw/source/core/frmedt/fews.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <svx/svdobj.hxx>
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
 #include <osl/diagnose.h>
 #include <comphelper/lok.hxx>
 #include <init.hxx>
diff --git a/sw/source/uibase/docvw/edtdd.cxx b/sw/source/uibase/docvw/edtdd.cxx
index 8f86aa1d310a..d697a65334b6 100644
--- a/sw/source/uibase/docvw/edtdd.cxx
+++ b/sw/source/uibase/docvw/edtdd.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <svx/svdview.hxx>
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
 #include <editeng/outliner.hxx>
 #include <svx/svdobj.hxx>
 #include <sot/exchange.hxx>
diff --git a/sw/source/uibase/docvw/edtwin.cxx 
b/sw/source/uibase/docvw/edtwin.cxx
index 420da9d0b295..0c4d98108916 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -58,6 +58,7 @@
 #include <svx/svdview.hxx>
 #include <svx/svdhdl.hxx>
 #include <svx/svdoutl.hxx>
+#include <svx/sdr/view/DropMarkerOverlay.hxx>
 #include <editeng/editeng.hxx>
 #include <editeng/editview.hxx>
 #include <editeng/svxacorr.hxx>
commit 3e1dcd205c1947dc6d53e3640daa53cbcc7c19e0
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jun 28 21:34:57 2022 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:00 2022 +0200

    svx: extract SdrViewEvent into own header file
    
    Change-Id: Id1b1a8adef4ae779b5fb456dcb46783e0cbb9d08

diff --git a/include/svx/sdr/view/ViewEvent.hxx 
b/include/svx/sdr/view/ViewEvent.hxx
new file mode 100644
index 000000000000..dbc408a8d639
--- /dev/null
+++ b/include/svx/sdr/view/ViewEvent.hxx
@@ -0,0 +1,82 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <svx/sdr/view/Enums.hxx>
+#include <vcl/event.hxx>
+#include <svx/svdmrkv.hxx>
+
+class SvxURLField;
+
+// helper class SdrViewEvent
+struct SVXCORE_DLLPUBLIC SdrViewEvent
+{
+    SdrHdl* mpHdl;
+    SdrObject* mpObj;
+    SdrObject* mpRootObj; // mark this when SdrBeginTextEdit is executed
+    SdrPageView* mpPV;
+    const SvxURLField* mpURLField;
+
+    Point maLogicPos;
+    SdrHitKind meHit;
+    SdrEventKind meEvent;
+
+    sal_uInt16 mnMouseClicks;
+    MouseEventModifiers mnMouseMode;
+    sal_uInt16 mnMouseCode;
+    sal_uInt16 mnHlplIdx;
+    sal_uInt16 mnGlueId;
+
+    bool mbMouseDown : 1;
+    bool mbMouseUp : 1;
+    bool mbIsAction : 1; // Action is active
+    bool mbIsTextEdit : 1; // TextEdit runs currently
+    bool mbAddMark : 1;
+    bool mbUnmark : 1;
+    bool mbPrevNextMark : 1;
+    bool mbMarkPrev : 1;
+
+public:
+    SdrViewEvent()
+        : mpHdl(nullptr)
+        , mpObj(nullptr)
+        , mpRootObj(nullptr)
+        , mpPV(nullptr)
+        , mpURLField(nullptr)
+        , meHit(SdrHitKind::NONE)
+        , meEvent(SdrEventKind::NONE)
+        , mnMouseClicks(0)
+        , mnMouseMode(MouseEventModifiers::NONE)
+        , mnMouseCode(0)
+        , mnHlplIdx(0)
+        , mnGlueId(0)
+        , mbMouseDown(false)
+        , mbMouseUp(false)
+        , mbIsAction(false)
+        , mbIsTextEdit(false)
+        , mbAddMark(false)
+        , mbUnmark(false)
+        , mbPrevNextMark(false)
+        , mbMarkPrev(false)
+    {
+    }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/svdview.hxx b/include/svx/svdview.hxx
index ae555aaab03d..03afde95b00e 100644
--- a/include/svx/svdview.hxx
+++ b/include/svx/svdview.hxx
@@ -26,6 +26,7 @@
 #include <svtools/accessibilityoptions.hxx>
 #include <svx/svxdllapi.h>
 #include <svx/sdr/view/Enums.hxx>
+#include <svx/sdr/view/ViewEvent.hxx>
 #include <svx/svdcrtv.hxx>
 #include <vcl/event.hxx>
 #include <unotools/options.hxx>
@@ -49,41 +50,8 @@
 //         SdrCreateView   CrtV   Action
 //         SdrView         View
 
-class SvxURLField;
 namespace sdr::contact { class ObjectContact; }
 
-// helper class SdrViewEvent
-struct SVXCORE_DLLPUBLIC SdrViewEvent
-{
-    SdrHdl* mpHdl;
-    SdrObject* mpObj;
-    SdrObject* mpRootObj; // mark this when SdrBeginTextEdit is executed
-    SdrPageView* mpPV;
-    const SvxURLField* mpURLField;
-
-    Point maLogicPos;
-    SdrHitKind meHit;
-    SdrEventKind meEvent;
-
-    sal_uInt16 mnMouseClicks;
-    MouseEventModifiers mnMouseMode;
-    sal_uInt16 mnMouseCode;
-    sal_uInt16 mnHlplIdx;
-    sal_uInt16 mnGlueId;
-
-    bool mbMouseDown : 1;
-    bool mbMouseUp : 1;
-    bool mbIsAction : 1;       // Action is active
-    bool mbIsTextEdit : 1;     // TextEdit runs currently
-    bool mbAddMark : 1;
-    bool mbUnmark : 1;
-    bool mbPrevNextMark : 1;
-    bool mbMarkPrev : 1;
-
-public:
-    SdrViewEvent();
-};
-
 // helper class for all D&D overlays
 class SVXCORE_DLLPUBLIC SdrDropMarkerOverlay
 {
diff --git a/svx/source/svdraw/svdview.cxx b/svx/source/svdraw/svdview.cxx
index 6179451b9596..7dc8ae174fc5 100644
--- a/svx/source/svdraw/svdview.cxx
+++ b/svx/source/svdraw/svdview.cxx
@@ -46,36 +46,12 @@
 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
 #include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
 #include <svx/sdr/contact/objectcontactofpageview.hxx>
+#include <svx/sdr/view/ViewEvent.hxx>
 #include <sal/log.hxx>
 #include <vcl/ptrstyle.hxx>
 #include <vcl/window.hxx>
 #include <comphelper/lok.hxx>
 
-
-SdrViewEvent::SdrViewEvent()
-    : mpHdl(nullptr),
-      mpObj(nullptr),
-      mpRootObj(nullptr),
-      mpPV(nullptr),
-      mpURLField(nullptr),
-      meHit(SdrHitKind::NONE),
-      meEvent(SdrEventKind::NONE),
-      mnMouseClicks(0),
-      mnMouseMode(MouseEventModifiers::NONE),
-      mnMouseCode(0),
-      mnHlplIdx(0),
-      mnGlueId(0),
-      mbMouseDown(false),
-      mbMouseUp(false),
-      mbIsAction(false),
-      mbIsTextEdit(false),
-      mbAddMark(false),
-      mbUnmark(false),
-      mbPrevNextMark(false),
-      mbMarkPrev(false)
-{
-}
-
 // helper class for all D&D overlays
 
 void SdrDropMarkerOverlay::ImplCreateOverlays(
commit a84709c340be0c015ab6cf009bb5868bbf77d633
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jun 28 20:32:15 2022 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:00 2022 +0200

    svx: extract common view enums into Enum.hxx
    
    Change-Id: Ic365a45de77aee5659a5869777b27cb8faa53f6d

diff --git a/include/svx/sdr/view/Enums.hxx b/include/svx/sdr/view/Enums.hxx
new file mode 100644
index 000000000000..778e7176d5ae
--- /dev/null
+++ b/include/svx/sdr/view/Enums.hxx
@@ -0,0 +1,66 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+enum class SdrViewContext
+{
+    Standard,
+    PointEdit,
+    GluePointEdit,
+    Graphic,
+    Media,
+    Table
+};
+
+enum class SdrEventKind
+{
+    NONE,
+    TextEdit,
+    MoveAction,
+    EndAction,
+    BackAction,
+    EndCreate,
+    EndDrag,
+    MarkObj,
+    MarkPoint,
+    MarkGluePoint,
+    BeginMark,
+    BeginInsertObjPoint,
+    EndInsertObjPoint,
+    BeginInsertGluePoint,
+    BeginDragHelpline,
+    BeginDragObj,
+    BeginCreateObj,
+    BeginMacroObj,
+    BeginTextEdit,
+    EndMark,
+    BrkMark,
+    ExecuteUrl
+};
+
+/* for PickAnything() */
+enum class SdrMouseEventKind
+{
+    BUTTONDOWN = 1,
+    MOVE = 2,
+    BUTTONUP = 3,
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/svdview.hxx b/include/svx/svdview.hxx
index 166990985830..ae555aaab03d 100644
--- a/include/svx/svdview.hxx
+++ b/include/svx/svdview.hxx
@@ -25,6 +25,7 @@
 #include <tools/weakbase.h>
 #include <svtools/accessibilityoptions.hxx>
 #include <svx/svxdllapi.h>
+#include <svx/sdr/view/Enums.hxx>
 #include <svx/svdcrtv.hxx>
 #include <vcl/event.hxx>
 #include <unotools/options.hxx>
@@ -51,48 +52,6 @@
 class SvxURLField;
 namespace sdr::contact { class ObjectContact; }
 
-enum class SdrViewContext {
-    Standard,
-    PointEdit,
-    GluePointEdit,
-    Graphic,
-    Media,
-    Table
-};
-
-enum class SdrEventKind {
-    NONE,
-    TextEdit,
-    MoveAction,
-    EndAction,
-    BackAction,
-    EndCreate,
-    EndDrag,
-    MarkObj,
-    MarkPoint,
-    MarkGluePoint,
-    BeginMark,
-    BeginInsertObjPoint,
-    EndInsertObjPoint,
-    BeginInsertGluePoint,
-    BeginDragHelpline,
-    BeginDragObj,
-    BeginCreateObj,
-    BeginMacroObj,
-    BeginTextEdit,
-    EndMark,
-    BrkMark,
-    ExecuteUrl
-};
-
-/* for PickAnything() */
-enum class SdrMouseEventKind
-{
-    BUTTONDOWN = 1,
-    MOVE       = 2,
-    BUTTONUP   = 3,
-};
-
 // helper class SdrViewEvent
 struct SVXCORE_DLLPUBLIC SdrViewEvent
 {
commit 3569e373912fe86a1fd4141d001b7a09949a6efe
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jun 28 17:06:19 2022 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:00 2022 +0200

    svx: rearrange forward imports
    
    Change-Id: I03360d17019bdc2959dbe80f128839d068312670

diff --git a/include/svx/svdpntv.hxx b/include/svx/svdpntv.hxx
index dc36e3a4f66a..c82f58ca998e 100644
--- a/include/svx/svdpntv.hxx
+++ b/include/svx/svdpntv.hxx
@@ -38,9 +38,7 @@
 // Pre defines
 class SdrPageWindow;
 
-namespace com::sun::star::awt {
-    class XControlContainer;
-}
+namespace com::sun::star::awt { class XControlContainer; }
 namespace sdr::overlay { class OverlayManager; }
 
 class SdrPage;
@@ -51,10 +49,10 @@ class SdrOle2Obj;
 class SdrModel;
 class SdrObject;
 enum class GraphicManagerDrawFlags;
-
-namespace sdr::contact {
-    class ViewObjectContactRedirector;
-}
+class SdrPaintView;
+namespace sdr::contact { class ViewObjectContactRedirector; }
+namespace vcl { class Window; }
+class SdrPaintWindow;
 
 // Defines for AnimationMode
 enum class SdrAnimationMode
@@ -63,15 +61,6 @@ enum class SdrAnimationMode
     Disable
 };
 
-class SdrPaintView;
-namespace sdr::contact { class ViewObjectContactRedirector; }
-
-namespace vcl {
-    class Window;
-}
-
-class SdrPaintWindow;
-
 /**
  * Helper to convert any GDIMetaFile to a good quality BitmapEx,
  * using default parameters and graphic::XPrimitive2DRenderer
commit 0a656d22e3de4c46c734954aff6ef31d5f1787af
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Jun 13 22:36:24 2022 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:00 2022 +0200

    sdr: move SvxViewChangeHint into its own class
    
    Change-Id: I104a9d4410b2197c8c9bb88e5b8dfd3c104c2def

diff --git a/include/svx/sdr/view/ViewChangeHint.hxx 
b/include/svx/sdr/view/ViewChangeHint.hxx
new file mode 100644
index 000000000000..d746523a6802
--- /dev/null
+++ b/include/svx/sdr/view/ViewChangeHint.hxx
@@ -0,0 +1,30 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <svl/hint.hxx>
+
+class SvxViewChangedHint final : public SfxHint
+{
+public:
+    explicit SvxViewChangedHint() = default;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/svdpntv.hxx b/include/svx/svdpntv.hxx
index 7370c5f1c7ed..dc36e3a4f66a 100644
--- a/include/svx/svdpntv.hxx
+++ b/include/svx/svdpntv.hxx
@@ -24,6 +24,7 @@
 #include <svl/undo.hxx>
 #include <svx/svddrag.hxx>
 #include <svx/svdlayer.hxx>
+#include <svx/sdr/view/ViewChangeHint.hxx>
 #include <svtools/colorcfg.hxx>
 #include <svl/itemset.hxx>
 #include <svx/svxdllapi.h>
@@ -69,13 +70,6 @@ namespace vcl {
     class Window;
 }
 
-
-class SvxViewChangedHint final : public SfxHint
-{
-public:
-    explicit SvxViewChangedHint();
-};
-
 class SdrPaintWindow;
 
 /**
diff --git a/svx/source/svdraw/svdpntv.cxx b/svx/source/svdraw/svdpntv.cxx
index f403ddd578ac..3cba91579eb2 100644
--- a/svx/source/svdraw/svdpntv.cxx
+++ b/svx/source/svdraw/svdpntv.cxx
@@ -98,12 +98,6 @@ OutputDevice* SdrPaintView::GetFirstOutputDevice() const
     return nullptr;
 }
 
-
-SvxViewChangedHint::SvxViewChangedHint()
-{
-}
-
-
 BitmapEx convertMetafileToBitmapEx(
     const GDIMetaFile& rMtf,
     const basegfx::B2DRange& rTargetRange,
commit a4be53a4f4edcea9a8054cb0e1bfd72acb732586
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Nov 12 10:01:20 2020 +0100
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:00 2022 +0200

    basegfx: added Length class as the base unit for length
    
    Change-Id: I1d4790b60dd784e8b2e2e438274f3ebd6db4b60c

diff --git a/basegfx/CppunitTest_basegfx.mk b/basegfx/CppunitTest_basegfx.mk
index 88f4966262f2..98d3a5d41926 100644
--- a/basegfx/CppunitTest_basegfx.mk
+++ b/basegfx/CppunitTest_basegfx.mk
@@ -45,6 +45,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basegfx,\
     basegfx/test/clipstate \
     basegfx/test/genericclipper \
     basegfx/test/VectorTest \
+    basegfx/test/LengthUnitTest \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/basegfx/test/LengthUnitTest.cxx b/basegfx/test/LengthUnitTest.cxx
new file mode 100644
index 000000000000..40c21aa7bc90
--- /dev/null
+++ b/basegfx/test/LengthUnitTest.cxx
@@ -0,0 +1,120 @@
+/* -*- 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 <basegfx/units/Length.hxx>
+#include <basegfx/range/Range2D.hxx>
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+struct LengthTraits
+{
+    static constexpr gfx::Length minVal() { return gfx::Length::min(); };
+    static constexpr gfx::Length maxVal() { return gfx::Length::max(); };
+    static constexpr gfx::Length neutral() { return gfx::Length(); };
+
+    typedef gfx::Length DifferenceType;
+};
+
+class LengthTest : public CppUnit::TestFixture
+{
+public:
+    void test()
+    {
+        gfx::Length cm = 1_cm + 5_cm - 2_cm;
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, cm.as_cm(), 1e-4);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(0.04, cm.as_m(), 1e-4);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(40.0, cm.as_mm(), 1e-4);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(1440000), cm.raw());
+
+        gfx::Length cm2 = 5_cm * 2;
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(3600000), cm2.raw());
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, cm2.as_cm(), 1e-4);
+
+        // 1 km - 50 m = 950 m = 95000 cm
+        gfx::Length cm3 = 100000_cm - 5000_cm;
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(34200000000), cm3.raw());
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(95000.0, cm3.as_cm(), 1e-4);
+
+        gfx::Length cm4(1_cm);
+        cm4 /= 2;
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(180000), cm4.raw());
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5, cm4.as_cm(), 1e-4);
+
+        // (635 * 20) + 3 * (635 * 15) = 41275EMU
+        gfx::Length pt = 1_pt + 3_px;
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(3.25, pt.as_pt(), 1e-4);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, pt.as_twip(), 1e-4);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0451, pt.as_in(), 1e-4);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(41275), pt.raw());
+
+        gfx::Length inch = 1_in; // 1440 * 635
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(1440.0, inch.as_twip(), 1e-4);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(96.0, inch.as_px(), 1e-4);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, inch.as_in(), 1e-4);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(914400.0, inch.as_emu(), 1e-4);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(914400), inch.raw());
+
+        // Conversion
+        sal_Int64 asNumber(17_pt);
+        asNumber += sal_Int64(1_pt);
+        gfx::Length asLength = gfx::Length::emu(asNumber);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(18 * 635 * 20), asLength.raw());
+
+        gfx::Length maximum = gfx::Length::emu(SAL_MAX_INT64);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(256204778801.5, maximum.as_m(), 1e-1);
+        // 256204778 km
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(SAL_MAX_INT64), maximum.raw());
+
+        gfx::Length minimum = gfx::Length::emu(SAL_MIN_INT64);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(-256204778801.5, minimum.as_m(), 1e-1);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(double(SAL_MIN_INT64), minimum.as_emu(), 
1e-1);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(SAL_MIN_INT64), minimum.raw());
+
+        // 27 emu + 33 emu + 360 emu = 420
+        gfx::Length emus = 27_emu + 33_emu + 1_hmm;
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(420), emus.raw());
+
+        //  Creation from number
+        int number = 10;
+        auto asCm = gfx::Length::cm(number);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, asCm.as_cm(), 1e-4);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(3600000), asCm.raw());
+
+        auto asMm = gfx::Length::mm(number);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, asMm.as_mm(), 1e-4);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(360000), asMm.raw());
+
+        auto asInch = gfx::Length::in(number);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, asInch.as_in(), 1e-4);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(9144000), asInch.raw());
+
+        typedef basegfx::Range2D<gfx::Length, LengthTraits> Range2DL;
+        typedef basegfx::Tuple2D<gfx::Length> Tuple2DL;
+
+        Range2DL aRange(1_cm, 2_cm, 2_cm, 30_mm);
+        CPPUNIT_ASSERT_EQUAL(1_cm, aRange.getMinX());
+        CPPUNIT_ASSERT_EQUAL(2_cm, aRange.getMaxX());
+        CPPUNIT_ASSERT_EQUAL(2_cm, aRange.getMinY());
+        CPPUNIT_ASSERT_EQUAL(3_cm, aRange.getMaxY());
+
+        CPPUNIT_ASSERT_EQUAL(1_cm, aRange.getWidth());
+        CPPUNIT_ASSERT_EQUAL(10_mm, aRange.getHeight());
+
+        Tuple2DL aTuple(0.5_pt, 1_pt);
+        CPPUNIT_ASSERT_EQUAL(6350_emu, aTuple.getX());
+        CPPUNIT_ASSERT_EQUAL(12700_emu, aTuple.getY());
+    }
+
+    CPPUNIT_TEST_SUITE(LengthTest);
+    CPPUNIT_TEST(test);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(LengthTest);
diff --git a/include/basegfx/units/Length.hxx b/include/basegfx/units/Length.hxx
new file mode 100644
index 000000000000..bf1adbf00178
--- /dev/null
+++ b/include/basegfx/units/Length.hxx
@@ -0,0 +1,73 @@
+/* -*- 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 <basegfx/units/LengthUnitBase.hxx>
+
+namespace gfx
+{
+typedef LengthUnitBase<sal_Int64> Length;
+
+} // end namespace gfx
+
+constexpr gfx::Length operator"" _emu(unsigned long long value) { return 
gfx::Length::emu(value); }
+constexpr gfx::Length operator"" _in(unsigned long long value) { return 
gfx::Length::in(value); }
+constexpr gfx::Length operator"" _cm(unsigned long long value) { return 
gfx::Length::cm(value); }
+constexpr gfx::Length operator"" _mm(unsigned long long value) { return 
gfx::Length::mm(value); }
+constexpr gfx::Length operator"" _hmm(unsigned long long value) { return 
gfx::Length::hmm(value); }
+constexpr gfx::Length operator"" _twip(unsigned long long value)
+{
+    return gfx::Length::twip(value);
+}
+constexpr gfx::Length operator"" _pt(unsigned long long value) { return 
gfx::Length::pt(value); }
+constexpr gfx::Length operator"" _px(unsigned long long value) { return 
gfx::Length::px(value); }
+
+constexpr gfx::Length operator"" _in(long double value)
+{
+    return gfx::Length::emu(std::round(gfx::constFactor_in_to_EMU * value));
+}
+constexpr gfx::Length operator"" _cm(long double value)
+{
+    return gfx::Length::emu(std::round(gfx::constFactor_cm_to_EMU * value));
+}
+
+constexpr gfx::Length operator"" _mm(long double value)
+{
+    return gfx::Length::emu(std::round(gfx::constFactor_mm_to_EMU * value));
+}
+
+constexpr gfx::Length operator"" _hmm(long double value)
+{
+    return gfx::Length::emu(std::round(gfx::constFactor_hmm_to_EMU * value));
+}
+
+constexpr gfx::Length operator"" _twip(long double value)
+{
+    return gfx::Length::emu(std::round(gfx::constFactor_twip_to_EMU * value));
+}
+
+constexpr gfx::Length operator"" _pt(long double value)
+{
+    return gfx::Length::emu(std::round(gfx::constFactor_pt_to_EMU * value));
+}
+
+constexpr gfx::Length operator"" _px(long double value)
+{
+    return gfx::Length::emu(std::round(gfx::constFactor_px_to_EMU * value));
+}
+
+/** Write to char stream */
+template <typename charT, typename traits>
+inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, 
traits>& stream,
+                                                     const gfx::Length& 
rLength)
+{
+    return stream << rLength.raw() << " (twip=" << rLength.as_twip() << ", 
hmm=" << rLength.as_hmm()
+                  << ")";
+}
diff --git a/include/basegfx/units/LengthUnitBase.hxx 
b/include/basegfx/units/LengthUnitBase.hxx
new file mode 100644
index 000000000000..81a4f8216d5e
--- /dev/null
+++ b/include/basegfx/units/LengthUnitBase.hxx
@@ -0,0 +1,183 @@
+/* -*- 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 <sal/types.h>
+
+#include <ostream>
+#include <cmath>
+
+namespace gfx
+{
+namespace
+{
+constexpr sal_Int64 constFactor_hmm_to_EMU = 360ll;
+constexpr sal_Int64 constFactor_mm_to_EMU = constFactor_hmm_to_EMU * 100ll;
+constexpr sal_Int64 constFactor_cm_to_EMU = constFactor_hmm_to_EMU * 1000ll;
+constexpr sal_Int64 constFactor_m_to_EMU = constFactor_hmm_to_EMU * 100000ll;
+
+constexpr sal_Int64 constFactor_twip_to_EMU = 635ll;
+constexpr sal_Int64 constFactor_in_to_EMU = constFactor_twip_to_EMU * 1440ll;
+constexpr sal_Int64 constFactor_pt_to_EMU = constFactor_twip_to_EMU * 20ll;
+constexpr sal_Int64 constFactor_px_to_EMU = constFactor_twip_to_EMU * 15ll;
+
+} // end anonymous namespace
+
+template <typename T> class LengthUnitBase
+{
+private:
+    // value in EMU units
+    T m_nValue;
+
+    constexpr explicit LengthUnitBase(T nValue)
+        : m_nValue(nValue)
+    {
+    }
+
+public:
+    static constexpr LengthUnitBase min() { return 
LengthUnitBase(SAL_MIN_INT64); }
+
+    static constexpr LengthUnitBase max() { return 
LengthUnitBase(SAL_MAX_INT64); }
+
+    static constexpr LengthUnitBase cm(T nValue)
+    {
+        return LengthUnitBase(gfx::constFactor_cm_to_EMU * nValue);
+    }
+
+    static constexpr LengthUnitBase mm(T nValue)
+    {
+        return LengthUnitBase(gfx::constFactor_mm_to_EMU * nValue);
+    }
+
+    static constexpr LengthUnitBase hmm(T nValue)
+    {
+        return LengthUnitBase(gfx::constFactor_hmm_to_EMU * nValue);
+    }
+
+    static constexpr LengthUnitBase in(T nValue)
+    {
+        return LengthUnitBase(gfx::constFactor_in_to_EMU * nValue);
+    }
+
+    static constexpr LengthUnitBase twip(T nValue)
+    {
+        return LengthUnitBase(gfx::constFactor_twip_to_EMU * nValue);
+    }
+
+    static constexpr LengthUnitBase pt(T nValue)
+    {
+        return LengthUnitBase(gfx::constFactor_pt_to_EMU * nValue);
+    }
+
+    static constexpr LengthUnitBase px(T nValue)
+    {
+        return LengthUnitBase(gfx::constFactor_px_to_EMU * nValue);
+    }
+
+    static constexpr LengthUnitBase emu(T nValue) { return 
LengthUnitBase(nValue); }
+
+    constexpr explicit LengthUnitBase()
+        : m_nValue(0)
+    {
+    }
+
+    constexpr explicit operator T() const { return m_nValue; }
+
+    constexpr LengthUnitBase& operator+=(LengthUnitBase const& rhs)
+    {
+        m_nValue += rhs.m_nValue;
+        return *this;
+    }
+
+    constexpr LengthUnitBase& operator-=(LengthUnitBase const& rhs)
+    {
+        m_nValue -= rhs.m_nValue;
+        return *this;
+    }
+
+    constexpr LengthUnitBase& operator*=(T const& rhs)
+    {
+        m_nValue *= rhs;
+        return *this;
+    }
+
+    constexpr LengthUnitBase& operator/=(T const& rhs)
+    {
+        m_nValue /= rhs;
+        return *this;
+    }
+
+    constexpr LengthUnitBase& operator-()
+    {
+        m_nValue = -m_nValue;
+        return *this;
+    }
+
+    constexpr bool operator<(LengthUnitBase const& other) const
+    {
+        return m_nValue < other.m_nValue;
+    }
+    constexpr bool operator<=(LengthUnitBase const& other) const
+    {
+        return m_nValue <= other.m_nValue;
+    }
+    constexpr bool operator>(LengthUnitBase const& other) const
+    {
+        return m_nValue > other.m_nValue;
+    }
+    constexpr bool operator>=(LengthUnitBase const& other) const
+    {
+        return m_nValue >= other.m_nValue;
+    }
+    constexpr bool operator==(LengthUnitBase const& other) const
+    {
+        return m_nValue == other.m_nValue;
+    }
+    constexpr bool operator!=(LengthUnitBase const& other) const
+    {
+        return m_nValue != other.m_nValue;
+    }
+
+    constexpr T raw() const { return m_nValue; }
+
+    double as_hmm() const { return m_nValue / double(constFactor_hmm_to_EMU); }
+    double as_mm() const { return m_nValue / double(constFactor_mm_to_EMU); }
+    double as_cm() const { return m_nValue / double(constFactor_cm_to_EMU); }
+    double as_m() const { return m_nValue / double(constFactor_m_to_EMU); }
+    double as_twip() const { return m_nValue / 
double(constFactor_twip_to_EMU); }
+    double as_in() const { return m_nValue / double(constFactor_in_to_EMU); }
+    double as_pt() const { return m_nValue / double(constFactor_pt_to_EMU); }
+    double as_px() const { return m_nValue / double(constFactor_px_to_EMU); }
+    double as_emu() const { return double(m_nValue); }
+};
+
+template <typename T>
+inline LengthUnitBase<T> operator+(LengthUnitBase<T> lhs, const 
LengthUnitBase<T>& rhs)
+{
+    return lhs += rhs;
+}
+
+template <typename T>
+inline LengthUnitBase<T> operator-(LengthUnitBase<T> lhs, const 
LengthUnitBase<T>& rhs)
+{
+    return lhs -= rhs;
+}
+
+template <typename T> inline LengthUnitBase<T> operator*(LengthUnitBase<T> 
lhs, const long rhs)
+{
+    return lhs *= rhs;
+}
+
+template <typename T> inline LengthUnitBase<T> operator/(LengthUnitBase<T> 
lhs, const long rhs)
+{
+    return lhs /= rhs;
+}
+
+} // end namespace gfx
commit 0cfefab238de6ea464b5988e1d2a111ec420c9a5
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon May 10 15:45:13 2021 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:00 2022 +0200

    vcl: add more methods to the PDFium
    
    Change-Id: I74ef0f713125c7069620d1abc9534a636c1707d9

diff --git a/include/vcl/filter/PDFiumLibrary.hxx 
b/include/vcl/filter/PDFiumLibrary.hxx
index c5f1766f60c0..46988cf3c946 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -111,6 +111,13 @@ public:
     virtual PDFSegmentType getType() const = 0;
 };
 
+struct PDFImageMetadata
+{
+    sal_uInt32 mnWidth;
+    sal_uInt32 mnHeight;
+    sal_uInt32 mnBitsPerPixel;
+};
+
 class VCL_DLLPUBLIC PDFiumPageObject
 {
 public:
@@ -127,15 +134,20 @@ public:
     virtual double getFontSize() = 0;
     virtual OUString getFontName() = 0;
     virtual PDFTextRenderMode getTextRenderMode() = 0;
+    virtual bool hasTransparency() = 0;
     virtual Color getFillColor() = 0;
     virtual Color getStrokeColor() = 0;
     virtual double getStrokeWidth() = 0;
     // Path
     virtual int getPathSegmentCount() = 0;
     virtual std::unique_ptr<PDFiumPathSegment> getPathSegment(int index) = 0;
+    virtual bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) = 0;
+    // Image
     virtual Size getImageSize(PDFiumPage& rPage) = 0;
+    virtual PDFImageMetadata getImageMetadata(PDFiumPage& rPage) = 0;
+
     virtual std::unique_ptr<PDFiumBitmap> getImageBitmap() = 0;
-    virtual bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) = 0;
+    virtual bool getDecodedImageData(std::vector<sal_uInt8>& rData) = 0;
 };
 
 class VCL_DLLPUBLIC PDFiumSearchHandle
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index d02e2a0bab49..b38506245758 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -255,15 +255,19 @@ public:
     double getFontSize() override;
     OUString getFontName() override;
     PDFTextRenderMode getTextRenderMode() override;
+    bool hasTransparency() override;
     Color getFillColor() override;
     Color getStrokeColor() override;
     double getStrokeWidth() override;
     // Path
     int getPathSegmentCount() override;
     std::unique_ptr<PDFiumPathSegment> getPathSegment(int index) override;
+    bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) override;
+    // Image
     Size getImageSize(PDFiumPage& rPage) override;
+    PDFImageMetadata getImageMetadata(PDFiumPage& rPage) override;
     std::unique_ptr<PDFiumBitmap> getImageBitmap() override;
-    bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) override;
+    bool getDecodedImageData(std::vector<sal_uInt8>& rData) override;
 };
 
 class PDFiumSearchHandleImpl final : public PDFiumSearchHandle
@@ -842,6 +846,8 @@ Color PDFiumPageObjectImpl::getFillColor()
     return aColor;
 }
 
+bool PDFiumPageObjectImpl::hasTransparency() { return 
FPDFPageObj_HasTransparency(mpPageObject); }
+
 Color PDFiumPageObjectImpl::getStrokeColor()
 {
     Color aColor = COL_TRANSPARENT;
@@ -881,6 +887,28 @@ Size PDFiumPageObjectImpl::getImageSize(PDFiumPage& rPage)
     return Size(aMeta.width, aMeta.height);
 }
 
+PDFImageMetadata PDFiumPageObjectImpl::getImageMetadata(PDFiumPage& rPage)
+{
+    FPDF_IMAGEOBJ_METADATA aMeta;
+    auto& rPageImpl = static_cast<PDFiumPageImpl&>(rPage);
+    FPDFImageObj_GetImageMetadata(mpPageObject, rPageImpl.getPointer(), 
&aMeta);
+    return { aMeta.width, aMeta.height, aMeta.bits_per_pixel };
+}
+
+bool PDFiumPageObjectImpl::getDecodedImageData(std::vector<sal_uInt8>& rData)
+{
+    unsigned long nLength = FPDFImageObj_GetImageDataDecoded(mpPageObject, 
nullptr, 0);
+    if (nLength > 0)
+    {
+        rData.resize(nLength);
+        unsigned long nReadLength
+            = FPDFImageObj_GetImageDataDecoded(mpPageObject, rData.data(), 
nLength);
+        if (nReadLength == nLength)
+            return true;
+    }
+    return false;
+}
+
 std::unique_ptr<PDFiumBitmap> PDFiumPageObjectImpl::getImageBitmap()
 {
     std::unique_ptr<PDFiumBitmap> pPDFiumBitmap;
commit 6f0c10cf974d95c955bafbf82669e6e3b88e836e
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon May 3 16:42:22 2021 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:38:00 2022 +0200

    Add PDF importer to read a PDF into drawinglayer primitives
    
    Change-Id: I8d2e28a39515dfef8a1b4c6b06df095dd3a4eaec

diff --git a/Repository.mk b/Repository.mk
index e9680db6d54c..c25e728eaade 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -439,6 +439,7 @@ $(eval $(call 
gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \
        passwordcontainer \
        pcr \
        pdffilter \
+       pdfimporter \
        $(call gb_Helper_optional,SCRIPTING,protocolhandler) \
        sax \
        sb \
diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx 
b/drawinglayer/source/tools/primitive2dxmldump.cxx
index 63562973d6ca..5aa2c9771f84 100644
--- a/drawinglayer/source/tools/primitive2dxmldump.cxx
+++ b/drawinglayer/source/tools/primitive2dxmldump.cxx
@@ -513,6 +513,13 @@ void Primitive2dXmlDump::dump(
     aWriter.endDocument();
 
     pStream->Seek(STREAM_SEEK_TO_BEGIN);
+
+    std::size_t nSize = pStream->remainingSize();
+    std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nSize + 1]);
+    pStream->ReadBytes(pBuffer.get(), nSize);
+    pBuffer[nSize] = 0;
+
+    printf ("%s\n", pBuffer.get());
 }
 
 namespace
diff --git a/filter/CppunitTest_filter_pdfimporter_test.mk 
b/filter/CppunitTest_filter_pdfimporter_test.mk
new file mode 100644
index 000000000000..3b17dcdcb43f
--- /dev/null
+++ b/filter/CppunitTest_filter_pdfimporter_test.mk
@@ -0,0 +1,48 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,filter_pdfimporter_test))
+
+$(eval $(call gb_CppunitTest_use_externals,filter_pdfimporter_test,\
+       boost_headers \
+       libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,filter_pdfimporter_test, \
+    filter/qa/cppunit/PdfImporterTest \
+))
+
+$(eval $(call gb_CppunitTest_use_library_objects,filter_pdfimporter_test,\
+    pdfimporter \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,filter_pdfimporter_test, \
+    basegfx \
+    drawinglayer \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    test \
+    unotest \
+    utl \
+    tl \
+    vcl \
+    tk \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,filter_pdfimporter_test))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,filter_pdfimporter_test))
+$(eval $(call gb_CppunitTest_use_ure,filter_pdfimporter_test))
+$(eval $(call gb_CppunitTest_use_vcl,filter_pdfimporter_test))
+$(eval $(call gb_CppunitTest_use_rdb,filter_pdfimporter_test,services))
+
+
+# vim: set noet sw=4 ts=4:
diff --git a/filter/Library_pdfimporter.mk b/filter/Library_pdfimporter.mk
new file mode 100644
index 000000000000..01f6786d6e11
--- /dev/null
+++ b/filter/Library_pdfimporter.mk
@@ -0,0 +1,38 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_Library_Library,pdfimporter))
+
+$(eval $(call gb_Library_set_include,pdfimporter,\
+       -I$(SRCDIR)/filter/inc \
+       $$(INCLUDE) \
+))
+
+$(eval $(call gb_Library_use_external,pdfimporter,boost_headers))
+
+$(eval $(call gb_Library_add_exception_objects,pdfimporter,\
+       filter/source/pdfimporter/PDFImporter \
+))
+
+$(eval $(call gb_Library_use_libraries,pdfimporter,\
+       drawinglayercore \
+       drawinglayer \
+       basegfx \
+       vcl \
+       tl \
+       sal \
+       cppu \
+       tk \
+       svxcore \
+       salhelper \
+))
+
+$(eval $(call gb_Library_use_sdk_api,pdfimporter))
+
+# vim: set noet sw=4 ts=4:
diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk
index c28c72705cec..e8ef1649c876 100644
--- a/filter/Module_filter.mk
+++ b/filter/Module_filter.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_Module_add_targets,filter,\
        Library_msfilter \
        Library_odfflatxml \
        Library_pdffilter \
+       Library_pdfimporter \
        Library_storagefd \
        Library_svgfilter \
        Library_graphicfilter \
@@ -49,6 +50,7 @@ $(eval $(call gb_Module_add_check_targets,filter,\
     CppunitTest_filter_xslt \
     CppunitTest_filter_priority \
     CppunitTest_filter_msfilter \
+    CppunitTest_filter_pdfimporter_test \
     CppunitTest_filter_textfilterdetect \
     CppunitTest_filter_pdf \
 ))
diff --git a/filter/qa/cppunit/PdfImporterTest.cxx 
b/filter/qa/cppunit/PdfImporterTest.cxx
new file mode 100644
index 000000000000..ee57b9bdbc67
--- /dev/null
+++ b/filter/qa/cppunit/PdfImporterTest.cxx
@@ -0,0 +1,173 @@
+/* -*- 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 <sal/config.h>
+#include <sal/types.h>
+#include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
+
+#include <filter/pdfimporter/PDFImporter.hxx>
+#include <vcl/BinaryDataContainer.hxx>
+#include <tools/stream.hxx>
+#include <drawinglayer/converters.hxx>
+#include <drawinglayer/geometry/viewinformation2d.hxx>
+#include <drawinglayer/tools/primitive2dxmldump.hxx>
+
+#include <tools/stream.hxx>
+#include <vcl/pngwrite.hxx>
+
+class PDFImporterTest : public test::BootstrapFixture, public XmlTestTools
+{
+    OUString getFullUrl(std::u16string_view sFileName)
+    {
+        return m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/") + 
sFileName;
+    }
+
+    void testPath();
+    void testImage();
+    void testText();
+
+    CPPUNIT_TEST_SUITE(PDFImporterTest);
+    //CPPUNIT_TEST(testPath);
+    //CPPUNIT_TEST(testImage);
+    CPPUNIT_TEST(testText);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void PDFImporterTest::testPath()
+{
+    SvFileStream aFileStream(getFullUrl(u"/PdfTest-Rect.pdf"), 
StreamMode::READ);
+    const sal_uInt64 nStreamLength = aFileStream.TellEnd();
+    auto rData = std::make_unique<std::vector<sal_uInt8>>(nStreamLength);
+    aFileStream.ReadBytes(rData->data(), rData->size());
+    BinaryDataContainer aDataContainer(std::move(rData));
+    PDFImporter aImporter(aDataContainer);
+
+    drawinglayer::primitive2d::Primitive2DContainer aContainer;
+    aImporter.importPage(0, aContainer);
+
+    drawinglayer::geometry::ViewInformation2D rViewInformation2D;
+
+    auto aRange = aContainer.getB2DRange(rViewInformation2D);
+
+    BitmapEx aBitmapEx
+        = drawinglayer::convertToBitmapEx(aContainer, rViewInformation2D, 
2000, 2000, 10000 * 1000);
+
+    SvFileStream aNew("~/xxxxxxx.png", StreamMode::WRITE | StreamMode::TRUNC);
+    vcl::PNGWriter aPNGWriter(aBitmapEx);
+    aPNGWriter.Write(aNew);
+
+    drawinglayer::Primitive2dXmlDump aDumper;
+    aDumper.dump(aContainer, OUString());
+    xmlDocUniquePtr pDocument = aDumper.dumpAndParse(aContainer);
+    CPPUNIT_ASSERT(pDocument);
+
+    assertXPath(pDocument, 
"/primitive2D/metafile/transform/mask/transform/unifiedtransparence",
+                "transparence", "0.498039215686275");
+
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinX());
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinY());
+    CPPUNIT_ASSERT_EQUAL(612.5, aRange.getMaxX());
+    CPPUNIT_ASSERT_EQUAL(792.5, aRange.getMaxY());
+
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Height());
+
+    CPPUNIT_ASSERT(false);
+}
+
+void PDFImporterTest::testImage()
+{
+    SvFileStream aFileStream(getFullUrl(u"/PdfTest-Image.pdf"), 
StreamMode::READ);
+    const sal_uInt64 nStreamLength = aFileStream.TellEnd();
+    auto rData = std::make_unique<std::vector<sal_uInt8>>(nStreamLength);
+    aFileStream.ReadBytes(rData->data(), rData->size());
+    BinaryDataContainer aDataContainer(std::move(rData));
+    PDFImporter aImporter(aDataContainer);
+
+    drawinglayer::primitive2d::Primitive2DContainer aContainer;
+    aImporter.importPage(0, aContainer);
+
+    drawinglayer::geometry::ViewInformation2D rViewInformation2D;
+
+    auto aRange = aContainer.getB2DRange(rViewInformation2D);
+
+    BitmapEx aBitmapEx
+        = drawinglayer::convertToBitmapEx(aContainer, rViewInformation2D, 
2000, 2000, 10000 * 1000);
+
+    SvFileStream aNew("~/xxxxxxx.png", StreamMode::WRITE | StreamMode::TRUNC);
+    vcl::PNGWriter aPNGWriter(aBitmapEx);
+    aPNGWriter.Write(aNew);
+
+    drawinglayer::Primitive2dXmlDump aDumper;
+    aDumper.dump(aContainer, OUString());
+    xmlDocUniquePtr pDocument = aDumper.dumpAndParse(aContainer);
+    CPPUNIT_ASSERT(pDocument);
+
+    assertXPath(pDocument, 
"/primitive2D/metafile/transform/mask/transform/unifiedtransparence",
+                "transparence", "0.498039215686275");
+
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinX());
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinY());
+    CPPUNIT_ASSERT_EQUAL(612.5, aRange.getMaxX());
+    CPPUNIT_ASSERT_EQUAL(792.5, aRange.getMaxY());
+
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Height());
+
+    CPPUNIT_ASSERT(false);
+}
+
+void PDFImporterTest::testText()
+{
+    SvFileStream aFileStream(getFullUrl(u"/PdfTest-Text.pdf"), 
StreamMode::READ);
+    const sal_uInt64 nStreamLength = aFileStream.TellEnd();
+    auto rData = std::make_unique<std::vector<sal_uInt8>>(nStreamLength);
+    aFileStream.ReadBytes(rData->data(), rData->size());
+    BinaryDataContainer aDataContainer(std::move(rData));
+    PDFImporter aImporter(aDataContainer);
+
+    drawinglayer::primitive2d::Primitive2DContainer aContainer;
+    aImporter.importPage(0, aContainer);
+
+    drawinglayer::geometry::ViewInformation2D rViewInformation2D;
+
+    auto aRange = aContainer.getB2DRange(rViewInformation2D);
+
+    BitmapEx aBitmapEx
+        = drawinglayer::convertToBitmapEx(aContainer, rViewInformation2D, 
2000, 2000, 10000 * 1000);
+
+    SvFileStream aNew("~/xxxxxxx.png", StreamMode::WRITE | StreamMode::TRUNC);
+    vcl::PNGWriter aPNGWriter(aBitmapEx);
+    aPNGWriter.Write(aNew);
+
+    drawinglayer::Primitive2dXmlDump aDumper;
+    aDumper.dump(aContainer, OUString());
+    xmlDocUniquePtr pDocument = aDumper.dumpAndParse(aContainer);
+    CPPUNIT_ASSERT(pDocument);
+
+    assertXPath(pDocument, 
"/primitive2D/metafile/transform/mask/transform/unifiedtransparence",
+                "transparence", "0.498039215686275");
+
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinX());
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinY());
+    CPPUNIT_ASSERT_EQUAL(612.5, aRange.getMaxX());
+    CPPUNIT_ASSERT_EQUAL(792.5, aRange.getMaxY());
+
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Height());
+
+    CPPUNIT_ASSERT(false);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PDFImporterTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/qa/cppunit/data/PdfTest-Image.pdf 
b/filter/qa/cppunit/data/PdfTest-Image.pdf
new file mode 100644
index 000000000000..394ee272f3d4
Binary files /dev/null and b/filter/qa/cppunit/data/PdfTest-Image.pdf differ
diff --git a/filter/qa/cppunit/data/PdfTest-Rect.pdf 
b/filter/qa/cppunit/data/PdfTest-Rect.pdf
new file mode 100644
index 000000000000..7115df65176f
--- /dev/null
+++ b/filter/qa/cppunit/data/PdfTest-Rect.pdf
@@ -0,0 +1,134 @@
+%PDF-1.6
+%äüöß
+2 0 obj
+<</Length 3 0 R/Filter/FlateDecode>>
+stream
+x����JA��y��{�&ٙ�Y(=�UQ�z�   ڪl.H_����"����!��%��x�7$�@R03��el;��=<-�
���#��O��
X#7��Ly�3��y9����j���6H��զ
+1���%K�̤0��hL:R,�SsSH�8S����BJ�duL�bg��|�Օs �4�����h����m�}E�� 
�ƅ��*�H���l��'���8a���M9��4S���Q���X8wY
+endstream
+endobj
+
+3 0 obj
+241
+endobj
+
+8 0 obj
+<<
+>>
+endobj
+
+9 0 obj
+<</Font 8 0 R
+/ProcSet[/PDF/Text]
+>>
+endobj
+
+1 0 obj
+<</Type/Page/Parent 7 0 R/Resources 9 0 R/MediaBox[0 0 612 792]/StructParents 0
+/Group<</S/Transparency/CS/DeviceRGB/I true>>/Contents 2 0 R>>
+endobj
+
+10 0 obj
+<</Count 1/First 11 0 R/Last 11 0 R
+>>
+endobj
+
+11 0 obj
+<</Count 0/Title<FEFF005000610067006500200031>
+/Dest[1 0 R/XYZ 0 792 0]/Parent 10 0 R>>
+endobj
+
+4 0 obj
+<</Type/StructElem
+/S/Figure
+/P 12 0 R
+/Pg 1 0 R
+/K[0 ]
+>>
+endobj
+
+5 0 obj
+<</Type/StructElem
+/S/Figure
+/P 12 0 R
+/Pg 1 0 R
+/K[1 ]
+>>
+endobj
+
+6 0 obj
+<</Type/StructElem
+/S/Figure
+/P 12 0 R
+/Pg 1 0 R
+/K[2 ]
+>>
+endobj
+
+12 0 obj
+<</Type/StructTreeRoot
+/ParentTree 13 0 R
+/K[4 0 R 5 0 R 6 0 R ]
+>>
+endobj
+
+13 0 obj
+<</Nums[
+0 [ 4 0 R 5 0 R 6 0 R ]
+]>>
+endobj
+
+7 0 obj
+<</Type/Pages
+/Resources 9 0 R
+/MediaBox[ 0 0 612 792 ]
+/Kids[ 1 0 R ]
+/Count 1>>
+endobj
+
+14 0 obj
+<</Type/Catalog/Pages 7 0 R
+/OpenAction[1 0 R /XYZ null null 0]
+/ViewerPreferences<</DisplayDocTitle true
+>>
+/Outlines 10 0 R
+/StructTreeRoot 12 0 R
+/MarkInfo<</Marked true>>
+>>
+endobj
+
+15 0 obj
+<</Title<FEFF004D007900540065006D0070006C006100740065>
+/Creator<FEFF0044007200610077>
+/Producer<FEFF004C0069006200720065004F0066006600690063006500200037002E0030>
+/CreationDate(D:20210505091047+09'00')>>
+endobj
+
+xref
+0 16
+0000000000 65535 f 
+0000000426 00000 n 
+0000000019 00000 n 
+0000000331 00000 n 
+0000000746 00000 n 
+0000000821 00000 n 
+0000000896 00000 n 
+0000001110 00000 n 
+0000000351 00000 n 
+0000000373 00000 n 
+0000000585 00000 n 
+0000000641 00000 n 
+0000000971 00000 n 
+0000001056 00000 n 
+0000001208 00000 n 
+0000001403 00000 n 
+trailer
+<</Size 16/Root 14 0 R
+/Info 15 0 R
+/ID [ <3F7788F2D0928B3B95B0CDBBD9EAC1B8>
+<3F7788F2D0928B3B95B0CDBBD9EAC1B8> ]
+/DocChecksum /F2715E25D79DC609834CA579FA23A5BA
+>>
+startxref
+1623
+%%EOF
diff --git a/filter/qa/cppunit/data/PdfTest-Text.pdf 
b/filter/qa/cppunit/data/PdfTest-Text.pdf
new file mode 100644
index 000000000000..c449bf559228
Binary files /dev/null and b/filter/qa/cppunit/data/PdfTest-Text.pdf differ
diff --git a/filter/source/pdfimporter/PDFImporter.cxx 
b/filter/source/pdfimporter/PDFImporter.cxx
new file mode 100644
index 000000000000..7c28f30f5275
--- /dev/null
+++ b/filter/source/pdfimporter/PDFImporter.cxx
@@ -0,0 +1,384 @@
+/* -*- 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 <filter/pdfimporter/PDFImporter.hxx>
+
+#include <sal/log.hxx>
+#include <tools/UnitConversion.hxx>
+#include <tools/color.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/BitmapTools.hxx>
+
+#include <cmath>
+
+#include <toolkit/helper/vclunohelper.hxx>
+
+#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+
+#include <drawinglayer/attribute/lineattribute.hxx>
+#include <drawinglayer/attribute/strokeattribute.hxx>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
+#include <drawinglayer/primitive2d/maskprimitive2d.hxx>
+#include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
+#include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
+#include <drawinglayer/primitive2d/PolyPolygonStrokePrimitive2D.hxx>
+#include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
+#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
+
+PDFImporter::PDFImporter(BinaryDataContainer& rDataContainer)
+    : mpPDFium(vcl::pdf::PDFiumLibrary::get())
+{
+    auto* pData = rDataContainer.getData();
+    sal_Int32 nSize = rDataContainer.getSize();
+
+    mpPdfDocument = mpPDFium->openDocument(pData, nSize);
+}
+
+namespace
+{
+void setupPage(drawinglayer::primitive2d::Primitive2DContainer& rContainer,
+               basegfx::B2DSize const& rPageSize)
+{
+    basegfx::B2DRange aPageRange(0.0, 0.0, rPageSize.getX(), rPageSize.getY());
+
+    printf("Page Size %.2fpt %.2fpt\n", rPageSize.getX(), rPageSize.getY());
+
+    const auto aPolygon = basegfx::utils::createPolygonFromRect(aPageRange);
+
+    const drawinglayer::primitive2d::Primitive2DReference xPage(
+        new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPolygon,
+                                                                  
basegfx::BColor(0.0, 0.0, 0.0)));
+    const drawinglayer::primitive2d::Primitive2DReference xHidden(
+        new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(
+            drawinglayer::primitive2d::Primitive2DContainer{ xPage }));
+
+    rContainer.push_back(xHidden);
+}
+
+double sqrt2(double a, double b) { return sqrt(a * a + b * b); }
+
+} // end anonymous namespace
+
+bool PDFImporter::importPage(int nPageIndex,
+                             drawinglayer::primitive2d::Primitive2DContainer& 
rContainer)
+{
+    if (!mpPdfDocument)
+        return false;
+
+    drawinglayer::primitive2d::Primitive2DContainer aContent;
+
+    const int nPageCount = mpPdfDocument->getPageCount();
+    if (!(nPageCount > 0 && nPageIndex >= 0 && nPageIndex < nPageCount))
+        return false;
+
+    mpPdfPage = mpPdfDocument->openPage(nPageIndex);
+    if (!mpPdfPage)
+        return false;
+
+    basegfx::B2DSize aPageSize = mpPdfDocument->getPageSize(nPageIndex);
+
+    setupPage(aContent, aPageSize);
+
+    // Load the page text to extract it when we get text elements.
+    auto pTextPage = mpPdfPage->getTextPage();
+
+    const int nPageObjectCount = mpPdfPage->getObjectCount();
+
+    for (int nPageObjectIndex = 0; nPageObjectIndex < nPageObjectCount; 
++nPageObjectIndex)
+    {
+        auto pPageObject = mpPdfPage->getObject(nPageObjectIndex);
+        importPdfObject(pPageObject, pTextPage, nPageObjectIndex, aContent);
+    }
+
+    // point to pixel conversion
+    double dConversionFactor = double(conversionFract(o3tl::Length::pt, 
o3tl::Length::px));
+    const auto aTransform = basegfx::utils::createScaleTranslateB2DHomMatrix(
+        dConversionFactor, -dConversionFactor, 0.0, aPageSize.getY() * 
dConversionFactor);
+
+    const drawinglayer::primitive2d::Primitive2DReference xTransform(
+        new drawinglayer::primitive2d::TransformPrimitive2D(aTransform, 
std::move(aContent)));
+
+    rContainer.push_back(xTransform);
+
+    return true;
+}
+
+void PDFImporter::importPdfObject(std::unique_ptr<vcl::pdf::PDFiumPageObject> 
const& pPageObject,
+                                  std::unique_ptr<vcl::pdf::PDFiumTextPage> 
const& pTextPage,
+                                  int nPageObjectIndex,
+                                  
drawinglayer::primitive2d::Primitive2DContainer& rContent)
+{
+    if (!pPageObject)
+        return;
+
+    const vcl::pdf::PDFPageObjectType ePageObjectType = pPageObject->getType();
+    switch (ePageObjectType)
+    {
+        case vcl::pdf::PDFPageObjectType::Text:
+            printf("pdf::PDFPageObjectType::Text\n");
+            importText(pPageObject, pTextPage, rContent);
+            break;
+        case vcl::pdf::PDFPageObjectType::Path:
+            printf("pdf::PDFPageObjectType::Path\n");
+            importPath(pPageObject, rContent);
+            break;
+        case vcl::pdf::PDFPageObjectType::Image:
+            printf("pdf::PDFPageObjectType::Image\n");
+            importImage(pPageObject, rContent);
+            break;
+        case vcl::pdf::PDFPageObjectType::Shading:
+            printf("pdf::PDFPageObjectType::Shading\n");
+            break;
+        case vcl::pdf::PDFPageObjectType::Form:
+            printf("pdf::PDFPageObjectType::Form\n");
+            break;
+        case vcl::pdf::PDFPageObjectType::Unknown:
+            SAL_WARN("filter", "Unknown PDF page object #" << nPageObjectIndex
+                                                           << " of type: " << 
int(ePageObjectType));
+            break;
+    }
+}
+
+void PDFImporter::importText(std::unique_ptr<vcl::pdf::PDFiumPageObject> 
const& pPageObject,
+                             std::unique_ptr<vcl::pdf::PDFiumTextPage> const& 
pTextPage,
+                             drawinglayer::primitive2d::Primitive2DContainer& 
rRootContainer)
+{
+    basegfx::B2DRectangle aTextRect = pPageObject->getBounds();
+    basegfx::B2DHomMatrix aMatrix = pPageObject->getMatrix();
+
+    OUString sText = pPageObject->getText(pTextPage);
+
+    const double dFontSize = pPageObject->getFontSize();
+    double dFontSizeH = std::fabs(sqrt2(aMatrix.a(), aMatrix.c()) * dFontSize);
+    double dFontSizeV = std::fabs(sqrt2(aMatrix.b(), aMatrix.d()) * dFontSize);
+
+    OUString sFontName = pPageObject->getFontName();
+
+    printf("TEXT: %s\n", sText.toUtf8().getStr());
+
+    Color aTextColor(COL_TRANSPARENT);
+    bool bFill = false;
+    bool bUse = true;
+
+    switch (pPageObject->getTextRenderMode())
+    {
+        case vcl::pdf::PDFTextRenderMode::Fill:
+        case vcl::pdf::PDFTextRenderMode::FillClip:
+        case vcl::pdf::PDFTextRenderMode::FillStroke:
+        case vcl::pdf::PDFTextRenderMode::FillStrokeClip:
+            bFill = true;
+            break;
+        case vcl::pdf::PDFTextRenderMode::Stroke:
+        case vcl::pdf::PDFTextRenderMode::StrokeClip:
+        case vcl::pdf::PDFTextRenderMode::Unknown:
+            break;
+        case vcl::pdf::PDFTextRenderMode::Invisible:
+        case vcl::pdf::PDFTextRenderMode::Clip:
+            bUse = false;
+            break;
+    }
+
+    if (bUse)
+    {
+        Color aColor = bFill ? pPageObject->getFillColor() : 
pPageObject->getStrokeColor();
+        if (aColor != COL_TRANSPARENT)
+        {
+            aTextColor = aColor.GetRGBColor();
+        }
+    }
+}
+
+void PDFImporter::importImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> 
const& pPageObject,
+                              drawinglayer::primitive2d::Primitive2DContainer& 
rRootContainer)
+{
+    std::unique_ptr<vcl::pdf::PDFiumBitmap> pPdfBitmap = 
pPageObject->getImageBitmap();
+    if (!pPdfBitmap)
+    {
+        SAL_WARN("filter", "Failed to get IMAGE");
+        return;
+    }
+
+    const vcl::pdf::PDFBitmapType eFormat = pPdfBitmap->getFormat();
+    if (eFormat == vcl::pdf::PDFBitmapType::Unknown)
+    {
+        SAL_WARN("filter", "Failed to get IMAGE format");
+        return;
+    }
+
+    vcl::pdf::PDFImageMetadata aMetadata = 
pPageObject->getImageMetadata(*mpPdfPage);
+    printf("METADATA %lu %lu %lu\n", aMetadata.mnWidth, aMetadata.mnHeight,
+           aMetadata.mnBitsPerPixel);
+
+    const sal_uInt8* pBuffer = pPdfBitmap->getBuffer();
+    const int nWidth = pPdfBitmap->getWidth();
+    const int nHeight = pPdfBitmap->getHeight();
+    const int nStride = pPdfBitmap->getStride();
+
+    BitmapEx aBitmap;
+
+    printf("hasTransparency %d\n", pPageObject->hasTransparency());
+
+    switch (eFormat)
+    {
+        case vcl::pdf::PDFBitmapType::BGR:
+            printf("vcl::pdf::PDFBitmapType::BGR\n");
+            aBitmap = vcl::bitmap::CreateFromData(pBuffer, nWidth, nHeight, 
nStride,
+                                                  vcl::PixelFormat::N24_BPP);
+            break;
+        case vcl::pdf::PDFBitmapType::BGRx:
+            printf("vcl::pdf::PDFBitmapType::BGRx\n");
+            aBitmap = vcl::bitmap::CreateFromData(pBuffer, nWidth, nHeight, 
nStride,
+                                                  vcl::PixelFormat::N32_BPP);
+            break;
+        case vcl::pdf::PDFBitmapType::BGRA:
+            printf("vcl::pdf::PDFBitmapType::BGRA\n");
+            aBitmap = vcl::bitmap::CreateFromData(pBuffer, nWidth, nHeight, 
nStride,
+                                                  vcl::PixelFormat::N32_BPP);
+            break;
+        case vcl::pdf::PDFBitmapType::Gray:
+            // TODO
+        default:
+            SAL_WARN("filter", "Got IMAGE width: " << nWidth << ", height: " 
<< nHeight
+                                                   << ", stride: " << nStride
+                                                   << ", format: " << 
int(eFormat));
+            break;
+    }
+
+    basegfx::B2DRectangle aBounds = pPageObject->getBounds();
+
+    rRootContainer.push_back(new drawinglayer::primitive2d::BitmapPrimitive2D(
+        VCLUnoHelper::CreateVCLXBitmap(aBitmap), 
basegfx::utils::createScaleTranslateB2DHomMatrix(
+                                                     aBounds.getRange(), 
aBounds.getMinimum())));
+}
+
+void PDFImporter::importPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> 
const& pPageObject,
+                             drawinglayer::primitive2d::Primitive2DContainer& 
rRootContainer)
+{
+    drawinglayer::primitive2d::Primitive2DContainer aContent;
+
+    basegfx::B2DHomMatrix aPathMatrix = pPageObject->getMatrix();
+
+    basegfx::B2DPolyPolygon aPolyPolygon;
+    basegfx::B2DPolygon aPolygon;
+    std::vector<basegfx::B2DPoint> aBezier;
+
+    const int nSegments = pPageObject->getPathSegmentCount();
+    for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex)
+    {
+        auto pPathSegment = pPageObject->getPathSegment(nSegmentIndex);
+        if (!pPathSegment)
+            continue;
+
+        basegfx::B2DPoint aB2DPoint = pPathSegment->getPoint();
+
+        aPolygon.setClosed(pPathSegment->isClosed());
+
+        const vcl::pdf::PDFSegmentType eSegmentType = pPathSegment->getType();
+        switch (eSegmentType)
+        {
+            case vcl::pdf::PDFSegmentType::Lineto:
+            {
+                aPolygon.append(aB2DPoint);
+            }
+            break;
+
+            case vcl::pdf::PDFSegmentType::Bezierto:
+            {
+                aBezier.emplace_back(aB2DPoint.getX(), aB2DPoint.getY());
+                if (aBezier.size() == 3)
+                {
+                    aPolygon.appendBezierSegment(aBezier[0], aBezier[1], 
aBezier[2]);
+                    aBezier.clear();
+                }
+            }
+            break;
+
+            case vcl::pdf::PDFSegmentType::Moveto:
+            {
+                if (aPolygon.count() > 0)
+                {
+                    aPolyPolygon.append(aPolygon);
+                    aPolygon.clear();
+                }
+
+                aPolygon.append(aB2DPoint);
+            }
+            break;
+
+            case vcl::pdf::PDFSegmentType::Unknown:
+            default:
+            {
+                SAL_WARN("filter", "Unknown path segment type in PDF: " << 
int(eSegmentType));
+            }
+            break;
+        }
+    }
+
+    if (aBezier.size() == 3)
+    {
+        aPolygon.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]);
+        aBezier.clear();
+    }
+
+    if (aPolygon.count() > 0)
+    {
+        aPolyPolygon.append(aPolygon, 1);
+        aPolygon.clear();
+    }
+
+    printf("PolyPoly size %d\n", aPolyPolygon.count());
+    for (auto const& rPoly : aPolyPolygon)
+        printf("Poly size %d\n", rPoly.count());
+
+    double fStrokeWidth = pPageObject->getStrokeWidth();
+    printf("Stroke: %f\n", fStrokeWidth);
+
+    vcl::pdf::PDFFillMode nFillMode = vcl::pdf::PDFFillMode::Alternate;
+    bool bStroke = true;
+
+    if (!pPageObject->getDrawMode(nFillMode, bStroke))
+    {
+        SAL_WARN("filter", "Huh...");
+    }
+
+    Color aFillColor = pPageObject->getFillColor();
+    Color aStokeColor = COL_TRANSPARENT;
+
+    if (bStroke)
+    {
+        aStokeColor = pPageObject->getStrokeColor();
+    }
+
+    if (aStokeColor == COL_TRANSPARENT)
+        aStokeColor = aFillColor;
+
+    if (!bStroke)
+    {
+        const drawinglayer::primitive2d::Primitive2DReference 
xPolyPolygonColorPrimitive(
+            new 
drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(aPolyPolygon,
+                                                                       
aFillColor.getBColor()));
+        aContent.push_back(xPolyPolygonColorPrimitive);
+    }
+
+    drawinglayer::attribute::LineAttribute 
aLineAttribute(aStokeColor.getBColor(), fStrokeWidth);
+    const drawinglayer::primitive2d::Primitive2DReference 
xPolyPolygonStrokePrimitive(
+        new 
drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(aPolyPolygon, 
aLineAttribute));
+    aContent.push_back(xPolyPolygonStrokePrimitive);
+
+    const drawinglayer::primitive2d::Primitive2DReference xTransform(
+        new drawinglayer::primitive2d::TransformPrimitive2D(aPathMatrix, 
std::move(aContent)));
+    rRootContainer.push_back(xTransform);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/filter/pdfimporter/PDFImporter.hxx 
b/include/filter/pdfimporter/PDFImporter.hxx
new file mode 100644
index 000000000000..01cd94d264c9
--- /dev/null
+++ b/include/filter/pdfimporter/PDFImporter.hxx
@@ -0,0 +1,45 @@
+/* -*- 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 <vcl/filter/PDFiumLibrary.hxx>
+#include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
+#include <vcl/BinaryDataContainer.hxx>
+
+class PDFImporter
+{
+private:
+    std::shared_ptr<vcl::pdf::PDFium> mpPDFium;
+    std::unique_ptr<vcl::pdf::PDFiumDocument> mpPdfDocument;
+    std::unique_ptr<vcl::pdf::PDFiumPage> mpPdfPage;
+
+    void importPdfObject(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& 
pPageObject,
+                         std::unique_ptr<vcl::pdf::PDFiumTextPage> const& 
pTextPage,
+                         int nPageObjectIndex,
+                         drawinglayer::primitive2d::Primitive2DContainer& 
rRootContainer);
+
+    void importText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& 
pPageObject,
+                    std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
+                    drawinglayer::primitive2d::Primitive2DContainer& 
rRootContainer);
+
+    void importPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& 
pPageObject,
+                    drawinglayer::primitive2d::Primitive2DContainer& 
rRootContainer);
+
+    void importImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& 
pPageObject,
+                     drawinglayer::primitive2d::Primitive2DContainer& 
rRootContainer);
+
+public:
+    PDFImporter(BinaryDataContainer& rDataContainer);
+
+    bool importPage(int nPageIndex, 
drawinglayer::primitive2d::Primitive2DContainer& rContainer);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit ef3955dc585d2126298972137d2578fd41f5419d
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Mar 18 15:59:20 2021 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:37:59 2022 +0200

    vcl: bring back RGB565 scanline transformer
    
    While we don't support this as a Bitmap format anymore, we still
    need to transform a buffer that is in RGB565 format in some cases.
    For example backwards compatibility or if a certain bitmap format
    supports such pixel format.
    This change also simplifies some scanline transformers by removing
    code duplication.
    
    Change-Id: I64aa258b8b1fbebf0ed174c0d5fdd2f75f382b28

diff --git a/vcl/inc/bitmap/ScanlineTools.hxx b/vcl/inc/bitmap/ScanlineTools.hxx
index c343cf34f61e..dc305937b5fd 100644
--- a/vcl/inc/bitmap/ScanlineTools.hxx
+++ b/vcl/inc/bitmap/ScanlineTools.hxx
@@ -16,7 +16,7 @@
 
 namespace vcl::bitmap
 {
-class ScanlineTransformer
+class IScanlineTransformer
 {
 public:
     virtual void startLine(sal_uInt8* pLine) = 0;
@@ -24,127 +24,162 @@ public:
     virtual Color readPixel() = 0;
     virtual void writePixel(Color nColor) = 0;
 
-    virtual ~ScanlineTransformer() = default;
+    virtual ~IScanlineTransformer() = default;
 };
 
-class ScanlineTransformer_ARGB final : public ScanlineTransformer
+class ScanlineTransformer_RGB565 final : public IScanlineTransformer
 {
-private:
-    sal_uInt8* pData;
+protected:
+    sal_uInt16* mpData;
 
 public:
-    virtual void startLine(sal_uInt8* pLine) override { pData = pLine; }
+    void startLine(sal_uInt8* pLine) override { mpData = 
reinterpret_cast<sal_uInt16*>(pLine); }
 
-    virtual void skipPixel(sal_uInt32 nPixel) override { pData += nPixel << 2; 
}
+    void skipPixel(sal_uInt32 nPixel) override { mpData += nPixel; }
 
-    virtual Color readPixel() override
+    Color readPixel() override
     {
-        const Color aColor(ColorTransparency, pData[4], pData[1], pData[2], 
pData[3]);
-        pData += 4;
-        return aColor;
+        sal_uInt8 R = sal_uInt8((*mpData & 0xf800) >> 8);
+        sal_uInt8 G = sal_uInt8((*mpData & 0x07e0) >> 3);
+        sal_uInt8 B = sal_uInt8((*mpData & 0x001f) << 3);
+        mpData++;
+        return Color(R, G, B);
     }
 
-    virtual void writePixel(Color nColor) override
+    void writePixel(Color nColor) override
     {
-        *pData++ = 255 - nColor.GetAlpha();
-        *pData++ = nColor.GetRed();
-        *pData++ = nColor.GetGreen();
-        *pData++ = nColor.GetBlue();
+        sal_uInt16 R = (nColor.GetRed() & 0xf8) << 8;
+        sal_uInt16 G = (nColor.GetGreen() & 0xfc) << 3;
+        sal_uInt16 B = (nColor.GetBlue() & 0xf8) >> 3;
+        *mpData++ = R | G | B;
     }
 };
 
-class ScanlineTransformer_BGR final : public ScanlineTransformer
+class ScanlineTransformerBase : public IScanlineTransformer
 {
-private:
-    sal_uInt8* pData;
+protected:
+    sal_uInt8* mpData;
 
 public:
-    virtual void startLine(sal_uInt8* pLine) override { pData = pLine; }
+    ScanlineTransformerBase()
+        : mpData(nullptr)
+    {
+    }
+
+    void startLine(sal_uInt8* pLine) override { mpData = pLine; }
+};
 
-    virtual void skipPixel(sal_uInt32 nPixel) override { pData += (nPixel << 
1) + nPixel; }
+class ScanlineTransformer_ARGB final : public ScanlineTransformerBase
+{
+public:
+    void skipPixel(sal_uInt32 nPixel) override { mpData += nPixel << 2; }
 
-    virtual Color readPixel() override
+    Color readPixel() override
     {
-        const Color aColor(pData[2], pData[1], pData[0]);
-        pData += 3;
+        const Color aColor(ColorTransparency, mpData[4], mpData[1], mpData[2], 
mpData[3]);
+        mpData += 4;
         return aColor;
     }
 
-    virtual void writePixel(Color nColor) override
+    void writePixel(Color nColor) override
     {
-        *pData++ = nColor.GetBlue();
-        *pData++ = nColor.GetGreen();
-        *pData++ = nColor.GetRed();
+        *mpData++ = 255 - nColor.GetAlpha();
+        *mpData++ = nColor.GetRed();
+        *mpData++ = nColor.GetGreen();
+        *mpData++ = nColor.GetBlue();
     }
 };
 
-class ScanlineTransformer_8BitPalette final : public ScanlineTransformer
+class ScanlineTransformer_BGR final : public ScanlineTransformerBase
 {
-private:
-    sal_uInt8* pData;
+public:
+    void skipPixel(sal_uInt32 nPixel) override { mpData += (nPixel << 1) + 
nPixel; }
+
+    Color readPixel() override
+    {
+        const Color aColor(mpData[2], mpData[1], mpData[0]);
+        mpData += 3;
+        return aColor;
+    }
+
+    void writePixel(Color nColor) override
+    {
+        *mpData++ = nColor.GetBlue();
+        *mpData++ = nColor.GetGreen();
+        *mpData++ = nColor.GetRed();
+    }
+};
+
+class ScanlineTransformerPaletteBase : public ScanlineTransformerBase
+{
+protected:
     const BitmapPalette& mrPalette;
 
 public:
-    explicit ScanlineTransformer_8BitPalette(const BitmapPalette& rPalette)
-        : pData(nullptr)
+    ScanlineTransformerPaletteBase(const BitmapPalette& rPalette)
+        : ScanlineTransformerBase()
         , mrPalette(rPalette)
     {
     }
+};
 
-    virtual void startLine(sal_uInt8* pLine) override { pData = pLine; }
+class ScanlineTransformer_8BitPalette final : public 
ScanlineTransformerPaletteBase
+{
+public:
+    explicit ScanlineTransformer_8BitPalette(const BitmapPalette& rPalette)
+        : ScanlineTransformerPaletteBase(rPalette)
+    {
+    }
 
-    virtual void skipPixel(sal_uInt32 nPixel) override { pData += nPixel; }
+    void skipPixel(sal_uInt32 nPixel) override { mpData += nPixel; }
 
-    virtual Color readPixel() override
+    Color readPixel() override
     {
-        const sal_uInt8 nIndex(*pData++);
+        const sal_uInt8 nIndex(*mpData++);
         if (nIndex < mrPalette.GetEntryCount())
             return mrPalette[nIndex];
         else
             return COL_BLACK;
     }
 
-    virtual void writePixel(Color nColor) override
+    void writePixel(Color nColor) override
     {
-        *pData++ = static_cast<sal_uInt8>(mrPalette.GetBestIndex(nColor));
+        *mpData++ = static_cast<sal_uInt8>(mrPalette.GetBestIndex(nColor));
     }
 };
 
-class ScanlineTransformer_4BitPalette final : public ScanlineTransformer
+class ScanlineTransformer_4BitPalette final : public 
ScanlineTransformerPaletteBase
 {
 private:
-    sal_uInt8* pData;
-    const BitmapPalette& mrPalette;
     sal_uInt32 mnX;
     sal_uInt32 mnShift;
 
 public:
     explicit ScanlineTransformer_4BitPalette(const BitmapPalette& rPalette)
-        : pData(nullptr)
-        , mrPalette(rPalette)
+        : ScanlineTransformerPaletteBase(rPalette)
         , mnX(0)
         , mnShift(0)
     {
     }
 
-    virtual void skipPixel(sal_uInt32 nPixel) override
+    void skipPixel(sal_uInt32 nPixel) override
     {
         mnX += nPixel;
         if (nPixel & 1) // is nPixel an odd number
             mnShift ^= 4;
     }
 
-    virtual void startLine(sal_uInt8* pLine) override
+    void startLine(sal_uInt8* pLine) override
     {
-        pData = pLine;
+        ScanlineTransformerBase::startLine(pLine);
         mnX = 0;
         mnShift = 4;
     }
 
-    virtual Color readPixel() override
+    Color readPixel() override
     {
         const sal_uInt32 nDataIndex = mnX / 2;
-        const sal_uInt8 nIndex((pData[nDataIndex] >> mnShift) & 0x0f);
+        const sal_uInt8 nIndex((mpData[nDataIndex] >> mnShift) & 0x0f);
         mnX++;
         mnShift ^= 4;
 
@@ -154,42 +189,39 @@ public:
             return COL_BLACK;
     }
 
-    virtual void writePixel(Color nColor) override
+    void writePixel(Color nColor) override
     {
         const sal_uInt32 nDataIndex = mnX / 2;
         const sal_uInt8 nColorIndex = mrPalette.GetBestIndex(nColor);
-        pData[nDataIndex] |= (nColorIndex & 0x0f) << mnShift;
+        mpData[nDataIndex] |= (nColorIndex & 0x0f) << mnShift;
         mnX++;
         mnShift ^= 4;
     }
 };
 
-class ScanlineTransformer_1BitPalette final : public ScanlineTransformer
+class ScanlineTransformer_1BitPalette final : public 
ScanlineTransformerPaletteBase
 {
 private:
-    sal_uInt8* pData;
-    const BitmapPalette& mrPalette;
     sal_uInt32 mnX;
 
 public:
     explicit ScanlineTransformer_1BitPalette(const BitmapPalette& rPalette)
-        : pData(nullptr)
-        , mrPalette(rPalette)
+        : ScanlineTransformerPaletteBase(rPalette)
         , mnX(0)
     {
     }
 
-    virtual void skipPixel(sal_uInt32 nPixel) override { mnX += nPixel; }
+    void skipPixel(sal_uInt32 nPixel) override { mnX += nPixel; }
 
-    virtual void startLine(sal_uInt8* pLine) override
+    void startLine(sal_uInt8* pLine) override
     {
-        pData = pLine;
+        ScanlineTransformerBase::startLine(pLine);
         mnX = 0;
     }
 
-    virtual Color readPixel() override
+    Color readPixel() override
     {
-        const sal_uInt8 nIndex((pData[mnX >> 3] >> (7 - (mnX & 7))) & 1);
+        const sal_uInt8 nIndex((mpData[mnX >> 3] >> (7 - (mnX & 7))) & 1);
         mnX++;
 
         if (nIndex < mrPalette.GetEntryCount())
@@ -198,18 +230,18 @@ public:
             return COL_BLACK;
     }
 
-    virtual void writePixel(Color nColor) override
+    void writePixel(Color nColor) override
     {
         if (mrPalette.GetBestIndex(nColor) & 1)
-            pData[mnX >> 3] |= 1 << (7 - (mnX & 7));
+            mpData[mnX >> 3] |= 1 << (7 - (mnX & 7));
         else
-            pData[mnX >> 3] &= ~(1 << (7 - (mnX & 7)));
+            mpData[mnX >> 3] &= ~(1 << (7 - (mnX & 7)));
         mnX++;
     }
 };
 
-std::unique_ptr<ScanlineTransformer> getScanlineTransformer(sal_uInt16 nBits,
-                                                            const 
BitmapPalette& rPalette)
+std::unique_ptr<IScanlineTransformer> getScanlineTransformer(sal_uInt16 nBits,
+                                                             const 
BitmapPalette& rPalette)
 {
     switch (nBits)
     {
@@ -219,6 +251,8 @@ std::unique_ptr<ScanlineTransformer> 
getScanlineTransformer(sal_uInt16 nBits,
             return std::make_unique<ScanlineTransformer_4BitPalette>(rPalette);
         case 8:
             return std::make_unique<ScanlineTransformer_8BitPalette>(rPalette);
+        case 16:
+            return std::make_unique<ScanlineTransformer_RGB565>();
         case 24:
             return std::make_unique<ScanlineTransformer_BGR>();
         case 32:
diff --git a/vcl/qa/cppunit/ScanlineToolsTest.cxx 
b/vcl/qa/cppunit/ScanlineToolsTest.cxx
index c6751b827ca1..6f497b2b8295 100644
--- a/vcl/qa/cppunit/ScanlineToolsTest.cxx
+++ b/vcl/qa/cppunit/ScanlineToolsTest.cxx
@@ -19,6 +19,7 @@ class ScanlineToolsTest : public CppUnit::TestFixture
 {
     void ScanlineTransformer_32_ARGB();
     void ScanlineTransformer_24_BGR();
+    void ScanlineTransformer_16_RGB565();
     void ScanlineTransformer_8bit_Palette();
     void ScanlineTransformer_4bit_Palette();
     void ScanlineTransformer_1bit_Palette();
@@ -26,6 +27,7 @@ class ScanlineToolsTest : public CppUnit::TestFixture
     CPPUNIT_TEST_SUITE(ScanlineToolsTest);
     CPPUNIT_TEST(ScanlineTransformer_32_ARGB);
     CPPUNIT_TEST(ScanlineTransformer_24_BGR);
+    CPPUNIT_TEST(ScanlineTransformer_16_RGB565);
     CPPUNIT_TEST(ScanlineTransformer_8bit_Palette);
     CPPUNIT_TEST(ScanlineTransformer_4bit_Palette);
     CPPUNIT_TEST(ScanlineTransformer_1bit_Palette);
@@ -35,8 +37,7 @@ class ScanlineToolsTest : public CppUnit::TestFixture
 void ScanlineToolsTest::ScanlineTransformer_32_ARGB()
 {
     BitmapPalette aPalette;
-    std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
-        = vcl::bitmap::getScanlineTransformer(32, aPalette);
+    auto pScanlineTransformer = vcl::bitmap::getScanlineTransformer(32, 
aPalette);
 
     std::vector<sal_uInt8> aScanLine(5 * 4, 0); // 5 * 4 BytesPerPixel
     pScanlineTransformer->startLine(aScanLine.data());
@@ -64,8 +65,7 @@ void ScanlineToolsTest::ScanlineTransformer_32_ARGB()
 void ScanlineToolsTest::ScanlineTransformer_24_BGR()
 {
     BitmapPalette aPalette;
-    std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
-        = vcl::bitmap::getScanlineTransformer(24, aPalette);
+    auto pScanlineTransformer = vcl::bitmap::getScanlineTransformer(24, 
aPalette);
 
     std::vector<sal_uInt8> aScanLine(5 * 3, 0); // 5 * 3 BytesPerPixel
     pScanlineTransformer->startLine(aScanLine.data());
@@ -90,6 +90,51 @@ void ScanlineToolsTest::ScanlineTransformer_24_BGR()
     }
 }
 
+void ScanlineToolsTest::ScanlineTransformer_16_RGB565()
+{
+    BitmapPalette aPalette;
+    auto pScanlineTransformer = vcl::bitmap::getScanlineTransformer(16, 
aPalette);
+
+    // Test writing - we apply colors which will be written into the scanline
+    // in the R5G6B5 format
+    std::vector<sal_uInt8> aScanLine(5 * 2, 0); // 5 * 2 BytesPerPixel
+    pScanlineTransformer->startLine(aScanLine.data());
+
+    std::vector<Color> aColors{
+        Color(ColorTransparency, 0, 10, 250, 120),   Color(ColorTransparency, 
50, 30, 230, 110),
+        Color(ColorTransparency, 100, 50, 210, 100), Color(ColorTransparency, 
150, 70, 190, 90),
+        Color(ColorTransparency, 200, 90, 170, 80),
+    };
+
+    for (Color const& aColor : aColors)
+    {
+        pScanlineTransformer->writePixel(aColor);
+    }
+
+    std::vector<sal_uInt8> aExpectedBytes{ 207, 15, 45, 31, 140, 54, 235, 69, 
74, 93 };
+
+    for (size_t i = 0; i < aScanLine.size(); ++i)
+    {
+        CPPUNIT_ASSERT_EQUAL(int(aExpectedBytes[i]), int(aScanLine[i]));
+    }
+
+    // Test reading - we insert a scanline in R5G6B5 format and read
+    // the colors from it
+
+    pScanlineTransformer->startLine(aScanLine.data());
+
+    std::vector<Color> aExpectedColors{
+        Color(8, 248, 120), Color(24, 228, 104), Color(48, 208, 96),
+        Color(64, 188, 88), Color(88, 168, 80),
+    };
+
+    for (size_t i = 0; i < aExpectedColors.size(); ++i)
+    {
+        Color aColor = pScanlineTransformer->readPixel();
+        CPPUNIT_ASSERT_EQUAL(aExpectedColors[i], aColor);
+    }
+}
+
 void ScanlineToolsTest::ScanlineTransformer_8bit_Palette()
 {
     std::vector<Color> aColors{
@@ -102,8 +147,7 @@ void ScanlineToolsTest::ScanlineTransformer_8bit_Palette()
     for (size_t i = 0; i < aColors.size(); ++i)
         aPalette[i] = aColors[i];
 
-    std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
-        = vcl::bitmap::getScanlineTransformer(8, aPalette);
+    auto pScanlineTransformer = vcl::bitmap::getScanlineTransformer(8, 
aPalette);
 
     std::vector<sal_uInt8> aScanLine(5, 0); // 5 * 1 BytesPerPixel
     pScanlineTransformer->startLine(aScanLine.data());
@@ -142,8 +186,7 @@ void ScanlineToolsTest::ScanlineTransformer_4bit_Palette()
         aPalette[i] = aColors[i];
     }
 
-    std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
-        = vcl::bitmap::getScanlineTransformer(4, aPalette);
+    auto pScanlineTransformer = vcl::bitmap::getScanlineTransformer(4, 
aPalette);
 
     std::vector<sal_uInt8> aScanLine(3, 0); // 6 * 0.5 BytesPerPixel
     pScanlineTransformer->startLine(aScanLine.data());
@@ -182,8 +225,7 @@ void ScanlineToolsTest::ScanlineTransformer_1bit_Palette()
     aPalette[0] = Color(10, 250, 120);
     aPalette[1] = Color(110, 150, 70);
 
-    std::unique_ptr<vcl::bitmap::ScanlineTransformer> pScanlineTransformer
-        = vcl::bitmap::getScanlineTransformer(1, aPalette);
+    auto pScanlineTransformer = vcl::bitmap::getScanlineTransformer(1, 
aPalette);
 
     std::vector<sal_uInt8> aScanLine(2, 0); // 13 * 1/8 BytesPerPixel
     pScanlineTransformer->startLine(aScanLine.data());
commit 0a12f4fadb5a102c8e18d4e8a35eac209e2f6ebb
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sun Mar 7 13:48:39 2021 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jul 5 12:37:59 2022 +0200

    vcl: add PNG writer based on libpng
    
    Change-Id: I52ffd1b286162ee0dd9f694c4f3210385f71daf8

diff --git a/include/vcl/filter/PngImageWriter.hxx 
b/include/vcl/filter/PngImageWriter.hxx
new file mode 100644
index 000000000000..4f64a028af53
--- /dev/null
+++ b/include/vcl/filter/PngImageWriter.hxx
@@ -0,0 +1,50 @@
+/* -*- 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 <vcl/dllapi.h>
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <tools/stream.hxx>
+#include <vcl/bitmapex.hxx>
+
+#pragma once
+
+namespace vcl
+{
+class VCL_DLLPUBLIC PngImageWriter
+{
+    SvStream& mrStream;
+    css::uno::Reference<css::task::XStatusIndicator> mxStatusIndicator;
+
+    int mnCompressionLevel;
+    bool mbInterlaced;
+
+public:
+    PngImageWriter(SvStream& rStream);
+
+    virtual ~PngImageWriter() {}
+
+    void setParameters(css::uno::Sequence<css::beans::PropertyValue> const& 
rParameters)
+    {
+        for (auto const& rValue : rParameters)
+        {
+            if (rValue.Name == "Compression")
+                rValue.Value >>= mnCompressionLevel;
+            else if (rValue.Name == "Interlaced")
+                rValue.Value >>= mbInterlaced;
+        }
+    }
+    bool write(BitmapEx& rBitmap);
+};
+
+} // namespace vcl
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 2cdbc1df0bba..37fcb7b6bfa5 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -474,6 +474,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/filter/wmf/wmfexternal \
     vcl/source/filter/wmf/wmfwr \
     vcl/source/filter/png/PngImageReader \
+    vcl/source/filter/png/PngImageWriter \
     vcl/source/filter/png/pngwrite \
     vcl/source/filter/webp/reader \
     vcl/source/filter/webp/writer \
diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx 
b/vcl/qa/cppunit/png/PngFilterTest.cxx
index c167c4c9c636..1c5f29b40abe 100644
--- a/vcl/qa/cppunit/png/PngFilterTest.cxx
+++ b/vcl/qa/cppunit/png/PngFilterTest.cxx
@@ -24,14 +24,20 @@
 #include <test/bootstrapfixture.hxx>
 #include <tools/stream.hxx>
 #include <vcl/filter/PngImageReader.hxx>
+#include <vcl/filter/PngImageWriter.hxx>
 #include <vcl/BitmapReadAccess.hxx>
+#include <bitmap/BitmapWriteAccess.hxx>
 #include <vcl/alpha.hxx>
 #include <vcl/graphicfilter.hxx>
+#include <unotools/tempfile.hxx>
 
 using namespace css;
 
 class PngFilterTest : public test::BootstrapFixture
 {
+    // Should keep the temp files (should be false)
+    static constexpr bool bKeepTemp = true;
+
     OUString maDataUrl;
 
     OUString getFullUrl(std::u16string_view sFileName)
@@ -48,10 +54,16 @@ public:
 
     void testPng();
     void testMsGifInPng();
+    void testPngRoundtrip8BitGrey();
+    void testPngRoundtrip24();
+    void testPngRoundtrip32();
 
     CPPUNIT_TEST_SUITE(PngFilterTest);
     CPPUNIT_TEST(testPng);
     CPPUNIT_TEST(testMsGifInPng);
+    CPPUNIT_TEST(testPngRoundtrip8BitGrey);
+    CPPUNIT_TEST(testPngRoundtrip24);
+    CPPUNIT_TEST(testPngRoundtrip32);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -245,6 +257,106 @@ void PngFilterTest::testMsGifInPng()
     CPPUNIT_ASSERT(aGraphic.IsAnimated());
 }
 
+void PngFilterTest::testPngRoundtrip8BitGrey()
+{
+    utl::TempFile aTempFile("testPngRoundtrip8BitGrey");
+    if (!bKeepTemp)
+        aTempFile.EnableKillingFile();
+    {
+        SvStream& rStream = *aTempFile.GetStream(StreamMode::WRITE);
+        Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N8_BPP, 
&Bitmap::GetGreyPalette(256));
+        {
+            BitmapScopedWriteAccess pWriteAccess(aBitmap);
+            pWriteAccess->Erase(COL_BLACK);
+            for (int i = 0; i < 8; ++i)
+            {
+                for (int j = 0; j < 8; ++j)
+                {
+                    pWriteAccess->SetPixel(i, j, COL_GRAY);
+                }
+            }
+            for (int i = 8; i < 16; ++i)
+            {
+                for (int j = 8; j < 16; ++j)
+                {
+                    pWriteAccess->SetPixel(i, j, COL_LIGHTGRAY);
+                }
+            }
+        }
+        BitmapEx aBitmapEx(aBitmap);
+
+        vcl::PngImageWriter aPngWriter(rStream);
+        CPPUNIT_ASSERT_EQUAL(true, aPngWriter.write(aBitmapEx));
+        aTempFile.CloseStream();
+    }
+    {
+        SvStream& rStream = *aTempFile.GetStream(StreamMode::READ);
+
+        vcl::PngImageReader aPngReader(rStream);
+        BitmapEx aBitmapEx;
+        CPPUNIT_ASSERT_EQUAL(true, aPngReader.read(aBitmapEx));
+
+        CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Width());
+        CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Height());
+
+        CPPUNIT_ASSERT_EQUAL(COL_GRAY, aBitmapEx.GetPixelColor(0, 0));
+        CPPUNIT_ASSERT_EQUAL(COL_LIGHTGRAY, aBitmapEx.GetPixelColor(15, 15));
+        CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmapEx.GetPixelColor(15, 0));
+        CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmapEx.GetPixelColor(0, 15));
+    }
+}
+
+void PngFilterTest::testPngRoundtrip24()
+{
+    utl::TempFile aTempFile("testPngRoundtrip24");
+    if (!bKeepTemp)
+        aTempFile.EnableKillingFile();
+    {
+        SvStream& rStream = *aTempFile.GetStream(StreamMode::WRITE);
+        Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
+        {
+            BitmapScopedWriteAccess pWriteAccess(aBitmap);
+            pWriteAccess->Erase(COL_BLACK);
+            for (int i = 0; i < 8; ++i)
+            {
+                for (int j = 0; j < 8; ++j)
+                {
+                    pWriteAccess->SetPixel(i, j, COL_LIGHTRED);
+                }
+            }
+            for (int i = 8; i < 16; ++i)
+            {
+                for (int j = 8; j < 16; ++j)
+                {
+                    pWriteAccess->SetPixel(i, j, COL_LIGHTBLUE);
+                }
+            }
+        }
+        BitmapEx aBitmapEx(aBitmap);
+
+        vcl::PngImageWriter aPngWriter(rStream);
+        CPPUNIT_ASSERT_EQUAL(true, aPngWriter.write(aBitmapEx));
+    }
+    {
+        SvStream& rStream = *aTempFile.GetStream(StreamMode::READ);
+        rStream.Seek(0);
+
+        vcl::PngImageReader aPngReader(rStream);
+        BitmapEx aBitmapEx;
+        CPPUNIT_ASSERT_EQUAL(true, aPngReader.read(aBitmapEx));
+
+        CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Width());
+        CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Height());
+
+        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmapEx.GetPixelColor(0, 0));
+        CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmapEx.GetPixelColor(15, 15));
+        CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmapEx.GetPixelColor(15, 0));
+        CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmapEx.GetPixelColor(0, 15));
+    }
+}
+
+void PngFilterTest::testPngRoundtrip32() {}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(PngFilterTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/filter/png/PngImageWriter.cxx 
b/vcl/source/filter/png/PngImageWriter.cxx
new file mode 100644
index 000000000000..c1e638e0aad0
--- /dev/null
+++ b/vcl/source/filter/png/PngImageWriter.cxx
@@ -0,0 +1,143 @@
+/* -*- 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 <vcl/filter/PngImageWriter.hxx>
+#include <png.h>
+#include <bitmap/BitmapWriteAccess.hxx>
+#include <vcl/bitmap.hxx>
+
+namespace vcl
+{
+static void lclWriteStream(png_structp pPng, png_bytep pData, png_size_t 
pDataSize)
+{
+    png_voidp pIO = png_get_io_ptr(pPng);
+
+    if (pIO == nullptr)
+        return;
+
+    SvStream* pStream = static_cast<SvStream*>(pIO);
+
+    sal_Size nBytesWritten = pStream->WriteBytes(pData, pDataSize);
+
+    if (nBytesWritten != pDataSize)
+        png_error(pPng, "Write Error");
+}
+

... etc. - the rest is truncated

Reply via email to