Kaydet (Commit) 6d05579c authored tarafından Miklos Vajna's avatar Miklos Vajna

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/51937Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst d0f1a431
......@@ -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;
......
......@@ -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.
*/
......
......@@ -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.
......
......@@ -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
}
......
......@@ -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.
......
......@@ -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()));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment