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

Miklos Vajna vmiklos at collabora.co.uk
Tue Mar 27 13:00:33 UTC 2018


 filter/source/msfilter/rtfutil.cxx          |   32 ++++++++++++++++++++++
 include/filter/msfilter/rtfutil.hxx         |    4 ++
 sw/source/filter/html/htmlreqifreader.cxx   |   27 +------------------
 sw/source/filter/ww8/rtfattributeoutput.cxx |   39 ++--------------------------
 sw/source/filter/ww8/rtfattributeoutput.hxx |    4 --
 sw/source/filter/ww8/rtfsdrexport.cxx       |    6 ++--
 6 files changed, 44 insertions(+), 68 deletions(-)

New commits:
commit 6d05579c7fceb0f3ce83abe25bdfe62b26c29671
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Mar 27 12:06:25 2018 +0200

    msfilter: extract duplicated WriteHex() from HTML/RTF filter
    
    The RtfAttributeOutput one is a superset of the HTML one, so use that.
    
    Change-Id: I3e342113a7ba26946320f43a164e457d6cbb6946
    Reviewed-on: https://gerrit.libreoffice.org/51937
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/filter/source/msfilter/rtfutil.cxx b/filter/source/msfilter/rtfutil.cxx
index 8ac044032163..2cad73a20a97 100644
--- a/filter/source/msfilter/rtfutil.cxx
+++ b/filter/source/msfilter/rtfutil.cxx
@@ -204,6 +204,38 @@ int AsHex(char ch)
     return ret;
 }
 
+OString WriteHex(const sal_uInt8* pData, sal_uInt32 nSize, SvStream* pStream, sal_uInt32 nLimit)
+{
+    OStringBuffer aRet;
+
+    sal_uInt32 nBreak = 0;
+    for (sal_uInt32 i = 0; i < nSize; i++)
+    {
+        OString sNo = OString::number(pData[i], 16);
+        if (sNo.getLength() < 2)
+        {
+            if (pStream)
+                pStream->WriteChar('0');
+            else
+                aRet.append('0');
+        }
+        if (pStream)
+            pStream->WriteCharPtr(sNo.getStr());
+        else
+            aRet.append(sNo);
+        if (++nBreak == nLimit)
+        {
+            if (pStream)
+                pStream->WriteCharPtr(SAL_NEWLINE_STRING);
+            else
+                aRet.append(SAL_NEWLINE_STRING);
+            nBreak = 0;
+        }
+    }
+
+    return aRet.makeStringAndClear();
+}
+
 bool ExtractOLE2FromObjdata(const OString& rObjdata, SvStream& rOle2)
 {
     SvMemoryStream aStream;
diff --git a/include/filter/msfilter/rtfutil.hxx b/include/filter/msfilter/rtfutil.hxx
index 48351d382786..1cadaa94bd50 100644
--- a/include/filter/msfilter/rtfutil.hxx
+++ b/include/filter/msfilter/rtfutil.hxx
@@ -62,6 +62,10 @@ MSFILTER_DLLPUBLIC OString OutStringUpr(const sal_Char* pToken, const OUString&
  */
 MSFILTER_DLLPUBLIC int AsHex(char ch);
 
+/// Writes binary data as a hex dump.
+MSFILTER_DLLPUBLIC OString WriteHex(const sal_uInt8* pData, sal_uInt32 nSize,
+                                    SvStream* pStream = nullptr, sal_uInt32 nLimit = 64);
+
 /**
  * Extract OLE2 data from an \objdata hex dump.
  */
diff --git a/sw/source/filter/html/htmlreqifreader.cxx b/sw/source/filter/html/htmlreqifreader.cxx
index 2a4519119e31..077483ab158b 100644
--- a/sw/source/filter/html/htmlreqifreader.cxx
+++ b/sw/source/filter/html/htmlreqifreader.cxx
@@ -130,30 +130,6 @@ OString InsertOLE1Header(SvStream& rOle2, SvStream& rOle1)
 
     return aClassName;
 }
-
-/// Writes rData on rSteram as a hexdump.
-void WriteHex(SvStream& rStream, SvMemoryStream& rData)
-{
-    rData.Seek(0);
-    sal_uInt64 nSize = rData.remainingSize();
-
-    sal_uInt32 nLimit = 64;
-    sal_uInt32 nBreak = 0;
-
-    for (sal_uInt64 i = 0; i < nSize; i++)
-    {
-        OString sNo = OString::number(static_cast<const sal_uInt8*>(rData.GetBuffer())[i], 16);
-        if (sNo.getLength() < 2)
-            rStream.WriteChar('0');
-        rStream.WriteCharPtr(sNo.getStr());
-
-        if (++nBreak == nLimit)
-        {
-            rStream.WriteCharPtr(SAL_NEWLINE_STRING);
-            nBreak = 0;
-        }
-    }
-}
 }
 
 namespace SwReqIfReader
