1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <tools/stream.hxx>
22 #include <comphelper/string.hxx>
23 #include <editeng/fontitem.hxx>
28 #include <txatbase.hxx>
29 #include <fchrfmt.hxx>
33 #include <charfmt.hxx>
36 #include <ftninfo.hxx>
39 * This file contains all output functions of the ASCII-Writer;
40 * For all nodes, attributes, formats and chars.
49 xub_StrLen
SearchNext( xub_StrLen nStartPos
);
52 SwASC_AttrIter( SwASCWriter
& rWrt
, const SwTxtNode
& rNd
, xub_StrLen nStt
);
54 void NextPos() { nAktSwPos
= SearchNext( nAktSwPos
+ 1 ); }
56 xub_StrLen
WhereNext() const { return nAktSwPos
; }
57 bool OutAttr( xub_StrLen nSwPos
);
61 SwASC_AttrIter::SwASC_AttrIter( SwASCWriter
& rWr
, const SwTxtNode
& rTxtNd
,
63 : rWrt( rWr
), rNd( rTxtNd
), nAktSwPos( 0 )
65 nAktSwPos
= SearchNext( nStt
+ 1 );
69 xub_StrLen
SwASC_AttrIter::SearchNext( xub_StrLen nStartPos
)
71 xub_StrLen nMinPos
= STRING_MAXLEN
;
72 const SwpHints
* pTxtAttrs
= rNd
.GetpSwpHints();
75 // TODO: This can be optimized, if we make use of the fact that the TxtAttrs
76 // are sorted by starting position. We would need to remember two indices, however.
77 for ( sal_uInt16 i
= 0; i
< pTxtAttrs
->Count(); i
++ )
79 const SwTxtAttr
* pHt
= (*pTxtAttrs
)[i
];
80 if (pHt
->HasDummyChar())
82 xub_StrLen nPos
= *pHt
->GetStart();
84 if( nPos
>= nStartPos
&& nPos
<= nMinPos
)
87 if( ( ++nPos
) >= nStartPos
&& nPos
< nMinPos
)
96 bool SwASC_AttrIter::OutAttr( xub_StrLen nSwPos
)
99 const SwpHints
* pTxtAttrs
= rNd
.GetpSwpHints();
103 for( i
= 0; i
< pTxtAttrs
->Count(); i
++ )
105 const SwTxtAttr
* pHt
= (*pTxtAttrs
)[i
];
106 if ( pHt
->HasDummyChar() && nSwPos
== *pHt
->GetStart() )
110 switch( pHt
->Which() )
112 case RES_TXTATR_FIELD
:
113 sOut
= static_cast<SwTxtFld
const*>(pHt
)->GetFld().GetFld()
119 const SwFmtFtn
& rFtn
= pHt
->GetFtn();
120 if( rFtn
.GetNumStr().Len() )
121 sOut
= rFtn
.GetNumStr();
122 else if( rFtn
.IsEndNote() )
123 sOut
= rWrt
.pDoc
->GetEndNoteInfo().aFmt
.
124 GetNumStr( rFtn
.GetNumber() );
126 sOut
= rWrt
.pDoc
->GetFtnInfo().aFmt
.
127 GetNumStr( rFtn
.GetNumber() );
132 rWrt
.Strm().WriteUnicodeOrByteText( sOut
);
134 else if( nSwPos
< *pHt
->GetStart() )
142 //------------------------
143 // Output of the node
144 //------------------------
146 static Writer
& OutASC_SwTxtNode( Writer
& rWrt
, SwCntntNode
& rNode
)
148 const SwTxtNode
& rNd
= (SwTxtNode
&)rNode
;
150 xub_StrLen nStrPos
= rWrt
.pCurPam
->GetPoint()->nContent
.GetIndex();
151 xub_StrLen nNodeEnde
= rNd
.Len(), nEnde
= nNodeEnde
;
152 bool bLastNd
= rWrt
.pCurPam
->GetPoint()->nNode
== rWrt
.pCurPam
->GetMark()->nNode
;
154 nEnde
= rWrt
.pCurPam
->GetMark()->nContent
.GetIndex();
156 SwASC_AttrIter
aAttrIter( (SwASCWriter
&)rWrt
, rNd
, nStrPos
);
158 if( !nStrPos
&& rWrt
.bExportPargraphNumbering
)
160 String
numString( rNd
.GetNumString() );
163 numString
.Append(' ');
164 rWrt
.Strm().WriteUnicodeOrByteText(numString
);
168 String
aStr( rNd
.GetTxt() );
169 if( rWrt
.bASCII_ParaAsBlanc
)
170 aStr
.SearchAndReplaceAll( 0x0A, ' ' );
172 const bool bExportSoftHyphens
= RTL_TEXTENCODING_UCS2
== rWrt
.GetAsciiOptions().GetCharSet() ||
173 RTL_TEXTENCODING_UTF8
== rWrt
.GetAsciiOptions().GetCharSet();
176 xub_StrLen nNextAttr
= aAttrIter
.WhereNext();
178 if( nNextAttr
> nEnde
)
181 if( !aAttrIter
.OutAttr( nStrPos
))
183 String
aOutStr( aStr
.Copy( nStrPos
, nNextAttr
- nStrPos
) );
184 if ( !bExportSoftHyphens
)
185 aOutStr
= comphelper::string::remove(aOutStr
, CHAR_SOFTHYPHEN
);
187 rWrt
.Strm().WriteUnicodeOrByteText( aOutStr
);
191 } while( nStrPos
< nEnde
);
194 ( ( !rWrt
.bWriteClipboardDoc
&& !rWrt
.bASCII_NoLastLineEnd
)
195 && !nStrPos
&& nEnde
== nNodeEnde
) )
196 rWrt
.Strm().WriteUnicodeOrByteText( ((SwASCWriter
&)rWrt
).GetLineEnd());
202 * Create the table for the ASCII function pointers to the output
204 * There are local structures that only need to be known to the ASCII DLL.
207 SwNodeFnTab aASCNodeFnTab
= {
208 /* RES_TXTNODE */ OutASC_SwTxtNode
,
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */