[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/qa vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Mar 5 10:24:11 UTC 2019


 include/vcl/alpha.hxx                                    |   13 +++------
 vcl/inc/bitmapwriteaccess.hxx                            |    2 -
 vcl/inc/widgetdraw/WidgetDefinition.hxx                  |   16 +++++++++++-
 vcl/inc/widgetdraw/WidgetDefinitionReader.hxx            |   15 ++++++-----
 vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx |    2 -
 vcl/source/gdi/FileDefinitionWidgetDraw.cxx              |   20 ++++++++++++++-
 vcl/source/gdi/WidgetDefinition.cxx                      |    7 +++++
 vcl/source/gdi/WidgetDefinitionReader.cxx                |   17 +++++++++---
 8 files changed, 67 insertions(+), 25 deletions(-)

New commits:
commit 983566119c926d0e2478f74548f00a789de55c15
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Feb 8 21:56:14 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Mar 5 11:23:41 2019 +0100

    Add support for <image> draw definition to draw a SVG image
    
    Attribute "source" is used to get the relative path to the image.
    Path is relative to the definition file.
    
    Change-Id: I6ca0c113385e26ad74b928e1f56635b4b0cef995
    Reviewed-on: https://gerrit.libreoffice.org/68712
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/alpha.hxx b/include/vcl/alpha.hxx
index b4ec04de031a..b0ea775e1516 100644
--- a/include/vcl/alpha.hxx
+++ b/include/vcl/alpha.hxx
@@ -29,7 +29,7 @@
 
 class BitmapEx;
 
-class VCL_DLLPUBLIC AlphaMask : private Bitmap
+class VCL_DLLPUBLIC AlphaMask : public Bitmap
 {
 public:
 
@@ -51,23 +51,18 @@ public:
 
     void        SetPrefSize( const Size& rSize ) { Bitmap::SetPrefSize( rSize ); }
 
-    Size        GetSizePixel() const { return Bitmap::GetSizePixel(); }
-
-    BitmapChecksum   GetChecksum() const { return Bitmap::GetChecksum(); }
-
     Bitmap const & GetBitmap() const;
 
     void        Erase( sal_uInt8 cTransparency );
     void        Replace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency );
     void        Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency );
 
-    BitmapReadAccess*  AcquireReadAccess() { return Bitmap::AcquireReadAccess(); }
-    BitmapWriteAccess* AcquireWriteAccess() { return Bitmap::AcquireWriteAccess(); }
+    BitmapReadAccess*  AcquireAlphaReadAccess() { return Bitmap::AcquireReadAccess(); }
+    BitmapWriteAccess* AcquireAlphaWriteAccess() { return Bitmap::AcquireWriteAccess(); }
 
     void        ReleaseAccess( BitmapReadAccess* pAccess );
 
-    typedef vcl::ScopedBitmapAccess< BitmapReadAccess, AlphaMask, &AlphaMask::AcquireReadAccess >
-        ScopedReadAccess;
+    typedef vcl::ScopedBitmapAccess<BitmapReadAccess, AlphaMask, &AlphaMask::AcquireAlphaReadAccess> ScopedReadAccess;
 
     using Bitmap::IsEmpty;
 
diff --git a/vcl/inc/bitmapwriteaccess.hxx b/vcl/inc/bitmapwriteaccess.hxx
index f20e4e8e2e6e..02ca3f983300 100644
--- a/vcl/inc/bitmapwriteaccess.hxx
+++ b/vcl/inc/bitmapwriteaccess.hxx
@@ -19,7 +19,7 @@
 typedef vcl::ScopedBitmapAccess<BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess>
     BitmapScopedWriteAccess;
 
-typedef vcl::ScopedBitmapAccess<BitmapWriteAccess, AlphaMask, &AlphaMask::AcquireWriteAccess>
+typedef vcl::ScopedBitmapAccess<BitmapWriteAccess, AlphaMask, &AlphaMask::AcquireAlphaWriteAccess>
     AlphaScopedWriteAccess;
 
 class VCL_DLLPUBLIC BitmapWriteAccess : public BitmapReadAccess
