1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
18 #include <com/sun/star/text/WrapTextMode.hpp>
19 #include <com/sun/star/io/WrongFormatException.hpp>
20 #include <oox/mathml/importutils.hxx>
21 #include <rtl/strbuf.hxx>
22 #include <rtl/ustrbuf.hxx>
23 #include <tools/color.hxx>
24 #include <tools/long.hxx>
26 #include <rtftok/RTFDocument.hxx>
27 #include "rtfreferencetable.hxx"
28 #include "rtfsprm.hxx"
29 #include "rtflistener.hxx"
36 namespace com::sun::star
44 class XDocumentProperties
;
48 class XMultiServiceFactory
;
52 namespace writerfilter::rtftok
55 class RTFDocumentImpl
;
60 enum class RTFBorderState
70 /// Different kind of buffers for table cell contents.
74 /// Stores properties, should be created only in bufferProperties().
88 BUFFER_RESOLVESUBSTREAM
,
89 /// Restores RTFParserState::aPicture.
94 enum class RTFFormFieldType
102 enum class RTFBmpStyle
110 enum class RTFFieldStatus
117 /// A buffer storing dmapper calls.
118 using Buf_t
= std::tuple
<RTFBufferTypes
, RTFValue::Pointer_t
, tools::SvRef
<TableRowBuffer
>>;
119 using RTFBuffer_t
= std::deque
<Buf_t
>;
121 /// holds one nested table row
122 class TableRowBuffer
: public virtual SvRefBase
124 RTFBuffer_t m_aBuffer
;
125 ::std::deque
<RTFSprms
> m_aCellsSprms
;
126 ::std::deque
<RTFSprms
> m_aCellsAttributes
;
128 writerfilter::Reference
<Properties
>::Pointer_t m_pParaProperties
;
129 writerfilter::Reference
<Properties
>::Pointer_t m_pFrameProperties
;
130 writerfilter::Reference
<Properties
>::Pointer_t m_pRowProperties
;
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
))
142 RTFBuffer_t
& GetBuffer() { return m_aBuffer
; }
143 std::deque
<RTFSprms
>& GetCellsSprms() { return m_aCellsSprms
; }
144 std::deque
<RTFSprms
>& GetCellsAttributes() { return m_aCellsAttributes
; }
145 int GetCells() const { return m_nCells
; }
146 writerfilter::Reference
<Properties
>::Pointer_t
& GetParaProperties()
148 return m_pParaProperties
;
150 writerfilter::Reference
<Properties
>::Pointer_t
& GetFrameProperties()
152 return m_pFrameProperties
;
154 writerfilter::Reference
<Properties
>::Pointer_t
& GetRowProperties() { return m_pRowProperties
; }
157 /// An entry in the color table.
158 class RTFColorTableEntry
161 void SetRed(sal_uInt8 nRed
)
166 void SetGreen(sal_uInt8 nGreen
)
171 void SetBlue(sal_uInt8 nBlue
)
176 Color
GetColor() const { return m_bAuto
? COL_AUTO
: Color(m_nR
, m_nG
, m_nB
); }
185 /// Stores the properties of a shape.
186 class RTFShape
: public virtual SvRefBase
191 std::vector
<std::pair
<OUString
, OUString
>>& getProperties() { return m_aProperties
; }
193 const std::vector
<std::pair
<OUString
, OUString
>>& getProperties() const
195 return m_aProperties
;
198 std::vector
<std::pair
<OUString
, OUString
>>& getGroupProperties() { return m_aGroupProperties
; }
200 void setLeft(sal_Int32 nLeft
) { m_nLeft
= nLeft
; }
202 sal_Int32
getLeft() const { return m_nLeft
; }
204 void setTop(sal_Int32 nTop
) { m_nTop
= nTop
; }
206 sal_Int32
getTop() const { return m_nTop
; }
208 void setRight(sal_Int32 nRight
) { m_nRight
= nRight
; }
210 sal_Int32
getRight() const { return m_nRight
; }
212 void setBottom(sal_Int32 nBottom
) { m_nBottom
= nBottom
; }
214 sal_Int32
getBottom() const { return m_nBottom
; }
216 void setZ(sal_Int32 nZ
) { m_oZ
= nZ
; }
218 bool hasZ() const { return bool(m_oZ
); }
220 sal_Int32
getZ() const { return *m_oZ
; }
222 void setHoriOrientRelation(sal_Int16 nHoriOrientRelation
)
224 m_nHoriOrientRelation
= nHoriOrientRelation
;
227 sal_Int16
getHoriOrientRelation() const { return m_nHoriOrientRelation
; }
229 void setVertOrientRelation(sal_Int16 nVertOrientRelation
)
231 m_nVertOrientRelation
= nVertOrientRelation
;
234 sal_Int16
getVertOrientRelation() const { return m_nVertOrientRelation
; }
236 void setHoriOrientRelationToken(sal_uInt32 nHoriOrientRelationToken
)
238 m_nHoriOrientRelationToken
= nHoriOrientRelationToken
;
241 sal_uInt32
getHoriOrientRelationToken() const { return m_nHoriOrientRelationToken
; }
243 void setVertOrientRelationToken(sal_uInt32 nVertOrientRelationToken
)
245 m_nVertOrientRelationToken
= nVertOrientRelationToken
;
248 sal_uInt32
getVertOrientRelationToken() const { return m_nVertOrientRelationToken
; }
250 void setWrap(css::text::WrapTextMode nWrap
) { m_nWrap
= nWrap
; }
252 css::text::WrapTextMode
getWrap() const { return m_nWrap
; }
254 void setInBackground(bool bInBackground
) { m_bInBackground
= bInBackground
; }
256 bool getInBackground() const { return m_bInBackground
; }
258 RTFSprms
& getWrapPolygonSprms() { return m_aWrapPolygonSprms
; }
260 RTFSprms
& getAnchorAttributes() { return m_aAnchorAttributes
; }
262 std::pair
<Id
, RTFValue::Pointer_t
>& getWrapSprm() { return m_aWrapSprm
; }
265 std::vector
<std::pair
<OUString
, OUString
>> m_aProperties
; ///< Properties of a single shape.
266 std::vector
<std::pair
<OUString
, OUString
>>
267 m_aGroupProperties
; ///< Properties applied on the groupshape.
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
; ///< Z-Order of the shape.
273 sal_Int16 m_nHoriOrientRelation
274 = 0; ///< Horizontal text::RelOrientation for drawinglayer shapes.
275 sal_Int16 m_nVertOrientRelation
= 0; ///< Vertical text::RelOrientation for drawinglayer shapes.
276 sal_uInt32 m_nHoriOrientRelationToken
= 0; ///< Horizontal dmapper token for Writer pictures.
277 sal_uInt32 m_nVertOrientRelationToken
= 0; ///< Vertical dmapper token for Writer pictures.
278 css::text::WrapTextMode m_nWrap
= css::text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE
;
279 /// If shape is below text (true) or text is below shape (false).
280 bool m_bInBackground
= false;
281 /// Wrap polygon, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict().
282 RTFSprms m_aWrapPolygonSprms
;
283 /// Anchor attributes like wrap distance, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict().
284 RTFSprms m_aAnchorAttributes
;
285 /// Wrap type, written by RTFDocumentImpl::popState(), read by RTFDocumentImpl::resolvePict().
286 std::pair
<Id
, RTFValue::Pointer_t
> m_aWrapSprm
{ 0, nullptr };
289 /// Stores the properties of a drawing object.
290 class RTFDrawingObject
: public RTFShape
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
)
299 m_xPropertySet
= xPropertySet
;
301 const css::uno::Reference
<css::beans::XPropertySet
>& getPropertySet() const
303 return m_xPropertySet
;
305 std::vector
<css::beans::PropertyValue
>& getPendingProperties() { return m_aPendingProperties
; }
306 void setLineColorR(sal_uInt8 nLineColorR
) { m_nLineColorR
= nLineColorR
; }
307 sal_uInt8
getLineColorR() const { return m_nLineColorR
; }
308 void setLineColorG(sal_uInt8 nLineColorG
) { m_nLineColorG
= nLineColorG
; }
309 sal_uInt8
getLineColorG() const { return m_nLineColorG
; }
310 void setLineColorB(sal_uInt8 nLineColorB
) { m_nLineColorB
= nLineColorB
; }
311 sal_uInt8
getLineColorB() const { return m_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
; }
315 sal_uInt8
getFillColorR() const { return m_nFillColorR
; }
316 void setFillColorG(sal_uInt8 nFillColorG
) { m_nFillColorG
= nFillColorG
; }
317 sal_uInt8
getFillColorG() const { return m_nFillColorG
; }
318 void setFillColorB(sal_uInt8 nFillColorB
) { m_nFillColorB
= nFillColorB
; }
319 sal_uInt8
getFillColorB() const { return m_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
; }
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
;
336 sal_uInt8 m_nLineColorR
= 0;
337 sal_uInt8 m_nLineColorG
= 0;
338 sal_uInt8 m_nLineColorB
= 0;
339 bool m_bHasLineColor
= false;
340 sal_uInt8 m_nFillColorR
= 0;
341 sal_uInt8 m_nFillColorG
= 0;
342 sal_uInt8 m_nFillColorB
= 0;
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;
351 /// Stores the properties of a picture.
352 class RTFPicture
: public virtual SvRefBase
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;
365 sal_uInt16 eWMetafile
= 0;
366 RTFBmpStyle eStyle
= RTFBmpStyle::NONE
;
369 /// Stores the properties of a frame
373 RTFDocumentImpl
* m_pDocumentImpl
;
374 sal_Int32 m_nX
, m_nY
, m_nW
, m_nH
;
375 sal_Int32 m_nHoriPadding
, m_nVertPadding
;
376 sal_Int32 m_nHoriAlign
, m_nHoriAnchor
, m_nVertAlign
, m_nVertAnchor
;
378 std::optional
<Id
> m_oWrap
;
381 explicit RTFFrame(RTFParserState
* pParserState
);
383 /// Convert the stored properties to Sprms
386 void setSprm(Id nId
, Id nValue
);
387 bool hasProperties() const;
388 /// If we got tokens indicating we're in a frame.
389 bool inFrame() const;
392 /// State of the parser, which gets saved / restored when changing groups.
396 /// Maps to OOXML's ascii, cs or eastAsia.
409 explicit RTFParserState(RTFDocumentImpl
* pDocumentImpl
);
411 void appendDestinationText(std::u16string_view rString
)
413 if (m_pCurrentDestinationText
)
414 m_pCurrentDestinationText
->append(rString
);
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
)
423 m_nTableRowWidthAfter
= nTableRowWidthAfter
;
425 int getTableRowWidthAfter() const { return m_nTableRowWidthAfter
; }
426 void setStartedTrackchange(bool bStartedTrackchange
)
428 m_bStartedTrackchange
= bStartedTrackchange
;
430 bool getStartedTrackchange() const { return m_bStartedTrackchange
; }
431 void setCreatedShapeGroup(bool bCreatedShapeGroup
)
433 m_bCreatedShapeGroup
= bCreatedShapeGroup
;
435 bool getCreatedShapeGroup() const { return m_bCreatedShapeGroup
; }
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
; }
447 RTFBuffer_t
* getCurrentBuffer() const { return m_pCurrentBuffer
; }
448 void setCurrentListOverrideIndex(int nCurrentListOverrideIndex
)
450 m_nCurrentListOverrideIndex
= nCurrentListOverrideIndex
;
452 int getCurrentListOverrideIndex() const { return m_nCurrentListOverrideIndex
; }
453 void setCurrentListIndex(int nCurrentListIndex
) { m_nCurrentListIndex
= nCurrentListIndex
; }
454 int getCurrentListIndex() const { return m_nCurrentListIndex
; }
455 void setCurrentCharacterStyleIndex(int nCurrentCharacterStyleIndex
)
457 m_nCurrentCharacterStyleIndex
= nCurrentCharacterStyleIndex
;
459 int getCurrentCharacterStyleIndex() const { return m_nCurrentCharacterStyleIndex
; }
460 void setCurrentStyleIndex(int nCurrentStyleIndex
) { m_nCurrentStyleIndex
= nCurrentStyleIndex
; }
461 int getCurrentStyleIndex() const { return m_nCurrentStyleIndex
; }
462 void setCurrentDestinationText(OUStringBuffer
* pDestinationText
)
464 m_pCurrentDestinationText
= pDestinationText
;
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
; }
480 RTFFrame
& getFrame() { return m_aFrame
; }
481 RTFDrawingObject
& getDrawingObject() { return m_aDrawingObject
; }
482 RTFShape
& getShape() { return m_aShape
; }
483 RTFPicture
& getPicture() { return m_aPicture
; }
484 void setLevelNumbersValid(bool bLevelNumbersValid
)
486 m_bLevelNumbersValid
= bLevelNumbersValid
;
488 bool getLevelNumbersValid() const { return m_bLevelNumbersValid
; }
489 std::vector
<sal_Int32
>& getLevelNumbers() { return m_aLevelNumbers
; }
490 RTFSprms
& getListLevelEntries() { return m_aListLevelEntries
; }
491 int& getListLevelNum() { return m_nListLevelNum
; }
492 void setBinaryToRead(int nBinaryToRead
) { m_nBinaryToRead
= nBinaryToRead
; }
493 int getBinaryToRead() const { return m_nBinaryToRead
; }
494 int& getCharsToSkip() { return m_nCharsToSkip
; }
495 void setUc(int nUc
) { m_nUc
= nUc
; }
496 int getUc() const { return m_nUc
; }
497 void setCurrentEncoding(rtl_TextEncoding nCurrentEncoding
)
499 m_nCurrentEncoding
= nCurrentEncoding
;
501 rtl_TextEncoding
getCurrentEncoding() const { return m_nCurrentEncoding
; }
502 RTFColorTableEntry
& getCurrentColor() { return m_aCurrentColor
; }
503 RTFSprms
& getTabAttributes() { return m_aTabAttributes
; }
504 RTFSprms
& getTableCellAttributes() { return m_aTableCellAttributes
; }
505 RTFSprms
& getTableCellSprms() { return m_aTableCellSprms
; }
506 RTFSprms
& getTableRowAttributes() { return m_aTableRowAttributes
; }
507 RTFSprms
& getTableRowSprms() { return m_aTableRowSprms
; }
508 RTFSprms
& getSectionAttributes() { return m_aSectionAttributes
; }
509 RTFSprms
& getSectionSprms() { return m_aSectionSprms
; }
510 RTFSprms
& getParagraphAttributes() { return m_aParagraphAttributes
; }
511 RTFSprms
& getParagraphSprms() { return m_aParagraphSprms
; }
512 RTFSprms
& getCharacterAttributes() { return m_aCharacterAttributes
; }
513 RTFSprms
& getCharacterSprms() { return m_aCharacterSprms
; }
514 RTFSprms
& getTableAttributes() { return m_aTableAttributes
; }
515 RTFSprms
& getTableSprms() { return m_aTableSprms
; }
516 void setBorderState(RTFBorderState nBorderState
) { m_nBorderState
= nBorderState
; }
517 RTFBorderState
getBorderState() const { return m_nBorderState
; }
518 void setFieldStatus(RTFFieldStatus eFieldStatus
) { m_eFieldStatus
= eFieldStatus
; }
519 RTFFieldStatus
getFieldStatus() const { return m_eFieldStatus
; }
520 void setFieldLocked(bool bSet
) { m_bFieldLocked
= bSet
; }
521 bool isFieldLocked() const { return m_bFieldLocked
; }
522 void setDestination(Destination eDestination
) { m_eDestination
= eDestination
; }
523 Destination
getDestination() const { return m_eDestination
; }
524 void setInternalState(RTFInternalState nInternalState
) { m_nInternalState
= nInternalState
; }
525 RTFInternalState
getInternalState() const { return m_nInternalState
; }
526 RTFDocumentImpl
* getDocumentImpl() { return m_pDocumentImpl
; }
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
; }
531 void clearDocVarName() { m_aDocVarName
= ""; }
534 RTFDocumentImpl
* m_pDocumentImpl
;
535 RTFInternalState m_nInternalState
;
536 Destination m_eDestination
;
537 RTFFieldStatus m_eFieldStatus
;
539 RTFBorderState m_nBorderState
;
540 // font table, stylesheet table
541 RTFSprms m_aTableSprms
;
542 RTFSprms m_aTableAttributes
;
544 RTFSprms m_aCharacterSprms
;
545 RTFSprms m_aCharacterAttributes
;
547 RTFSprms m_aParagraphSprms
;
548 RTFSprms m_aParagraphAttributes
;
550 RTFSprms m_aSectionSprms
;
551 RTFSprms m_aSectionAttributes
;
553 RTFSprms m_aTableRowSprms
;
554 RTFSprms m_aTableRowAttributes
;
556 RTFSprms m_aTableCellSprms
;
557 RTFSprms m_aTableCellAttributes
;
559 RTFSprms m_aTabAttributes
;
561 RTFColorTableEntry m_aCurrentColor
;
563 rtl_TextEncoding m_nCurrentEncoding
;
565 /// Current \uc value.
567 /// Characters to skip, set to nUc by \u.
569 /// Characters to read, once in binary mode.
572 /// Next list level index to use when parsing list table.
574 /// List level entries, which will form a list entry later.
575 RTFSprms m_aListLevelEntries
;
576 /// List of character positions in leveltext to replace.
577 std::vector
<sal_Int32
> m_aLevelNumbers
;
578 /// If aLevelNumbers should be read at all.
579 bool m_bLevelNumbersValid
;
581 RTFPicture m_aPicture
;
583 RTFDrawingObject m_aDrawingObject
;
593 sal_uInt16 m_nMinute
;
595 /// Text from special destinations.
596 OUStringBuffer m_aDestinationText
{ 512 };
597 /// point to the buffer of the current destination
598 OUStringBuffer
* m_pCurrentDestinationText
;
600 /// Index of the current style.
601 int m_nCurrentStyleIndex
;
602 /// Index of the current character style.
603 int m_nCurrentCharacterStyleIndex
;
604 /// Current listid, points to a listtable entry.
605 int m_nCurrentListIndex
= -1;
606 /// Current ls, points to a listoverridetable entry.
607 int m_nCurrentListOverrideIndex
= -1;
609 /// Points to the active buffer, if there is one.
610 RTFBuffer_t
* m_pCurrentBuffer
;
612 /// If we're inside a \listpicture group.
613 bool m_bInListpicture
;
615 /// If we're inside a \background group.
616 bool m_bInBackground
;
618 bool m_bHadShapeText
;
619 bool m_bInShapeGroup
; ///< If we're inside a \shpgrp group.
620 bool m_bInShape
; ///< If we're inside a \shp group.
621 bool m_bCreatedShapeGroup
; ///< A GroupShape was created and pushed to the parent stack.
622 bool m_bStartedTrackchange
; ///< Track change is started, need to end it before popping.
624 /// User-defined property: key name.
625 OUString m_aPropName
;
626 /// User-defined property: value type.
627 css::uno::Type m_aPropType
;
629 /// Width of invisible cell at the end of the row.
630 int m_nTableRowWidthAfter
;
632 /// For importing document variables which are not referenced in the document
634 OUString m_aDocVarName
;
637 /// An RTF stack is similar to std::stack, except that it has an operator[].
641 std::deque
<RTFParserState
> m_Impl
;
644 RTFParserState
& top()
647 throw css::io::WrongFormatException(
648 "Parser state is empty! Invalid usage of destination braces in RTF?", nullptr);
649 return m_Impl
.back();
654 throw css::io::WrongFormatException(
655 "Parser state is empty! Invalid usage of destination braces in RTF?", nullptr);
656 return m_Impl
.pop_back();
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
]; }
665 void putBorderProperty(RTFStack
& aStates
, Id nId
, const RTFValue::Pointer_t
& pValue
);
666 void putNestedSprm(RTFSprms
& rSprms
, Id nParent
, Id nId
, const RTFValue::Pointer_t
& pValue
,
667 RTFOverwrite eOverwrite
= RTFOverwrite::NO_APPEND
);
668 Id
getParagraphBorder(sal_uInt32 nIndex
);
669 void putNestedAttribute(RTFSprms
& rSprms
, Id nParent
, Id nId
, const RTFValue::Pointer_t
& pValue
,
670 RTFOverwrite eOverwrite
= RTFOverwrite::YES
, bool bAttribute
= true);
671 bool eraseNestedAttribute(RTFSprms
& rSprms
, Id nParent
, Id nId
);
673 /// Looks up the nParent then the nested nId attribute in rSprms.
674 RTFValue::Pointer_t
getNestedAttribute(RTFSprms
& rSprms
, Id nParent
, Id nId
);
676 /// Looks up the nParent then the nested nId sprm in rSprms.
677 RTFValue::Pointer_t
getNestedSprm(RTFSprms
& rSprms
, Id nParent
, Id nId
);
679 /// Checks if rName is contained at least once in rProperties as a key.
680 bool findPropertyName(const std::vector
<css::beans::PropertyValue
>& rProperties
,
681 const OUString
& rName
);
682 RTFSprms
& getLastAttributes(RTFSprms
& rSprms
, Id nId
);
683 OString
DTTM22OString(tools::Long nDTTM
);
685 /// Implementation of the RTFDocument interface.
686 class RTFDocumentImpl
: public RTFDocument
, public RTFListener
689 using Pointer_t
= tools::SvRef
<RTFDocumentImpl
>;
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
);
696 ~RTFDocumentImpl() override
;
699 void resolve(Stream
& rMapper
) override
;
702 RTFError
dispatchDestination(RTFKeyword nKeyword
) override
;
703 RTFError
dispatchFlag(RTFKeyword nKeyword
) override
;
704 /// Dispatches flags related to Positioned Wrapped Tables.
705 bool dispatchFloatingTableFlag(RTFKeyword nKeyword
);
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
;
718 RTFError
beforePopState(RTFParserState
& rState
);
719 RTFError
popState() override
;
720 void afterPopState(RTFParserState
& rState
);
721 Destination
getDestination() override
;
722 void setDestination(Destination eDestination
) override
;
723 RTFInternalState
getInternalState() 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
;
730 Stream
& Mapper() { return *m_pMapperStream
; }
731 void setSuperstream(RTFDocumentImpl
* pSuperstream
);
732 const css::uno::Reference
<css::lang::XMultiServiceFactory
>& getModelFactory() const
734 return m_xModelFactory
;
736 bool isInBackground();
737 void setDestinationText(std::u16string_view rString
);
738 /// Resolve a picture: If not inline, then anchored.
739 void resolvePict(bool bInline
, css::uno::Reference
<css::drawing::XShape
> const& rShape
);
741 /// If this is the first run of the document, starts the initial paragraph.
742 void checkFirstRun();
743 /// Send NS_ooxml::LN_settings_settings to dmapper.
744 void outputSettingsTable();
745 /// If the initial paragraph is started.
746 bool getFirstRun() const { return m_bFirstRun
; }
747 /// If we need to add a dummy paragraph before a section break.
748 void setNeedPar(bool bNeedPar
);
749 /// Return the dmapper index of an RTF index for fonts.
750 int getFontIndex(int nIndex
);
751 /// Return the name of the font, based on a dmapper index.
752 OUString
getFontName(int nIndex
);
753 /// Return the style name of an RTF style index.
754 OUString
getStyleName(int nIndex
);
755 /// Return the style type of an RTF style index.
756 Id
getStyleType(int nIndex
);
757 /// Return the encoding associated with a font index.
758 rtl_TextEncoding
getEncoding(int nFontIndex
);
759 /// Get the default parser state.
760 RTFParserState
& getDefaultState();
761 oox::GraphicHelper
& getGraphicHelper();
762 /// Are we inside the stylesheet table?
763 bool isStyleSheetImport();
764 /// Resets m_aStates.top().aFrame.
766 /// Buffers properties to be sent later.
767 void bufferProperties(RTFBuffer_t
& rBuffer
, const RTFValue::Pointer_t
& pValue
,
768 const tools::SvRef
<TableRowBuffer
>& pTableProperties
, Id nStyleType
= 0);
769 /// implement non-obvious RTF specific style inheritance
770 RTFReferenceTable::Entries_t
deduplicateStyleTable();
774 Color
getColorTable(sal_uInt32 nIndex
);
775 writerfilter::Reference
<Properties
>::Pointer_t
createStyleProperties();
777 void resetAttributes();
778 void resolveSubstream(std::size_t nPos
, Id nId
);
779 void resolveSubstream(std::size_t nPos
, Id nId
, OUString
const& rIgnoreFirst
);
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.
789 writerfilter::Reference
<Properties
>::Pointer_t
790 getProperties(const RTFSprms
& rAttributes
, RTFSprms
const& rSprms
, Id nStyleType
);
792 void handleFontTableEntry();
793 void sectBreak(bool bFinal
= false);
794 void prepareProperties(RTFParserState
& rState
,
795 writerfilter::Reference
<Properties
>::Pointer_t
& o_rpParagraphProperties
,
796 writerfilter::Reference
<Properties
>::Pointer_t
& o_rpFrameProperties
,
797 writerfilter::Reference
<Properties
>::Pointer_t
& o_rpTableRowProperties
,
798 int nCells
, int nCurrentCellX
);
799 /// Send the passed properties to dmapper.
800 void sendProperties(writerfilter::Reference
<Properties
>::Pointer_t
const& pParagraphProperties
,
801 writerfilter::Reference
<Properties
>::Pointer_t
const& pFrameProperties
,
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
);
806 /// If we have some unicode or hex characters to send.
807 void checkUnicode(bool bUnicode
, bool bHex
);
808 /// If we need a final section break at the end of the document.
809 void setNeedSect(bool bNeedSect
);
810 void resetTableRowProperties();
811 void backupTableRowProperties();
812 void restoreTableRowProperties();
813 /// Turns the destination text into an input stream of the current OLE attributes.
814 RTFError
handleEmbeddedObject();
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
;
824 Stream
* m_pMapperStream
;
825 tools::SvRef
<RTFSdrImport
> m_pSdrImport
;
826 tools::SvRef
<RTFTokenizer
> m_pTokenizer
;
828 /// Read by RTF_PARD.
829 RTFParserState m_aDefaultState
;
831 /// Font index <-> encoding map, *not* part of the parser state
832 std::map
<int, rtl_TextEncoding
> m_aFontEncodings
;
833 /// Font index <-> name map.
834 std::map
<int, OUString
> m_aFontNames
;
835 /// Maps the non-continuous font indexes to the continuous dmapper indexes.
836 std::vector
<int> m_aFontIndexes
;
837 /// Maps style indexes to style names.
838 std::map
<int, OUString
> m_aStyleNames
;
839 /// Maps style indexes to style types.
840 std::map
<int, Id
> m_aStyleTypes
;
841 /// Color index <-> RGB color value map
842 std::vector
<Color
> m_aColorTable
;
843 /// to start initial paragraph / section after font/style tables
845 /// except in the case of tables in initial multicolumn section (global for assertion)
846 bool m_bFirstRunException
;
847 /// If paragraph properties should be emitted on next run.
849 /// If we need to emit a CR at the end of substream.
851 /// Original value of m_bNeedCr -- saved/restored before/after textframes.
854 /// If set, an empty paragraph will be added at the end of the document.
855 bool m_bNeedFinalPar
;
856 /// The list table and list override table combined.
857 RTFSprms m_aListTableSprms
;
858 /// Maps between listoverridetable and listtable indexes.
859 std::map
<int, int> m_aListOverrideTable
;
860 /// Maps listtable indexes to listtable entries.
861 std::map
<int, RTFValue::Pointer_t
> m_aListTable
;
862 /// Index of the current list level in a list table entry.
863 int m_nListLevel
= -1;
864 /// Maps List level indexes to removed values in the current list entry.
865 std::map
<int, int> m_aInvalidListLevelFirstIndents
;
866 /// Maps list table indexes to levels (and their removed values).
867 std::map
<int, std::map
<int, int>> m_aInvalidListTableFirstIndents
;
868 /// The settings table attributes.
869 RTFSprms m_aSettingsTableAttributes
;
870 /// The settings table sprms.
871 RTFSprms m_aSettingsTableSprms
;
873 std::shared_ptr
<oox::GraphicHelper
> m_pGraphicHelper
;
875 /// cell props buffer for nested tables, reset by \nestrow
876 /// the \nesttableprops is a destination and must follow the
877 /// nested cells, so it should be sufficient to store the
878 /// currently active one, no need for a stack of them
880 std::deque
<RTFSprms
> m_aNestedTableCellsSprms
;
881 std::deque
<RTFSprms
> m_aNestedTableCellsAttributes
;
882 /// cell props buffer for top-level table, reset by \row
883 int m_nTopLevelCells
;
884 std::deque
<RTFSprms
> m_aTopLevelTableCellsSprms
;
885 std::deque
<RTFSprms
> m_aTopLevelTableCellsAttributes
;
886 /// backup of top-level props, to support inheriting cell props
887 int m_nInheritingCells
;
888 std::deque
<RTFSprms
> m_aTableInheritingCellsSprms
;
889 std::deque
<RTFSprms
> m_aTableInheritingCellsAttributes
;
891 // Left row margin (for nested and top-level rows)
893 int m_nTopLevelTRLeft
;
895 /// Current cellx value (nested table)
896 int m_nNestedCurrentCellX
;
897 /// Current cellx value (top-level table)
898 int m_nTopLevelCurrentCellX
;
900 // Backup of what \trowd clears, to work around invalid input.
901 RTFSprms m_aBackupTableRowSprms
;
902 RTFSprms m_aBackupTableRowAttributes
;
903 int m_nBackupTopLevelCurrentCellX
;
905 /// Buffered table cells, till cell definitions are not reached.
906 /// for nested table, one buffer per table level
907 std::deque
<RTFBuffer_t
> m_aTableBufferStack
;
908 /// Buffered superscript, till footnote is reached (or not).
909 RTFBuffer_t m_aSuperBuffer
;
911 /// Superstream of this substream.
912 RTFDocumentImpl
* m_pSuperstream
;
913 /// Type of the stream: header, footer, footnote, etc.
915 std::queue
<std::pair
<Id
, std::size_t>> m_nHeaderFooterPositions
;
916 std::size_t m_nGroupStartPos
;
917 /// Ignore the first occurrence of this text.
918 OUString m_aIgnoreFirst
;
919 /// Bookmark name <-> index map.
920 std::map
<OUString
, int> m_aBookmarks
;
921 /// Revision index <-> author map.
922 std::map
<int, OUString
> m_aAuthors
;
923 /// Annotation author of the next annotation.
925 /// Initials of author of the next annotation.
926 OUString m_aAuthorInitials
;
928 RTFSprms m_aFormfieldSprms
;
929 RTFSprms m_aFormfieldAttributes
;
930 RTFFormFieldType m_nFormFieldType
;
932 /// OLE attributes are attributes of the ooxml:OLEObject_OLEObject sprm.
933 RTFSprms m_aOLEAttributes
;
934 RTFSprms m_aObjectAttributes
;
935 /** If we are in an object group and if the we use its
937 * (if we don't use the \objdata we use the \result element)*/
939 /// If the data for a picture is a binary one, it's stored here.
940 std::shared_ptr
<SvStream
> m_pBinaryData
;
942 RTFReferenceTable::Entries_t m_aFontTableEntries
;
943 int m_nCurrentFontIndex
;
944 /// Used only during font table parsing till we don't know the font name.
945 int m_nCurrentEncoding
;
946 /// Raw default font index, use getFont() on it to get a real one.
947 int m_nDefaultFontIndex
;
949 /// To avoid copying entries between DomainMapper instances it is stored as pointer
950 std::shared_ptr
<RTFReferenceTable::Entries_t
> m_pStyleTableEntries
;
951 int m_nCurrentStyleIndex
;
953 /// For the INCLUDEPICTURE field's argument.
954 OUString m_aPicturePath
;
955 // Unicode characters are collected here so we don't have to send them one by one.
956 OUStringBuffer m_aUnicodeBuffer
{ 512 };
957 /// Same for hex characters.
958 OStringBuffer m_aHexBuffer
{ 512 };
960 oox::formulaimport::XmlStreamBuilder m_aMathBuffer
;
961 /// Normal text property, that is math italic and math spacing are not applied to the current run.
963 /// If the next continuous section break should be ignored.
964 bool m_bIgnoreNextContSectBreak
;
965 /// clean up a synthetic page break, see RTF_PAGE
966 /// if inactive value is -1, otherwise the RTF_SKB* to restore
967 RTFKeyword m_nResetBreakOnSectBreak
;
968 /// If a section break is needed before the end of the doc (false right after a section break).
970 /// If aFrame.inFrame() was true in the previous state.
972 /// A picture was seen in the current paragraph.
974 /// The document has multiple sections.
976 /// Max width of the rows in the current table.
978 /// ID of the next \listlevel picture.
979 int m_nListPictureId
;
981 /// New document means not pasting into an existing one.
983 /// The media descriptor contains e.g. the base URL of the document.
984 const utl::MediaDescriptor
& m_rMediaDescriptor
;
986 /// Flags for ensuring that only one header and footer is added per section
992 /// Are we after a \cell, but before a \row?
993 bool m_bAfterCellBeforeRow
;
995 } // namespace writerfilter::rtftok
997 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */