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();
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
)
104 if( ( ++nPos
) >= nStartPos
&& nPos
< nMinPos
)
113 BOOL
SwASC_AttrIter::OutAttr( xub_StrLen nSwPos
)
116 const SwpHints
* pTxtAttrs
= rNd
.GetpSwpHints();
120 for( i
= 0; i
< pTxtAttrs
->Count(); i
++ )
122 const SwTxtAttr
* pHt
= (*pTxtAttrs
)[i
];
123 if ( pHt
->HasDummyChar() && nSwPos
== *pHt
->GetStart() )
127 switch( pHt
->Which() )
129 case RES_TXTATR_FIELD
:
130 sOut
= ((SwTxtFld
*)pHt
)->GetFld().GetFld()->Expand();
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() );
142 sOut
= rWrt
.pDoc
->GetFtnInfo().aFmt
.
143 GetNumStr( rFtn
.GetNumber() );
148 rWrt
.Strm().WriteUnicodeOrByteText( sOut
);
150 else if( nSwPos
< *pHt
->GetStart() )
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
;
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();
185 xub_StrLen nNextAttr
= aAttrIter
.WhereNext();
187 if( 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
);
200 } while( nStrPos
< nEnde
);
203 ( !rWrt
.bWriteClipboardDoc
&& !rWrt
.bASCII_NoLastLineEnd
)
204 && !nStrPos
&& nEnde
== nNodeEnde
)
205 rWrt
.Strm().WriteUnicodeOrByteText( ((SwASCWriter
&)rWrt
).GetLineEnd());
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
,