14#include <rtl/strbuf.hxx>
40 bool WriteObjectData(
SvStream& rOLE);
43 bool m_bInObjData =
false;
47ReqIfRtfReader::ReqIfRtfReader(
SvStream& rStream)
52void ReqIfRtfReader::NextToken(
int nToken)
69bool ReqIfRtfReader::WriteObjectData(
SvStream& rOLE)
84 pCompObj->SeekRel(28);
85 if (!pCompObj->good())
89 pCompObj->ReadUInt32(nData);
90 pCompObj->SeekRel(nData);
91 if (!pCompObj->good())
94 pCompObj->ReadUInt32(nData);
95 pCompObj->SeekRel(nData);
96 if (!pCompObj->good())
99 pCompObj->ReadUInt32(nData);
104bool ParseOLE2Presentation(
SvStream& rOle2, sal_uInt32& nWidth, sal_uInt32& nHeight,
111 = pStorage->OpenSotStream(
"\002OlePres000", StreamMode::STD_READ);
114 sal_uInt32 nMarkerOrLength = 0;
115 xOle2Presentation->ReadUInt32(nMarkerOrLength);
116 if (nMarkerOrLength != 0xffffffff)
119 sal_uInt32 nFormatOrAnsiLength = 0;
120 xOle2Presentation->ReadUInt32(nFormatOrAnsiLength);
121 if (nFormatOrAnsiLength != 0x00000003)
125 sal_uInt32 nTargetDeviceSize = 0;
126 xOle2Presentation->ReadUInt32(nTargetDeviceSize);
127 if (nTargetDeviceSize != 0x00000004)
131 sal_uInt32 nAspect = 0;
132 xOle2Presentation->ReadUInt32(nAspect);
133 sal_uInt32 nLindex = 0;
134 xOle2Presentation->ReadUInt32(nLindex);
135 sal_uInt32 nAdvf = 0;
136 xOle2Presentation->ReadUInt32(nAdvf);
137 sal_uInt32 nReserved1 = 0;
138 xOle2Presentation->ReadUInt32(nReserved1);
139 xOle2Presentation->ReadUInt32(nWidth);
140 xOle2Presentation->ReadUInt32(nHeight);
141 sal_uInt32 nSize = 0;
142 xOle2Presentation->ReadUInt32(nSize);
145 if (nSize > xOle2Presentation->remainingSize())
151 "ParseOLE2Presentation: ignoring potentially broken small preview: size is "
156 std::vector<char>
aBuffer(nSize);
171 = xStorage->OpenSotStream(
"\1Ole10Native", StreamMode::STD_READ);
172 sal_uInt32 nOle1Size = 0;
173 xOle1Stream->ReadUInt32(nOle1Size);
176 if (xStorage->GetClassName() ==
SvGlobalName(0x0003000A, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46))
178 aClassName =
"PBrush";
182 if (xStorage->GetClassName()
183 !=
SvGlobalName(0x0003000C, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46))
185 SAL_WARN(
"sw.html",
"InsertOLE1HeaderFromOle10NativeStream: unexpected class id: "
186 << xStorage->GetClassName().GetHexName());
188 aClassName =
"Package";
200 rOle1.
WriteUInt32(aClassName.isEmpty() ? 0 : aClassName.getLength() + 1);
201 if (!aClassName.isEmpty())
235 sal_uInt64 nPresentationData = aGraphicStream.
TellEnd();
243 OString aPresentationClassName(
"METAFILEPICT");
244 rOle1.
WriteUInt32(aPresentationClassName.getLength() + 1);
258 rOle1.
WriteBytes(pGraphicAry, nPresentationData);
269OString InsertOLE1Header(
SvStream& rOle2,
SvStream& rOle1, sal_uInt32& nWidth, sal_uInt32& nHeight,
271 sal_uInt64 nPresentationData)
275 if (xStorage->GetError() != ERRCODE_NONE)
278 if (xStorage->IsStream(
"\1Ole10Native"))
280 return InsertOLE1HeaderFromOle10NativeStream(xStorage, rOLENode, rOle1);
283 OString aClassName = ExtractOLEClassName(xStorage);
294 rOle1.
WriteUInt32(aClassName.isEmpty() ? 0 : aClassName.getLength() + 1);
295 if (!aClassName.isEmpty())
322 OString aPresentationClassName(
"METAFILEPICT");
323 rOle1.
WriteUInt32(aPresentationClassName.getLength() + 1);
327 sal_uInt64 nBytes = 0;
328 if (ParseOLE2Presentation(rOle2, nWidth, nHeight, aPresentationData))
332 nBytes = aPresentationData.
Tell();
337 pBytes = pPresentationData;
338 nBytes = nPresentationData;
357void WrapOleGraphicInRtf(
SvStream& rRtf, sal_uInt32 nWidth, sal_uInt32 nHeight,
358 const sal_uInt8* pPresentationData, sal_uInt64 nPresentationData)
366 rRtf.
WriteOString(OOO_STRING_SVTOOLS_RTF_WMETAFILE
"8");
375 if (pPresentationData)
403 if (eState == SvParserState::Error)
407 if (!xReader->WriteObjectData(rOle))
412 bOwnFormat = !aFilterName.isEmpty();
443 sal_uInt32 nWidth = aSize.
getWidth();
446 const sal_uInt8* pPresentationData =
nullptr;
447 sal_uInt64 nPresentationData = 0;
451 uno::Sequence<beans::PropertyValue> aFilterData
456 pPresentationData =
static_cast<const sal_uInt8*
>(aGraphicStream.
GetData());
457 nPresentationData = aGraphicStream.
TellEnd();
461 OString aClassName = InsertOLE1Header(rOle2, aOLE1, nWidth, nHeight, rOLENode,
462 pPresentationData, nPresentationData);
488 if (pPresentationData)
490 WrapOleGraphicInRtf(rRtf, nWidth, nHeight, pPresentationData, nPresentationData);
507 sal_uInt32 nWidth = aSize.
getWidth();
517 OString aClassName(
"PBrush");
556 aBitmap.
Convert(BmpConversion::N24Bit);
562 SAL_WARN(
"sw.html",
"WrapGraphicInRtf: bmp conversion failed");
571 const sal_uInt8* pPresentationData =
nullptr;
572 sal_uInt64 nPresentationData = 0;
574 uno::Sequence<beans::PropertyValue> aFilterData
579 pPresentationData =
static_cast<const sal_uInt8*
>(aGraphicStream.
GetData());
580 nPresentationData = aGraphicStream.
TellEnd();
590 OString aPresentationClassName(
"METAFILEPICT");
591 aOle1.
WriteUInt32(aPresentationClassName.getLength() + 1);
595 sal_uInt64 nBytes = 0;
597 pBytes = pPresentationData;
598 nBytes = nPresentationData;
634 if (pPresentationData)
Bitmap GetBitmap(Color aTransparentReplaceColor) const
bool Convert(BmpConversion eConversion)
vcl::PixelFormat getPixelFormat() const
static ErrCode Export(SvStream &rOStm, const Graphic &rGraphic, ConvertDataFormat nFormat)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
constexpr tools::Long getWidth() const
constexpr tools::Long Width() const
virtual sal_uInt64 TellEnd() override
virtual void NextToken(T nToken)=0
virtual sal_uInt64 TellEnd()
std::size_t WriteBytes(const void *pData, std::size_t nSize)
bool SetStreamSize(sal_uInt64 nSize)
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & WriteOString(std::string_view rStr)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & WriteChar(char nChar)
SvStream & WriteStream(SvStream &rStream)
static OUString GetFilterNameFromClassID(const SvGlobalName &aGlobName)
static void ExtractOwnStream(SotStorage &rSrcStg, SvMemoryStream &rMemStream)
const Size & GetSize() const
virtual Size GetTwipSize() const override
const Graphic * GetGraphic()
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
#define SAL_NEWLINE_STRING
#define SAL_WARN(area, stream)
bool WrapOleInRtf(SvStream &rOle2, SvStream &rRtf, SwOLENode &rOLENode, const SwFrameFormat &rFormat)
Wraps an OLE2 container binary in an RTF fragment.
bool ExtractOleFromRtf(SvStream &rRtf, SvStream &rOle, bool &bOwnFormat)
Extracts an OLE2 container binary from an RTF fragment.
bool WrapGraphicInRtf(const Graphic &rGraphic, const SwFrameFormat &rFormat, SvStream &rRtf)
Wraps an image in an RTF fragment.
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool StripMetafileHeader(const sal_uInt8 *&rpGraphicAry, sal_uInt64 &rSize)
bool ExtractOLE2FromObjdata(const OString &rObjdata, SvStream &rOle2)
OString WriteHex(const sal_uInt8 *pData, sal_uInt32 nSize, SvStream *pStream=nullptr, sal_uInt32 nLimit=64)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
#define OOO_STRING_SVTOOLS_RTF_OBJH
#define OOO_STRING_SVTOOLS_RTF_OBJEMB
#define OOO_STRING_SVTOOLS_RTF_RESULT
#define OOO_STRING_SVTOOLS_RTF_OBJDATA
#define OOO_STRING_SVTOOLS_RTF_PICWGOAL
#define OOO_STRING_SVTOOLS_RTF_PICW
#define OOO_STRING_SVTOOLS_RTF_PICH
#define OOO_STRING_SVTOOLS_RTF_WMETAFILE
#define OOO_STRING_SVTOOLS_RTF_OBJW
#define OOO_STRING_SVTOOLS_RTF_OBJCLASS
#define OOO_STRING_SVTOOLS_RTF_OBJECT
#define OOO_STRING_SVTOOLS_RTF_PICHGOAL
#define OOO_STRING_SVTOOLS_RTF_IGNORE
#define OOO_STRING_SVTOOLS_RTF_PICT
TOOLS_DLLPUBLIC OString read_uInt8s_ToOString(SvStream &rStrm, std::size_t nUnits)
VCL_DLLPUBLIC bool ConvertGraphicToWMF(const Graphic &rGraphic, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable=true)
std::unique_ptr< char[]> aBuffer