Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / writerfilter / source / rtftok / rtfdocumentimpl.hxx
blob360c753172b7a9ab56d8cf78e0c7c807e436a415
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFDOCUMENTIMPL_HXX
11 #define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFDOCUMENTIMPL_HXX
13 #include <queue>
14 #include <tuple>
15 #include <vector>
16 #include <boost/optional.hpp>
18 #include <com/sun/star/text/WrapTextMode.hpp>
19 #include <oox/mathml/importutils.hxx>
20 #include <rtl/strbuf.hxx>
21 #include <rtl/ustrbuf.hxx>
22 #include <tools/color.hxx>
24 #include <rtftok/RTFDocument.hxx>
25 #include "rtfreferencetable.hxx"
26 #include "rtfsprm.hxx"
27 #include "rtflistener.hxx"
29 class SvStream;
30 namespace oox
32 class GraphicHelper;
34 namespace com
36 namespace sun
38 namespace star
40 namespace beans
42 class XPropertySet;
44 namespace document
46 class XDocumentProperties;
48 namespace lang
50 class XMultiServiceFactory;
56 namespace writerfilter
58 namespace rtftok
60 class RTFParserState;
61 class RTFDocumentImpl;
62 class RTFTokenizer;
63 class RTFSdrImport;
64 class TableRowBuffer;
66 enum class RTFBorderState
68 NONE,
69 PARAGRAPH,
70 PARAGRAPH_BOX,
71 CELL,
72 PAGE,
73 CHARACTER
76 /// Different kind of buffers for table cell contents.
77 enum RTFBufferTypes
79 BUFFER_SETSTYLE,
80 /// Stores properties, should be created only in bufferProperties().
81 BUFFER_PROPS,
82 BUFFER_NESTROW,
83 BUFFER_CELLEND,
84 BUFFER_STARTRUN,
85 BUFFER_TEXT,
86 BUFFER_UTEXT,
87 BUFFER_ENDRUN,
88 BUFFER_PAR,
89 BUFFER_STARTSHAPE,
90 /// Imports a shape.
91 BUFFER_RESOLVESHAPE,
92 BUFFER_ENDSHAPE,
93 BUFFER_RESOLVESUBSTREAM,
94 /// Restores RTFParserState::aPicture.
95 BUFFER_PICTURE
98 /// Form field types
99 enum class RTFFormFieldType
101 NONE,
102 TEXT,
103 CHECKBOX,
104 LIST
107 enum class RTFBmpStyle
109 NONE,
110 PNG,
111 JPEG,
112 DIBITMAP
115 enum class RTFFieldStatus
117 NONE,
118 INSTRUCTION,
119 RESULT
122 /// A buffer storing dmapper calls.
123 using Buf_t = std::tuple<RTFBufferTypes, RTFValue::Pointer_t, tools::SvRef<TableRowBuffer>>;
124 using RTFBuffer_t = std::deque<Buf_t>;
126 /// holds one nested table row
127 class TableRowBuffer : public virtual SvRefBase
129 RTFBuffer_t m_aBuffer;
130 ::std::deque<RTFSprms> m_aCellsSprms;
131 ::std::deque<RTFSprms> m_aCellsAttributes;
132 int const m_nCells;
133 writerfilter::Reference<Properties>::Pointer_t m_pParaProperties;
134 writerfilter::Reference<Properties>::Pointer_t m_pFrameProperties;
135 writerfilter::Reference<Properties>::Pointer_t m_pRowProperties;
137 public:
138 TableRowBuffer(RTFBuffer_t aBuffer, std::deque<RTFSprms> aSprms,
139 std::deque<RTFSprms> aAttributes, int const nCells)
140 : m_aBuffer(std::move(aBuffer))
141 , m_aCellsSprms(std::move(aSprms))
142 , m_aCellsAttributes(std::move(aAttributes))
143 , m_nCells(nCells)
147 RTFBuffer_t& GetBuffer() { return m_aBuffer; }
148 std::deque<RTFSprms>& GetCellsSprms() { return m_aCellsSprms; }
149 std::deque<RTFSprms>& GetCellsAttributes() { return m_aCellsAttributes; }
150 int GetCells() const { return m_nCells; }
151 writerfilter::Reference<Properties>::Pointer_t& GetParaProperties()
153 return m_pParaProperties;
155 writerfilter::Reference<Properties>::Pointer_t& GetFrameProperties()
157 return m_pFrameProperties;
159 writerfilter::Reference<Properties>::Pointer_t& GetRowProperties() { return m_pRowProperties; }
162 /// An entry in the color table.
163 class RTFColorTableEntry
165 public:
166 void SetRed(sal_uInt8 nRed)
168 m_bAuto = false;
169 m_nR = nRed;
171 void SetGreen(sal_uInt8 nGreen)
173 m_bAuto = false;
174 m_nG = nGreen;
176 void SetBlue(sal_uInt8 nBlue)
178 m_bAuto = false;
179 m_nB = nBlue;
181 Color GetColor() const { return m_bAuto ? COL_AUTO : Color(m_nR, m_nG, m_nB); }
183 private:
184 bool m_bAuto = true;
185 sal_uInt8 m_nR = 0;
186 sal_uInt8 m_nG = 0;
187 sal_uInt8 m_nB = 0;
190 /// Stores the properties of a shape.
191 class RTFShape : public virtual SvRefBase
193 public:
194 RTFShape();
196 std::vector<std::pair<OUString, OUString>>& getProperties() { return m_aProperties; }
198 const std::vector<std::pair<OUString, OUString>>& getProperties() const
200 return m_aProperties;
203 std::vector<std::pair<OUString, OUString>>& getGroupProperties() { return m_aGroupProperties; }
205 void setLeft(sal_Int32 nLeft) { m_nLeft = nLeft; }
207 sal_Int32 getLeft() const { return m_nLeft; }
209 void setTop(sal_Int32 nTop) { m_nTop = nTop; }
211 sal_Int32 getTop() const { return m_nTop; }
213 void setRight(sal_Int32 nRight) { m_nRight = nRight; }
215 sal_Int32 getRight() const { return m_nRight; }
217 void setBottom(sal_Int32 nBottom) { m_nBottom = nBottom; }
219 sal_Int32 getBottom() const { return m_nBottom; }
221 void setZ(sal_Int32 nZ) { m_oZ.reset(nZ); }
223 bool hasZ() const { return bool(m_oZ); }
225 sal_Int32 getZ() const { return *m_oZ; }
227 void setHoriOrientRelation(sal_Int16 nHoriOrientRelation)
229 m_nHoriOrientRelation = nHoriOrientRelation;
232 sal_Int16 getHoriOrientRelation() const { return m_nHoriOrientRelation; }
234 void setVertOrientRelation(sal_Int16 nVertOrientRelation)
236 m_nVertOrientRelation = nVertOrientRelation;
239 sal_Int16 getVertOrientRelation() const { return m_nVertOrientRelation; }
241 void setHoriOrientRelationToken(sal_uInt32 nHoriOrientRelationToken)
243 m_nHoriOrientRelationToken = nHoriOrientRelationToken;
246 sal_uInt32 getHoriOrientRelationToken() const { return m_nHoriOrientRelationToken; }
248 void setVertOrientRelationToken(sal_uInt32 nVertOrientRelationToken)
250 m_nVertOrientRelationToken = nVertOrientRelationToken;
253 sal_uInt32 getVertOrientRelationToken() const { return m_nVertOrientRelationToken; }
255 void setWrap(css::text::WrapTextMode nWrap) { m_nWrap = nWrap; }
257 css::text::WrapTextMode getWrap() const { return m_nWrap; }
259 void setInBackground(bool bInBackground) { m_bInBackground = bInBackground; }
261 bool getInBackground() const { return m_bInBackground; }
263 RTFSprms& getWrapPolygonSprms() { return m_aWrapPolygonSprms; }
265 RTFSprms& getAnchorAttributes() { return m_aAnchorAttributes; }
267 std::pair<Id, RTFValue::Pointer_t>& getWrapSprm() { return m_aWrapSprm; }
269 private:
270 std::vector<std::pair<OUString, OUString>> m_aProperties; ///< Properties of a single shape.
271 std::vector<std::pair<OUString, OUString>>
272 m_aGroupProperties; ///< Properties applied on the groupshape.
273 sal_Int32 m_nLeft = 0;
274 sal_Int32 m_nTop = 0;
275 sal_Int32 m_nRight = 0;
276 sal_Int32 m_nBottom = 0;
277 boost::optional<sal_Int32> m_oZ; ///< Z-Order of the shape.
278 sal_Int16 m_nHoriOrientRelation
279 = 0; ///< Horizontal text::RelOrientation for drawinglayer shapes.
280 sal_Int16 m_nVertOrientRelation = 0; ///< Vertical text::RelOrientation for drawinglayer shapes.
281 sal_uInt32 m_nHoriOrientRelationToken = 0; ///< Horizontal dmapper token for Writer pictures.
282 sal_uInt32 m_nVertOrientRelationToken = 0; ///< Vertical dmapper token for Writer pictures.
283 css::text::WrapTextMode m_nWrap = css::text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE;
284 /// If shape is below text (true) or text is below shape (false).
285 bool m_bInBackground = false;
286 /// Wrap polygon, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict().
287 RTFSprms m_aWrapPolygonSprms;
288 /// Anchor attributes like wrap distance, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict().
289 RTFSprms m_aAnchorAttributes;
290 /// Wrap type, written by RTFDocumentImpl::popState(), read by RTFDocumentImpl::resolvePict().
291 std::pair<Id, RTFValue::Pointer_t> m_aWrapSprm{ 0, nullptr };
294 /// Stores the properties of a drawing object.
295 class RTFDrawingObject : public RTFShape
297 public:
298 RTFDrawingObject();
300 void setShape(const css::uno::Reference<css::drawing::XShape>& xShape) { m_xShape = xShape; }
301 const css::uno::Reference<css::drawing::XShape>& getShape() const { return m_xShape; }
302 void setPropertySet(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet)
304 m_xPropertySet = xPropertySet;
306 const css::uno::Reference<css::beans::XPropertySet>& getPropertySet() const
308 return m_xPropertySet;
310 std::vector<css::beans::PropertyValue>& getPendingProperties() { return m_aPendingProperties; }
311 void setLineColorR(sal_uInt8 nLineColorR) { m_nLineColorR = nLineColorR; }
312 sal_uInt8 getLineColorR() const { return m_nLineColorR; }
313 void setLineColorG(sal_uInt8 nLineColorG) { m_nLineColorG = nLineColorG; }
314 sal_uInt8 getLineColorG() const { return m_nLineColorG; }
315 void setLineColorB(sal_uInt8 nLineColorB) { m_nLineColorB = nLineColorB; }
316 sal_uInt8 getLineColorB() const { return m_nLineColorB; }
317 void setHasLineColor(bool bHasLineColor) { m_bHasLineColor = bHasLineColor; }
318 bool getHasLineColor() const { return m_bHasLineColor; }
319 void setFillColorR(sal_uInt8 nFillColorR) { m_nFillColorR = nFillColorR; }
320 sal_uInt8 getFillColorR() const { return m_nFillColorR; }
321 void setFillColorG(sal_uInt8 nFillColorG) { m_nFillColorG = nFillColorG; }
322 sal_uInt8 getFillColorG() const { return m_nFillColorG; }
323 void setFillColorB(sal_uInt8 nFillColorB) { m_nFillColorB = nFillColorB; }
324 sal_uInt8 getFillColorB() const { return m_nFillColorB; }
325 void setHasFillColor(bool bHasFillColor) { m_bHasFillColor = bHasFillColor; }
326 bool getHasFillColor() const { return m_bHasFillColor; }
327 void setDhgt(sal_Int32 nDhgt) { m_nDhgt = nDhgt; }
328 sal_Int32 getDhgt() const { return m_nDhgt; }
329 void setFLine(sal_Int32 nFLine) { m_nFLine = nFLine; }
330 sal_Int32 getFLine() const { return m_nFLine; }
331 void setPolyLineCount(sal_Int32 nPolyLineCount) { m_nPolyLineCount = nPolyLineCount; }
332 sal_Int32 getPolyLineCount() const { return m_nPolyLineCount; }
333 std::vector<css::awt::Point>& getPolyLinePoints() { return m_aPolyLinePoints; }
334 void setHadShapeText(bool bHadShapeText) { m_bHadShapeText = bHadShapeText; }
335 bool getHadShapeText() const { return m_bHadShapeText; }
337 private:
338 css::uno::Reference<css::drawing::XShape> m_xShape;
339 css::uno::Reference<css::beans::XPropertySet> m_xPropertySet;
340 std::vector<css::beans::PropertyValue> m_aPendingProperties;
341 sal_uInt8 m_nLineColorR = 0;
342 sal_uInt8 m_nLineColorG = 0;
343 sal_uInt8 m_nLineColorB = 0;
344 bool m_bHasLineColor = false;
345 sal_uInt8 m_nFillColorR = 0;
346 sal_uInt8 m_nFillColorG = 0;
347 sal_uInt8 m_nFillColorB = 0;
348 bool m_bHasFillColor = false;
349 sal_Int32 m_nDhgt = 0;
350 sal_Int32 m_nFLine = -1;
351 sal_Int32 m_nPolyLineCount = 0;
352 std::vector<css::awt::Point> m_aPolyLinePoints;
353 bool m_bHadShapeText = false;
356 /// Stores the properties of a picture.
357 class RTFPicture : public virtual SvRefBase
359 public:
360 sal_Int32 nWidth = 0;
361 sal_Int32 nHeight = 0;
362 sal_Int32 nGoalWidth = 0;
363 sal_Int32 nGoalHeight = 0;
364 sal_uInt16 nScaleX = 100;
365 sal_uInt16 nScaleY = 100;
366 short nCropT = 0;
367 short nCropB = 0;
368 short nCropL = 0;
369 short nCropR = 0;
370 sal_uInt16 eWMetafile = 0;
371 RTFBmpStyle eStyle = RTFBmpStyle::NONE;
374 /// Stores the properties of a frame
375 class RTFFrame
377 private:
378 RTFDocumentImpl* m_pDocumentImpl;
379 sal_Int32 m_nX, m_nY, m_nW, m_nH;
380 sal_Int32 m_nHoriPadding, m_nVertPadding;
381 sal_Int32 m_nHoriAlign, m_nHoriAnchor, m_nVertAlign, m_nVertAnchor;
382 Id m_nHRule;
383 boost::optional<Id> m_oWrap;
385 public:
386 explicit RTFFrame(RTFParserState* pParserState);
388 /// Convert the stored properties to Sprms
389 RTFSprms getSprms();
390 /// Store a property
391 void setSprm(Id nId, Id nValue);
392 bool hasProperties() const;
393 /// If we got tokens indicating we're in a frame.
394 bool inFrame();
397 /// State of the parser, which gets saved / restored when changing groups.
398 class RTFParserState
400 public:
401 /// Maps to OOXML's ascii, cs or eastAsia.
402 enum class RunType
404 NONE,
405 LOCH,
406 HICH,
407 DBCH,
408 LTRCH_RTLCH_1,
409 LTRCH_RTLCH_2,
410 RTLCH_LTRCH_1,
411 RTLCH_LTRCH_2
414 explicit RTFParserState(RTFDocumentImpl* pDocumentImpl);
416 void appendDestinationText(const OUString& rString)
418 if (m_pCurrentDestinationText)
419 m_pCurrentDestinationText->append(rString);
422 void setPropName(const OUString& rPropName) { m_aPropName = rPropName; }
423 OUString const& getPropName() const { return m_aPropName; }
424 void setPropType(const css::uno::Type& rPropType) { m_aPropType = rPropType; }
425 css::uno::Type const& getPropType() const { return m_aPropType; }
426 void setTableRowWidthAfter(int nTableRowWidthAfter)
428 m_nTableRowWidthAfter = nTableRowWidthAfter;
430 int getTableRowWidthAfter() const { return m_nTableRowWidthAfter; }
431 void setStartedTrackchange(bool bStartedTrackchange)
433 m_bStartedTrackchange = bStartedTrackchange;
435 bool getStartedTrackchange() const { return m_bStartedTrackchange; }
436 void setCreatedShapeGroup(bool bCreatedShapeGroup)
438 m_bCreatedShapeGroup = bCreatedShapeGroup;
440 bool getCreatedShapeGroup() const { return m_bCreatedShapeGroup; }
441 void setInShape(bool bInShape) { m_bInShape = bInShape; }
442 bool getInShape() const { return m_bInShape; }
443 void setInShapeGroup(bool bInShapeGroup) { m_bInShapeGroup = bInShapeGroup; }
444 bool getInShapeGroup() const { return m_bInShapeGroup; }
445 void setHadShapeText(bool bHadShapeText) { m_bHadShapeText = bHadShapeText; }
446 bool getHadShapeText() const { return m_bHadShapeText; }
447 void setInBackground(bool bInBackground) { m_bInBackground = bInBackground; }
448 bool getInBackground() const { return m_bInBackground; }
449 void setInListpicture(bool bInListpicture) { m_bInListpicture = bInListpicture; }
450 bool getInListpicture() const { return m_bInListpicture; }
451 void setCurrentBuffer(RTFBuffer_t* pCurrentBuffer) { m_pCurrentBuffer = pCurrentBuffer; }
452 RTFBuffer_t* getCurrentBuffer() const { return m_pCurrentBuffer; }
453 void setCurrentListOverrideIndex(int nCurrentListOverrideIndex)
455 m_nCurrentListOverrideIndex = nCurrentListOverrideIndex;
457 int getCurrentListOverrideIndex() const { return m_nCurrentListOverrideIndex; }
458 void setCurrentListIndex(int nCurrentListIndex) { m_nCurrentListIndex = nCurrentListIndex; }
459 int getCurrentListIndex() const { return m_nCurrentListIndex; }
460 void setCurrentCharacterStyleIndex(int nCurrentCharacterStyleIndex)
462 m_nCurrentCharacterStyleIndex = nCurrentCharacterStyleIndex;
464 int getCurrentCharacterStyleIndex() const { return m_nCurrentCharacterStyleIndex; }
465 void setCurrentStyleIndex(int nCurrentStyleIndex) { m_nCurrentStyleIndex = nCurrentStyleIndex; }
466 int getCurrentStyleIndex() const { return m_nCurrentStyleIndex; }
467 void setCurrentDestinationText(OUStringBuffer* pDestinationText)
469 m_pCurrentDestinationText = pDestinationText;
471 OUStringBuffer* getCurrentDestinationText() const { return m_pCurrentDestinationText; }
472 OUStringBuffer& getDestinationText() { return m_aDestinationText; }
473 void setMinute(sal_uInt16 nMinute) { m_nMinute = nMinute; }
474 sal_uInt16 getMinute() const { return m_nMinute; }
475 void setHour(sal_uInt16 nHour) { m_nHour = nHour; }
476 sal_uInt16 getHour() const { return m_nHour; }
477 void setDay(sal_uInt16 nDay) { m_nDay = nDay; }
478 sal_uInt16 getDay() const { return m_nDay; }
479 void setMonth(sal_uInt16 nMonth) { m_nMonth = nMonth; }
480 sal_uInt16 getMonth() const { return m_nMonth; }
481 void setYear(sal_uInt16 nYear) { m_nYear = nYear; }
482 sal_uInt16 getYear() const { return m_nYear; }
483 void setRunType(RunType eRunType) { m_eRunType = eRunType; }
484 RunType getRunType() const { return m_eRunType; }
485 RTFFrame& getFrame() { return m_aFrame; }
486 RTFDrawingObject& getDrawingObject() { return m_aDrawingObject; }
487 RTFShape& getShape() { return m_aShape; }
488 RTFPicture& getPicture() { return m_aPicture; }
489 void setLevelNumbersValid(bool bLevelNumbersValid)
491 m_bLevelNumbersValid = bLevelNumbersValid;
493 bool getLevelNumbersValid() const { return m_bLevelNumbersValid; }
494 std::vector<sal_Int32>& getLevelNumbers() { return m_aLevelNumbers; }
495 RTFSprms& getListLevelEntries() { return m_aListLevelEntries; }
496 int& getListLevelNum() { return m_nListLevelNum; }
497 void setBinaryToRead(int nBinaryToRead) { m_nBinaryToRead = nBinaryToRead; }
498 int getBinaryToRead() const { return m_nBinaryToRead; }
499 int& getCharsToSkip() { return m_nCharsToSkip; }
500 void setUc(int nUc) { m_nUc = nUc; }
501 int getUc() const { return m_nUc; }
502 void setCurrentEncoding(rtl_TextEncoding nCurrentEncoding)
504 m_nCurrentEncoding = nCurrentEncoding;
506 rtl_TextEncoding getCurrentEncoding() const { return m_nCurrentEncoding; }
507 RTFColorTableEntry& getCurrentColor() { return m_aCurrentColor; }
508 RTFSprms& getTabAttributes() { return m_aTabAttributes; }
509 RTFSprms& getTableCellAttributes() { return m_aTableCellAttributes; }
510 RTFSprms& getTableCellSprms() { return m_aTableCellSprms; }
511 RTFSprms& getTableRowAttributes() { return m_aTableRowAttributes; }
512 RTFSprms& getTableRowSprms() { return m_aTableRowSprms; }
513 RTFSprms& getSectionAttributes() { return m_aSectionAttributes; }
514 RTFSprms& getSectionSprms() { return m_aSectionSprms; }
515 RTFSprms& getParagraphAttributes() { return m_aParagraphAttributes; }
516 RTFSprms& getParagraphSprms() { return m_aParagraphSprms; }
517 RTFSprms& getCharacterAttributes() { return m_aCharacterAttributes; }
518 RTFSprms& getCharacterSprms() { return m_aCharacterSprms; }
519 RTFSprms& getTableAttributes() { return m_aTableAttributes; }
520 RTFSprms& getTableSprms() { return m_aTableSprms; }
521 void setBorderState(RTFBorderState nBorderState) { m_nBorderState = nBorderState; }
522 RTFBorderState getBorderState() const { return m_nBorderState; }
523 void setFieldStatus(RTFFieldStatus eFieldStatus) { m_eFieldStatus = eFieldStatus; }
524 RTFFieldStatus getFieldStatus() const { return m_eFieldStatus; }
525 void setDestination(Destination eDestination) { m_eDestination = eDestination; }
526 Destination getDestination() const { return m_eDestination; }
527 void setInternalState(RTFInternalState nInternalState) { m_nInternalState = nInternalState; }
528 RTFInternalState getInternalState() const { return m_nInternalState; }
529 RTFDocumentImpl* getDocumentImpl() { return m_pDocumentImpl; }
531 private:
532 RTFDocumentImpl* m_pDocumentImpl;
533 RTFInternalState m_nInternalState;
534 Destination m_eDestination;
535 RTFFieldStatus m_eFieldStatus;
536 RTFBorderState m_nBorderState;
537 // font table, stylesheet table
538 RTFSprms m_aTableSprms;
539 RTFSprms m_aTableAttributes;
540 // reset by plain
541 RTFSprms m_aCharacterSprms;
542 RTFSprms m_aCharacterAttributes;
543 // reset by pard
544 RTFSprms m_aParagraphSprms;
545 RTFSprms m_aParagraphAttributes;
546 // reset by sectd
547 RTFSprms m_aSectionSprms;
548 RTFSprms m_aSectionAttributes;
549 // reset by trowd
550 RTFSprms m_aTableRowSprms;
551 RTFSprms m_aTableRowAttributes;
552 // reset by cellx
553 RTFSprms m_aTableCellSprms;
554 RTFSprms m_aTableCellAttributes;
555 // reset by tx
556 RTFSprms m_aTabAttributes;
558 RTFColorTableEntry m_aCurrentColor;
560 rtl_TextEncoding m_nCurrentEncoding;
562 /// Current \uc value.
563 int m_nUc;
564 /// Characters to skip, set to nUc by \u.
565 int m_nCharsToSkip;
566 /// Characters to read, once in binary mode.
567 int m_nBinaryToRead;
569 /// Next list level index to use when parsing list table.
570 int m_nListLevelNum;
571 /// List level entries, which will form a list entry later.
572 RTFSprms m_aListLevelEntries;
573 /// List of character positions in leveltext to replace.
574 std::vector<sal_Int32> m_aLevelNumbers;
575 /// If aLevelNumbers should be read at all.
576 bool m_bLevelNumbersValid;
578 RTFPicture m_aPicture;
579 RTFShape m_aShape;
580 RTFDrawingObject m_aDrawingObject;
581 RTFFrame m_aFrame;
583 RunType m_eRunType;
585 // Info group.
586 sal_Int16 m_nYear;
587 sal_uInt16 m_nMonth;
588 sal_uInt16 m_nDay;
589 sal_uInt16 m_nHour;
590 sal_uInt16 m_nMinute;
592 /// Text from special destinations.
593 OUStringBuffer m_aDestinationText{ 512 };
594 /// point to the buffer of the current destination
595 OUStringBuffer* m_pCurrentDestinationText;
597 /// Index of the current style.
598 int m_nCurrentStyleIndex;
599 /// Index of the current character style.
600 int m_nCurrentCharacterStyleIndex;
601 /// Current listid, points to a listtable entry.
602 int m_nCurrentListIndex = -1;
603 /// Current ls, points to a listoverridetable entry.
604 int m_nCurrentListOverrideIndex = -1;
606 /// Points to the active buffer, if there is one.
607 RTFBuffer_t* m_pCurrentBuffer;
609 /// If we're inside a \listpicture group.
610 bool m_bInListpicture;
612 /// If we're inside a \background group.
613 bool m_bInBackground;
615 bool m_bHadShapeText;
616 bool m_bInShapeGroup; ///< If we're inside a \shpgrp group.
617 bool m_bInShape; ///< If we're inside a \shp group.
618 bool m_bCreatedShapeGroup; ///< A GroupShape was created and pushed to the parent stack.
619 bool m_bStartedTrackchange; ///< Track change is started, need to end it before popping.
621 /// User-defined property: key name.
622 OUString m_aPropName;
623 /// User-defined property: value type.
624 css::uno::Type m_aPropType;
626 /// Width of invisible cell at the end of the row.
627 int m_nTableRowWidthAfter;
630 /// An RTF stack is similar to std::stack, except that it has an operator[].
631 struct RTFStack
633 private:
634 std::deque<RTFParserState> m_Impl;
636 public:
637 RTFParserState& top()
639 if (m_Impl.empty())
640 throw std::out_of_range("empty rtf state stack");
641 return m_Impl.back();
643 void pop()
645 if (m_Impl.empty())
646 throw std::out_of_range("empty rtf state stack");
647 return m_Impl.pop_back();
649 void push(RTFParserState const& rState) { return m_Impl.push_back(rState); }
650 bool empty() const { return m_Impl.empty(); }
651 size_t size() const { return m_Impl.size(); }
652 const RTFParserState& operator[](size_t nIndex) const { return m_Impl[nIndex]; }
653 RTFParserState& operator[](size_t nIndex) { return m_Impl[nIndex]; }
656 void putBorderProperty(RTFStack& aStates, Id nId, const RTFValue::Pointer_t& pValue);
657 void putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue,
658 RTFOverwrite eOverwrite = RTFOverwrite::NO_APPEND);
659 Id getParagraphBorder(sal_uInt32 nIndex);
660 void putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue,
661 RTFOverwrite eOverwrite = RTFOverwrite::YES, bool bAttribute = true);
662 bool eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId);
664 /// Looks up the nParent then the nested nId attribute in rSprms.
665 RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId);
667 /// Looks up the nParent then the nested nId sprm in rSprms.
668 RTFValue::Pointer_t getNestedSprm(RTFSprms& rSprms, Id nParent, Id nId);
670 /// Checks if rName is contained at least once in rProperties as a key.
671 bool findPropertyName(const std::vector<css::beans::PropertyValue>& rProperties,
672 const OUString& rName);
673 RTFSprms& getLastAttributes(RTFSprms& rSprms, Id nId);
674 OString DTTM22OString(long nDTTM);
676 /// Implementation of the RTFDocument interface.
677 class RTFDocumentImpl : public RTFDocument, public RTFListener
679 public:
680 using Pointer_t = tools::SvRef<RTFDocumentImpl>;
681 RTFDocumentImpl(css::uno::Reference<css::uno::XComponentContext> const& xContext,
682 css::uno::Reference<css::io::XInputStream> const& xInputStream,
683 css::uno::Reference<css::lang::XComponent> const& xDstDoc,
684 css::uno::Reference<css::frame::XFrame> const& xFrame,
685 css::uno::Reference<css::task::XStatusIndicator> const& xStatusIndicator,
686 const utl::MediaDescriptor& rMediaDescriptor);
687 ~RTFDocumentImpl() override;
689 // RTFDocument
690 void resolve(Stream& rMapper) override;
692 // RTFListener
693 RTFError dispatchDestination(RTFKeyword nKeyword) override;
694 RTFError dispatchFlag(RTFKeyword nKeyword) override;
695 RTFError dispatchSymbol(RTFKeyword nKeyword) override;
696 RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) override;
697 RTFError dispatchValue(RTFKeyword nKeyword, int nParam) override;
698 RTFError resolveChars(char ch) override;
699 RTFError pushState() override;
700 RTFError popState() override;
701 Destination getDestination() override;
702 void setDestination(Destination eDestination) override;
703 RTFInternalState getInternalState() override;
704 void setInternalState(RTFInternalState nInternalState) override;
705 bool getSkipUnknown() override;
706 void setSkipUnknown(bool bSkipUnknown) override;
707 void finishSubstream() override;
708 bool isSubstream() const override;
710 Stream& Mapper() { return *m_pMapperStream; }
711 void setSuperstream(RTFDocumentImpl* pSuperstream);
712 const css::uno::Reference<css::lang::XMultiServiceFactory>& getModelFactory() const
714 return m_xModelFactory;
716 bool isInBackground();
717 void setDestinationText(OUString const& rString);
718 /// Resolve a picture: If not inline, then anchored.
719 void resolvePict(bool bInline, css::uno::Reference<css::drawing::XShape> const& rShape);
721 /// If this is the first run of the document, starts the initial paragraph.
722 void checkFirstRun();
723 /// Send NS_ooxml::LN_settings_settings to dmapper.
724 void outputSettingsTable();
725 /// If the initial paragraph is started.
726 bool getFirstRun() const { return m_bFirstRun; }
727 /// If we need to add a dummy paragraph before a section break.
728 void setNeedPar(bool bNeedPar);
729 /// Return the dmapper index of an RTF index for fonts.
730 int getFontIndex(int nIndex);
731 /// Return the name of the font, based on a dmapper index.
732 OUString getFontName(int nIndex);
733 /// Return the style name of an RTF style index.
734 OUString getStyleName(int nIndex);
735 /// Return the style type of an RTF style index.
736 Id getStyleType(int nIndex);
737 /// Return the encoding associated with a font index.
738 rtl_TextEncoding getEncoding(int nFontIndex);
739 /// Get the default parser state.
740 RTFParserState& getDefaultState();
741 oox::GraphicHelper& getGraphicHelper();
742 /// Are we inside the stylesheet table?
743 bool isStyleSheetImport();
744 /// Resets m_aStates.top().aFrame.
745 void resetFrame();
746 /// Buffers properties to be sent later.
747 void bufferProperties(RTFBuffer_t& rBuffer, const RTFValue::Pointer_t& pValue,
748 const tools::SvRef<TableRowBuffer>& pTableProperties);
749 /// implement non-obvious RTF specific style inheritance
750 RTFReferenceTable::Entries_t deduplicateStyleTable();
752 private:
753 SvStream& Strm();
754 Color getColorTable(sal_uInt32 nIndex);
755 writerfilter::Reference<Properties>::Pointer_t createStyleProperties();
756 void resetSprms();
757 void resetAttributes();
758 void resolveSubstream(std::size_t nPos, Id nId);
759 void resolveSubstream(std::size_t nPos, Id nId, OUString const& rIgnoreFirst);
761 void text(OUString& rString);
762 // Sends a single character to dmapper, taking care of buffering.
763 void singleChar(sal_uInt8 nValue, bool bRunProps = false);
764 // Sends run properties to dmapper, taking care of buffering.
765 void runProps();
766 void runBreak();
767 void parBreak();
768 void tableBreak();
769 writerfilter::Reference<Properties>::Pointer_t
770 getProperties(const RTFSprms& rAttributes, RTFSprms const& rSprms, Id nStyleType);
771 void checkNeedPap();
772 void sectBreak(bool bFinal = false);
773 void prepareProperties(RTFParserState& rState,
774 writerfilter::Reference<Properties>::Pointer_t& o_rpParagraphProperties,
775 writerfilter::Reference<Properties>::Pointer_t& o_rpFrameProperties,
776 writerfilter::Reference<Properties>::Pointer_t& o_rpTableRowProperties,
777 int nCells, int nCurrentCellX);
778 /// Send the passed properties to dmapper.
779 void sendProperties(writerfilter::Reference<Properties>::Pointer_t const& pParagraphProperties,
780 writerfilter::Reference<Properties>::Pointer_t const& pFrameProperties,
781 writerfilter::Reference<Properties>::Pointer_t const& pTableRowProperties);
782 void replayRowBuffer(RTFBuffer_t& rBuffer, ::std::deque<RTFSprms>& rCellsSrpms,
783 ::std::deque<RTFSprms>& rCellsAttributes, int nCells);
784 void replayBuffer(RTFBuffer_t& rBuffer, RTFSprms* pSprms, RTFSprms const* pAttributes);
785 /// If we have some unicode or hex characters to send.
786 void checkUnicode(bool bUnicode, bool bHex);
787 /// If we need a final section break at the end of the document.
788 void setNeedSect(bool bNeedSect);
789 void resetTableRowProperties();
790 void backupTableRowProperties();
791 void restoreTableRowProperties();
792 /// Turns the destination text into an input stream of the current OLE attributes.
793 RTFError handleEmbeddedObject();
795 css::uno::Reference<css::uno::XComponentContext> const& m_xContext;
796 css::uno::Reference<css::io::XInputStream> const& m_xInputStream;
797 css::uno::Reference<css::lang::XComponent> const& m_xDstDoc;
798 css::uno::Reference<css::frame::XFrame> const& m_xFrame;
799 css::uno::Reference<css::task::XStatusIndicator> const& m_xStatusIndicator;
800 css::uno::Reference<css::lang::XMultiServiceFactory> m_xModelFactory;
801 css::uno::Reference<css::document::XDocumentProperties> m_xDocumentProperties;
802 std::shared_ptr<SvStream> m_pInStream;
803 Stream* m_pMapperStream;
804 tools::SvRef<RTFSdrImport> m_pSdrImport;
805 tools::SvRef<RTFTokenizer> m_pTokenizer;
806 RTFStack m_aStates;
807 /// Read by RTF_PARD.
808 RTFParserState m_aDefaultState;
809 bool m_bSkipUnknown;
810 /// Font index <-> encoding map, *not* part of the parser state
811 std::map<int, rtl_TextEncoding> m_aFontEncodings;
812 /// Font index <-> name map.
813 std::map<int, OUString> m_aFontNames;
814 /// Maps the non-continuous font indexes to the continuous dmapper indexes.
815 std::vector<int> m_aFontIndexes;
816 /// Maps style indexes to style names.
817 std::map<int, OUString> m_aStyleNames;
818 /// Maps style indexes to style types.
819 std::map<int, Id> m_aStyleTypes;
820 /// Color index <-> RGB color value map
821 std::vector<Color> m_aColorTable;
822 /// to start initial paragraph / section after font/style tables
823 bool m_bFirstRun;
824 /// except in the case of tables in initial multicolumn section (global for assertion)
825 bool m_bFirstRunException;
826 /// If paragraph properties should be emitted on next run.
827 bool m_bNeedPap;
828 /// If we need to emit a CR at the end of substream.
829 bool m_bNeedCr;
830 /// Original value of m_bNeedCr -- saved/restored before/after textframes.
831 bool m_bNeedCrOrig;
832 bool m_bNeedPar;
833 /// If set, an empty paragraph will be added at the end of the document.
834 bool m_bNeedFinalPar;
835 /// The list table and list override table combined.
836 RTFSprms m_aListTableSprms;
837 /// Maps between listoverridetable and listtable indexes.
838 std::map<int, int> m_aListOverrideTable;
839 /// Maps listtable indexes to listtable entries.
840 std::map<int, RTFValue::Pointer_t> m_aListTable;
841 /// Index of the current list level in a list table entry.
842 int m_nListLevel = -1;
843 /// Maps List level indexes to removed values in the current list entry.
844 std::map<int, int> m_aInvalidListLevelFirstIndents;
845 /// Maps list table indexes to levels (and their removed values).
846 std::map<int, std::map<int, int>> m_aInvalidListTableFirstIndents;
847 /// The settings table attributes.
848 RTFSprms m_aSettingsTableAttributes;
849 /// The settings table sprms.
850 RTFSprms m_aSettingsTableSprms;
852 std::shared_ptr<oox::GraphicHelper> m_pGraphicHelper;
854 /// cell props buffer for nested tables, reset by \nestrow
855 /// the \nesttableprops is a destination and must follow the
856 /// nested cells, so it should be sufficient to store the
857 /// currently active one, no need for a stack of them
858 int m_nNestedCells;
859 std::deque<RTFSprms> m_aNestedTableCellsSprms;
860 std::deque<RTFSprms> m_aNestedTableCellsAttributes;
861 /// cell props buffer for top-level table, reset by \row
862 int m_nTopLevelCells;
863 std::deque<RTFSprms> m_aTopLevelTableCellsSprms;
864 std::deque<RTFSprms> m_aTopLevelTableCellsAttributes;
865 /// backup of top-level props, to support inheriting cell props
866 int m_nInheritingCells;
867 std::deque<RTFSprms> m_aTableInheritingCellsSprms;
868 std::deque<RTFSprms> m_aTableInheritingCellsAttributes;
870 // Left row margin (for nested and top-level rows)
871 int m_nNestedTRLeft;
872 int m_nTopLevelTRLeft;
874 /// Current cellx value (nested table)
875 int m_nNestedCurrentCellX;
876 /// Current cellx value (top-level table)
877 int m_nTopLevelCurrentCellX;
879 // Backup of what \trowd clears, to work around invalid input.
880 RTFSprms m_aBackupTableRowSprms;
881 RTFSprms m_aBackupTableRowAttributes;
882 int m_nBackupTopLevelCurrentCellX;
884 /// Buffered table cells, till cell definitions are not reached.
885 /// for nested table, one buffer per table level
886 std::deque<RTFBuffer_t> m_aTableBufferStack;
887 /// Buffered superscript, till footnote is reached (or not).
888 RTFBuffer_t m_aSuperBuffer;
890 /// Superstream of this substream.
891 RTFDocumentImpl* m_pSuperstream;
892 /// Type of the stream: header, footer, footnote, etc.
893 Id m_nStreamType;
894 std::queue<std::pair<Id, std::size_t>> m_nHeaderFooterPositions;
895 std::size_t m_nGroupStartPos;
896 /// Ignore the first occurrence of this text.
897 OUString m_aIgnoreFirst;
898 /// Bookmark name <-> index map.
899 std::map<OUString, int> m_aBookmarks;
900 /// Revision index <-> author map.
901 std::map<int, OUString> m_aAuthors;
902 /// Annotation author of the next annotation.
903 OUString m_aAuthor;
904 /// Initials of author of the next annotation.
905 OUString m_aAuthorInitials;
907 RTFSprms m_aFormfieldSprms;
908 RTFSprms m_aFormfieldAttributes;
909 RTFFormFieldType m_nFormFieldType;
911 /// OLE attributes are attributes of the ooxml:OLEObject_OLEObject sprm.
912 RTFSprms m_aOLEAttributes;
913 RTFSprms m_aObjectAttributes;
914 /** If we are in an object group and if the we use its
915 * \objdata element.
916 * (if we don't use the \objdata we use the \result element)*/
917 bool m_bObject;
918 /// If the data for a picture is a binary one, it's stored here.
919 std::shared_ptr<SvStream> m_pBinaryData;
921 RTFReferenceTable::Entries_t m_aFontTableEntries;
922 int m_nCurrentFontIndex;
923 /// Used only during font table parsing till we don't know the font name.
924 int m_nCurrentEncoding;
925 /// Raw default font index, use getFont() on it to get a real one.
926 int m_nDefaultFontIndex;
928 RTFReferenceTable::Entries_t m_aStyleTableEntries;
929 int m_nCurrentStyleIndex;
930 bool m_bFormField;
931 /// For the INCLUDEPICTURE field's argument.
932 OUString m_aPicturePath;
933 // Unicode characters are collected here so we don't have to send them one by one.
934 OUStringBuffer m_aUnicodeBuffer{ 512 };
935 /// Same for hex characters.
936 OStringBuffer m_aHexBuffer{ 512 };
937 /// Formula import.
938 oox::formulaimport::XmlStreamBuilder m_aMathBuffer;
939 /// Normal text property, that is math italic and math spacing are not applied to the current run.
940 bool m_bMathNor;
941 /// If the next continuous section break should be ignored.
942 bool m_bIgnoreNextContSectBreak;
943 /// clean up a synthetic page break, see RTF_PAGE
944 /// if inactive value is -1, otherwise the RTF_SKB* to restore
945 RTFKeyword m_nResetBreakOnSectBreak;
946 /// If a section break is needed before the end of the doc (false right after a section break).
947 bool m_bNeedSect;
948 /// If aFrame.inFrame() was true in the previous state.
949 bool m_bWasInFrame;
950 /// A picture was seen in the current paragraph.
951 bool m_bHadPicture;
952 /// The document has multiple sections.
953 bool m_bHadSect;
954 /// Max width of the rows in the current table.
955 int m_nCellxMax;
956 /// ID of the next \listlevel picture.
957 int m_nListPictureId;
959 /// New document means not pasting into an existing one.
960 bool const m_bIsNewDoc;
961 /// The media descriptor contains e.g. the base URL of the document.
962 const utl::MediaDescriptor& m_rMediaDescriptor;
964 /// Flags for ensuring that only one header and footer is added per section
965 bool m_hasRHeader;
966 bool m_hasFHeader;
967 bool m_hasRFooter;
968 bool m_hasFFooter;
970 /// Are we after a \cell, but before a \row?
971 bool m_bAfterCellBeforeRow;
973 } // namespace rtftok
974 } // namespace writerfilter
976 #endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFDOCUMENTIMPL_HXX
978 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */