Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <deque>
21 :
22 : #include <hintids.hxx>
23 :
24 : #include <com/sun/star/i18n/ScriptType.hpp>
25 : #include <editeng/twolinesitem.hxx>
26 : #include <editeng/charrotateitem.hxx>
27 : #include <vcl/outdev.hxx>
28 : #include <fmtfld.hxx>
29 : #include <fldbas.hxx>
30 : #include <txatbase.hxx>
31 : #include <fmtruby.hxx>
32 : #include <txtatr.hxx>
33 : #include <charfmt.hxx>
34 : #include <txtinet.hxx>
35 : #include <fchrfmt.hxx>
36 : #include <layfrm.hxx>
37 : #include <SwPortionHandler.hxx>
38 : #include <pormulti.hxx>
39 : #include <inftxt.hxx>
40 : #include <itrpaint.hxx>
41 : #include <viewopt.hxx>
42 : #include <itrform2.hxx>
43 : #include <porfld.hxx>
44 : #include <porglue.hxx>
45 : #include <breakit.hxx>
46 : #include <pagefrm.hxx>
47 : #include <rowfrm.hxx>
48 : #include <pagedesc.hxx>
49 : #include <tgrditem.hxx>
50 : #include <swtable.hxx>
51 : #include <fmtfsize.hxx>
52 :
53 : using namespace ::com::sun::star;
54 :
55 : /*--------------------------------------------------
56 : * class SwMultiPortion
57 : *
58 : * A SwMultiPortion is not a simple portion,
59 : * it's a container, which contains almost a SwLineLayoutPortion.
60 : * This SwLineLayout could be followed by other textportions via pPortion
61 : * and by another SwLineLayout via pNext to realize a doubleline portion.
62 : * --------------------------------------------------*/
63 :
64 0 : SwMultiPortion::~SwMultiPortion()
65 : {
66 0 : delete pFldRest;
67 0 : }
68 :
69 0 : void SwMultiPortion::Paint( const SwTxtPaintInfo & ) const
70 : {
71 : OSL_FAIL( "Don't try SwMultiPortion::Paint, try SwTxtPainter::PaintMultiPortion" );
72 0 : }
73 :
74 : /*--------------------------------------------------
75 : * Summarize the internal lines to calculate the (external) size.
76 : * The internal line has to calculate first.
77 : * --------------------------------------------------*/
78 :
79 0 : void SwMultiPortion::CalcSize( SwTxtFormatter& rLine, SwTxtFormatInfo &rInf )
80 : {
81 0 : Width( 0 );
82 0 : Height( 0 );
83 0 : SetAscent( 0 );
84 0 : SetFlyInCntnt( false );
85 0 : SwLineLayout *pLay = &GetRoot();
86 0 : do
87 : {
88 0 : pLay->CalcLine( rLine, rInf );
89 0 : if( rLine.IsFlyInCntBase() )
90 0 : SetFlyInCntnt( true );
91 0 : if( IsRuby() && ( OnTop() == ( pLay == &GetRoot() ) ) )
92 : {
93 : // An empty phonetic line don't need an ascent or a height.
94 0 : if( !pLay->Width() )
95 : {
96 0 : pLay->SetAscent( 0 );
97 0 : pLay->Height( 0 );
98 : }
99 0 : if( OnTop() )
100 0 : SetAscent( GetAscent() + pLay->Height() );
101 : }
102 : else
103 0 : SetAscent( GetAscent() + pLay->GetAscent() );
104 0 : Height( Height() + pLay->Height() );
105 0 : if( Width() < pLay->Width() )
106 0 : Width( pLay->Width() );
107 0 : pLay = pLay->GetNext();
108 : } while ( pLay );
109 0 : if( HasBrackets() )
110 : {
111 0 : KSHORT nTmp = ((SwDoubleLinePortion*)this)->GetBrackets()->nHeight;
112 0 : if( nTmp > Height() )
113 : {
114 0 : KSHORT nAdd = ( nTmp - Height() ) / 2;
115 0 : GetRoot().SetAscent( GetRoot().GetAscent() + nAdd );
116 0 : GetRoot().Height( GetRoot().Height() + nAdd );
117 0 : Height( nTmp );
118 : }
119 0 : nTmp = ((SwDoubleLinePortion*)this)->GetBrackets()->nAscent;
120 0 : if( nTmp > GetAscent() )
121 0 : SetAscent( nTmp );
122 : }
123 0 : }
124 :
125 0 : long SwMultiPortion::CalcSpacing( long , const SwTxtSizeInfo & ) const
126 : {
127 0 : return 0;
128 : }
129 :
130 0 : bool SwMultiPortion::ChgSpaceAdd( SwLineLayout*, long ) const
131 : {
132 0 : return false;
133 : }
134 :
135 : /*************************************************************************
136 : * virtual SwMultiPortion::HandlePortion()
137 : *************************************************************************/
138 :
139 0 : void SwMultiPortion::HandlePortion( SwPortionHandler& rPH ) const
140 : {
141 0 : rPH.Text( GetLen(), GetWhichPor() );
142 0 : }
143 :
144 : /*--------------------------------------------------
145 : * SwMultiPortion::ActualizeTabulator()
146 : * sets the tabulator-flag, if there's any tabulator-portion inside.
147 : * --------------------------------------------------*/
148 :
149 0 : void SwMultiPortion::ActualizeTabulator()
150 : {
151 0 : SwLinePortion* pPor = GetRoot().GetFirstPortion();
152 : // First line
153 0 : for( bTab1 = bTab2 = false; pPor; pPor = pPor->GetPortion() )
154 0 : if( pPor->InTabGrp() )
155 0 : SetTab1( true );
156 0 : if( GetRoot().GetNext() )
157 : {
158 : // Second line
159 0 : pPor = GetRoot().GetNext()->GetFirstPortion();
160 0 : do
161 : {
162 0 : if( pPor->InTabGrp() )
163 0 : SetTab2( true );
164 0 : pPor = pPor->GetPortion();
165 : } while ( pPor );
166 : }
167 0 : }
168 :
169 : /*--------------------------------------------------
170 : * SwRotatedPortion::SwRotatedPortion(..)
171 : * --------------------------------------------------*/
172 :
173 0 : SwRotatedPortion::SwRotatedPortion( const SwMultiCreator& rCreate,
174 0 : sal_Int32 nEnd, bool bRTL ) : SwMultiPortion( nEnd )
175 : {
176 0 : const SvxCharRotateItem* pRot = (SvxCharRotateItem*)rCreate.pItem;
177 0 : if( !pRot )
178 : {
179 0 : const SwTxtAttr& rAttr = *rCreate.pAttr;
180 : const SfxPoolItem *const pItem =
181 0 : CharFmt::GetItem(rAttr, RES_CHRATR_ROTATE);
182 0 : if ( pItem )
183 : {
184 0 : pRot = static_cast<const SvxCharRotateItem*>(pItem);
185 : }
186 : }
187 0 : if( pRot )
188 : {
189 : sal_uInt8 nDir;
190 0 : if ( bRTL )
191 0 : nDir = pRot->IsBottomToTop() ? 3 : 1;
192 : else
193 0 : nDir = pRot->IsBottomToTop() ? 1 : 3;
194 :
195 0 : SetDirection( nDir );
196 : }
197 0 : }
198 :
199 : /*---------------------------------------------------
200 : * SwBidiPortion::SwBidiPortion(..)
201 : * --------------------------------------------------*/
202 :
203 0 : SwBidiPortion::SwBidiPortion( sal_Int32 nEnd, sal_uInt8 nLv )
204 0 : : SwMultiPortion( nEnd ), nLevel( nLv )
205 : {
206 0 : SetBidi();
207 :
208 0 : if ( nLevel % 2 )
209 0 : SetDirection( DIR_RIGHT2LEFT );
210 : else
211 0 : SetDirection( DIR_LEFT2RIGHT );
212 0 : }
213 :
214 0 : long SwBidiPortion::CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo& rInf ) const
215 : {
216 0 : return HasTabulator() ? 0 : GetSpaceCnt(rInf) * nSpaceAdd / SPACING_PRECISION_FACTOR;
217 : }
218 :
219 0 : bool SwBidiPortion::ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const
220 : {
221 0 : if( !HasTabulator() && nSpaceAdd > 0 && !pCurr->IsSpaceAdd() )
222 : {
223 0 : pCurr->CreateSpaceAdd();
224 0 : pCurr->SetLLSpaceAdd( nSpaceAdd, 0 );
225 0 : return true;
226 : }
227 :
228 0 : return false;
229 : }
230 :
231 0 : sal_Int32 SwBidiPortion::GetSpaceCnt( const SwTxtSizeInfo &rInf ) const
232 : {
233 : // Calculate number of blanks for justified alignment
234 0 : SwLinePortion* pPor = GetRoot().GetFirstPortion();
235 0 : sal_Int32 nTmpStart = rInf.GetIdx();
236 0 : sal_Int32 nNull = 0;
237 : sal_Int32 nBlanks;
238 :
239 0 : for( nBlanks = 0; pPor; pPor = pPor->GetPortion() )
240 : {
241 0 : if( pPor->InTxtGrp() )
242 0 : nBlanks = nBlanks + ((SwTxtPortion*)pPor)->GetSpaceCnt( rInf, nNull );
243 0 : else if ( pPor->IsMultiPortion() &&
244 0 : ((SwMultiPortion*)pPor)->IsBidi() )
245 0 : nBlanks = nBlanks + ((SwBidiPortion*)pPor)->GetSpaceCnt( rInf );
246 :
247 0 : ((SwTxtSizeInfo &)rInf).SetIdx( rInf.GetIdx() + pPor->GetLen() );
248 : }
249 0 : ((SwTxtSizeInfo &)rInf).SetIdx( nTmpStart );
250 0 : return nBlanks;
251 : }
252 :
253 : /*--------------------------------------------------
254 : * SwDoubleLinePortion::SwDoubleLinePortion(..)
255 : * This constructor is for the continuation of a doubleline portion
256 : * in the next line.
257 : * It takes the same brackets and if the original has no content except
258 : * brackets, these will be deleted.
259 : * --------------------------------------------------*/
260 :
261 0 : SwDoubleLinePortion::SwDoubleLinePortion(SwDoubleLinePortion& rDouble, sal_Int32 nEnd)
262 : : SwMultiPortion(nEnd)
263 : , pBracket(0)
264 : , nLineDiff(0)
265 : , nBlank1(0)
266 0 : , nBlank2(0)
267 : {
268 0 : SetDirection( rDouble.GetDirection() );
269 0 : SetDouble();
270 0 : if( rDouble.GetBrackets() )
271 : {
272 0 : SetBrackets( rDouble );
273 : // An empty multiportion needs no brackets.
274 : // Notice: GetLen() might be zero, if the multiportion contains
275 : // the second part of a field and the width might be zero, if
276 : // it contains a note only. In this cases the brackets are okay.
277 : // But if the length and the width are both zero, the portion
278 : // is really empty.
279 0 : if( rDouble.Width() == rDouble.BracketWidth() )
280 0 : rDouble.ClearBrackets();
281 : }
282 0 : }
283 :
284 : /*--------------------------------------------------
285 : * SwDoubleLinePortion::SwDoubleLinePortion(..)
286 : * This constructor uses the textattribut to get the right brackets.
287 : * The textattribut could be a 2-line-attribute or a character- or
288 : * internetstyle, which contains the 2-line-attribute.
289 : * --------------------------------------------------*/
290 :
291 0 : SwDoubleLinePortion::SwDoubleLinePortion(const SwMultiCreator& rCreate, sal_Int32 nEnd)
292 : : SwMultiPortion(nEnd)
293 : , pBracket(new SwBracket())
294 : , nLineDiff(0)
295 : , nBlank1(0)
296 0 : , nBlank2(0)
297 : {
298 0 : SetDouble();
299 0 : const SvxTwoLinesItem* pTwo = (SvxTwoLinesItem*)rCreate.pItem;
300 0 : if( pTwo )
301 0 : pBracket->nStart = 0;
302 : else
303 : {
304 0 : const SwTxtAttr& rAttr = *rCreate.pAttr;
305 0 : pBracket->nStart = *rAttr.GetStart();
306 :
307 : const SfxPoolItem * const pItem =
308 0 : CharFmt::GetItem( rAttr, RES_CHRATR_TWO_LINES );
309 0 : if ( pItem )
310 : {
311 0 : pTwo = static_cast<const SvxTwoLinesItem*>(pItem);
312 : }
313 : }
314 0 : if( pTwo )
315 : {
316 0 : pBracket->cPre = pTwo->GetStartBracket();
317 0 : pBracket->cPost = pTwo->GetEndBracket();
318 : }
319 : else
320 : {
321 0 : pBracket->cPre = 0;
322 0 : pBracket->cPost = 0;
323 : }
324 0 : sal_uInt8 nTmp = SW_SCRIPTS;
325 0 : if( pBracket->cPre > 255 )
326 : {
327 0 : OUString aTxt = OUString(pBracket->cPre);
328 0 : nTmp = SwScriptInfo::WhichFont( 0, &aTxt, 0 );
329 : }
330 0 : pBracket->nPreScript = nTmp;
331 0 : nTmp = SW_SCRIPTS;
332 0 : if( pBracket->cPost > 255 )
333 : {
334 0 : OUString aTxt = OUString(pBracket->cPost);
335 0 : nTmp = SwScriptInfo::WhichFont( 0, &aTxt, 0 );
336 : }
337 0 : pBracket->nPostScript = nTmp;
338 :
339 0 : if( !pBracket->cPre && !pBracket->cPost )
340 : {
341 0 : delete pBracket;
342 0 : pBracket = 0;
343 : }
344 :
345 : // double line portions have the same direction as the frame directions
346 0 : if ( rCreate.nLevel % 2 )
347 0 : SetDirection( DIR_RIGHT2LEFT );
348 : else
349 0 : SetDirection( DIR_LEFT2RIGHT );
350 0 : }
351 :
352 : /*--------------------------------------------------
353 : * SwMultiPortion::PaintBracket paints the wished bracket,
354 : * if the multiportion has surrounding brackets.
355 : * The X-position of the SwTxtPaintInfo will be modified:
356 : * the open bracket sets position behind itself,
357 : * the close bracket in front of itself.
358 : * --------------------------------------------------*/
359 :
360 0 : void SwDoubleLinePortion::PaintBracket( SwTxtPaintInfo &rInf,
361 : long nSpaceAdd,
362 : bool bOpen ) const
363 : {
364 0 : sal_Unicode cCh = bOpen ? pBracket->cPre : pBracket->cPost;
365 0 : if( !cCh )
366 0 : return;
367 0 : KSHORT nChWidth = bOpen ? PreWidth() : PostWidth();
368 0 : if( !nChWidth )
369 0 : return;
370 0 : if( !bOpen )
371 0 : rInf.X( rInf.X() + Width() - PostWidth() +
372 0 : ( nSpaceAdd > 0 ? CalcSpacing( nSpaceAdd, rInf ) : 0 ) );
373 :
374 0 : SwBlankPortion aBlank( cCh, true );
375 0 : aBlank.SetAscent( pBracket->nAscent );
376 0 : aBlank.Width( nChWidth );
377 0 : aBlank.Height( pBracket->nHeight );
378 : {
379 0 : SwFont* pTmpFnt = new SwFont( *rInf.GetFont() );
380 0 : sal_uInt8 nAct = bOpen ? pBracket->nPreScript : pBracket->nPostScript;
381 0 : if( SW_SCRIPTS > nAct )
382 0 : pTmpFnt->SetActual( nAct );
383 0 : pTmpFnt->SetProportion( 100 );
384 0 : SwFontSave aSave( rInf, pTmpFnt );
385 0 : aBlank.Paint( rInf );
386 0 : delete pTmpFnt;
387 : }
388 0 : if( bOpen )
389 0 : rInf.X( rInf.X() + PreWidth() );
390 : }
391 :
392 : /*--------------------------------------------------
393 : * SwDoubleLinePortion::SetBrackets creates the bracket-structur
394 : * and fills it, if not both characters are 0x00.
395 : * --------------------------------------------------*/
396 :
397 0 : void SwDoubleLinePortion::SetBrackets( const SwDoubleLinePortion& rDouble )
398 : {
399 0 : if( rDouble.pBracket )
400 : {
401 0 : pBracket = new SwBracket;
402 0 : pBracket->cPre = rDouble.pBracket->cPre;
403 0 : pBracket->cPost = rDouble.pBracket->cPost;
404 0 : pBracket->nPreScript = rDouble.pBracket->nPreScript;
405 0 : pBracket->nPostScript = rDouble.pBracket->nPostScript;
406 0 : pBracket->nStart = rDouble.pBracket->nStart;
407 : }
408 0 : }
409 :
410 : /*--------------------------------------------------
411 : * SwDoubleLinePortion::FormatBrackets
412 : * calculates the size of the brackets => pBracket,
413 : * reduces the nMaxWidth-parameter ( minus bracket-width )
414 : * and moves the rInf-x-position behind the opening bracket.
415 : * --------------------------------------------------*/
416 :
417 0 : void SwDoubleLinePortion::FormatBrackets( SwTxtFormatInfo &rInf, SwTwips& nMaxWidth )
418 : {
419 0 : nMaxWidth -= rInf.X();
420 0 : SwFont* pTmpFnt = new SwFont( *rInf.GetFont() );
421 0 : pTmpFnt->SetProportion( 100 );
422 0 : pBracket->nAscent = 0;
423 0 : pBracket->nHeight = 0;
424 0 : if( pBracket->cPre )
425 : {
426 0 : OUString aStr( pBracket->cPre );
427 0 : sal_uInt8 nActualScr = pTmpFnt->GetActual();
428 0 : if( SW_SCRIPTS > pBracket->nPreScript )
429 0 : pTmpFnt->SetActual( pBracket->nPreScript );
430 0 : SwFontSave aSave( rInf, pTmpFnt );
431 0 : SwPosSize aSize = rInf.GetTxtSize( aStr );
432 0 : pBracket->nAscent = rInf.GetAscent();
433 0 : pBracket->nHeight = aSize.Height();
434 0 : pTmpFnt->SetActual( nActualScr );
435 0 : if( nMaxWidth > aSize.Width() )
436 : {
437 0 : pBracket->nPreWidth = aSize.Width();
438 0 : nMaxWidth -= aSize.Width();
439 0 : rInf.X( rInf.X() + aSize.Width() );
440 : }
441 : else
442 : {
443 0 : pBracket->nPreWidth = 0;
444 0 : nMaxWidth = 0;
445 0 : }
446 : }
447 : else
448 0 : pBracket->nPreWidth = 0;
449 0 : if( pBracket->cPost )
450 : {
451 0 : OUString aStr( pBracket->cPost );
452 0 : if( SW_SCRIPTS > pBracket->nPostScript )
453 0 : pTmpFnt->SetActual( pBracket->nPostScript );
454 0 : SwFontSave aSave( rInf, pTmpFnt );
455 0 : SwPosSize aSize = rInf.GetTxtSize( aStr );
456 0 : KSHORT nTmpAsc = rInf.GetAscent();
457 0 : if( nTmpAsc > pBracket->nAscent )
458 : {
459 0 : pBracket->nHeight += nTmpAsc - pBracket->nAscent;
460 0 : pBracket->nAscent = nTmpAsc;
461 : }
462 0 : if( aSize.Height() > pBracket->nHeight )
463 0 : pBracket->nHeight = aSize.Height();
464 0 : if( nMaxWidth > aSize.Width() )
465 : {
466 0 : pBracket->nPostWidth = aSize.Width();
467 0 : nMaxWidth -= aSize.Width();
468 : }
469 : else
470 : {
471 0 : pBracket->nPostWidth = 0;
472 0 : nMaxWidth = 0;
473 0 : }
474 : }
475 : else
476 0 : pBracket->nPostWidth = 0;
477 0 : nMaxWidth += rInf.X();
478 0 : delete(pTmpFnt);
479 0 : }
480 :
481 : /*--------------------------------------------------
482 : * SwDoubleLinePortion::CalcBlanks
483 : * calculates the number of blanks in each line and
484 : * the difference of the width of the two lines.
485 : * These results are used from the text adjustment.
486 : * --------------------------------------------------*/
487 :
488 0 : void SwDoubleLinePortion::CalcBlanks( SwTxtFormatInfo &rInf )
489 : {
490 0 : SwLinePortion* pPor = GetRoot().GetFirstPortion();
491 0 : sal_Int32 nNull = 0;
492 0 : sal_Int32 nStart = rInf.GetIdx();
493 0 : SetTab1( false );
494 0 : SetTab2( false );
495 0 : for( nBlank1 = 0; pPor; pPor = pPor->GetPortion() )
496 : {
497 0 : if( pPor->InTxtGrp() )
498 0 : nBlank1 = nBlank1 + ((SwTxtPortion*)pPor)->GetSpaceCnt( rInf, nNull );
499 0 : rInf.SetIdx( rInf.GetIdx() + pPor->GetLen() );
500 0 : if( pPor->InTabGrp() )
501 0 : SetTab1( true );
502 : }
503 0 : nLineDiff = GetRoot().Width();
504 0 : if( GetRoot().GetNext() )
505 : {
506 0 : pPor = GetRoot().GetNext()->GetFirstPortion();
507 0 : nLineDiff -= GetRoot().GetNext()->Width();
508 : }
509 0 : for( nBlank2 = 0; pPor; pPor = pPor->GetPortion() )
510 : {
511 0 : if( pPor->InTxtGrp() )
512 0 : nBlank2 = nBlank2 + ((SwTxtPortion*)pPor)->GetSpaceCnt( rInf, nNull );
513 0 : rInf.SetIdx( rInf.GetIdx() + pPor->GetLen() );
514 0 : if( pPor->InTabGrp() )
515 0 : SetTab2( true );
516 : }
517 0 : rInf.SetIdx( nStart );
518 0 : }
519 :
520 0 : long SwDoubleLinePortion::CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo & ) const
521 : {
522 0 : return HasTabulator() ? 0 : GetSpaceCnt() * nSpaceAdd / SPACING_PRECISION_FACTOR;
523 : }
524 :
525 : /*--------------------------------------------------
526 : * SwDoubleLinePortion::ChangeSpaceAdd(..)
527 : * merges the spaces for text adjustment from the inner and outer part.
528 : * Inside the doubleline portion the wider line has no spaceadd-array, the
529 : * smaller line has such an array to reach width of the wider line.
530 : * If the surrounding line has text adjustment and the doubleline portion
531 : * contains no tabulator, it is necessary to create/manipulate the inner
532 : * space arrays.
533 : * --------------------------------------------------*/
534 :
535 0 : bool SwDoubleLinePortion::ChgSpaceAdd( SwLineLayout* pCurr,
536 : long nSpaceAdd ) const
537 : {
538 0 : bool bRet = false;
539 0 : if( !HasTabulator() && nSpaceAdd > 0 )
540 : {
541 0 : if( !pCurr->IsSpaceAdd() )
542 : {
543 : // The wider line gets the spaceadd from the surrounding line direct
544 0 : pCurr->CreateSpaceAdd();
545 0 : pCurr->SetLLSpaceAdd( nSpaceAdd, 0 );
546 0 : bRet = true;
547 : }
548 : else
549 : {
550 0 : sal_Int32 nMyBlank = GetSmallerSpaceCnt();
551 0 : sal_Int32 nOther = GetSpaceCnt();
552 0 : SwTwips nMultiSpace = pCurr->GetLLSpaceAdd( 0 ) * nMyBlank + nOther * nSpaceAdd;
553 :
554 0 : if( nMyBlank )
555 0 : nMultiSpace /= nMyBlank;
556 :
557 0 : if( nMultiSpace < KSHRT_MAX * SPACING_PRECISION_FACTOR )
558 : {
559 : // pCurr->SetLLSpaceAdd( nMultiSpace, 0 );
560 : // #i65711# SetLLSpaceAdd replaces the first value,
561 : // instead we want to insert a new first value:
562 0 : std::vector<long>* pVec = pCurr->GetpLLSpaceAdd();
563 0 : pVec->insert( pVec->begin(), nMultiSpace );
564 0 : bRet = true;
565 : }
566 : }
567 : }
568 0 : return bRet;
569 : }
570 : /*--------------------------------------------------
571 : * SwDoubleLinePortion::ResetSpaceAdd(..)
572 : * cancels the manipulation from SwDoubleLinePortion::ChangeSpaceAdd(..)
573 : * --------------------------------------------------*/
574 :
575 0 : void SwDoubleLinePortion::ResetSpaceAdd( SwLineLayout* pCurr )
576 : {
577 0 : pCurr->RemoveFirstLLSpaceAdd();;
578 0 : if( !pCurr->GetLLSpaceAddCount() )
579 0 : pCurr->FinishSpaceAdd();
580 0 : }
581 :
582 0 : SwDoubleLinePortion::~SwDoubleLinePortion()
583 : {
584 0 : delete pBracket;
585 0 : }
586 :
587 : /*--------------------------------------------------
588 : * SwRubyPortion::SwRubyPortion(..)
589 : * constructs a ruby portion, i.e. an additional text is displayed
590 : * beside the main text, e.g. phonetic characters.
591 : * --------------------------------------------------*/
592 :
593 0 : SwRubyPortion::SwRubyPortion( const SwRubyPortion& rRuby, sal_Int32 nEnd ) :
594 : SwMultiPortion( nEnd ),
595 0 : nRubyOffset( rRuby.GetRubyOffset() ),
596 0 : nAdjustment( rRuby.GetAdjustment() )
597 : {
598 0 : SetDirection( rRuby.GetDirection() ),
599 0 : SetTop( rRuby.OnTop() );
600 0 : SetRuby();
601 0 : }
602 :
603 : /*--------------------------------------------------
604 : * SwRubyPortion::SwRubyPortion(..)
605 : * constructs a ruby portion, i.e. an additional text is displayed
606 : * beside the main text, e.g. phonetic characters.
607 : * --------------------------------------------------*/
608 :
609 0 : SwRubyPortion::SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
610 : const IDocumentSettingAccess& rIDocumentSettingAccess,
611 : sal_Int32 nEnd, sal_Int32 nOffs,
612 : const bool* pForceRubyPos )
613 0 : : SwMultiPortion( nEnd )
614 : {
615 0 : SetRuby();
616 : OSL_ENSURE( SW_MC_RUBY == rCreate.nId, "Ruby expected" );
617 : OSL_ENSURE( RES_TXTATR_CJK_RUBY == rCreate.pAttr->Which(), "Wrong attribute" );
618 0 : const SwFmtRuby& rRuby = rCreate.pAttr->GetRuby();
619 0 : nAdjustment = rRuby.GetAdjustment();
620 0 : nRubyOffset = nOffs;
621 :
622 : // in grid mode we force the ruby text to the upper or lower line
623 0 : if ( pForceRubyPos )
624 0 : SetTop( *pForceRubyPos );
625 : else
626 0 : SetTop( ! rRuby.GetPosition() );
627 :
628 0 : const SwCharFmt* pFmt = ((SwTxtRuby*)rCreate.pAttr)->GetCharFmt();
629 : SwFont *pRubyFont;
630 0 : if( pFmt )
631 : {
632 0 : const SwAttrSet& rSet = pFmt->GetAttrSet();
633 0 : pRubyFont = new SwFont( rFnt );
634 0 : pRubyFont->SetDiffFnt( &rSet, &rIDocumentSettingAccess );
635 :
636 : // we do not allow a vertical font for the ruby text
637 0 : pRubyFont->SetVertical( rFnt.GetOrientation() );
638 : }
639 : else
640 0 : pRubyFont = NULL;
641 :
642 0 : OUString aStr = rRuby.GetText().copy( nOffs );
643 0 : SwFldPortion *pFld = new SwFldPortion( aStr, pRubyFont );
644 0 : pFld->SetNextOffset( nOffs );
645 0 : pFld->SetFollow( true );
646 :
647 0 : if( OnTop() )
648 0 : GetRoot().SetPortion( pFld );
649 : else
650 : {
651 0 : GetRoot().SetNext( new SwLineLayout() );
652 0 : GetRoot().GetNext()->SetPortion( pFld );
653 : }
654 :
655 : // ruby portions have the same direction as the frame directions
656 0 : if ( rCreate.nLevel % 2 )
657 : {
658 : // switch right and left ruby adjustment in rtl environment
659 0 : if ( 0 == nAdjustment )
660 0 : nAdjustment = 2;
661 0 : else if ( 2 == nAdjustment )
662 0 : nAdjustment = 0;
663 :
664 0 : SetDirection( DIR_RIGHT2LEFT );
665 : }
666 : else
667 0 : SetDirection( DIR_LEFT2RIGHT );
668 0 : }
669 :
670 : /*--------------------------------------------------
671 : * SwRubyPortion::_Adjust(..)
672 : * In ruby portion there are different alignments for
673 : * the ruby text and the main text.
674 : * Left, right, centered and two possibilities of block adjustment
675 : * The block adjustment is realized by spacing between the characteres,
676 : * either with a half space or no space in front of the first letter and
677 : * a half space at the end of the last letter.
678 : * Notice: the smaller line will be manipulated, normally it's the ruby line,
679 : * but it could be the main text, too.
680 : * If there is a tabulator in smaller line, no adjustment is possible.
681 : * --------------------------------------------------*/
682 :
683 0 : void SwRubyPortion::_Adjust( SwTxtFormatInfo &rInf )
684 : {
685 0 : SwTwips nLineDiff = GetRoot().Width() - GetRoot().GetNext()->Width();
686 0 : sal_Int32 nOldIdx = rInf.GetIdx();
687 0 : if( !nLineDiff )
688 0 : return;
689 : SwLineLayout *pCurr;
690 0 : if( nLineDiff < 0 )
691 : { // The first line has to be adjusted.
692 0 : if( GetTab1() )
693 0 : return;
694 0 : pCurr = &GetRoot();
695 0 : nLineDiff = -nLineDiff;
696 : }
697 : else
698 : { // The second line has to be adjusted.
699 0 : if( GetTab2() )
700 0 : return;
701 0 : pCurr = GetRoot().GetNext();
702 0 : rInf.SetIdx( nOldIdx + GetRoot().GetLen() );
703 : }
704 0 : KSHORT nLeft = 0; // the space in front of the first letter
705 0 : KSHORT nRight = 0; // the space at the end of the last letter
706 0 : sal_uInt16 nSub = 0;
707 0 : switch ( nAdjustment )
708 : {
709 0 : case 1: nRight = static_cast<sal_uInt16>(nLineDiff / 2); // no break
710 0 : case 2: nLeft = static_cast<sal_uInt16>(nLineDiff - nRight); break;
711 0 : case 3: nSub = 1; // no break
712 : case 4:
713 : {
714 0 : sal_Int32 nCharCnt = 0;
715 : SwLinePortion *pPor;
716 0 : for( pPor = pCurr->GetFirstPortion(); pPor; pPor = pPor->GetPortion() )
717 : {
718 0 : if( pPor->InTxtGrp() )
719 0 : ((SwTxtPortion*)pPor)->GetSpaceCnt( rInf, nCharCnt );
720 0 : rInf.SetIdx( rInf.GetIdx() + pPor->GetLen() );
721 : }
722 0 : if( nCharCnt > nSub )
723 : {
724 0 : SwTwips nCalc = nLineDiff / ( nCharCnt - nSub );
725 : short nTmp;
726 0 : if( nCalc < SHRT_MAX )
727 0 : nTmp = -short(nCalc);
728 : else
729 0 : nTmp = SHRT_MIN;
730 :
731 0 : pCurr->CreateSpaceAdd( SPACING_PRECISION_FACTOR * nTmp );
732 0 : nLineDiff -= nCalc * ( nCharCnt - 1 );
733 : }
734 0 : if( nLineDiff > 1 )
735 : {
736 0 : nRight = static_cast<sal_uInt16>(nLineDiff / 2);
737 0 : nLeft = static_cast<sal_uInt16>(nLineDiff - nRight);
738 : }
739 0 : break;
740 : }
741 : default: OSL_FAIL( "New ruby adjustment" );
742 : }
743 0 : if( nLeft || nRight )
744 : {
745 0 : if( !pCurr->GetPortion() )
746 0 : pCurr->SetPortion( new SwTxtPortion( *pCurr ) );
747 0 : if( nLeft )
748 : {
749 0 : SwMarginPortion *pMarg = new SwMarginPortion( 0 );
750 0 : pMarg->AddPrtWidth( nLeft );
751 0 : pMarg->SetPortion( pCurr->GetPortion() );
752 0 : pCurr->SetPortion( pMarg );
753 : }
754 0 : if( nRight )
755 : {
756 0 : SwMarginPortion *pMarg = new SwMarginPortion( 0 );
757 0 : pMarg->AddPrtWidth( nRight );
758 0 : pCurr->FindLastPortion()->Append( pMarg );
759 : }
760 : }
761 :
762 0 : pCurr->Width( Width() );
763 0 : rInf.SetIdx( nOldIdx );
764 : }
765 :
766 : /*--------------------------------------------------
767 : * CalcRubyOffset()
768 : * has to change the nRubyOffset, if there's a fieldportion
769 : * in the phonetic line.
770 : * The nRubyOffset is the position in the rubystring, where the
771 : * next SwRubyPortion has start the displaying of the phonetics.
772 : * --------------------------------------------------*/
773 :
774 0 : void SwRubyPortion::CalcRubyOffset()
775 : {
776 0 : const SwLineLayout *pCurr = &GetRoot();
777 0 : if( !OnTop() )
778 : {
779 0 : pCurr = pCurr->GetNext();
780 0 : if( !pCurr )
781 0 : return;
782 : }
783 0 : const SwLinePortion *pPor = pCurr->GetFirstPortion();
784 0 : const SwFldPortion *pFld = NULL;
785 0 : while( pPor )
786 : {
787 0 : if( pPor->InFldGrp() )
788 0 : pFld = (SwFldPortion*)pPor;
789 0 : pPor = pPor->GetPortion();
790 : }
791 0 : if( pFld )
792 : {
793 0 : if( pFld->HasFollow() )
794 0 : nRubyOffset = pFld->GetNextOffset();
795 : else
796 0 : nRubyOffset = COMPLETE_STRING;
797 : }
798 : }
799 :
800 : /*--------------------------------------------------
801 : * SwTxtSizeInfo::GetMultiCreator(..)
802 : * If we (e.g. the position rPos) are inside a two-line-attribute or
803 : * a ruby-attribute, the attribute will be returned in a SwMultiCreator-struct,
804 : * otherwise the function returns zero.
805 : * The rPos parameter is set to the end of the multiportion,
806 : * normally this is the end of the attribute,
807 : * but sometimes it is the start of another attribute, which finished or
808 : * interrupts the first attribute.
809 : * E.g. a ruby portion interrupts a 2-line-attribute, a 2-line-attribute
810 : * with different brackets interrupts another 2-line-attribute.
811 : * --------------------------------------------------*/
812 :
813 : /*--------------------------------------------------
814 : * lcl_Has2Lines(..)
815 : * is a little help function for GetMultiCreator(..)
816 : * It extracts the 2-line-format from a 2-line-attribute or a character style.
817 : * The rValue is set to true, if the 2-line-attribute's value is set and
818 : * no 2-line-format reference is passed. If there is a 2-line-format reference,
819 : * then the rValue is set only, if the 2-line-attribute's value is set _and_
820 : * the 2-line-formats has the same brackets.
821 : * --------------------------------------------------*/
822 :
823 0 : static bool lcl_Has2Lines( const SwTxtAttr& rAttr, const SvxTwoLinesItem* &rpRef,
824 : bool &rValue )
825 : {
826 0 : const SfxPoolItem* pItem = CharFmt::GetItem( rAttr, RES_CHRATR_TWO_LINES );
827 0 : if( pItem )
828 : {
829 0 : rValue = ((SvxTwoLinesItem*)pItem)->GetValue();
830 0 : if( !rpRef )
831 0 : rpRef = (SvxTwoLinesItem*)pItem;
832 0 : else if( ((SvxTwoLinesItem*)pItem)->GetEndBracket() !=
833 0 : rpRef->GetEndBracket() ||
834 0 : ((SvxTwoLinesItem*)pItem)->GetStartBracket() !=
835 0 : rpRef->GetStartBracket() )
836 0 : rValue = false;
837 0 : return true;
838 : }
839 0 : return false;
840 : }
841 :
842 : /*--------------------------------------------------
843 : * lcl_HasRotation(..)
844 : * is a little help function for GetMultiCreator(..)
845 : * It extracts the charrotation from a charrotate-attribute or a character style.
846 : * The rValue is set to true, if the charrotate-attribute's value is set and
847 : * no charrotate-format reference is passed.
848 : * If there is a charrotate-format reference, then the rValue is set only,
849 : * if the charrotate-attribute's value is set _and_ identical
850 : * to the charrotate-format's value.
851 : * --------------------------------------------------*/
852 :
853 0 : static bool lcl_HasRotation( const SwTxtAttr& rAttr,
854 : const SvxCharRotateItem* &rpRef, bool &rValue )
855 : {
856 0 : const SfxPoolItem* pItem = CharFmt::GetItem( rAttr, RES_CHRATR_ROTATE );
857 0 : if ( pItem )
858 : {
859 0 : rValue = ((SvxCharRotateItem*)pItem)->GetValue();
860 0 : if( !rpRef )
861 0 : rpRef = (SvxCharRotateItem*)pItem;
862 0 : else if( ((SvxCharRotateItem*)pItem)->GetValue() !=
863 0 : rpRef->GetValue() )
864 0 : rValue = false;
865 0 : return true;
866 : }
867 :
868 0 : return false;
869 : }
870 :
871 0 : SwMultiCreator* SwTxtSizeInfo::GetMultiCreator( sal_Int32 &rPos,
872 : SwMultiPortion* pMulti ) const
873 : {
874 0 : SwScriptInfo& rSI = ((SwParaPortion*)GetParaPortion())->GetScriptInfo();
875 :
876 : // get the last embedding level
877 : sal_uInt8 nCurrLevel;
878 0 : if ( pMulti )
879 : {
880 : OSL_ENSURE( pMulti->IsBidi(), "Nested MultiPortion is not BidiPortion" );
881 : // level associated with bidi-portion;
882 0 : nCurrLevel = ((SwBidiPortion*)pMulti)->GetLevel();
883 : }
884 : else
885 : // no nested bidi portion required
886 0 : nCurrLevel = GetTxtFrm()->IsRightToLeft() ? 1 : 0;
887 :
888 : // check if there is a field at rPos:
889 0 : sal_uInt8 nNextLevel = nCurrLevel;
890 0 : bool bFldBidi = false;
891 :
892 0 : if ( rPos < GetTxt().getLength() && CH_TXTATR_BREAKWORD == GetChar( rPos ) )
893 : {
894 0 : bFldBidi = true;
895 : }
896 : else
897 0 : nNextLevel = rSI.DirType( rPos );
898 :
899 0 : if ( GetTxt().getLength() != rPos && nNextLevel > nCurrLevel )
900 : {
901 0 : rPos = bFldBidi ? rPos + 1 : rSI.NextDirChg( rPos, &nCurrLevel );
902 0 : if ( COMPLETE_STRING == rPos )
903 0 : return NULL;
904 0 : SwMultiCreator *pRet = new SwMultiCreator;
905 0 : pRet->pItem = NULL;
906 0 : pRet->pAttr = NULL;
907 0 : pRet->nId = SW_MC_BIDI;
908 0 : pRet->nLevel = nCurrLevel + 1;
909 0 : return pRet;
910 : }
911 :
912 : // a bidi portion can only contain other bidi portions
913 0 : if ( pMulti )
914 0 : return NULL;
915 :
916 0 : const SvxCharRotateItem* pRotate = NULL;
917 : const SfxPoolItem* pRotItem;
918 0 : if( SFX_ITEM_SET == m_pFrm->GetTxtNode()->GetSwAttrSet().
919 0 : GetItemState( RES_CHRATR_ROTATE, true, &pRotItem ) &&
920 0 : ((SvxCharRotateItem*)pRotItem)->GetValue() )
921 0 : pRotate = (SvxCharRotateItem*)pRotItem;
922 : else
923 0 : pRotItem = NULL;
924 0 : const SvxTwoLinesItem* p2Lines = NULL;
925 0 : const SwTxtNode *pLclTxtNode = m_pFrm->GetTxtNode();
926 0 : if( !pLclTxtNode )
927 0 : return NULL;
928 : const SfxPoolItem* pItem;
929 0 : if( SFX_ITEM_SET == pLclTxtNode->GetSwAttrSet().
930 0 : GetItemState( RES_CHRATR_TWO_LINES, true, &pItem ) &&
931 0 : ((SvxTwoLinesItem*)pItem)->GetValue() )
932 0 : p2Lines = (SvxTwoLinesItem*)pItem;
933 : else
934 0 : pItem = NULL;
935 :
936 0 : const SwpHints *pHints = pLclTxtNode->GetpSwpHints();
937 0 : if( !pHints && !p2Lines && !pRotate )
938 0 : return NULL;
939 0 : const SwTxtAttr *pRuby = NULL;
940 0 : bool bTwo = false;
941 0 : bool bRot = false;
942 0 : sal_uInt16 n2Lines = USHRT_MAX;
943 0 : sal_uInt16 nRotate = USHRT_MAX;
944 0 : sal_uInt16 nCount = pHints ? pHints->Count() : 0;
945 : sal_uInt16 i;
946 0 : for( i = 0; i < nCount; ++i )
947 : {
948 0 : const SwTxtAttr *pTmp = (*pHints)[i];
949 0 : sal_Int32 nStart = *pTmp->GetStart();
950 0 : if( rPos < nStart )
951 0 : break;
952 0 : if( *pTmp->GetAnyEnd() > rPos )
953 : {
954 0 : if( RES_TXTATR_CJK_RUBY == pTmp->Which() )
955 0 : pRuby = pTmp;
956 : else
957 : {
958 0 : const SvxCharRotateItem* pRoTmp = NULL;
959 0 : if( lcl_HasRotation( *pTmp, pRoTmp, bRot ) )
960 : {
961 0 : nRotate = bRot ? i : nCount;
962 0 : pRotate = pRoTmp;
963 : }
964 0 : const SvxTwoLinesItem* p2Tmp = NULL;
965 0 : if( lcl_Has2Lines( *pTmp, p2Tmp, bTwo ) )
966 : {
967 0 : n2Lines = bTwo ? i : nCount;
968 0 : p2Lines = p2Tmp;
969 : }
970 : }
971 : }
972 : }
973 0 : if( pRuby )
974 : { // The winner is ... a ruby attribute and so
975 : // the end of the multiportion is the end of the ruby attribute.
976 0 : rPos = *pRuby->End();
977 0 : SwMultiCreator *pRet = new SwMultiCreator;
978 0 : pRet->pItem = NULL;
979 0 : pRet->pAttr = pRuby;
980 0 : pRet->nId = SW_MC_RUBY;
981 0 : pRet->nLevel = GetTxtFrm()->IsRightToLeft() ? 1 : 0;
982 0 : return pRet;
983 : }
984 0 : if( n2Lines < nCount || ( pItem && pItem == p2Lines &&
985 0 : rPos < GetTxt().getLength() ) )
986 : { // The winner is a 2-line-attribute,
987 : // the end of the multiportion depends on the following attributes...
988 0 : SwMultiCreator *pRet = new SwMultiCreator;
989 :
990 : // We note the endpositions of the 2-line attributes in aEnd as stack
991 0 : std::deque< sal_Int32 > aEnd;
992 :
993 : // The bOn flag signs the state of the last 2-line attribute in the
994 : // aEnd-stack, it is compatible with the winner-attribute or
995 : // it interrupts the other attribute.
996 0 : bool bOn = true;
997 :
998 0 : if( n2Lines < nCount )
999 : {
1000 0 : pRet->pItem = NULL;
1001 0 : pRet->pAttr = (*pHints)[n2Lines];
1002 0 : aEnd.push_front( *pRet->pAttr->End() );
1003 0 : if( pItem )
1004 : {
1005 0 : aEnd.front() = GetTxt().getLength();
1006 0 : bOn = ((SvxTwoLinesItem*)pItem)->GetEndBracket() ==
1007 0 : p2Lines->GetEndBracket() &&
1008 0 : ((SvxTwoLinesItem*)pItem)->GetStartBracket() ==
1009 0 : p2Lines->GetStartBracket();
1010 : }
1011 : }
1012 : else
1013 : {
1014 0 : pRet->pItem = pItem;
1015 0 : pRet->pAttr = NULL;
1016 0 : aEnd.push_front( GetTxt().getLength() );
1017 : }
1018 0 : pRet->nId = SW_MC_DOUBLE;
1019 0 : pRet->nLevel = GetTxtFrm()->IsRightToLeft() ? 1 : 0;
1020 :
1021 : // n2Lines is the index of the last 2-line-attribute, which contains
1022 : // the actual position.
1023 0 : i = 0;
1024 : // At this moment we know that at position rPos the "winner"-attribute
1025 : // causes a 2-line-portion. The end of the attribute is the end of the
1026 : // portion, if there's no interrupting attribute.
1027 : // There are two kinds of interruptors:
1028 : // - ruby attributes stops the 2-line-attribute, the end of the
1029 : // multiline is the start of the ruby attribute
1030 : // - 2-line-attributes with value "Off" or with different brackets,
1031 : // these attributes may interrupt the winner, but they could be
1032 : // neutralized by another 2-line-attribute starting at the same
1033 : // position with the same brackets as the winner-attribute.
1034 :
1035 : // In the following loop rPos is the critical position and it will be
1036 : // evaluated, if at rPos starts a interrupting or a maintaining
1037 : // continuity attribute.
1038 0 : while( i < nCount )
1039 : {
1040 0 : const SwTxtAttr *pTmp = (*pHints)[i++];
1041 0 : if( *pTmp->GetAnyEnd() <= rPos )
1042 0 : continue;
1043 0 : if( rPos < *pTmp->GetStart() )
1044 : {
1045 : // If bOn is false and the next attribute starts later than rPos
1046 : // the winner attribute is interrupted at rPos.
1047 : // If the start of the next attribute is behind the end of
1048 : // the last attribute on the aEnd-stack, this is the endposition
1049 : // on the stack is the end of the 2-line portion.
1050 0 : if( !bOn || aEnd.back() < *pTmp->GetStart() )
1051 0 : break;
1052 : // At this moment, bOn is true and the next attribute starts
1053 : // behind rPos, so we could move rPos to the next startpoint
1054 0 : rPos = *pTmp->GetStart();
1055 : // We clean up the aEnd-stack, endpositions equal to rPos are
1056 : // superfluous.
1057 0 : while( !aEnd.empty() && aEnd.back() <= rPos )
1058 : {
1059 0 : bOn = !bOn;
1060 0 : aEnd.pop_back();
1061 : }
1062 : // If the endstack is empty, we simulate an attribute with
1063 : // state true and endposition rPos
1064 0 : if( aEnd.empty() )
1065 : {
1066 0 : aEnd.push_front( rPos );
1067 0 : bOn = true;
1068 : }
1069 : }
1070 : // A ruby attribute stops the 2-line immediately
1071 0 : if( RES_TXTATR_CJK_RUBY == pTmp->Which() )
1072 0 : return pRet;
1073 0 : if( lcl_Has2Lines( *pTmp, p2Lines, bTwo ) )
1074 : { // We have an interesting attribute..
1075 0 : if( bTwo == bOn )
1076 : { // .. with the same state, so the last attribute could
1077 : // be continued.
1078 0 : if( aEnd.back() < *pTmp->End() )
1079 0 : aEnd.back() = *pTmp->End();
1080 : }
1081 : else
1082 : { // .. with a different state.
1083 0 : bOn = bTwo;
1084 : // If this is smaller than the last on the stack, we put
1085 : // it on the stack. If it has the same endposition, the last
1086 : // could be removed.
1087 0 : if( aEnd.back() > *pTmp->End() )
1088 0 : aEnd.push_back( *pTmp->End() );
1089 0 : else if( aEnd.size() > 1 )
1090 0 : aEnd.pop_back();
1091 : else
1092 0 : aEnd.back() = *pTmp->End();
1093 : }
1094 : }
1095 : }
1096 0 : if( bOn && !aEnd.empty() )
1097 0 : rPos = aEnd.back();
1098 0 : return pRet;
1099 : }
1100 0 : if( nRotate < nCount || ( pRotItem && pRotItem == pRotate &&
1101 0 : rPos < GetTxt().getLength() ) )
1102 : { // The winner is a rotate-attribute,
1103 : // the end of the multiportion depends on the following attributes...
1104 0 : SwMultiCreator *pRet = new SwMultiCreator;
1105 0 : pRet->nId = SW_MC_ROTATE;
1106 :
1107 : // We note the endpositions of the 2-line attributes in aEnd as stack
1108 0 : std::deque< sal_Int32 > aEnd;
1109 :
1110 : // The bOn flag signs the state of the last 2-line attribute in the
1111 : // aEnd-stack, which could interrupts the winning rotation attribute.
1112 0 : bool bOn = pItem;
1113 0 : aEnd.push_front( GetTxt().getLength() );
1114 : // n2Lines is the index of the last 2-line-attribute, which contains
1115 : // the actual position.
1116 0 : i = 0;
1117 0 : sal_Int32 n2Start = rPos;
1118 0 : while( i < nCount )
1119 : {
1120 0 : const SwTxtAttr *pTmp = (*pHints)[i++];
1121 0 : if( *pTmp->GetAnyEnd() <= n2Start )
1122 0 : continue;
1123 0 : if( n2Start < *pTmp->GetStart() )
1124 : {
1125 0 : if( bOn || aEnd.back() < *pTmp->GetStart() )
1126 0 : break;
1127 0 : n2Start = *pTmp->GetStart();
1128 0 : while( !aEnd.empty() && aEnd.back() <= n2Start )
1129 : {
1130 0 : bOn = !bOn;
1131 0 : aEnd.pop_back();
1132 : }
1133 0 : if( aEnd.empty() )
1134 : {
1135 0 : aEnd.push_front( n2Start );
1136 0 : bOn = false;
1137 : }
1138 : }
1139 : // A ruby attribute stops immediately
1140 0 : if( RES_TXTATR_CJK_RUBY == pTmp->Which() )
1141 : {
1142 0 : bOn = true;
1143 0 : break;
1144 : }
1145 0 : p2Lines = NULL;
1146 0 : if( lcl_Has2Lines( *pTmp, p2Lines, bTwo ) )
1147 : {
1148 0 : if( bTwo == bOn )
1149 : {
1150 0 : if( aEnd.back() < *pTmp->End() )
1151 0 : aEnd.back() = *pTmp->End();
1152 : }
1153 : else
1154 : {
1155 0 : bOn = bTwo;
1156 0 : if( aEnd.back() > *pTmp->End() )
1157 0 : aEnd.push_back( *pTmp->End() );
1158 0 : else if( aEnd.size() > 1 )
1159 0 : aEnd.pop_back();
1160 : else
1161 0 : aEnd.back() = *pTmp->End();
1162 : }
1163 : }
1164 : }
1165 0 : if( !bOn && !aEnd.empty() )
1166 0 : n2Start = aEnd.back();
1167 :
1168 0 : if( !aEnd.empty() )
1169 0 : aEnd.clear();
1170 :
1171 0 : bOn = true;
1172 0 : if( nRotate < nCount )
1173 : {
1174 0 : pRet->pItem = NULL;
1175 0 : pRet->pAttr = (*pHints)[nRotate];
1176 0 : aEnd.push_front( *pRet->pAttr->End() );
1177 0 : if( pRotItem )
1178 : {
1179 0 : aEnd.front() = GetTxt().getLength();
1180 0 : bOn = ((SvxCharRotateItem*)pRotItem)->GetValue() ==
1181 0 : pRotate->GetValue();
1182 : }
1183 : }
1184 : else
1185 : {
1186 0 : pRet->pItem = pRotItem;
1187 0 : pRet->pAttr = NULL;
1188 0 : aEnd.push_front( GetTxt().getLength() );
1189 : }
1190 0 : i = 0;
1191 0 : while( i < nCount )
1192 : {
1193 0 : const SwTxtAttr *pTmp = (*pHints)[i++];
1194 0 : if( *pTmp->GetAnyEnd() <= rPos )
1195 0 : continue;
1196 0 : if( rPos < *pTmp->GetStart() )
1197 : {
1198 0 : if( !bOn || aEnd.back() < *pTmp->GetStart() )
1199 0 : break;
1200 0 : rPos = *pTmp->GetStart();
1201 0 : while( !aEnd.empty() && aEnd.back() <= rPos )
1202 : {
1203 0 : bOn = !bOn;
1204 0 : aEnd.pop_back();
1205 : }
1206 0 : if( aEnd.empty() )
1207 : {
1208 0 : aEnd.push_front( rPos );
1209 0 : bOn = true;
1210 : }
1211 : }
1212 0 : if( RES_TXTATR_CJK_RUBY == pTmp->Which() )
1213 : {
1214 0 : bOn = false;
1215 0 : break;
1216 : }
1217 0 : if( lcl_HasRotation( *pTmp, pRotate, bTwo ) )
1218 : {
1219 0 : if( bTwo == bOn )
1220 : {
1221 0 : if( aEnd.back() < *pTmp->End() )
1222 0 : aEnd.back() = *pTmp->End();
1223 : }
1224 : else
1225 : {
1226 0 : bOn = bTwo;
1227 0 : if( aEnd.back() > *pTmp->End() )
1228 0 : aEnd.push_back( *pTmp->End() );
1229 0 : else if( aEnd.size() > 1 )
1230 0 : aEnd.pop_back();
1231 : else
1232 0 : aEnd.back() = *pTmp->End();
1233 : }
1234 : }
1235 : }
1236 0 : if( bOn && !aEnd.empty() )
1237 0 : rPos = aEnd.back();
1238 0 : if( rPos > n2Start )
1239 0 : rPos = n2Start;
1240 0 : return pRet;
1241 : }
1242 0 : return NULL;
1243 : }
1244 :
1245 : /*--------------------------------------------------
1246 : * SwSpaceManipulator
1247 : * is a little helper class to manage the spaceadd-arrays of the text adjustment
1248 : * during a PaintMultiPortion.
1249 : * The constructor prepares the array for the first line of multiportion,
1250 : * the SecondLine-function restores the values for the first line and prepares
1251 : * the second line.
1252 : * The destructor restores the values of the last manipulation.
1253 : * --------------------------------------------------*/
1254 :
1255 : class SwSpaceManipulator
1256 : {
1257 : SwTxtPaintInfo& rInfo;
1258 : SwMultiPortion& rMulti;
1259 : std::vector<long>* pOldSpaceAdd;
1260 : MSHORT nOldSpIdx;
1261 : long nSpaceAdd;
1262 : bool bSpaceChg;
1263 : sal_uInt8 nOldDir;
1264 : public:
1265 : SwSpaceManipulator( SwTxtPaintInfo& rInf, SwMultiPortion& rMult );
1266 : ~SwSpaceManipulator();
1267 : void SecondLine();
1268 0 : inline long GetSpaceAdd() const { return nSpaceAdd; }
1269 : };
1270 :
1271 0 : SwSpaceManipulator::SwSpaceManipulator( SwTxtPaintInfo& rInf,
1272 : SwMultiPortion& rMult )
1273 : : rInfo(rInf)
1274 : , rMulti(rMult)
1275 0 : , nSpaceAdd(0)
1276 : {
1277 0 : pOldSpaceAdd = rInfo.GetpSpaceAdd();
1278 0 : nOldSpIdx = rInfo.GetSpaceIdx();
1279 0 : nOldDir = rInfo.GetDirection();
1280 0 : rInfo.SetDirection( rMulti.GetDirection() );
1281 0 : bSpaceChg = false;
1282 :
1283 0 : if( rMulti.IsDouble() )
1284 : {
1285 0 : nSpaceAdd = ( pOldSpaceAdd && !rMulti.HasTabulator() ) ?
1286 0 : rInfo.GetSpaceAdd() : 0;
1287 0 : if( rMulti.GetRoot().IsSpaceAdd() )
1288 : {
1289 0 : rInfo.SetpSpaceAdd( rMulti.GetRoot().GetpLLSpaceAdd() );
1290 0 : rInfo.ResetSpaceIdx();
1291 0 : bSpaceChg = rMulti.ChgSpaceAdd( &rMulti.GetRoot(), nSpaceAdd );
1292 : }
1293 0 : else if( rMulti.HasTabulator() )
1294 0 : rInfo.SetpSpaceAdd( NULL );
1295 : }
1296 0 : else if ( ! rMulti.IsBidi() )
1297 : {
1298 0 : rInfo.SetpSpaceAdd( rMulti.GetRoot().GetpLLSpaceAdd() );
1299 0 : rInfo.ResetSpaceIdx();
1300 : }
1301 0 : }
1302 :
1303 0 : void SwSpaceManipulator::SecondLine()
1304 : {
1305 0 : if( bSpaceChg )
1306 : {
1307 0 : rInfo.RemoveFirstSpaceAdd();
1308 0 : bSpaceChg = false;
1309 : }
1310 0 : SwLineLayout *pLay = rMulti.GetRoot().GetNext();
1311 0 : if( pLay->IsSpaceAdd() )
1312 : {
1313 0 : rInfo.SetpSpaceAdd( pLay->GetpLLSpaceAdd() );
1314 0 : rInfo.ResetSpaceIdx();
1315 0 : bSpaceChg = rMulti.ChgSpaceAdd( pLay, nSpaceAdd );
1316 : }
1317 : else
1318 : {
1319 0 : rInfo.SetpSpaceAdd( (!rMulti.IsDouble() || rMulti.HasTabulator() ) ?
1320 0 : 0 : pOldSpaceAdd );
1321 0 : rInfo.SetSpaceIdx( nOldSpIdx);
1322 : }
1323 0 : }
1324 :
1325 0 : SwSpaceManipulator::~SwSpaceManipulator()
1326 : {
1327 0 : if( bSpaceChg )
1328 : {
1329 0 : rInfo.RemoveFirstSpaceAdd();
1330 0 : bSpaceChg = false;
1331 : }
1332 0 : rInfo.SetpSpaceAdd( pOldSpaceAdd );
1333 0 : rInfo.SetSpaceIdx( nOldSpIdx);
1334 0 : rInfo.SetDirection( nOldDir );
1335 0 : }
1336 :
1337 : /*--------------------------------------------------
1338 : * SwTxtPainter::PaintMultiPortion manages the paint for a SwMultiPortion.
1339 : * External, for the calling function, it seems to be a normal Paint-function,
1340 : * internal it is like a SwTxtFrm::Paint with multiple DrawTextLines
1341 : * --------------------------------------------------*/
1342 :
1343 0 : void SwTxtPainter::PaintMultiPortion( const SwRect &rPaint,
1344 : SwMultiPortion& rMulti, const SwMultiPortion* pEnvPor )
1345 : {
1346 0 : SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
1347 0 : const bool bHasGrid = pGrid && GetInfo().SnapToGrid();
1348 0 : sal_uInt16 nRubyHeight = 0;
1349 0 : bool bRubyTop = false;
1350 :
1351 0 : if ( bHasGrid )
1352 : {
1353 0 : nRubyHeight = pGrid->GetRubyHeight();
1354 0 : bRubyTop = ! pGrid->GetRubyTextBelow();
1355 : }
1356 :
1357 : // do not allow grid mode for first line in ruby portion
1358 0 : const bool bRubyInGrid = bHasGrid && rMulti.IsRuby();
1359 :
1360 0 : const sal_uInt16 nOldHeight = rMulti.Height();
1361 0 : const bool bOldGridModeAllowed = GetInfo().SnapToGrid();
1362 :
1363 0 : if ( bRubyInGrid )
1364 : {
1365 0 : GetInfo().SetSnapToGrid( ! bRubyTop );
1366 0 : rMulti.Height( pCurr->Height() );
1367 : }
1368 :
1369 0 : SwLayoutModeModifier aLayoutModeModifier( *GetInfo().GetOut() );
1370 0 : sal_uInt8 nEnvDir = 0;
1371 0 : sal_uInt8 nThisDir = 0;
1372 0 : sal_uInt8 nFrmDir = 0;
1373 0 : if ( rMulti.IsBidi() )
1374 : {
1375 : // these values are needed for the calculation of the x coordinate
1376 : // and the layout mode
1377 : OSL_ENSURE( ! pEnvPor || pEnvPor->IsBidi(),
1378 : "Oh no, I expected a BidiPortion" );
1379 0 : nFrmDir = GetInfo().GetTxtFrm()->IsRightToLeft() ? 1 : 0;
1380 0 : nEnvDir = pEnvPor ? ((SwBidiPortion*)pEnvPor)->GetLevel() % 2 : nFrmDir;
1381 0 : nThisDir = ((SwBidiPortion&)rMulti).GetLevel() % 2;
1382 : }
1383 :
1384 : #if OSL_DEBUG_LEVEL > 1
1385 : // only paint first level bidi portions
1386 : if( rMulti.Width() > 1 && ! pEnvPor )
1387 : GetInfo().DrawViewOpt( rMulti, POR_FLD );
1388 : #endif
1389 :
1390 0 : if ( bRubyInGrid )
1391 0 : rMulti.Height( nOldHeight );
1392 :
1393 : // do we have to repaint a post it portion?
1394 0 : if( GetInfo().OnWin() && rMulti.GetPortion() &&
1395 0 : ! rMulti.GetPortion()->Width() )
1396 0 : rMulti.GetPortion()->PrePaint( GetInfo(), &rMulti );
1397 :
1398 : // old values must be saved and restored at the end
1399 0 : sal_Int32 nOldLen = GetInfo().GetLen();
1400 0 : KSHORT nOldX = KSHORT(GetInfo().X());
1401 0 : long nOldY = GetInfo().Y();
1402 0 : sal_Int32 nOldIdx = GetInfo().GetIdx();
1403 :
1404 0 : SwSpaceManipulator aManip( GetInfo(), rMulti );
1405 :
1406 : SwFontSave *pFontSave;
1407 : SwFont* pTmpFnt;
1408 :
1409 0 : if( rMulti.IsDouble() )
1410 : {
1411 0 : pTmpFnt = new SwFont( *GetInfo().GetFont() );
1412 0 : if( rMulti.IsDouble() )
1413 : {
1414 0 : SetPropFont( 50 );
1415 0 : pTmpFnt->SetProportion( GetPropFont() );
1416 : }
1417 0 : pFontSave = new SwFontSave( GetInfo(), pTmpFnt, this );
1418 : }
1419 : else
1420 : {
1421 0 : pFontSave = NULL;
1422 0 : pTmpFnt = NULL;
1423 : }
1424 :
1425 0 : if( rMulti.HasBrackets() )
1426 : {
1427 0 : sal_Int32 nTmpOldIdx = GetInfo().GetIdx();
1428 0 : GetInfo().SetIdx(((SwDoubleLinePortion&)rMulti).GetBrackets()->nStart);
1429 0 : SeekAndChg( GetInfo() );
1430 0 : ((SwDoubleLinePortion&)rMulti).PaintBracket( GetInfo(), 0, true );
1431 0 : GetInfo().SetIdx( nTmpOldIdx );
1432 : }
1433 :
1434 0 : KSHORT nTmpX = KSHORT(GetInfo().X());
1435 :
1436 0 : SwLineLayout* pLay = &rMulti.GetRoot();// the first line of the multiportion
1437 0 : SwLinePortion* pPor = pLay->GetFirstPortion();//first portion of these line
1438 0 : SwTwips nOfst = 0;
1439 :
1440 : // GetInfo().Y() is the baseline from the surrounding line. We must switch
1441 : // this temporary to the baseline of the inner lines of the multiportion.
1442 0 : if( rMulti.HasRotation() )
1443 : {
1444 0 : if( rMulti.IsRevers() )
1445 : {
1446 0 : GetInfo().Y( nOldY - rMulti.GetAscent() );
1447 0 : nOfst = nTmpX + rMulti.Width();
1448 : }
1449 : else
1450 : {
1451 0 : GetInfo().Y( nOldY - rMulti.GetAscent() + rMulti.Height() );
1452 0 : nOfst = nTmpX;
1453 : }
1454 : }
1455 0 : else if ( rMulti.IsBidi() )
1456 : {
1457 : // does the current bidi portion has the same direction
1458 : // as its environment?
1459 0 : if ( nEnvDir != nThisDir )
1460 : {
1461 : // different directions, we have to adjust the x coordinate
1462 0 : SwTwips nMultiWidth = rMulti.Width() +
1463 0 : rMulti.CalcSpacing( GetInfo().GetSpaceAdd(), GetInfo() );
1464 :
1465 0 : if ( nFrmDir == nThisDir )
1466 0 : GetInfo().X( GetInfo().X() - nMultiWidth );
1467 : else
1468 0 : GetInfo().X( GetInfo().X() + nMultiWidth );
1469 : }
1470 :
1471 0 : nOfst = nOldY - rMulti.GetAscent();
1472 :
1473 : // set layout mode
1474 0 : aLayoutModeModifier.Modify( nThisDir );
1475 : }
1476 : else
1477 0 : nOfst = nOldY - rMulti.GetAscent();
1478 :
1479 0 : bool bRest = pLay->IsRest();
1480 0 : bool bFirst = true;
1481 :
1482 : OSL_ENSURE( 0 == GetInfo().GetUnderFnt() || rMulti.IsBidi(),
1483 : " Only BiDi portions are allowed to use the common underlining font" );
1484 :
1485 0 : do
1486 : {
1487 0 : if ( bHasGrid )
1488 : {
1489 0 : if( rMulti.HasRotation() )
1490 : {
1491 0 : const sal_uInt16 nAdjustment = ( pLay->Height() - pPor->Height() ) / 2 +
1492 0 : pPor->GetAscent();
1493 0 : if( rMulti.IsRevers() )
1494 0 : GetInfo().X( nOfst - nAdjustment );
1495 : else
1496 0 : GetInfo().X( nOfst + nAdjustment );
1497 : }
1498 : else
1499 : {
1500 : // special treatment for ruby portions in grid mode
1501 0 : SwTwips nAdjustment = 0;
1502 0 : if ( rMulti.IsRuby() )
1503 : {
1504 0 : if ( bRubyTop != ( pLay == &rMulti.GetRoot() ) )
1505 : // adjust base text
1506 0 : nAdjustment = ( pCurr->Height() - nRubyHeight - pPor->Height() ) / 2;
1507 0 : else if ( bRubyTop )
1508 : // adjust upper ruby text
1509 0 : nAdjustment = nRubyHeight - pPor->Height();
1510 : // else adjust lower ruby text
1511 : }
1512 :
1513 0 : GetInfo().Y( nOfst + nAdjustment + pPor->GetAscent() );
1514 : }
1515 : }
1516 0 : else if( rMulti.HasRotation() )
1517 : {
1518 0 : if( rMulti.IsRevers() )
1519 0 : GetInfo().X( nOfst - AdjustBaseLine( *pLay, pPor, 0, 0, true ) );
1520 : else
1521 0 : GetInfo().X( nOfst + AdjustBaseLine( *pLay, pPor ) );
1522 : }
1523 : else
1524 0 : GetInfo().Y( nOfst + AdjustBaseLine( *pLay, pPor ) );
1525 :
1526 0 : bool bSeeked = true;
1527 0 : GetInfo().SetLen( pPor->GetLen() );
1528 :
1529 0 : if( bRest && pPor->InFldGrp() && !pPor->GetLen() )
1530 : {
1531 0 : if( ((SwFldPortion*)pPor)->HasFont() )
1532 0 : bSeeked = false;
1533 : else
1534 0 : SeekAndChgBefore( GetInfo() );
1535 : }
1536 0 : else if( pPor->InTxtGrp() || pPor->InFldGrp() || pPor->InTabGrp() )
1537 0 : SeekAndChg( GetInfo() );
1538 0 : else if ( !bFirst && pPor->IsBreakPortion() && GetInfo().GetOpt().IsParagraph() )
1539 : {
1540 0 : if( GetRedln() )
1541 0 : SeekAndChg( GetInfo() );
1542 : else
1543 0 : SeekAndChgBefore( GetInfo() );
1544 : }
1545 : else
1546 0 : bSeeked = false;
1547 :
1548 0 : SwLinePortion *pNext = pPor->GetPortion();
1549 0 : if(GetInfo().OnWin() && pNext && !pNext->Width() )
1550 : {
1551 0 : if ( !bSeeked )
1552 0 : SeekAndChg( GetInfo() );
1553 0 : pNext->PrePaint( GetInfo(), pPor );
1554 : }
1555 :
1556 0 : CheckSpecialUnderline( pPor );
1557 0 : SwUnderlineFont* pUnderLineFnt = GetInfo().GetUnderFnt();
1558 0 : if ( pUnderLineFnt )
1559 : {
1560 0 : if ( rMulti.IsDouble() )
1561 0 : pUnderLineFnt->GetFont().SetProportion( 50 );
1562 0 : pUnderLineFnt->SetPos( GetInfo().GetPos() );
1563 : }
1564 :
1565 0 : if ( rMulti.IsBidi() )
1566 : {
1567 : // we do not allow any rotation inside a bidi portion
1568 0 : SwFont* pTmpFont = GetInfo().GetFont();
1569 0 : pTmpFont->SetVertical( 0, GetInfo().GetTxtFrm()->IsVertical() );
1570 : }
1571 :
1572 0 : if( pPor->IsMultiPortion() && ((SwMultiPortion*)pPor)->IsBidi() )
1573 : {
1574 : // but we do allow nested bidi portions
1575 : OSL_ENSURE( rMulti.IsBidi(), "Only nesting of bidi portions is allowed" );
1576 0 : PaintMultiPortion( rPaint, (SwMultiPortion&)*pPor, &rMulti );
1577 : }
1578 : else
1579 0 : pPor->Paint( GetInfo() );
1580 :
1581 0 : if( GetFnt()->IsURL() && pPor->InTxtGrp() )
1582 0 : GetInfo().NotifyURL( *pPor );
1583 :
1584 0 : bFirst &= !pPor->GetLen();
1585 0 : if( pNext || !pPor->IsMarginPortion() )
1586 0 : pPor->Move( GetInfo() );
1587 :
1588 0 : pPor = pNext;
1589 :
1590 : // If there's no portion left, we go to the next line
1591 0 : if( !pPor && pLay->GetNext() )
1592 : {
1593 0 : pLay = pLay->GetNext();
1594 0 : pPor = pLay->GetFirstPortion();
1595 0 : bRest = pLay->IsRest();
1596 0 : aManip.SecondLine();
1597 :
1598 : // delete underline font
1599 0 : delete GetInfo().GetUnderFnt();
1600 0 : GetInfo().SetUnderFnt( 0 );
1601 :
1602 0 : if( rMulti.HasRotation() )
1603 : {
1604 0 : if( rMulti.IsRevers() )
1605 : {
1606 0 : nOfst += pLay->Height();
1607 0 : GetInfo().Y( nOldY - rMulti.GetAscent() );
1608 : }
1609 : else
1610 : {
1611 0 : nOfst -= pLay->Height();
1612 0 : GetInfo().Y( nOldY - rMulti.GetAscent() + rMulti.Height() );
1613 : }
1614 : }
1615 0 : else if ( bHasGrid && rMulti.IsRuby() )
1616 : {
1617 0 : GetInfo().X( nTmpX );
1618 0 : if ( bRubyTop )
1619 : {
1620 0 : nOfst += nRubyHeight;
1621 0 : GetInfo().SetSnapToGrid( true );
1622 : }
1623 : else
1624 : {
1625 0 : nOfst += pCurr->Height() - nRubyHeight;
1626 0 : GetInfo().SetSnapToGrid( false );
1627 : }
1628 : } else
1629 : {
1630 0 : GetInfo().X( nTmpX );
1631 : // We switch to the baseline of the next inner line
1632 0 : nOfst += rMulti.GetRoot().Height();
1633 : }
1634 : }
1635 : } while( pPor );
1636 :
1637 0 : if ( bRubyInGrid )
1638 0 : GetInfo().SetSnapToGrid( bOldGridModeAllowed );
1639 :
1640 : // delete underline font
1641 0 : if ( ! rMulti.IsBidi() )
1642 : {
1643 0 : delete GetInfo().GetUnderFnt();
1644 0 : GetInfo().SetUnderFnt( 0 );
1645 : }
1646 :
1647 0 : GetInfo().SetIdx( nOldIdx );
1648 0 : GetInfo().Y( nOldY );
1649 :
1650 0 : if( rMulti.HasBrackets() )
1651 : {
1652 0 : sal_Int32 nTmpOldIdx = GetInfo().GetIdx();
1653 0 : GetInfo().SetIdx(((SwDoubleLinePortion&)rMulti).GetBrackets()->nStart);
1654 0 : SeekAndChg( GetInfo() );
1655 0 : GetInfo().X( nOldX );
1656 0 : ((SwDoubleLinePortion&)rMulti).PaintBracket( GetInfo(),
1657 0 : aManip.GetSpaceAdd(), false );
1658 0 : GetInfo().SetIdx( nTmpOldIdx );
1659 : }
1660 : // Restore the saved values
1661 0 : GetInfo().X( nOldX );
1662 0 : GetInfo().SetLen( nOldLen );
1663 0 : delete pFontSave;
1664 0 : delete pTmpFnt;
1665 0 : SetPropFont( 0 );
1666 0 : }
1667 :
1668 0 : static bool lcl_ExtractFieldFollow( SwLineLayout* pLine, SwLinePortion* &rpFld )
1669 : {
1670 0 : SwLinePortion* pLast = pLine;
1671 0 : rpFld = pLine->GetPortion();
1672 0 : while( rpFld && !rpFld->InFldGrp() )
1673 : {
1674 0 : pLast = rpFld;
1675 0 : rpFld = rpFld->GetPortion();
1676 : }
1677 0 : bool bRet = rpFld != 0;
1678 0 : if( bRet )
1679 : {
1680 0 : if( ((SwFldPortion*)rpFld)->IsFollow() )
1681 : {
1682 0 : rpFld->Truncate();
1683 0 : pLast->SetPortion( NULL );
1684 : }
1685 : else
1686 0 : rpFld = NULL;
1687 : }
1688 0 : pLine->Truncate();
1689 0 : return bRet;
1690 : }
1691 :
1692 : /*----------------------------------------------------
1693 : * lcl_TruncateMultiPortion
1694 : * If a multi portion completely has to go to the
1695 : * next line, this function is called to trunctate
1696 : * the rest of the remaining multi portion
1697 : * --------------------------------------------------*/
1698 :
1699 0 : static void lcl_TruncateMultiPortion( SwMultiPortion& rMulti, SwTxtFormatInfo& rInf,
1700 : sal_Int32 nStartIdx )
1701 : {
1702 0 : rMulti.GetRoot().Truncate();
1703 0 : rMulti.GetRoot().SetLen(0);
1704 0 : rMulti.GetRoot().Width(0);
1705 : // rMulti.CalcSize( *this, aInf );
1706 0 : if ( rMulti.GetRoot().GetNext() )
1707 : {
1708 0 : rMulti.GetRoot().GetNext()->Truncate();
1709 0 : rMulti.GetRoot().GetNext()->SetLen( 0 );
1710 0 : rMulti.GetRoot().GetNext()->Width( 0 );
1711 : }
1712 0 : rMulti.Width( 0 );
1713 0 : rMulti.SetLen(0);
1714 0 : rInf.SetIdx( nStartIdx );
1715 0 : }
1716 :
1717 : /*-----------------------------------------------------------------------------
1718 : * SwTxtFormatter::BuildMultiPortion
1719 : * manages the formatting of a SwMultiPortion. External, for the calling
1720 : * function, it seems to be a normal Format-function, internal it is like a
1721 : * SwTxtFrm::_Format with multiple BuildPortions
1722 : *---------------------------------------------------------------------------*/
1723 :
1724 0 : bool SwTxtFormatter::BuildMultiPortion( SwTxtFormatInfo &rInf,
1725 : SwMultiPortion& rMulti )
1726 : {
1727 0 : SwTwips nMaxWidth = rInf.Width();
1728 0 : KSHORT nOldX = 0;
1729 :
1730 0 : if( rMulti.HasBrackets() )
1731 : {
1732 0 : sal_Int32 nOldIdx = rInf.GetIdx();
1733 0 : rInf.SetIdx( ((SwDoubleLinePortion&)rMulti).GetBrackets()->nStart );
1734 0 : SeekAndChg( rInf );
1735 0 : nOldX = KSHORT(GetInfo().X());
1736 0 : ((SwDoubleLinePortion&)rMulti).FormatBrackets( rInf, nMaxWidth );
1737 0 : rInf.SetIdx( nOldIdx );
1738 : }
1739 :
1740 0 : SeekAndChg( rInf );
1741 0 : boost::scoped_ptr<SwFontSave> xFontSave;
1742 0 : if( rMulti.IsDouble() )
1743 : {
1744 0 : SwFont* pTmpFnt = new SwFont( *rInf.GetFont() );
1745 0 : if( rMulti.IsDouble() )
1746 : {
1747 0 : SetPropFont( 50 );
1748 0 : pTmpFnt->SetProportion( GetPropFont() );
1749 : }
1750 0 : xFontSave.reset(new SwFontSave(rInf, pTmpFnt, this));
1751 : }
1752 :
1753 0 : SwLayoutModeModifier aLayoutModeModifier( *GetInfo().GetOut() );
1754 0 : if ( rMulti.IsBidi() )
1755 : {
1756 : // set layout mode
1757 0 : aLayoutModeModifier.Modify( ! rInf.GetTxtFrm()->IsRightToLeft() );
1758 : }
1759 :
1760 0 : SwTwips nTmpX = 0;
1761 :
1762 0 : if( rMulti.HasRotation() )
1763 : {
1764 : // For nMaxWidth we take the height of the body frame.
1765 : // #i25067#: If the current frame is inside a table, we restrict
1766 : // nMaxWidth to the current frame height, unless the frame size
1767 : // attribute is set to variable size:
1768 :
1769 : // We set nTmpX (which is used for portion calculating) to the
1770 : // current Y value
1771 0 : const SwPageFrm* pPage = pFrm->FindPageFrm();
1772 : OSL_ENSURE( pPage, "No page in frame!");
1773 0 : const SwLayoutFrm* pUpperFrm = pPage;
1774 :
1775 0 : if ( pFrm->IsInTab() )
1776 : {
1777 0 : pUpperFrm = pFrm->GetUpper();
1778 0 : while ( pUpperFrm && !pUpperFrm->IsCellFrm() )
1779 0 : pUpperFrm = pUpperFrm->GetUpper();
1780 : assert(pUpperFrm); //pFrm is in table but does not have an upper cell frame
1781 0 : if (!pUpperFrm)
1782 0 : return false;
1783 0 : const SwTableLine* pLine = ((SwRowFrm*)pUpperFrm->GetUpper())->GetTabLine();
1784 0 : const SwFmtFrmSize& rFrmFmtSize = pLine->GetFrmFmt()->GetFrmSize();
1785 0 : if ( ATT_VAR_SIZE == rFrmFmtSize.GetHeightSizeType() )
1786 0 : pUpperFrm = pPage;
1787 : }
1788 0 : if ( pUpperFrm == pPage && !pFrm->IsInFtn() )
1789 0 : pUpperFrm = pPage->FindBodyCont();
1790 :
1791 : nMaxWidth = pUpperFrm ?
1792 0 : ( rInf.GetTxtFrm()->IsVertical() ?
1793 0 : pUpperFrm->Prt().Width() :
1794 0 : pUpperFrm->Prt().Height() ) :
1795 0 : USHRT_MAX;
1796 : }
1797 : else
1798 0 : nTmpX = rInf.X();
1799 :
1800 0 : SwMultiPortion* pOldMulti = pMulti;
1801 :
1802 0 : pMulti = &rMulti;
1803 0 : SwLineLayout *pOldCurr = pCurr;
1804 0 : sal_Int32 nOldStart = GetStart();
1805 0 : SwTwips nMinWidth = nTmpX + 1;
1806 0 : SwTwips nActWidth = nMaxWidth;
1807 0 : const sal_Int32 nStartIdx = rInf.GetIdx();
1808 0 : sal_Int32 nMultiLen = rMulti.GetLen();
1809 :
1810 : SwLinePortion *pFirstRest;
1811 : SwLinePortion *pSecondRest;
1812 0 : if( rMulti.IsFormatted() )
1813 : {
1814 0 : if( !lcl_ExtractFieldFollow( &rMulti.GetRoot(), pFirstRest )
1815 0 : && rMulti.IsDouble() && rMulti.GetRoot().GetNext() )
1816 0 : lcl_ExtractFieldFollow( rMulti.GetRoot().GetNext(), pFirstRest );
1817 0 : if( !rMulti.IsDouble() && rMulti.GetRoot().GetNext() )
1818 0 : lcl_ExtractFieldFollow( rMulti.GetRoot().GetNext(), pSecondRest );
1819 : else
1820 0 : pSecondRest = NULL;
1821 : }
1822 : else
1823 : {
1824 0 : pFirstRest = rMulti.GetRoot().GetPortion();
1825 0 : pSecondRest = rMulti.GetRoot().GetNext() ?
1826 0 : rMulti.GetRoot().GetNext()->GetPortion() : NULL;
1827 0 : if( pFirstRest )
1828 0 : rMulti.GetRoot().SetPortion( NULL );
1829 0 : if( pSecondRest )
1830 0 : rMulti.GetRoot().GetNext()->SetPortion( NULL );
1831 0 : rMulti.SetFormatted();
1832 0 : nMultiLen = nMultiLen - rInf.GetIdx();
1833 : }
1834 :
1835 : // save some values
1836 0 : const OUString* pOldTxt = &(rInf.GetTxt());
1837 0 : const SwTwips nOldPaintOfst = rInf.GetPaintOfst();
1838 :
1839 0 : OUString const aMultiStr( rInf.GetTxt().copy(0, nMultiLen + rInf.GetIdx()) );
1840 0 : rInf.SetTxt( aMultiStr );
1841 0 : SwTxtFormatInfo aInf( rInf, rMulti.GetRoot(), nActWidth );
1842 : // Do we allow break cuts? The FirstMulti-Flag is evaluated during
1843 : // line break determination.
1844 0 : bool bFirstMulti = rInf.GetIdx() != rInf.GetLineStart();
1845 :
1846 0 : SwLinePortion *pNextFirst = NULL;
1847 0 : SwLinePortion *pNextSecond = NULL;
1848 0 : bool bRet = false;
1849 :
1850 0 : SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
1851 0 : const bool bHasGrid = pGrid && GRID_LINES_CHARS == pGrid->GetGridType();
1852 :
1853 0 : bool bRubyTop = false;
1854 :
1855 0 : if ( bHasGrid )
1856 0 : bRubyTop = ! pGrid->GetRubyTextBelow();
1857 :
1858 : do
1859 : {
1860 0 : pCurr = &rMulti.GetRoot();
1861 0 : nStart = nStartIdx;
1862 0 : bRet = false;
1863 0 : FormatReset( aInf );
1864 0 : aInf.X( nTmpX );
1865 0 : aInf.Width( KSHORT(nActWidth) );
1866 0 : aInf.RealWidth( KSHORT(nActWidth) );
1867 0 : aInf.SetFirstMulti( bFirstMulti );
1868 0 : aInf.SetNumDone( rInf.IsNumDone() );
1869 0 : aInf.SetFtnDone( rInf.IsFtnDone() );
1870 :
1871 0 : if( pFirstRest )
1872 : {
1873 : OSL_ENSURE( pFirstRest->InFldGrp(), "BuildMulti: Fieldrest expected");
1874 : SwFldPortion *pFld =
1875 : ((SwFldPortion*)pFirstRest)->Clone(
1876 0 : ((SwFldPortion*)pFirstRest)->GetExp() );
1877 0 : pFld->SetFollow( true );
1878 0 : aInf.SetRest( pFld );
1879 : }
1880 0 : aInf.SetRuby( rMulti.IsRuby() && rMulti.OnTop() );
1881 :
1882 : // in grid mode we temporarily have to disable the grid for the ruby line
1883 0 : const bool bOldGridModeAllowed = GetInfo().SnapToGrid();
1884 0 : if ( bHasGrid && aInf.IsRuby() && bRubyTop )
1885 0 : aInf.SetSnapToGrid( false );
1886 :
1887 : // If there's no more rubytext, then buildportion is forbidden
1888 0 : if( pFirstRest || !aInf.IsRuby() )
1889 0 : BuildPortions( aInf );
1890 :
1891 0 : aInf.SetSnapToGrid( bOldGridModeAllowed );
1892 :
1893 0 : rMulti.CalcSize( *this, aInf );
1894 0 : pCurr->SetRealHeight( pCurr->Height() );
1895 :
1896 0 : if( rMulti.IsBidi() )
1897 : {
1898 0 : pNextFirst = aInf.GetRest();
1899 0 : break;
1900 : }
1901 :
1902 0 : if( rMulti.HasRotation() && !rMulti.IsDouble() )
1903 0 : break;
1904 : // second line has to be formatted
1905 0 : else if( pCurr->GetLen()<nMultiLen || rMulti.IsRuby() || aInf.GetRest())
1906 : {
1907 0 : sal_Int32 nFirstLen = pCurr->GetLen();
1908 0 : delete pCurr->GetNext();
1909 0 : pCurr->SetNext( new SwLineLayout() );
1910 0 : pCurr = pCurr->GetNext();
1911 0 : nStart = aInf.GetIdx();
1912 0 : aInf.X( nTmpX );
1913 0 : SwTxtFormatInfo aTmp( aInf, *pCurr, nActWidth );
1914 0 : if( rMulti.IsRuby() )
1915 : {
1916 0 : aTmp.SetRuby( !rMulti.OnTop() );
1917 0 : pNextFirst = aInf.GetRest();
1918 0 : if( pSecondRest )
1919 : {
1920 : OSL_ENSURE( pSecondRest->InFldGrp(), "Fieldrest expected");
1921 : SwFldPortion *pFld = ((SwFldPortion*)pSecondRest)->Clone(
1922 0 : ((SwFldPortion*)pSecondRest)->GetExp() );
1923 0 : pFld->SetFollow( true );
1924 0 : aTmp.SetRest( pFld );
1925 : }
1926 0 : if( !rMulti.OnTop() && nFirstLen < nMultiLen )
1927 0 : bRet = true;
1928 : }
1929 : else
1930 0 : aTmp.SetRest( aInf.GetRest() );
1931 0 : aInf.SetRest( NULL );
1932 :
1933 : // in grid mode we temporarily have to disable the grid for the ruby line
1934 0 : if ( bHasGrid && aTmp.IsRuby() && ! bRubyTop )
1935 0 : aTmp.SetSnapToGrid( false );
1936 :
1937 0 : BuildPortions( aTmp );
1938 :
1939 0 : aTmp.SetSnapToGrid( bOldGridModeAllowed );
1940 :
1941 0 : rMulti.CalcSize( *this, aInf );
1942 0 : rMulti.GetRoot().SetRealHeight( rMulti.GetRoot().Height() );
1943 0 : pCurr->SetRealHeight( pCurr->Height() );
1944 0 : if( rMulti.IsRuby() )
1945 : {
1946 0 : pNextSecond = aTmp.GetRest();
1947 0 : if( pNextFirst )
1948 0 : bRet = true;
1949 : }
1950 : else
1951 0 : pNextFirst = aTmp.GetRest();
1952 0 : if( ( !aTmp.IsRuby() && nFirstLen + pCurr->GetLen() < nMultiLen )
1953 0 : || aTmp.GetRest() )
1954 : // our guess for width of multiportion was too small,
1955 : // text did not fit into multiportion
1956 0 : bRet = true;
1957 : }
1958 0 : if( rMulti.IsRuby() )
1959 0 : break;
1960 0 : if( bRet )
1961 : {
1962 : // our guess for multiportion width was too small,
1963 : // we set min to act
1964 0 : nMinWidth = nActWidth;
1965 0 : nActWidth = ( 3 * nMaxWidth + nMinWidth + 3 ) / 4;
1966 0 : if ( nActWidth == nMaxWidth && rInf.GetLineStart() == rInf.GetIdx() )
1967 : // we have too less space, we must allow break cuts
1968 : // ( the first multi flag is considered during TxtPortion::_Format() )
1969 0 : bFirstMulti = false;
1970 0 : if( nActWidth <= nMinWidth )
1971 0 : break;
1972 : }
1973 : else
1974 : {
1975 : // For Solaris, this optimization can causes trouble:
1976 : // Setting this to the portion width ( = rMulti.Width() )
1977 : // can make GetTextBreak inside SwTxtGuess::Guess return to small
1978 : // values. Therefore we add some extra twips.
1979 0 : if( nActWidth > nTmpX + rMulti.Width() + 6 )
1980 0 : nActWidth = nTmpX + rMulti.Width() + 6;
1981 0 : nMaxWidth = nActWidth;
1982 0 : nActWidth = ( 3 * nMaxWidth + nMinWidth + 3 ) / 4;
1983 0 : if( nActWidth >= nMaxWidth )
1984 0 : break;
1985 : // we do not allow break cuts during formatting
1986 0 : bFirstMulti = true;
1987 : }
1988 0 : delete pNextFirst;
1989 0 : pNextFirst = NULL;
1990 : } while ( true );
1991 :
1992 0 : pMulti = pOldMulti;
1993 :
1994 0 : pCurr = pOldCurr;
1995 0 : nStart = nOldStart;
1996 0 : SetPropFont( 0 );
1997 :
1998 0 : rMulti.SetLen( rMulti.GetRoot().GetLen() + ( rMulti.GetRoot().GetNext() ?
1999 0 : rMulti.GetRoot().GetNext()->GetLen() : 0 ) );
2000 :
2001 0 : if( rMulti.IsDouble() )
2002 : {
2003 0 : ((SwDoubleLinePortion&)rMulti).CalcBlanks( rInf );
2004 0 : if( ((SwDoubleLinePortion&)rMulti).GetLineDiff() )
2005 : {
2006 0 : SwLineLayout* pLine = &rMulti.GetRoot();
2007 0 : if( ((SwDoubleLinePortion&)rMulti).GetLineDiff() > 0 )
2008 : {
2009 0 : rInf.SetIdx( nStartIdx + pLine->GetLen() );
2010 0 : pLine = pLine->GetNext();
2011 : }
2012 0 : if( pLine )
2013 : {
2014 0 : GetInfo().SetMulti( true );
2015 :
2016 : // If the fourth element bSkipKashida of function CalcNewBlock is true, multiportion will be showed in justification.
2017 : // Kashida (Persian) is a type of justification used in some cursive scripts, particularly Arabic.
2018 : // In contrast to white-space justification, which increases the length of a line of text by expanding spaces between words or individual letters,
2019 : // kashida justification is accomplished by elongating characters at certain chosen points.
2020 : // Kashida justification can be combined with white-space justification to various extents.
2021 : // The default value of bSkipKashida (the 4th parameter passed to 'CalcNewBlock') is false.
2022 : // Only when Adjust is SVX_ADJUST_BLOCK ( alignment is justify ), multiportion will be showed in justification in new code.
2023 0 : CalcNewBlock( pLine, NULL, rMulti.Width(), GetAdjust() != SVX_ADJUST_BLOCK );
2024 :
2025 0 : GetInfo().SetMulti( false );
2026 : }
2027 0 : rInf.SetIdx( nStartIdx );
2028 : }
2029 0 : if( ((SwDoubleLinePortion&)rMulti).GetBrackets() )
2030 : {
2031 0 : rMulti.Width( rMulti.Width() +
2032 0 : ((SwDoubleLinePortion&)rMulti).BracketWidth() );
2033 0 : GetInfo().X( nOldX );
2034 : }
2035 : }
2036 : else
2037 : {
2038 0 : rMulti.ActualizeTabulator();
2039 0 : if( rMulti.IsRuby() )
2040 : {
2041 0 : ((SwRubyPortion&)rMulti).Adjust( rInf );
2042 0 : ((SwRubyPortion&)rMulti).CalcRubyOffset();
2043 : }
2044 : }
2045 0 : if( rMulti.HasRotation() )
2046 : {
2047 0 : SwTwips nH = rMulti.Width();
2048 0 : SwTwips nAsc = rMulti.GetAscent() + ( nH - rMulti.Height() )/2;
2049 0 : if( nAsc > nH )
2050 0 : nAsc = nH;
2051 0 : else if( nAsc < 0 )
2052 0 : nAsc = 0;
2053 0 : rMulti.Width( rMulti.Height() );
2054 0 : rMulti.Height( KSHORT(nH) );
2055 0 : rMulti.SetAscent( KSHORT(nAsc) );
2056 0 : bRet = ( rInf.GetPos().X() + rMulti.Width() > rInf.Width() ) &&
2057 0 : nStartIdx != rInf.GetLineStart();
2058 : }
2059 0 : else if ( rMulti.IsBidi() )
2060 : {
2061 0 : bRet = rMulti.GetLen() < nMultiLen || pNextFirst;
2062 : }
2063 :
2064 : // line break has to be performed!
2065 0 : if( bRet )
2066 : {
2067 : OSL_ENSURE( !pNextFirst || pNextFirst->InFldGrp(),
2068 : "BuildMultiPortion: Surprising restportion, field expected" );
2069 : SwMultiPortion *pTmp;
2070 0 : if( rMulti.IsDouble() )
2071 : pTmp = new SwDoubleLinePortion( ((SwDoubleLinePortion&)rMulti),
2072 0 : nMultiLen + rInf.GetIdx() );
2073 0 : else if( rMulti.IsRuby() )
2074 : {
2075 : OSL_ENSURE( !pNextSecond || pNextSecond->InFldGrp(),
2076 : "BuildMultiPortion: Surprising restportion, field expected" );
2077 :
2078 0 : if ( rInf.GetIdx() == rInf.GetLineStart() )
2079 : {
2080 : // the ruby portion has to be split in two portions
2081 : pTmp = new SwRubyPortion( ((SwRubyPortion&)rMulti),
2082 0 : nMultiLen + rInf.GetIdx() );
2083 :
2084 0 : if( pNextSecond )
2085 : {
2086 0 : pTmp->GetRoot().SetNext( new SwLineLayout() );
2087 0 : pTmp->GetRoot().GetNext()->SetPortion( pNextSecond );
2088 : }
2089 0 : pTmp->SetFollowFld();
2090 : }
2091 : else
2092 : {
2093 : // we try to keep our ruby portion together
2094 0 : lcl_TruncateMultiPortion( rMulti, rInf, nStartIdx );
2095 0 : pTmp = 0;
2096 : }
2097 : }
2098 0 : else if( rMulti.HasRotation() )
2099 : {
2100 : // we try to keep our rotated portion together
2101 0 : lcl_TruncateMultiPortion( rMulti, rInf, nStartIdx );
2102 0 : pTmp = new SwRotatedPortion( nMultiLen + rInf.GetIdx(),
2103 0 : rMulti.GetDirection() );
2104 : }
2105 : // during a recursion of BuildMultiPortions we may not build
2106 : // a new SwBidiPortion, this would cause a memory leak
2107 0 : else if( rMulti.IsBidi() && ! pMulti )
2108 : {
2109 0 : if ( ! rMulti.GetLen() )
2110 0 : lcl_TruncateMultiPortion( rMulti, rInf, nStartIdx );
2111 :
2112 : // If there is a HolePortion at the end of the bidi portion,
2113 : // it has to be moved behind the bidi portion. Otherwise
2114 : // the visual cursor travelling gets into trouble.
2115 0 : SwLineLayout& aRoot = rMulti.GetRoot();
2116 0 : SwLinePortion* pPor = aRoot.GetFirstPortion();
2117 0 : while ( pPor )
2118 : {
2119 0 : if ( pPor->GetPortion() && pPor->GetPortion()->IsHolePortion() )
2120 : {
2121 0 : SwLinePortion* pHolePor = pPor->GetPortion();
2122 0 : pPor->SetPortion( NULL );
2123 0 : aRoot.SetLen( aRoot.GetLen() - pHolePor->GetLen() );
2124 0 : rMulti.SetLen( rMulti.GetLen() - pHolePor->GetLen() );
2125 0 : rMulti.SetPortion( pHolePor );
2126 0 : break;
2127 : }
2128 0 : pPor = pPor->GetPortion();
2129 : }
2130 :
2131 0 : pTmp = new SwBidiPortion( nMultiLen + rInf.GetIdx(),
2132 0 : ((SwBidiPortion&)rMulti).GetLevel() );
2133 : }
2134 : else
2135 0 : pTmp = NULL;
2136 :
2137 0 : if ( ! rMulti.GetLen() && rInf.GetLast() )
2138 : {
2139 0 : SeekAndChgBefore( rInf );
2140 0 : rInf.GetLast()->FormatEOL( rInf );
2141 : }
2142 :
2143 0 : if( pNextFirst && pTmp )
2144 : {
2145 0 : pTmp->SetFollowFld();
2146 0 : pTmp->GetRoot().SetPortion( pNextFirst );
2147 : }
2148 : else
2149 : // A follow field portion is still waiting. If nobody wants it,
2150 : // we delete it.
2151 0 : delete pNextFirst;
2152 :
2153 0 : rInf.SetRest( pTmp );
2154 : }
2155 :
2156 0 : rInf.SetTxt( *pOldTxt );
2157 0 : rInf.SetPaintOfst( nOldPaintOfst );
2158 0 : rInf.SetStop( aInf.IsStop() );
2159 0 : rInf.SetNumDone( true );
2160 0 : rInf.SetFtnDone( true );
2161 0 : SeekAndChg( rInf );
2162 0 : delete pFirstRest;
2163 0 : delete pSecondRest;
2164 0 : xFontSave.reset();
2165 0 : return bRet;
2166 : }
2167 :
2168 : /*--------------------------------------------------
2169 : * SwTxtFormatter::MakeRestPortion(..)
2170 : * When a fieldportion at the end of line breaks and needs a following
2171 : * fieldportion in the next line, then the "restportion" of the formatinfo
2172 : * has to be set. Normally this happens during the formatting of the first
2173 : * part of the fieldportion.
2174 : * But sometimes the formatting starts at the line with the following part,
2175 : * especially when the following part is on the next page.
2176 : * In this case the MakeRestPortion-function has to create the following part.
2177 : * The first parameter is the line that contains possibly a first part
2178 : * of a field. When the function finds such field part, it creates the right
2179 : * restportion. This may be a multiportion, e.g. if the field is surrounded by
2180 : * a doubleline- or ruby-portion.
2181 : * The second parameter is the start index of the line.
2182 : * --------------------------------------------------*/
2183 :
2184 0 : SwLinePortion* SwTxtFormatter::MakeRestPortion( const SwLineLayout* pLine,
2185 : sal_Int32 nPosition )
2186 : {
2187 0 : if( !nPosition )
2188 0 : return NULL;
2189 0 : sal_Int32 nMultiPos = nPosition - pLine->GetLen();
2190 0 : const SwMultiPortion *pTmpMulti = NULL;
2191 0 : const SwMultiPortion *pHelpMulti = NULL;
2192 0 : const SwLinePortion* pPor = pLine->GetFirstPortion();
2193 0 : SwFldPortion *pFld = NULL;
2194 0 : while( pPor )
2195 : {
2196 0 : if( pPor->GetLen() )
2197 : {
2198 0 : if( !pHelpMulti )
2199 : {
2200 0 : nMultiPos = nMultiPos + pPor->GetLen();
2201 0 : pTmpMulti = NULL;
2202 : }
2203 : }
2204 0 : if( pPor->InFldGrp() )
2205 : {
2206 0 : if( !pHelpMulti )
2207 0 : pTmpMulti = NULL;
2208 0 : pFld = (SwFldPortion*)pPor;
2209 : }
2210 0 : else if( pPor->IsMultiPortion() )
2211 : {
2212 : OSL_ENSURE( !pHelpMulti || pHelpMulti->IsBidi(),
2213 : "Nested multiportions are forbidden." );
2214 :
2215 0 : pFld = NULL;
2216 0 : pTmpMulti = (SwMultiPortion*)pPor;
2217 : }
2218 0 : pPor = pPor->GetPortion();
2219 : // If the last portion is a multi-portion, we enter it
2220 : // and look for a field portion inside.
2221 : // If we are already in a multiportion, we could change to the
2222 : // next line
2223 0 : if( !pPor && pTmpMulti )
2224 : {
2225 0 : if( pHelpMulti )
2226 : { // We're already inside the multiportion, let's take the second
2227 : // line, if we are in a double line portion
2228 0 : if( !pHelpMulti->IsRuby() )
2229 0 : pPor = pHelpMulti->GetRoot().GetNext();
2230 0 : pTmpMulti = NULL;
2231 : }
2232 : else
2233 : { // Now we enter a multiportion, in a ruby portion we take the
2234 : // main line, not the phonetic line, in a doublelineportion we
2235 : // starts with the first line.
2236 0 : pHelpMulti = pTmpMulti;
2237 0 : nMultiPos = nMultiPos - pHelpMulti->GetLen();
2238 0 : if( pHelpMulti->IsRuby() && pHelpMulti->OnTop() )
2239 0 : pPor = pHelpMulti->GetRoot().GetNext();
2240 : else
2241 0 : pPor = pHelpMulti->GetRoot().GetFirstPortion();
2242 : }
2243 : }
2244 : }
2245 0 : if( pFld && !pFld->HasFollow() )
2246 0 : pFld = NULL;
2247 :
2248 0 : SwLinePortion *pRest = NULL;
2249 0 : if( pFld )
2250 : {
2251 0 : const SwTxtAttr *pHint = GetAttr( nPosition - 1 );
2252 0 : if ( pHint
2253 0 : && ( pHint->Which() == RES_TXTATR_FIELD
2254 0 : || pHint->Which() == RES_TXTATR_ANNOTATION ) )
2255 : {
2256 0 : pRest = NewFldPortion( GetInfo(), pHint );
2257 0 : if( pRest->InFldGrp() )
2258 0 : ((SwFldPortion*)pRest)->TakeNextOffset( pFld );
2259 : else
2260 : {
2261 0 : delete pRest;
2262 0 : pRest = NULL;
2263 : }
2264 : }
2265 : }
2266 0 : if( !pHelpMulti )
2267 0 : return pRest;
2268 :
2269 0 : nPosition = nMultiPos + pHelpMulti->GetLen();
2270 0 : SwMultiCreator* pCreate = GetInfo().GetMultiCreator( nMultiPos, 0 );
2271 :
2272 0 : if ( !pCreate )
2273 : {
2274 : OSL_ENSURE( !pHelpMulti->GetLen(), "Multiportion without attribut?" );
2275 0 : if ( nMultiPos )
2276 0 : --nMultiPos;
2277 0 : pCreate = GetInfo().GetMultiCreator( --nMultiPos, 0 );
2278 : }
2279 :
2280 0 : if (!pCreate)
2281 0 : return pRest;
2282 :
2283 0 : if( pRest || nMultiPos > nPosition || ( pHelpMulti->IsRuby() &&
2284 0 : ((SwRubyPortion*)pHelpMulti)->GetRubyOffset() < COMPLETE_STRING ) )
2285 : {
2286 : SwMultiPortion* pTmp;
2287 0 : if( pHelpMulti->IsDouble() )
2288 0 : pTmp = new SwDoubleLinePortion( *pCreate, nMultiPos );
2289 0 : else if( pHelpMulti->IsBidi() )
2290 0 : pTmp = new SwBidiPortion( nMultiPos, pCreate->nLevel );
2291 0 : else if( pHelpMulti->IsRuby() )
2292 : {
2293 : bool bRubyTop;
2294 0 : bool* pRubyPos = 0;
2295 :
2296 0 : if ( GetInfo().SnapToGrid() )
2297 : {
2298 : SwTextGridItem const*const pGrid(
2299 0 : GetGridItem(pFrm->FindPageFrm()));
2300 0 : if ( pGrid )
2301 : {
2302 0 : bRubyTop = ! pGrid->GetRubyTextBelow();
2303 0 : pRubyPos = &bRubyTop;
2304 : }
2305 : }
2306 :
2307 0 : pTmp = new SwRubyPortion( *pCreate, *GetInfo().GetFont(),
2308 0 : *pFrm->GetTxtNode()->getIDocumentSettingAccess(),
2309 : nMultiPos, ((SwRubyPortion*)pHelpMulti)->GetRubyOffset(),
2310 0 : pRubyPos );
2311 : }
2312 0 : else if( pHelpMulti->HasRotation() )
2313 0 : pTmp = new SwRotatedPortion( nMultiPos, pHelpMulti->GetDirection() );
2314 : else
2315 : {
2316 0 : delete pCreate;
2317 0 : return pRest;
2318 : }
2319 0 : delete pCreate;
2320 0 : pTmp->SetFollowFld();
2321 0 : if( pRest )
2322 : {
2323 0 : SwLineLayout *pLay = &pTmp->GetRoot();
2324 0 : if( pTmp->IsRuby() && pTmp->OnTop() )
2325 : {
2326 0 : pLay->SetNext( new SwLineLayout() );
2327 0 : pLay = pLay->GetNext();
2328 : }
2329 0 : pLay->SetPortion( pRest );
2330 : }
2331 0 : return pTmp;
2332 : }
2333 0 : delete (pCreate);
2334 0 : return pRest;
2335 : }
2336 :
2337 : /*--------------------------------------------------
2338 : * SwTxtCursorSave notes the start and current line of a SwTxtCursor,
2339 : * sets them to the values for GetCrsrOfst inside a multiportion
2340 : * and restores them in the destructor.
2341 : * --------------------------------------------------*/
2342 :
2343 0 : SwTxtCursorSave::SwTxtCursorSave( SwTxtCursor* pTxtCursor,
2344 : SwMultiPortion* pMulti,
2345 : SwTwips nY,
2346 : sal_uInt16& nX,
2347 : sal_Int32 nCurrStart,
2348 : long nSpaceAdd )
2349 : {
2350 0 : pTxtCrsr = pTxtCursor;
2351 0 : nStart = pTxtCursor->nStart;
2352 0 : pTxtCursor->nStart = nCurrStart;
2353 0 : pCurr = pTxtCursor->pCurr;
2354 0 : pTxtCursor->pCurr = &pMulti->GetRoot();
2355 0 : while( pTxtCursor->Y() + pTxtCursor->GetLineHeight() < nY &&
2356 0 : pTxtCursor->Next() )
2357 : ; // nothing
2358 0 : nWidth = pTxtCursor->pCurr->Width();
2359 0 : nOldProp = pTxtCursor->GetPropFont();
2360 :
2361 0 : if ( pMulti->IsDouble() || pMulti->IsBidi() )
2362 : {
2363 0 : bSpaceChg = pMulti->ChgSpaceAdd( pTxtCursor->pCurr, nSpaceAdd );
2364 :
2365 : sal_uInt16 nSpaceCnt;
2366 0 : if ( pMulti->IsDouble() )
2367 : {
2368 0 : pTxtCursor->SetPropFont( 50 );
2369 0 : nSpaceCnt = ((SwDoubleLinePortion*)pMulti)->GetSpaceCnt();
2370 : }
2371 : else
2372 : {
2373 0 : const sal_Int32 nOldIdx = pTxtCursor->GetInfo().GetIdx();
2374 0 : pTxtCursor->GetInfo().SetIdx ( nCurrStart );
2375 0 : nSpaceCnt = ((SwBidiPortion*)pMulti)->GetSpaceCnt(pTxtCursor->GetInfo());
2376 0 : pTxtCursor->GetInfo().SetIdx ( nOldIdx );
2377 : }
2378 :
2379 0 : if( nSpaceAdd > 0 && !pMulti->HasTabulator() )
2380 0 : pTxtCursor->pCurr->Width( static_cast<sal_uInt16>(nWidth + nSpaceAdd * nSpaceCnt / SPACING_PRECISION_FACTOR ) );
2381 :
2382 : // For a BidiPortion we have to calculate the offset from the
2383 : // end of the portion
2384 0 : if ( nX && pMulti->IsBidi() )
2385 0 : nX = pTxtCursor->pCurr->Width() - nX;
2386 : }
2387 : else
2388 0 : bSpaceChg = false;
2389 0 : }
2390 :
2391 0 : SwTxtCursorSave::~SwTxtCursorSave()
2392 : {
2393 0 : if( bSpaceChg )
2394 0 : SwDoubleLinePortion::ResetSpaceAdd( pTxtCrsr->pCurr );
2395 0 : pTxtCrsr->pCurr->Width( KSHORT(nWidth) );
2396 0 : pTxtCrsr->pCurr = pCurr;
2397 0 : pTxtCrsr->nStart = nStart;
2398 0 : pTxtCrsr->SetPropFont( nOldProp );
2399 0 : }
2400 :
2401 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|