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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _RTFATTRIBUTEOUTPUT_HXX_
21 #define _RTFATTRIBUTEOUTPUT_HXX_
23 #include "attributeoutputbase.hxx"
24 #include "rtfexport.hxx"
25 #include "rtfstringbuffer.hxx"
27 #include <rtl/strbuf.hxx>
28 #include <svx/xenum.hxx>
30 #include <boost/optional.hpp>
36 /// The class that has handlers for various resource types when exporting as RTF
37 class RtfAttributeOutput
: public AttributeOutputBase
39 friend class RtfStringBufferValue
;
41 /// Export the state of RTL/CJK.
42 virtual void RTLAndCJKState( bool bIsRTL
, sal_uInt16 nScript
);
44 /// Start of the paragraph.
45 virtual void StartParagraph( ww8::WW8TableNodeInfo::Pointer_t pTextNodeInfo
);
47 /// End of the paragraph.
48 virtual void EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner
);
51 virtual void EmptyParagraph();
53 /// Called before we start outputting the attributes.
54 virtual void StartParagraphProperties( const SwTxtNode
& rNode
);
56 /// Called after we end outputting the attributes.
57 virtual void EndParagraphProperties();
59 /// Start of the text run.
60 virtual void StartRun( const SwRedlineData
* pRedlineData
, bool bSingleEmptyRun
= false );
62 /// End of the text run.
63 virtual void EndRun();
65 /// Called before we start outputting the attributes.
66 virtual void StartRunProperties();
68 /// Called after we end outputting the attributes.
69 virtual void EndRunProperties( const SwRedlineData
* pRedlineData
);
71 virtual void WritePostitFieldStart() SAL_OVERRIDE
;
73 virtual void WritePostitFieldEnd() SAL_OVERRIDE
;
75 /// Output text (inside a run).
76 virtual void RunText( const String
& rText
, rtl_TextEncoding eCharSet
= RTL_TEXTENCODING_UTF8
);
78 // Access to (anyway) private buffers, used by the sdr exporter
79 OStringBuffer
& RunText();
80 OStringBuffer
& Styles();
82 /// Output text (without markup).
83 virtual void RawText( const String
& rText
, bool bForceUnicode
, rtl_TextEncoding eCharSet
);
85 /// Output ruby start.
86 virtual void StartRuby( const SwTxtNode
& rNode
, xub_StrLen nPos
, const SwFmtRuby
& rRuby
);
89 virtual void EndRuby();
92 virtual bool StartURL( const String
& rUrl
, const String
& rTarget
);
95 virtual bool EndURL();
97 virtual void FieldVanish( const String
& rTxt
, ww::eField eType
);
101 /// The common attribute that can be among the run properties.
102 virtual void Redline( const SwRedlineData
* pRedline
);
104 virtual void FormatDrop( const SwTxtNode
& rNode
, const SwFmtDrop
& rSwFmtDrop
, sal_uInt16 nStyle
, ww8::WW8TableNodeInfo::Pointer_t pTextNodeInfo
, ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner
);
107 virtual void ParagraphStyle( sal_uInt16 nStyle
);
109 virtual void TableInfoCell( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
110 virtual void TableInfoRow( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
111 virtual void TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
112 virtual void TableDefaultBorders( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
113 virtual void TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
114 virtual void TableHeight( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
115 virtual void TableCanSplit( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
116 virtual void TableBidi( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
117 virtual void TableVerticalCell( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
118 virtual void TableNodeInfo( ww8::WW8TableNodeInfo::Pointer_t pNodeInfo
);
119 virtual void TableNodeInfoInner( ww8::WW8TableNodeInfoInner::Pointer_t pNodeInfoInner
);
120 virtual void TableOrientation( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
121 virtual void TableSpacing( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
122 virtual void TableRowEnd( sal_uInt32 nDepth
);
124 /// Start of the styles table.
125 virtual void StartStyles();
127 /// End of the styles table.
128 virtual void EndStyles( sal_uInt16 nNumberOfStyles
);
130 /// Write default style.
131 virtual void DefaultStyle( sal_uInt16 nStyle
);
133 /// Start of a style in the styles table.
134 virtual void StartStyle( const String
& rName
, bool bPapFmt
,
135 sal_uInt16 nBase
, sal_uInt16 nNext
, sal_uInt16 nWwId
, sal_uInt16 nId
,
138 /// End of a style in the styles table.
139 virtual void EndStyle();
141 /// Start of (paragraph or run) properties of a style.
142 virtual void StartStyleProperties( bool bParProp
, sal_uInt16 nStyle
);
144 /// End of (paragraph or run) properties of a style.
145 virtual void EndStyleProperties( bool bParProp
);
147 /// Numbering rule and Id.
148 virtual void OutlineNumbering( sal_uInt8 nLvl
, const SwNumFmt
&rNFmt
, const SwFmt
&rFmt
);
151 /// As a paragraph property - the paragraph should be on the next page.
152 virtual void PageBreakBefore( bool bBreak
);
154 /// Write a section break
155 /// msword::ColumnBreak or msword::PageBreak
156 virtual void SectionBreak( sal_uInt8 nC
, const WW8_SepInfo
* pSectionInfo
= NULL
);
158 /// Start of the section properties.
159 virtual void StartSection();
161 /// End of the section properties.
162 virtual void EndSection();
164 /// Protection of forms.
165 virtual void SectionFormProtection( bool bProtected
);
167 /// Numbering of the lines in the document.
168 virtual void SectionLineNumbering( sal_uLong nRestartNo
, const SwLineNumberInfo
& rLnNumInfo
);
170 /// Has different headers/footers for the title page.
171 virtual void SectionTitlePage();
173 /// Description of the page borders.
174 virtual void SectionPageBorders( const SwFrmFmt
* pFmt
, const SwFrmFmt
* pFirstPageFmt
);
176 /// Columns populated from right/numbers on the right side?
177 virtual void SectionBiDi( bool bBiDi
);
179 /// The style of the page numbers.
181 /// nPageRestartNumberr being 0 means no restart.
182 virtual void SectionPageNumbering( sal_uInt16 nNumType
, sal_uInt16 nPageRestartNumber
);
184 /// The type of breaking.
185 virtual void SectionType( sal_uInt8 nBreakCode
);
187 /// Definition of a numbering instance.
188 virtual void NumberingDefinition( sal_uInt16 nId
, const SwNumRule
&rRule
);
190 /// Start of the abstract numbering definition instance.
191 virtual void StartAbstractNumbering( sal_uInt16 nId
) SAL_OVERRIDE
;
193 /// End of the abstract numbering definition instance.
194 virtual void EndAbstractNumbering() SAL_OVERRIDE
;
196 /// All the numbering level information.
197 virtual void NumberingLevel( sal_uInt8 nLevel
,
199 sal_uInt16 nNumberingType
,
201 const sal_uInt8
*pNumLvlPos
,
204 const SfxItemSet
*pOutSet
,
206 sal_Int16 nFirstLineIndex
,
207 sal_Int16 nListTabPos
,
208 const String
&rNumberingString
,
209 const SvxBrushItem
* pBrush
= 0);//For i120928,to export graphic of bullet
211 void WriteField_Impl( const SwField
* pFld
, ww::eField eType
, const String
& rFldCmd
, sal_uInt8 nMode
);
212 void WriteBookmarks_Impl( std::vector
< OUString
>& rStarts
, std::vector
< OUString
>& rEnds
);
213 void WriteHeaderFooter_Impl( const SwFrmFmt
& rFmt
, bool bHeader
, const sal_Char
* pStr
, bool bTitlepg
);
216 /// Output frames - the implementation.
217 virtual void OutputFlyFrame_Impl( const sw::Frame
& rFmt
, const Point
& rNdTopLeft
);
219 /// Sfx item Sfx item RES_CHRATR_CASEMAP
220 virtual void CharCaseMap( const SvxCaseMapItem
& rCaseMap
);
222 /// Sfx item Sfx item RES_CHRATR_COLOR
223 virtual void CharColor( const SvxColorItem
& rColor
);
225 /// Sfx item Sfx item RES_CHRATR_CONTOUR
226 virtual void CharContour( const SvxContourItem
& rContour
);
228 /// Sfx item RES_CHRATR_CROSSEDOUT
229 virtual void CharCrossedOut( const SvxCrossedOutItem
& rCrossedOut
);
231 /// Sfx item RES_CHRATR_ESCAPEMENT
232 virtual void CharEscapement( const SvxEscapementItem
& rEscapement
);
234 /// Sfx item RES_CHRATR_FONT
235 virtual void CharFont( const SvxFontItem
& rFont
);
237 /// Sfx item RES_CHRATR_FONTSIZE
238 virtual void CharFontSize( const SvxFontHeightItem
& rFontSize
);
240 /// Sfx item RES_CHRATR_KERNING
241 virtual void CharKerning( const SvxKerningItem
& rKerning
);
243 /// Sfx item RES_CHRATR_LANGUAGE
244 virtual void CharLanguage( const SvxLanguageItem
& rLanguage
);
246 /// Sfx item RES_CHRATR_POSTURE
247 virtual void CharPosture( const SvxPostureItem
& rPosture
);
249 /// Sfx item RES_CHRATR_SHADOWED
250 virtual void CharShadow( const SvxShadowedItem
& rShadow
);
252 /// Sfx item RES_CHRATR_UNDERLINE
253 virtual void CharUnderline( const SvxUnderlineItem
& rUnderline
);
255 /// Sfx item RES_CHRATR_WEIGHT
256 virtual void CharWeight( const SvxWeightItem
& rWeight
);
258 /// Sfx item RES_CHRATR_AUTOKERN
259 virtual void CharAutoKern( const SvxAutoKernItem
& );
261 /// Sfx item RES_CHRATR_BLINK
262 virtual void CharAnimatedText( const SvxBlinkItem
& rBlink
);
264 /// Sfx item RES_CHRATR_BACKGROUND
265 virtual void CharBackground( const SvxBrushItem
& rBrush
);
267 /// Sfx item RES_CHRATR_CJK_FONT
268 virtual void CharFontCJK( const SvxFontItem
& rFont
);
270 /// Sfx item RES_CHRATR_CJK_FONTSIZE
271 virtual void CharFontSizeCJK( const SvxFontHeightItem
& rFontSize
);
273 /// Sfx item RES_CHRATR_CJK_LANGUAGE
274 virtual void CharLanguageCJK( const SvxLanguageItem
& rLanguageItem
);
276 /// Sfx item RES_CHRATR_CJK_POSTURE
277 virtual void CharPostureCJK( const SvxPostureItem
& rPosture
);
279 /// Sfx item RES_CHRATR_CJK_WEIGHT
280 virtual void CharWeightCJK( const SvxWeightItem
& rWeight
);
282 /// Sfx item RES_CHRATR_CTL_FONT
283 virtual void CharFontCTL( const SvxFontItem
& rFont
);
285 /// Sfx item RES_CHRATR_CTL_FONTSIZE
286 virtual void CharFontSizeCTL( const SvxFontHeightItem
& rFontSize
);
288 /// Sfx item RES_CHRATR_CTL_LANGUAGE
289 virtual void CharLanguageCTL( const SvxLanguageItem
& rLanguageItem
);
291 /// Sfx item RES_CHRATR_CTL_POSTURE
292 virtual void CharPostureCTL( const SvxPostureItem
& rWeight
);
294 /// Sfx item RES_CHRATR_CTL_WEIGHT
295 virtual void CharWeightCTL( const SvxWeightItem
& rWeight
);
297 /// Sfx item RES_CHRATR_ROTATE
298 virtual void CharRotate( const SvxCharRotateItem
& rRotate
);
300 /// Sfx item RES_CHRATR_EMPHASIS_MARK
301 virtual void CharEmphasisMark( const SvxEmphasisMarkItem
& rEmphasisMark
);
303 /// Sfx item RES_CHRATR_TWO_LINES
304 virtual void CharTwoLines( const SvxTwoLinesItem
& rTwoLines
);
306 /// Sfx item RES_CHRATR_SCALEW
307 virtual void CharScaleWidth( const SvxCharScaleWidthItem
& rScaleWidth
);
309 /// Sfx item RES_CHRATR_RELIEF
310 virtual void CharRelief( const SvxCharReliefItem
& rRelief
);
312 /// Sfx item RES_CHRATR_HIDDEN
313 virtual void CharHidden( const SvxCharHiddenItem
& rHidden
);
315 /// Sfx item RES_TXTATR_INETFMT
316 virtual void TextINetFormat( const SwFmtINetFmt
& );
318 /// Sfx item RES_TXTATR_CHARFMT
319 virtual void TextCharFormat( const SwFmtCharFmt
& );
321 /// Sfx item RES_TXTATR_FTN
322 virtual void TextFootnote_Impl( const SwFmtFtn
& );
324 /// Sfx item RES_PARATR_LINESPACING
325 virtual void ParaLineSpacing_Impl( short nSpace
, short nMulti
);
327 /// Sfx item RES_PARATR_ADJUST
328 virtual void ParaAdjust( const SvxAdjustItem
& rAdjust
);
330 /// Sfx item RES_PARATR_SPLIT
331 virtual void ParaSplit( const SvxFmtSplitItem
& rSplit
);
333 /// Sfx item RES_PARATR_WIDOWS
334 virtual void ParaWidows( const SvxWidowsItem
& rWidows
);
336 /// Sfx item RES_PARATR_TABSTOP
337 virtual void ParaTabStop( const SvxTabStopItem
& rTabStop
);
339 /// Sfx item RES_PARATR_HYPHENZONE
340 virtual void ParaHyphenZone( const SvxHyphenZoneItem
& );
342 /// Sfx item RES_PARATR_NUMRULE
343 virtual void ParaNumRule_Impl( const SwTxtNode
*pTxtNd
, sal_Int32 nLvl
, sal_Int32 nNumId
);
345 /// Sfx item RES_PARATR_SCRIPTSPACE
346 virtual void ParaScriptSpace( const SfxBoolItem
& );
348 /// Sfx item RES_PARATR_VERTALIGN
349 virtual void ParaVerticalAlign( const SvxParaVertAlignItem
& rAlign
);
351 /// Sfx item RES_PARATR_SNAPTOGRID
352 virtual void ParaSnapToGrid( const SvxParaGridItem
& );
354 /// Sfx item RES_FRM_SIZE
355 virtual void FormatFrameSize( const SwFmtFrmSize
& );
357 /// Sfx item RES_PAPER_BIN
358 virtual void FormatPaperBin( const SvxPaperBinItem
& );
360 /// Sfx item RES_LR_SPACE
361 virtual void FormatLRSpace( const SvxLRSpaceItem
& rLRSpace
);
363 /// Sfx item RES_UL_SPACE
364 virtual void FormatULSpace( const SvxULSpaceItem
& rULSpace
);
366 /// Sfx item RES_SURROUND
367 virtual void FormatSurround( const SwFmtSurround
& );
369 /// Sfx item RES_VERT_ORIENT
370 virtual void FormatVertOrientation( const SwFmtVertOrient
& );
372 /// Sfx item RES_HORI_ORIENT
373 virtual void FormatHorizOrientation( const SwFmtHoriOrient
& );
375 /// Sfx item RES_ANCHOR
376 virtual void FormatAnchor( const SwFmtAnchor
& );
378 /// Sfx item RES_BACKGROUND
379 virtual void FormatBackground( const SvxBrushItem
& );
381 /// Sfx item RES_FILL_STYLE
382 virtual void FormatFillStyle( const XFillStyleItem
& );
384 /// Sfx item RES_FILL_GRADIENT
385 virtual void FormatFillGradient( const XFillGradientItem
& );
388 virtual void FormatBox( const SvxBoxItem
& );
391 virtual void FormatColumns_Impl( sal_uInt16 nCols
, const SwFmtCol
& rCol
, bool bEven
, SwTwips nPageSize
);
393 /// Sfx item RES_KEEP
394 virtual void FormatKeep( const SvxFmtKeepItem
& );
396 /// Sfx item RES_TEXTGRID
397 virtual void FormatTextGrid( const SwTextGridItem
& );
399 /// Sfx item RES_LINENUMBER
400 virtual void FormatLineNumbering( const SwFmtLineNumber
& );
402 /// Sfx item RES_FRAMEDIR
403 virtual void FormatFrameDirection( const SvxFrameDirectionItem
& );
405 /// Write the expanded field
406 virtual void WriteExpand( const SwField
* pFld
);
408 virtual void RefField( const SwField
& rFld
, const String
& rRef
);
409 virtual void HiddenField( const SwField
& rFld
);
410 virtual void SetField( const SwField
& rFld
, ww::eField eType
, const String
& rCmd
);
411 virtual void PostitField( const SwField
* pFld
);
412 virtual bool DropdownField( const SwField
* pFld
);
413 virtual bool PlaceholderField( const SwField
* pFld
);
415 /// Reference to the export, where to get the data from
416 RtfExport
&m_rExport
;
420 /// Output graphic fly frames.
421 void FlyFrameGraphic( const SwFlyFrmFmt
* pFlyFrmFmt
, const SwGrfNode
* pGrfNode
);
422 void FlyFrameOLE( const SwFlyFrmFmt
* pFlyFrmFmt
, SwOLENode
& rOLENode
, const Size
& rSize
);
423 void FlyFrameOLEReplacement(const SwFlyFrmFmt
* pFlyFrmFmt
, SwOLENode
& rOLENode
, const Size
& rSize
);
425 bool FlyFrameOLEMath(const SwFlyFrmFmt
* pFlyFrmFmt
, SwOLENode
& rOLENode
, const Size
& rSize
);
430 void InitTableHelper( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
431 void StartTable( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
432 void StartTableRow( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
433 void StartTableCell( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
434 void TableCellProperties( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner
);
435 void EndTableCell( );
439 /// End cell, row, and even the entire table if necessary.
440 void FinishTableRowCell( ww8::WW8TableNodeInfoInner::Pointer_t pInner
, bool bForceEmptyParagraph
= false );
442 void WriteTextFootnoteNumStr(const SwFmtFtn
& rFootnote
);
445 * Current style name and its ID.
448 sal_uInt16 m_nStyleId
;
452 sal_uInt16 m_nListId
;
454 * This is needed because the call order is: run text, run properties, paragraph properties.
455 * What we need is the opposite.
457 RtfStringBuffer m_aRun
;
458 RtfStringBuffer m_aRunText
;
460 * This is written after runs.
462 OStringBuffer m_aAfterRuns
;
464 * Same for colors and stylesheets: first we just want to output colors,
465 * need to buffer the stylesheet table to output it after the color one.
467 OStringBuffer m_aStylesheet
;
469 * This one just holds the style commands in the current style.
471 OStringBuffer m_aStyles
;
473 * This is the same as m_aStyles but the conents of it is written last.
475 OStringBuffer m_aStylesEnd
;
478 * We just get a "end of strike" mark at the end of strike, store here what to finish: single or double strike.
480 bool m_bStrikeDouble
;
483 * The current table helper.
485 SwWriteTable
*m_pTableWrt
;
488 * Remember if we are in an open cell, or not.
490 bool m_bTableCellOpen
;
493 * Remember the current table depth.
495 sal_uInt32 m_nTableDepth
;
498 * Remember if we wrote a \cell or not.
500 bool m_bTblAfterCell
;
503 * For late output of row definitions.
505 OStringBuffer m_aRowDefs
;
508 * Is a column break needed after the next \par?
510 bool m_nColBreakNeeded
;
513 * If section breaks should be buffered to m_aSectionBreaks
515 bool m_bBufferSectionBreaks
;
516 OStringBuffer m_aSectionBreaks
;
519 * If section headers (and footers) should be buffered to
522 bool m_bBufferSectionHeaders
;
523 OStringBuffer m_aSectionHeaders
;
526 * Support for starting multiple tables at the same cell.
527 * If the current table is the last started one.
531 * List of already started but not yet defined tables (need to be defined
532 * after the nested tables).
534 std::vector
< OString
> m_aTables
;
536 * If cell info is already output.
538 bool m_bWroteCellInfo
;
541 * If we had a field result in the URL.
543 bool m_bHadFieldResult
;
545 /// If we ended a table row without starting a new one.
546 bool m_bTableRowEnded
;
548 /// Number of cells from the table definition, by depth.
549 std::map
<sal_uInt32
,sal_uInt32
> m_aCells
;
551 /// If we're in a paragraph that has a single empty run only.
552 bool m_bSingleEmptyRun
;
556 unsigned int m_nPostitFieldsMaxId
;
558 /// When exporting fly frames, this holds the real size of the frame.
559 const Size
* m_pFlyFrameSize
;
561 std::vector
< std::pair
<OString
, OString
> > m_aFlyProperties
;
563 boost::optional
<XFillStyle
> m_oFillStyle
;
566 RtfAttributeOutput( RtfExport
&rExport
);
568 virtual ~RtfAttributeOutput();
570 /// Return the right export class.
571 virtual MSWordExportBase
& GetExport();
573 OStringBuffer m_aTabStop
;
575 /// Access to the page style of the previous paragraph.
576 const SwPageDesc
* m_pPrevPageDesc
;
578 // These are used by wwFont::WriteRtf()
580 void StartFont( const String
& rFamilyName
) const;
583 void EndFont() const;
585 /// Alternate name for the font.
586 void FontAlternateName( const String
& rName
) const;
589 void FontCharset( sal_uInt8 nCharSet
) const;
592 void FontFamilyType( FontFamily eFamily
, const wwFont
&rFont
) const;
595 void FontPitchType( FontPitch ePitch
) const;
597 /// Writes binary data as a hex dump.
598 static OString
WriteHex(const sal_uInt8
* pData
, sal_uInt32 nSize
, SvStream
* pStream
= 0, sal_uInt32 nLimit
= 64);
600 void BulletDefinition(int nId
, const Graphic
& rGraphic
, Size aSize
) SAL_OVERRIDE
;
603 #endif // _RTFATTRIBUTEOUTPUT_HXX_
605 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */