1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scfilt.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir #include <editeng/eeitem.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <svx/algitem.hxx>
34cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
35cdf0e10cSrcweir #include <editeng/postitem.hxx>
36cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
37cdf0e10cSrcweir #include <editeng/fontitem.hxx>
38cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
39cdf0e10cSrcweir #include <svl/style.hxx>
40cdf0e10cSrcweir #include <svtools/rtfout.hxx>
41cdf0e10cSrcweir #include <svtools/rtfkeywd.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include "rtfexp.hxx"
44cdf0e10cSrcweir #include "filter.hxx"
45cdf0e10cSrcweir #include "document.hxx"
46cdf0e10cSrcweir #include "patattr.hxx"
47cdf0e10cSrcweir #include "attrib.hxx"
48cdf0e10cSrcweir #include "cell.hxx"
49cdf0e10cSrcweir #include "cellform.hxx"
50cdf0e10cSrcweir #include "editutil.hxx"
51cdf0e10cSrcweir #include "stlpool.hxx"
52cdf0e10cSrcweir #include "ftools.hxx"
53cdf0e10cSrcweir
54cdf0e10cSrcweir //------------------------------------------------------------------
55cdf0e10cSrcweir
ScExportRTF(SvStream & rStrm,ScDocument * pDoc,const ScRange & rRange,const CharSet)56cdf0e10cSrcweir FltError ScFormatFilterPluginImpl::ScExportRTF( SvStream& rStrm, ScDocument* pDoc,
57cdf0e10cSrcweir const ScRange& rRange, const CharSet /*eNach*/ )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir ScRTFExport aEx( rStrm, pDoc, rRange );
60cdf0e10cSrcweir return aEx.Write();
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
63cdf0e10cSrcweir
ScRTFExport(SvStream & rStrmP,ScDocument * pDocP,const ScRange & rRangeP)64cdf0e10cSrcweir ScRTFExport::ScRTFExport( SvStream& rStrmP, ScDocument* pDocP, const ScRange& rRangeP )
65cdf0e10cSrcweir :
66cdf0e10cSrcweir ScExportBase( rStrmP, pDocP, rRangeP ),
67cdf0e10cSrcweir pCellX( new sal_uLong[ MAXCOL+2 ] )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir
~ScRTFExport()72cdf0e10cSrcweir ScRTFExport::~ScRTFExport()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir delete [] pCellX;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir
Write()78cdf0e10cSrcweir sal_uLong ScRTFExport::Write()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir rStrm << '{' << OOO_STRING_SVTOOLS_RTF_RTF;
81cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_ANSI << sNewLine;
82cdf0e10cSrcweir
83cdf0e10cSrcweir #if 0
84cdf0e10cSrcweir // das ist noch nicht ausgegoren
85cdf0e10cSrcweir /*
86cdf0e10cSrcweir SfxStyleSheetBasePool* pStylePool = pDoc->GetStyleSheetPool();
87cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet = NULL;
88cdf0e10cSrcweir DBG_ASSERT( pStylePool, "StylePool not found! :-(" );
89cdf0e10cSrcweir pStylePool->SetSearchMask( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
90cdf0e10cSrcweir pStyleSheet = pStylePool->Find( STRING_STANDARD, SFX_STYLE_FAMILY_PARA );
91cdf0e10cSrcweir DBG_ASSERT( pStyleSheet, "ParaStyle not found! :-(" );
92cdf0e10cSrcweir const SfxItemSet& rSetPara = pStyleSheet->GetItemSet();
93cdf0e10cSrcweir
94cdf0e10cSrcweir // fonttbl
95cdf0e10cSrcweir String aFontFamilyName(
96cdf0e10cSrcweir ((const SvxFontItem&)(rSetPara.Get( ATTR_FONT ))).GetFamilyName() );
97cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_DEFF << '0'
98cdf0e10cSrcweir << '{' << OOO_STRING_SVTOOLS_RTF_FONTTBL
99cdf0e10cSrcweir << '{' << OOO_STRING_SVTOOLS_RTF_F << '0' << OOO_STRING_SVTOOLS_RTF_FNIL << ' ' << aFontFamilyName.GetStr() << ";}"
100cdf0e10cSrcweir << '}' << sNewLine;
101cdf0e10cSrcweir
102cdf0e10cSrcweir // hier kaeme die colortbl
103cdf0e10cSrcweir
104cdf0e10cSrcweir // stylesheet
105cdf0e10cSrcweir sal_uInt32 nFontHeight =
106cdf0e10cSrcweir ((const SvxFontHeightItem&)(rSetPara.Get( ATTR_FONT_HEIGHT ))).GetHeight();
107cdf0e10cSrcweir rStrm << '{' << OOO_STRING_SVTOOLS_RTF_STYLESHEET
108cdf0e10cSrcweir << '{' << OOO_STRING_SVTOOLS_RTF_FS << String( sal_uInt32(nFontHeight / TWIPS_PER_POINT) ).GetStr()
109cdf0e10cSrcweir << ' ' << pStyleSheet->GetName().GetStr() << ";}"
110cdf0e10cSrcweir << '}' << sNewLine;
111cdf0e10cSrcweir */
112cdf0e10cSrcweir #endif
113cdf0e10cSrcweir
114cdf0e10cSrcweir // Daten
115cdf0e10cSrcweir for ( SCTAB nTab = aRange.aStart.Tab(); nTab <= aRange.aEnd.Tab(); nTab++ )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir if ( nTab > aRange.aStart.Tab() )
118cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_PAR;
119cdf0e10cSrcweir WriteTab( nTab );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
122cdf0e10cSrcweir rStrm << '}' << sNewLine;
123cdf0e10cSrcweir return rStrm.GetError();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
126cdf0e10cSrcweir
WriteTab(SCTAB nTab)127cdf0e10cSrcweir void ScRTFExport::WriteTab( SCTAB nTab )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir rStrm << '{' << sNewLine;
130cdf0e10cSrcweir if ( pDoc->HasTable( nTab ) )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir memset( &pCellX[0], 0, (MAXCOL+2) * sizeof(sal_uLong) );
133cdf0e10cSrcweir SCCOL nCol;
134cdf0e10cSrcweir SCCOL nEndCol = aRange.aEnd.Col();
135cdf0e10cSrcweir for ( nCol = aRange.aStart.Col(); nCol <= nEndCol; nCol++ )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir pCellX[nCol+1] = pCellX[nCol] + pDoc->GetColWidth( nCol, nTab );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir SCROW nEndRow = aRange.aEnd.Row();
141cdf0e10cSrcweir for ( SCROW nRow = aRange.aStart.Row(); nRow <= nEndRow; nRow++ )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir WriteRow( nTab, nRow );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir }
146cdf0e10cSrcweir rStrm << '}' << sNewLine;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir
WriteRow(SCTAB nTab,SCROW nRow)150cdf0e10cSrcweir void ScRTFExport::WriteRow( SCTAB nTab, SCROW nRow )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_TROWD << OOO_STRING_SVTOOLS_RTF_TRGAPH << "30" << OOO_STRING_SVTOOLS_RTF_TRLEFT << "-30";
153cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_TRRH << ByteString::CreateFromInt32( pDoc->GetRowHeight( nRow, nTab ) ).GetBuffer();
154cdf0e10cSrcweir SCCOL nCol;
155cdf0e10cSrcweir SCCOL nEndCol = aRange.aEnd.Col();
156cdf0e10cSrcweir for ( nCol = aRange.aStart.Col(); nCol <= nEndCol; nCol++ )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab );
159cdf0e10cSrcweir const ScMergeAttr& rMergeAttr = (const ScMergeAttr&) pAttr->GetItem( ATTR_MERGE );
160cdf0e10cSrcweir const SvxVerJustifyItem& rVerJustifyItem= (const SvxVerJustifyItem&)pAttr->GetItem( ATTR_VER_JUSTIFY );
161cdf0e10cSrcweir
162cdf0e10cSrcweir const sal_Char* pChar;
163cdf0e10cSrcweir
164cdf0e10cSrcweir if ( rMergeAttr.GetColMerge() != 0 )
165cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_CLMGF;
166cdf0e10cSrcweir else
167cdf0e10cSrcweir {
168cdf0e10cSrcweir const ScMergeFlagAttr& rMergeFlagAttr = (const ScMergeFlagAttr&) pAttr->GetItem( ATTR_MERGE_FLAG );
169cdf0e10cSrcweir if ( rMergeFlagAttr.IsHorOverlapped() )
170cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_CLMRG;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir switch( rVerJustifyItem.GetValue() )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir case SVX_VER_JUSTIFY_TOP: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALT; break;
176cdf0e10cSrcweir case SVX_VER_JUSTIFY_CENTER: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALC; break;
177cdf0e10cSrcweir case SVX_VER_JUSTIFY_BOTTOM: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALB; break;
178cdf0e10cSrcweir case SVX_VER_JUSTIFY_STANDARD: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALB; break; //! Bottom
179cdf0e10cSrcweir default: pChar = NULL; break;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir if ( pChar )
182cdf0e10cSrcweir rStrm << pChar;
183cdf0e10cSrcweir
184cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_CELLX << ByteString::CreateFromInt32( pCellX[nCol+1] ).GetBuffer();
185cdf0e10cSrcweir if ( (nCol & 0x0F) == 0x0F )
186cdf0e10cSrcweir rStrm << sNewLine; // Zeilen nicht zu lang werden lassen
187cdf0e10cSrcweir }
188cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_PLAIN << OOO_STRING_SVTOOLS_RTF_INTBL << sNewLine;
189cdf0e10cSrcweir
190cdf0e10cSrcweir sal_uLong nStrmPos = rStrm.Tell();
191cdf0e10cSrcweir for ( nCol = aRange.aStart.Col(); nCol <= nEndCol; nCol++ )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir WriteCell( nTab, nRow, nCol );
194cdf0e10cSrcweir if ( rStrm.Tell() - nStrmPos > 255 )
195cdf0e10cSrcweir { // Zeilen nicht zu lang werden lassen
196cdf0e10cSrcweir rStrm << sNewLine;
197cdf0e10cSrcweir nStrmPos = rStrm.Tell();
198cdf0e10cSrcweir }
199cdf0e10cSrcweir }
200cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_ROW << sNewLine;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir
WriteCell(SCTAB nTab,SCROW nRow,SCCOL nCol)204cdf0e10cSrcweir void ScRTFExport::WriteCell( SCTAB nTab, SCROW nRow, SCCOL nCol )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab );
207cdf0e10cSrcweir
208cdf0e10cSrcweir const ScMergeFlagAttr& rMergeFlagAttr = (const ScMergeFlagAttr&) pAttr->GetItem( ATTR_MERGE_FLAG );
209cdf0e10cSrcweir if ( rMergeFlagAttr.IsHorOverlapped() )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_CELL;
212cdf0e10cSrcweir return ;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir ScBaseCell* pCell;
216cdf0e10cSrcweir pDoc->GetCell( nCol, nRow, nTab, pCell );
217cdf0e10cSrcweir sal_Bool bValueData;
218cdf0e10cSrcweir String aContent;
219cdf0e10cSrcweir if ( pCell )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir switch ( pCell->GetCellType() )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir case CELLTYPE_NOTE :
224cdf0e10cSrcweir bValueData = sal_False;
225cdf0e10cSrcweir break; // nix
226cdf0e10cSrcweir case CELLTYPE_EDIT :
227cdf0e10cSrcweir {
228cdf0e10cSrcweir bValueData = sal_False;
229cdf0e10cSrcweir EditEngine& rEngine = GetEditEngine();
230cdf0e10cSrcweir const EditTextObject* pObj;
231cdf0e10cSrcweir ((const ScEditCell*)pCell)->GetData( pObj );
232cdf0e10cSrcweir if ( pObj )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir rEngine.SetText( *pObj );
235cdf0e10cSrcweir aContent = rEngine.GetText( LINEEND_LF ); // LineFeed zwischen Absaetzen!
236cdf0e10cSrcweir }
237cdf0e10cSrcweir }
238cdf0e10cSrcweir break;
239cdf0e10cSrcweir default:
240cdf0e10cSrcweir {
241cdf0e10cSrcweir bValueData = pCell->HasValueData();
242cdf0e10cSrcweir sal_uLong nFormat = pAttr->GetNumberFormat( pFormatter );
243cdf0e10cSrcweir Color* pColor;
244cdf0e10cSrcweir ScCellFormat::GetString( pCell, nFormat, aContent, &pColor, *pFormatter );
245cdf0e10cSrcweir }
246cdf0e10cSrcweir }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir else
249cdf0e10cSrcweir bValueData = sal_False;
250cdf0e10cSrcweir
251cdf0e10cSrcweir sal_Bool bResetPar, bResetAttr;
252cdf0e10cSrcweir bResetPar = bResetAttr = sal_False;
253cdf0e10cSrcweir
254cdf0e10cSrcweir const SvxHorJustifyItem& rHorJustifyItem = (const SvxHorJustifyItem&)pAttr->GetItem( ATTR_HOR_JUSTIFY );
255cdf0e10cSrcweir const SvxWeightItem& rWeightItem = (const SvxWeightItem&) pAttr->GetItem( ATTR_FONT_WEIGHT );
256cdf0e10cSrcweir const SvxPostureItem& rPostureItem = (const SvxPostureItem&) pAttr->GetItem( ATTR_FONT_POSTURE );
257cdf0e10cSrcweir const SvxUnderlineItem& rUnderlineItem = (const SvxUnderlineItem&) pAttr->GetItem( ATTR_FONT_UNDERLINE );
258cdf0e10cSrcweir
259cdf0e10cSrcweir const sal_Char* pChar;
260cdf0e10cSrcweir
261cdf0e10cSrcweir switch( rHorJustifyItem.GetValue() )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir case SVX_HOR_JUSTIFY_STANDARD:
264cdf0e10cSrcweir pChar = (bValueData ? OOO_STRING_SVTOOLS_RTF_QR : OOO_STRING_SVTOOLS_RTF_QL);
265cdf0e10cSrcweir break;
266cdf0e10cSrcweir case SVX_HOR_JUSTIFY_CENTER: pChar = OOO_STRING_SVTOOLS_RTF_QC; break;
267cdf0e10cSrcweir case SVX_HOR_JUSTIFY_BLOCK: pChar = OOO_STRING_SVTOOLS_RTF_QJ; break;
268cdf0e10cSrcweir case SVX_HOR_JUSTIFY_RIGHT: pChar = OOO_STRING_SVTOOLS_RTF_QR; break;
269cdf0e10cSrcweir case SVX_HOR_JUSTIFY_LEFT:
270cdf0e10cSrcweir case SVX_HOR_JUSTIFY_REPEAT:
271cdf0e10cSrcweir default: pChar = OOO_STRING_SVTOOLS_RTF_QL; break;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir rStrm << pChar;
274cdf0e10cSrcweir
275cdf0e10cSrcweir if ( rWeightItem.GetWeight() >= WEIGHT_BOLD )
276cdf0e10cSrcweir { // bold
277cdf0e10cSrcweir bResetAttr = sal_True;
278cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_B;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir if ( rPostureItem.GetPosture() != ITALIC_NONE )
281cdf0e10cSrcweir { // italic
282cdf0e10cSrcweir bResetAttr = sal_True;
283cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_I;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir if ( rUnderlineItem.GetLineStyle() != UNDERLINE_NONE )
286cdf0e10cSrcweir { // underline
287cdf0e10cSrcweir bResetAttr = sal_True;
288cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_UL;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
291cdf0e10cSrcweir rStrm << ' ';
292cdf0e10cSrcweir RTFOutFuncs::Out_String( rStrm, aContent );
293cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_CELL;
294cdf0e10cSrcweir
295cdf0e10cSrcweir if ( bResetPar )
296cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_INTBL;
297cdf0e10cSrcweir if ( bResetAttr )
298cdf0e10cSrcweir rStrm << OOO_STRING_SVTOOLS_RTF_PLAIN;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir
301cdf0e10cSrcweir
302