summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-03-27 12:06:25 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-03-27 15:00:07 +0200
commit6d05579c7fceb0f3ce83abe25bdfe62b26c29671 (patch)
tree4a82c2c20f36c68dee1cd4c6ee1a7225e513d127
parentd0f1a431eab9a7a503bf6487732eeaec0e881053 (diff)
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@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r--filter/source/msfilter/rtfutil.cxx32
-rw-r--r--include/filter/msfilter/rtfutil.hxx4
-rw-r--r--sw/source/filter/html/htmlreqifreader.cxx27
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx39
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.hxx4
-rw-r--r--sw/source/filter/ww8/rtfsdrexport.cxx6
6 files changed, 44 insertions, 68 deletions
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()));
}