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

panoskorovesis (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 9 09:48:54 UTC 2021


 include/vcl/filter/SvmReader.hxx    |    1 
 include/vcl/metaact.hxx             |    5 ++
 vcl/source/filter/svm/SvmReader.cxx |   81 +++++++++++++++++++++++++++++++++++-
 vcl/source/gdi/metaact.cxx          |   11 ++++
 4 files changed, 97 insertions(+), 1 deletion(-)

New commits:
commit 58a064595e43428f7d74341aff38df40fec0c8b3
Author:     panoskorovesis <panoskorovesis at outlook.com>
AuthorDate: Thu Jul 8 12:51:11 2021 +0300
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Jul 9 11:48:22 2021 +0200

    Add Handler for MetaTextArray Read
    
    The handler separates the MetaTextArrayAction::Read from metaact.hxx
    Read implementation is now in SvmReader.hxx
    
    Change-Id: Ie74ef5b2e44d48c8c8a6d8efe9adda956cde4d3a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118633
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/filter/SvmReader.hxx b/include/vcl/filter/SvmReader.hxx
index ea3d9a31fd63..7baae24379b0 100644
--- a/include/vcl/filter/SvmReader.hxx
+++ b/include/vcl/filter/SvmReader.hxx
@@ -52,6 +52,7 @@ public:
     rtl::Reference<MetaAction> PolygonHandler();
     rtl::Reference<MetaAction> PolyPolygonHandler();
     rtl::Reference<MetaAction> TextHandler(ImplMetaReadData* pData);
+    rtl::Reference<MetaAction> TextArrayHandler(ImplMetaReadData* pData);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/metaact.hxx b/include/vcl/metaact.hxx
index 96c15ff23213..28a5373329c6 100644
--- a/include/vcl/metaact.hxx
+++ b/include/vcl/metaact.hxx
@@ -563,6 +563,11 @@ public:
     sal_Int32       GetIndex() const { return mnIndex; }
     sal_Int32       GetLen() const { return mnLen; }
     tools::Long*           GetDXArray() const { return mpDXAry.get(); }
+    void            SetPoint(Point& rPt) { maStartPt = rPt; }
+    void            SetText(OUString& rStr) { maStr = rStr; }
+    void            SetIndex(sal_Int32 rIndex) { mnIndex = rIndex; }
+    void            SetLen(sal_Int32 rLen) { mnLen = rLen; }
+    void            SetDXArray(tools::Long* rDXAry);
 };
 
 class SAL_DLLPUBLIC_RTTI MetaStretchTextAction final : public MetaAction
diff --git a/vcl/source/filter/svm/SvmReader.cxx b/vcl/source/filter/svm/SvmReader.cxx
index 6fbd043d9ad1..74919c3b17d1 100644
--- a/vcl/source/filter/svm/SvmReader.cxx
+++ b/vcl/source/filter/svm/SvmReader.cxx
@@ -198,7 +198,7 @@ rtl::Reference<MetaAction> SvmReader::MetaActionHandler(ImplMetaReadData* pData)
             return TextHandler(pData);
             break;
         case MetaActionType::TEXTARRAY:
-            pAction = new MetaTextArrayAction;
+            return TextArrayHandler(pData);
             break;
         case MetaActionType::STRETCHTEXT:
             pAction = new MetaStretchTextAction;
@@ -666,4 +666,83 @@ rtl::Reference<MetaAction> SvmReader::TextHandler(ImplMetaReadData* pData)
 
     return pAction;
 }
+
+rtl::Reference<MetaAction> SvmReader::TextArrayHandler(ImplMetaReadData* pData)
+{
+    auto pAction = new MetaTextArrayAction();
+
+    std::unique_ptr<tools::Long[]> aArray;
+    aArray.reset();
+
+    VersionCompatRead aCompat(mrStream);
+    TypeSerializer aSerializer(mrStream);
+
+    Point aPoint;
+    aSerializer.readPoint(aPoint);
+    pAction->SetPoint(aPoint);
+
+    OUString aStr;
+    aStr = mrStream.ReadUniOrByteString(pData->meActualCharSet);
+    pAction->SetText(aStr);
+
+    sal_uInt16 nTmpIndex(0);
+    mrStream.ReadUInt16(nTmpIndex);
+    pAction->SetIndex(nTmpIndex);
+
+    sal_uInt16 nTmpLen(0);
+    mrStream.ReadUInt16(nTmpLen);
+    pAction->SetLen(nTmpLen);
+
+    sal_Int32 nAryLen(0);
+    mrStream.ReadInt32(nAryLen);
+
+    if (nTmpLen > aStr.getLength() - nTmpIndex)
+    {
+        pAction->SetIndex(0);
+        pAction->SetDXArray(nullptr);
+        return pAction;
+    }
+    if (nAryLen)
+    {
+        // #i9762#, #106172# Ensure that DX array is at least mnLen entries long
+        if (nTmpLen >= nAryLen)
+        {
+            aArray.reset(new (std::nothrow) tools::Long[nTmpLen]);
+            if (aArray)
+            {
+                sal_Int32 i;
+                sal_Int32 val;
+                for (i = 0; i < nAryLen; i++)
+                {
+                    mrStream.ReadInt32(val);
+                    aArray[i] = val;
+                }
+                // #106172# setup remainder
+                for (; i < nTmpLen; i++)
+                    aArray[i] = 0;
+            }
+        }
+        else
+        {
+            pAction->SetDXArray(nullptr);
+            return pAction;
+        }
+    }
+    else
+        pAction->SetDXArray(nullptr);
+
+    if (aCompat.GetVersion() >= 2) // Version 2
+    {
+        aStr = read_uInt16_lenPrefixed_uInt16s_ToOUString(mrStream);
+
+        if (nTmpIndex + nTmpLen > aStr.getLength())
+        {
+            pAction->SetIndex(0);
+            aArray.reset();
+        }
+    }
+
+    pAction->SetDXArray(aArray.get());
+    return pAction;
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/metaact.cxx b/vcl/source/gdi/metaact.cxx
index 20325ed90e33..bd3c6d60681f 100644
--- a/vcl/source/gdi/metaact.cxx
+++ b/vcl/source/gdi/metaact.cxx
@@ -1242,6 +1242,17 @@ void MetaTextArrayAction::Read( SvStream& rIStm, ImplMetaReadData* pData )
     }
 }
 
+void MetaTextArrayAction::SetDXArray(tools::Long* pDXAry)
+{
+    const sal_Int32 nAryLen = pDXAry ? mnLen : 0;
+
+    if (nAryLen > 0)
+    {
+        mpDXAry.reset( new tools::Long[ nAryLen ] );
+        memcpy( mpDXAry.get(), pDXAry, nAryLen * sizeof(tools::Long) );
+    }
+}
+
 MetaStretchTextAction::MetaStretchTextAction() :
     MetaAction  ( MetaActionType::STRETCHTEXT ),
     mnWidth     ( 0 ),


More information about the Libreoffice-commits mailing list