diff --git a/vcl/inc/widgetdraw/WidgetDefinition.hxx b/vcl/inc/widgetdraw/WidgetDefinition.hxx
index f1035c694cfe..d3d6c1413992 100644
--- a/vcl/inc/widgetdraw/WidgetDefinition.hxx
+++ b/vcl/inc/widgetdraw/WidgetDefinition.hxx
@@ -28,7 +28,8 @@ enum class DrawCommandType
 {
     RECTANGLE,
     CIRCLE,
-    LINE
+    LINE,
+    IMAGE
 };
 
 class VCL_DLLPUBLIC DrawCommand
@@ -102,6 +103,17 @@ public:
     }
 };
 
+class VCL_DLLPUBLIC ImageDrawCommand : public DrawCommand
+{
+public:
+    OUString msSource;
+
+    ImageDrawCommand()
+        : DrawCommand(DrawCommandType::IMAGE)
+    {
+    }
+};
+
 struct VCL_DLLPUBLIC ControlTypeAndPart
 {
     ControlType const meType;
@@ -162,6 +174,8 @@ public:
 
     void addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2,
                      float fY2);
+
+    void addDrawImage(OUString sSource);
 };
 
 class VCL_DLLPUBLIC WidgetDefinitionPart
diff --git a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx
index 53da5e1a3bed..94c7d49e18cd 100644
--- a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx
+++ b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx
@@ -22,18 +22,19 @@ namespace vcl
 class VCL_DLLPUBLIC WidgetDefinitionReader
 {
 private:
-    OUString m_rFilePath;
+    OUString m_rDefinitionFile;
+    OUString m_rResourcePath;
 
-    static void readDefinition(tools::XmlWalker& rWalker, WidgetDefinition& rWidgetDefinition,
-                               ControlType eType);
+    void readDefinition(tools::XmlWalker& rWalker, WidgetDefinition& rWidgetDefinition,
+                        ControlType eType);
 
-    static void readPart(tools::XmlWalker& rWalker, std::shared_ptr<WidgetDefinitionPart> rpPart);
+    void readPart(tools::XmlWalker& rWalker, std::shared_ptr<WidgetDefinitionPart> rpPart);
 
-    static void readDrawingDefinition(tools::XmlWalker& rWalker,
-                                      std::shared_ptr<WidgetDefinitionState>& rStates);
+    void readDrawingDefinition(tools::XmlWalker& rWalker,
+                               std::shared_ptr<WidgetDefinitionState>& rStates);
 
 public:
-    WidgetDefinitionReader(OUString const& rFilePath);
+    WidgetDefinitionReader(OUString const& rDefinitionFile, OUString const& rResourcePath);
     bool read(WidgetDefinition& rWidgetDefinition);
 };
 
diff --git a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx
index 6f64c95ebd7a..24713e9795b3 100644
--- a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx
+++ b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx
@@ -43,7 +43,7 @@ void WidgetDefinitionReaderTest::testRead()
     CPPUNIT_ASSERT_EQUAL(OUString("000000"), aDefinition.maCheckedColor.AsRGBHexString());
     CPPUNIT_ASSERT_EQUAL(OUString("000000"), aDefinition.maLightColor.AsRGBHexString());
 
-    vcl::WidgetDefinitionReader aReader(getFullUrl("definition1.xml"));
+    vcl::WidgetDefinitionReader aReader(getFullUrl("definition1.xml"), getFullUrl(""));
     aReader.read(aDefinition);
 
     CPPUNIT_ASSERT_EQUAL(OUString("123456"), aDefinition.maFaceColor.AsRGBHexString());
diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
index 6681d2190dd2..a615bd390c81 100644
--- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -18,6 +18,10 @@
 #include <basegfx/range/b2drectangle.hxx>
 #include <basegfx/polygon/b2dpolygontools.hxx>
 
