update dev300-m58
[ooovba.git] / sw / source / filter / ascii / ascatr.cxx
blob5d313e5905fe3ebc5d3bc78f153a562f5b2e5141
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 USHORT i;
92 xub_StrLen nPos;
93 const xub_StrLen * pPos;
95 // kann noch optimiert werden, wenn ausgenutzt wird, dass die TxtAttrs
96 // nach der Anfangsposition geordnet sind. Dann muessten
97 // allerdings noch 2 Indices gemerkt werden
98 for( i = 0; i < pTxtAttrs->Count(); i++ )
100 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
101 nPos = *pHt->GetStart(); // gibt erstes Attr-Zeichen
102 pPos = pHt->GetEnd();
103 if( !pPos )
105 if( nPos >= nStartPos && nPos <= nMinPos )
106 nMinPos = nPos;
108 if( ( ++nPos ) >= nStartPos && nPos < nMinPos )
109 nMinPos = nPos;
113 return nMinPos;
117 BOOL SwASC_AttrIter::OutAttr( xub_StrLen nSwPos )
119 BOOL bRet = FALSE;
120 const SwpHints* pTxtAttrs = rNd.GetpSwpHints();
121 if( pTxtAttrs )
123 USHORT i;
124 for( i = 0; i < pTxtAttrs->Count(); i++ )
126 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
127 const xub_StrLen * pEnd = pHt->GetEnd();
128 if( !pEnd && nSwPos == *pHt->GetStart() )
130 bRet = TRUE;
131 String sOut;
132 switch( pHt->Which() )
134 case RES_TXTATR_FIELD:
135 sOut = ((SwTxtFld*)pHt)->GetFld().GetFld()->Expand();
136 break;
138 case RES_TXTATR_HARDBLANK:
139 sOut = ((SwTxtHardBlank*)pHt)->GetChar();
140 break;
142 case RES_TXTATR_FTN:
144 const SwFmtFtn& rFtn = pHt->GetFtn();
145 if( rFtn.GetNumStr().Len() )
146 sOut = rFtn.GetNumStr();
147 else if( rFtn.IsEndNote() )
148 sOut = rWrt.pDoc->GetEndNoteInfo().aFmt.
149 GetNumStr( rFtn.GetNumber() );
150 else
151 sOut = rWrt.pDoc->GetFtnInfo().aFmt.
152 GetNumStr( rFtn.GetNumber() );
154 break;
156 if( sOut.Len() )
157 rWrt.Strm().WriteUnicodeOrByteText( sOut );
159 else if( nSwPos < *pHt->GetStart() )
160 break;
163 return bRet;
167 //------------------------
168 /* Ausgabe der Nodes */
169 //------------------------
171 static Writer& OutASC_SwTxtNode( Writer& rWrt, SwCntntNode& rNode )
173 const SwTxtNode& rNd = (SwTxtNode&)rNode;
175 xub_StrLen nStrPos = rWrt.pCurPam->GetPoint()->nContent.GetIndex();
176 xub_StrLen nNodeEnde = rNd.Len(), nEnde = nNodeEnde;
177 BOOL bLastNd = rWrt.pCurPam->GetPoint()->nNode == rWrt.pCurPam->GetMark()->nNode;
178 if( bLastNd )
179 nEnde = rWrt.pCurPam->GetMark()->nContent.GetIndex();
181 SwASC_AttrIter aAttrIter( (SwASCWriter&)rWrt, rNd, nStrPos );
183 if( !nStrPos && rWrt.bExportPargraphNumbering )
184 rWrt.Strm().WriteUnicodeOrByteText( rNd.GetNumString() );
186 String aStr( rNd.GetTxt() );
187 if( rWrt.bASCII_ParaAsBlanc )
188 aStr.SearchAndReplaceAll( 0x0A, ' ' );
190 const bool bExportSoftHyphens = RTL_TEXTENCODING_UCS2 == rWrt.GetAsciiOptions().GetCharSet() ||
191 RTL_TEXTENCODING_UTF8 == rWrt.GetAsciiOptions().GetCharSet();
193 do {
194 xub_StrLen nNextAttr = aAttrIter.WhereNext();
196 if( nNextAttr > nEnde )
197 nNextAttr = nEnde;
199 if( !aAttrIter.OutAttr( nStrPos ))
201 String aOutStr( aStr.Copy( nStrPos, nNextAttr - nStrPos ) );
202 if ( !bExportSoftHyphens )
203 aOutStr.EraseAllChars( CHAR_SOFTHYPHEN );
205 rWrt.Strm().WriteUnicodeOrByteText( aOutStr );
207 nStrPos = nNextAttr;
208 aAttrIter.NextPos();
209 } while( nStrPos < nEnde );
211 if( !bLastNd ||
212 ( !rWrt.bWriteClipboardDoc && !rWrt.bASCII_NoLastLineEnd )
213 && !nStrPos && nEnde == nNodeEnde )
214 rWrt.Strm().WriteUnicodeOrByteText( ((SwASCWriter&)rWrt).GetLineEnd());
216 return rWrt;
220 * lege hier jetzt die Tabellen fuer die ASCII-Funktions-Pointer auf
221 * die Ausgabe-Funktionen an.
222 * Es sind lokale Strukturen, die nur innerhalb der ASCII-DLL
223 * bekannt sein muessen.
226 SwNodeFnTab aASCNodeFnTab = {
227 /* RES_TXTNODE */ OutASC_SwTxtNode,
228 /* RES_GRFNODE */ 0,
229 /* RES_OLENODE */ 0