Update ooo320-m1
[ooovba.git] / sw / source / filter / ascii / ascatr.cxx
blob10e85b5c084b86f5381f1035e1e9bde2c1d4ea61
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ascatr.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <hintids.hxx>
34 #include <tools/stream.hxx>
35 #ifndef _SVSTDARR_HXX
36 #define _SVSTDARR_USHORTS
37 #include <svtools/svstdarr.hxx>
38 #endif
39 #include <svx/fontitem.hxx>
40 #include <pam.hxx>
41 #include <doc.hxx>
42 #include <ndtxt.hxx>
43 #include <wrtasc.hxx>
44 #include <txatbase.hxx>
45 #include <fchrfmt.hxx>
46 #include <txtfld.hxx>
47 #include <txtatr.hxx>
48 #include <fmtftn.hxx>
49 #include <charfmt.hxx>
50 #include <fmtfld.hxx>
51 #include <fldbas.hxx>
52 #include <ftninfo.hxx>
55 * Dieses File enthaelt alle Ausgabe-Funktionen des ASCII-Writers;
56 * fuer alle Nodes, Attribute, Formate und Chars.
59 class SwASC_AttrIter
61 SwASCWriter& rWrt;
62 const SwTxtNode& rNd;
63 xub_StrLen nAktSwPos;
65 xub_StrLen SearchNext( xub_StrLen nStartPos );
67 public:
68 SwASC_AttrIter( SwASCWriter& rWrt, const SwTxtNode& rNd, xub_StrLen nStt );
70 void NextPos() { nAktSwPos = SearchNext( nAktSwPos + 1 ); }
72 xub_StrLen WhereNext() const { return nAktSwPos; }
73 BOOL OutAttr( xub_StrLen nSwPos );
77 SwASC_AttrIter::SwASC_AttrIter( SwASCWriter& rWr, const SwTxtNode& rTxtNd,
78 xub_StrLen nStt )
79 : rWrt( rWr ), rNd( rTxtNd ), nAktSwPos( 0 )
81 nAktSwPos = SearchNext( nStt + 1 );
85 xub_StrLen SwASC_AttrIter::SearchNext( xub_StrLen nStartPos )
87 xub_StrLen nMinPos = STRING_MAXLEN;
88 const SwpHints* pTxtAttrs = rNd.GetpSwpHints();
89 if( pTxtAttrs )
91 // kann noch optimiert werden, wenn ausgenutzt wird, dass die TxtAttrs
92 // nach der Anfangsposition geordnet sind. Dann muessten
93 // allerdings noch 2 Indices gemerkt werden
94 for ( USHORT i = 0; i < pTxtAttrs->Count(); i++ )
96 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
97 if (pHt->HasDummyChar())
99 xub_StrLen nPos = *pHt->GetStart();
101 if( nPos >= nStartPos && nPos <= nMinPos )
102 nMinPos = nPos;
104 if( ( ++nPos ) >= nStartPos && nPos < nMinPos )
105 nMinPos = nPos;
109 return nMinPos;
113 BOOL SwASC_AttrIter::OutAttr( xub_StrLen nSwPos )
115 BOOL bRet = FALSE;
116 const SwpHints* pTxtAttrs = rNd.GetpSwpHints();
117 if( pTxtAttrs )
119 USHORT i;
120 for( i = 0; i < pTxtAttrs->Count(); i++ )
122 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
123 if ( pHt->HasDummyChar() && nSwPos == *pHt->GetStart() )
125 bRet = TRUE;
126 String sOut;
127 switch( pHt->Which() )
129 case RES_TXTATR_FIELD:
130 sOut = ((SwTxtFld*)pHt)->GetFld().GetFld()->Expand();
131 break;
133 case RES_TXTATR_FTN:
135 const SwFmtFtn& rFtn = pHt->GetFtn();
136 if( rFtn.GetNumStr().Len() )
137 sOut = rFtn.GetNumStr();
138 else if( rFtn.IsEndNote() )
139 sOut = rWrt.pDoc->GetEndNoteInfo().aFmt.
140 GetNumStr( rFtn.GetNumber() );
141 else
142 sOut = rWrt.pDoc->GetFtnInfo().aFmt.
143 GetNumStr( rFtn.GetNumber() );
145 break;
147 if( sOut.Len() )
148 rWrt.Strm().WriteUnicodeOrByteText( sOut );
150 else if( nSwPos < *pHt->GetStart() )
151 break;
154 return bRet;
158 //------------------------
159 /* Ausgabe der Nodes */
160 //------------------------
162 static Writer& OutASC_SwTxtNode( Writer& rWrt, SwCntntNode& rNode )
164 const SwTxtNode& rNd = (SwTxtNode&)rNode;
166 xub_StrLen nStrPos = rWrt.pCurPam->GetPoint()->nContent.GetIndex();
167 xub_StrLen nNodeEnde = rNd.Len(), nEnde = nNodeEnde;
168 BOOL bLastNd = rWrt.pCurPam->GetPoint()->nNode == rWrt.pCurPam->GetMark()->nNode;
169 if( bLastNd )
170 nEnde = rWrt.pCurPam->GetMark()->nContent.GetIndex();
172 SwASC_AttrIter aAttrIter( (SwASCWriter&)rWrt, rNd, nStrPos );
174 if( !nStrPos && rWrt.bExportPargraphNumbering )
175 rWrt.Strm().WriteUnicodeOrByteText( rNd.GetNumString() );
177 String aStr( rNd.GetTxt() );
178 if( rWrt.bASCII_ParaAsBlanc )
179 aStr.SearchAndReplaceAll( 0x0A, ' ' );
181 const bool bExportSoftHyphens = RTL_TEXTENCODING_UCS2 == rWrt.GetAsciiOptions().GetCharSet() ||
182 RTL_TEXTENCODING_UTF8 == rWrt.GetAsciiOptions().GetCharSet();
184 do {
185 xub_StrLen nNextAttr = aAttrIter.WhereNext();
187 if( nNextAttr > nEnde )
188 nNextAttr = nEnde;
190 if( !aAttrIter.OutAttr( nStrPos ))
192 String aOutStr( aStr.Copy( nStrPos, nNextAttr - nStrPos ) );
193 if ( !bExportSoftHyphens )
194 aOutStr.EraseAllChars( CHAR_SOFTHYPHEN );
196 rWrt.Strm().WriteUnicodeOrByteText( aOutStr );
198 nStrPos = nNextAttr;
199 aAttrIter.NextPos();
200 } while( nStrPos < nEnde );
202 if( !bLastNd ||
203 ( !rWrt.bWriteClipboardDoc && !rWrt.bASCII_NoLastLineEnd )
204 && !nStrPos && nEnde == nNodeEnde )
205 rWrt.Strm().WriteUnicodeOrByteText( ((SwASCWriter&)rWrt).GetLineEnd());
207 return rWrt;
211 * lege hier jetzt die Tabellen fuer die ASCII-Funktions-Pointer auf
212 * die Ausgabe-Funktionen an.
213 * Es sind lokale Strukturen, die nur innerhalb der ASCII-DLL
214 * bekannt sein muessen.
217 SwNodeFnTab aASCNodeFnTab = {
218 /* RES_TXTNODE */ OutASC_SwTxtNode,
219 /* RES_GRFNODE */ 0,
220 /* RES_OLENODE */ 0