1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #include <vector>
28 #include <list>
29 #include <utility>
30 #include <algorithm>
31 #include <functional>
32 #include <iostream>
33 #if OSL_DEBUG_LEVEL > 0
34 # include <cstdio>
35 #endif
36
37 #include <hintids.hxx>
38 #include <tools/urlobj.hxx>
39 #include <editeng/boxitem.hxx>
40 #include <editeng/cmapitem.hxx>
41 #include <editeng/langitem.hxx>
42 #include <editeng/svxfont.hxx>
43 #include <editeng/lrspitem.hxx>
44 #include <editeng/brshitem.hxx>
45 #include <editeng/fontitem.hxx>
46 #include <editeng/keepitem.hxx>
47 #include <editeng/fhgtitem.hxx>
48 #include <editeng/ulspitem.hxx>
49 #include <editeng/brkitem.hxx>
50 #include <editeng/frmdiritem.hxx>
51 #include <editeng/tstpitem.hxx>
52 #include "svl/urihelper.hxx"
53 #include <svl/whiter.hxx>
54 #include <fmtpdsc.hxx>
55 #include <fmtfsize.hxx>
56 #include <fmtornt.hxx>
57 #include <fmtlsplt.hxx>
58 #include <fmtflcnt.hxx>
59 #include <fmtanchr.hxx>
60 #include <fmtcntnt.hxx>
61 #include <frmatr.hxx>
62 #include <paratr.hxx>
63 #include <txatbase.hxx>
64 #include <fmtinfmt.hxx>
65 #include <fmtrfmrk.hxx>
66 #include <fchrfmt.hxx>
67 #include <fmtautofmt.hxx>
68 #include <charfmt.hxx>
69 #include <tox.hxx>
70 #include <ndtxt.hxx>
71 #include <pam.hxx>
72 #include <doc.hxx>
73 #include <docary.hxx>
74 #include <swtable.hxx>
75 #include <swtblfmt.hxx>
76 #include <section.hxx>
77 #include <pagedesc.hxx>
78 #include <swrect.hxx>
79 #include <reffld.hxx>
80 #include <redline.hxx>
81 #include <wrtswtbl.hxx>
82 #include <htmltbl.hxx>
83 #include <txttxmrk.hxx>
84 #include <fmtline.hxx>
85 #include <fmtruby.hxx>
86 #include <breakit.hxx>
87 #include <txtatr.hxx>
88 #include <fmtsrnd.hxx>
89 #include <fmtrowsplt.hxx>
90 #include <com/sun/star/i18n/ScriptType.hdl>
91 #include <com/sun/star/i18n/WordType.hpp>
92
93 #include <writerfilter/doctok/sprmids.hxx>
94
95 #include "writerhelper.hxx"
96 #include "writerwordglue.hxx"
97 #include <numrule.hxx>
98 #include "wrtww8.hxx"
99 #include "ww8par.hxx"
100 #include <IMark.hxx>
101 #include "ww8attributeoutput.hxx"
102
103 #include <ndgrf.hxx>
104 #include <ndole.hxx>
105
106 #include <cstdio>
107
108 using namespace ::com::sun::star;
109 using namespace ::com::sun::star::i18n;
110 using namespace sw::util;
111 using namespace sw::types;
112 using namespace sw::mark;
113 using namespace nsFieldFlags;
114
115
lcl_getFieldCode(const IFieldmark * pFieldmark)116 static String lcl_getFieldCode( const IFieldmark* pFieldmark ) {
117 ASSERT(pFieldmark!=NULL, "where is my fieldmark???");
118 if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMTEXT ) ) {
119 return String::CreateFromAscii(" FORMTEXT ");
120 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMDROPDOWN ) ) {
121 return String::CreateFromAscii(" FORMDROPDOWN ");
122 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMCHECKBOX ) ) {
123 return String::CreateFromAscii(" FORMCHECKBOX ");
124 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_TOC ) ) {
125 return String::CreateFromAscii(" TOC ");
126 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_HYPERLINK ) ) {
127 return String::CreateFromAscii(" HYPERLINK ");
128 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_PAGEREF ) ) {
129 return String::CreateFromAscii(" PAGEREF ");
130 } else {
131 return pFieldmark->GetFieldname();
132 }
133 }
134
lcl_getFieldId(const IFieldmark * pFieldmark)135 ww::eField lcl_getFieldId( const IFieldmark* pFieldmark ) {
136 ASSERT(pFieldmark!=NULL, "where is my fieldmark???");
137 if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMTEXT ) ) {
138 return ww::eFORMTEXT;
139 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMDROPDOWN ) ) {
140 return ww::eFORMDROPDOWN;
141 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMCHECKBOX ) ) {
142 return ww::eFORMCHECKBOX;
143 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_TOC ) ) {
144 return ww::eTOC;
145 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_HYPERLINK ) ) {
146 return ww::eHYPERLINK;
147 } else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_PAGEREF ) ) {
148 return ww::ePAGEREF;
149 } else {
150 return ww::eUNKNOWN;
151 }
152 }
153
154 /* */
155
MSWordAttrIter(MSWordExportBase & rExport)156 MSWordAttrIter::MSWordAttrIter( MSWordExportBase& rExport )
157 : pOld( rExport.pChpIter ), m_rExport( rExport )
158 {
159 m_rExport.pChpIter = this;
160 }
161
~MSWordAttrIter()162 MSWordAttrIter::~MSWordAttrIter()
163 {
164 m_rExport.pChpIter = pOld;
165 }
166
167 // Die Klasse SwAttrIter ist eine Hilfe zum Aufbauen der Fkp.chpx.
168 // Dabei werden nur Zeichen-Attribute beachtet; Absatz-Attribute brauchen
169 // diese Behandlung nicht.
170 // Die Absatz- und Textattribute des Writers kommen rein, und es wird
171 // mit Where() die naechste Position geliefert, an der sich die Attribute
172 // aendern. IsTxtAtr() sagt, ob sich an der mit Where() gelieferten Position
173 // ein Attribut ohne Ende und mit \xff im Text befindet.
174 // Mit OutAttr() werden die Attribute an der angegebenen SwPos
175 // ausgegeben.
176
177 class WW8SwAttrIter : public MSWordAttrIter
178 {
179 private:
180 const SwTxtNode& rNd;
181
182 CharRuns maCharRuns;
183 cCharRunIter maCharRunIter;
184
185 rtl_TextEncoding meChrSet;
186 sal_uInt16 mnScript;
187 bool mbCharIsRTL;
188
189 const SwRedline* pCurRedline;
190 xub_StrLen nAktSwPos;
191 sal_uInt16 nCurRedlinePos;
192
193 bool mbParaIsRTL;
194
195 const SwFmtDrop &mrSwFmtDrop;
196
197 sw::Frames maFlyFrms; // #i2916#
198 sw::FrameIter maFlyIter;
199
200 xub_StrLen SearchNext( xub_StrLen nStartPos );
201 void FieldVanish( const String& rTxt );
202
203 void OutSwFmtRefMark(const SwFmtRefMark& rAttr, bool bStart);
204
205 void IterToCurrent();
206
207 //No copying
208 WW8SwAttrIter(const WW8SwAttrIter&);
209 WW8SwAttrIter& operator=(const WW8SwAttrIter&);
210 public:
211 WW8SwAttrIter( MSWordExportBase& rWr, const SwTxtNode& rNd );
212
213 bool IsTxtAttr( xub_StrLen nSwPos );
214 bool IsRedlineAtEnd( xub_StrLen nPos ) const;
215 bool IsDropCap( int nSwPos );
216 bool RequiresImplicitBookmark();
217
NextPos()218 void NextPos() { nAktSwPos = SearchNext( nAktSwPos + 1 ); }
219
220 void OutAttr( xub_StrLen nSwPos );
221 virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const;
222 virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const;
223 int OutAttrWithRange(xub_StrLen nPos);
224 const SwRedlineData* GetRedline( xub_StrLen nPos );
225 void OutFlys(xub_StrLen nSwPos);
226
WhereNext() const227 xub_StrLen WhereNext() const { return nAktSwPos; }
GetScript() const228 sal_uInt16 GetScript() const { return mnScript; }
IsCharRTL() const229 bool IsCharRTL() const { return mbCharIsRTL; }
IsParaRTL() const230 bool IsParaRTL() const { return mbParaIsRTL; }
GetCharSet() const231 rtl_TextEncoding GetCharSet() const { return meChrSet; }
232 String GetSnippet(const String &rStr, xub_StrLen nAktPos,
233 xub_StrLen nLen) const;
GetSwFmtDrop() const234 const SwFmtDrop& GetSwFmtDrop() const { return mrSwFmtDrop; }
235 };
236
237 class sortswflys
238 {
239 public:
240 typedef const sw::Frame& first_argument_type;
241 typedef const sw::Frame& second_argument_type;
242 typedef bool result_type;
operator ()(const sw::Frame & rOne,const sw::Frame & rTwo) const243 bool operator()(const sw::Frame &rOne, const sw::Frame &rTwo) const
244 {
245 return rOne.GetPosition() < rTwo.GetPosition();
246 }
247 };
248
IterToCurrent()249 void WW8SwAttrIter::IterToCurrent()
250 {
251 ASSERT(maCharRuns.begin() != maCharRuns.end(), "Impossible");
252 mnScript = maCharRunIter->mnScript;
253 meChrSet = maCharRunIter->meCharSet;
254 mbCharIsRTL = maCharRunIter->mbRTL;
255 }
256
WW8SwAttrIter(MSWordExportBase & rWr,const SwTxtNode & rTxtNd)257 WW8SwAttrIter::WW8SwAttrIter(MSWordExportBase& rWr, const SwTxtNode& rTxtNd) :
258 MSWordAttrIter(rWr),
259 rNd(rTxtNd),
260 maCharRuns(GetPseudoCharRuns(rTxtNd, 0, !rWr.HackIsWW8OrHigher())),
261 pCurRedline(0),
262 nAktSwPos(0),
263 nCurRedlinePos(USHRT_MAX),
264 mrSwFmtDrop(rTxtNd.GetSwAttrSet().GetDrop())
265 {
266
267 SwPosition aPos(rTxtNd);
268 if (FRMDIR_HORI_RIGHT_TOP == rWr.pDoc->GetTextDirection(aPos))
269 mbParaIsRTL = true;
270 else
271 mbParaIsRTL = false;
272
273 maCharRunIter = maCharRuns.begin();
274 IterToCurrent();
275
276 /*
277 #i2916#
278 Get list of any graphics which may be anchored from this paragraph.
279 */
280 maFlyFrms = GetFramesInNode(rWr.maFrames, rNd);
281 std::sort(maFlyFrms.begin(), maFlyFrms.end(), sortswflys());
282
283 /*
284 #i18480#
285 If we are inside a frame then anything anchored inside this frame can
286 only be supported by word anchored inline ("as character"), so force
287 this in the supportable case.
288 */
289 if (rWr.HackIsWW8OrHigher() && rWr.bInWriteEscher)
290 {
291 std::for_each(maFlyFrms.begin(), maFlyFrms.end(),
292 std::mem_fn(&sw::Frame::ForceTreatAsInline));
293 }
294
295 maFlyIter = maFlyFrms.begin();
296
297 if ( m_rExport.pDoc->GetRedlineTbl().Count() )
298 {
299 SwPosition aPosition( rNd, SwIndex( (SwTxtNode*)&rNd ) );
300 pCurRedline = m_rExport.pDoc->GetRedline( aPosition, &nCurRedlinePos );
301 }
302
303 nAktSwPos = SearchNext(1);
304 }
305
lcl_getMinPos(xub_StrLen pos1,xub_StrLen pos2)306 xub_StrLen lcl_getMinPos( xub_StrLen pos1, xub_StrLen pos2 )
307 {
308 xub_StrLen min = STRING_NOTFOUND;
309 if ( pos1 == STRING_NOTFOUND && pos2 != STRING_NOTFOUND )
310 min = pos2;
311 else if ( pos2 == STRING_NOTFOUND && pos1 != STRING_NOTFOUND )
312 min = pos1;
313 else if ( pos2 != STRING_NOTFOUND && pos2 != STRING_NOTFOUND )
314 {
315 if ( pos1 < pos2 )
316 min = pos1;
317 else
318 min = pos2;
319 }
320
321 return min;
322 }
323
SearchNext(xub_StrLen nStartPos)324 xub_StrLen WW8SwAttrIter::SearchNext( xub_StrLen nStartPos )
325 {
326 xub_StrLen nPos;
327 xub_StrLen nMinPos = STRING_MAXLEN;
328 xub_StrLen i=0;
329
330 const String aTxt = rNd.GetTxt();
331 xub_StrLen fieldEndPos = aTxt.Search(CH_TXT_ATR_FIELDEND, nStartPos);
332 xub_StrLen fieldStartPos = aTxt.Search(CH_TXT_ATR_FIELDSTART, nStartPos);
333 xub_StrLen formElementPos = aTxt.Search(CH_TXT_ATR_FORMELEMENT, nStartPos);
334
335 xub_StrLen pos = lcl_getMinPos( fieldEndPos, fieldStartPos );
336 pos = lcl_getMinPos( pos, formElementPos );
337
338 if (pos!=STRING_NOTFOUND)
339 nMinPos=pos;
340
341 // first the redline, then the attributes
342 if( pCurRedline )
343 {
344 const SwPosition* pEnd = pCurRedline->End();
345 if (pEnd->nNode == rNd && ((i = pEnd->nContent.GetIndex()) >= nStartPos) && i < nMinPos )
346 nMinPos = i;
347 }
348
349 if ( nCurRedlinePos < m_rExport.pDoc->GetRedlineTbl().Count() )
350 {
351 // nCurRedlinePos point to the next redline
352 nPos = nCurRedlinePos;
353 if( pCurRedline )
354 ++nPos;
355
356 for ( ; nPos < m_rExport.pDoc->GetRedlineTbl().Count(); ++nPos )
357 {
358 const SwRedline* pRedl = m_rExport.pDoc->GetRedlineTbl()[ nPos ];
359
360 const SwPosition* pStt = pRedl->Start();
361 const SwPosition* pEnd = pStt == pRedl->GetPoint()
362 ? pRedl->GetMark()
363 : pRedl->GetPoint();
364
365 if( pStt->nNode == rNd )
366 {
367 if( ( i = pStt->nContent.GetIndex() ) >= nStartPos &&
368 i < nMinPos )
369 nMinPos = i;
370 }
371 else
372 break;
373
374 if( pEnd->nNode == rNd &&
375 ( i = pEnd->nContent.GetIndex() ) < nMinPos &&
376 i >= nStartPos )
377 nMinPos = i;
378 }
379 }
380
381
382 if (mrSwFmtDrop.GetWholeWord() && nStartPos <= rNd.GetDropLen(0))
383 nMinPos = rNd.GetDropLen(0);
384 else if(nStartPos <= mrSwFmtDrop.GetChars())
385 nMinPos = mrSwFmtDrop.GetChars();
386
387 if(const SwpHints* pTxtAttrs = rNd.GetpSwpHints())
388 {
389
390 // kann noch optimiert werden, wenn ausgenutzt wird, dass die TxtAttrs
391 // nach der Anfangsposition geordnet sind. Dann muessten
392 // allerdings noch 2 Indices gemerkt werden
393 for( i = 0; i < pTxtAttrs->Count(); i++ )
394 {
395 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
396 nPos = *pHt->GetStart(); // gibt erstes Attr-Zeichen
397 if( nPos >= nStartPos && nPos <= nMinPos )
398 nMinPos = nPos;
399
400 if( pHt->End() ) // Attr mit Ende
401 {
402 nPos = *pHt->End(); // gibt letztes Attr-Zeichen + 1
403 if( nPos >= nStartPos && nPos <= nMinPos )
404 nMinPos = nPos;
405 }
406 if (pHt->HasDummyChar())
407 {
408 // pos + 1 because of CH_TXTATR in Text
409 nPos = *pHt->GetStart() + 1;
410 if( nPos >= nStartPos && nPos <= nMinPos )
411 nMinPos = nPos;
412 }
413 }
414 }
415
416 if (maCharRunIter != maCharRuns.end())
417 {
418 if (maCharRunIter->mnEndPos < nMinPos)
419 nMinPos = maCharRunIter->mnEndPos;
420 IterToCurrent();
421 }
422
423 /*
424 #i2916#
425 Check to see if there are any graphics anchored to characters in this
426 paragraph's text. Set nMinPos to 1 past the placement for anchored to
427 character because anchors in Word appear after the character they are
428 anchored to.
429 */
430 if (maFlyIter != maFlyFrms.end())
431 {
432 const SwPosition &rAnchor = maFlyIter->GetPosition();
433
434 nPos = rAnchor.nContent.GetIndex();
435 if (nPos >= nStartPos && nPos <= nMinPos)
436 nMinPos = nPos;
437
438 if (maFlyIter->GetFrmFmt().GetAnchor().GetAnchorId() == FLY_AT_CHAR)
439 {
440 ++nPos;
441 if (nPos >= nStartPos && nPos <= nMinPos)
442 nMinPos = nPos;
443 }
444 }
445
446 //nMinPos found and not going to change at this point
447
448 if (maCharRunIter != maCharRuns.end())
449 {
450 if (maCharRunIter->mnEndPos == nMinPos)
451 ++maCharRunIter;
452 }
453
454 return nMinPos;
455 }
456
OutAttr(xub_StrLen nSwPos)457 void WW8SwAttrIter::OutAttr( xub_StrLen nSwPos )
458 {
459 m_rExport.AttrOutput().RTLAndCJKState( IsCharRTL(), GetScript() );
460
461 /*
462 Depending on whether text is in CTL/CJK or Western, get the id of that
463 script, the idea is that the font that is actually in use to render this
464 range of text ends up in pFont
465 */
466 sal_uInt16 nFontId = GetWhichOfScript( RES_CHRATR_FONT, GetScript() );
467
468 const SvxFontItem &rParentFont = ItemGet<SvxFontItem>(
469 (const SwTxtFmtColl&)rNd.GetAnyFmtColl(), nFontId);
470 const SvxFontItem *pFont = &rParentFont;
471
472 SfxItemSet aExportSet(*rNd.GetSwAttrSet().GetPool(),
473 RES_CHRATR_BEGIN, RES_TXTATR_END - 1);
474
475 //The hard formatting properties that affect the entire paragraph
476 if (rNd.HasSwAttrSet())
477 {
478 sal_Bool bDeep = sal_False;
479 // only copy hard attributes - bDeep = false
480 aExportSet.Set(rNd.GetSwAttrSet(), bDeep);
481 // get the current font item. Use rNd.GetSwAttrSet instead of aExportSet:
482 const SvxFontItem &rNdFont = ItemGet<SvxFontItem>(rNd.GetSwAttrSet(), nFontId);
483 pFont = &rNdFont;
484 aExportSet.ClearItem(nFontId);
485 }
486
487 //The additional hard formatting properties that affect this range in the
488 //paragraph
489 sw::PoolItems aRangeItems;
490 if (const SwpHints* pTxtAttrs = rNd.GetpSwpHints())
491 {
492 for (xub_StrLen i = 0; i < pTxtAttrs->Count(); ++i)
493 {
494 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
495 const xub_StrLen* pEnd = pHt->End();
496
497 if (pEnd ? ( nSwPos >= *pHt->GetStart() && nSwPos < *pEnd)
498 : nSwPos == *pHt->GetStart() )
499 {
500 sal_uInt16 nWhich = pHt->GetAttr().Which();
501 if (nWhich == RES_TXTATR_AUTOFMT)
502 {
503 const SwFmtAutoFmt& rAutoFmt = static_cast<const SwFmtAutoFmt&>(pHt->GetAttr());
504 const boost::shared_ptr<SfxItemSet> pSet = rAutoFmt.GetStyleHandle();
505 SfxWhichIter aIter( *pSet );
506 const SfxPoolItem* pItem;
507 sal_uInt16 nWhichId = aIter.FirstWhich();
508 while( nWhichId )
509 {
510 if( SFX_ITEM_SET == pSet->GetItemState( nWhichId, sal_False, &pItem ))
511 {
512 if (nWhichId == nFontId)
513 pFont = &(item_cast<SvxFontItem>(*pItem));
514 else
515 aRangeItems[nWhichId] = pItem;
516 }
517 nWhichId = aIter.NextWhich();
518 }
519 }
520 else
521 aRangeItems[nWhich] = (&(pHt->GetAttr()));
522 }
523 else if (nSwPos < *pHt->GetStart())
524 break;
525 }
526 }
527
528 /*
529 For #i24291# we need to explicitly remove any properties from the
530 aExportSet which a SwCharFmt would override, we can't rely on word doing
531 this for us like writer does
532 */
533 const SwFmtCharFmt *pCharFmtItem =
534 HasItem< SwFmtCharFmt >( aRangeItems, RES_TXTATR_CHARFMT );
535 if ( pCharFmtItem )
536 ClearOverridesFromSet( *pCharFmtItem, aExportSet );
537
538 sw::PoolItems aExportItems;
539 GetPoolItems( aExportSet, aExportItems, false );
540
541 sw::cPoolItemIter aEnd = aRangeItems.end();
542 for ( sw::cPoolItemIter aI = aRangeItems.begin(); aI != aEnd; ++aI )
543 aExportItems[aI->first] = aI->second;
544
545 if ( !aExportItems.empty() )
546 {
547 const SwModify* pOldMod = m_rExport.pOutFmtNode;
548 m_rExport.pOutFmtNode = &rNd;
549 m_rExport.m_aCurrentCharPropStarts.push( nSwPos );
550
551 m_rExport.ExportPoolItemsToCHP( aExportItems, GetScript() );
552
553 // HasTextItem nur in dem obigen Bereich erlaubt
554 m_rExport.m_aCurrentCharPropStarts.pop();
555 m_rExport.pOutFmtNode = pOldMod;
556 }
557
558 ASSERT( pFont, "must be *some* font associated with this txtnode" );
559 if ( pFont )
560 {
561 SvxFontItem aFont( *pFont );
562
563 /*
564 If we are a nonunicode aware format then we set the charset we want to
565 use for export of this range. If necessary this will generate a pseudo
566 font to use for this range.
567
568 So now we are guaranteed to have a font with the correct charset set
569 for WW6/95 which will match the script we have exported this range in,
570 this makes older nonunicode aware versions of word display the correct
571 characters.
572 */
573 if ( !m_rExport.HackIsWW8OrHigher() )
574 aFont.SetCharSet( GetCharSet() );
575
576 if ( rParentFont != aFont )
577 m_rExport.AttrOutput().OutputItem( aFont );
578 }
579 }
580
OutFlys(xub_StrLen nSwPos)581 void WW8SwAttrIter::OutFlys(xub_StrLen nSwPos)
582 {
583 /*
584 #i2916#
585 May have an anchored graphic to be placed, loop through sorted array
586 and output all at this position
587 */
588 while ( maFlyIter != maFlyFrms.end() )
589 {
590 const SwPosition &rAnchor = maFlyIter->GetPosition();
591 xub_StrLen nPos = rAnchor.nContent.GetIndex();
592
593 if ( nPos != nSwPos )
594 break;
595 else
596 {
597 m_rExport.AttrOutput().OutputFlyFrame( *maFlyIter );
598 ++maFlyIter;
599 }
600 }
601 }
602
IsTxtAttr(xub_StrLen nSwPos)603 bool WW8SwAttrIter::IsTxtAttr( xub_StrLen nSwPos )
604 {
605 // search for attrs with dummy character or content
606 if (const SwpHints* pTxtAttrs = rNd.GetpSwpHints())
607 {
608 for (sal_uInt16 i = 0; i < pTxtAttrs->Count(); ++i)
609 {
610 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
611 if ( ( pHt->HasDummyChar() || pHt->HasContent() )
612 && (*pHt->GetStart() == nSwPos) )
613 {
614 return true;
615 }
616 }
617 }
618
619 return false;
620 }
621
IsDropCap(int nSwPos)622 bool WW8SwAttrIter::IsDropCap( int nSwPos )
623 {
624 // see if the current position falls on a DropCap
625 int nDropChars = mrSwFmtDrop.GetChars();
626 bool bWholeWord = mrSwFmtDrop.GetWholeWord();
627 if (bWholeWord)
628 {
629 short nWordLen = rNd.GetDropLen(0);
630 if(nSwPos == nWordLen && nSwPos != 0)
631 return true;
632 }
633 else
634 {
635 if (nSwPos == nDropChars && nSwPos != 0)
636 return true;
637 }
638 return false;
639 }
640
RequiresImplicitBookmark()641 bool WW8SwAttrIter::RequiresImplicitBookmark()
642 {
643 SwImplBookmarksIter bkmkIterEnd = m_rExport.maImplicitBookmarks.end();
644 for ( SwImplBookmarksIter aIter = m_rExport.maImplicitBookmarks.begin(); aIter != bkmkIterEnd; ++aIter )
645 {
646 sal_uLong sample = aIter->second;
647
648 if ( sample == rNd.GetIndex() )
649 return true;
650 }
651 return false;
652 }
653
654 // HasItem ist fuer die Zusammenfassung des Doppel-Attributes Underline
655 // und WordLineMode als TextItems. OutAttr() ruft die Ausgabefunktion,
656 // die dann ueber HasItem() nach anderen Items an der
657 // Attribut-Anfangposition fragen kann.
658 // Es koennen nur Attribute mit Ende abgefragt werden.
659 // Es wird mit bDeep gesucht
HasTextItem(sal_uInt16 nWhich) const660 const SfxPoolItem* WW8SwAttrIter::HasTextItem( sal_uInt16 nWhich ) const
661 {
662 const SfxPoolItem* pRet = 0;
663 const SwpHints* pTxtAttrs = rNd.GetpSwpHints();
664 if (pTxtAttrs)
665 {
666 xub_StrLen nTmpSwPos = m_rExport.m_aCurrentCharPropStarts.size() ?
667 m_rExport.m_aCurrentCharPropStarts.top() : 0;
668 for (sal_uInt16 i = 0; i < pTxtAttrs->Count(); ++i)
669 {
670 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
671 const SfxPoolItem* pItem = &pHt->GetAttr();
672 const xub_StrLen* pAtrEnd = 0;
673 if( 0 != ( pAtrEnd = pHt->End() ) && // nur Attr mit Ende
674 nWhich == pItem->Which() && //
675 nTmpSwPos >= *pHt->GetStart() && nTmpSwPos < *pAtrEnd )
676 {
677 pRet = pItem; // gefunden
678 break;
679 }
680 else if (nTmpSwPos < *pHt->GetStart())
681 break; // dann kommt da nichts mehr
682 }
683 }
684 return pRet;
685 }
686
GetCurrentItems(WW8Bytes & rItems) const687 void WW8Export::GetCurrentItems(WW8Bytes& rItems) const
688 {
689 sal_uInt16 nEnd = pO ? pO->Count() : 0;
690 for (sal_uInt16 nI = 0; nI < nEnd; ++nI)
691 rItems.Insert((*pO)[nI], rItems.Count());
692 }
693
GetItem(sal_uInt16 nWhich) const694 const SfxPoolItem& WW8SwAttrIter::GetItem(sal_uInt16 nWhich) const
695 {
696 const SfxPoolItem* pRet = HasTextItem(nWhich);
697 return pRet ? *pRet : rNd.SwCntntNode::GetAttr(nWhich);
698 }
699
StartRuby(const SwTxtNode & rNode,const SwFmtRuby & rRuby)700 void WW8AttributeOutput::StartRuby( const SwTxtNode& rNode, const SwFmtRuby& rRuby )
701 {
702 String aStr( FieldString( ww::eEQ ) );
703 aStr.APPEND_CONST_ASC( "\\* jc" );
704 sal_Int32 nJC = 0;
705 sal_Char cDirective = 0;
706 switch ( rRuby.GetAdjustment() )
707 {
708 case 0:
709 nJC = 3;
710 cDirective = 'l';
711 break;
712 case 1:
713 //defaults to 0
714 break;
715 case 2:
716 nJC = 4;
717 cDirective = 'r';
718 break;
719 case 3:
720 nJC = 1;
721 cDirective = 'd';
722 break;
723 case 4:
724 nJC = 2;
725 cDirective = 'd';
726 break;
727 default:
728 ASSERT( sal_False,"Unhandled Ruby justication code" );
729 break;
730 }
731 aStr += String::CreateFromInt32( nJC );
732
733 /*
734 MS needs to know the name and size of the font used in the ruby item,
735 but we could have written it in a mixture of asian and western
736 scripts, and each of these can be a different font and size than the
737 other, so we make a guess based upon the first character of the text,
738 defaulting to asian.
739 */
740 sal_uInt16 nRubyScript;
741 if( pBreakIt->GetBreakIter().is() )
742 nRubyScript = pBreakIt->GetBreakIter()->getScriptType( rRuby.GetText(), 0);
743 else
744 nRubyScript = i18n::ScriptType::ASIAN;
745
746 const SwTxtRuby* pRubyTxt = rRuby.GetTxtRuby();
747 const SwCharFmt* pFmt = pRubyTxt ? pRubyTxt->GetCharFmt() : 0;
748 String sFamilyName;
749 long nHeight;
750 if ( pFmt )
751 {
752 const SvxFontItem &rFont = ItemGet< SvxFontItem >( *pFmt,
753 GetWhichOfScript(RES_CHRATR_FONT,nRubyScript) );
754 sFamilyName = rFont.GetFamilyName();
755
756 const SvxFontHeightItem &rHeight = ItemGet< SvxFontHeightItem >( *pFmt,
757 GetWhichOfScript( RES_CHRATR_FONTSIZE, nRubyScript ) );
758 nHeight = rHeight.GetHeight();
759 }
760 else
761 {
762 /*Get defaults if no formatting on ruby text*/
763
764 const SfxItemPool *pPool = rNode.GetSwAttrSet().GetPool();
765 const SfxItemPool &rPool = pPool ? *pPool : m_rWW8Export.pDoc->GetAttrPool();
766
767 const SvxFontItem &rFont = DefaultItemGet< SvxFontItem >( rPool,
768 GetWhichOfScript( RES_CHRATR_FONT,nRubyScript ) );
769 sFamilyName = rFont.GetFamilyName();
770
771 const SvxFontHeightItem &rHeight = DefaultItemGet< SvxFontHeightItem >
772 ( rPool, GetWhichOfScript( RES_CHRATR_FONTSIZE, nRubyScript ) );
773 nHeight = rHeight.GetHeight();
774 }
775 nHeight = (nHeight + 5)/10;
776
777 aStr.APPEND_CONST_ASC( " \\* \"Font:" );
778 aStr.Append( sFamilyName );
779 aStr.APPEND_CONST_ASC( "\" \\* hps" );
780 aStr += String::CreateFromInt32( nHeight );
781 aStr.APPEND_CONST_ASC( " \\o" );
782 if ( cDirective )
783 {
784 aStr.APPEND_CONST_ASC( "\\a" );
785 aStr.Append( cDirective );
786 }
787 aStr.APPEND_CONST_ASC( "(\\s\\up " );
788
789
790 if ( pBreakIt->GetBreakIter().is() )
791 nRubyScript = pBreakIt->GetBreakIter()->getScriptType( rNode.GetTxt(),
792 *( pRubyTxt->GetStart() ) );
793 else
794 nRubyScript = i18n::ScriptType::ASIAN;
795
796 const SwAttrSet& rSet = rNode.GetSwAttrSet();
797 const SvxFontHeightItem &rHeightItem =
798 ( const SvxFontHeightItem& )rSet.Get(
799 GetWhichOfScript( RES_CHRATR_FONTSIZE, nRubyScript ) );
800 nHeight = (rHeightItem.GetHeight() + 10)/20-1;
801 aStr += String::CreateFromInt32(nHeight);
802 aStr += '(';
803 aStr += rRuby.GetText();
804 aStr.APPEND_CONST_ASC( ");" );
805 m_rWW8Export.OutputField( 0, ww::eEQ, aStr,
806 WRITEFIELD_START | WRITEFIELD_CMD_START );
807 }
808
EndRuby()809 void WW8AttributeOutput::EndRuby()
810 {
811 m_rWW8Export.WriteChar( ')' );
812 m_rWW8Export.OutputField( 0, ww::eEQ, aEmptyStr, WRITEFIELD_END | WRITEFIELD_CLOSE );
813 }
814
815 /*#i15387# Better ideas welcome*/
TruncateBookmark(String & rRet)816 String &TruncateBookmark( String &rRet )
817 {
818 if ( rRet.Len() > 40 )
819 rRet.Erase( 40 );
820 ASSERT( rRet.Len() <= 40, "Word cannot have bookmarks longer than 40 chars" );
821 return rRet;
822 }
823
AnalyzeURL(const String & rUrl,const String &,String * pLinkURL,String * pMark)824 bool AttributeOutputBase::AnalyzeURL( const String& rUrl, const String& /*rTarget*/, String* pLinkURL, String* pMark )
825 {
826 bool bBookMarkOnly = false;
827
828 INetURLObject aURL( rUrl );
829 String sMark;
830 String sURL;
831
832 if ( rUrl.Len() > 1 && rUrl.GetChar(0) == INET_MARK_TOKEN )
833 {
834 sMark = BookmarkToWriter( rUrl.Copy(1) );
835
836 xub_StrLen nPos = sMark.SearchBackward( cMarkSeperator );
837
838 String sRefType( sMark.Copy( nPos+1 ) );
839 sRefType.EraseAllChars();
840
841 // i21465 Only interested in outline references
842 if ( sRefType.EqualsAscii( pMarkToOutline ) )
843 {
844 String sLink = sMark.Copy(0, nPos);
845 SwImplBookmarksIter bkmkIterEnd = GetExport().maImplicitBookmarks.end();
846 for ( SwImplBookmarksIter aIter = GetExport().maImplicitBookmarks.begin(); aIter != bkmkIterEnd; ++aIter )
847 {
848 String bkmkName = aIter->first;
849
850 if ( bkmkName == sLink )
851 {
852 sMark = String( RTL_CONSTASCII_STRINGPARAM( "_toc" ) );
853 sMark += String::CreateFromInt32( aIter->second );
854 }
855 }
856 }
857 }
858 else
859 {
860 sURL = aURL.GetURLNoMark( INetURLObject::DECODE_UNAMBIGUOUS );
861 sMark = aURL.GetMark( INetURLObject::DECODE_UNAMBIGUOUS );
862
863 }
864
865 if ( sMark.Len() && !sURL.Len() )
866 bBookMarkOnly = true;
867
868
869
870 *pMark = sMark;
871 *pLinkURL = sURL;
872 return bBookMarkOnly;
873 }
874
AnalyzeURL(const String & rUrl,const String & rTarget,String * pLinkURL,String * pMark)875 bool WW8AttributeOutput::AnalyzeURL( const String& rUrl, const String& rTarget, String* pLinkURL, String* pMark )
876 {
877 bool bBookMarkOnly = AttributeOutputBase::AnalyzeURL( rUrl, rTarget, pLinkURL, pMark );
878
879 String sURL = *pLinkURL;
880 String sMark = *pMark;
881
882 if ( sURL.Len() )
883 sURL = URIHelper::simpleNormalizedMakeRelative( m_rWW8Export.GetWriter().GetBaseURL(), sURL );
884
885 if ( bBookMarkOnly )
886 sURL = FieldString( ww::eHYPERLINK );
887 else
888 {
889 String sFld( FieldString( ww::eHYPERLINK ) );
890 sFld.APPEND_CONST_ASC( "\"" );
891 sURL.Insert( sFld, 0 );
892 sURL += '\"';
893 }
894
895 if ( sMark.Len() )
896 ( ( sURL.APPEND_CONST_ASC( " \\l \"" ) ) += sMark ) += '\"';
897
898 if ( rTarget.Len() )
899 ( sURL.APPEND_CONST_ASC( " \\n " ) ) += rTarget;
900
901 *pLinkURL = sURL;
902 *pMark = sMark;
903
904 return bBookMarkOnly;
905 }
906
StartURL(const String & rUrl,const String & rTarget)907 bool WW8AttributeOutput::StartURL( const String &rUrl, const String &rTarget )
908 {
909 // hyperlinks only in WW8
910 if ( !m_rWW8Export.bWrtWW8 )
911 return false;
912
913 INetURLObject aURL( rUrl );
914 String sURL;
915 String sMark;
916
917 bool bBookMarkOnly = AnalyzeURL( rUrl, rTarget, &sURL, &sMark );
918
919
920 m_rWW8Export.OutputField( 0, ww::eHYPERLINK, sURL, WRITEFIELD_START | WRITEFIELD_CMD_START );
921
922 // write the refence to the "picture" structure
923 sal_uLong nDataStt = m_rWW8Export.pDataStrm->Tell();
924 m_rWW8Export.pChpPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell() );
925
926 // WinWord 2000 doesn't write this - so its a temp solution by W97 ?
927 m_rWW8Export.WriteChar( 0x01 );
928
929 static sal_uInt8 aArr1[] = {
930 0x03, 0x6a, 0,0,0,0, // sprmCPicLocation
931
932 0x06, 0x08, 0x01, // sprmCFData
933 0x55, 0x08, 0x01, // sprmCFSpec
934 0x02, 0x08, 0x01 // sprmCFFldVanish
935 };
936 sal_uInt8* pDataAdr = aArr1 + 2;
937 Set_UInt32( pDataAdr, nDataStt );
938
939 m_rWW8Export.pChpPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), sizeof( aArr1 ), aArr1 );
940
941 m_rWW8Export.OutputField( 0, ww::eHYPERLINK, sURL, WRITEFIELD_CMD_END );
942
943 // now write the picture structur
944 sURL = aURL.GetURLNoMark();
945
946 //all links end up in the data stream as absolute references.
947 bool bAbsolute = !bBookMarkOnly;
948
949 static sal_uInt8 __READONLY_DATA aURLData1[] = {
950 0,0,0,0, // len of struct
951 0x44,0, // the start of "next" data
952 0,0,0,0,0,0,0,0,0,0, // PIC-Structure!
953 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // |
954 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // |
955 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // |
956 0,0,0,0, // /
957 };
958 static sal_uInt8 __READONLY_DATA MAGIC_A[] = {
959 // start of "next" data
960 0xD0,0xC9,0xEA,0x79,0xF9,0xBA,0xCE,0x11,
961 0x8C,0x82,0x00,0xAA,0x00,0x4B,0xA9,0x0B
962 };
963
964 m_rWW8Export.pDataStrm->Write( aURLData1, sizeof( aURLData1 ) );
965 sal_uInt8 nAnchor = 0x00;
966 if ( sMark.Len() )
967 nAnchor = 0x08;
968 m_rWW8Export.pDataStrm->Write( &nAnchor, 1 );
969 m_rWW8Export.pDataStrm->Write( MAGIC_A, sizeof(MAGIC_A) );
970 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 0x00000002);
971 sal_uInt32 nFlag = bBookMarkOnly ? 0 : 0x01;
972 if ( bAbsolute )
973 nFlag |= 0x02;
974 if ( sMark.Len() )
975 nFlag |= 0x08;
976 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, nFlag );
977
978 INetProtocol eProto = aURL.GetProtocol();
979 if ( eProto == INET_PROT_FILE )
980 {
981 // version 1 (for a document)
982
983 static sal_uInt8 __READONLY_DATA MAGIC_C[] = {
984 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
985 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
986 0x00, 0x00
987 };
988
989 static sal_uInt8 __READONLY_DATA MAGIC_D[] = {
990 0xFF, 0xFF, 0xAD, 0xDE, 0x00, 0x00, 0x00, 0x00,
991 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
992 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
993 };
994
995 // save the links to files as relative
996 sURL = URIHelper::simpleNormalizedMakeRelative( m_rWW8Export.GetWriter().GetBaseURL(), sURL );
997 if ( sURL.EqualsAscii( "/", 0, 1 ) )
998 sURL = aURL.PathToFileName();
999
1000 // special case for the absolute windows names
1001 // (convert '/c:/foo/bar.doc' into 'c:\foo\bar.doc')
1002 sal_Unicode aDrive = ( sURL.Len() > 1 )? sURL.GetChar( 1 ): 0;
1003 if ( sURL.EqualsAscii( "/", 0, 1 ) &&
1004 ( ( aDrive >= 'A' && aDrive <= 'Z' ) || ( aDrive >= 'a' && aDrive <= 'z' ) ) &&
1005 sURL.EqualsAscii( ":", 2, 1 ) )
1006 {
1007 sURL.Erase( 0, 1 );
1008 sURL.SearchAndReplaceAll( '/', '\\' );
1009 }
1010
1011 m_rWW8Export.pDataStrm->Write( MAGIC_C, sizeof(MAGIC_C) );
1012 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, sURL.Len()+1 );
1013 SwWW8Writer::WriteString8( *m_rWW8Export.pDataStrm, sURL, true,
1014 RTL_TEXTENCODING_MS_1252 );
1015 m_rWW8Export.pDataStrm->Write( MAGIC_D, sizeof( MAGIC_D ) );
1016
1017 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2*sURL.Len() + 6 );
1018 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2*sURL.Len() );
1019 SwWW8Writer::WriteShort( *m_rWW8Export.pDataStrm, 3 );
1020 SwWW8Writer::WriteString16( *m_rWW8Export.pDataStrm, sURL, false );
1021 }
1022 else if ( eProto != INET_PROT_NOT_VALID )
1023 {
1024 // version 2 (simple url)
1025 // an write some data to the data stream, but dont ask
1026 // what the data mean, except for the URL.
1027 // The First piece is the WW8_PIC structure.
1028 //
1029 static sal_uInt8 __READONLY_DATA MAGIC_B[] = {
1030 0xE0,0xC9,0xEA,0x79,0xF9,0xBA,0xCE,0x11,
1031 0x8C,0x82,0x00,0xAA,0x00,0x4B,0xA9,0x0B
1032 };
1033
1034 m_rWW8Export.pDataStrm->Write( MAGIC_B, sizeof(MAGIC_B) );
1035 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2 * ( sURL.Len() + 1 ) );
1036 SwWW8Writer::WriteString16( *m_rWW8Export.pDataStrm, sURL, true );
1037 }
1038
1039 if ( sMark.Len() )
1040 {
1041 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, sMark.Len()+1 );
1042 SwWW8Writer::WriteString16( *m_rWW8Export.pDataStrm, sMark, true );
1043 }
1044 SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, nDataStt,
1045 m_rWW8Export.pDataStrm->Tell() - nDataStt );
1046
1047 return true;
1048 }
1049
EndURL()1050 bool WW8AttributeOutput::EndURL()
1051 {
1052 // hyperlinks only in WW8
1053 if ( !m_rWW8Export.bWrtWW8 )
1054 return false;
1055
1056 m_rWW8Export.OutputField( 0, ww::eHYPERLINK, aEmptyStr, WRITEFIELD_CLOSE );
1057
1058 return true;
1059 }
1060
BookmarkToWord(const String & rBookmark)1061 String BookmarkToWord(const String &rBookmark)
1062 {
1063 String sRet(INetURLObject::encode(rBookmark,
1064 INetURLObject::PART_REL_SEGMENT_EXTRA, '%',
1065 INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_ASCII_US));
1066 return TruncateBookmark(sRet);
1067 }
1068
BookmarkToWriter(const String & rBookmark)1069 String BookmarkToWriter(const String &rBookmark)
1070 {
1071 return INetURLObject::decode(rBookmark, '%',
1072 INetURLObject::DECODE_UNAMBIGUOUS, RTL_TEXTENCODING_ASCII_US);
1073 }
1074
OutSwFmtRefMark(const SwFmtRefMark & rAttr,bool)1075 void WW8SwAttrIter::OutSwFmtRefMark(const SwFmtRefMark& rAttr, bool)
1076 {
1077 if ( m_rExport.HasRefToObject( REF_SETREFATTR, &rAttr.GetRefName(), 0 ) )
1078 m_rExport.AppendBookmark( m_rExport.GetBookmarkName( REF_SETREFATTR,
1079 &rAttr.GetRefName(), 0 ));
1080 }
1081
FieldVanish(const String & rTxt,ww::eField)1082 void WW8AttributeOutput::FieldVanish( const String& rTxt, ww::eField /*eType*/ )
1083 {
1084 WW8Bytes aItems;
1085 m_rWW8Export.GetCurrentItems( aItems );
1086
1087 // sprmCFFldVanish
1088 if ( m_rWW8Export.bWrtWW8 )
1089 SwWW8Writer::InsUInt16( aItems, NS_sprm::LN_CFFldVanish );
1090 else
1091 aItems.Insert( 67, aItems.Count() );
1092 aItems.Insert( 1, aItems.Count() );
1093
1094 sal_uInt16 nStt_sprmCFSpec = aItems.Count();
1095
1096 // sprmCFSpec -- fSpec-Attribut true
1097 if ( m_rWW8Export.bWrtWW8 )
1098 SwWW8Writer::InsUInt16( aItems, 0x855 );
1099 else
1100 aItems.Insert( 117, aItems.Count() );
1101 aItems.Insert( 1, aItems.Count() );
1102
1103 m_rWW8Export.WriteChar( '\x13' );
1104 m_rWW8Export.pChpPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), aItems.Count(),
1105 aItems.GetData() );
1106 m_rWW8Export.OutSwString( rTxt, 0, rTxt.Len(), m_rWW8Export.IsUnicode(),
1107 RTL_TEXTENCODING_MS_1252 );
1108 m_rWW8Export.pChpPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), nStt_sprmCFSpec,
1109 aItems.GetData() );
1110 m_rWW8Export.WriteChar( '\x15' );
1111 m_rWW8Export.pChpPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), aItems.Count(),
1112 aItems.GetData() );
1113 }
1114
TOXMark(const SwTxtNode & rNode,const SwTOXMark & rAttr)1115 void AttributeOutputBase::TOXMark( const SwTxtNode& rNode, const SwTOXMark& rAttr )
1116 {
1117 // its a field; so get the Text form the Node and build the field
1118 String sTxt;
1119 ww::eField eType = ww::eNONE;
1120
1121 const SwTxtTOXMark& rTxtTOXMark = *rAttr.GetTxtTOXMark();
1122 const xub_StrLen* pTxtEnd = rTxtTOXMark.End();
1123 if ( pTxtEnd ) // has range?
1124 {
1125 sTxt = rNode.GetExpandTxt( *rTxtTOXMark.GetStart(),
1126 *pTxtEnd - *rTxtTOXMark.GetStart() );
1127 }
1128 else
1129 sTxt = rAttr.GetAlternativeText();
1130
1131 switch ( rAttr.GetTOXType()->GetType() )
1132 {
1133 case TOX_INDEX:
1134 eType = ww::eXE;
1135 if ( rAttr.GetPrimaryKey().Len() )
1136 {
1137 if ( rAttr.GetSecondaryKey().Len() )
1138 {
1139 sTxt.Insert( ':', 0 );
1140 sTxt.Insert( rAttr.GetSecondaryKey(), 0 );
1141 }
1142
1143 sTxt.Insert( ':', 0 );
1144 sTxt.Insert( rAttr.GetPrimaryKey(), 0 );
1145 }
1146 sTxt.InsertAscii( " XE \"", 0 );
1147 sTxt.InsertAscii( "\" " );
1148 break;
1149
1150 case TOX_USER:
1151 ( sTxt.APPEND_CONST_ASC( "\" \\f \"" ) )
1152 += (sal_Char)( 'A' + GetExport( ).GetId( *rAttr.GetTOXType() ) );
1153 // fall through - no break;
1154 case TOX_CONTENT:
1155 {
1156 eType = ww::eTC;
1157 sTxt.InsertAscii( " TC \"", 0 );
1158 sal_uInt16 nLvl = rAttr.GetLevel();
1159 if (nLvl > WW8ListManager::nMaxLevel)
1160 nLvl = WW8ListManager::nMaxLevel;
1161
1162 ((sTxt.APPEND_CONST_ASC( "\" \\l " ))
1163 += String::CreateFromInt32( nLvl )) += ' ';
1164 }
1165 break;
1166 default:
1167 ASSERT( sal_False, "Unhandled option for toc export" );
1168 break;
1169 }
1170
1171 if ( sTxt.Len() )
1172 FieldVanish( sTxt, eType );
1173 }
1174
OutAttrWithRange(xub_StrLen nPos)1175 int WW8SwAttrIter::OutAttrWithRange(xub_StrLen nPos)
1176 {
1177 int nRet = 0;
1178 if ( const SwpHints* pTxtAttrs = rNd.GetpSwpHints() )
1179 {
1180 m_rExport.m_aCurrentCharPropStarts.push( nPos );
1181 const xub_StrLen* pEnd;
1182 for ( sal_uInt16 i = 0; i < pTxtAttrs->Count(); ++i )
1183 {
1184 const SwTxtAttr* pHt = (*pTxtAttrs)[i];
1185 const SfxPoolItem* pItem = &pHt->GetAttr();
1186 switch ( pItem->Which() )
1187 {
1188 case RES_TXTATR_INETFMT:
1189 if ( nPos == *pHt->GetStart() )
1190 {
1191 const SwFmtINetFmt *rINet = static_cast< const SwFmtINetFmt* >( pItem );
1192 if ( m_rExport.AttrOutput().StartURL( rINet->GetValue(), rINet->GetTargetFrame() ) )
1193 ++nRet;
1194 }
1195 if ( 0 != ( pEnd = pHt->End() ) && nPos == *pEnd )
1196 {
1197 if ( m_rExport.AttrOutput().EndURL() )
1198 --nRet;
1199 }
1200 break;
1201 case RES_TXTATR_REFMARK:
1202 if ( nPos == *pHt->GetStart() )
1203 {
1204 OutSwFmtRefMark( *static_cast< const SwFmtRefMark* >( pItem ), true );
1205 ++nRet;
1206 }
1207 if ( 0 != ( pEnd = pHt->End() ) && nPos == *pEnd )
1208 {
1209 OutSwFmtRefMark( *static_cast< const SwFmtRefMark* >( pItem ), false );
1210 --nRet;
1211 }
1212 break;
1213 case RES_TXTATR_TOXMARK:
1214 if ( nPos == *pHt->GetStart() )
1215 m_rExport.AttrOutput().TOXMark( rNd, *static_cast< const SwTOXMark* >( pItem ) );
1216 break;
1217 case RES_TXTATR_CJK_RUBY:
1218 if ( nPos == *pHt->GetStart() )
1219 {
1220 m_rExport.AttrOutput().StartRuby( rNd, *static_cast< const SwFmtRuby* >( pItem ) );
1221 ++nRet;
1222 }
1223 if ( 0 != ( pEnd = pHt->End() ) && nPos == *pEnd )
1224 {
1225 m_rExport.AttrOutput().EndRuby();
1226 --nRet;
1227 }
1228 break;
1229 }
1230 }
1231 m_rExport.m_aCurrentCharPropStarts.pop(); // HasTextItem nur in dem obigen Bereich erlaubt
1232 }
1233 return nRet;
1234 }
1235
IsRedlineAtEnd(xub_StrLen nEnd) const1236 bool WW8SwAttrIter::IsRedlineAtEnd( xub_StrLen nEnd ) const
1237 {
1238 bool bRet = false;
1239 // search next Redline
1240 for( sal_uInt16 nPos = nCurRedlinePos;
1241 nPos < m_rExport.pDoc->GetRedlineTbl().Count(); ++nPos )
1242 {
1243 const SwPosition* pEnd = m_rExport.pDoc->GetRedlineTbl()[ nPos ]->End();
1244 if( pEnd->nNode == rNd )
1245 {
1246 if( pEnd->nContent.GetIndex() == nEnd )
1247 {
1248 bRet = true;
1249 break;
1250 }
1251 }
1252 else
1253 break;
1254 }
1255 return bRet;
1256 }
1257
GetRedline(xub_StrLen nPos)1258 const SwRedlineData* WW8SwAttrIter::GetRedline( xub_StrLen nPos )
1259 {
1260 if( pCurRedline )
1261 {
1262 const SwPosition* pEnd = pCurRedline->End();
1263 if( pEnd->nNode == rNd &&
1264 pEnd->nContent.GetIndex() <= nPos )
1265 {
1266 pCurRedline = 0;
1267 ++nCurRedlinePos;
1268 }
1269 else
1270 {
1271 // write data of current redline
1272 return &( pCurRedline->GetRedlineData() );
1273 }
1274 }
1275
1276 if( !pCurRedline )
1277 {
1278 // search next Redline
1279 for( ; nCurRedlinePos < m_rExport.pDoc->GetRedlineTbl().Count();
1280 ++nCurRedlinePos )
1281 {
1282 const SwRedline* pRedl = m_rExport.pDoc->GetRedlineTbl()[ nCurRedlinePos ];
1283
1284 const SwPosition* pStt = pRedl->Start();
1285 const SwPosition* pEnd = pStt == pRedl->GetPoint()
1286 ? pRedl->GetMark()
1287 : pRedl->GetPoint();
1288
1289 if( pStt->nNode == rNd )
1290 {
1291 if( pStt->nContent.GetIndex() >= nPos )
1292 {
1293 if( pStt->nContent.GetIndex() == nPos )
1294 {
1295 // write data of this redline
1296 pCurRedline = pRedl;
1297 return &( pCurRedline->GetRedlineData() );
1298 }
1299 break;
1300 }
1301 }
1302 else
1303 break;
1304
1305 if( pEnd->nNode == rNd &&
1306 pEnd->nContent.GetIndex() < nPos )
1307 {
1308 pCurRedline = pRedl;
1309 break;
1310 }
1311 }
1312 }
1313 return NULL;
1314 }
1315
1316 /* */
1317
GetCurrentPageDirection() const1318 short MSWordExportBase::GetCurrentPageDirection() const
1319 {
1320 const SwFrmFmt &rFmt = pAktPageDesc
1321 ? pAktPageDesc->GetMaster()
1322 : const_cast<const SwDoc *>( pDoc )->GetPageDesc( 0 ).GetMaster();
1323 return rFmt.GetFrmDir().GetValue();
1324 }
1325
GetDefaultFrameDirection() const1326 short MSWordExportBase::GetDefaultFrameDirection( ) const
1327 {
1328 short nDir = FRMDIR_ENVIRONMENT;
1329
1330 if ( bOutPageDescs )
1331 nDir = GetCurrentPageDirection( );
1332 else if ( pOutFmtNode )
1333 {
1334 if ( bOutFlyFrmAttrs ) //frame
1335 {
1336 nDir = TrueFrameDirection( *( const SwFrmFmt * ) pOutFmtNode );
1337 }
1338 else if ( pOutFmtNode->ISA( SwCntntNode ) ) //paragraph
1339 {
1340 const SwCntntNode *pNd = ( const SwCntntNode * ) pOutFmtNode;
1341 SwPosition aPos( *pNd );
1342 nDir = pDoc->GetTextDirection( aPos );
1343 }
1344 else if ( pOutFmtNode->ISA( SwTxtFmtColl ) )
1345 nDir = FRMDIR_HORI_LEFT_TOP; //what else can we do :-(
1346 }
1347
1348 if ( nDir == FRMDIR_ENVIRONMENT )
1349 nDir = FRMDIR_HORI_LEFT_TOP; //Set something
1350
1351 return nDir;
1352 }
1353
TrueFrameDirection(const SwFrmFmt & rFlyFmt) const1354 short MSWordExportBase::TrueFrameDirection( const SwFrmFmt &rFlyFmt ) const
1355 {
1356 const SwFrmFmt *pFlyFmt = &rFlyFmt;
1357 const SvxFrameDirectionItem* pItem = 0;
1358 while ( pFlyFmt )
1359 {
1360 pItem = &pFlyFmt->GetFrmDir();
1361 if ( FRMDIR_ENVIRONMENT == pItem->GetValue() )
1362 {
1363 pItem = 0;
1364 const SwFmtAnchor* pAnchor = &pFlyFmt->GetAnchor();
1365 if ((FLY_AT_PAGE != pAnchor->GetAnchorId()) &&
1366 pAnchor->GetCntntAnchor() )
1367 {
1368 pFlyFmt = pAnchor->GetCntntAnchor()->nNode.GetNode().GetFlyFmt();
1369 }
1370 else
1371 pFlyFmt = 0;
1372 }
1373 else
1374 pFlyFmt = 0;
1375 }
1376
1377 short nRet;
1378 if ( pItem )
1379 nRet = pItem->GetValue();
1380 else
1381 nRet = GetCurrentPageDirection();
1382
1383 ASSERT( nRet != FRMDIR_ENVIRONMENT, "leaving with environment direction" );
1384 return nRet;
1385 }
1386
GetCurrentPageBgBrush() const1387 const SvxBrushItem* WW8Export::GetCurrentPageBgBrush() const
1388 {
1389 const SwFrmFmt &rFmt = pAktPageDesc
1390 ? pAktPageDesc->GetMaster()
1391 : const_cast<const SwDoc *>(pDoc)->GetPageDesc(0).GetMaster();
1392
1393 const SfxPoolItem* pItem = 0;
1394 //If not set, or "no fill", get real bg
1395 SfxItemState eState = rFmt.GetItemState(RES_BACKGROUND, true, &pItem);
1396
1397 const SvxBrushItem* pRet = (const SvxBrushItem*)pItem;
1398 if (SFX_ITEM_SET != eState || (!pRet->GetGraphic() &&
1399 pRet->GetColor() == COL_TRANSPARENT))
1400 {
1401 pRet = &(DefaultItemGet<SvxBrushItem>(*pDoc,RES_BACKGROUND));
1402 }
1403 return pRet;
1404 }
1405
TrueFrameBgBrush(const SwFrmFmt & rFlyFmt) const1406 SvxBrushItem WW8Export::TrueFrameBgBrush(const SwFrmFmt &rFlyFmt) const
1407 {
1408 const SwFrmFmt *pFlyFmt = &rFlyFmt;
1409 const SvxBrushItem* pRet = 0;
1410
1411 while (pFlyFmt)
1412 {
1413 //If not set, or "no fill", get real bg
1414 const SfxPoolItem* pItem = 0;
1415 SfxItemState eState =
1416 pFlyFmt->GetItemState(RES_BACKGROUND, true, &pItem);
1417 pRet = (const SvxBrushItem*)pItem;
1418 if (SFX_ITEM_SET != eState || (!pRet->GetGraphic() &&
1419 pRet->GetColor() == COL_TRANSPARENT))
1420 {
1421 pRet = 0;
1422 const SwFmtAnchor* pAnchor = &pFlyFmt->GetAnchor();
1423 if ((FLY_AT_PAGE != pAnchor->GetAnchorId()) &&
1424 pAnchor->GetCntntAnchor())
1425 {
1426 pFlyFmt =
1427 pAnchor->GetCntntAnchor()->nNode.GetNode().GetFlyFmt();
1428 }
1429 else
1430 pFlyFmt = 0;
1431 }
1432 else
1433 pFlyFmt = 0;
1434 }
1435
1436 if (!pRet)
1437 pRet = GetCurrentPageBgBrush();
1438
1439 const Color aTmpColor( COL_WHITE );
1440 SvxBrushItem aRet( aTmpColor, RES_BACKGROUND );
1441 if (pRet && (pRet->GetGraphic() ||( pRet->GetColor() != COL_TRANSPARENT)))
1442 aRet = *pRet;
1443
1444 return aRet;
1445 }
1446
1447
1448 /*
1449 Convert characters that need to be converted, the basic replacements and the
1450 ridicously complicated title case attribute mapping to hardcoded upper case
1451 because word doesn't have the feature
1452 */
GetSnippet(const String & rStr,xub_StrLen nAktPos,xub_StrLen nLen) const1453 String WW8SwAttrIter::GetSnippet(const String &rStr, xub_StrLen nAktPos,
1454 xub_StrLen nLen) const
1455 {
1456 String aSnippet(rStr, nAktPos, nLen);
1457 if (!nLen)
1458 return aSnippet;
1459
1460 // 0x0a ( Hard Line Break ) -> 0x0b
1461 // 0xad ( soft hyphen ) -> 0x1f
1462 // 0x2011 ( hard hyphen ) -> 0x1e
1463 aSnippet.SearchAndReplaceAll(0x0A, 0x0B);
1464 aSnippet.SearchAndReplaceAll(CHAR_HARDHYPHEN, 0x1e);
1465 aSnippet.SearchAndReplaceAll(CHAR_SOFTHYPHEN, 0x1f);
1466
1467 m_rExport.m_aCurrentCharPropStarts.push( nAktPos );
1468 const SfxPoolItem &rItem = GetItem(RES_CHRATR_CASEMAP);
1469
1470 if (SVX_CASEMAP_TITEL == ((const SvxCaseMapItem&)rItem).GetValue())
1471 {
1472 sal_uInt16 nScriptType = i18n::ScriptType::LATIN;
1473 if (pBreakIt->GetBreakIter().is())
1474 nScriptType = pBreakIt->GetBreakIter()->getScriptType(aSnippet, 0);
1475
1476 LanguageType nLanguage;
1477 switch (nScriptType)
1478 {
1479 case i18n::ScriptType::ASIAN:
1480 nLanguage = ((const SvxLanguageItem&)GetItem(RES_CHRATR_CJK_LANGUAGE)).GetLanguage();
1481 break;
1482 case i18n::ScriptType::COMPLEX:
1483 nLanguage = ((const SvxLanguageItem&)GetItem(RES_CHRATR_CTL_LANGUAGE)).GetLanguage();
1484 break;
1485 case i18n::ScriptType::LATIN:
1486 default:
1487 nLanguage = ((const SvxLanguageItem&)GetItem(RES_CHRATR_LANGUAGE)).GetLanguage();
1488 break;
1489 }
1490
1491 SvxFont aFontHelper;
1492 aFontHelper.SetCaseMap(SVX_CASEMAP_TITEL);
1493 aFontHelper.SetLanguage(nLanguage);
1494 aSnippet = aFontHelper.CalcCaseMap(aSnippet);
1495
1496 //If we weren't at the begin of a word undo the case change.
1497 //not done before doing the casemap because the sequence might start
1498 //with whitespace
1499 if (pBreakIt->GetBreakIter().is() && !pBreakIt->GetBreakIter()->isBeginWord(
1500 rStr, nAktPos, pBreakIt->GetLocale(nLanguage),
1501 i18n::WordType::ANYWORD_IGNOREWHITESPACES ) )
1502 {
1503 aSnippet.SetChar(0, rStr.GetChar(nAktPos));
1504 }
1505 }
1506 m_rExport.m_aCurrentCharPropStarts.pop();
1507
1508 return aSnippet;
1509 }
1510
1511 /** Delivers the right paragraph style
1512
1513 Because of the different style handling for delete operations,
1514 the track changes have to be analysed. A deletion, starting in paragraph A
1515 with style A, ending in paragraph B with style B, needs a hack.
1516 */
lcl_getFormatCollection(MSWordExportBase & rExport,const SwTxtNode * pTxtNode)1517 static SwTxtFmtColl& lcl_getFormatCollection( MSWordExportBase& rExport, const SwTxtNode* pTxtNode )
1518 {
1519 sal_uInt16 nPos = 0;
1520 sal_uInt16 nMax = rExport.pDoc->GetRedlineTbl().Count();
1521 while( nPos < nMax )
1522 {
1523 const SwRedline* pRedl = rExport.pDoc->GetRedlineTbl()[ nPos++ ];
1524 const SwPosition* pStt = pRedl->Start();
1525 const SwPosition* pEnd = pStt == pRedl->GetPoint()
1526 ? pRedl->GetMark()
1527 : pRedl->GetPoint();
1528 // Looking for deletions, which ends in current pTxtNode
1529 if( nsRedlineType_t::REDLINE_DELETE == pRedl->GetRedlineData().GetType() &&
1530 pEnd->nNode == *pTxtNode && pStt->nNode != *pTxtNode &&
1531 pStt->nNode.GetNode().IsTxtNode() )
1532 {
1533 pTxtNode = pStt->nNode.GetNode().GetTxtNode();
1534 nMax = nPos;
1535 nPos = 0;
1536 }
1537 }
1538 return static_cast<SwTxtFmtColl&>( pTxtNode->GetAnyFmtColl() );
1539 }
1540
FormatDrop(const SwTxtNode & rNode,const SwFmtDrop & rSwFmtDrop,sal_uInt16 nStyle,ww8::WW8TableNodeInfo::Pointer_t pTextNodeInfo,ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner)1541 void WW8AttributeOutput::FormatDrop( const SwTxtNode& rNode, const SwFmtDrop &rSwFmtDrop, sal_uInt16 nStyle,
1542 ww8::WW8TableNodeInfo::Pointer_t pTextNodeInfo, ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner )
1543 {
1544 short nDropLines = rSwFmtDrop.GetLines();
1545 short nDistance = rSwFmtDrop.GetDistance();
1546 int rFontHeight, rDropHeight, rDropDescent;
1547
1548 SVBT16 nSty;
1549 ShortToSVBT16( nStyle, nSty );
1550 m_rWW8Export.pO->Insert( (sal_uInt8*)&nSty, 2, m_rWW8Export.pO->Count() ); // Style #
1551
1552 if ( m_rWW8Export.bWrtWW8 )
1553 {
1554 m_rWW8Export.InsUInt16( NS_sprm::LN_PPc ); // Alignment (sprmPPc)
1555 m_rWW8Export.pO->Insert( 0x20, m_rWW8Export.pO->Count() );
1556
1557 m_rWW8Export.InsUInt16( NS_sprm::LN_PWr ); // Wrapping (sprmPWr)
1558 m_rWW8Export.pO->Insert( 0x02, m_rWW8Export.pO->Count() );
1559
1560 m_rWW8Export.InsUInt16( NS_sprm::LN_PDcs ); // Dropcap (sprmPDcs)
1561 int nDCS = ( nDropLines << 3 ) | 0x01;
1562 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( nDCS ) );
1563
1564 m_rWW8Export.InsUInt16( NS_sprm::LN_PDxaFromText ); // Distance from text (sprmPDxaFromText)
1565 m_rWW8Export.InsUInt16( nDistance );
1566
1567 if ( rNode.GetDropSize( rFontHeight, rDropHeight, rDropDescent ) )
1568 {
1569 m_rWW8Export.InsUInt16( NS_sprm::LN_PDyaLine ); // Line spacing
1570 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( -rDropHeight ) );
1571 m_rWW8Export.InsUInt16( 0 );
1572 }
1573 }
1574 else
1575 {
1576 m_rWW8Export.pO->Insert( 29, m_rWW8Export.pO->Count() ); // Alignment (sprmPPc)
1577 m_rWW8Export.pO->Insert( 0x20, m_rWW8Export.pO->Count() );
1578
1579 m_rWW8Export.pO->Insert( 37, m_rWW8Export.pO->Count() ); // Wrapping (sprmPWr)
1580 m_rWW8Export.pO->Insert( 0x02, m_rWW8Export.pO->Count() );
1581
1582 m_rWW8Export.pO->Insert( 46, m_rWW8Export.pO->Count() ); // Dropcap (sprmPDcs)
1583 int nDCS = ( nDropLines << 3 ) | 0x01;
1584 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( nDCS ) );
1585
1586 m_rWW8Export.pO->Insert( 49, m_rWW8Export.pO->Count() ); // Distance from text (sprmPDxaFromText)
1587 m_rWW8Export.InsUInt16( nDistance );
1588
1589 if (rNode.GetDropSize(rFontHeight, rDropHeight, rDropDescent))
1590 {
1591 m_rWW8Export.pO->Insert( 20, m_rWW8Export.pO->Count() ); // Line spacing
1592 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( -rDropHeight ) );
1593 m_rWW8Export.InsUInt16( 0 );
1594 }
1595 }
1596
1597 m_rWW8Export.WriteCR( pTextNodeInfoInner );
1598
1599 if ( pTextNodeInfo.get() != NULL )
1600 {
1601 #ifdef DEBUG
1602 ::std::clog << pTextNodeInfo->toString() << ::std::endl;
1603 #endif
1604
1605 TableInfoCell( pTextNodeInfoInner );
1606 }
1607
1608 m_rWW8Export.pPapPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), m_rWW8Export.pO->Count(), m_rWW8Export.pO->GetData() );
1609 m_rWW8Export.pO->Remove( 0, m_rWW8Export.pO->Count() );
1610
1611 if ( rNode.GetDropSize( rFontHeight, rDropHeight, rDropDescent ) )
1612 {
1613 if ( m_rWW8Export.bWrtWW8 )
1614 {
1615 const SwCharFmt *pSwCharFmt = rSwFmtDrop.GetCharFmt();
1616 if ( pSwCharFmt )
1617 {
1618 m_rWW8Export.InsUInt16( NS_sprm::LN_CIstd );
1619 m_rWW8Export.InsUInt16( m_rWW8Export.GetId( *pSwCharFmt ) );
1620 }
1621
1622 m_rWW8Export.InsUInt16( NS_sprm::LN_CHpsPos ); // Lower the chars
1623 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( -((nDropLines - 1)*rDropDescent) / 10 ) );
1624
1625 m_rWW8Export.InsUInt16( NS_sprm::LN_CHps ); // Font Size
1626 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( rFontHeight / 10 ) );
1627 }
1628 else
1629 {
1630 const SwCharFmt *pSwCharFmt = rSwFmtDrop.GetCharFmt();
1631 if ( pSwCharFmt )
1632 {
1633 m_rWW8Export.InsUInt16( 80 );
1634 m_rWW8Export.InsUInt16( m_rWW8Export.GetId( *pSwCharFmt ) );
1635 }
1636
1637 m_rWW8Export.pO->Insert( 101, m_rWW8Export.pO->Count() ); // Lower the chars
1638 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( -((nDropLines - 1)*rDropDescent) / 10 ) );
1639
1640 m_rWW8Export.pO->Insert( 99, m_rWW8Export.pO->Count() ); // Font Size
1641 m_rWW8Export.InsUInt16( static_cast< sal_uInt16 >( rFontHeight / 10 ) );
1642 }
1643 }
1644
1645 m_rWW8Export.pChpPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), m_rWW8Export.pO->Count(), m_rWW8Export.pO->GetData() );
1646 m_rWW8Export.pO->Remove( 0, m_rWW8Export.pO->Count() );
1647 }
1648
GetNextPos(WW8SwAttrIter * aAttrIter,const SwTxtNode & rNode,xub_StrLen nAktPos)1649 xub_StrLen MSWordExportBase::GetNextPos( WW8SwAttrIter* aAttrIter, const SwTxtNode& rNode, xub_StrLen nAktPos )
1650 {
1651 // Get the bookmarks for the normal run
1652 xub_StrLen nNextPos = aAttrIter->WhereNext();
1653 xub_StrLen nNextBookmark = nNextPos;
1654
1655 if( nNextBookmark > nAktPos )//no need to search for bookmarks otherwise
1656 {
1657 GetSortedBookmarks( rNode, nAktPos, nNextBookmark - nAktPos );
1658 NearestBookmark( nNextBookmark, nAktPos, false );
1659 }
1660 return std::min( nNextPos, nNextBookmark );
1661 }
1662
UpdatePosition(WW8SwAttrIter * aAttrIter,xub_StrLen nAktPos,xub_StrLen)1663 void MSWordExportBase::UpdatePosition( WW8SwAttrIter* aAttrIter, xub_StrLen nAktPos, xub_StrLen /*nEnd*/ )
1664 {
1665 xub_StrLen nNextPos;
1666
1667 // go to next attribute if no bookmark is found and if the next attribute position if at the current position
1668 bool bNextBookmark = NearestBookmark( nNextPos, nAktPos, true );
1669 if( !bNextBookmark && nAktPos >= aAttrIter->WhereNext() )
1670 aAttrIter->NextPos();
1671 }
1672
GetBookmarks(const SwTxtNode & rNd,const xub_StrLen nStt,const xub_StrLen nEnd,IMarkVector & rArr)1673 bool MSWordExportBase::GetBookmarks(
1674 const SwTxtNode& rNd,
1675 const xub_StrLen nStt,
1676 const xub_StrLen nEnd,
1677 IMarkVector& rArr )
1678 {
1679 IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1680 sal_uLong nNd = rNd.GetIndex( );
1681
1682 const sal_Int32 nMarks = pMarkAccess->getAllMarksCount();
1683 for ( sal_Int32 i = 0; i < nMarks; i++ )
1684 {
1685 IMark* pMark = ( pMarkAccess->getAllMarksBegin() + i )->get();
1686
1687 if ( IDocumentMarkAccess::GetType( *(pMark) ) == IDocumentMarkAccess::ANNOTATIONMARK )
1688 {
1689 continue;
1690 }
1691
1692 // Only keep the bookmarks starting or ending in this node
1693 if ( pMark->GetMarkStart().nNode == nNd ||
1694 pMark->GetMarkEnd().nNode == nNd )
1695 {
1696 // Keep only the bookmarks starting or ending in the snippet
1697 const xub_StrLen nBStart = pMark->GetMarkStart().nContent.GetIndex();
1698 const bool bIsStartOk = ( pMark->GetMarkStart().nNode == nNd ) && ( nBStart >= nStt ) && ( nBStart <= nEnd );
1699 const xub_StrLen nBEnd = pMark->GetMarkEnd().nContent.GetIndex();
1700 const bool bIsEndOk = ( pMark->GetMarkEnd().nNode == nNd ) && ( nBEnd >= nStt ) && ( nBEnd <= nEnd );
1701 if ( bIsStartOk || bIsEndOk )
1702 {
1703 rArr.push_back( pMark );
1704 }
1705 }
1706 }
1707 return ( rArr.size() > 0 );
1708 }
1709
1710 class CompareMarksEnd
1711 {
1712 public:
1713 typedef const IMark * first_argument_type;
1714 typedef const IMark * second_argument_type;
1715 typedef bool result_type;
operator ()(const IMark * pOneB,const IMark * pTwoB) const1716 inline bool operator() ( const IMark * pOneB, const IMark * pTwoB ) const
1717 {
1718 xub_StrLen nOEnd = pOneB->GetMarkEnd().nContent.GetIndex();
1719 xub_StrLen nTEnd = pTwoB->GetMarkEnd().nContent.GetIndex();
1720
1721 return nOEnd < nTEnd;
1722 }
1723 };
1724
NearestBookmark(xub_StrLen & rNearest,const xub_StrLen nAktPos,bool bNextPositionOnly)1725 bool MSWordExportBase::NearestBookmark( xub_StrLen& rNearest, const xub_StrLen nAktPos, bool bNextPositionOnly )
1726 {
1727 bool bHasBookmark = false;
1728
1729 if ( m_rSortedMarksStart.size( ) > 0 )
1730 {
1731 IMark* pMarkStart = m_rSortedMarksStart.front();
1732 xub_StrLen nNext = pMarkStart->GetMarkStart().nContent.GetIndex();
1733 if( !bNextPositionOnly || (nNext > nAktPos ))
1734 {
1735 rNearest = nNext;
1736 bHasBookmark = true;
1737 }
1738 }
1739
1740 if ( m_rSortedMarksEnd.size( ) > 0 )
1741 {
1742 IMark* pMarkEnd = m_rSortedMarksEnd[0];
1743 xub_StrLen nNext = pMarkEnd->GetMarkEnd().nContent.GetIndex();
1744 if( !bNextPositionOnly || nNext > nAktPos )
1745 {
1746 if ( !bHasBookmark )
1747 rNearest = nNext;
1748 else
1749 rNearest = std::min( rNearest, nNext );
1750 bHasBookmark = true;
1751 }
1752 }
1753
1754 return bHasBookmark;
1755 }
1756
GetSortedBookmarks(const SwTxtNode & rNode,xub_StrLen nAktPos,xub_StrLen nLen)1757 void MSWordExportBase::GetSortedBookmarks( const SwTxtNode& rNode, xub_StrLen nAktPos, xub_StrLen nLen )
1758 {
1759 IMarkVector aMarksStart;
1760 if ( GetBookmarks( rNode, nAktPos, nAktPos + nLen, aMarksStart ) )
1761 {
1762 IMarkVector aSortedEnd;
1763 IMarkVector aSortedStart;
1764 for ( IMarkVector::const_iterator it = aMarksStart.begin(), end = aMarksStart.end();
1765 it < end; ++it )
1766 {
1767 IMark* pMark = (*it);
1768
1769 // Remove the positions egals to the current pos
1770 xub_StrLen nStart = pMark->GetMarkStart().nContent.GetIndex();
1771 xub_StrLen nEnd = pMark->GetMarkEnd().nContent.GetIndex();
1772
1773 if ( nStart > nAktPos && ( pMark->GetMarkStart().nNode == rNode.GetIndex()) )
1774 aSortedStart.push_back( pMark );
1775
1776 if ( nEnd > nAktPos && nEnd <= ( nAktPos + nLen ) && (pMark->GetMarkEnd().nNode == rNode.GetIndex()) )
1777 aSortedEnd.push_back( pMark );
1778 }
1779
1780 // Sort the bookmarks by end position
1781 std::sort( aSortedEnd.begin(), aSortedEnd.end(), CompareMarksEnd() );
1782
1783 m_rSortedMarksStart.swap( aSortedStart );
1784 m_rSortedMarksEnd.swap( aSortedEnd );
1785 }
1786 else
1787 {
1788 m_rSortedMarksStart.clear( );
1789 m_rSortedMarksEnd.clear( );
1790 }
1791 }
1792
OutputTextNode(const SwTxtNode & rNode)1793 void MSWordExportBase::OutputTextNode( const SwTxtNode& rNode )
1794 {
1795 #ifdef DEBUG
1796 ::std::clog << "<OutWW8_SwTxtNode>" << ::std::endl;
1797 #endif
1798
1799 ww8::WW8TableNodeInfo::Pointer_t pTextNodeInfo( mpTableInfo->getTableNodeInfo( &rNode ) );
1800
1801 //For i120928,identify the last node
1802 bool bLastCR = false;
1803 bool bExported = false;
1804 {
1805 SwNodeIndex aNextIdx(rNode,1);
1806 SwNodeIndex aLastIdx(rNode.GetNodes().GetEndOfContent());
1807 if (aNextIdx == aLastIdx)
1808 bLastCR = true;
1809 }
1810
1811 AttrOutput().StartParagraph( pTextNodeInfo );
1812
1813 bool bFlyInTable = mpParentFrame && IsInTable();
1814
1815 if ( !bFlyInTable )
1816 nStyleBeforeFly = GetId( lcl_getFormatCollection( *this, &rNode ) );
1817
1818 // nStyleBeforeFly may change when we recurse into another node, so we
1819 // have to remember it in nStyle
1820 sal_uInt16 nStyle = nStyleBeforeFly;
1821
1822 WW8SwAttrIter aAttrIter( *this, rNode );
1823 rtl_TextEncoding eChrSet = aAttrIter.GetCharSet();
1824
1825 if ( bStartTOX )
1826 {
1827 // ignore TOX header section
1828 const SwSectionNode* pSectNd = rNode.FindSectionNode();
1829 if ( pSectNd && TOX_CONTENT_SECTION == pSectNd->GetSection().GetType() )
1830 {
1831 AttrOutput().StartTOX( pSectNd->GetSection() );
1832 m_aCurrentCharPropStarts.push( 0 );
1833 }
1834 }
1835
1836 const SwSection* pTOXSect = 0;
1837 if( bInWriteTOX )
1838 {
1839 // check for end of TOX
1840 SwNodeIndex aIdx( rNode, 1 );
1841 if( !aIdx.GetNode().IsTxtNode() )
1842 {
1843 const SwSectionNode* pTOXSectNd = rNode.FindSectionNode();
1844 pTOXSect = &pTOXSectNd->GetSection();
1845
1846 const SwNode* pNxt = rNode.GetNodes().GoNext( &aIdx );
1847 if( pNxt && pNxt->FindSectionNode() == pTOXSectNd )
1848 pTOXSect = 0;
1849 }
1850 }
1851
1852 if ( aAttrIter.RequiresImplicitBookmark() )
1853 {
1854 String sBkmkName = String( RTL_CONSTASCII_STRINGPARAM( "_toc" ) );
1855 sBkmkName += String::CreateFromInt32( rNode.GetIndex() );
1856 AppendWordBookmark( sBkmkName );
1857 }
1858
1859 //Would need to move into WW8Export, probably not worth it
1860 //ASSERT( pO->Count(), " pO ist am Zeilenanfang nicht leer" );
1861
1862 String aStr( rNode.GetTxt() );
1863
1864 xub_StrLen nAktPos = 0;
1865 xub_StrLen const nEnd = aStr.Len();
1866 bool bRedlineAtEnd = false;
1867 int nOpenAttrWithRange = 0;
1868
1869 ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner;
1870 if ( pTextNodeInfo.get() != NULL )
1871 pTextNodeInfoInner = pTextNodeInfo->getFirstInner();
1872
1873 do {
1874 const SwRedlineData* pRedlineData = aAttrIter.GetRedline( nAktPos );
1875
1876 AttrOutput().StartRun( pRedlineData );
1877
1878 xub_StrLen nNextAttr = GetNextPos( &aAttrIter, rNode, nAktPos );
1879
1880 if( nNextAttr > nEnd )
1881 nNextAttr = nEnd;
1882
1883 aAttrIter.OutFlys( nAktPos );
1884 //Append bookmarks in this range after flys, exclusive of final
1885 //position of this range
1886 AppendBookmarks( rNode, nAktPos, nNextAttr - nAktPos );
1887 bool bTxtAtr = aAttrIter.IsTxtAttr( nAktPos );
1888 nOpenAttrWithRange += aAttrIter.OutAttrWithRange(nAktPos);
1889
1890 xub_StrLen nLen = nNextAttr - nAktPos;
1891 if ( !bTxtAtr && nLen )
1892 {
1893 sal_Unicode ch = aStr.GetChar( nAktPos );
1894 int ofs = ( ch == CH_TXT_ATR_FIELDSTART || ch == CH_TXT_ATR_FIELDEND || ch == CH_TXT_ATR_FORMELEMENT? 1: 0 );
1895
1896 IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1897 if ( ch == CH_TXT_ATR_FIELDSTART )
1898 {
1899 SwPosition aPosition( rNode, SwIndex( const_cast< SwTxtNode* >( &rNode ), nAktPos + 1 ) );
1900 ::sw::mark::IFieldmark const * const pFieldmark = pMarkAccess->getFieldmarkFor( aPosition );
1901 OSL_ENSURE( pFieldmark, "Looks like this doc is broken...; where is the Fieldmark for the FIELDSTART??" );
1902
1903 if ( pFieldmark->GetFieldname().equalsAscii( ODF_FORMTEXT ) )
1904 AppendBookmark( pFieldmark->GetName(), false );
1905
1906 const bool bCommentRange = pFieldmark != NULL && pFieldmark->GetFieldname().equalsAscii( ODF_COMMENTRANGE );
1907 if ( bCommentRange )
1908 {
1909 AttrOutput().WritePostitFieldStart(); // Note: empty for WW8 export
1910 }
1911 else
1912 {
1913 OutputField( NULL, lcl_getFieldId( pFieldmark ), lcl_getFieldCode( pFieldmark ), WRITEFIELD_START | WRITEFIELD_CMD_START );
1914 }
1915
1916 if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMTEXT ) )
1917 WriteFormData( *pFieldmark );
1918 else if ( pFieldmark->GetFieldname( ).equalsAscii( ODF_HYPERLINK ) )
1919 WriteHyperlinkData( *pFieldmark );
1920
1921 if ( !bCommentRange )
1922 {
1923 OutputField( NULL, lcl_getFieldId( pFieldmark ), String(), WRITEFIELD_CMD_END );
1924 }
1925 }
1926 else if ( ch == CH_TXT_ATR_FIELDEND )
1927 {
1928 SwPosition aPosition( rNode, SwIndex( const_cast< SwTxtNode* >( &rNode ), nAktPos ) );
1929 ::sw::mark::IFieldmark const * const pFieldmark = pMarkAccess->getFieldmarkFor( aPosition );
1930 OSL_ENSURE( pFieldmark, "Looks like this doc is broken...; where is the Fieldmark for the FIELDSTART??" );
1931
1932 if ( pFieldmark && pFieldmark->GetFieldname().equalsAscii( ODF_COMMENTRANGE ) )
1933 {
1934 AttrOutput().WritePostitFieldEnd(); // Note: empty for WW8 export
1935 }
1936 else
1937 {
1938 OutputField( NULL, lcl_getFieldId( pFieldmark ), String(), WRITEFIELD_CLOSE );
1939 }
1940
1941 if ( pFieldmark->GetFieldname().equalsAscii( ODF_FORMTEXT ) )
1942 AppendBookmark( pFieldmark->GetName(), false );
1943 }
1944 else if ( ch == CH_TXT_ATR_FORMELEMENT )
1945 {
1946 SwPosition aPosition( rNode, SwIndex( const_cast< SwTxtNode* >( &rNode ), nAktPos ) );
1947 ::sw::mark::IFieldmark const * const pFieldmark = pMarkAccess->getFieldmarkFor( aPosition );
1948 OSL_ENSURE( pFieldmark, "Looks like this doc is broken...; where is the Fieldmark for the FIELDSTART??" );
1949
1950 bool isDropdownOrCheckbox = pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMDROPDOWN ) ||
1951 pFieldmark->GetFieldname( ).equalsAscii( ODF_FORMCHECKBOX );
1952
1953 if ( isDropdownOrCheckbox )
1954 AppendBookmark( pFieldmark->GetName(), 0 );
1955 OutputField( NULL, lcl_getFieldId( pFieldmark ),
1956 lcl_getFieldCode( pFieldmark ),
1957 WRITEFIELD_START | WRITEFIELD_CMD_START );
1958 if ( isDropdownOrCheckbox )
1959 WriteFormData( *pFieldmark );
1960 OutputField( NULL, lcl_getFieldId( pFieldmark ), String(), WRITEFIELD_CLOSE );
1961 if ( isDropdownOrCheckbox )
1962 AppendBookmark( pFieldmark->GetName(), false );
1963 }
1964 nLen -= static_cast< sal_uInt16 >( ofs );
1965
1966 String aSnippet( aAttrIter.GetSnippet( aStr, nAktPos + static_cast< sal_uInt16 >( ofs ), nLen ) );
1967 if ( ( nTxtTyp == TXT_EDN || nTxtTyp == TXT_FTN ) && nAktPos == 0 && nLen > 0 )
1968 {
1969 // Insert tab for aesthetic puposes #i24762#
1970 if ( aSnippet.GetChar( 0 ) != 0x09 )
1971 aSnippet.Insert( 0x09, 0 );
1972 }
1973 AttrOutput().RunText( aSnippet, eChrSet );
1974 }
1975
1976 if ( aAttrIter.IsDropCap( nNextAttr ) )
1977 AttrOutput().FormatDrop( rNode, aAttrIter.GetSwFmtDrop(), nStyle, pTextNodeInfo, pTextNodeInfoInner );
1978
1979 if (0 != nEnd)
1980 {
1981 // Output the character attributes
1982 // #i51277# do this before writing flys at end of paragraph
1983 AttrOutput().StartRunProperties();
1984 aAttrIter.OutAttr( nAktPos );
1985 AttrOutput().EndRunProperties( pRedlineData );
1986 }
1987
1988 // At the end of line, output the attributes until the CR.
1989 // Exception: footnotes at the end of line
1990 if ( nNextAttr == nEnd )
1991 {
1992 ASSERT( nOpenAttrWithRange >= 0, "odd to see this happening, expected >= 0" );
1993 if ( !bTxtAtr && nOpenAttrWithRange <= 0 )
1994 {
1995 if ( aAttrIter.IsRedlineAtEnd( nEnd ) )
1996 bRedlineAtEnd = true;
1997 else
1998 {
1999 // insert final graphic anchors if any before CR
2000 aAttrIter.OutFlys( nEnd );
2001 // insert final bookmarks if any before CR and after flys
2002 AppendBookmarks( rNode, nEnd, 1 );
2003 if ( pTOXSect )
2004 {
2005 m_aCurrentCharPropStarts.pop();
2006 AttrOutput().EndTOX( *pTOXSect ,false);
2007 }
2008 //For i120928,the position of the bullet's graphic is at end of doc
2009 if (bLastCR && (!bExported))
2010 {
2011 ExportGrfBullet(rNode);
2012 bExported = true;
2013 }
2014
2015 WriteCR( pTextNodeInfoInner );
2016 }
2017 }
2018 }
2019
2020 if (0 == nEnd)
2021 {
2022 // Output the character attributes
2023 // do it after WriteCR for an empty paragraph (otherwise
2024 // WW8_WrFkp::Append throws SPRMs away...)
2025 AttrOutput().StartRunProperties();
2026 aAttrIter.OutAttr( nAktPos );
2027 AttrOutput().EndRunProperties( pRedlineData );
2028 }
2029
2030 // Exception: footnotes at the end of line
2031 if ( nNextAttr == nEnd )
2032 {
2033 ASSERT(nOpenAttrWithRange >= 0,
2034 "odd to see this happening, expected >= 0");
2035 bool bAttrWithRange = (nOpenAttrWithRange > 0);
2036 if ( nAktPos != nEnd )
2037 {
2038 nOpenAttrWithRange += aAttrIter.OutAttrWithRange(nEnd);
2039 ASSERT(nOpenAttrWithRange == 0,
2040 "odd to see this happening, expected 0");
2041 }
2042
2043 AttrOutput().OutputFKP();
2044
2045 if ( bTxtAtr || bAttrWithRange || bRedlineAtEnd )
2046 {
2047 // insert final graphic anchors if any before CR
2048 aAttrIter.OutFlys( nEnd );
2049 // insert final bookmarks if any before CR and after flys
2050 AppendBookmarks( rNode, nEnd, 1 );
2051 WriteCR( pTextNodeInfoInner );
2052 //For i120928,the position of the bullet's graphic is at end of doc
2053 if (bLastCR && (!bExported))
2054 {
2055 ExportGrfBullet(rNode);
2056 bExported = true;
2057 }
2058
2059 if ( pTOXSect )
2060 {
2061 m_aCurrentCharPropStarts.pop();
2062 AttrOutput().EndTOX( *pTOXSect );
2063 }
2064
2065 if ( bRedlineAtEnd )
2066 {
2067 AttrOutput().Redline( aAttrIter.GetRedline( nEnd ) );
2068 AttrOutput().OutputFKP();
2069 }
2070 }
2071 }
2072
2073 AttrOutput().EndRun();
2074
2075 nAktPos = nNextAttr;
2076 UpdatePosition( &aAttrIter, nAktPos, nEnd );
2077 eChrSet = aAttrIter.GetCharSet();
2078 }
2079 while ( nAktPos < nEnd );
2080
2081 AttrOutput().StartParagraphProperties( rNode );
2082
2083 AttrOutput().ParagraphStyle( nStyle );
2084
2085 if ( mpParentFrame && IsInTable() ) // Fly-Attrs
2086 OutputFormat( mpParentFrame->GetFrmFmt(), false, false, true );
2087
2088 if ( pTextNodeInfo.get() != NULL )
2089 {
2090 #ifdef DEBUG
2091 ::std::clog << pTextNodeInfo->toString() << ::std::endl;
2092 #endif
2093
2094 AttrOutput().TableInfoCell( pTextNodeInfoInner );
2095 if (pTextNodeInfoInner->isFirstInTable())
2096 {
2097 const SwTable * pTable = pTextNodeInfoInner->getTable();
2098
2099 const SwTableFmt * pTabFmt = pTable->GetTableFmt();
2100 if (pTabFmt != NULL)
2101 {
2102 if (pTabFmt->GetBreak().GetBreak() == SVX_BREAK_PAGE_BEFORE)
2103 AttrOutput().PageBreakBefore(true);
2104 }
2105 }
2106 }
2107
2108 if ( !bFlyInTable )
2109 {
2110 SfxItemSet* pTmpSet = 0;
2111 const sal_uInt8 nPrvNxtNd = rNode.HasPrevNextLayNode();
2112
2113 if( (ND_HAS_PREV_LAYNODE|ND_HAS_NEXT_LAYNODE ) != nPrvNxtNd )
2114 {
2115 const SfxPoolItem* pItem;
2116 if( SFX_ITEM_SET == rNode.GetSwAttrSet().GetItemState(
2117 RES_UL_SPACE, true, &pItem ) &&
2118 ( ( !( ND_HAS_PREV_LAYNODE & nPrvNxtNd ) &&
2119 ((SvxULSpaceItem*)pItem)->GetUpper()) ||
2120 ( !( ND_HAS_NEXT_LAYNODE & nPrvNxtNd ) &&
2121 ((SvxULSpaceItem*)pItem)->GetLower()) ))
2122 {
2123 pTmpSet = new SfxItemSet( rNode.GetSwAttrSet() );
2124 SvxULSpaceItem aUL( *(SvxULSpaceItem*)pItem );
2125 // OD, MMAHER 2004-03-01 #i25901#- consider compatibility option
2126 if (!pDoc->get(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES))
2127 {
2128 if( !(ND_HAS_PREV_LAYNODE & nPrvNxtNd ))
2129 aUL.SetUpper( 0 );
2130 }
2131 // OD, MMAHER 2004-03-01 #i25901# - consider compatibility option
2132 if (!pDoc->get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS))
2133 {
2134 if( !(ND_HAS_NEXT_LAYNODE & nPrvNxtNd ))
2135 aUL.SetLower( 0 );
2136 }
2137 pTmpSet->Put( aUL );
2138 }
2139 }
2140
2141 sal_Bool bParaRTL = sal_False;
2142 const SvxFrameDirectionItem* pItem = (const SvxFrameDirectionItem*)
2143 rNode.GetSwAttrSet().GetItem(RES_FRAMEDIR);
2144 if ( aAttrIter.IsParaRTL())
2145 bParaRTL = sal_True;
2146
2147 if( rNode.IsNumbered())
2148 {
2149 const SwNumRule* pRule = rNode.GetNumRule();
2150 sal_uInt8 nLvl = static_cast< sal_uInt8 >( rNode.GetActualListLevel() );
2151 const SwNumFmt* pFmt = pRule->GetNumFmt( nLvl );
2152 if( !pFmt )
2153 pFmt = &pRule->Get( nLvl );
2154
2155 if( !pTmpSet )
2156 pTmpSet = new SfxItemSet( rNode.GetSwAttrSet() );
2157
2158 SvxLRSpaceItem aLR(ItemGet<SvxLRSpaceItem>(*pTmpSet, RES_LR_SPACE));
2159 // --> OD 2008-06-03 #i86652#
2160 if ( pFmt->GetPositionAndSpaceMode() ==
2161 SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
2162 {
2163 aLR.SetTxtLeft( aLR.GetTxtLeft() + pFmt->GetAbsLSpace() );
2164 }
2165 // <--
2166
2167 if( rNode.IsNumbered() && rNode.IsCountedInList() )
2168 {
2169 // --> OD 2008-06-03 #i86652#
2170 if ( pFmt->GetPositionAndSpaceMode() ==
2171 SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
2172 {
2173 if (bParaRTL)
2174 aLR.SetTxtFirstLineOfstValue(pFmt->GetAbsLSpace() - pFmt->GetFirstLineOffset());
2175 else
2176 aLR.SetTxtFirstLineOfst(GetWordFirstLineOffset(*pFmt));
2177 }
2178 // <--
2179
2180 // --> OD 2009-03-09 #100020#
2181 // correct fix for issue i94187
2182 if (SFX_ITEM_SET !=
2183 pTmpSet->GetItemState(RES_PARATR_NUMRULE, false) )
2184 {
2185 // List style set via paragraph style - then put it into the itemset.
2186 // This is needed to get list level and list id exported for
2187 // the paragraph.
2188 pTmpSet->Put( SwNumRuleItem( pRule->GetName() ));
2189
2190 // Put indent values into the itemset in case that the list
2191 // style is applied via paragraph style and the list level
2192 // indent values are not applicable.
2193 if ( pFmt->GetPositionAndSpaceMode() ==
2194 SvxNumberFormat::LABEL_ALIGNMENT &&
2195 !rNode.AreListLevelIndentsApplicable() )
2196 {
2197 pTmpSet->Put( aLR );
2198 }
2199 }
2200 }
2201 else
2202 pTmpSet->ClearItem(RES_PARATR_NUMRULE);
2203
2204 // --> OD 2008-06-03 #i86652#
2205 if ( pFmt->GetPositionAndSpaceMode() ==
2206 SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
2207 {
2208 pTmpSet->Put(aLR);
2209
2210 //#i21847#
2211 SvxTabStopItem aItem(
2212 ItemGet<SvxTabStopItem>(*pTmpSet, RES_PARATR_TABSTOP));
2213 SvxTabStop aTabStop(pFmt->GetAbsLSpace());
2214 aItem.Insert(aTabStop);
2215 pTmpSet->Put(aItem);
2216
2217 MSWordExportBase::CorrectTabStopInSet(*pTmpSet, pFmt->GetAbsLSpace());
2218 }
2219 }
2220
2221 /*
2222 If a given para is using the FRMDIR_ENVIRONMENT direction we
2223 cannot export that, if it's ltr then that's ok as that's Word's
2224 default. Otherwise we must add a RTL attribute to our export list
2225 */
2226 pItem = (const SvxFrameDirectionItem*)
2227 rNode.GetSwAttrSet().GetItem(RES_FRAMEDIR);
2228 if (
2229 (!pItem || pItem->GetValue() == FRMDIR_ENVIRONMENT) &&
2230 aAttrIter.IsParaRTL()
2231 )
2232 {
2233 if ( !pTmpSet )
2234 pTmpSet = new SfxItemSet(rNode.GetSwAttrSet());
2235
2236 pTmpSet->Put(SvxFrameDirectionItem(FRMDIR_HORI_RIGHT_TOP, RES_FRAMEDIR));
2237 }
2238 // --> OD 2005-10-18 #126238# - move code for handling of numbered,
2239 // but not counted paragraphs to this place. Otherwise, the paragraph
2240 // isn't exported as numbered, but not counted, if no other attribute
2241 // is found in <pTmpSet>
2242 // #i44815# adjust numbering/indents for numbered paragraphs
2243 // without number (NO_NUMLEVEL)
2244 // #i47013# need to check rNode.GetNumRule()!=NULL as well.
2245 if ( ! rNode.IsCountedInList() && rNode.GetNumRule()!=NULL )
2246 {
2247 // WW8 does not know numbered paragraphs without number
2248 // (NO_NUMLEVEL). In WW8AttributeOutput::ParaNumRule(), we will export
2249 // the RES_PARATR_NUMRULE as list-id 0, which in WW8 means
2250 // no numbering. Here, we will adjust the indents to match
2251 // visually.
2252
2253 if ( !pTmpSet )
2254 pTmpSet = new SfxItemSet(rNode.GetSwAttrSet());
2255
2256 // create new LRSpace item, based on the current (if present)
2257 const SfxPoolItem* pPoolItem = NULL;
2258 pTmpSet->GetItemState(RES_LR_SPACE, sal_True, &pPoolItem);
2259 SvxLRSpaceItem aLRSpace(
2260 ( pPoolItem == NULL )
2261 ? SvxLRSpaceItem(0, 0, 0, 0, RES_LR_SPACE)
2262 : *static_cast<const SvxLRSpaceItem*>( pPoolItem ) );
2263
2264 // new left margin = old left + label space
2265 const SwNumRule* pRule = rNode.GetNumRule();
2266 const SwNumFmt& rNumFmt = pRule->Get( static_cast< sal_uInt16 >(rNode.GetActualListLevel()) );
2267 // --> OD 2008-06-03 #i86652#
2268 if ( rNumFmt.GetPositionAndSpaceMode() ==
2269 SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
2270 {
2271 aLRSpace.SetTxtLeft( aLRSpace.GetLeft() + rNumFmt.GetAbsLSpace() );
2272
2273 // new first line indent = 0
2274 // (first line indent is ignored for NO_NUMLEVEL)
2275 if (!bParaRTL)
2276 aLRSpace.SetTxtFirstLineOfst( 0 );
2277
2278 // put back the new item
2279 pTmpSet->Put( aLRSpace );
2280 }
2281 // <--
2282
2283 // assure that numbering rule is in <pTmpSet>
2284 if (SFX_ITEM_SET != pTmpSet->GetItemState(RES_PARATR_NUMRULE, false) )
2285 {
2286 pTmpSet->Put( SwNumRuleItem( pRule->GetName() ));
2287 }
2288 }
2289
2290 // --> OD 2007-04-24 #i75457#
2291 // Export page break after attribute from paragraph style.
2292 // If page break attribute at the text node exist, an existing page
2293 // break after at the paragraph style hasn't got to be considered.
2294 if ( !rNode.GetpSwAttrSet() ||
2295 SFX_ITEM_SET != rNode.GetpSwAttrSet()->GetItemState(RES_BREAK, false) )
2296 {
2297 const SvxFmtBreakItem* pBreakAtParaStyle =
2298 &(ItemGet<SvxFmtBreakItem>(rNode.GetSwAttrSet(), RES_BREAK));
2299 if ( pBreakAtParaStyle &&
2300 pBreakAtParaStyle->GetBreak() == SVX_BREAK_PAGE_AFTER )
2301 {
2302 if ( !pTmpSet )
2303 {
2304 pTmpSet = new SfxItemSet(rNode.GetSwAttrSet());
2305 }
2306 pTmpSet->Put( *pBreakAtParaStyle );
2307 }
2308 else if( pTmpSet )
2309 { // Even a pagedesc item is set, the break item can be set 'NONE',
2310 // this has to be overruled.
2311 const SwFmtPageDesc& rPageDescAtParaStyle =
2312 ItemGet<SwFmtPageDesc>( rNode, RES_PAGEDESC );
2313 if( rPageDescAtParaStyle.KnowsPageDesc() )
2314 pTmpSet->ClearItem( RES_BREAK );
2315 }
2316 }
2317
2318 // --> FME 2007-05-30 #i76520# Emulate non-splitting tables
2319 if ( bOutTable )
2320 {
2321 const SwTableNode* pTableNode = rNode.FindTableNode();
2322
2323 if ( pTableNode )
2324 {
2325 const SwTable& rTable = pTableNode->GetTable();
2326 const SvxFmtKeepItem& rKeep = rTable.GetFrmFmt()->GetKeep();
2327 const bool bKeep = rKeep.GetValue();
2328 const bool bDontSplit = !bKeep ?
2329 !rTable.GetFrmFmt()->GetLayoutSplit().GetValue() :
2330 false;
2331
2332 if ( bKeep || bDontSplit )
2333 {
2334 // bKeep: set keep at first paragraphs in all lines
2335 // bDontSplit : set keep at first paragraphs in all lines except from last line
2336 // but only for non-complex tables
2337 const SwTableBox* pBox = rNode.GetTblBox();
2338 const SwTableLine* pLine = pBox ? pBox->GetUpper() : 0;
2339
2340 if ( pLine && !pLine->GetUpper() )
2341 {
2342 // check if box is first in that line:
2343 if ( 0 == pLine->GetTabBoxes().GetPos( pBox ) && pBox->GetSttNd() )
2344 {
2345 // check if paragraph is first in that line:
2346 if ( 1 == ( rNode.GetIndex() - pBox->GetSttNd()->GetIndex() ) )
2347 {
2348 bool bSetAtPara = false;
2349 if ( bKeep )
2350 bSetAtPara = true;
2351 else if ( bDontSplit )
2352 {
2353 // check if pLine isn't last line in table
2354 if ( rTable.GetTabLines().Count() - rTable.GetTabLines().GetPos( pLine ) != 1 )
2355 bSetAtPara = true;
2356 }
2357
2358 if ( bSetAtPara )
2359 {
2360 if ( !pTmpSet )
2361 pTmpSet = new SfxItemSet(rNode.GetSwAttrSet());
2362
2363 const SvxFmtKeepItem aKeepItem( sal_True, RES_KEEP );
2364 pTmpSet->Put( aKeepItem );
2365 }
2366 }
2367 }
2368 }
2369 }
2370 }
2371 }
2372 // <--
2373
2374 const SfxItemSet* pNewSet = pTmpSet ? pTmpSet : rNode.GetpSwAttrSet();
2375 if( pNewSet )
2376 { // Para-Attrs
2377 pStyAttr = &rNode.GetAnyFmtColl().GetAttrSet();
2378
2379 const SwModify* pOldMod = pOutFmtNode;
2380 pOutFmtNode = &rNode;
2381
2382 // Pap-Attrs, so script is not necessary
2383 OutputItemSet( *pNewSet, true, false, i18n::ScriptType::LATIN, false);
2384
2385 pStyAttr = 0;
2386 pOutFmtNode = pOldMod;
2387
2388 if( pNewSet != rNode.GetpSwAttrSet() )
2389 delete pNewSet;
2390 }
2391 }
2392
2393 AttrOutput().EndParagraphProperties();
2394
2395 AttrOutput().EndParagraph( pTextNodeInfoInner );
2396
2397 #ifdef DEBUG
2398 ::std::clog << "</OutWW8_SwTxtNode>" << ::std::endl;
2399 #endif
2400 }
2401
TableNodeInfo(ww8::WW8TableNodeInfo::Pointer_t pNodeInfo)2402 void WW8AttributeOutput::TableNodeInfo( ww8::WW8TableNodeInfo::Pointer_t pNodeInfo )
2403 {
2404 SVBT16 nSty;
2405 ShortToSVBT16( GetExport().nStyleBeforeFly, nSty );
2406
2407 ww8::WW8TableNodeInfo::Inners_t::const_iterator aIt( pNodeInfo->getInners().begin() );
2408 ww8::WW8TableNodeInfo::Inners_t::const_iterator aItEnd( pNodeInfo->getInners().end() );
2409
2410 while (aIt != aItEnd)
2411 {
2412 ww8::WW8TableNodeInfoInner::Pointer_t pInner = aIt->second;
2413 if ( pInner->isEndOfCell() )
2414 {
2415 TableRowEnd( pInner->getDepth() );
2416
2417 m_rWW8Export.pO->Insert( (sal_uInt8*)&nSty, 2, m_rWW8Export.pO->Count() ); // Style #
2418 TableInfoRow( pInner );
2419 m_rWW8Export.pPapPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), m_rWW8Export.pO->Count(),
2420 m_rWW8Export.pO->GetData() );
2421 m_rWW8Export.pO->Remove( 0, m_rWW8Export.pO->Count() ); // leeren
2422 }
2423
2424 if ( pInner->isEndOfLine() )
2425 {
2426 }
2427
2428 aIt++;
2429 }
2430 }
2431
2432 #if 0
2433 /* */
2434
2435 sal_uInt16 WW8Export::StartTableFromFrmFmt( WW8Bytes &rAt, const SwFrmFmt *pFmt )
2436 {
2437 // Tell the undocumented table hack that everything between here and
2438 // the last table position is nontable text
2439 if ( WW8_CP nPos = Fc2Cp( Strm().Tell() ) )
2440 pMagicTable->Append(nPos,0);
2441
2442 // sprmPDxaFromText10
2443 if( bWrtWW8 )
2444 {
2445 static sal_uInt8 __READONLY_DATA aTabLineAttr[] = {
2446 0, 0, // Sty # 0
2447 0x16, 0x24, 1, // sprmPFInTable
2448 0x17, 0x24, 1 }; // sprmPFTtp
2449 rAt.Insert( aTabLineAttr, sizeof( aTabLineAttr ), rAt.Count() );
2450 }
2451 else
2452 {
2453 static sal_uInt8 __READONLY_DATA aTabLineAttr[] = {
2454 0, 0, // Sty # 0
2455 24, 1, // sprmPFInTable
2456 25, 1 }; // sprmPFTtp
2457 rAt.Insert( aTabLineAttr, sizeof( aTabLineAttr ), rAt.Count() );
2458 }
2459
2460 ASSERT( pFmt, "No pFmt!" );
2461 if ( pFmt )
2462 {
2463 const SwFmtHoriOrient &rHori = pFmt->GetHoriOrient();
2464 const SwFmtVertOrient &rVert = pFmt->GetVertOrient();
2465 if (
2466 (text::RelOrientation::PRINT_AREA == rHori.GetRelationOrient() ||
2467 text::RelOrientation::FRAME == rHori.GetRelationOrient())
2468 &&
2469 (text::RelOrientation::PRINT_AREA == rVert.GetRelationOrient() ||
2470 text::RelOrientation::FRAME == rVert.GetRelationOrient())
2471 )
2472 {
2473 sal_Int16 eHOri = rHori.GetHoriOrient();
2474 switch (eHOri)
2475 {
2476 case text::HoriOrientation::CENTER:
2477 case text::HoriOrientation::RIGHT:
2478 if( bWrtWW8 )
2479 SwWW8Writer::InsUInt16( rAt, NS_sprm::LN_TJc );
2480 else
2481 rAt.Insert( 182, rAt.Count() );
2482 SwWW8Writer::InsUInt16( rAt, (text::HoriOrientation::RIGHT == eHOri ? 2 : 1 ));
2483 break;
2484 default:
2485 break;
2486 }
2487 }
2488 }
2489 return rAt.Count();
2490 }
2491
2492 //See #i19484# for why we need this
2493 static bool CellContainsProblematicGraphic( const SwWriteTableCell *pCell,
2494 const MSWordExportBase &rExport )
2495 {
2496 const SwNode *pStart = pCell ? pCell->GetBox()->GetSttNd() : 0;
2497 const SwNode *pEnd = pStart ? pStart->EndOfSectionNode() : 0;
2498 ASSERT( pStart && pEnd, "No start or end?" );
2499 if ( !pStart || !pEnd )
2500 return false;
2501
2502 bool bHasGraphic = false;
2503
2504 sw::Frames aFrames( GetFramesBetweenNodes( rExport.maFrames, *pStart, *pEnd ) );
2505 sw::FrameIter aEnd = aFrames.end();
2506 for ( sw::FrameIter aIter = aFrames.begin(); aIter != aEnd; ++aIter )
2507 {
2508 const SwFrmFmt &rEntry = aIter->GetFrmFmt();
2509 if ( rEntry.GetSurround().GetSurround() == SURROUND_THROUGHT )
2510 {
2511 bHasGraphic = true;
2512 break;
2513 }
2514 }
2515 return bHasGraphic;
2516 }
2517
2518 static bool RowContainsProblematicGraphic( const SwWriteTableCellPtr *pRow,
2519 sal_uInt16 nCols, const MSWordExportBase &rExport )
2520 {
2521 bool bHasGraphic = false;
2522 for ( sal_uInt16 nI = 0; nI < nCols; ++nI )
2523 {
2524 if ( CellContainsProblematicGraphic( pRow[nI], rExport ) )
2525 {
2526 bHasGraphic = true;
2527 break;
2528 }
2529 }
2530 return bHasGraphic;
2531 }
2532 #endif
2533 //---------------------------------------------------------------------------
2534 // Tabellen
2535 //---------------------------------------------------------------------------
2536
EmptyParagraph()2537 void WW8AttributeOutput::EmptyParagraph()
2538 {
2539 m_rWW8Export.WriteStringAsPara( aEmptyStr );
2540 }
2541
NoPageBreakSection(const SfxItemSet * pSet)2542 bool MSWordExportBase::NoPageBreakSection( const SfxItemSet* pSet )
2543 {
2544 bool bRet = false;
2545 const SfxPoolItem* pI;
2546 if( pSet)
2547 {
2548 bool bNoPageBreak = false;
2549 if ( SFX_ITEM_ON != pSet->GetItemState(RES_PAGEDESC, true, &pI)
2550 || 0 == ((SwFmtPageDesc*)pI)->GetPageDesc() )
2551 {
2552 bNoPageBreak = true;
2553 }
2554
2555 if (bNoPageBreak)
2556 {
2557 if (SFX_ITEM_ON != pSet->GetItemState(RES_BREAK, true, &pI))
2558 bNoPageBreak = true;
2559 else
2560 {
2561 SvxBreak eBreak = ((const SvxFmtBreakItem*)pI)->GetBreak();
2562 switch (eBreak)
2563 {
2564 case SVX_BREAK_PAGE_BEFORE:
2565 case SVX_BREAK_PAGE_AFTER:
2566 bNoPageBreak = false;
2567 break;
2568 default:
2569 break;
2570 }
2571 }
2572 }
2573 bRet = bNoPageBreak;
2574 }
2575 return bRet;
2576 }
2577
2578 /* */
2579
OutputSectionNode(const SwSectionNode & rSectionNode)2580 void MSWordExportBase::OutputSectionNode( const SwSectionNode& rSectionNode )
2581 {
2582 const SwSection& rSection = rSectionNode.GetSection();
2583
2584 SwNodeIndex aIdx( rSectionNode, 1 );
2585 const SwNode& rNd = aIdx.GetNode();
2586 if ( !rNd.IsSectionNode() && !IsInTable()
2587 && rSection.GetType() != TOX_CONTENT_SECTION && rSection.GetType() != TOX_HEADER_SECTION) //No sections in table
2588 {
2589 // Bug 74245 - if the first Node inside the section has an own
2590 // PageDesc or PageBreak attribut, then dont write
2591 // here the section break
2592 sal_uLong nRstLnNum = 0;
2593 const SfxItemSet* pSet;
2594 if ( rNd.IsTableNode() )
2595 pSet = &rNd.GetTableNode()->GetTable().GetFrmFmt()->GetAttrSet();
2596 else if ( rNd.IsCntntNode() )
2597 {
2598 pSet = &rNd.GetCntntNode()->GetSwAttrSet();
2599 nRstLnNum = ((SwFmtLineNumber&)pSet->Get(
2600 RES_LINENUMBER )).GetStartValue();
2601 }
2602 else
2603 pSet = 0;
2604
2605 if ( pSet && NoPageBreakSection( pSet ) )
2606 pSet = 0;
2607
2608 if ( !pSet )
2609 {
2610 // new Section with no own PageDesc/-Break
2611 // -> write follow section break;
2612 const SwSectionFmt& rFmt = *rSection.GetFmt();
2613 ReplaceCr( msword::PageBreak ); // Indikator fuer Page/Section-Break
2614
2615 //Get the page in use at the top of this section
2616 SwNodeIndex aIdxTmp(rSectionNode, 1);
2617 const SwPageDesc *pCurrent =
2618 SwPageDesc::GetPageDescOfNode(aIdxTmp.GetNode());
2619 if (!pCurrent)
2620 pCurrent = pAktPageDesc;
2621
2622 AppendSection( pCurrent, &rFmt, nRstLnNum );
2623 }
2624 }
2625 if ( TOX_CONTENT_SECTION == rSection.GetType() )
2626 bStartTOX = true;
2627 }
2628
2629
AppendSection(const SwPageDesc * pPageDesc,const SwSectionFmt * pFmt,sal_uLong nLnNum)2630 void WW8Export::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum )
2631 {
2632 pSepx->AppendSep(Fc2Cp(Strm().Tell()), pPageDesc, pFmt, nLnNum);
2633 }
2634
2635 /* */
2636
2637 //---------------------------------------------------------------------------
2638 // Flys
2639 //---------------------------------------------------------------------------
2640
OutWW6FlyFrmsInCntnt(const SwTxtNode & rNd)2641 void WW8Export::OutWW6FlyFrmsInCntnt( const SwTxtNode& rNd )
2642 {
2643 ASSERT(!bWrtWW8, "I shouldn't be needed for Word >=8");
2644 if ( bWrtWW8 )
2645 return;
2646
2647 if (const SwpHints* pTxtAttrs = rNd.GetpSwpHints())
2648 {
2649 for( sal_uInt16 n=0; n < pTxtAttrs->Count(); ++n )
2650 {
2651 const SwTxtAttr* pAttr = (*pTxtAttrs)[ n ];
2652 if( RES_TXTATR_FLYCNT == pAttr->Which() )
2653 {
2654 // zeichengebundenes Attribut
2655 const SwFmtFlyCnt& rFlyCntnt = pAttr->GetFlyCnt();
2656 const SwFlyFrmFmt& rFlyFrmFmt = *(SwFlyFrmFmt*)rFlyCntnt.GetFrmFmt();
2657 const SwNodeIndex* pNodeIndex = rFlyFrmFmt.GetCntnt().GetCntntIdx();
2658
2659 if( pNodeIndex )
2660 {
2661 sal_uLong nStt = pNodeIndex->GetIndex()+1,
2662 nEnd = pNodeIndex->GetNode().EndOfSectionIndex();
2663
2664 if( (nStt < nEnd) && !pDoc->GetNodes()[ nStt ]->IsNoTxtNode() )
2665 {
2666 Point aOffset;
2667 // Rechtecke des Flys und des Absatzes besorgen
2668 SwRect aParentRect(rNd.FindLayoutRect(false, &aOffset)),
2669 aFlyRect(rFlyFrmFmt.FindLayoutRect(false, &aOffset ) );
2670
2671 aOffset = aFlyRect.Pos() - aParentRect.Pos();
2672
2673 // PaM umsetzen: auf Inhalt des Fly-Frameformats
2674 SaveData( nStt, nEnd );
2675
2676 // wird in OutputFormat() ausgewertet
2677 pFlyOffset = &aOffset;
2678 eNewAnchorType = rFlyFrmFmt.GetAnchor().GetAnchorId();
2679 sw::Frame aFrm(rFlyFrmFmt, SwPosition(rNd));
2680 mpParentFrame = &aFrm;
2681 // Ok, rausschreiben:
2682 WriteText();
2683
2684 RestoreData();
2685 }
2686 }
2687 }
2688 }
2689 }
2690 }
2691
OutputFlyFrame_Impl(const sw::Frame & rFmt,const Point & rNdTopLeft)2692 void WW8AttributeOutput::OutputFlyFrame_Impl( const sw::Frame& rFmt, const Point& rNdTopLeft )
2693 {
2694 const SwFrmFmt &rFrmFmt = rFmt.GetFrmFmt();
2695 const SwFmtAnchor& rAnch = rFrmFmt.GetAnchor();
2696
2697 bool bUseEscher = m_rWW8Export.bWrtWW8;
2698
2699 if ( m_rWW8Export.bWrtWW8 && rFmt.IsInline() )
2700 {
2701 sw::Frame::WriterSource eType = rFmt.GetWriterType();
2702 if ((eType == sw::Frame::eGraphic) || (eType == sw::Frame::eOle))
2703 bUseEscher = false;
2704 else
2705 bUseEscher = true;
2706
2707 /*
2708 #110185#
2709 A special case for converting some inline form controls to form fields
2710 when in winword 8+ mode
2711 */
2712 if ((bUseEscher == true) && (eType == sw::Frame::eFormControl))
2713 {
2714 if ( m_rWW8Export.MiserableFormFieldExportHack( rFrmFmt ) )
2715 return ;
2716 }
2717 }
2718
2719 if (bUseEscher)
2720 {
2721 ASSERT( m_rWW8Export.bWrtWW8, "this has gone horribly wrong" );
2722 // write as escher
2723 m_rWW8Export.AppendFlyInFlys(rFmt, rNdTopLeft);
2724 }
2725 else
2726 {
2727 bool bDone = false;
2728
2729 // Hole vom Node und vom letzten Node die Position in der Section
2730 const SwNodeIndex* pNodeIndex = rFrmFmt.GetCntnt().GetCntntIdx();
2731
2732 sal_uLong nStt = pNodeIndex ? pNodeIndex->GetIndex()+1 : 0;
2733 sal_uLong nEnd = pNodeIndex ? pNodeIndex->GetNode().EndOfSectionIndex() : 0;
2734
2735 if( nStt >= nEnd ) // kein Bereich, also kein gueltiger Node
2736 return;
2737
2738 if ( !m_rWW8Export.IsInTable() && rFmt.IsInline() )
2739 {
2740 //Test to see if this textbox contains only a single graphic/ole
2741 SwTxtNode* pParTxtNode = rAnch.GetCntntAnchor()->nNode.GetNode().GetTxtNode();
2742 if ( pParTxtNode && !m_rWW8Export.pDoc->GetNodes()[ nStt ]->IsNoTxtNode() )
2743 bDone = true;
2744 }
2745 if( !bDone )
2746 {
2747 // ein NICHT zeichengebundener Rahmen liegt vor
2748
2749 // --> OD 2007-04-19 #i43447# - removed
2750 // const SwFmtFrmSize& rS = rFrmFmt.GetFrmSize();
2751 // nFlyWidth = rS.GetWidth(); // Fuer Anpassung Graphic-Groesse
2752 // nFlyHeight = rS.GetHeight();
2753 // <--
2754
2755 m_rWW8Export.SaveData( nStt, nEnd );
2756
2757 Point aOffset;
2758 if ( m_rWW8Export.mpParentFrame )
2759 {
2760 /*
2761 #90804#
2762 Munge flys in fly into absolutely positioned elements for
2763 word 6
2764 */
2765 const SwTxtNode* pParTxtNode = rAnch.GetCntntAnchor()->nNode.GetNode().GetTxtNode();
2766 const SwRect aPageRect = pParTxtNode->FindPageFrmRect( sal_False, 0, sal_False );
2767
2768 aOffset = rFrmFmt.FindLayoutRect().Pos();
2769 aOffset -= aPageRect.Pos();
2770
2771 m_rWW8Export.pFlyOffset = &aOffset;
2772 m_rWW8Export.eNewAnchorType = FLY_AT_PAGE;
2773 }
2774
2775 m_rWW8Export.mpParentFrame = &rFmt;
2776 if (
2777 m_rWW8Export.IsInTable() &&
2778 (FLY_AT_PAGE != rAnch.GetAnchorId()) &&
2779 !m_rWW8Export.pDoc->GetNodes()[ nStt ]->IsNoTxtNode()
2780 )
2781 {
2782 // Beachten: Flag bOutTable wieder setzen,
2783 // denn wir geben ja ganz normalen Content der
2784 // Tabelenzelle aus und keinen Rahmen
2785 // (Flag wurde oben in aSaveData() geloescht)
2786 m_rWW8Export.bOutTable = true;
2787 const String& rName = rFrmFmt.GetName();
2788 m_rWW8Export.StartCommentOutput(rName);
2789 m_rWW8Export.WriteText();
2790 m_rWW8Export.EndCommentOutput(rName);
2791 }
2792 else
2793 m_rWW8Export.WriteText();
2794
2795 m_rWW8Export.RestoreData();
2796 }
2797 }
2798 }
2799
OutputFlyFrame(const sw::Frame & rFmt)2800 void AttributeOutputBase::OutputFlyFrame( const sw::Frame& rFmt )
2801 {
2802 if ( !rFmt.GetCntntNode() )
2803 return;
2804
2805 const SwCntntNode &rNode = *rFmt.GetCntntNode();
2806 Point aNdPos, aPgPos;
2807 Point* pLayPos;
2808 bool bValidNdPos = false, bValidPgPos = false;
2809
2810 if (FLY_AT_PAGE == rFmt.GetFrmFmt().GetAnchor().GetAnchorId())
2811 {
2812 // get the Layout Node-Position.
2813 if ( !bValidPgPos )
2814 {
2815 aPgPos = rNode.FindPageFrmRect(false, &aPgPos).Pos();
2816 bValidPgPos = true;
2817 }
2818 pLayPos = &aPgPos;
2819 }
2820 else
2821 {
2822 // get the Layout Node-Position.
2823 if ( !bValidNdPos )
2824 {
2825 aNdPos = rNode.FindLayoutRect(false, &aNdPos).Pos();
2826 bValidNdPos = true;
2827 }
2828 pLayPos = &aNdPos;
2829 }
2830
2831 OutputFlyFrame_Impl( rFmt, *pLayPos );
2832 }
2833
2834 // write data of any redline
Redline(const SwRedlineData * pRedline)2835 void WW8AttributeOutput::Redline( const SwRedlineData* pRedline )
2836 {
2837 if ( !pRedline )
2838 return;
2839
2840 if ( pRedline->Next() )
2841 Redline( pRedline->Next() );
2842
2843 static sal_uInt16 __READONLY_DATA aSprmIds[ 2 * 2 * 3 ] =
2844 {
2845 // Ids for insert
2846 NS_sprm::LN_CFRMark, NS_sprm::LN_CIbstRMark, NS_sprm::LN_CDttmRMark, // for WW8
2847 0x0042, 0x0045, 0x0046, // for WW6
2848 // Ids for delete
2849 NS_sprm::LN_CFRMarkDel, NS_sprm::LN_CIbstRMarkDel, NS_sprm::LN_CDttmRMarkDel, // for WW8
2850 0x0041, 0x0045, 0x0046 // for WW6
2851 };
2852
2853 const sal_uInt16* pSprmIds = 0;
2854 switch( pRedline->GetType() )
2855 {
2856 case nsRedlineType_t::REDLINE_INSERT:
2857 pSprmIds = aSprmIds;
2858 break;
2859
2860 case nsRedlineType_t::REDLINE_DELETE:
2861 pSprmIds = aSprmIds + (2 * 3);
2862 break;
2863
2864 case nsRedlineType_t::REDLINE_FORMAT:
2865 if( m_rWW8Export.bWrtWW8 )
2866 {
2867 m_rWW8Export.InsUInt16( NS_sprm::LN_CPropRMark );
2868 m_rWW8Export.pO->Insert( 7, m_rWW8Export.pO->Count() ); // len
2869 m_rWW8Export.pO->Insert( 1, m_rWW8Export.pO->Count() );
2870 m_rWW8Export.InsUInt16( m_rWW8Export.AddRedlineAuthor( pRedline->GetAuthor() ) );
2871 m_rWW8Export.InsUInt32( sw::ms::DateTime2DTTM( pRedline->GetTimeStamp() ));
2872 }
2873 break;
2874 default:
2875 ASSERT(sal_False, "Unhandled redline type for export");
2876 break;
2877 }
2878
2879 if ( pSprmIds )
2880 {
2881 if ( !m_rWW8Export.bWrtWW8 )
2882 pSprmIds += 3;
2883
2884 if ( m_rWW8Export.bWrtWW8 )
2885 m_rWW8Export.InsUInt16( pSprmIds[0] );
2886 else
2887 m_rWW8Export.pO->Insert( msword_cast<sal_uInt8>(pSprmIds[0]), m_rWW8Export.pO->Count() );
2888 m_rWW8Export.pO->Insert( 1, m_rWW8Export.pO->Count() );
2889
2890 if ( m_rWW8Export.bWrtWW8 )
2891 m_rWW8Export.InsUInt16( pSprmIds[1] );
2892 else
2893 m_rWW8Export.pO->Insert( msword_cast<sal_uInt8>(pSprmIds[1]), m_rWW8Export.pO->Count() );
2894 m_rWW8Export.InsUInt16( m_rWW8Export.AddRedlineAuthor( pRedline->GetAuthor() ) );
2895
2896 if ( m_rWW8Export.bWrtWW8 )
2897 m_rWW8Export.InsUInt16( pSprmIds[2] );
2898 else
2899 m_rWW8Export.pO->Insert( msword_cast<sal_uInt8>(pSprmIds[2]), m_rWW8Export.pO->Count() );
2900 m_rWW8Export.InsUInt32( sw::ms::DateTime2DTTM( pRedline->GetTimeStamp() ));
2901 }
2902 }
2903
2904 /* */
2905
OutputContentNode(const SwCntntNode & rNode)2906 void MSWordExportBase::OutputContentNode( const SwCntntNode& rNode )
2907 {
2908 switch ( rNode.GetNodeType() )
2909 {
2910 case ND_TEXTNODE:
2911 {
2912 const SwTxtNode& rTextNode = *rNode.GetTxtNode();
2913 if( !mbOutOutlineOnly || rTextNode.IsOutline() )
2914 OutputTextNode( rTextNode );
2915 }
2916 break;
2917 case ND_GRFNODE:
2918 OutputGrfNode( *rNode.GetGrfNode() );
2919 break;
2920 case ND_OLENODE:
2921 OutputOLENode( *rNode.GetOLENode() );
2922 break;
2923 default:
2924 #if OSL_DEBUG_LEVEL > 0
2925 OSL_TRACE("Unhandled node, type == %d\n", rNode.GetNodeType() );
2926 #endif
2927 break;
2928 }
2929 }
2930
2931 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
2932