@@ -199,7 +175,8 @@ bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf)
     // Start objdata.
     rRtf.WriteCharPtr(
         "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_OBJDATA SAL_NEWLINE_STRING);
-    WriteHex(rRtf, aOLE1);
+    msfilter::rtfutil::WriteHex(static_cast<const sal_uInt8*>(aOLE1.GetData()), aOLE1.GetSize(),
+                                &rRtf);
     // End objdata.
     rRtf.WriteCharPtr("}");
     // End object.
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 5340916cd5a9..ff0257873bc4 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -3725,39 +3725,6 @@ static bool StripMetafileHeader(const sal_uInt8*& rpGraphicAry, unsigned long& r
     return false;
 }
 
-OString RtfAttributeOutput::WriteHex(const sal_uInt8* pData, sal_uInt32 nSize, SvStream* pStream,
-                                     sal_uInt32 nLimit)
-{
-    OStringBuffer aRet;
-
-    sal_uInt32 nBreak = 0;
-    for (sal_uInt32 i = 0; i < nSize; i++)
-    {
-        OString sNo = OString::number(pData[i], 16);
-        if (sNo.getLength() < 2)
-        {
-            if (pStream)
-                pStream->WriteChar('0');
-            else
-                aRet.append('0');
-        }
-        if (pStream)
-            pStream->WriteCharPtr(sNo.getStr());
-        else
-            aRet.append(sNo);
-        if (++nBreak == nLimit)
-        {
-            if (pStream)
-                pStream->WriteCharPtr(SAL_NEWLINE_STRING);
-            else
-                aRet.append(SAL_NEWLINE_STRING);
-            nBreak = 0;
-        }
-    }
-
-    return aRet.makeStringAndClear();
-}
-
 static void lcl_AppendSP(OStringBuffer& rBuffer, const char cName[], const OUString& rValue,
                          const RtfExport& rExport)
 {
@@ -3850,9 +3817,9 @@ static OString ExportPICT(const SwFlyFrameFormat* pFlyFrameFormat, const Size& r
         if (pStream)
             pStream->WriteCharPtr(aRet.makeStringAndClear().getStr());
         if (pStream)
-            RtfAttributeOutput::WriteHex(pGraphicAry, nSize, pStream);
+            msfilter::rtfutil::WriteHex(pGraphicAry, nSize, pStream);
         else
-            aRet.append(RtfAttributeOutput::WriteHex(pGraphicAry, nSize));
+            aRet.append(msfilter::rtfutil::WriteHex(pGraphicAry, nSize));
         aRet.append('}');
         if (pStream)
             pStream->WriteCharPtr(aRet.makeStringAndClear().getStr());
@@ -4179,7 +4146,7 @@ void RtfAttributeOutput::BulletDefinition(int /*nId*/, const Graphic& rGraphic,
     aStream.Seek(STREAM_SEEK_TO_END);
     sal_uInt32 nSize = aStream.Tell();
     pGraphicAry = static_cast<sal_uInt8 const*>(aStream.GetData());
-    RtfAttributeOutput::WriteHex(pGraphicAry, nSize, &m_rExport.Strm());
+    msfilter::rtfutil::WriteHex(pGraphicAry, nSize, &m_rExport.Strm());
     m_rExport.Strm().WriteCharPtr("}}"); // pict, shppict
 }
 
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index a29621aa42d7..13c54e387f5e 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -643,10 +643,6 @@ public:
     /// Font pitch.
     void FontPitchType(FontPitch ePitch) const;
 
-    /// Writes binary data as a hex dump.
-    static OString WriteHex(const sal_uInt8* pData, sal_uInt32 nSize, SvStream* pStream = nullptr,
-                            sal_uInt32 nLimit = 64);
-
     void BulletDefinition(int nId, const Graphic& rGraphic, Size aSize) override;
 
     /// Handles just the {\shptxt ...} part of a shape export.
diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx
index 981be1e338c2..ab63e083da44 100644
--- a/sw/source/filter/ww8/rtfsdrexport.cxx
+++ b/sw/source/filter/ww8/rtfsdrexport.cxx
@@ -431,8 +431,8 @@ void RtfSdrExport::Commit(EscherPropertyContainer& rProps, const tools::Rectangl
                     .append(SAL_NEWLINE_STRING);
                 int nHeaderSize
                     = 25; // The first bytes are WW8-specific, we're only interested in the PNG
-                aBuf.append(RtfAttributeOutput::WriteHex(rOpt.pBuf + nHeaderSize,
-                                                         rOpt.nPropSize - nHeaderSize));
+                aBuf.append(msfilter::rtfutil::WriteHex(rOpt.pBuf + nHeaderSize,
+                                                        rOpt.nPropSize - nHeaderSize));
                 aBuf.append('}');
                 m_aShapeProps.insert(
                     std::pair<OString, OString>("fillBlip", aBuf.makeStringAndClear()));
@@ -534,7 +534,7 @@ void RtfSdrExport::impl_writeGraphic()
     aBuf->append(OOO_STRING_SVTOOLS_RTF_PICH)
         .append(sal_Int32(aMapped.Height()))
         .append(SAL_NEWLINE_STRING);
-    aBuf->append(RtfAttributeOutput::WriteHex(pGraphicAry, nSize));
+    aBuf->append(msfilter::rtfutil::WriteHex(pGraphicAry, nSize));
     aBuf->append('}');
     m_aShapeProps.insert(std::pair<OString, OString>("pib", aBuf.makeStringAndClear()));
 }


More information about the Libreoffice-commits mailing list