1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ascatr.cxx,v $
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>
36 #define _SVSTDARR_USHORTS
37 #include <svtools/svstdarr.hxx>
39 #include <svx/fontitem.hxx>
44 #include <txatbase.hxx>
45 #include <fchrfmt.hxx>
49 #include <charfmt.hxx>
52 #include <ftninfo.hxx>
55 * Dieses File enthaelt alle Ausgabe-Funktionen des ASCII-Writers;
56 * fuer alle Nodes, Attribute, Formate und Chars.
65 xub_StrLen
SearchNext( xub_StrLen nStartPos
);
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
,
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();
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();
105 if( nPos
>= nStartPos
&& nPos
<= nMinPos
)
108 if( ( ++nPos
) >= nStartPos
&& nPos
< nMinPos
)
117 BOOL
SwASC_AttrIter::OutAttr( xub_StrLen nSwPos
)
120 const SwpHints
* pTxtAttrs
= rNd
.GetpSwpHints();
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() )
132 switch( pHt
->Which() )
134 case RES_TXTATR_FIELD
:
135 sOut
= ((SwTxtFld
*)pHt
)->GetFld().GetFld()->Expand();
138 case RES_TXTATR_HARDBLANK
:
139 sOut
= ((SwTxtHardBlank
*)pHt
)->GetChar();
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() );
151 sOut
= rWrt
.pDoc
->GetFtnInfo().aFmt
.
152 GetNumStr( rFtn
.GetNumber() );
157 rWrt
.Strm().WriteUnicodeOrByteText( sOut
);
159 else if( nSwPos
< *pHt
->GetStart() )
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
;
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();
194 xub_StrLen nNextAttr
= aAttrIter
.WhereNext();
196 if( 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
);
209 } while( nStrPos
< nEnde
);
212 ( !rWrt
.bWriteClipboardDoc
&& !rWrt
.bASCII_NoLastLineEnd
)
213 && !nStrPos
&& nEnde
== nNodeEnde
)
214 rWrt
.Strm().WriteUnicodeOrByteText( ((SwASCWriter
&)rWrt
).GetLineEnd());
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
,