LibreOffice Module sw (master)  1
rtfexport.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SW_SOURCE_FILTER_WW8_RTFEXPORT_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_WW8_RTFEXPORT_HXX
22 
23 #include <memory>
24 #include "wrtww8.hxx"
25 
26 class RtfAttributeOutput;
27 class RtfExportFilter;
28 class RtfSdrExport;
29 using RtfColorTable = std::map<sal_uInt16, Color>;
30 class SwNode;
31 class SwTextNode;
32 class SwGrfNode;
33 class SwOLENode;
34 
37 {
41 
43  std::unique_ptr<RtfAttributeOutput> m_pAttrOutput;
44 
47 
48  std::unique_ptr<RtfSdrExport> m_pSdrExport;
50 
51 public:
53  AttributeOutputBase& AttrOutput() const override;
54 
56  MSWordSections& Sections() const override;
57 
59  RtfSdrExport& SdrExporter() const;
60 
61  bool FieldsQuoted() const override { return true; }
62 
63  bool AddSectionBreaksForTOX() const override { return false; }
64 
65  bool PreferPageBreakBefore() const override { return true; }
66 
68  bool CollapseScriptsforWordOk(sal_uInt16 nScript, sal_uInt16 nWhich) override;
69 
70  void AppendBookmarks(const SwTextNode& rNode, sal_Int32 nCurrentPos, sal_Int32 nLen) override;
71 
72  void AppendBookmark(const OUString& rName) override;
73 
74  void AppendAnnotationMarks(const SwWW8AttrIter& rAttrs, sal_Int32 nCurrentPos,
75  sal_Int32 nLen) override;
76 
77  //For i120928,add an interface to export graphic of bullet
78  void ExportGrfBullet(const SwTextNode& rNd) override;
79 
80  void
82  Pointer_t /*pTableTextNodeInfoInner = ww8::WW8TableNodeInfoInner::Pointer_t()*/)
83  override
84  {
85  /* no-op for rtf, most probably should not even be in MSWordExportBase */
86  }
87  void WriteChar(sal_Unicode c) override;
88 
90  void WriteNumbering() override;
91 
93  void WriteRevTab();
94 
96  void WriteHeadersFooters(sal_uInt8 nHeadFootFlags, const SwFrameFormat& rFormat,
97  const SwFrameFormat& rLeftFormat,
98  const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode) override;
99 
101  void OutputField(const SwField* pField, ww::eField eFieldType, const OUString& rFieldCmd,
102  FieldFlags nMode = FieldFlags::All) override;
103 
105  void WriteFormData(const ::sw::mark::IFieldmark& rFieldmark) override;
106  void WriteHyperlinkData(const ::sw::mark::IFieldmark& rFieldmark) override;
107 
108  void DoComboBox(const OUString& rName, const OUString& rHelp, const OUString& ToolTip,
109  const OUString& rSelected,
110  const css::uno::Sequence<OUString>& rListItems) override;
111 
112  void DoFormText(const SwInputField* pField) override;
113 
114  sal_uLong ReplaceCr(sal_uInt8 nChar) override;
115 
116  ExportFormat GetExportFormat() const override { return ExportFormat::RTF; }
117 
118 protected:
120  ErrCode ExportDocument_Impl() override;
121 
122  void SectionBreaksAndFrames(const SwTextNode& /*rNode*/) override {}
123 
125  void PrepareNewPageDesc(const SfxItemSet* pSet, const SwNode& rNd,
126  const SwFormatPageDesc* pNewPgDescFormat,
127  const SwPageDesc* pNewPgDesc) override;
128 
130  bool DisallowInheritingOutlineNumbering(const SwFormat& rFormat) override;
131 
133  void OutputTextNode(SwTextNode& rNode) override;
134 
136  void OutputEndNode(const SwEndNode& rEndNode) override;
137 
139  void OutputGrfNode(const SwGrfNode& rGrfNode) override;
140 
142  void OutputOLENode(const SwOLENode& rOLENode) override;
143 
144  void OutputLinkedOLE(const OUString& rLink) override;
145 
146  void AppendSection(const SwPageDesc* pPageDesc, const SwSectionFormat* pFormat,
147  sal_uLong nLnNum) override;
148 
149 public:
151  RtfExport(RtfExportFilter* pFilter, SwDoc* pDocument, std::shared_ptr<SwUnoCursor>& pCurrentPam,
152  SwPaM* pOriginalPam, Writer* pWriter, bool bOutOutlineOnly = false);
153 
154  RtfExport(const RtfExport&) = delete;
155 
156  RtfExport& operator=(const RtfExport&) = delete;
157 
159  ~RtfExport() override;
160 
161 private:
162  rtl_TextEncoding m_eDefaultEncoding;
163  rtl_TextEncoding m_eCurrentEncoding;
168 
169 public:
170  rtl_TextEncoding GetDefaultEncoding() const { return m_eDefaultEncoding; }
171  void SetCurrentEncoding(rtl_TextEncoding eCurrentEncoding)
172  {
173  m_eCurrentEncoding = eCurrentEncoding;
174  }
175  rtl_TextEncoding GetCurrentEncoding() const { return m_eCurrentEncoding; }
176  void SetRTFFlySyntax(bool bRTFFlySyntax) { m_bRTFFlySyntax = bRTFFlySyntax; }
177  bool GetRTFFlySyntax() const { return m_bRTFFlySyntax; }
179  SvStream& Strm();
181  void setStream();
183  OString getStream();
185  void resetStream();
186  SvStream& OutULong(sal_uLong nVal);
187  SvStream& OutLong(long nVal);
188  void OutUnicode(const char* pToken, const OUString& rContent, bool bUpr = false);
189  void OutDateTime(const char* pStr, const css::util::DateTime& rDT);
190  void OutPageDescription(const SwPageDesc& rPgDsc, bool bCheckForFirstPage);
191 
192  sal_uInt16 GetColor(const Color& rColor) const;
193  void InsColor(const Color& rCol);
194  void InsColorLine(const SvxBoxItem& rBox);
195  void OutColorTable();
196  sal_uInt16 GetRedline(const OUString& rAuthor);
197  const OUString* GetRedline(sal_uInt16 nId);
198 
199  void InsStyle(sal_uInt16 nId, const OString& rStyle);
200  OString* GetStyle(sal_uInt16 nId);
201 
203 
204 private:
205  void WriteFonts();
206  void WriteStyles();
207  void WriteFootnoteSettings();
208  void WriteMainText();
209  void WriteInfo();
211  void WriteUserPropType(int nType);
213  void WriteUserPropValue(const OUString& rValue);
215  void WriteUserProps();
217  void WritePageDescTable();
219  void BuildNumbering();
220  void WriteHeaderFooter(const SfxPoolItem& rItem, bool bHeader);
221  void WriteHeaderFooter(const SwFrameFormat& rFormat, bool bHeader, const char* pStr,
222  bool bTitlepg = false);
223 
225  std::map<sal_uInt16, OString> m_aStyTable;
226  std::map<OUString, sal_uInt16> m_aRedlineTable;
228  std::unique_ptr<SvMemoryStream> m_pStream;
230  const SfxItemSet* m_pFirstPageItemSet = nullptr;
231 };
232 
233 #endif // INCLUDED_SW_SOURCE_FILTER_WW8_RTFEXPORT_HXX
234 
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RtfExport & operator=(const RtfExport &)=delete
std::unique_ptr< SvMemoryStream > m_pStream
If set, then Strm() returns this stream, instead of m_pWriter's stream.
Definition: rtfexport.hxx:228
SvStream & OutULong(sal_uLong nVal)
Definition: rtfexport.cxx:1076
std::unique_ptr< RtfAttributeOutput > m_pAttrOutput
Attribute output for document.
Definition: rtfexport.hxx:43
Class to collect and output the sections/headers/footers.
Definition: wrtww8.hxx:190
void WriteMainText()
Definition: rtfexport.cxx:419
OString * GetStyle(sal_uInt16 nId)
Definition: rtfexport.cxx:1317
void WriteHeaderFooter(const SfxPoolItem &rItem, bool bHeader)
Definition: rtfexport.cxx:1395
void OutputEndNode(const SwEndNode &rEndNode) override
Output SwEndNode.
Definition: rtfexport.cxx:990
rtl_TextEncoding m_eCurrentEncoding
Definition: rtfexport.hxx:163
void SectionBreaksAndFrames(const SwTextNode &) override
Definition: rtfexport.hxx:122
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
MSWordSections * m_pSections
Sections/headers/footers.
Definition: rtfexport.hxx:46
void DoComboBox(const OUString &rName, const OUString &rHelp, const OUString &ToolTip, const OUString &rSelected, const css::uno::Sequence< OUString > &rListItems) override
Definition: rtfexport.cxx:329
rtl_TextEncoding GetCurrentEncoding() const
Definition: rtfexport.hxx:175
RtfColorTable m_aColTable
Definition: rtfexport.hxx:224
void OutputGrfNode(const SwGrfNode &rGrfNode) override
Output SwGrfNode.
Definition: rtfexport.cxx:997
AttributeOutputBase & AttrOutput() const override
Access to the attribute output class.
Definition: rtfexport.cxx:76
ExportFormat GetExportFormat() const override
Definition: rtfexport.hxx:116
sal_uIntPtr sal_uLong
RtfExport(RtfExportFilter *pFilter, SwDoc *pDocument, std::shared_ptr< SwUnoCursor > &pCurrentPam, SwPaM *pOriginalPam, Writer *pWriter, bool bOutOutlineOnly=false)
Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
Definition: rtfexport.cxx:1024
Base class of all fields.
Definition: fldbas.hxx:293
void WriteNumbering() override
Write the numbering table.
Definition: rtfexport.cxx:223
SvStream & Strm()
Definition: rtfexport.cxx:1054
Definition: doc.hxx:184
void DoFormText(const SwInputField *pField) override
Definition: rtfexport.cxx:336
bool GetRTFFlySyntax() const
Definition: rtfexport.hxx:177
std::map< sal_uInt16, Color > RtfColorTable
Definition: rtfexport.hxx:29
rtl_TextEncoding GetDefaultEncoding() const
Definition: rtfexport.hxx:170
rtl_TextEncoding m_eDefaultEncoding
Definition: rtfexport.hxx:162
bool m_bOutOutlineOnly
Definition: rtfexport.hxx:49
sal_uInt16 GetRedline(const OUString &rAuthor)
Definition: rtfexport.cxx:1325
Writer * m_pWriter
Definition: rtfexport.hxx:40
void OutputField(const SwField *pField, ww::eField eFieldType, const OUString &rFieldCmd, FieldFlags nMode=FieldFlags::All) override
Write the field.
Definition: rtfexport.cxx:313
bool PreferPageBreakBefore() const override
If saving page break is preferred as a paragraph attribute (yes) or as a special character (no)...
Definition: rtfexport.hxx:65
bool FieldsQuoted() const override
Determines if the import filter already quoted fields or not.
Definition: rtfexport.hxx:61
sal_uInt16 sal_Unicode
void AppendBookmarks(const SwTextNode &rNode, sal_Int32 nCurrentPos, sal_Int32 nLen) override
Definition: rtfexport.cxx:116
FieldFlags
Definition: wrtww8.hxx:138
void InsStyle(sal_uInt16 nId, const OString &rStyle)
Definition: rtfexport.cxx:1312
The class that does all the actual RTF export-related work.
Definition: rtfexport.hxx:36
void InsColorLine(const SvxBoxItem &rBox)
Definition: rtfexport.cxx:1145
bool AddSectionBreaksForTOX() const override
Determines the Section Breaks are to be added for TOX Section.
Definition: rtfexport.hxx:63
void WriteCR(ww8::WW8TableNodeInfoInner::Pointer_t) override
Definition: rtfexport.hxx:81
void WriteUserPropType(int nType)
Writes a single user property type.
Definition: rtfexport.cxx:523
The class that has handlers for various resource types when exporting as RTF.
void OutputTextNode(SwTextNode &rNode) override
Output SwTextNode is depending on outline export mode.
Definition: rtfexport.cxx:1009
const SfxItemSet * m_pFirstPageItemSet
Item set of the first page during export of a follow page format.
Definition: rtfexport.hxx:230
void OutputLinkedOLE(const OUString &rLink) override
Definition: rtfexport.cxx:1007
bool DisallowInheritingOutlineNumbering(const SwFormat &rFormat) override
Return value indicates if an inherited outline numbering is suppressed.
Definition: rtfexport.cxx:968
bool CollapseScriptsforWordOk(sal_uInt16 nScript, sal_uInt16 nWhich) override
Guess the script (asian/western).
Definition: rtfexport.cxx:82
RtfExportFilter * m_pFilter
Pointer to the filter that owns us.
Definition: rtfexport.hxx:39
Base class for various Writer styles.
Definition: format.hxx:43
void InsColor(const Color &rCol)
Definition: rtfexport.cxx:1120
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
void SetCurrentEncoding(rtl_TextEncoding eCurrentEncoding)
Definition: rtfexport.hxx:171
std::map< sal_uInt16, OString > m_aStyTable
Definition: rtfexport.hxx:225
void WriteFormData(const ::sw::mark::IFieldmark &rFieldmark) override
Write the data of the form field.
Definition: rtfexport.cxx:319
bool m_bRTFFlySyntax
This is used by OutputFlyFrame_Impl() to control the written syntax.
Definition: rtfexport.hxx:165
Style of a layout element.
Definition: frmfmt.hxx:57
void WriteHeadersFooters(sal_uInt8 nHeadFootFlags, const SwFrameFormat &rFormat, const SwFrameFormat &rLeftFormat, const SwFrameFormat &rFirstPageFormat, sal_uInt8 nBreakCode) override
Output the actual headers and footers.
Definition: rtfexport.cxx:288
void WriteUserProps()
Writes the userprops group: user defined document properties.
Definition: rtfexport.cxx:536
void setStream()
From now on, let Strm() return a memory stream, not a real one.
Definition: rtfexport.cxx:1062
void AppendBookmark(const OUString &rName) override
Definition: rtfexport.cxx:140
void WriteRevTab()
Write the revision table.
Definition: rtfexport.cxx:255
void WriteStyles()
Definition: rtfexport.cxx:397
void OutPageDescription(const SwPageDesc &rPgDsc, bool bCheckForFirstPage)
Definition: rtfexport.cxx:1344
void WriteChar(sal_Unicode c) override
Definition: rtfexport.cxx:182
MSWordSections & Sections() const override
Access to the sections/headers/footres.
Definition: rtfexport.cxx:78
Handles export of drawings using RTF markup.
SvStream & OutLong(long nVal)
Definition: rtfexport.cxx:1078
const SfxItemSet * GetFirstPageItemSet() const
Definition: rtfexport.hxx:202
void OutDateTime(const char *pStr, const css::util::DateTime &rDT)
Definition: rtfexport.cxx:1096
void AppendSection(const SwPageDesc *pPageDesc, const SwSectionFormat *pFormat, sal_uLong nLnNum) override
Definition: rtfexport.cxx:1017
void WriteFonts()
Definition: rtfexport.cxx:387
void WriteFootnoteSettings()
Definition: rtfexport.cxx:404
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
OString getStream()
Get the contents of the memory stream as a string.
Definition: rtfexport.cxx:1064
void SetRTFFlySyntax(bool bRTFFlySyntax)
Definition: rtfexport.hxx:176
void resetStream()
Return back to the real stream.
Definition: rtfexport.cxx:1074
std::unique_ptr< RtfSdrExport > m_pSdrExport
Definition: rtfexport.hxx:48
unsigned char sal_uInt8
void BuildNumbering()
This is necessary to have the numbering table ready before the main text is being processed...
Definition: rtfexport.cxx:204
void OutputOLENode(const SwOLENode &rOLENode) override
Output SwOLENode.
Definition: rtfexport.cxx:1002
void OutColorTable()
Definition: rtfexport.cxx:1168
~RtfExport() override
Destructor.
ErrCode ExportDocument_Impl() override
Format-dependent part of the actual export.
Definition: rtfexport.cxx:678
void ExportGrfBullet(const SwTextNode &rNd) override
Definition: rtfexport.cxx:177
sal_uLong GetCurrentNodeIndex() const
Definition: rtfexport.hxx:178
sal_uLong ReplaceCr(sal_uInt8 nChar) override
Definition: rtfexport.cxx:379
void AppendAnnotationMarks(const SwWW8AttrIter &rAttrs, sal_Int32 nCurrentPos, sal_Int32 nLen) override
Definition: rtfexport.cxx:151
void WriteHyperlinkData(const ::sw::mark::IFieldmark &rFieldmark) override
Definition: rtfexport.cxx:324
RtfSdrExport & SdrExporter() const
Access to the Rtf Sdr exporter.
Definition: rtfexport.cxx:80
Base class for WW8Export and DocxExport.
Definition: wrtww8.hxx:445
sal_uInt16 GetColor(const Color &rColor) const
Definition: rtfexport.cxx:1106
Ends a section of nodes in the document model.
Definition: node.hxx:333
void OutUnicode(const char *pToken, const OUString &rContent, bool bUpr=false)
Definition: rtfexport.cxx:1080
void PrepareNewPageDesc(const SfxItemSet *pSet, const SwNode &rNd, const SwFormatPageDesc *pNewPgDescFormat, const SwPageDesc *pNewPgDesc) override
Get ready for a new section.
Definition: rtfexport.cxx:948
void WritePageDescTable()
Writes the writer-specific group.
Definition: rtfexport.cxx:632
std::map< OUString, sal_uInt16 > m_aRedlineTable
Definition: rtfexport.hxx:226
sal_uLong m_nCurrentNodeIndex
Index of the current SwTextNode, if any.
Definition: rtfexport.hxx:167
The physical access to the RTF document (for writing).
void WriteInfo()
Definition: rtfexport.cxx:465
void WriteUserPropValue(const OUString &rValue)
Writes a single user property value.
Definition: rtfexport.cxx:529
Base class of the Writer document model elements.
Definition: node.hxx:79