14 #include <rtl/strbuf.hxx>
33 bool WriteObjectData(
SvStream& rOLE);
36 bool m_bInObjData =
false;
40 ReqIfRtfReader::ReqIfRtfReader(
SvStream& rStream)
45 void ReqIfRtfReader::NextToken(
int nToken)
62 bool ReqIfRtfReader::WriteObjectData(
SvStream& rOLE)
77 pCompObj->SeekRel(28);
78 if (!pCompObj->good())
82 pCompObj->ReadUInt32(nData);
83 pCompObj->SeekRel(nData);
84 if (!pCompObj->good())
87 pCompObj->ReadUInt32(nData);
88 pCompObj->SeekRel(nData);
89 if (!pCompObj->good())
92 pCompObj->ReadUInt32(nData);
97 bool ParseOLE2Presentation(
SvStream& rOle2, sal_uInt32& nWidth, sal_uInt32& nHeight,
104 = pStorage->
OpenSotStream(
"\002OlePres000", StreamMode::STD_READ);
107 sal_uInt32 nMarkerOrLength = 0;
108 xOle2Presentation->ReadUInt32(nMarkerOrLength);
109 if (nMarkerOrLength != 0xffffffff)
112 sal_uInt32 nFormatOrAnsiLength = 0;
113 xOle2Presentation->ReadUInt32(nFormatOrAnsiLength);
114 if (nFormatOrAnsiLength != 0x00000003)
118 sal_uInt32 nTargetDeviceSize = 0;
119 xOle2Presentation->ReadUInt32(nTargetDeviceSize);
120 if (nTargetDeviceSize != 0x00000004)
124 sal_uInt32 nAspect = 0;
125 xOle2Presentation->ReadUInt32(nAspect);
126 sal_uInt32 nLindex = 0;
127 xOle2Presentation->ReadUInt32(nLindex);
128 sal_uInt32 nAdvf = 0;
129 xOle2Presentation->ReadUInt32(nAdvf);
130 sal_uInt32 nReserved1 = 0;
131 xOle2Presentation->ReadUInt32(nReserved1);
132 xOle2Presentation->ReadUInt32(nWidth);
133 xOle2Presentation->ReadUInt32(nHeight);
134 sal_uInt32 nSize = 0;
135 xOle2Presentation->ReadUInt32(nSize);
138 if (nSize > xOle2Presentation->remainingSize())
140 std::vector<char>
aBuffer(nSize);
155 = xStorage->
OpenSotStream(
"\1Ole10Native", StreamMode::STD_READ);
156 sal_uInt32 nOle1Size = 0;
157 xOle1Stream->ReadUInt32(nOle1Size);
160 if (xStorage->
GetClassName() ==
SvGlobalName(0x0003000A, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46))
162 aClassName =
"PBrush";
167 !=
SvGlobalName(0x0003000C, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46))
169 SAL_WARN(
"sw.html",
"InsertOLE1HeaderFromOle10NativeStream: unexpected class id: "
172 aClassName =
"Package";
184 rOle1.
WriteUInt32(aClassName.isEmpty() ? 0 : aClassName.getLength() + 1);
185 if (!aClassName.isEmpty())
219 sal_uInt64 nPresentationData = aGraphicStream.
TellEnd();
227 OString aPresentationClassName(
"METAFILEPICT");
228 rOle1.
WriteUInt32(aPresentationClassName.getLength() + 1);
242 rOle1.
WriteBytes(pGraphicAry, nPresentationData);
253 OString InsertOLE1Header(
SvStream& rOle2,
SvStream& rOle1, sal_uInt32& nWidth, sal_uInt32& nHeight,
255 sal_uInt64 nPresentationData)
262 if (xStorage->
IsStream(
"\1Ole10Native"))
264 return InsertOLE1HeaderFromOle10NativeStream(xStorage, rOLENode, rOle1);
267 OString aClassName = ExtractOLEClassName(xStorage);
278 rOle1.
WriteUInt32(aClassName.isEmpty() ? 0 : aClassName.getLength() + 1);
279 if (!aClassName.isEmpty())
306 OString aPresentationClassName(
"METAFILEPICT");
307 rOle1.
WriteUInt32(aPresentationClassName.getLength() + 1);
311 sal_uInt64 nBytes = 0;
312 if (ParseOLE2Presentation(rOle2, nWidth, nHeight, aPresentationData))
316 nBytes = aPresentationData.
Tell();
321 pBytes = pPresentationData;
322 nBytes = nPresentationData;
341 void WrapOleGraphicInRtf(
SvStream& rRtf, sal_uInt32 nWidth, sal_uInt32 nHeight,
342 const sal_uInt8* pPresentationData, sal_uInt64 nPresentationData)
350 rRtf.
WriteCharPtr(OOO_STRING_SVTOOLS_RTF_WMETAFILE
"8");
359 if (pPresentationData)
387 if (eState == SvParserState::Error)
391 if (!xReader->WriteObjectData(rOle))
396 bOwnFormat = !aFilterName.isEmpty();
426 sal_uInt32 nWidth = aSize.
getWidth();
429 const sal_uInt8* pPresentationData =
nullptr;
430 sal_uInt64 nPresentationData = 0;
437 pPresentationData =
static_cast<const sal_uInt8*
>(aGraphicStream.
GetData());
438 nPresentationData = aGraphicStream.
TellEnd();
442 OString aClassName = InsertOLE1Header(rOle2, aOLE1, nWidth, nHeight, rOLENode,
443 pPresentationData, nPresentationData);
469 if (pPresentationData)
471 WrapOleGraphicInRtf(rRtf, nWidth, nHeight, pPresentationData, nPresentationData);
491 case GfxLinkType::NativeBmp:
494 case GfxLinkType::NativeJpg:
497 case GfxLinkType::NativePng:
500 case GfxLinkType::NativeWmf:
513 if (aBlipType.isEmpty())
bool SetStreamSize(sal_uInt64 nSize)
#define OOO_STRING_SVTOOLS_RTF_PNGBLIP
SvStream & WriteUInt16(sal_uInt16 nUInt16)
#define OOO_STRING_SVTOOLS_RTF_OBJH
bool WrapOleInRtf(SvStream &rOle2, SvStream &rRtf, SwOLENode &rOLENode)
Wraps an OLE2 container binary in an RTF fragment.
tools::Long getWidth() const
virtual sal_uInt64 TellEnd()
bool ExtractOLE2FromObjdata(const OString &rObjdata, SvStream &rOle2)
#define OOO_STRING_SVTOOLS_RTF_PICT
sal_uInt64 Seek(sal_uInt64 nPos)
bool IsStream(const OUString &rEleName) const
SvStream & WriteOString(const OString &rStr)
#define OOO_STRING_SVTOOLS_RTF_PICH
SvStream & WriteCharPtr(const char *pBuf)
const sal_uInt8 * GetData() const
virtual sal_uInt64 TellEnd() override
bool StripMetafileHeader(const sal_uInt8 *&rpGraphicAry, sal_uInt64 &rSize)
#define OOO_STRING_SVTOOLS_RTF_WBITMAP
#define OOO_STRING_SVTOOLS_RTF_OBJDATA
SvStream & WriteUInt32(sal_uInt32 nUInt32)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
OString WriteHex(const sal_uInt8 *pData, sal_uInt32 nSize, SvStream *pStream=nullptr, sal_uInt32 nLimit=64)
static OUString GetFilterNameFromClassID(const SvGlobalName &aGlobName)
bool WrapGraphicInRtf(const Graphic &rGraphic, const Size &rLogicSize, SvStream &rRtf)
Wraps an image in an RTF fragment.
#define OOO_STRING_SVTOOLS_RTF_PICWGOAL
tools::Long getHeight() const
SvGlobalName GetClassName()
virtual void NextToken(int nToken)=0
OUString GetHexName() const
tools::SvRef< SotStorageStream > OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
const Graphic * GetGraphic()
tools::Long Width() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
#define OOO_STRING_SVTOOLS_RTF_EMFBLIP
GfxLink GetGfxLink() const
virtual Size GetTwipSize() const override
SvStream & WriteStream(SvStream &rStream)
#define OOO_STRING_SVTOOLS_RTF_PICW
#define OOO_STRING_SVTOOLS_RTF_OBJEMB
static ErrCode Export(SvStream &rOStm, const Graphic &rGraphic, ConvertDataFormat nFormat)
#define OOO_STRING_SVTOOLS_RTF_IGNORE
std::unique_ptr< char[]> aBuffer
#define OOO_STRING_SVTOOLS_RTF_OBJCLASS
GfxLinkType GetType() const
bool ExtractOleFromRtf(SvStream &rRtf, SvStream &rOle, bool &bOwnFormat)
Extracts an OLE2 container binary from an RTF fragment.
tools::Long Height() const
#define OOO_STRING_SVTOOLS_RTF_PICHGOAL
SvStream & WriteChar(char nChar)
sal_uInt32 GetDataSize() const
#define SAL_WARN(area, stream)
#define OOO_STRING_SVTOOLS_RTF_WMETAFILE
OString read_uInt8s_ToOString(SvStream &rStrm, std::size_t nLen)
#define OOO_STRING_SVTOOLS_RTF_OBJECT
#define OOO_STRING_SVTOOLS_RTF_OBJW
#define SAL_NEWLINE_STRING
#define OOO_STRING_SVTOOLS_RTF_JPEGBLIP
static void ExtractOwnStream(SotStorage &rSrcStg, SvMemoryStream &rMemStream)