LibreOffice Module writerfilter (master) 1
rtfdocumentimpl.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#pragma once
11
12#include <memory>
13#include <queue>
14#include <tuple>
15#include <vector>
16#include <optional>
17
18#include <com/sun/star/text/WrapTextMode.hpp>
19#include <com/sun/star/io/WrongFormatException.hpp>
21#include <rtl/strbuf.hxx>
22#include <rtl/ustrbuf.hxx>
23#include <tools/color.hxx>
24#include <tools/long.hxx>
25
27#include "rtfreferencetable.hxx"
28#include "rtfsprm.hxx"
29#include "rtflistener.hxx"
30
31class SvStream;
32namespace oox
33{
34class GraphicHelper;
35}
36namespace com::sun::star
37{
38namespace beans
39{
40class XPropertySet;
41}
42namespace document
43{
44class XDocumentProperties;
45}
46namespace lang
47{
48class XMultiServiceFactory;
49}
50}
51
53{
54class RTFParserState;
55class RTFDocumentImpl;
56class RTFTokenizer;
57class RTFSdrImport;
58class TableRowBuffer;
59
61{
62 NONE,
65 CELL,
66 PAGE,
68};
69
72{
91};
92
95{
96 NONE,
97 TEXT,
99 LIST
100};
101
102enum class RTFBmpStyle
103{
104 NONE,
105 PNG,
106 JPEG,
108};
109
111{
112 NONE,
114 RESULT
115};
116
118using Buf_t = std::tuple<RTFBufferTypes, RTFValue::Pointer_t, tools::SvRef<TableRowBuffer>>;
119using RTFBuffer_t = std::deque<Buf_t>;
120
122class TableRowBuffer : public virtual SvRefBase
123{
125 ::std::deque<RTFSprms> m_aCellsSprms;
126 ::std::deque<RTFSprms> m_aCellsAttributes;
131
132public:
133 TableRowBuffer(RTFBuffer_t aBuffer, std::deque<RTFSprms> aSprms,
134 std::deque<RTFSprms> aAttributes, int const nCells)
135 : m_aBuffer(std::move(aBuffer))
136 , m_aCellsSprms(std::move(aSprms))
137 , m_aCellsAttributes(std::move(aAttributes))
138 , m_nCells(nCells)
139 {
140 }
141
143 std::deque<RTFSprms>& GetCellsSprms() { return m_aCellsSprms; }
144 std::deque<RTFSprms>& GetCellsAttributes() { return m_aCellsAttributes; }
145 int GetCells() const { return m_nCells; }
147 {
148 return m_pParaProperties;
149 }
151 {
152 return m_pFrameProperties;
153 }
155};
156
159{
160public:
161 void SetRed(sal_uInt8 nRed)
162 {
163 m_bAuto = false;
164 m_nR = nRed;
165 }
166 void SetGreen(sal_uInt8 nGreen)
167 {
168 m_bAuto = false;
169 m_nG = nGreen;
170 }
171 void SetBlue(sal_uInt8 nBlue)
172 {
173 m_bAuto = false;
174 m_nB = nBlue;
175 }
176 Color GetColor() const { return m_bAuto ? COL_AUTO : Color(m_nR, m_nG, m_nB); }
177
178private:
179 bool m_bAuto = true;
183};
184
186class RTFShape : public virtual SvRefBase
187{
188public:
190
191 std::vector<std::pair<OUString, OUString>>& getProperties() { return m_aProperties; }
192
193 const std::vector<std::pair<OUString, OUString>>& getProperties() const
194 {
195 return m_aProperties;
196 }
197
198 std::vector<std::pair<OUString, OUString>>& getGroupProperties() { return m_aGroupProperties; }
199
200 void setLeft(sal_Int32 nLeft) { m_nLeft = nLeft; }
201
202 sal_Int32 getLeft() const { return m_nLeft; }
203
204 void setTop(sal_Int32 nTop) { m_nTop = nTop; }
205
206 sal_Int32 getTop() const { return m_nTop; }
207
208 void setRight(sal_Int32 nRight) { m_nRight = nRight; }
209
210 sal_Int32 getRight() const { return m_nRight; }
211
212 void setBottom(sal_Int32 nBottom) { m_nBottom = nBottom; }
213
214 sal_Int32 getBottom() const { return m_nBottom; }
215
216 void setZ(sal_Int32 nZ) { m_oZ = nZ; }
217
218 bool hasZ() const { return bool(m_oZ); }
219
220 sal_Int32 getZ() const { return *m_oZ; }
221
222 void setHoriOrientRelation(sal_Int16 nHoriOrientRelation)
223 {
224 m_nHoriOrientRelation = nHoriOrientRelation;
225 }
226
227 sal_Int16 getHoriOrientRelation() const { return m_nHoriOrientRelation; }
228
229 void setVertOrientRelation(sal_Int16 nVertOrientRelation)
230 {
231 m_nVertOrientRelation = nVertOrientRelation;
232 }
233
234 sal_Int16 getVertOrientRelation() const { return m_nVertOrientRelation; }
235
236 void setHoriOrientRelationToken(sal_uInt32 nHoriOrientRelationToken)
237 {
238 m_nHoriOrientRelationToken = nHoriOrientRelationToken;
239 }
240
242
243 void setVertOrientRelationToken(sal_uInt32 nVertOrientRelationToken)
244 {
245 m_nVertOrientRelationToken = nVertOrientRelationToken;
246 }
247
249
250 void setWrap(css::text::WrapTextMode nWrap) { m_nWrap = nWrap; }
251
252 css::text::WrapTextMode getWrap() const { return m_nWrap; }
253
254 void setInBackground(bool bInBackground) { m_bInBackground = bInBackground; }
255
256 bool getInBackground() const { return m_bInBackground; }
257
259
261
262 std::pair<Id, RTFValue::Pointer_t>& getWrapSprm() { return m_aWrapSprm; }
263
264private:
265 std::vector<std::pair<OUString, OUString>> m_aProperties;
266 std::vector<std::pair<OUString, OUString>>
268 sal_Int32 m_nLeft = 0;
269 sal_Int32 m_nTop = 0;
270 sal_Int32 m_nRight = 0;
271 sal_Int32 m_nBottom = 0;
272 std::optional<sal_Int32> m_oZ;
274 = 0;
275 sal_Int16 m_nVertOrientRelation = 0;
278 css::text::WrapTextMode m_nWrap = css::text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE;
280 bool m_bInBackground = false;
286 std::pair<Id, RTFValue::Pointer_t> m_aWrapSprm{ 0, nullptr };
287};
288
291{
292public:
294
295 void setShape(const css::uno::Reference<css::drawing::XShape>& xShape) { m_xShape = xShape; }
296 const css::uno::Reference<css::drawing::XShape>& getShape() const { return m_xShape; }
297 void setPropertySet(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet)
298 {
299 m_xPropertySet = xPropertySet;
300 }
301 const css::uno::Reference<css::beans::XPropertySet>& getPropertySet() const
302 {
303 return m_xPropertySet;
304 }
305 std::vector<css::beans::PropertyValue>& getPendingProperties() { return m_aPendingProperties; }
306 void setLineColorR(sal_uInt8 nLineColorR) { m_nLineColorR = nLineColorR; }
308 void setLineColorG(sal_uInt8 nLineColorG) { m_nLineColorG = nLineColorG; }
310 void setLineColorB(sal_uInt8 nLineColorB) { m_nLineColorB = nLineColorB; }
312 void setHasLineColor(bool bHasLineColor) { m_bHasLineColor = bHasLineColor; }
313 bool getHasLineColor() const { return m_bHasLineColor; }
314 void setFillColorR(sal_uInt8 nFillColorR) { m_nFillColorR = nFillColorR; }
316 void setFillColorG(sal_uInt8 nFillColorG) { m_nFillColorG = nFillColorG; }
318 void setFillColorB(sal_uInt8 nFillColorB) { m_nFillColorB = nFillColorB; }
320 void setHasFillColor(bool bHasFillColor) { m_bHasFillColor = bHasFillColor; }
321 bool getHasFillColor() const { return m_bHasFillColor; }
322 void setDhgt(sal_Int32 nDhgt) { m_nDhgt = nDhgt; }
323 sal_Int32 getDhgt() const { return m_nDhgt; }
324 void setFLine(sal_Int32 nFLine) { m_nFLine = nFLine; }
325 sal_Int32 getFLine() const { return m_nFLine; }
326 void setPolyLineCount(sal_Int32 nPolyLineCount) { m_nPolyLineCount = nPolyLineCount; }
327 sal_Int32 getPolyLineCount() const { return m_nPolyLineCount; }
328 std::vector<css::awt::Point>& getPolyLinePoints() { return m_aPolyLinePoints; }
329 void setHadShapeText(bool bHadShapeText) { m_bHadShapeText = bHadShapeText; }
330 bool getHadShapeText() const { return m_bHadShapeText; }
331
332private:
333 css::uno::Reference<css::drawing::XShape> m_xShape;
334 css::uno::Reference<css::beans::XPropertySet> m_xPropertySet;
335 std::vector<css::beans::PropertyValue> m_aPendingProperties;
339 bool m_bHasLineColor = false;
343 bool m_bHasFillColor = false;
344 sal_Int32 m_nDhgt = 0;
345 sal_Int32 m_nFLine = -1;
346 sal_Int32 m_nPolyLineCount = 0;
347 std::vector<css::awt::Point> m_aPolyLinePoints;
348 bool m_bHadShapeText = false;
349};
350
352class RTFPicture : public virtual SvRefBase
353{
354public:
355 sal_Int32 nWidth = 0;
356 sal_Int32 nHeight = 0;
357 sal_Int32 nGoalWidth = 0;
358 sal_Int32 nGoalHeight = 0;
359 sal_uInt16 nScaleX = 100;
360 sal_uInt16 nScaleY = 100;
361 short nCropT = 0;
362 short nCropB = 0;
363 short nCropL = 0;
364 short nCropR = 0;
365 sal_uInt16 eWMetafile = 0;
367};
368
371{
372private:
374 sal_Int32 m_nX, m_nY, m_nW, m_nH;
378 std::optional<Id> m_oWrap;
379
380public:
381 explicit RTFFrame(RTFParserState* pParserState);
382
386 void setSprm(Id nId, Id nValue);
387 bool hasProperties() const;
389 bool inFrame() const;
390};
391
394{
395public:
397 enum class RunType
398 {
399 NONE,
400 LOCH,
401 HICH,
402 DBCH,
403 LTRCH_RTLCH_1,
404 LTRCH_RTLCH_2,
405 RTLCH_LTRCH_1,
406 RTLCH_LTRCH_2
407 };
408
409 explicit RTFParserState(RTFDocumentImpl* pDocumentImpl);
410
411 void appendDestinationText(std::u16string_view rString)
412 {
414 m_pCurrentDestinationText->append(rString);
415 }
416
417 void setPropName(const OUString& rPropName) { m_aPropName = rPropName; }
418 OUString const& getPropName() const { return m_aPropName; }
419 void setPropType(const css::uno::Type& rPropType) { m_aPropType = rPropType; }
420 css::uno::Type const& getPropType() const { return m_aPropType; }
421 void setTableRowWidthAfter(int nTableRowWidthAfter)
422 {
423 m_nTableRowWidthAfter = nTableRowWidthAfter;
424 }
426 void setStartedTrackchange(bool bStartedTrackchange)
427 {
428 m_bStartedTrackchange = bStartedTrackchange;
429 }
431 void setCreatedShapeGroup(bool bCreatedShapeGroup)
432 {
433 m_bCreatedShapeGroup = bCreatedShapeGroup;
434 }
436 void setInShape(bool bInShape) { m_bInShape = bInShape; }
437 bool getInShape() const { return m_bInShape; }
438 void setInShapeGroup(bool bInShapeGroup) { m_bInShapeGroup = bInShapeGroup; }
439 bool getInShapeGroup() const { return m_bInShapeGroup; }
440 void setHadShapeText(bool bHadShapeText) { m_bHadShapeText = bHadShapeText; }
441 bool getHadShapeText() const { return m_bHadShapeText; }
442 void setInBackground(bool bInBackground) { m_bInBackground = bInBackground; }
443 bool getInBackground() const { return m_bInBackground; }
444 void setInListpicture(bool bInListpicture) { m_bInListpicture = bInListpicture; }
445 bool getInListpicture() const { return m_bInListpicture; }
446 void setCurrentBuffer(RTFBuffer_t* pCurrentBuffer) { m_pCurrentBuffer = pCurrentBuffer; }
448 void setCurrentListOverrideIndex(int nCurrentListOverrideIndex)
449 {
450 m_nCurrentListOverrideIndex = nCurrentListOverrideIndex;
451 }
453 void setCurrentListIndex(int nCurrentListIndex) { m_nCurrentListIndex = nCurrentListIndex; }
455 void setCurrentCharacterStyleIndex(int nCurrentCharacterStyleIndex)
456 {
457 m_nCurrentCharacterStyleIndex = nCurrentCharacterStyleIndex;
458 }
460 void setCurrentStyleIndex(int nCurrentStyleIndex) { m_nCurrentStyleIndex = nCurrentStyleIndex; }
462 void setCurrentDestinationText(OUStringBuffer* pDestinationText)
463 {
464 m_pCurrentDestinationText = pDestinationText;
465 }
466 OUStringBuffer* getCurrentDestinationText() const { return m_pCurrentDestinationText; }
467 OUStringBuffer& getDestinationText() { return m_aDestinationText; }
468 void setMinute(sal_uInt16 nMinute) { m_nMinute = nMinute; }
469 sal_uInt16 getMinute() const { return m_nMinute; }
470 void setHour(sal_uInt16 nHour) { m_nHour = nHour; }
471 sal_uInt16 getHour() const { return m_nHour; }
472 void setDay(sal_uInt16 nDay) { m_nDay = nDay; }
473 sal_uInt16 getDay() const { return m_nDay; }
474 void setMonth(sal_uInt16 nMonth) { m_nMonth = nMonth; }
475 sal_uInt16 getMonth() const { return m_nMonth; }
476 void setYear(sal_uInt16 nYear) { m_nYear = nYear; }
477 sal_uInt16 getYear() const { return m_nYear; }
478 void setRunType(RunType eRunType) { m_eRunType = eRunType; }
479 RunType getRunType() const { return m_eRunType; }
484 void setLevelNumbersValid(bool bLevelNumbersValid)
485 {
486 m_bLevelNumbersValid = bLevelNumbersValid;
487 }
489 std::vector<sal_Int32>& getLevelNumbers() { return m_aLevelNumbers; }
492 void setBinaryToRead(int nBinaryToRead) { m_nBinaryToRead = nBinaryToRead; }
493 int getBinaryToRead() const { return m_nBinaryToRead; }
495 void setUc(int nUc) { m_nUc = nUc; }
496 int getUc() const { return m_nUc; }
497 void setCurrentEncoding(rtl_TextEncoding nCurrentEncoding)
498 {
499 m_nCurrentEncoding = nCurrentEncoding;
500 }
501 rtl_TextEncoding getCurrentEncoding() const { return m_nCurrentEncoding; }
516 void setBorderState(RTFBorderState nBorderState) { m_nBorderState = nBorderState; }
518 void setFieldStatus(RTFFieldStatus eFieldStatus) { m_eFieldStatus = eFieldStatus; }
520 void setFieldLocked(bool bSet) { m_bFieldLocked = bSet; }
521 bool isFieldLocked() const { return m_bFieldLocked; }
522 void setDestination(Destination eDestination) { m_eDestination = eDestination; }
524 void setInternalState(RTFInternalState nInternalState) { m_nInternalState = nInternalState; }
527 OUString getDocVar() { return m_aDocVar; }
528 void appendDocVar(OUString& aDocVar) { m_aDocVar += aDocVar; };
529 OUString getDocVarName() { return m_aDocVarName; }
530 void setDocVarName(OUString& aDocVarName) { m_aDocVarName = aDocVarName; }
532
533private:
540 // font table, stylesheet table
543 // reset by plain
546 // reset by pard
549 // reset by sectd
552 // reset by trowd
555 // reset by cellx
558 // reset by tx
560
562
563 rtl_TextEncoding m_nCurrentEncoding;
564
566 int m_nUc;
571
577 std::vector<sal_Int32> m_aLevelNumbers;
580
585
587
588 // Info group.
589 sal_Int16 m_nYear;
590 sal_uInt16 m_nMonth;
591 sal_uInt16 m_nDay;
592 sal_uInt16 m_nHour;
593 sal_uInt16 m_nMinute;
594
596 OUStringBuffer m_aDestinationText{ 512 };
599
608
611
614
617
623
625 OUString m_aPropName;
627 css::uno::Type m_aPropType;
628
631
633 OUString m_aDocVar;
635};
636
639{
640private:
641 std::deque<RTFParserState> m_Impl;
642
643public:
645 {
646 if (m_Impl.empty())
647 throw css::io::WrongFormatException(
648 "Parser state is empty! Invalid usage of destination braces in RTF?", nullptr);
649 return m_Impl.back();
650 }
651 void pop()
652 {
653 if (m_Impl.empty())
654 throw css::io::WrongFormatException(
655 "Parser state is empty! Invalid usage of destination braces in RTF?", nullptr);
656 return m_Impl.pop_back();
657 }
658 void push(RTFParserState const& rState) { return m_Impl.push_back(rState); }
659 bool empty() const { return m_Impl.empty(); }
660 size_t size() const { return m_Impl.size(); }
661 const RTFParserState& operator[](size_t nIndex) const { return m_Impl[nIndex]; }
662 RTFParserState& operator[](size_t nIndex) { return m_Impl[nIndex]; }
663};
664
665void putBorderProperty(RTFStack& aStates, Id nId, const RTFValue::Pointer_t& pValue);
666void putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue,
668Id getParagraphBorder(sal_uInt32 nIndex);
669void putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue,
670 RTFOverwrite eOverwrite = RTFOverwrite::YES, bool bAttribute = true);
671bool eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId);
672
674RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId);
675
677RTFValue::Pointer_t getNestedSprm(RTFSprms& rSprms, Id nParent, Id nId);
678
680bool findPropertyName(const std::vector<css::beans::PropertyValue>& rProperties,
681 const OUString& rName);
683OString DTTM22OString(tools::Long nDTTM);
684
687{
688public:
690 RTFDocumentImpl(css::uno::Reference<css::uno::XComponentContext> const& xContext,
691 css::uno::Reference<css::io::XInputStream> const& xInputStream,
692 css::uno::Reference<css::lang::XComponent> const& xDstDoc,
693 css::uno::Reference<css::frame::XFrame> const& xFrame,
694 css::uno::Reference<css::task::XStatusIndicator> const& xStatusIndicator,
695 const utl::MediaDescriptor& rMediaDescriptor);
697
698 // RTFDocument
699 void resolve(Stream& rMapper) override;
700
701 // RTFListener
702 RTFError dispatchDestination(RTFKeyword nKeyword) override;
703 RTFError dispatchFlag(RTFKeyword nKeyword) override;
706 RTFError dispatchSymbol(RTFKeyword nKeyword) override;
707 RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) override;
708 RTFError dispatchValue(RTFKeyword nKeyword, int nParam) override;
709 bool dispatchTableSprmValue(RTFKeyword nKeyword, int nParam);
710 bool dispatchCharacterSprmValue(RTFKeyword nKeyword, int nParam);
711 bool dispatchCharacterAttributeValue(RTFKeyword nKeyword, int nParam);
712 bool dispatchParagraphSprmValue(RTFKeyword nKeyword, int nParam);
713 bool dispatchInfoValue(RTFKeyword nKeyword, int nParam);
714 bool dispatchFrameValue(RTFKeyword nKeyword, int nParam);
715 bool dispatchTableValue(RTFKeyword nKeyword, int nParam);
716 RTFError resolveChars(char ch) override;
717 RTFError pushState() override;
719 RTFError popState() override;
720 void afterPopState(RTFParserState& rState);
721 Destination getDestination() override;
722 void setDestination(Destination eDestination) override;
724 void setInternalState(RTFInternalState nInternalState) override;
725 bool getSkipUnknown() override;
726 void setSkipUnknown(bool bSkipUnknown) override;
727 void finishSubstream() override;
728 bool isSubstream() const override;
729
731 void setSuperstream(RTFDocumentImpl* pSuperstream);
732 const css::uno::Reference<css::lang::XMultiServiceFactory>& getModelFactory() const
733 {
734 return m_xModelFactory;
735 }
736 bool isInBackground();
737 void setDestinationText(std::u16string_view rString);
739 void resolvePict(bool bInline, css::uno::Reference<css::drawing::XShape> const& rShape);
740
742 void checkFirstRun();
744 void outputSettingsTable();
746 bool getFirstRun() const { return m_bFirstRun; }
748 void setNeedPar(bool bNeedPar);
750 int getFontIndex(int nIndex);
752 OUString getFontName(int nIndex);
754 OUString getStyleName(int nIndex);
756 Id getStyleType(int nIndex);
758 rtl_TextEncoding getEncoding(int nFontIndex);
763 bool isStyleSheetImport();
765 void resetFrame();
767 void bufferProperties(RTFBuffer_t& rBuffer, const RTFValue::Pointer_t& pValue,
768 const tools::SvRef<TableRowBuffer>& pTableProperties, Id nStyleType = 0);
771
772private:
773 SvStream& Strm();
774 Color getColorTable(sal_uInt32 nIndex);
776 void resetSprms();
777 void resetAttributes();
778 void resolveSubstream(std::size_t nPos, Id nId);
779 void resolveSubstream(std::size_t nPos, Id nId, OUString const& rIgnoreFirst);
780
781 void text(OUString& rString);
782 // Sends a single character to dmapper, taking care of buffering.
783 void singleChar(sal_uInt8 nValue, bool bRunProps = false);
784 // Sends run properties to dmapper, taking care of buffering.
785 void runProps();
786 void runBreak();
787 void parBreak();
788 void tableBreak();
790 getProperties(const RTFSprms& rAttributes, RTFSprms const& rSprms, Id nStyleType);
791 void checkNeedPap();
793 void sectBreak(bool bFinal = false);
795 writerfilter::Reference<Properties>::Pointer_t& o_rpParagraphProperties,
798 int nCells, int nCurrentCellX);
800 void sendProperties(writerfilter::Reference<Properties>::Pointer_t const& pParagraphProperties,
802 writerfilter::Reference<Properties>::Pointer_t const& pTableRowProperties);
803 void replayRowBuffer(RTFBuffer_t& rBuffer, ::std::deque<RTFSprms>& rCellsSprms,
804 ::std::deque<RTFSprms>& rCellsAttributes, int nCells);
805 void replayBuffer(RTFBuffer_t& rBuffer, RTFSprms* pSprms, RTFSprms const* pAttributes);
807 void checkUnicode(bool bUnicode, bool bHex);
809 void setNeedSect(bool bNeedSect);
815
816 css::uno::Reference<css::uno::XComponentContext> const& m_xContext;
817 css::uno::Reference<css::io::XInputStream> const& m_xInputStream;
818 css::uno::Reference<css::lang::XComponent> const& m_xDstDoc;
819 css::uno::Reference<css::frame::XFrame> const& m_xFrame;
820 css::uno::Reference<css::task::XStatusIndicator> const& m_xStatusIndicator;
821 css::uno::Reference<css::lang::XMultiServiceFactory> m_xModelFactory;
822 css::uno::Reference<css::document::XDocumentProperties> m_xDocumentProperties;
823 std::unique_ptr<SvStream> m_pInStream;
832 std::map<int, rtl_TextEncoding> m_aFontEncodings;
834 std::map<int, OUString> m_aFontNames;
836 std::vector<int> m_aFontIndexes;
838 std::map<int, OUString> m_aStyleNames;
840 std::map<int, Id> m_aStyleTypes;
842 std::vector<Color> m_aColorTable;
859 std::map<int, int> m_aListOverrideTable;
861 std::map<int, RTFValue::Pointer_t> m_aListTable;
863 int m_nListLevel = -1;
867 std::map<int, std::map<int, int>> m_aInvalidListTableFirstIndents;
872
873 std::shared_ptr<oox::GraphicHelper> m_pGraphicHelper;
874
880 std::deque<RTFSprms> m_aNestedTableCellsSprms;
881 std::deque<RTFSprms> m_aNestedTableCellsAttributes;
884 std::deque<RTFSprms> m_aTopLevelTableCellsSprms;
888 std::deque<RTFSprms> m_aTableInheritingCellsSprms;
890
891 // Left row margin (for nested and top-level rows)
894
899
900 // Backup of what \trowd clears, to work around invalid input.
904
907 std::deque<RTFBuffer_t> m_aTableBufferStack;
910
915 std::queue<std::pair<Id, std::size_t>> m_nHeaderFooterPositions;
916 std::size_t m_nGroupStartPos;
920 std::map<OUString, int> m_aBookmarks;
922 std::map<int, OUString> m_aAuthors;
924 OUString m_aAuthor;
927
931
940 std::shared_ptr<SvStream> m_pBinaryData;
941
948
950 std::shared_ptr<RTFReferenceTable::Entries_t> m_pStyleTableEntries;
955 // Unicode characters are collected here so we don't have to send them one by one.
956 OUStringBuffer m_aUnicodeBuffer{ 512 };
958 OStringBuffer m_aHexBuffer{ 512 };
980
985
991
994};
995} // namespace writerfilter::rtftok
996
997/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Handler for a stream.
Implementation of the RTFDocument interface.
int m_nInheritingCells
backup of top-level props, to support inheriting cell props
void replayRowBuffer(RTFBuffer_t &rBuffer, ::std::deque< RTFSprms > &rCellsSprms, ::std::deque< RTFSprms > &rCellsAttributes, int nCells)
void resolvePict(bool bInline, css::uno::Reference< css::drawing::XShape > const &rShape)
Resolve a picture: If not inline, then anchored.
void resolve(Stream &rMapper) override
Resolves this document to a stream handler.
int m_nNestedCurrentCellX
Current cellx value (nested table)
void setNeedSect(bool bNeedSect)
If we need a final section break at the end of the document.
void afterPopState(RTFParserState &rState)
RTFSprms m_aSettingsTableAttributes
The settings table attributes.
bool m_bHadPicture
A picture was seen in the current paragraph.
RTFDocumentImpl * m_pSuperstream
Superstream of this substream.
bool dispatchCharacterSprmValue(RTFKeyword nKeyword, int nParam)
bool m_bObject
If we are in an object group and if the we use its \objdata element.
css::uno::Reference< css::frame::XFrame > const & m_xFrame
bool dispatchTableValue(RTFKeyword nKeyword, int nParam)
std::deque< RTFBuffer_t > m_aTableBufferStack
Buffered table cells, till cell definitions are not reached.
RTFError dispatchValue(RTFKeyword nKeyword, int nParam) override
int m_nDefaultFontIndex
Raw default font index, use getFont() on it to get a real one.
std::map< int, RTFValue::Pointer_t > m_aListTable
Maps listtable indexes to listtable entries.
std::map< int, OUString > m_aFontNames
Font index <-> name map.
writerfilter::Reference< Properties >::Pointer_t getProperties(const RTFSprms &rAttributes, RTFSprms const &rSprms, Id nStyleType)
RTFSprms m_aOLEAttributes
OLE attributes are attributes of the ooxml:OLEObject_OLEObject sprm.
bool isStyleSheetImport()
Are we inside the stylesheet table?
OUString m_aIgnoreFirst
Ignore the first occurrence of this text.
bool m_bIgnoreNextContSectBreak
If the next continuous section break should be ignored.
std::map< int, int > m_aInvalidListLevelFirstIndents
Maps List level indexes to removed values in the current list entry.
std::deque< RTFSprms > m_aTopLevelTableCellsAttributes
int m_nListPictureId
ID of the next \listlevel picture.
OUString m_aAuthor
Annotation author of the next annotation.
std::deque< RTFSprms > m_aTableInheritingCellsSprms
bool m_bNeedFinalPar
If set, an empty paragraph will be added at the end of the document.
std::map< int, int > m_aListOverrideTable
Maps between listoverridetable and listtable indexes.
OUString m_aPicturePath
For the INCLUDEPICTURE field's argument.
bool dispatchCharacterAttributeValue(RTFKeyword nKeyword, int nParam)
RTFError dispatchDestination(RTFKeyword nKeyword) override
RTFKeyword m_nResetBreakOnSectBreak
clean up a synthetic page break, see RTF_PAGE if inactive value is -1, otherwise the RTF_SKB* to rest...
void resetFrame()
Resets m_aStates.top().aFrame.
const utl::MediaDescriptor & m_rMediaDescriptor
The media descriptor contains e.g. the base URL of the document.
RTFError dispatchSymbol(RTFKeyword nKeyword) override
std::queue< std::pair< Id, std::size_t > > m_nHeaderFooterPositions
css::uno::Reference< css::task::XStatusIndicator > const & m_xStatusIndicator
RTFSprms m_aSettingsTableSprms
The settings table sprms.
int m_nCurrentEncoding
Used only during font table parsing till we don't know the font name.
bool m_bNeedCrOrig
Original value of m_bNeedCr – saved/restored before/after textframes.
OUString getFontName(int nIndex)
Return the name of the font, based on a dmapper index.
bool m_bHadSect
The document has multiple sections.
RTFReferenceTable::Entries_t m_aFontTableEntries
css::uno::Reference< css::uno::XComponentContext > const & m_xContext
RTFError handleEmbeddedObject()
Turns the destination text into an input stream of the current OLE attributes.
void singleChar(sal_uInt8 nValue, bool bRunProps=false)
Id m_nStreamType
Type of the stream: header, footer, footnote, etc.
int m_nTopLevelCurrentCellX
Current cellx value (top-level table)
bool m_bFirstRunException
except in the case of tables in initial multicolumn section (global for assertion)
bool getFirstRun() const
If the initial paragraph is started.
std::deque< RTFSprms > m_aNestedTableCellsAttributes
bool m_bFirstRun
to start initial paragraph / section after font/style tables
std::deque< RTFSprms > m_aTopLevelTableCellsSprms
void checkUnicode(bool bUnicode, bool bHex)
If we have some unicode or hex characters to send.
RTFBuffer_t m_aSuperBuffer
Buffered superscript, till footnote is reached (or not).
std::unique_ptr< SvStream > m_pInStream
css::uno::Reference< css::lang::XMultiServiceFactory > m_xModelFactory
OStringBuffer m_aHexBuffer
Same for hex characters.
std::deque< RTFSprms > m_aTableInheritingCellsAttributes
std::map< int, rtl_TextEncoding > m_aFontEncodings
Font index <-> encoding map, not part of the parser state.
RTFInternalState getInternalState() override
std::deque< RTFSprms > m_aNestedTableCellsSprms
Id getStyleType(int nIndex)
Return the style type of an RTF style index.
bool m_bIsNewDoc
New document means not pasting into an existing one.
std::shared_ptr< SvStream > m_pBinaryData
If the data for a picture is a binary one, it's stored here.
bool dispatchFloatingTableFlag(RTFKeyword nKeyword)
Dispatches flags related to Positioned Wrapped Tables.
RTFParserState & getDefaultState()
Get the default parser state.
void setDestination(Destination eDestination) override
std::map< int, std::map< int, int > > m_aInvalidListTableFirstIndents
Maps list table indexes to levels (and their removed values).
std::map< OUString, int > m_aBookmarks
Bookmark name <-> index map.
int m_nNestedCells
cell props buffer for nested tables, reset by \nestrow the \nesttableprops is a destination and must ...
int m_nListLevel
Index of the current list level in a list table entry.
void bufferProperties(RTFBuffer_t &rBuffer, const RTFValue::Pointer_t &pValue, const tools::SvRef< TableRowBuffer > &pTableProperties, Id nStyleType=0)
Buffers properties to be sent later.
oox::formulaimport::XmlStreamBuilder m_aMathBuffer
Formula import.
const css::uno::Reference< css::lang::XMultiServiceFactory > & getModelFactory() const
std::map< int, Id > m_aStyleTypes
Maps style indexes to style types.
std::shared_ptr< oox::GraphicHelper > m_pGraphicHelper
OUString getStyleName(int nIndex)
Return the style name of an RTF style index.
std::vector< Color > m_aColorTable
Color index <-> RGB color value map.
OUString m_aAuthorInitials
Initials of author of the next annotation.
css::uno::Reference< css::io::XInputStream > const & m_xInputStream
writerfilter::Reference< Properties >::Pointer_t createStyleProperties()
void sendProperties(writerfilter::Reference< Properties >::Pointer_t const &pParagraphProperties, writerfilter::Reference< Properties >::Pointer_t const &pFrameProperties, writerfilter::Reference< Properties >::Pointer_t const &pTableRowProperties)
Send the passed properties to dmapper.
int getFontIndex(int nIndex)
Return the dmapper index of an RTF index for fonts.
bool m_bMathNor
Normal text property, that is math italic and math spacing are not applied to the current run.
RTFDocumentImpl(css::uno::Reference< css::uno::XComponentContext > const &xContext, css::uno::Reference< css::io::XInputStream > const &xInputStream, css::uno::Reference< css::lang::XComponent > const &xDstDoc, css::uno::Reference< css::frame::XFrame > const &xFrame, css::uno::Reference< css::task::XStatusIndicator > const &xStatusIndicator, const utl::MediaDescriptor &rMediaDescriptor)
void setInternalState(RTFInternalState nInternalState) override
bool m_bNeedCr
If we need to emit a CR at the end of substream.
css::uno::Reference< css::lang::XComponent > const & m_xDstDoc
int m_nTopLevelCells
cell props buffer for top-level table, reset by \row
tools::SvRef< RTFTokenizer > m_pTokenizer
void prepareProperties(RTFParserState &rState, writerfilter::Reference< Properties >::Pointer_t &o_rpParagraphProperties, writerfilter::Reference< Properties >::Pointer_t &o_rpFrameProperties, writerfilter::Reference< Properties >::Pointer_t &o_rpTableRowProperties, int nCells, int nCurrentCellX)
RTFParserState m_aDefaultState
Read by RTF_PARD.
void checkFirstRun()
If this is the first run of the document, starts the initial paragraph.
bool dispatchInfoValue(RTFKeyword nKeyword, int nParam)
void replayBuffer(RTFBuffer_t &rBuffer, RTFSprms *pSprms, RTFSprms const *pAttributes)
std::map< int, OUString > m_aAuthors
Revision index <-> author map.
RTFReferenceTable::Entries_t deduplicateStyleTable()
implement non-obvious RTF specific style inheritance
tools::SvRef< RTFSdrImport > m_pSdrImport
RTFError beforePopState(RTFParserState &rState)
void setSkipUnknown(bool bSkipUnknown) override
void setSuperstream(RTFDocumentImpl *pSuperstream)
RTFError dispatchFlag(RTFKeyword nKeyword) override
bool m_bAfterCellBeforeRow
Are we after a \cell, but before a \row?
std::map< int, OUString > m_aStyleNames
Maps style indexes to style names.
void resolveSubstream(std::size_t nPos, Id nId)
rtl_TextEncoding getEncoding(int nFontIndex)
Return the encoding associated with a font index.
RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) override
void setNeedPar(bool bNeedPar)
If we need to add a dummy paragraph before a section break.
void setDestinationText(std::u16string_view rString)
bool m_bNeedPap
If paragraph properties should be emitted on next run.
bool dispatchTableSprmValue(RTFKeyword nKeyword, int nParam)
bool dispatchParagraphSprmValue(RTFKeyword nKeyword, int nParam)
std::shared_ptr< RTFReferenceTable::Entries_t > m_pStyleTableEntries
To avoid copying entries between DomainMapper instances it is stored as pointer.
std::vector< int > m_aFontIndexes
Maps the non-continuous font indexes to the continuous dmapper indexes.
bool m_hasRHeader
Flags for ensuring that only one header and footer is added per section.
RTFError resolveChars(char ch) override
RTFSprms m_aListTableSprms
The list table and list override table combined.
bool m_bWasInFrame
If aFrame.inFrame() was true in the previous state.
bool m_bNeedSect
If a section break is needed before the end of the doc (false right after a section break).
void outputSettingsTable()
Send NS_ooxml::LN_settings_settings to dmapper.
int m_nCellxMax
Max width of the rows in the current table.
Color getColorTable(sal_uInt32 nIndex)
bool dispatchFrameValue(RTFKeyword nKeyword, int nParam)
css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties
The RTFDocument opens and resolves the RTF document.
Definition: RTFDocument.hxx:23
Stores the properties of a drawing object.
std::vector< css::beans::PropertyValue > m_aPendingProperties
void setPropertySet(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet)
void setFillColorG(sal_uInt8 nFillColorG)
void setHasLineColor(bool bHasLineColor)
const css::uno::Reference< css::beans::XPropertySet > & getPropertySet() const
void setHasFillColor(bool bHasFillColor)
void setLineColorR(sal_uInt8 nLineColorR)
void setPolyLineCount(sal_Int32 nPolyLineCount)
std::vector< css::beans::PropertyValue > & getPendingProperties()
void setHadShapeText(bool bHadShapeText)
void setLineColorG(sal_uInt8 nLineColorG)
const css::uno::Reference< css::drawing::XShape > & getShape() const
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
css::uno::Reference< css::drawing::XShape > m_xShape
std::vector< css::awt::Point > & getPolyLinePoints()
void setFillColorB(sal_uInt8 nFillColorB)
void setFillColorR(sal_uInt8 nFillColorR)
void setShape(const css::uno::Reference< css::drawing::XShape > &xShape)
void setLineColorB(sal_uInt8 nLineColorB)
std::vector< css::awt::Point > m_aPolyLinePoints
Stores the properties of a frame.
RTFFrame(RTFParserState *pParserState)
bool inFrame() const
If we got tokens indicating we're in a frame.
RTFSprms getSprms()
Convert the stored properties to Sprms.
void setSprm(Id nId, Id nValue)
Store a property.
RTFTokenizer needs a class implementing this interface.
Definition: rtflistener.hxx:41
State of the parser, which gets saved / restored when changing groups.
OUString m_aDocVar
For importing document variables which are not referenced in the document.
void setCurrentListIndex(int nCurrentListIndex)
void setStartedTrackchange(bool bStartedTrackchange)
int m_nListLevelNum
Next list level index to use when parsing list table.
void setCurrentCharacterStyleIndex(int nCurrentCharacterStyleIndex)
void setCurrentEncoding(rtl_TextEncoding nCurrentEncoding)
bool m_bCreatedShapeGroup
A GroupShape was created and pushed to the parent stack.
std::vector< sal_Int32 > m_aLevelNumbers
List of character positions in leveltext to replace.
void setCreatedShapeGroup(bool bCreatedShapeGroup)
RTFParserState(RTFDocumentImpl *pDocumentImpl)
bool m_bInListpicture
If we're inside a \listpicture group.
void setDocVarName(OUString &aDocVarName)
bool m_bStartedTrackchange
Track change is started, need to end it before popping.
OUString const & getPropName() const
void setPropType(const css::uno::Type &rPropType)
OUString m_aPropName
User-defined property: key name.
void setCurrentStyleIndex(int nCurrentStyleIndex)
OUStringBuffer * m_pCurrentDestinationText
point to the buffer of the current destination
RTFInternalState getInternalState() const
bool m_bInShapeGroup
If we're inside a \shpgrp group.
int m_nCurrentListOverrideIndex
Current ls, points to a listoverridetable entry.
int m_nCurrentCharacterStyleIndex
Index of the current character style.
RTFSprms m_aListLevelEntries
List level entries, which will form a list entry later.
int m_nCurrentStyleIndex
Index of the current style.
void setBorderState(RTFBorderState nBorderState)
void setLevelNumbersValid(bool bLevelNumbersValid)
void setCurrentBuffer(RTFBuffer_t *pCurrentBuffer)
rtl_TextEncoding getCurrentEncoding() const
css::uno::Type const & getPropType() const
void setDestination(Destination eDestination)
void setPropName(const OUString &rPropName)
void setTableRowWidthAfter(int nTableRowWidthAfter)
OUStringBuffer * getCurrentDestinationText() const
int m_nTableRowWidthAfter
Width of invisible cell at the end of the row.
int m_nCharsToSkip
Characters to skip, set to nUc by \u.
void setFieldStatus(RTFFieldStatus eFieldStatus)
void setBinaryToRead(int nBinaryToRead)
void setInShapeGroup(bool bInShapeGroup)
void setInListpicture(bool bInListpicture)
void setCurrentListOverrideIndex(int nCurrentListOverrideIndex)
css::uno::Type m_aPropType
User-defined property: value type.
OUStringBuffer m_aDestinationText
Text from special destinations.
RunType
Maps to OOXML's ascii, cs or eastAsia.
int m_nCurrentListIndex
Current listid, points to a listtable entry.
RTFBuffer_t * m_pCurrentBuffer
Points to the active buffer, if there is one.
bool m_bLevelNumbersValid
If aLevelNumbers should be read at all.
bool m_bInBackground
If we're inside a \background group.
int m_nBinaryToRead
Characters to read, once in binary mode.
void setInBackground(bool bInBackground)
bool m_bInShape
If we're inside a \shp group.
std::vector< sal_Int32 > & getLevelNumbers()
void appendDestinationText(std::u16string_view rString)
void setHadShapeText(bool bHadShapeText)
void setInternalState(RTFInternalState nInternalState)
void setCurrentDestinationText(OUStringBuffer *pDestinationText)
Stores the properties of a picture.
std::map< int, writerfilter::Reference< Properties >::Pointer_t > Entries_t
Stores the properties of a shape.
RTFSprms m_aWrapPolygonSprms
Wrap polygon, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict().
std::vector< std::pair< OUString, OUString > > & getProperties()
sal_Int16 getVertOrientRelation() const
void setHoriOrientRelation(sal_Int16 nHoriOrientRelation)
void setBottom(sal_Int32 nBottom)
css::text::WrapTextMode m_nWrap
sal_Int16 getHoriOrientRelation() const
std::pair< Id, RTFValue::Pointer_t > m_aWrapSprm
Wrap type, written by RTFDocumentImpl::popState(), read by RTFDocumentImpl::resolvePict().
RTFSprms m_aAnchorAttributes
Anchor attributes like wrap distance, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::re...
sal_uInt32 m_nVertOrientRelationToken
Vertical dmapper token for Writer pictures.
css::text::WrapTextMode getWrap() const
sal_Int16 m_nVertOrientRelation
Vertical text::RelOrientation for drawinglayer shapes.
sal_uInt32 getHoriOrientRelationToken() const
std::pair< Id, RTFValue::Pointer_t > & getWrapSprm()
std::vector< std::pair< OUString, OUString > > & getGroupProperties()
std::optional< sal_Int32 > m_oZ
Z-Order of the shape.
void setVertOrientRelationToken(sal_uInt32 nVertOrientRelationToken)
std::vector< std::pair< OUString, OUString > > m_aGroupProperties
Properties applied on the groupshape.
bool m_bInBackground
If shape is below text (true) or text is below shape (false).
sal_uInt32 m_nHoriOrientRelationToken
Horizontal dmapper token for Writer pictures.
const std::vector< std::pair< OUString, OUString > > & getProperties() const
void setInBackground(bool bInBackground)
sal_Int16 m_nHoriOrientRelation
Horizontal text::RelOrientation for drawinglayer shapes.
void setVertOrientRelation(sal_Int16 nVertOrientRelation)
void setWrap(css::text::WrapTextMode nWrap)
sal_uInt32 getVertOrientRelationToken() const
std::vector< std::pair< OUString, OUString > > m_aProperties
Properties of a single shape.
void setHoriOrientRelationToken(sal_uInt32 nHoriOrientRelationToken)
void setRight(sal_Int32 nRight)
A list of RTFSprm with a copy constructor that performs a deep copy.
Definition: rtfsprm.hxx:39
tools::SvRef< RTFValue > Pointer_t
Definition: rtfvalue.hxx:41
writerfilter::Reference< Properties >::Pointer_t m_pParaProperties
writerfilter::Reference< Properties >::Pointer_t & GetParaProperties()
std::deque< RTFSprms > & GetCellsSprms()
writerfilter::Reference< Properties >::Pointer_t m_pFrameProperties
writerfilter::Reference< Properties >::Pointer_t m_pRowProperties
std::deque< RTFSprms > & GetCellsAttributes()
writerfilter::Reference< Properties >::Pointer_t & GetRowProperties()
writerfilter::Reference< Properties >::Pointer_t & GetFrameProperties()
::std::deque< RTFSprms > m_aCellsSprms
TableRowBuffer(RTFBuffer_t aBuffer, std::deque< RTFSprms > aSprms, std::deque< RTFSprms > aAttributes, int const nCells)
::std::deque< RTFSprms > m_aCellsAttributes
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
PNG
#define CELL(col, row)
CHARACTER
sal_Int32 nIndex
NONE
class SAL_NO_VTABLE XPropertySet
long Long
bool findPropertyName(const std::vector< beans::PropertyValue > &rProperties, const OUString &rName)
RTFValue::Pointer_t getNestedAttribute(RTFSprms &rSprms, Id nParent, Id nId)
Looks up the nParent then the nested nId attribute in rSprms.
std::tuple< RTFBufferTypes, RTFValue::Pointer_t, tools::SvRef< TableRowBuffer > > Buf_t
A buffer storing dmapper calls.
void putNestedAttribute(RTFSprms &rSprms, Id nParent, Id nId, const RTFValue::Pointer_t &pValue, RTFOverwrite eOverwrite, bool bAttribute)
bool eraseNestedAttribute(RTFSprms &rSprms, Id nParent, Id nId)
@ NO_APPEND
No, always append the value to the end of the list.
@ YES
Yes, if an existing key is found, overwrite it.
void putNestedSprm(RTFSprms &rSprms, Id nParent, Id nId, const RTFValue::Pointer_t &pValue, RTFOverwrite eOverwrite)
RTFValue::Pointer_t getNestedSprm(RTFSprms &rSprms, Id nParent, Id nId)
Looks up the nParent then the nested nId sprm in rSprms.
Destination
An RTF destination state is the last open destination control word.
RTFFormFieldType
Form field types.
Id getParagraphBorder(sal_uInt32 nIndex)
OString DTTM22OString(tools::Long nDTTM)
RTFBufferTypes
Different kind of buffers for table cell contents.
@ BUFFER_RESOLVESHAPE
Imports a shape.
@ BUFFER_PROPS
Stores properties, should be created only in bufferProperties().
@ BUFFER_PICTURE
Restores RTFParserState::aPicture.
RTFSprms & getLastAttributes(RTFSprms &rSprms, Id nId)
std::deque< Buf_t > RTFBuffer_t
void putBorderProperty(RTFStack &aStates, Id nId, const RTFValue::Pointer_t &pValue)
sal_uInt32 Id
An RTF stack is similar to std::stack, except that it has an operator[].
const RTFParserState & operator[](size_t nIndex) const
RTFParserState & operator[](size_t nIndex)
std::deque< RTFParserState > m_Impl
void push(RTFParserState const &rState)
TEXT
unsigned char sal_uInt8
std::unique_ptr< char[]> aBuffer