1efeef26fSAndrew Rist /**************************************************************
2efeef26fSAndrew Rist *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10efeef26fSAndrew Rist *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19efeef26fSAndrew Rist *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "rtfexport.hxx"
25cdf0e10cSrcweir #include "rtfexportfilter.hxx"
26cdf0e10cSrcweir #include "rtfsdrexport.hxx"
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
29cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
30cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hdl>
31cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <map>
34cdf0e10cSrcweir #include <algorithm>
35cdf0e10cSrcweir #include <iostream>
36cdf0e10cSrcweir #include <iomanip>
37cdf0e10cSrcweir #include <string>
38cdf0e10cSrcweir #include <sstream>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include <IMark.hxx>
41cdf0e10cSrcweir #include <docsh.hxx>
42cdf0e10cSrcweir #include <ndtxt.hxx>
43cdf0e10cSrcweir #include <wrtww8.hxx>
44cdf0e10cSrcweir #include <fltini.hxx>
45cdf0e10cSrcweir #include <fmtline.hxx>
46cdf0e10cSrcweir #include <fmtpdsc.hxx>
47cdf0e10cSrcweir #include <frmfmt.hxx>
48cdf0e10cSrcweir #include <section.hxx>
49cdf0e10cSrcweir #include <pagedesc.hxx>
50cdf0e10cSrcweir #include <swtable.hxx>
51cdf0e10cSrcweir #include <fmtfsize.hxx>
52cdf0e10cSrcweir #include <frmatr.hxx>
53cdf0e10cSrcweir #include <ftninfo.hxx>
54cdf0e10cSrcweir #include <fmthdft.hxx>
55cdf0e10cSrcweir #include <editeng/fontitem.hxx>
56cdf0e10cSrcweir #include <editeng/colritem.hxx>
57cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
58cdf0e10cSrcweir #include <editeng/boxitem.hxx>
59cdf0e10cSrcweir #include <editeng/brshitem.hxx>
60cdf0e10cSrcweir #include <editeng/shaditem.hxx>
61cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
62cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
63cdf0e10cSrcweir #include <editeng/paperinf.hxx>
64cdf0e10cSrcweir #include <editeng/protitem.hxx>
65cdf0e10cSrcweir
66cdf0e10cSrcweir #include <docary.hxx>
67cdf0e10cSrcweir #include <numrule.hxx>
68cdf0e10cSrcweir #include <charfmt.hxx>
69cdf0e10cSrcweir #include <lineinfo.hxx>
70cdf0e10cSrcweir #include <swmodule.hxx>
71cdf0e10cSrcweir
72cdf0e10cSrcweir #include "ww8par.hxx"
73cdf0e10cSrcweir #include "ww8scan.hxx"
74cdf0e10cSrcweir
75cdf0e10cSrcweir #include <comphelper/string.hxx>
76cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
77cdf0e10cSrcweir #include <vcl/font.hxx>
78cdf0e10cSrcweir #include <svtools/rtfkeywd.hxx>
79cdf0e10cSrcweir #include <unotools/configmgr.hxx>
80cdf0e10cSrcweir
81cdf0e10cSrcweir using namespace ::comphelper;
82cdf0e10cSrcweir using namespace ::com::sun::star;
83cdf0e10cSrcweir
84cdf0e10cSrcweir using rtl::OString;
85cdf0e10cSrcweir using rtl::OUString;
86cdf0e10cSrcweir using rtl::OStringBuffer;
87cdf0e10cSrcweir using rtl::OUStringBuffer;
88cdf0e10cSrcweir
89cdf0e10cSrcweir using sw::mark::IMark;
90cdf0e10cSrcweir
91cdf0e10cSrcweir #if defined(UNX)
92cdf0e10cSrcweir const sal_Char RtfExport::sNewLine = '\012';
93cdf0e10cSrcweir #else
94cdf0e10cSrcweir const sal_Char __FAR_DATA RtfExport::sNewLine[] = "\015\012";
95cdf0e10cSrcweir #endif
96cdf0e10cSrcweir
97cdf0e10cSrcweir // the default text encoding for the export, if it doesn't fit unicode will
98cdf0e10cSrcweir // be used
99cdf0e10cSrcweir #define DEF_ENCODING RTL_TEXTENCODING_ASCII_US
100cdf0e10cSrcweir
AttrOutput() const101cdf0e10cSrcweir AttributeOutputBase& RtfExport::AttrOutput() const
102cdf0e10cSrcweir {
103cdf0e10cSrcweir return *m_pAttrOutput;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
Sections() const106cdf0e10cSrcweir MSWordSections& RtfExport::Sections() const
107cdf0e10cSrcweir {
108cdf0e10cSrcweir return *m_pSections;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
SdrExporter() const111cdf0e10cSrcweir RtfSdrExport& RtfExport::SdrExporter() const
112cdf0e10cSrcweir {
113cdf0e10cSrcweir return *m_pSdrExport;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
HackIsWW8OrHigher() const116cdf0e10cSrcweir bool RtfExport::HackIsWW8OrHigher() const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir return true;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
CollapseScriptsforWordOk(sal_uInt16 nScript,sal_uInt16 nWhich)121cdf0e10cSrcweir bool RtfExport::CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir // FIXME is this actually true for rtf? - this is copied from DOCX
124cdf0e10cSrcweir if ( nScript == i18n::ScriptType::ASIAN )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir // for asian in ww8, there is only one fontsize
127cdf0e10cSrcweir // and one fontstyle (posture/weight)
128cdf0e10cSrcweir switch ( nWhich )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir case RES_CHRATR_FONTSIZE:
131cdf0e10cSrcweir case RES_CHRATR_POSTURE:
132cdf0e10cSrcweir case RES_CHRATR_WEIGHT:
133cdf0e10cSrcweir return false;
134cdf0e10cSrcweir default:
135cdf0e10cSrcweir break;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir else if ( nScript != i18n::ScriptType::COMPLEX )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir // for western in ww8, there is only one fontsize
141cdf0e10cSrcweir // and one fontstyle (posture/weight)
142cdf0e10cSrcweir switch ( nWhich )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir case RES_CHRATR_CJK_FONTSIZE:
145cdf0e10cSrcweir case RES_CHRATR_CJK_POSTURE:
146cdf0e10cSrcweir case RES_CHRATR_CJK_WEIGHT:
147cdf0e10cSrcweir return false;
148cdf0e10cSrcweir default:
149cdf0e10cSrcweir break;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir }
152cdf0e10cSrcweir return true;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
AppendBookmarks(const SwTxtNode & rNode,xub_StrLen nAktPos,xub_StrLen nLen)155cdf0e10cSrcweir void RtfExport::AppendBookmarks( const SwTxtNode& rNode, xub_StrLen nAktPos, xub_StrLen nLen )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
158cdf0e10cSrcweir
159cdf0e10cSrcweir std::vector< OUString > aStarts;
160cdf0e10cSrcweir std::vector< OUString > aEnds;
161cdf0e10cSrcweir
162cdf0e10cSrcweir IMarkVector aMarks;
163cdf0e10cSrcweir if ( GetBookmarks( rNode, nAktPos, nAktPos + nLen, aMarks ) )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir for ( IMarkVector::const_iterator it = aMarks.begin(), end = aMarks.end();
166cdf0e10cSrcweir it < end; ++it )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir IMark* pMark = (*it);
169cdf0e10cSrcweir xub_StrLen nStart = pMark->GetMarkStart().nContent.GetIndex();
170cdf0e10cSrcweir xub_StrLen nEnd = pMark->GetMarkEnd().nContent.GetIndex();
171cdf0e10cSrcweir
172cdf0e10cSrcweir if ( nStart == nAktPos )
173cdf0e10cSrcweir aStarts.push_back( pMark->GetName() );
174cdf0e10cSrcweir
175cdf0e10cSrcweir if ( nEnd == nAktPos )
176cdf0e10cSrcweir aEnds.push_back( pMark->GetName() );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir m_pAttrOutput->WriteBookmarks_Impl( aStarts, aEnds );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
AppendBookmark(const OUString & rName,bool)183cdf0e10cSrcweir void RtfExport::AppendBookmark( const OUString& rName, bool /*bSkip*/ )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
186cdf0e10cSrcweir
187cdf0e10cSrcweir std::vector<OUString> aStarts;
188cdf0e10cSrcweir std::vector<OUString> aEnds;
189cdf0e10cSrcweir
190cdf0e10cSrcweir aStarts.push_back(rName);
191cdf0e10cSrcweir aEnds.push_back(rName);
192cdf0e10cSrcweir
193cdf0e10cSrcweir m_pAttrOutput->WriteBookmarks_Impl(aStarts, aEnds);
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
19641623124SJian Hong Cheng //For i120928,to export graphic of bullet for RTF filter
ExportGrfBullet(const SwTxtNode &)197d762df0fSPavel Janík void RtfExport::ExportGrfBullet(const SwTxtNode& /* rNd */)
19841623124SJian Hong Cheng {
19941623124SJian Hong Cheng //This is for RTF filter on the graphic bullets
20041623124SJian Hong Cheng }
20141623124SJian Hong Cheng
WriteChar(sal_Unicode)202cdf0e10cSrcweir void RtfExport::WriteChar( sal_Unicode )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
205cdf0e10cSrcweir
206cdf0e10cSrcweir /* WriteChar() has nothing to do for rtf. */
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
IsExportNumRule(const SwNumRule & rRule,sal_uInt8 * pEnd=0)209cdf0e10cSrcweir static bool IsExportNumRule( const SwNumRule& rRule, sal_uInt8* pEnd = 0 )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir sal_uInt8 nEnd = MAXLEVEL;
212cdf0e10cSrcweir while( nEnd-- && !rRule.GetNumFmt( nEnd ))
213cdf0e10cSrcweir ;
214cdf0e10cSrcweir ++nEnd;
215cdf0e10cSrcweir
216cdf0e10cSrcweir const SwNumFmt* pNFmt;
217cdf0e10cSrcweir sal_uInt8 nLvl;
218cdf0e10cSrcweir
219cdf0e10cSrcweir for( nLvl = 0; nLvl < nEnd; ++nLvl )
220cdf0e10cSrcweir if( SVX_NUM_NUMBER_NONE != ( pNFmt = &rRule.Get( nLvl ))
221cdf0e10cSrcweir ->GetNumberingType() || pNFmt->GetPrefix().Len() ||
222cdf0e10cSrcweir (pNFmt->GetSuffix().Len() && pNFmt->GetSuffix() != aDotStr ))
223cdf0e10cSrcweir break;
224cdf0e10cSrcweir
225cdf0e10cSrcweir if( pEnd )
226cdf0e10cSrcweir *pEnd = nEnd;
227cdf0e10cSrcweir return nLvl != nEnd;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
BuildNumbering()230cdf0e10cSrcweir void RtfExport::BuildNumbering()
231cdf0e10cSrcweir {
232cdf0e10cSrcweir const SwNumRuleTbl& rListTbl = pDoc->GetNumRuleTbl();
233cdf0e10cSrcweir
234cdf0e10cSrcweir for( sal_uInt16 n = rListTbl.Count()+1; n; )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir SwNumRule* pRule;
237cdf0e10cSrcweir --n;
238cdf0e10cSrcweir if( n == rListTbl.Count() )
239cdf0e10cSrcweir pRule = (SwNumRule*)pDoc->GetOutlineNumRule();
240cdf0e10cSrcweir else
241cdf0e10cSrcweir {
242cdf0e10cSrcweir pRule = rListTbl[ n ];
243cdf0e10cSrcweir if( !pDoc->IsUsed( *pRule ))
244cdf0e10cSrcweir continue;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir if( IsExportNumRule( *pRule ))
248cdf0e10cSrcweir GetId( *pRule );
249cdf0e10cSrcweir }
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
WriteNumbering()252cdf0e10cSrcweir void RtfExport::WriteNumbering()
253cdf0e10cSrcweir {
254cdf0e10cSrcweir OSL_TRACE("%s start", OSL_THIS_FUNC);
255cdf0e10cSrcweir
256cdf0e10cSrcweir if ( !pUsedNumTbl )
257cdf0e10cSrcweir return; // no numbering is used
258cdf0e10cSrcweir
259cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_IGNORE << OOO_STRING_SVTOOLS_RTF_LISTTABLE;
260cdf0e10cSrcweir AbstractNumberingDefinitions();
261cdf0e10cSrcweir Strm() << '}';
262cdf0e10cSrcweir
263cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_LISTOVERRIDETABLE;
264cdf0e10cSrcweir NumberingDefinitions();
265cdf0e10cSrcweir Strm() << '}';
266cdf0e10cSrcweir
267cdf0e10cSrcweir OSL_TRACE("%s end", OSL_THIS_FUNC);
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
WriteRevTab()270cdf0e10cSrcweir void RtfExport::WriteRevTab()
271cdf0e10cSrcweir {
272cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
273cdf0e10cSrcweir
274cdf0e10cSrcweir int nRevAuthors = pDoc->GetRedlineTbl().Count();
275cdf0e10cSrcweir
276cdf0e10cSrcweir if (nRevAuthors < 1)
277cdf0e10cSrcweir return;
278cdf0e10cSrcweir
279cdf0e10cSrcweir // RTF always seems to use Unknown as the default first entry
280cdf0e10cSrcweir String sUnknown(RTL_CONSTASCII_USTRINGPARAM("Unknown"));
281cdf0e10cSrcweir GetRedline(sUnknown);
282cdf0e10cSrcweir
283cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pDoc->GetRedlineTbl().Count(); ++i )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir const SwRedline* pRedl = pDoc->GetRedlineTbl()[ i ];
286cdf0e10cSrcweir
287cdf0e10cSrcweir GetRedline(SW_MOD()->GetRedlineAuthor(pRedl->GetAuthor()));
288cdf0e10cSrcweir }
289cdf0e10cSrcweir
290cdf0e10cSrcweir // Now write the table
291cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_IGNORE << OOO_STRING_SVTOOLS_RTF_REVTBL << ' ';
292cdf0e10cSrcweir for(sal_uInt16 i = 0; i < m_aRedlineTbl.size(); ++i)
293cdf0e10cSrcweir {
294cdf0e10cSrcweir const String* pAuthor = GetRedline(i);
295cdf0e10cSrcweir Strm() << '{';
296cdf0e10cSrcweir if (pAuthor)
297cdf0e10cSrcweir Strm() << OutString(*pAuthor, eDefaultEncoding);
298cdf0e10cSrcweir Strm() << ";}";
299cdf0e10cSrcweir }
300cdf0e10cSrcweir Strm() << '}' << sNewLine;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
WriteHeadersFooters(sal_uInt8 nHeadFootFlags,const SwFrmFmt & rFmt,const SwFrmFmt & rLeftFmt,const SwFrmFmt & rFirstPageFmt,sal_uInt8)303cdf0e10cSrcweir void RtfExport::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
304cdf0e10cSrcweir const SwFrmFmt& rFmt, const SwFrmFmt& rLeftFmt, const SwFrmFmt& rFirstPageFmt, sal_uInt8 /*nBreakCode*/ )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
307cdf0e10cSrcweir
308cdf0e10cSrcweir // headers
309cdf0e10cSrcweir if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_EVEN )
310cdf0e10cSrcweir WriteHeaderFooter( rLeftFmt, true, OOO_STRING_SVTOOLS_RTF_HEADERL );
311cdf0e10cSrcweir
312cdf0e10cSrcweir if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
313cdf0e10cSrcweir WriteHeaderFooter( rFmt, true, OOO_STRING_SVTOOLS_RTF_HEADER );
314cdf0e10cSrcweir
315cdf0e10cSrcweir if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_FIRST )
316cdf0e10cSrcweir WriteHeaderFooter( rFirstPageFmt, true, OOO_STRING_SVTOOLS_RTF_HEADERF );
317cdf0e10cSrcweir
318cdf0e10cSrcweir // footers
319cdf0e10cSrcweir if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_EVEN )
320cdf0e10cSrcweir WriteHeaderFooter( rLeftFmt, false, OOO_STRING_SVTOOLS_RTF_FOOTERL );
321cdf0e10cSrcweir
322cdf0e10cSrcweir if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
323cdf0e10cSrcweir WriteHeaderFooter( rFmt, false, OOO_STRING_SVTOOLS_RTF_FOOTER );
324cdf0e10cSrcweir
325cdf0e10cSrcweir if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_FIRST )
326cdf0e10cSrcweir WriteHeaderFooter( rFirstPageFmt, false, OOO_STRING_SVTOOLS_RTF_FOOTERF );
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
OutputField(const SwField * pFld,ww::eField eFldType,const String & rFldCmd,sal_uInt8 nMode)329cdf0e10cSrcweir void RtfExport::OutputField( const SwField* pFld, ww::eField eFldType, const String& rFldCmd, sal_uInt8 nMode )
330cdf0e10cSrcweir {
331cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
332cdf0e10cSrcweir
333cdf0e10cSrcweir m_pAttrOutput->WriteField_Impl( pFld, eFldType, rFldCmd, nMode );
334cdf0e10cSrcweir }
335cdf0e10cSrcweir
WriteFormData(const::sw::mark::IFieldmark &)336cdf0e10cSrcweir void RtfExport::WriteFormData( const ::sw::mark::IFieldmark& /*rFieldmark*/ )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir OSL_TRACE("TODO: %s", OSL_THIS_FUNC);
339cdf0e10cSrcweir }
340cdf0e10cSrcweir
WriteHyperlinkData(const::sw::mark::IFieldmark &)341cdf0e10cSrcweir void RtfExport::WriteHyperlinkData( const ::sw::mark::IFieldmark& /*rFieldmark*/ )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir OSL_TRACE("TODO: %s", OSL_THIS_FUNC);
344cdf0e10cSrcweir }
345cdf0e10cSrcweir
DoComboBox(const rtl::OUString &,const rtl::OUString &,const rtl::OUString &,const rtl::OUString &,uno::Sequence<rtl::OUString> &)346cdf0e10cSrcweir void RtfExport::DoComboBox(const rtl::OUString& /*rName*/,
347cdf0e10cSrcweir const rtl::OUString& /*rHelp*/,
348cdf0e10cSrcweir const rtl::OUString& /*rToolTip*/,
349cdf0e10cSrcweir const rtl::OUString& /*rSelected*/,
350cdf0e10cSrcweir uno::Sequence<rtl::OUString>& /*rListItems*/)
351cdf0e10cSrcweir {
352cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
353cdf0e10cSrcweir
354cdf0e10cSrcweir // this is handled in RtfAttributeOutput::OutputFlyFrame_Impl
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
DoFormText(const SwInputField * pFld)357cdf0e10cSrcweir void RtfExport::DoFormText(const SwInputField* pFld )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
360cdf0e10cSrcweir
361cdf0e10cSrcweir ::rtl::OUString sResult = pFld->ExpandField(pDoc->IsClipBoard());
362cdf0e10cSrcweir ::rtl::OUString sHelp( pFld->GetHelp() );
363cdf0e10cSrcweir ::rtl::OUString sName = pFld->GetPar2();
364cdf0e10cSrcweir ::rtl::OUString sStatus = pFld->GetToolTip();
365cdf0e10cSrcweir m_pAttrOutput->RunText().append("{" OOO_STRING_SVTOOLS_RTF_FIELD "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FLDINST "{ FORMTEXT }");
366cdf0e10cSrcweir m_pAttrOutput->RunText().append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FORMFIELD " {" OOO_STRING_SVTOOLS_RTF_FFTYPE "0" );
367cdf0e10cSrcweir if( sHelp.getLength() )
368cdf0e10cSrcweir m_pAttrOutput->RunText().append( OOO_STRING_SVTOOLS_RTF_FFOWNHELP );
369cdf0e10cSrcweir if( sStatus.getLength() )
370cdf0e10cSrcweir m_pAttrOutput->RunText().append( OOO_STRING_SVTOOLS_RTF_FFOWNSTAT );
371cdf0e10cSrcweir m_pAttrOutput->RunText().append( OOO_STRING_SVTOOLS_RTF_FFTYPETXT "0" );
372cdf0e10cSrcweir
373cdf0e10cSrcweir if( sName.getLength() )
374cdf0e10cSrcweir m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFNAME " ").append( OutString( sName, eDefaultEncoding )).append( "}" );
375cdf0e10cSrcweir if( sHelp.getLength() )
376cdf0e10cSrcweir m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFHELPTEXT " ").append( OutString( sHelp, eDefaultEncoding )).append( "}" );
377cdf0e10cSrcweir m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFDEFTEXT " ").append( OutString( sResult, eDefaultEncoding )).append( "}" );
378cdf0e10cSrcweir if( sStatus.getLength() )
379cdf0e10cSrcweir m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFSTATTEXT " ").append( OutString( sStatus, eDefaultEncoding )).append( "}");
380cdf0e10cSrcweir m_pAttrOutput->RunText().append( "}}}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " " );
381cdf0e10cSrcweir m_pAttrOutput->RunText().append( OutString( sResult, eDefaultEncoding )).append( "}}" );
382cdf0e10cSrcweir }
383cdf0e10cSrcweir
ReplaceCr(sal_uInt8)384cdf0e10cSrcweir sal_uLong RtfExport::ReplaceCr( sal_uInt8 )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
387cdf0e10cSrcweir
388cdf0e10cSrcweir // Completely unused for Rtf export... only here for code sharing
389cdf0e10cSrcweir // purpose with binary export
390cdf0e10cSrcweir
391cdf0e10cSrcweir return 0;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
WriteFonts()394cdf0e10cSrcweir void RtfExport::WriteFonts()
395cdf0e10cSrcweir {
396cdf0e10cSrcweir Strm() << sNewLine << '{' << OOO_STRING_SVTOOLS_RTF_FONTTBL;
397cdf0e10cSrcweir maFontHelper.WriteFontTable( *m_pAttrOutput );
398cdf0e10cSrcweir Strm() << '}';
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
WriteStyles()401cdf0e10cSrcweir void RtfExport::WriteStyles()
402cdf0e10cSrcweir {
403cdf0e10cSrcweir OSL_TRACE("%s start", OSL_THIS_FUNC);
404cdf0e10cSrcweir pStyles->OutputStylesTable();
405cdf0e10cSrcweir OSL_TRACE("%s end", OSL_THIS_FUNC);
406cdf0e10cSrcweir }
407cdf0e10cSrcweir
WriteMainText()408cdf0e10cSrcweir void RtfExport::WriteMainText()
409cdf0e10cSrcweir {
410cdf0e10cSrcweir OSL_TRACE("%s start", OSL_THIS_FUNC);
411*8fb62665SOliver-Rainer Wittmann
412*8fb62665SOliver-Rainer Wittmann SwTableNode* pTableNode = pCurPam->GetNode()->FindTableNode();
413*8fb62665SOliver-Rainer Wittmann if ( m_pWriter && m_pWriter->bWriteOnlyFirstTable
414*8fb62665SOliver-Rainer Wittmann && pTableNode != 0 )
415*8fb62665SOliver-Rainer Wittmann {
416*8fb62665SOliver-Rainer Wittmann pCurPam->GetPoint()->nNode = *pTableNode;
417*8fb62665SOliver-Rainer Wittmann pCurPam->GetMark()->nNode = *(pTableNode->EndOfSectionNode());
418*8fb62665SOliver-Rainer Wittmann }
419*8fb62665SOliver-Rainer Wittmann else
420*8fb62665SOliver-Rainer Wittmann {
421*8fb62665SOliver-Rainer Wittmann pCurPam->GetPoint()->nNode = pDoc->GetNodes().GetEndOfContent().StartOfSectionNode()->GetIndex();
422*8fb62665SOliver-Rainer Wittmann }
423*8fb62665SOliver-Rainer Wittmann
424cdf0e10cSrcweir WriteText();
425*8fb62665SOliver-Rainer Wittmann
426cdf0e10cSrcweir OSL_TRACE("%s end", OSL_THIS_FUNC);
427cdf0e10cSrcweir }
428cdf0e10cSrcweir
WriteInfo()429cdf0e10cSrcweir void RtfExport::WriteInfo()
430cdf0e10cSrcweir {
431cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
432cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_INFO;
433cdf0e10cSrcweir
434cdf0e10cSrcweir SwDocShell *pDocShell(pDoc->GetDocShell());
435cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps;
436cdf0e10cSrcweir if (pDocShell) {
437cdf0e10cSrcweir uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
438cdf0e10cSrcweir pDocShell->GetModel(), uno::UNO_QUERY);
439cdf0e10cSrcweir xDocProps.set(xDPS->getDocumentProperties());
440cdf0e10cSrcweir }
441cdf0e10cSrcweir
442cdf0e10cSrcweir if (xDocProps.is()) {
443cdf0e10cSrcweir OutUnicode(OOO_STRING_SVTOOLS_RTF_TITLE, xDocProps->getTitle());
444cdf0e10cSrcweir OutUnicode(OOO_STRING_SVTOOLS_RTF_SUBJECT, xDocProps->getSubject());
445cdf0e10cSrcweir
446cdf0e10cSrcweir OutUnicode(OOO_STRING_SVTOOLS_RTF_KEYWORDS,
447cdf0e10cSrcweir ::comphelper::string::convertCommaSeparated(xDocProps->getKeywords()));
448cdf0e10cSrcweir OutUnicode(OOO_STRING_SVTOOLS_RTF_DOCCOMM, xDocProps->getDescription());
449cdf0e10cSrcweir
450cdf0e10cSrcweir OutUnicode(OOO_STRING_SVTOOLS_RTF_AUTHOR, xDocProps->getAuthor());
451cdf0e10cSrcweir OutDateTime(OOO_STRING_SVTOOLS_RTF_CREATIM, xDocProps->getCreationDate());
452cdf0e10cSrcweir
453cdf0e10cSrcweir OutUnicode(OOO_STRING_SVTOOLS_RTF_AUTHOR,xDocProps->getModifiedBy());
454cdf0e10cSrcweir OutDateTime(OOO_STRING_SVTOOLS_RTF_REVTIM, xDocProps->getModificationDate());
455cdf0e10cSrcweir
456cdf0e10cSrcweir OutDateTime(OOO_STRING_SVTOOLS_RTF_PRINTIM, xDocProps->getPrintDate());
457cdf0e10cSrcweir }
458cdf0e10cSrcweir
459cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_COMMENT << " ";
460cdf0e10cSrcweir OUString sProduct;
461cdf0e10cSrcweir utl::ConfigManager::GetDirectConfigProperty(utl::ConfigManager::PRODUCTNAME) >>= sProduct;
462cdf0e10cSrcweir Strm() << OUStringToOString( sProduct, eCurrentEncoding) << "}{" << OOO_STRING_SVTOOLS_RTF_VERN;
463cdf0e10cSrcweir OutULong( SUPD*10 ) << '}';
464cdf0e10cSrcweir Strm() << '}';
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
WritePageDescTable()467cdf0e10cSrcweir void RtfExport::WritePageDescTable()
468cdf0e10cSrcweir {
469cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
470cdf0e10cSrcweir
471cdf0e10cSrcweir // Write page descriptions (page styles)
472cdf0e10cSrcweir sal_uInt16 nSize = pDoc->GetPageDescCnt();
473cdf0e10cSrcweir if( !nSize )
474cdf0e10cSrcweir return;
475cdf0e10cSrcweir
476cdf0e10cSrcweir Strm() << sNewLine; // a separator
477cdf0e10cSrcweir bOutPageDescs = sal_True;
478cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_IGNORE << OOO_STRING_SVTOOLS_RTF_PGDSCTBL;
479cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nSize; ++n )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir const SwPageDesc& rPageDesc =
482cdf0e10cSrcweir const_cast<const SwDoc*>(pDoc)->GetPageDesc( n );
483cdf0e10cSrcweir
484cdf0e10cSrcweir Strm() << sNewLine << '{' << OOO_STRING_SVTOOLS_RTF_PGDSC;
485cdf0e10cSrcweir OutULong( n ) << OOO_STRING_SVTOOLS_RTF_PGDSCUSE;
486cdf0e10cSrcweir OutULong( rPageDesc.ReadUseOn() );
487cdf0e10cSrcweir
488cdf0e10cSrcweir OutPageDescription( rPageDesc, sal_False, sal_False );
489cdf0e10cSrcweir
490cdf0e10cSrcweir // search for the next page description
491cdf0e10cSrcweir sal_uInt16 i = nSize;
492cdf0e10cSrcweir while( i )
493cdf0e10cSrcweir if( rPageDesc.GetFollow() ==
494cdf0e10cSrcweir &const_cast<const SwDoc *>(pDoc)->GetPageDesc( --i ) )
495cdf0e10cSrcweir break;
496cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_PGDSCNXT;
497cdf0e10cSrcweir OutULong( i ) << ' ';
498cdf0e10cSrcweir Strm() << OutString( rPageDesc.GetName(), eDefaultEncoding) << ";}";
499cdf0e10cSrcweir }
500cdf0e10cSrcweir Strm() << '}' << sNewLine;
501cdf0e10cSrcweir bOutPageDescs = sal_False;
502cdf0e10cSrcweir
503cdf0e10cSrcweir // reset table infos, otherwise the depth of the cells will be incorrect,
504cdf0e10cSrcweir // in case the page style (header or footer) had tables
505cdf0e10cSrcweir mpTableInfo = ww8::WW8TableInfo::Pointer_t(new ww8::WW8TableInfo());
506cdf0e10cSrcweir }
507cdf0e10cSrcweir
ExportDocument_Impl()508cdf0e10cSrcweir void RtfExport::ExportDocument_Impl()
509cdf0e10cSrcweir {
510cdf0e10cSrcweir #ifdef DEBUG
511cdf0e10cSrcweir // MSWordExportBase::WriteText and others write debug messages to std::clog
512cdf0e10cSrcweir // which is not interesting while debugging RtfExport
513cdf0e10cSrcweir std::ostringstream aOss;
514cdf0e10cSrcweir std::streambuf *pOldBuf = std::clog.rdbuf(aOss.rdbuf());
515cdf0e10cSrcweir #endif
516cdf0e10cSrcweir
517cdf0e10cSrcweir // Make the header
518cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_RTF << '1'
519cdf0e10cSrcweir << OOO_STRING_SVTOOLS_RTF_ANSI;
520cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_DEFF;
521cdf0e10cSrcweir OutULong( maFontHelper.GetId( (SvxFontItem&)pDoc->GetAttrPool().GetDefaultItem(
522cdf0e10cSrcweir RES_CHRATR_FONT ) ));
523cdf0e10cSrcweir // If this not exist, MS don't understand our ansi characters (0x80-0xff).
524cdf0e10cSrcweir Strm() << "\\adeflang1025";
525cdf0e10cSrcweir
526cdf0e10cSrcweir // Font table
527cdf0e10cSrcweir WriteFonts();
528cdf0e10cSrcweir
529cdf0e10cSrcweir pStyles = new MSWordStyles( *this );
530cdf0e10cSrcweir // Color and stylesheet table
531cdf0e10cSrcweir WriteStyles();
532cdf0e10cSrcweir
533cdf0e10cSrcweir // List table
534cdf0e10cSrcweir BuildNumbering();
535cdf0e10cSrcweir WriteNumbering();
536cdf0e10cSrcweir
537cdf0e10cSrcweir WriteRevTab();
538cdf0e10cSrcweir
539cdf0e10cSrcweir WriteInfo();
540cdf0e10cSrcweir // Default TabSize
541cdf0e10cSrcweir Strm() << m_pAttrOutput->m_aTabStop.makeStringAndClear() << sNewLine;
542cdf0e10cSrcweir // Page description
543cdf0e10cSrcweir WritePageDescTable();
544cdf0e10cSrcweir
545cdf0e10cSrcweir // Enable form protection by default if needed, as there is no switch to
546cdf0e10cSrcweir // enable it on a per-section basis. OTOH don't always enable it as it
547cdf0e10cSrcweir // breaks moving of drawings - so write it only in case there is really a
548cdf0e10cSrcweir // protected section in the document.
549cdf0e10cSrcweir {
550cdf0e10cSrcweir const SfxItemPool& rPool = pDoc->GetAttrPool();
551cdf0e10cSrcweir sal_uInt32 const nMaxItem = rPool.GetItemCount2(RES_PROTECT);
552cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nMaxItem; ++n)
553cdf0e10cSrcweir {
554cdf0e10cSrcweir const SvxProtectItem* pProtect = (const SvxProtectItem*)rPool.GetItem2(RES_PROTECT, n);
555cdf0e10cSrcweir if (pProtect && pProtect->IsCntntProtected())
556cdf0e10cSrcweir {
557cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_FORMPROT;
558cdf0e10cSrcweir break;
559cdf0e10cSrcweir }
560cdf0e10cSrcweir }
561cdf0e10cSrcweir }
562cdf0e10cSrcweir
563cdf0e10cSrcweir // enable form field shading
564cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_FORMSHADE;
565cdf0e10cSrcweir
566cdf0e10cSrcweir // size and empty margins of the page
567cdf0e10cSrcweir if( pDoc->GetPageDescCnt() )
568cdf0e10cSrcweir {
569cdf0e10cSrcweir //JP 06.04.99: Bug 64361 - Seeking the first SwFmtPageDesc. If
570cdf0e10cSrcweir // no set, the default is valid
571cdf0e10cSrcweir const SwFmtPageDesc* pSttPgDsc = 0;
572cdf0e10cSrcweir {
573cdf0e10cSrcweir const SwNode& rSttNd = *pDoc->GetNodes()[
574cdf0e10cSrcweir pDoc->GetNodes().GetEndOfExtras().GetIndex() + 2 ];
575cdf0e10cSrcweir const SfxItemSet* pSet = 0;
576cdf0e10cSrcweir
577cdf0e10cSrcweir if( rSttNd.IsCntntNode() )
578cdf0e10cSrcweir pSet = &rSttNd.GetCntntNode()->GetSwAttrSet();
579cdf0e10cSrcweir else if( rSttNd.IsTableNode() )
580cdf0e10cSrcweir pSet = &rSttNd.GetTableNode()->GetTable().
581cdf0e10cSrcweir GetFrmFmt()->GetAttrSet();
582cdf0e10cSrcweir else if( rSttNd.IsSectionNode() )
583cdf0e10cSrcweir pSet = &rSttNd.GetSectionNode()->GetSection().
584cdf0e10cSrcweir GetFmt()->GetAttrSet();
585cdf0e10cSrcweir
586cdf0e10cSrcweir if( pSet )
587cdf0e10cSrcweir {
588cdf0e10cSrcweir sal_uInt16 nPosInDoc;
589cdf0e10cSrcweir pSttPgDsc = (SwFmtPageDesc*)&pSet->Get( RES_PAGEDESC );
590cdf0e10cSrcweir if( !pSttPgDsc->GetPageDesc() )
591cdf0e10cSrcweir pSttPgDsc = 0;
592cdf0e10cSrcweir else if( pDoc->FindPageDescByName( pSttPgDsc->
593cdf0e10cSrcweir GetPageDesc()->GetName(), &nPosInDoc ))
594cdf0e10cSrcweir {
595cdf0e10cSrcweir Strm() << '{' << OOO_STRING_SVTOOLS_RTF_IGNORE << OOO_STRING_SVTOOLS_RTF_PGDSCNO;
596cdf0e10cSrcweir OutULong( nPosInDoc ) << '}';
597cdf0e10cSrcweir }
598cdf0e10cSrcweir }
599cdf0e10cSrcweir }
600cdf0e10cSrcweir const SwPageDesc& rPageDesc = pSttPgDsc ? *pSttPgDsc->GetPageDesc()
601cdf0e10cSrcweir : const_cast<const SwDoc *>(pDoc)->GetPageDesc( 0 );
602cdf0e10cSrcweir const SwFrmFmt &rFmtPage = rPageDesc.GetMaster();
603cdf0e10cSrcweir
604cdf0e10cSrcweir {
605cdf0e10cSrcweir if( rPageDesc.GetLandscape() )
606cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_LANDSCAPE;
607cdf0e10cSrcweir
608cdf0e10cSrcweir const SwFmtFrmSize& rSz = rFmtPage.GetFrmSize();
609cdf0e10cSrcweir // Clipboard document is always created without a printer, then
610cdf0e10cSrcweir // the size will be always LONG_MAX! Solution then is to use A4
611cdf0e10cSrcweir if( LONG_MAX == rSz.GetHeight() || LONG_MAX == rSz.GetWidth() )
612cdf0e10cSrcweir {
613cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_PAPERH;
614cdf0e10cSrcweir Size a4 = SvxPaperInfo::GetPaperSize(PAPER_A4);
615cdf0e10cSrcweir OutULong( a4.Height() ) << OOO_STRING_SVTOOLS_RTF_PAPERW;
616cdf0e10cSrcweir OutULong( a4.Width() );
617cdf0e10cSrcweir }
618cdf0e10cSrcweir else
619cdf0e10cSrcweir {
620cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_PAPERH;
621cdf0e10cSrcweir OutULong( rSz.GetHeight() ) << OOO_STRING_SVTOOLS_RTF_PAPERW;
622cdf0e10cSrcweir OutULong( rSz.GetWidth() );
623cdf0e10cSrcweir }
624cdf0e10cSrcweir }
625cdf0e10cSrcweir
626cdf0e10cSrcweir {
627cdf0e10cSrcweir const SvxLRSpaceItem& rLR = rFmtPage.GetLRSpace();
628cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_MARGL;
629cdf0e10cSrcweir OutLong( rLR.GetLeft() ) << OOO_STRING_SVTOOLS_RTF_MARGR;
630cdf0e10cSrcweir OutLong( rLR.GetRight() );
631cdf0e10cSrcweir }
632cdf0e10cSrcweir
633cdf0e10cSrcweir {
634cdf0e10cSrcweir const SvxULSpaceItem& rUL = rFmtPage.GetULSpace();
635cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_MARGT;
636cdf0e10cSrcweir OutLong( rUL.GetUpper() ) << OOO_STRING_SVTOOLS_RTF_MARGB;
637cdf0e10cSrcweir OutLong( rUL.GetLower() );
638cdf0e10cSrcweir }
639cdf0e10cSrcweir
640cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_SECTD << OOO_STRING_SVTOOLS_RTF_SBKNONE;
641cdf0e10cSrcweir // All sections are unlocked by default
642cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_SECTUNLOCKED;
643cdf0e10cSrcweir OutLong(1);
644cdf0e10cSrcweir OutPageDescription( rPageDesc, sal_False, sal_True ); // Changed bCheckForFirstPage to sal_True so headers
645cdf0e10cSrcweir // following title page are correctly added - i13107
646cdf0e10cSrcweir if( pSttPgDsc )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir pAktPageDesc = &rPageDesc;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir }
651cdf0e10cSrcweir
652cdf0e10cSrcweir // line numbering
653cdf0e10cSrcweir const SwLineNumberInfo& rLnNumInfo = pDoc->GetLineNumberInfo();
654cdf0e10cSrcweir if ( rLnNumInfo.IsPaintLineNumbers() )
655cdf0e10cSrcweir AttrOutput().SectionLineNumbering( 0, rLnNumInfo );
656cdf0e10cSrcweir
657cdf0e10cSrcweir {
658cdf0e10cSrcweir // write the footnotes and endnotes-out Info
659cdf0e10cSrcweir const SwFtnInfo& rFtnInfo = pDoc->GetFtnInfo();
660cdf0e10cSrcweir
661cdf0e10cSrcweir const char* pOut = FTNPOS_CHAPTER == rFtnInfo.ePos
662cdf0e10cSrcweir ? OOO_STRING_SVTOOLS_RTF_ENDDOC
663cdf0e10cSrcweir : OOO_STRING_SVTOOLS_RTF_FTNBJ;
664cdf0e10cSrcweir Strm() << pOut << OOO_STRING_SVTOOLS_RTF_FTNSTART;
665cdf0e10cSrcweir OutLong( rFtnInfo.nFtnOffset + 1 );
666cdf0e10cSrcweir
667cdf0e10cSrcweir switch( rFtnInfo.eNum )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir case FTNNUM_PAGE: pOut = OOO_STRING_SVTOOLS_RTF_FTNRSTPG; break;
670cdf0e10cSrcweir case FTNNUM_DOC: pOut = OOO_STRING_SVTOOLS_RTF_FTNRSTCONT; break;
671cdf0e10cSrcweir // case FTNNUM_CHAPTER:
672cdf0e10cSrcweir default: pOut = OOO_STRING_SVTOOLS_RTF_FTNRESTART; break;
673cdf0e10cSrcweir }
674cdf0e10cSrcweir Strm() << pOut;
675cdf0e10cSrcweir
676cdf0e10cSrcweir switch( rFtnInfo.aFmt.GetNumberingType() )
677cdf0e10cSrcweir {
678cdf0e10cSrcweir case SVX_NUM_CHARS_LOWER_LETTER:
679cdf0e10cSrcweir case SVX_NUM_CHARS_LOWER_LETTER_N: pOut = OOO_STRING_SVTOOLS_RTF_FTNNALC; break;
680cdf0e10cSrcweir case SVX_NUM_CHARS_UPPER_LETTER:
681cdf0e10cSrcweir case SVX_NUM_CHARS_UPPER_LETTER_N: pOut = OOO_STRING_SVTOOLS_RTF_FTNNAUC; break;
682cdf0e10cSrcweir case SVX_NUM_ROMAN_LOWER: pOut = OOO_STRING_SVTOOLS_RTF_FTNNRLC; break;
683cdf0e10cSrcweir case SVX_NUM_ROMAN_UPPER: pOut = OOO_STRING_SVTOOLS_RTF_FTNNRUC; break;
684cdf0e10cSrcweir case SVX_NUM_CHAR_SPECIAL: pOut = OOO_STRING_SVTOOLS_RTF_FTNNCHI; break;
685cdf0e10cSrcweir // case SVX_NUM_ARABIC:
686cdf0e10cSrcweir default: pOut = OOO_STRING_SVTOOLS_RTF_FTNNAR; break;
687cdf0e10cSrcweir }
688cdf0e10cSrcweir Strm() << pOut;
689cdf0e10cSrcweir
690cdf0e10cSrcweir
691cdf0e10cSrcweir const SwEndNoteInfo& rEndNoteInfo = pDoc->GetEndNoteInfo();
692cdf0e10cSrcweir
693cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_AENDDOC << OOO_STRING_SVTOOLS_RTF_AFTNRSTCONT
694cdf0e10cSrcweir << OOO_STRING_SVTOOLS_RTF_AFTNSTART;
695cdf0e10cSrcweir OutLong( rEndNoteInfo.nFtnOffset + 1 );
696cdf0e10cSrcweir
697cdf0e10cSrcweir switch( rEndNoteInfo.aFmt.GetNumberingType() )
698cdf0e10cSrcweir {
699cdf0e10cSrcweir case SVX_NUM_CHARS_LOWER_LETTER:
700cdf0e10cSrcweir case SVX_NUM_CHARS_LOWER_LETTER_N: pOut = OOO_STRING_SVTOOLS_RTF_AFTNNALC; break;
701cdf0e10cSrcweir case SVX_NUM_CHARS_UPPER_LETTER:
702cdf0e10cSrcweir case SVX_NUM_CHARS_UPPER_LETTER_N: pOut = OOO_STRING_SVTOOLS_RTF_AFTNNAUC; break;
703cdf0e10cSrcweir case SVX_NUM_ROMAN_LOWER: pOut = OOO_STRING_SVTOOLS_RTF_AFTNNRLC; break;
704cdf0e10cSrcweir case SVX_NUM_ROMAN_UPPER: pOut = OOO_STRING_SVTOOLS_RTF_AFTNNRUC; break;
705cdf0e10cSrcweir case SVX_NUM_CHAR_SPECIAL: pOut = OOO_STRING_SVTOOLS_RTF_AFTNNCHI; break;
706cdf0e10cSrcweir // case SVX_NUM_ARABIC:
707cdf0e10cSrcweir default: pOut = OOO_STRING_SVTOOLS_RTF_AFTNNAR; break;
708cdf0e10cSrcweir }
709cdf0e10cSrcweir Strm() << pOut;
710cdf0e10cSrcweir }
711cdf0e10cSrcweir
712cdf0e10cSrcweir Strm() << sNewLine;
713cdf0e10cSrcweir
714cdf0e10cSrcweir // Init sections
715cdf0e10cSrcweir m_pSections = new MSWordSections( *this );
716cdf0e10cSrcweir
717cdf0e10cSrcweir WriteMainText();
718cdf0e10cSrcweir
719cdf0e10cSrcweir Strm() << '}';
720cdf0e10cSrcweir
721cdf0e10cSrcweir #ifdef DEBUG
722cdf0e10cSrcweir std::clog.rdbuf(pOldBuf);
723cdf0e10cSrcweir #endif
724cdf0e10cSrcweir }
725cdf0e10cSrcweir
PrepareNewPageDesc(const SfxItemSet * pSet,const SwNode & rNd,const SwFmtPageDesc * pNewPgDescFmt,const SwPageDesc * pNewPgDesc)726cdf0e10cSrcweir void RtfExport::PrepareNewPageDesc( const SfxItemSet* pSet,
727cdf0e10cSrcweir const SwNode& rNd, const SwFmtPageDesc* pNewPgDescFmt,
728cdf0e10cSrcweir const SwPageDesc* pNewPgDesc )
729cdf0e10cSrcweir {
730cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
731cdf0e10cSrcweir const SwSectionFmt* pFmt = GetSectionFormat( rNd );
732cdf0e10cSrcweir const sal_uLong nLnNm = GetSectionLineNo( pSet, rNd );
733cdf0e10cSrcweir
734cdf0e10cSrcweir OSL_ENSURE( pNewPgDescFmt || pNewPgDesc, "Neither page desc format nor page desc provided." );
735cdf0e10cSrcweir
736cdf0e10cSrcweir if ( pNewPgDescFmt )
737cdf0e10cSrcweir m_pSections->AppendSection( *pNewPgDescFmt, rNd, pFmt, nLnNm );
738cdf0e10cSrcweir else if ( pNewPgDesc )
739cdf0e10cSrcweir m_pSections->AppendSection( pNewPgDesc, rNd, pFmt, nLnNm );
740cdf0e10cSrcweir
741cdf0e10cSrcweir AttrOutput().SectionBreak( msword::PageBreak, m_pSections->CurrentSectionInfo() );
742cdf0e10cSrcweir }
743cdf0e10cSrcweir
DisallowInheritingOutlineNumbering(const SwFmt & rFmt)744cdf0e10cSrcweir bool RtfExport::DisallowInheritingOutlineNumbering( const SwFmt& rFmt )
745cdf0e10cSrcweir {
746cdf0e10cSrcweir bool bRet( false );
747cdf0e10cSrcweir
748cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
749cdf0e10cSrcweir
750cdf0e10cSrcweir if (SFX_ITEM_SET != rFmt.GetItemState(RES_PARATR_NUMRULE, false))
751cdf0e10cSrcweir {
752cdf0e10cSrcweir if (const SwFmt *pParent = rFmt.DerivedFrom())
753cdf0e10cSrcweir {
754cdf0e10cSrcweir if (((const SwTxtFmtColl*)pParent)->IsAssignedToListLevelOfOutlineStyle())
755cdf0e10cSrcweir {
756cdf0e10cSrcweir // Level 9 disables the outline
757cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_LEVEL << 9;
758cdf0e10cSrcweir
759cdf0e10cSrcweir bRet = true;
760cdf0e10cSrcweir }
761cdf0e10cSrcweir }
762cdf0e10cSrcweir }
763cdf0e10cSrcweir
764cdf0e10cSrcweir return bRet;
765cdf0e10cSrcweir }
766cdf0e10cSrcweir
OutputGrfNode(const SwGrfNode &)767cdf0e10cSrcweir void RtfExport::OutputGrfNode( const SwGrfNode& )
768cdf0e10cSrcweir {
769cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
770cdf0e10cSrcweir
771cdf0e10cSrcweir /* noop, see RtfAttributeOutput::FlyFrameGraphic */
772cdf0e10cSrcweir }
773cdf0e10cSrcweir
OutputOLENode(const SwOLENode &)774cdf0e10cSrcweir void RtfExport::OutputOLENode( const SwOLENode& )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
777cdf0e10cSrcweir
778cdf0e10cSrcweir /* noop, see RtfAttributeOutput::FlyFrameOLE */
779cdf0e10cSrcweir }
780cdf0e10cSrcweir
AppendSection(const SwPageDesc * pPageDesc,const SwSectionFmt * pFmt,sal_uLong nLnNum)781cdf0e10cSrcweir void RtfExport::AppendSection( const SwPageDesc* pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum )
782cdf0e10cSrcweir {
783cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
784cdf0e10cSrcweir
785cdf0e10cSrcweir m_pSections->AppendSection( pPageDesc, pFmt, nLnNum );
786cdf0e10cSrcweir AttrOutput().SectionBreak( msword::PageBreak, m_pSections->CurrentSectionInfo() );
787cdf0e10cSrcweir }
788cdf0e10cSrcweir
RtfExport(RtfExportFilter * pFilter,SwDoc * pDocument,SwPaM * pCurrentPam,SwPaM * pOriginalPam,Writer * pWriter)789cdf0e10cSrcweir RtfExport::RtfExport( RtfExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam, Writer* pWriter )
790cdf0e10cSrcweir : MSWordExportBase( pDocument, pCurrentPam, pOriginalPam ),
791cdf0e10cSrcweir m_pFilter( pFilter ),
792cdf0e10cSrcweir m_pWriter( pWriter ),
793cdf0e10cSrcweir m_pAttrOutput( NULL ),
794cdf0e10cSrcweir m_pSections( NULL ),
795cdf0e10cSrcweir m_pSdrExport( NULL ),
796cdf0e10cSrcweir eDefaultEncoding(
797cdf0e10cSrcweir rtl_getTextEncodingFromWindowsCharset(
798cdf0e10cSrcweir sw::ms::rtl_TextEncodingToWinCharset(DEF_ENCODING))),
799cdf0e10cSrcweir eCurrentEncoding(eDefaultEncoding),
800cdf0e10cSrcweir bRTFFlySyntax(false)
801cdf0e10cSrcweir {
802cdf0e10cSrcweir mbExportModeRTF = true;
803cdf0e10cSrcweir // the attribute output for the document
804cdf0e10cSrcweir m_pAttrOutput = new RtfAttributeOutput( *this );
805cdf0e10cSrcweir // that just causes problems for RTF
806cdf0e10cSrcweir bSubstituteBullets = false;
807cdf0e10cSrcweir // needed to have a complete font table
808cdf0e10cSrcweir maFontHelper.bLoadAllFonts = true;
809cdf0e10cSrcweir // the related SdrExport
810cdf0e10cSrcweir m_pSdrExport = new RtfSdrExport( *this );
811cdf0e10cSrcweir
812cdf0e10cSrcweir if (!m_pWriter)
813cdf0e10cSrcweir m_pWriter = &m_pFilter->m_aWriter;
814cdf0e10cSrcweir }
815cdf0e10cSrcweir
~RtfExport()816cdf0e10cSrcweir RtfExport::~RtfExport()
817cdf0e10cSrcweir {
818cdf0e10cSrcweir delete m_pAttrOutput, m_pAttrOutput = NULL;
819cdf0e10cSrcweir delete m_pSdrExport, m_pSdrExport = NULL;
820cdf0e10cSrcweir }
821cdf0e10cSrcweir
Strm()822cdf0e10cSrcweir SvStream& RtfExport::Strm()
823cdf0e10cSrcweir {
824cdf0e10cSrcweir return m_pWriter->Strm();
825cdf0e10cSrcweir }
826cdf0e10cSrcweir
OutULong(sal_uLong nVal)827cdf0e10cSrcweir SvStream& RtfExport::OutULong( sal_uLong nVal )
828cdf0e10cSrcweir {
829cdf0e10cSrcweir return m_pWriter->OutULong( Strm(), nVal );
830cdf0e10cSrcweir }
831cdf0e10cSrcweir
OutLong(long nVal)832cdf0e10cSrcweir SvStream& RtfExport::OutLong( long nVal )
833cdf0e10cSrcweir {
834cdf0e10cSrcweir return m_pWriter->OutLong( Strm(), nVal );
835cdf0e10cSrcweir }
836cdf0e10cSrcweir
OutUnicode(const sal_Char * pToken,const String & rContent)837cdf0e10cSrcweir void RtfExport::OutUnicode(const sal_Char *pToken, const String &rContent)
838cdf0e10cSrcweir {
839cdf0e10cSrcweir if (rContent.Len())
840cdf0e10cSrcweir {
841cdf0e10cSrcweir Strm() << '{' << pToken << ' ';
842cdf0e10cSrcweir Strm() << OutString( rContent, eCurrentEncoding ).getStr();
843cdf0e10cSrcweir Strm() << '}';
844cdf0e10cSrcweir }
845cdf0e10cSrcweir }
846cdf0e10cSrcweir
OutHex(sal_uLong nHex,sal_uInt8 nLen)847cdf0e10cSrcweir OString RtfExport::OutHex(sal_uLong nHex, sal_uInt8 nLen)
848cdf0e10cSrcweir {
849cdf0e10cSrcweir sal_Char aNToABuf[] = "0000000000000000";
850cdf0e10cSrcweir
851cdf0e10cSrcweir OSL_ENSURE( nLen < sizeof(aNToABuf), "nLen is too big" );
852cdf0e10cSrcweir if( nLen >= sizeof(aNToABuf) )
853cdf0e10cSrcweir nLen = (sizeof(aNToABuf)-1);
854cdf0e10cSrcweir
855cdf0e10cSrcweir // Set pointer to the buffer end
856cdf0e10cSrcweir sal_Char* pStr = aNToABuf + (sizeof(aNToABuf)-1);
857cdf0e10cSrcweir for( sal_uInt8 n = 0; n < nLen; ++n )
858cdf0e10cSrcweir {
859cdf0e10cSrcweir *(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
860cdf0e10cSrcweir if( *pStr > '9' )
861cdf0e10cSrcweir *pStr += 39;
862cdf0e10cSrcweir nHex >>= 4;
863cdf0e10cSrcweir }
864cdf0e10cSrcweir return OString(pStr);
865cdf0e10cSrcweir }
866cdf0e10cSrcweir
OutChar(sal_Unicode c,int * pUCMode,rtl_TextEncoding eDestEnc)867cdf0e10cSrcweir OString RtfExport::OutChar(sal_Unicode c, int *pUCMode, rtl_TextEncoding eDestEnc)
868cdf0e10cSrcweir {
869cdf0e10cSrcweir OStringBuffer aBuf;
870cdf0e10cSrcweir const sal_Char* pStr = 0;
871cdf0e10cSrcweir // 0x0b instead of \n, etc because of the replacements in SwAttrIter::GetSnippet()
872cdf0e10cSrcweir switch (c)
873cdf0e10cSrcweir {
874cdf0e10cSrcweir case 0x0b:
875cdf0e10cSrcweir // hard line break
876cdf0e10cSrcweir pStr = OOO_STRING_SVTOOLS_RTF_LINE;
877cdf0e10cSrcweir break;
878cdf0e10cSrcweir case '\t':
879cdf0e10cSrcweir pStr = OOO_STRING_SVTOOLS_RTF_TAB;
880cdf0e10cSrcweir break;
881cdf0e10cSrcweir case '\\':
882cdf0e10cSrcweir case '}':
883cdf0e10cSrcweir case '{':
884cdf0e10cSrcweir aBuf.append('\\');
885cdf0e10cSrcweir aBuf.append((sal_Char)c);
886cdf0e10cSrcweir break;
887cdf0e10cSrcweir case 0xa0:
888cdf0e10cSrcweir // non-breaking space
889cdf0e10cSrcweir pStr = "\\~";
890cdf0e10cSrcweir break;
891cdf0e10cSrcweir case 0x1e:
892cdf0e10cSrcweir // non-breaking hyphen
893cdf0e10cSrcweir pStr = "\\_";
894cdf0e10cSrcweir break;
895cdf0e10cSrcweir case 0x1f:
896cdf0e10cSrcweir // optional hyphen
897cdf0e10cSrcweir pStr = "\\-";
898cdf0e10cSrcweir break;
899cdf0e10cSrcweir default:
900cdf0e10cSrcweir if (c >= ' ' && c <= '~')
901cdf0e10cSrcweir aBuf.append((sal_Char)c);
902cdf0e10cSrcweir else {
903cdf0e10cSrcweir //If we can't convert to the dest encoding, or if
904cdf0e10cSrcweir //its an uncommon multibyte sequence which most
905cdf0e10cSrcweir //readers won't be able to handle correctly, then
906cdf0e10cSrcweir //If we can't convert to the dest encoding, then
907cdf0e10cSrcweir //export as unicode
908cdf0e10cSrcweir OUString sBuf(&c, 1);
909cdf0e10cSrcweir OString sConverted;
910cdf0e10cSrcweir sal_uInt32 nFlags =
911cdf0e10cSrcweir RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
912cdf0e10cSrcweir RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR;
913cdf0e10cSrcweir bool bWriteAsUnicode = !(sBuf.convertToString(&sConverted,
914cdf0e10cSrcweir eDestEnc, nFlags))
915cdf0e10cSrcweir || (RTL_TEXTENCODING_UTF8==eDestEnc); // #i43933# do not export UTF-8 chars in RTF;
916cdf0e10cSrcweir if (bWriteAsUnicode)
917cdf0e10cSrcweir sBuf.convertToString(&sConverted,
918cdf0e10cSrcweir eDestEnc, OUSTRING_TO_OSTRING_CVTFLAGS);
919cdf0e10cSrcweir const sal_Int32 nLen = sConverted.getLength();
920cdf0e10cSrcweir
921cdf0e10cSrcweir if (bWriteAsUnicode && pUCMode)
922cdf0e10cSrcweir {
923cdf0e10cSrcweir // then write as unicode - character
924cdf0e10cSrcweir if (*pUCMode != nLen)
925cdf0e10cSrcweir {
926cdf0e10cSrcweir aBuf.append("\\uc");
927cdf0e10cSrcweir aBuf.append((sal_Int32)nLen);
928cdf0e10cSrcweir // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.
929cdf0e10cSrcweir aBuf.append(' ');
930cdf0e10cSrcweir *pUCMode = nLen;
931cdf0e10cSrcweir }
932cdf0e10cSrcweir aBuf.append("\\u");
933cdf0e10cSrcweir aBuf.append((sal_Int32)c);
934cdf0e10cSrcweir }
935cdf0e10cSrcweir
936cdf0e10cSrcweir for (sal_Int32 nI = 0; nI < nLen; ++nI)
937cdf0e10cSrcweir {
938cdf0e10cSrcweir aBuf.append("\\'");
939cdf0e10cSrcweir aBuf.append(OutHex(sConverted.getStr()[nI], 2));
940cdf0e10cSrcweir }
941cdf0e10cSrcweir }
942cdf0e10cSrcweir }
943cdf0e10cSrcweir if (pStr) {
944cdf0e10cSrcweir aBuf.append(pStr);
945cdf0e10cSrcweir aBuf.append(' ');
946cdf0e10cSrcweir }
947cdf0e10cSrcweir return aBuf.makeStringAndClear();
948cdf0e10cSrcweir }
949cdf0e10cSrcweir
OutString(const String & rStr,rtl_TextEncoding eDestEnc)950cdf0e10cSrcweir OString RtfExport::OutString(const String &rStr, rtl_TextEncoding eDestEnc)
951cdf0e10cSrcweir {
952cdf0e10cSrcweir OSL_TRACE("%s, rStr = '%s'", OSL_THIS_FUNC,
953cdf0e10cSrcweir OUStringToOString( OUString( rStr ), eDestEnc ).getStr());
954cdf0e10cSrcweir OStringBuffer aBuf;
955cdf0e10cSrcweir int nUCMode = 1;
956cdf0e10cSrcweir for (xub_StrLen n = 0; n < rStr.Len(); ++n)
957cdf0e10cSrcweir aBuf.append(OutChar(rStr.GetChar(n), &nUCMode, eDestEnc));
958cdf0e10cSrcweir if (nUCMode != 1) {
959cdf0e10cSrcweir aBuf.append(OOO_STRING_SVTOOLS_RTF_UC);
960cdf0e10cSrcweir aBuf.append((sal_Int32)1);
961cdf0e10cSrcweir aBuf.append(" "); // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
962cdf0e10cSrcweir }
963cdf0e10cSrcweir return aBuf.makeStringAndClear();
964cdf0e10cSrcweir }
965cdf0e10cSrcweir
OutDateTime(const sal_Char * pStr,const util::DateTime & rDT)966cdf0e10cSrcweir void RtfExport::OutDateTime(const sal_Char* pStr, const util::DateTime& rDT )
967cdf0e10cSrcweir {
968cdf0e10cSrcweir Strm() << '{' << pStr << OOO_STRING_SVTOOLS_RTF_YR;
969cdf0e10cSrcweir OutULong( rDT.Year ) << OOO_STRING_SVTOOLS_RTF_MO;
970cdf0e10cSrcweir OutULong( rDT.Month ) << OOO_STRING_SVTOOLS_RTF_DY;
971cdf0e10cSrcweir OutULong( rDT.Day ) << OOO_STRING_SVTOOLS_RTF_HR;
972cdf0e10cSrcweir OutULong( rDT.Hours ) << OOO_STRING_SVTOOLS_RTF_MIN;
973cdf0e10cSrcweir OutULong( rDT.Minutes ) << '}';
974cdf0e10cSrcweir }
975cdf0e10cSrcweir
GetColor(const Color & rColor) const976cdf0e10cSrcweir sal_uInt16 RtfExport::GetColor( const Color& rColor ) const
977cdf0e10cSrcweir {
978cdf0e10cSrcweir for (RtfColorTbl::const_iterator it=m_aColTbl.begin() ; it != m_aColTbl.end(); it++ )
979cdf0e10cSrcweir if ((*it).second == rColor) {
980cdf0e10cSrcweir OSL_TRACE("%s returning %d (%d,%d,%d)", OSL_THIS_FUNC, (*it).first, rColor.GetRed(), rColor.GetGreen(), rColor.GetBlue());
981cdf0e10cSrcweir return (*it).first;
982cdf0e10cSrcweir }
983cdf0e10cSrcweir OSL_ENSURE( sal_False, "No such Color in m_aColTbl!" );
984cdf0e10cSrcweir return 0;
985cdf0e10cSrcweir }
986cdf0e10cSrcweir
InsColor(const Color & rCol)987cdf0e10cSrcweir void RtfExport::InsColor( const Color& rCol )
988cdf0e10cSrcweir {
989cdf0e10cSrcweir sal_uInt16 n;
990908991bcSMathias Bauer bool bAutoColorInTable = false;
991908991bcSMathias Bauer for (RtfColorTbl::iterator it=m_aColTbl.begin() ; it != m_aColTbl.end(); ++it )
992908991bcSMathias Bauer {
993cdf0e10cSrcweir if ((*it).second == rCol)
994cdf0e10cSrcweir return; // Already in the table
995908991bcSMathias Bauer else if ((*it).second == COL_AUTO)
996908991bcSMathias Bauer bAutoColorInTable = true;
997908991bcSMathias Bauer }
998908991bcSMathias Bauer
999cdf0e10cSrcweir if (rCol.GetColor() == COL_AUTO)
1000908991bcSMathias Bauer // COL_AUTO gets value 0
1001cdf0e10cSrcweir n = 0;
1002cdf0e10cSrcweir else
1003cdf0e10cSrcweir {
1004908991bcSMathias Bauer // other colors get values >0
1005cdf0e10cSrcweir n = m_aColTbl.size();
1006908991bcSMathias Bauer if (!bAutoColorInTable)
1007908991bcSMathias Bauer // reserve value "0" for COL_AUTO (if COL_AUTO wasn't inserted until now)
1008cdf0e10cSrcweir n++;
1009cdf0e10cSrcweir }
1010908991bcSMathias Bauer
1011cdf0e10cSrcweir m_aColTbl.insert(std::pair<sal_uInt16,Color>( n, rCol ));
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir
InsColorLine(const SvxBoxItem & rBox)1014cdf0e10cSrcweir void RtfExport::InsColorLine( const SvxBoxItem& rBox )
1015cdf0e10cSrcweir {
1016cdf0e10cSrcweir const SvxBorderLine* pLine = 0;
1017cdf0e10cSrcweir
1018cdf0e10cSrcweir if( rBox.GetTop() )
1019cdf0e10cSrcweir InsColor( (pLine = rBox.GetTop())->GetColor() );
1020cdf0e10cSrcweir if( rBox.GetBottom() && pLine != rBox.GetBottom() )
1021cdf0e10cSrcweir InsColor( (pLine = rBox.GetBottom())->GetColor() );
1022cdf0e10cSrcweir if( rBox.GetLeft() && pLine != rBox.GetLeft() )
1023cdf0e10cSrcweir InsColor( (pLine = rBox.GetLeft())->GetColor() );
1024cdf0e10cSrcweir if( rBox.GetRight() && pLine != rBox.GetRight() )
1025cdf0e10cSrcweir InsColor( rBox.GetRight()->GetColor() );
1026cdf0e10cSrcweir }
OutColorTable()1027cdf0e10cSrcweir void RtfExport::OutColorTable()
1028cdf0e10cSrcweir {
1029cdf0e10cSrcweir // Build the table from rPool since the colors provided to
1030cdf0e10cSrcweir // RtfAttributeOutput callbacks are too late.
1031cdf0e10cSrcweir sal_uInt32 nMaxItem;
1032cdf0e10cSrcweir const SfxItemPool& rPool = pDoc->GetAttrPool();
1033cdf0e10cSrcweir
1034cdf0e10cSrcweir // char color
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir const SvxColorItem* pCol = (const SvxColorItem*)GetDfltAttr(
1037cdf0e10cSrcweir RES_CHRATR_COLOR );
1038cdf0e10cSrcweir InsColor( pCol->GetValue() );
1039cdf0e10cSrcweir if( 0 != ( pCol = (const SvxColorItem*)rPool.GetPoolDefaultItem(
1040cdf0e10cSrcweir RES_CHRATR_COLOR ) ))
1041cdf0e10cSrcweir InsColor( pCol->GetValue() );
1042cdf0e10cSrcweir nMaxItem = rPool.GetItemCount2(RES_CHRATR_COLOR);
1043cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nMaxItem; ++n)
1044cdf0e10cSrcweir {
1045cdf0e10cSrcweir if( 0 != (pCol = (const SvxColorItem*)rPool.GetItem2(
1046cdf0e10cSrcweir RES_CHRATR_COLOR, n ) ) )
1047cdf0e10cSrcweir InsColor( pCol->GetValue() );
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir const SvxUnderlineItem* pUnder = (const SvxUnderlineItem*)GetDfltAttr( RES_CHRATR_UNDERLINE );
1051cdf0e10cSrcweir InsColor( pUnder->GetColor() );
1052cdf0e10cSrcweir nMaxItem = rPool.GetItemCount2(RES_CHRATR_UNDERLINE);
1053cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nMaxItem; ++n)
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir if( 0 != (pUnder = (const SvxUnderlineItem*)rPool.GetItem2( RES_CHRATR_UNDERLINE, n ) ) )
1056cdf0e10cSrcweir InsColor( pUnder->GetColor() );
1057cdf0e10cSrcweir
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir
1060cdf0e10cSrcweir const SvxOverlineItem* pOver = (const SvxOverlineItem*)GetDfltAttr( RES_CHRATR_OVERLINE );
1061cdf0e10cSrcweir InsColor( pOver->GetColor() );
1062cdf0e10cSrcweir nMaxItem = rPool.GetItemCount2(RES_CHRATR_OVERLINE);
1063cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nMaxItem; ++n)
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir if( 0 != (pOver = (const SvxOverlineItem*)rPool.GetItem2( RES_CHRATR_OVERLINE, n ) ) )
1066cdf0e10cSrcweir InsColor( pOver->GetColor() );
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir }
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir // background color
1073cdf0e10cSrcweir static const sal_uInt16 aBrushIds[] = {
1074cdf0e10cSrcweir RES_BACKGROUND, RES_CHRATR_BACKGROUND, 0 };
1075cdf0e10cSrcweir
1076cdf0e10cSrcweir for( const sal_uInt16* pIds = aBrushIds; *pIds; ++pIds )
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir const SvxBrushItem* pBkgrd = (const SvxBrushItem*)GetDfltAttr( *pIds );
1079cdf0e10cSrcweir InsColor( pBkgrd->GetColor() );
1080cdf0e10cSrcweir if( 0 != ( pBkgrd = (const SvxBrushItem*)rPool.GetPoolDefaultItem(
1081cdf0e10cSrcweir *pIds ) ))
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir InsColor( pBkgrd->GetColor() );
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir nMaxItem = rPool.GetItemCount2( *pIds );
1086cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nMaxItem; ++n)
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir if( 0 != (pBkgrd = (const SvxBrushItem*)rPool.GetItem2(
1089cdf0e10cSrcweir *pIds , n ) ))
1090cdf0e10cSrcweir {
1091cdf0e10cSrcweir InsColor( pBkgrd->GetColor() );
1092cdf0e10cSrcweir }
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir // shadow color
1097cdf0e10cSrcweir {
1098cdf0e10cSrcweir const SvxShadowItem* pShadow = (const SvxShadowItem*)GetDfltAttr(
1099cdf0e10cSrcweir RES_SHADOW );
1100cdf0e10cSrcweir InsColor( pShadow->GetColor() );
1101cdf0e10cSrcweir if( 0 != ( pShadow = (const SvxShadowItem*)rPool.GetPoolDefaultItem(
1102cdf0e10cSrcweir RES_SHADOW ) ))
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir InsColor( pShadow->GetColor() );
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir nMaxItem = rPool.GetItemCount2(RES_SHADOW);
1107cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nMaxItem; ++n)
1108cdf0e10cSrcweir {
1109cdf0e10cSrcweir if( 0 != (pShadow = (const SvxShadowItem*)rPool.GetItem2(
1110cdf0e10cSrcweir RES_SHADOW, n ) ) )
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir InsColor( pShadow->GetColor() );
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir }
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir
1117cdf0e10cSrcweir // frame border color
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir const SvxBoxItem* pBox;
1120cdf0e10cSrcweir if( 0 != ( pBox = (const SvxBoxItem*)rPool.GetPoolDefaultItem(
1121cdf0e10cSrcweir RES_BOX ) ))
1122cdf0e10cSrcweir InsColorLine( *pBox );
1123cdf0e10cSrcweir nMaxItem = rPool.GetItemCount2(RES_BOX);
1124cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nMaxItem; ++n)
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir if( 0 != (pBox = (const SvxBoxItem*)rPool.GetItem2( RES_BOX, n ) ))
1127cdf0e10cSrcweir InsColorLine( *pBox );
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir }
1130cdf0e10cSrcweir
1131cdf0e10cSrcweir for (size_t n = 0; n < m_aColTbl.size(); ++n)
1132cdf0e10cSrcweir {
1133cdf0e10cSrcweir const Color& rCol = m_aColTbl[ n ];
1134cdf0e10cSrcweir if( n || COL_AUTO != rCol.GetColor() )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_RED;
1137cdf0e10cSrcweir OutULong( rCol.GetRed() ) << OOO_STRING_SVTOOLS_RTF_GREEN;
1138cdf0e10cSrcweir OutULong( rCol.GetGreen() ) << OOO_STRING_SVTOOLS_RTF_BLUE;
1139cdf0e10cSrcweir OutULong( rCol.GetBlue() );
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir Strm() << ';';
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir }
1144cdf0e10cSrcweir
InsStyle(sal_uInt16 nId,const OString & rStyle)1145cdf0e10cSrcweir void RtfExport::InsStyle( sal_uInt16 nId, const OString& rStyle )
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir m_aStyTbl.insert(std::pair<sal_uInt16,OString>(nId, rStyle) );
1148cdf0e10cSrcweir }
1149cdf0e10cSrcweir
GetStyle(sal_uInt16 nId)1150cdf0e10cSrcweir OString* RtfExport::GetStyle( sal_uInt16 nId )
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir std::map<sal_uInt16,OString>::iterator i = m_aStyTbl.find(nId);
1153cdf0e10cSrcweir if (i != m_aStyTbl.end())
1154cdf0e10cSrcweir return &i->second;
1155cdf0e10cSrcweir return NULL;
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir
GetRedline(const String & rAuthor)1158cdf0e10cSrcweir sal_uInt16 RtfExport::GetRedline( const String& rAuthor )
1159cdf0e10cSrcweir {
1160cdf0e10cSrcweir std::map<String,sal_uInt16>::iterator i = m_aRedlineTbl.find(rAuthor);
1161cdf0e10cSrcweir if (i != m_aRedlineTbl.end())
1162cdf0e10cSrcweir return i->second;
1163cdf0e10cSrcweir else
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir int nId = m_aRedlineTbl.size();
1166cdf0e10cSrcweir m_aRedlineTbl.insert(std::pair<String,sal_uInt16>(rAuthor,nId));
1167cdf0e10cSrcweir return nId;
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir
GetRedline(sal_uInt16 nId)1171cdf0e10cSrcweir const String* RtfExport::GetRedline( sal_uInt16 nId )
1172cdf0e10cSrcweir {
1173cdf0e10cSrcweir for(std::map<String,sal_uInt16>::iterator aIter = m_aRedlineTbl.begin(); aIter != m_aRedlineTbl.end(); ++aIter)
1174cdf0e10cSrcweir if ((*aIter).second == nId)
1175cdf0e10cSrcweir return &(*aIter).first;
1176cdf0e10cSrcweir return NULL;
1177cdf0e10cSrcweir }
1178cdf0e10cSrcweir
OutPageDescription(const SwPageDesc & rPgDsc,sal_Bool bWriteReset,sal_Bool bCheckForFirstPage)1179cdf0e10cSrcweir void RtfExport::OutPageDescription( const SwPageDesc& rPgDsc, sal_Bool bWriteReset, sal_Bool bCheckForFirstPage )
1180cdf0e10cSrcweir {
1181cdf0e10cSrcweir OSL_TRACE("%s start", OSL_THIS_FUNC);
1182cdf0e10cSrcweir const SwPageDesc *pSave = pAktPageDesc;
1183cdf0e10cSrcweir
1184cdf0e10cSrcweir pAktPageDesc = &rPgDsc;
1185cdf0e10cSrcweir if( bCheckForFirstPage && pAktPageDesc->GetFollow() &&
1186cdf0e10cSrcweir pAktPageDesc->GetFollow() != pAktPageDesc )
1187cdf0e10cSrcweir pAktPageDesc = pAktPageDesc->GetFollow();
1188cdf0e10cSrcweir
1189cdf0e10cSrcweir if( bWriteReset )
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir if( pCurPam->GetPoint()->nNode == pOrigPam->Start()->nNode )
1192cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_SECTD << OOO_STRING_SVTOOLS_RTF_SBKNONE;
1193cdf0e10cSrcweir else
1194cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_SECT << OOO_STRING_SVTOOLS_RTF_SECTD;
1195cdf0e10cSrcweir }
1196cdf0e10cSrcweir
1197cdf0e10cSrcweir if( pAktPageDesc->GetLandscape() )
1198cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_LNDSCPSXN;
1199cdf0e10cSrcweir
1200cdf0e10cSrcweir const SwFmt *pFmt = &pAktPageDesc->GetMaster(); //GetLeft();
1201cdf0e10cSrcweir bOutPageDescs = true;
1202cdf0e10cSrcweir OutputFormat(*pFmt, true, false);
1203cdf0e10cSrcweir bOutPageDescs = false;
1204cdf0e10cSrcweir
1205cdf0e10cSrcweir // normal header / footer (without a style)
1206cdf0e10cSrcweir const SfxPoolItem* pItem;
1207cdf0e10cSrcweir if( pAktPageDesc->GetLeft().GetAttrSet().GetItemState( RES_HEADER, sal_False,
1208cdf0e10cSrcweir &pItem ) == SFX_ITEM_SET)
1209cdf0e10cSrcweir WriteHeaderFooter(*pItem, true);
1210cdf0e10cSrcweir if( pAktPageDesc->GetLeft().GetAttrSet().GetItemState( RES_FOOTER, sal_False,
1211cdf0e10cSrcweir &pItem ) == SFX_ITEM_SET)
1212cdf0e10cSrcweir WriteHeaderFooter(*pItem, false);
1213cdf0e10cSrcweir
1214cdf0e10cSrcweir // title page
1215cdf0e10cSrcweir if( pAktPageDesc != &rPgDsc )
1216cdf0e10cSrcweir {
1217cdf0e10cSrcweir pAktPageDesc = &rPgDsc;
1218cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_TITLEPG;
1219cdf0e10cSrcweir if( pAktPageDesc->GetMaster().GetAttrSet().GetItemState( RES_HEADER,
1220cdf0e10cSrcweir sal_False, &pItem ) == SFX_ITEM_SET )
1221cdf0e10cSrcweir WriteHeaderFooter(*pItem, true);
1222cdf0e10cSrcweir if( pAktPageDesc->GetMaster().GetAttrSet().GetItemState( RES_FOOTER,
1223cdf0e10cSrcweir sal_False, &pItem ) == SFX_ITEM_SET )
1224cdf0e10cSrcweir WriteHeaderFooter(*pItem, false);
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir
1227cdf0e10cSrcweir // numbering type
1228cdf0e10cSrcweir AttrOutput().SectionPageNumbering(pAktPageDesc->GetNumType().GetNumberingType(), 0);
1229cdf0e10cSrcweir
1230cdf0e10cSrcweir pAktPageDesc = pSave;
1231cdf0e10cSrcweir //bOutPageDesc = bOldOut;
1232cdf0e10cSrcweir OSL_TRACE("%s end", OSL_THIS_FUNC);
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir
WriteHeaderFooter(const SfxPoolItem & rItem,bool bHeader)1235cdf0e10cSrcweir void RtfExport::WriteHeaderFooter(const SfxPoolItem& rItem, bool bHeader)
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir if (bHeader)
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir const SwFmtHeader& rHeader = (const SwFmtHeader&)rItem;
1240cdf0e10cSrcweir if (!rHeader.IsActive())
1241cdf0e10cSrcweir return;
1242cdf0e10cSrcweir }
1243cdf0e10cSrcweir else
1244cdf0e10cSrcweir {
1245cdf0e10cSrcweir const SwFmtFooter& rFooter = (const SwFmtFooter&)rItem;
1246cdf0e10cSrcweir if (!rFooter.IsActive())
1247cdf0e10cSrcweir return;
1248cdf0e10cSrcweir }
1249cdf0e10cSrcweir
1250cdf0e10cSrcweir OSL_TRACE("%s start", OSL_THIS_FUNC);
1251cdf0e10cSrcweir
1252cdf0e10cSrcweir const sal_Char* pStr = (bHeader ? OOO_STRING_SVTOOLS_RTF_HEADER : OOO_STRING_SVTOOLS_RTF_FOOTER);
1253cdf0e10cSrcweir /* is this a title page? */
1254cdf0e10cSrcweir if( pAktPageDesc->GetFollow() && pAktPageDesc->GetFollow() != pAktPageDesc )
1255cdf0e10cSrcweir {
1256cdf0e10cSrcweir Strm() << OOO_STRING_SVTOOLS_RTF_TITLEPG;
1257cdf0e10cSrcweir pStr = (bHeader ? OOO_STRING_SVTOOLS_RTF_HEADERF : OOO_STRING_SVTOOLS_RTF_FOOTERF);
1258cdf0e10cSrcweir }
1259cdf0e10cSrcweir Strm() << '{' << pStr;
1260cdf0e10cSrcweir WriteHeaderFooterText(pAktPageDesc->GetMaster(), bHeader);
1261cdf0e10cSrcweir Strm() << '}';
1262cdf0e10cSrcweir
1263cdf0e10cSrcweir OSL_TRACE("%s end", OSL_THIS_FUNC);
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir
WriteHeaderFooter(const SwFrmFmt & rFmt,bool bHeader,const sal_Char * pStr)1266cdf0e10cSrcweir void RtfExport::WriteHeaderFooter(const SwFrmFmt& rFmt, bool bHeader, const sal_Char* pStr)
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir OSL_TRACE("%s start", OSL_THIS_FUNC);
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir m_pAttrOutput->WriteHeaderFooter_Impl( rFmt, bHeader, pStr );
1271cdf0e10cSrcweir
1272cdf0e10cSrcweir OSL_TRACE("%s end", OSL_THIS_FUNC);
1273cdf0e10cSrcweir }
1274cdf0e10cSrcweir
1275cdf0e10cSrcweir class SwRTFWriter : public Writer
1276cdf0e10cSrcweir {
1277cdf0e10cSrcweir bool m_bOutOutlineOnly;
1278cdf0e10cSrcweir public:
1279cdf0e10cSrcweir SwRTFWriter( const String& rFilterName, const String& rBaseURL );
1280cdf0e10cSrcweir virtual ~SwRTFWriter();
1281cdf0e10cSrcweir virtual sal_uLong WriteStream();
1282cdf0e10cSrcweir };
1283cdf0e10cSrcweir
SwRTFWriter(const String & rFltName,const String & rBaseURL)1284cdf0e10cSrcweir SwRTFWriter::SwRTFWriter( const String& rFltName, const String & rBaseURL )
1285cdf0e10cSrcweir {
1286cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
1287cdf0e10cSrcweir SetBaseURL( rBaseURL );
1288cdf0e10cSrcweir // export outline nodes, only (send outline to clipboard/presentation)
1289cdf0e10cSrcweir m_bOutOutlineOnly = 'O' == rFltName.GetChar( 0 );
1290cdf0e10cSrcweir }
1291cdf0e10cSrcweir
~SwRTFWriter()1292cdf0e10cSrcweir SwRTFWriter::~SwRTFWriter()
1293cdf0e10cSrcweir {}
1294cdf0e10cSrcweir
WriteStream()1295cdf0e10cSrcweir sal_uLong SwRTFWriter::WriteStream()
1296cdf0e10cSrcweir {
1297cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
1298cdf0e10cSrcweir RtfExport aExport( NULL, pDoc, new SwPaM( *pCurPam->End(), *pCurPam->Start() ), pCurPam, this );
1299cdf0e10cSrcweir aExport.mbOutOutlineOnly = m_bOutOutlineOnly;
1300cdf0e10cSrcweir aExport.ExportDocument( true );
1301cdf0e10cSrcweir return 0;
1302cdf0e10cSrcweir }
1303cdf0e10cSrcweir
ExportRTF(const String & rFltName,const String & rBaseURL,WriterRef & xRet)1304cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL ExportRTF( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
1305cdf0e10cSrcweir {
1306cdf0e10cSrcweir OSL_TRACE("%s", OSL_THIS_FUNC);
1307cdf0e10cSrcweir xRet = new SwRTFWriter( rFltName, rBaseURL );
1308cdf0e10cSrcweir }
1309cdf0e10cSrcweir
1310cdf0e10cSrcweir /* vi:set shiftwidth=4 expandtab: */
1311