+#include <tools/stream.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/BitmapTools.hxx>
+
 namespace vcl
 {
 namespace
@@ -34,7 +38,8 @@ OUString lcl_getThemeDefinitionPath()
 FileDefinitionWidgetDraw::FileDefinitionWidgetDraw(SalGraphics& rGraphics)
     : m_rGraphics(rGraphics)
 {
-    WidgetDefinitionReader aReader(lcl_getThemeDefinitionPath() + "definition.xml");
+    OUString sDefinitionBasePath = lcl_getThemeDefinitionPath();
+    WidgetDefinitionReader aReader(sDefinitionBasePath + "definition.xml", sDefinitionBasePath);
     aReader.read(m_aWidgetDefinition);
 
     ImplSVData* pSVData = ImplGetSVData();
@@ -171,6 +176,19 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom
                                        0.0f, false, nullptr);
             }
             break;
+            case DrawCommandType::IMAGE:
+            {
+                auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand);
+                SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ);
+                BitmapEx aBitmap;
+                vcl::bitmap::loadFromSvg(aFileStream, "", aBitmap, 1.0);
+                long nImageWidth = aBitmap.GetSizePixel().Width();
+                long nImageHeight = aBitmap.GetSizePixel().Height();
+                SalTwoRect aTR(0, 0, nImageWidth, nImageHeight, nX, nY, nImageWidth, nImageHeight);
+                rGraphics.DrawBitmap(aTR, *aBitmap.GetBitmap().ImplGetSalBitmap().get(),
+                                     *aBitmap.GetAlpha().ImplGetSalBitmap().get(), nullptr);
+            }
+            break;
         }
     }
 }
diff --git a/vcl/source/gdi/WidgetDefinition.cxx b/vcl/source/gdi/WidgetDefinition.cxx
index 2cff3aedd36e..defcf0b84cd8 100644
--- a/vcl/source/gdi/WidgetDefinition.cxx
+++ b/vcl/source/gdi/WidgetDefinition.cxx
@@ -132,6 +132,13 @@ void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWid
     mpDrawCommands.push_back(std::move(pCommand));
 }
 
+void WidgetDefinitionState::addDrawImage(OUString sSource)
+{
+    auto pCommand(std::make_shared<ImageDrawCommand>());
+    pCommand->msSource = sSource;
+    mpDrawCommands.push_back(std::move(pCommand));
+}
+
 } // end vcl namespace
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx
index f37385cc09b9..72bd5649d4db 100644
--- a/vcl/source/gdi/WidgetDefinitionReader.cxx
+++ b/vcl/source/gdi/WidgetDefinitionReader.cxx
@@ -164,8 +164,10 @@ bool getControlTypeForXmlString(OString const& rString, ControlType& reType)
 
 } // end anonymous namespace
 
-WidgetDefinitionReader::WidgetDefinitionReader(OUString const& rFilePath)
-    : m_rFilePath(rFilePath)
+WidgetDefinitionReader::WidgetDefinitionReader(OUString const& rDefinitionFile,
+                                               OUString const& rResourcePath)
+    : m_rDefinitionFile(rDefinitionFile)
+    , m_rResourcePath(rResourcePath)
 {
 }
 
@@ -260,7 +262,12 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker,
 
             rpState->addDrawLine(aStrokeColor, nStrokeWidth, fX1, fY1, fX2, fY2);
         }
-
+        else if (rWalker.name() == "image")
+        {
+            OString sSource = rWalker.attribute("source");
+            rpState->addDrawImage(m_rResourcePath
+                                  + OStringToOUString(sSource, RTL_TEXTENCODING_UTF8));
+        }
         rWalker.next();
     }
     rWalker.parent();
@@ -313,10 +320,10 @@ void WidgetDefinitionReader::readPart(tools::XmlWalker& rWalker,
 
 bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition)
 {
-    if (!lcl_fileExists(m_rFilePath))
+    if (!lcl_fileExists(m_rDefinitionFile))
         return false;
 
-    SvFileStream aFileStream(m_rFilePath, StreamMode::READ);
+    SvFileStream aFileStream(m_rDefinitionFile, StreamMode::READ);
 
     std::unordered_map<OString, Color*> aStyleColorMap = {
         { "faceColor", &rWidgetDefinition.maFaceColor },


More information about the Libreoffice-commits mailing list