Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "porlay.hxx"
31 : : #include "itrform2.hxx"
32 : : #include "porglue.hxx"
33 : : #include "porexp.hxx" // SwQuoVadisPortion
34 : : #include "blink.hxx" // pBlink
35 : : #include "redlnitr.hxx" // SwRedlineItr
36 : : #include "porfly.hxx" // SwFlyCntPortion
37 : : #include <porrst.hxx> // SwHangingPortion
38 : : #include <pormulti.hxx> // SwMultiPortion
39 : : #include <breakit.hxx>
40 : : #include <unicode/uchar.h>
41 : : #include <com/sun/star/i18n/ScriptType.hpp>
42 : : #include <com/sun/star/i18n/CTLScriptType.hpp>
43 : : #include <com/sun/star/i18n/WordType.hpp>
44 : : #include <paratr.hxx>
45 : : #include <editeng/adjitem.hxx>
46 : : #include <editeng/scripttypeitem.hxx>
47 : : #include <editeng/charhiddenitem.hxx>
48 : : #include <vcl/outdev.hxx>
49 : : #include <editeng/blnkitem.hxx>
50 : : #include <tools/multisel.hxx>
51 : : #include <unotools/charclass.hxx>
52 : : #include <i18npool/mslangid.hxx>
53 : : #include <charfmt.hxx>
54 : : #include <fchrfmt.hxx>
55 : : #include <docary.hxx> // SwRedlineTbl
56 : : #include <redline.hxx> // SwRedline
57 : : #include <section.hxx>
58 : : #include <switerator.hxx>
59 : : #include <IDocumentRedlineAccess.hxx>
60 : : #include <IDocumentSettingAccess.hxx>
61 : : #include <IDocumentContentOperations.hxx>
62 : :
63 : : using namespace ::com::sun::star;
64 : : using namespace i18n::ScriptType;
65 : :
66 : : #include <unicode/ubidi.h>
67 : : #include <i18nutil/scripttypedetector.hxx>
68 : : #include <i18nutil/unicode.hxx>
69 : :
70 : : #define IS_JOINING_GROUP(c, g) ( u_getIntPropertyValue( (c), UCHAR_JOINING_GROUP ) == U_JG_##g )
71 : : #define isAinChar(c) IS_JOINING_GROUP((c), AIN)
72 : : #define isAlefChar(c) IS_JOINING_GROUP((c), ALEF)
73 : : #define isBaaChar(c) IS_JOINING_GROUP((c), BEH)
74 : : #define isDalChar(c) IS_JOINING_GROUP((c), DAL)
75 : : #define isFehChar(c) IS_JOINING_GROUP((c), FEH)
76 : : #define isGafChar(c) IS_JOINING_GROUP((c), GAF)
77 : : #define isHahChar(c) IS_JOINING_GROUP((c), HAH)
78 : : #define isKafChar(c) IS_JOINING_GROUP((c), KAF)
79 : : #define isLamChar(c) IS_JOINING_GROUP((c), LAM)
80 : : #define isQafChar(c) IS_JOINING_GROUP((c), QAF)
81 : : #define isRehChar(c) IS_JOINING_GROUP((c), REH)
82 : : #define isTehMarbutaChar(c) IS_JOINING_GROUP((c), TEH_MARBUTA)
83 : : #define isWawChar(c) IS_JOINING_GROUP((c), WAW)
84 : : #if ( (U_ICU_VERSION_MAJOR_NUM > 4 ) || ((U_ICU_VERSION_MAJOR_NUM == 4) && (U_ICU_VERSION_MINOR_NUM >= 4)) )
85 : : #define isYehChar(c) (IS_JOINING_GROUP((c), YEH) || IS_JOINING_GROUP((c), FARSI_YEH))
86 : : #else
87 : : #define isYehChar(c) (c == 0x626 || c == 0x649 || c == 0x64A || c == 0x678 || c == 0x6CC || c == 0x6CE || c == 0x6D0 || c == 0x6D1)
88 : : #endif
89 : : #define isSeenOrSadChar(c) (IS_JOINING_GROUP((c), SAD) || IS_JOINING_GROUP((c), SEEN))
90 : :
91 : 0 : sal_Bool isTransparentChar ( xub_Unicode cCh )
92 : : {
93 : 0 : return u_getIntPropertyValue( cCh, UCHAR_JOINING_TYPE ) == U_JT_TRANSPARENT;
94 : : }
95 : :
96 : : /*************************************************************************
97 : : * lcl_IsLigature
98 : : *
99 : : * Checks if cCh + cNectCh builds a ligature (used for Kashidas)
100 : : *************************************************************************/
101 : :
102 : 0 : sal_Bool lcl_IsLigature( xub_Unicode cCh, xub_Unicode cNextCh )
103 : : {
104 : : // Lam + Alef
105 [ # # ][ # # ]: 0 : return ( isLamChar ( cCh ) && isAlefChar ( cNextCh ));
106 : : }
107 : :
108 : : /*************************************************************************
109 : : * lcl_ConnectToPrev
110 : : *
111 : : * Checks if cCh is connectable to cPrevCh (used for Kashidas)
112 : : *************************************************************************/
113 : :
114 : 0 : sal_Bool lcl_ConnectToPrev( xub_Unicode cCh, xub_Unicode cPrevCh )
115 : : {
116 : 0 : const int32_t nJoiningType = u_getIntPropertyValue( cPrevCh, UCHAR_JOINING_TYPE );
117 [ # # ][ # # ]: 0 : sal_Bool bRet = nJoiningType != U_JT_RIGHT_JOINING && nJoiningType != U_JT_NON_JOINING;
118 : :
119 : : // check for ligatures cPrevChar + cChar
120 [ # # ]: 0 : if( bRet )
121 : 0 : bRet = !lcl_IsLigature( cPrevCh, cCh );
122 : :
123 : 0 : return bRet;
124 : : }
125 : :
126 : : /*************************************************************************
127 : : * lcl_HasStrongLTR
128 : : *************************************************************************/
129 : 0 : bool lcl_HasStrongLTR ( const String& rTxt, xub_StrLen nStart, xub_StrLen nEnd )
130 : : {
131 [ # # ]: 0 : for ( xub_StrLen nCharIdx = nStart; nCharIdx < nEnd; ++nCharIdx )
132 : : {
133 : 0 : const UCharDirection nCharDir = u_charDirection ( rTxt.GetChar ( nCharIdx ));
134 [ # # ][ # # ]: 0 : if ( nCharDir == U_LEFT_TO_RIGHT ||
[ # # ]
135 : : nCharDir == U_LEFT_TO_RIGHT_EMBEDDING ||
136 : : nCharDir == U_LEFT_TO_RIGHT_OVERRIDE )
137 : 0 : return true;
138 : : }
139 : 0 : return false;
140 : : }
141 : :
142 : : /*************************************************************************
143 : : * SwLineLayout::~SwLineLayout()
144 : : *
145 : : * class SwLineLayout: This is the layout of a single line, which is made
146 : : * up of it's dimension, the character count and the word spacing in the
147 : : * line.
148 : : * Line objects are managed in an own pool, in order to store them continuously
149 : : * in memory so that they are paged out together and don't fragment memory.
150 : : *************************************************************************/
151 : :
152 : 12829 : SwLineLayout::~SwLineLayout()
153 : : {
154 [ + - ]: 12829 : Truncate();
155 [ + + ][ + - ]: 12829 : delete pNext;
156 [ + + ]: 12829 : if( pBlink )
157 [ + - ]: 1242 : pBlink->Delete( this );
158 [ + + ]: 12829 : delete pLLSpaceAdd;
159 [ - + ]: 12829 : delete pKanaComp;
160 [ - + ]: 20211 : }
161 : :
162 : 4732 : SwLinePortion *SwLineLayout::Insert( SwLinePortion *pIns )
163 : : {
164 : : // First attribute change: copy mass and length from *pIns into the first
165 : : // text portion
166 [ + - ]: 4732 : if( !pPortion )
167 : : {
168 [ + + ]: 4732 : if( GetLen() )
169 : : {
170 [ + - ]: 2004 : pPortion = new SwTxtPortion( *(SwLinePortion*)this );
171 [ - + ][ # # ]: 2004 : if( IsBlinking() && pBlink )
[ - + ]
172 : : {
173 : 0 : SetBlinking( sal_False );
174 : 0 : pBlink->Replace( this, pPortion );
175 : : }
176 : : }
177 : : else
178 : : {
179 : 2728 : SetPortion( pIns );
180 : 2728 : return pIns;
181 : : }
182 : : }
183 : : // Call with scope or we'll end up with recursion!
184 : 4732 : return pPortion->SwLinePortion::Insert( pIns );
185 : : }
186 : :
187 : 20 : SwLinePortion *SwLineLayout::Append( SwLinePortion *pIns )
188 : : {
189 : : // First attribute change: copy mass and length from *pIns into the first
190 : : // text portion
191 [ + - ]: 20 : if( !pPortion )
192 [ + - ]: 20 : pPortion = new SwTxtPortion( *(SwLinePortion*)this );
193 : : // Call with scope or we'll end up with recursion!
194 : 20 : return pPortion->SwLinePortion::Append( pIns );
195 : : }
196 : :
197 : : // For special treatment of empty lines
198 : :
199 : 49260 : sal_Bool SwLineLayout::Format( SwTxtFormatInfo &rInf )
200 : : {
201 [ + - ]: 49260 : if( GetLen() )
202 : 49260 : return SwTxtPortion::Format( rInf );
203 : : else
204 : : {
205 : 0 : Height( rInf.GetTxtHeight() );
206 : 49260 : return sal_True;
207 : : }
208 : : }
209 : :
210 : : /*************************************************************************
211 : : * SwLineLayout::CalcLeftMargin()
212 : : *
213 : : * We collect all FlyPortions at the beginning of the line and make that a
214 : : * MarginPortion.
215 : : *************************************************************************/
216 : :
217 : 885 : SwMarginPortion *SwLineLayout::CalcLeftMargin()
218 : : {
219 : 893 : SwMarginPortion *pLeft = (GetPortion() && GetPortion()->IsMarginPortion()) ?
220 [ + + - + ]: 893 : (SwMarginPortion *)GetPortion() : 0;
221 [ + + ]: 885 : if( !GetPortion() )
222 [ + - ]: 877 : SetPortion( new SwTxtPortion( *(SwLinePortion*)this ) );
223 [ + - ]: 885 : if( !pLeft )
224 : : {
225 [ + - ]: 885 : pLeft = new SwMarginPortion( 0 );
226 : 885 : pLeft->SetPortion( GetPortion() );
227 : 885 : SetPortion( pLeft );
228 : : }
229 : : else
230 : : {
231 : 0 : pLeft->Height( 0 );
232 : 0 : pLeft->Width( 0 );
233 : 0 : pLeft->SetLen( 0 );
234 : 0 : pLeft->SetAscent( 0 );
235 : 0 : pLeft->SetPortion( NULL );
236 : 0 : pLeft->SetFixWidth(0);
237 : : }
238 : :
239 : 885 : SwLinePortion *pPos = pLeft->GetPortion();
240 [ + + ]: 1770 : while( pPos )
241 : : {
242 [ + + ]: 885 : if( pPos->IsFlyPortion() )
243 : : {
244 : : // The FlyPortion get's sucked out ...
245 : 3 : pLeft->Join( (SwGluePortion*)pPos );
246 : 3 : pPos = pLeft->GetPortion();
247 [ # # ][ - + ]: 3 : if( GetpKanaComp() && !GetKanaComp().empty() )
[ - + ]
248 : 0 : GetKanaComp().pop_front();
249 : : }
250 : : else
251 : 882 : pPos = 0;
252 : : }
253 : 885 : return pLeft;
254 : : }
255 : :
256 : 20 : void SwLineLayout::InitSpaceAdd()
257 : : {
258 [ + - ]: 20 : if ( !pLLSpaceAdd )
259 : 20 : CreateSpaceAdd();
260 : : else
261 : 0 : SetLLSpaceAdd( 0, 0 );
262 : 20 : }
263 : :
264 : 20 : void SwLineLayout::CreateSpaceAdd( const long nInit )
265 : : {
266 [ + - ]: 20 : pLLSpaceAdd = new std::vector<long>;
267 : 20 : SetLLSpaceAdd( nInit, 0 );
268 : 20 : }
269 : :
270 : : /*************************************************************************
271 : : * Local helper function. Returns true if there are only blanks
272 : : * in [nStt, nEnd[
273 : : *************************************************************************/
274 : :
275 : 369 : bool lcl_HasOnlyBlanks( const XubString& rTxt, xub_StrLen nStt, xub_StrLen nEnd )
276 : : {
277 : 369 : bool bBlankOnly = true;
278 [ + + ]: 375 : while ( nStt < nEnd )
279 : : {
280 : 348 : const xub_Unicode cChar = rTxt.GetChar( nStt++ );
281 [ + - ][ + + ]: 348 : if ( ' ' != cChar && 0x3000 != cChar )
282 : : {
283 : 342 : bBlankOnly = false;
284 : 342 : break;
285 : : }
286 : : }
287 : 369 : return bBlankOnly;
288 : : }
289 : :
290 : : /*************************************************************************
291 : : * SwLineLayout::CalcLine()
292 : : *
293 : : * Swapped out from FormatLine()
294 : : *************************************************************************/
295 : :
296 : 55335 : void SwLineLayout::CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf )
297 : : {
298 : 55335 : const KSHORT nLineWidth = rInf.RealWidth();
299 : :
300 : 55335 : KSHORT nFlyAscent = 0;
301 : 55335 : KSHORT nFlyHeight = 0;
302 : 55335 : KSHORT nFlyDescent = 0;
303 : 55335 : sal_Bool bOnlyPostIts = sal_True;
304 : 55335 : SetHanging( sal_False );
305 : :
306 : 55335 : sal_Bool bTmpDummy = ( 0 == GetLen() );
307 : 55335 : SwFlyCntPortion* pFlyCnt = 0;
308 [ + + ]: 55335 : if( bTmpDummy )
309 : : {
310 : 5121 : nFlyAscent = 0;
311 : 5121 : nFlyHeight = 0;
312 : 5121 : nFlyDescent = 0;
313 : : }
314 : :
315 : : // #i3952#
316 : : const bool bIgnoreBlanksAndTabsForLineHeightCalculation =
317 : 55335 : rInf.GetTxtFrm()->GetNode()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::IGNORE_TABS_AND_BLANKS_FOR_LINE_CALCULATION);
318 : :
319 : 55335 : bool bHasBlankPortion = false;
320 : 55335 : bool bHasOnlyBlankPortions = true;
321 : :
322 [ + + ]: 55335 : if( pPortion )
323 : : {
324 : 6007 : SetCntnt( sal_False );
325 [ + + ]: 6007 : if( pPortion->IsBreakPortion() )
326 : : {
327 : 159 : SetLen( pPortion->GetLen() );
328 [ + - ]: 159 : if( GetLen() )
329 : 159 : bTmpDummy = sal_False;
330 : : }
331 : : else
332 : : {
333 : 5848 : KSHORT nLineHeight = Height();
334 : 5848 : Init( GetPortion() );
335 : 5848 : SwLinePortion *pPos = pPortion;
336 : 5848 : SwLinePortion *pLast = this;
337 : 5848 : KSHORT nMaxDescent = 0;
338 : :
339 : : // A group is a segment in the portion chain of pCurr or a fixed
340 : : // portion spanning to the end or the next fixed portion
341 [ + + ]: 17280 : while( pPos )
342 : : {
343 : : SAL_WARN_IF( POR_LIN == pPos->GetWhichPor(),
344 : : "sw.core", "SwLineLayout::CalcLine: don't use SwLinePortions !" );
345 : :
346 : : // Null portions are eliminated. They can form if two FlyFrms
347 : : // overlap.
348 [ + - ][ + + ]: 11432 : if( !pPos->Compress() )
349 : : {
350 : : // Only take over Height and Ascent if the rest of the line
351 : : // is empty.
352 [ + + ]: 604 : if( !pPos->GetPortion() )
353 : : {
354 [ + + ]: 409 : if( !Height() )
355 : 137 : Height( pPos->Height() );
356 [ + + ]: 409 : if( !GetAscent() )
357 : 143 : SetAscent( pPos->GetAscent() );
358 : : }
359 [ + - ][ + - ]: 604 : delete pLast->Cut( pPos );
[ + - ]
360 : 604 : pPos = pLast->GetPortion();
361 : 604 : continue;
362 : : }
363 : :
364 : 10828 : const xub_StrLen nPorSttIdx = rInf.GetLineStart() + nLineLength;
365 : 10828 : nLineLength = nLineLength + pPos->GetLen();
366 : 10828 : AddPrtWidth( pPos->Width() );
367 : :
368 : : // #i3952#
369 [ + + ]: 10828 : if ( bIgnoreBlanksAndTabsForLineHeightCalculation )
370 : : {
371 [ + - ][ + + : 132 : if ( pPos->InTabGrp() || pPos->IsHolePortion() ||
+ + - + ]
[ + + ]
372 : 57 : ( pPos->IsTextPortion() &&
373 : 15 : lcl_HasOnlyBlanks( rInf.GetTxt(), nPorSttIdx, nPorSttIdx + pPos->GetLen() ) ) )
374 : : {
375 : 3 : pLast = pPos;
376 : 3 : pPos = pPos->GetPortion();
377 : 3 : bHasBlankPortion = true;
378 : 3 : continue;
379 : : }
380 : : }
381 : :
382 : 10825 : bHasOnlyBlankPortions = false;
383 : :
384 : : // We had an attribute change: Sum up/build maxima of length and mass
385 : :
386 : 10825 : KSHORT nPosHeight = pPos->Height();
387 : 10825 : KSHORT nPosAscent = pPos->GetAscent();
388 : :
389 : : SAL_WARN_IF( nPosHeight < nPosAscent,
390 : : "sw.core", "SwLineLayout::CalcLine: bad ascent or height" );
391 : :
392 [ - + ]: 10825 : if( pPos->IsHangingPortion() )
393 : : {
394 : 0 : SetHanging( sal_True );
395 : 0 : rInf.GetParaPortion()->SetMargin( sal_True );
396 : : }
397 : :
398 : : // To prevent that a paragraph-end-character does not change
399 : : // the line height through a Descent and thus causing the line
400 : : // to reformat.
401 [ + + ][ - + ]: 10825 : if ( !pPos->IsBreakPortion() || !Height() )
[ + + ]
402 : : {
403 : 10713 : bOnlyPostIts &= pPos->IsPostItsPortion();
404 : :
405 [ + + ][ + + ]: 10713 : if( bTmpDummy && !nLineLength )
406 : : {
407 [ + + ]: 1076 : if( pPos->IsFlyPortion() )
408 : : {
409 [ + - ]: 56 : if( nFlyHeight < nPosHeight )
410 : 56 : nFlyHeight = nPosHeight;
411 [ + - ]: 56 : if( nFlyAscent < nPosAscent )
412 : 56 : nFlyAscent = nPosAscent;
413 [ + + ]: 56 : if( nFlyDescent < nPosHeight - nPosAscent )
414 : 50 : nFlyDescent = nPosHeight - nPosAscent;
415 : : }
416 : : else
417 : : {
418 [ + + ]: 1020 : if( pPos->InNumberGrp() )
419 : : {
420 : : KSHORT nTmp = rInf.GetFont()->GetAscent(
421 [ + - ]: 362 : rInf.GetVsh(), *rInf.GetOut() );
422 [ + + ]: 362 : if( nTmp > nPosAscent )
423 : : {
424 : 18 : nPosHeight += nTmp - nPosAscent;
425 : 18 : nPosAscent = nTmp;
426 : : }
427 : : nTmp = rInf.GetFont()->GetHeight( rInf.GetVsh(),
428 [ + - ]: 362 : *rInf.GetOut() );
429 [ + + ]: 362 : if( nTmp > nPosHeight )
430 : 18 : nPosHeight = nTmp;
431 : : }
432 : 1020 : Height( nPosHeight );
433 : 1020 : nAscent = nPosAscent;
434 : 1020 : nMaxDescent = nPosHeight - nPosAscent;
435 : 1076 : }
436 : : }
437 [ + + ]: 9637 : else if( !pPos->IsFlyPortion() )
438 : : {
439 [ + + ]: 9565 : if( Height() < nPosHeight )
440 : : {
441 : : // Height is set to 0 when Init() is called.
442 [ + + ][ + + ]: 5093 : if (bIgnoreBlanksAndTabsForLineHeightCalculation && pPos->GetWhichPor() == POR_FLYCNT)
[ + + ]
443 : : // Compat flag set: take the line height, if it's larger.
444 [ + - ]: 30 : Height(std::max(nPosHeight, nLineHeight));
445 : : else
446 : : // Just care about the portion height.
447 : 5063 : Height(nPosHeight);
448 : : }
449 [ + + ]: 9921 : if( pPos->IsFlyCntPortion() || ( pPos->IsMultiPortion()
[ + + - + ]
[ + + ]
450 : 356 : && ((SwMultiPortion*)pPos)->HasFlyInCntnt() ) )
451 : 2532 : rLine.SetFlyInCntBase();
452 [ + + - + ]: 12097 : if( pPos->IsFlyCntPortion() &&
[ - + ]
453 : 2532 : ((SwFlyCntPortion*)pPos)->GetAlign() )
454 : : {
455 : 0 : ((SwFlyCntPortion*)pPos)->SetMax( sal_False );
456 [ # # ][ # # ]: 0 : if( !pFlyCnt || pPos->Height() > pFlyCnt->Height() )
[ # # ]
457 : 0 : pFlyCnt = (SwFlyCntPortion*)pPos;
458 : : }
459 : : else
460 : : {
461 [ + + ]: 9565 : if( nAscent < nPosAscent )
462 : 3800 : nAscent = nPosAscent;
463 [ + + ]: 9565 : if( nMaxDescent < nPosHeight - nPosAscent )
464 : 10713 : nMaxDescent = nPosHeight - nPosAscent;
465 : : }
466 : : }
467 : : }
468 [ + - ]: 112 : else if( pPos->GetLen() )
469 : 112 : bTmpDummy = sal_False;
470 : :
471 [ + + ][ + + ]: 10825 : if( !HasCntnt() && !pPos->InNumberGrp() )
[ + + ]
472 : : {
473 [ + + ]: 6613 : if ( pPos->InExpGrp() )
474 : : {
475 [ + - ]: 786 : XubString aTxt;
476 [ + - ][ + - ]: 786 : if( pPos->GetExpTxt( rInf, aTxt ) && aTxt.Len() )
[ + + ][ + + ]
477 [ + - ]: 786 : SetCntnt( sal_True );
478 : : }
479 [ + + ]: 8868 : else if( ( pPos->InTxtGrp() || pPos->IsMultiPortion() ) &&
[ + + + - ]
[ + + ]
480 : 3041 : pPos->GetLen() )
481 : 3041 : SetCntnt( sal_True );
482 : : }
483 : :
484 : 2834 : bTmpDummy = bTmpDummy && !HasCntnt() &&
485 [ + + + + ]: 13659 : ( !pPos->Width() || pPos->IsFlyPortion() );
[ + + ][ + + ]
486 : :
487 : 10825 : pLast = pPos;
488 : 11432 : pPos = pPos->GetPortion();
489 : : }
490 : :
491 [ - + ]: 5848 : if( pFlyCnt )
492 : : {
493 [ # # ]: 0 : if( pFlyCnt->Height() == Height() )
494 : : {
495 : 0 : pFlyCnt->SetMax( sal_True );
496 [ # # ]: 0 : if( Height() > nMaxDescent + nAscent )
497 : : {
498 [ # # ]: 0 : if( 3 == pFlyCnt->GetAlign() ) // Bottom
499 : 0 : nAscent = Height() - nMaxDescent;
500 [ # # ]: 0 : else if( 2 == pFlyCnt->GetAlign() ) // Center
501 : 0 : nAscent = ( Height() + nAscent - nMaxDescent ) / 2;
502 : : }
503 : 0 : pFlyCnt->SetAscent( nAscent );
504 : : }
505 : : }
506 : :
507 [ + + ][ + + ]: 5848 : if( bTmpDummy && nFlyHeight )
508 : : {
509 : 56 : nAscent = nFlyAscent;
510 [ - + ]: 112 : if( nFlyDescent > nFlyHeight - nFlyAscent )
511 : 0 : Height( nFlyHeight + nFlyDescent );
512 : : else
513 : 56 : Height( nFlyHeight );
514 : : }
515 [ + + ]: 5792 : else if( nMaxDescent > Height() - nAscent )
516 : 55 : Height( nMaxDescent + nAscent );
517 : :
518 [ + + ][ - + ]: 5848 : if( bOnlyPostIts && !( bHasBlankPortion && bHasOnlyBlankPortions ) )
[ # # ]
519 : : {
520 [ + - ]: 128 : Height( rInf.GetFont()->GetHeight( rInf.GetVsh(), *rInf.GetOut() ) );
521 [ + - ]: 5848 : nAscent = rInf.GetFont()->GetAscent( rInf.GetVsh(), *rInf.GetOut() );
522 : : }
523 : : }
524 : : }
525 : : else
526 : : {
527 : 49328 : SetCntnt( !bTmpDummy );
528 : :
529 : : // #i3952#
530 [ + + ]: 49682 : if ( bIgnoreBlanksAndTabsForLineHeightCalculation &&
[ + + + + ]
531 : 354 : lcl_HasOnlyBlanks( rInf.GetTxt(), rInf.GetLineStart(), rInf.GetLineStart() + GetLen() ) )
532 : : {
533 : 27 : bHasBlankPortion = true;
534 : : }
535 : : }
536 : :
537 : : // #i3952#
538 [ + + ][ + + ]: 55335 : if ( bHasBlankPortion && bHasOnlyBlankPortions )
539 : : {
540 : 27 : sal_uInt16 nTmpAscent = GetAscent();
541 : 27 : sal_uInt16 nTmpHeight = Height();
542 [ + - ]: 27 : rLine.GetAttrHandler().GetDefaultAscentAndHeight( rInf.GetVsh(), *rInf.GetOut(), nTmpAscent, nTmpHeight );
543 : 27 : SetAscent( nTmpAscent );
544 : 27 : Height( nTmpHeight );
545 : : }
546 : :
547 : : // Robust:
548 [ + + ]: 55335 : if( nLineWidth < Width() )
549 : 24 : Width( nLineWidth );
550 : : SAL_WARN_IF( nLineWidth < Width(), "sw.core", "SwLineLayout::CalcLine: line is bursting" );
551 : 55335 : SetDummy( bTmpDummy );
552 : 55335 : SetRedline( rLine.GetRedln() &&
553 [ # # ][ - + ]: 55335 : rLine.GetRedln()->CheckLine( rLine.GetStart(), rLine.GetEnd() ) );
554 : 55335 : }
555 : :
556 : : // #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
557 : : // to control, if the fly content portions and line portion are considered.
558 : 30889 : void SwLineLayout::MaxAscentDescent( SwTwips& _orAscent,
559 : : SwTwips& _orDescent,
560 : : SwTwips& _orObjAscent,
561 : : SwTwips& _orObjDescent,
562 : : const SwLinePortion* _pDontConsiderPortion,
563 : : const bool _bNoFlyCntPorAndLinePor ) const
564 : : {
565 : 30889 : _orAscent = 0;
566 : 30889 : _orDescent = 0;
567 : 30889 : _orObjAscent = 0;
568 : 30889 : _orObjDescent = 0;
569 : :
570 : 30889 : const SwLinePortion* pTmpPortion = this;
571 [ + + ][ + + ]: 30889 : if ( !pTmpPortion->GetLen() && pTmpPortion->GetPortion() )
[ + + ]
572 : : {
573 : 684 : pTmpPortion = pTmpPortion->GetPortion();
574 : : }
575 : :
576 [ + + ]: 75550 : while ( pTmpPortion )
577 : : {
578 [ + + ][ + + ]: 79784 : if ( !pTmpPortion->IsBreakPortion() && !pTmpPortion->IsFlyPortion() &&
[ + + + + ]
[ + + ][ + + ]
579 : 44340 : ( !_bNoFlyCntPorAndLinePor ||
580 : 20354 : ( !pTmpPortion->IsFlyCntPortion() &&
581 [ + + ]: 14769 : !(pTmpPortion == this && pTmpPortion->GetPortion() ) ) ) )
582 : : {
583 : 40186 : SwTwips nPortionAsc = static_cast<SwTwips>(pTmpPortion->GetAscent());
584 : 40186 : SwTwips nPortionDesc = static_cast<SwTwips>(pTmpPortion->Height()) -
585 : 40186 : nPortionAsc;
586 : :
587 : 40186 : const sal_Bool bFlyCmp = pTmpPortion->IsFlyCntPortion() ?
588 : : static_cast<const SwFlyCntPortion*>(pTmpPortion)->IsMax() :
589 [ + + ]: 40186 : !( pTmpPortion == _pDontConsiderPortion );
590 : :
591 [ + + ]: 40186 : if ( bFlyCmp )
592 : : {
593 : 33477 : _orObjAscent = Max( _orObjAscent, nPortionAsc );
594 : 33477 : _orObjDescent = Max( _orObjDescent, nPortionDesc );
595 : : }
596 : :
597 [ + + ][ + - ]: 40186 : if ( !pTmpPortion->IsFlyCntPortion() && !pTmpPortion->IsGrfNumPortion() )
[ + + ]
598 : : {
599 : 33477 : _orAscent = Max( _orAscent, nPortionAsc );
600 : 33477 : _orDescent = Max( _orDescent, nPortionDesc );
601 : : }
602 : : }
603 : 44661 : pTmpPortion = pTmpPortion->GetPortion();
604 : : }
605 : 30889 : }
606 : :
607 : 9749 : SwCharRange &SwCharRange::operator+=(const SwCharRange &rRange)
608 : : {
609 [ + - ]: 9749 : if(0 != rRange.nLen ) {
610 [ + + ]: 9749 : if(0 == nLen) {
611 : 8886 : nStart = rRange.nStart;
612 : 8886 : nLen = rRange.nLen ;
613 : : }
614 : : else {
615 [ + - ]: 863 : if(rRange.nStart + rRange.nLen > nStart + nLen) {
616 : 863 : nLen = rRange.nStart + rRange.nLen - nStart;
617 : : }
618 [ + + ]: 863 : if(rRange.nStart < nStart) {
619 : 10 : nLen += nStart - rRange.nStart;
620 : 10 : nStart = rRange.nStart;
621 : : }
622 : : }
623 : : }
624 : 9749 : return *this;
625 : : }
626 : :
627 : 5113 : SwScriptInfo::SwScriptInfo() :
628 : : nInvalidityPos( 0 ),
629 [ + - ][ + - ]: 5113 : nDefaultDir( 0 )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
630 : : {
631 : 5113 : };
632 : :
633 : 5113 : SwScriptInfo::~SwScriptInfo()
634 : : {
635 : 5113 : }
636 : :
637 : : /*************************************************************************
638 : : * SwScriptInfo::WhichFont()
639 : : *
640 : : * Converts i18n Script Type (LATIN, ASIAN, COMPLEX, WEAK) to
641 : : * Sw Script Types (SW_LATIN, SW_CJK, SW_CTL), used to identify the font
642 : : *************************************************************************/
643 : :
644 : 330438 : sal_uInt8 SwScriptInfo::WhichFont( xub_StrLen nIdx, const String* pTxt, const SwScriptInfo* pSI )
645 : : {
646 : : SAL_WARN_IF( !pTxt && !pSI, "sw.core", "How should I determine the script type?" );
647 : : sal_uInt16 nScript;
648 : :
649 : : // First we try to use our SwScriptInfo
650 [ + + ]: 330438 : if ( pSI )
651 : 330432 : nScript = pSI->ScriptType( nIdx );
652 : : else
653 : : // Ok, we have to ask the break iterator
654 [ + - ]: 6 : nScript = pBreakIt->GetRealScriptOfText( *pTxt, nIdx );
655 : :
656 [ + + - - ]: 330438 : switch ( nScript ) {
657 : 330384 : case i18n::ScriptType::LATIN : return SW_LATIN;
658 : 54 : case i18n::ScriptType::ASIAN : return SW_CJK;
659 : 0 : case i18n::ScriptType::COMPLEX : return SW_CTL;
660 : : }
661 : :
662 : : OSL_FAIL( "Somebody tells lies about the script type!" );
663 : 330438 : return SW_LATIN;
664 : : }
665 : :
666 : : /*************************************************************************
667 : : * SwScriptInfo::InitScriptInfo()
668 : : *
669 : : * searches for script changes in rTxt and stores them
670 : : *************************************************************************/
671 : :
672 : 6 : void SwScriptInfo::InitScriptInfo( const SwTxtNode& rNode )
673 : : {
674 : 6 : InitScriptInfo( rNode, nDefaultDir == UBIDI_RTL );
675 : 6 : }
676 : :
677 : 13602 : void SwScriptInfo::InitScriptInfo( const SwTxtNode& rNode, sal_Bool bRTL )
678 : : {
679 [ + - ][ + - ]: 13602 : if( !pBreakIt->GetBreakIter().is() )
680 : 13602 : return;
681 : :
682 : 13602 : const String& rTxt = rNode.GetTxt();
683 : :
684 : : //
685 : : // HIDDEN TEXT INFORMATION
686 : : //
687 [ + + ]: 13602 : Range aRange( 0, rTxt.Len() ? rTxt.Len() - 1 : 0 );
688 [ + - ]: 13602 : MultiSelection aHiddenMulti( aRange );
689 [ + - ]: 13602 : CalcHiddenRanges( rNode, aHiddenMulti );
690 : :
691 : 13602 : aHiddenChg.clear();
692 : 13602 : sal_uInt16 i = 0;
693 [ - + ]: 13602 : for( i = 0; i < aHiddenMulti.GetRangeCount(); ++i )
694 : : {
695 [ # # ]: 0 : const Range& rRange = aHiddenMulti.GetRange( i );
696 : 0 : const xub_StrLen nStart = (xub_StrLen)rRange.Min();
697 : 0 : const xub_StrLen nEnd = (xub_StrLen)rRange.Max() + 1;
698 : :
699 [ # # ]: 0 : aHiddenChg.push_back( nStart );
700 [ # # ]: 0 : aHiddenChg.push_back( nEnd );
701 : : }
702 : :
703 : : //
704 : : // SCRIPT AND SCRIPT RELATED INFORMATION
705 : : //
706 : :
707 : 13602 : xub_StrLen nChg = nInvalidityPos;
708 : :
709 : : // STRING_LEN means the data structure is up to date
710 : 13602 : nInvalidityPos = STRING_LEN;
711 : :
712 : : // this is the default direction
713 [ - + ]: 13602 : nDefaultDir = static_cast<sal_uInt8>(bRTL ? UBIDI_RTL : UBIDI_LTR);
714 : :
715 : : // counter for script info arrays
716 : 13602 : sal_uInt16 nCnt = 0;
717 : : // counter for compression information arrays
718 : 13602 : sal_uInt16 nCntComp = 0;
719 : : // counter for kashida array
720 : 13602 : sal_uInt16 nCntKash = 0;
721 : :
722 : 13602 : sal_uInt8 nScript = i18n::ScriptType::LATIN;
723 : :
724 : : // compression type
725 [ + - ][ + - ]: 13602 : const SwCharCompressType aCompEnum = rNode.getIDocumentSettingAccess()->getCharacterCompressionType();
726 : :
727 : : // justification type
728 : : const sal_Bool bAdjustBlock = SVX_ADJUST_BLOCK ==
729 [ + - ][ + - ]: 13602 : rNode.GetSwAttrSet().GetAdjust().GetAdjust();
730 : :
731 : : //
732 : : // FIND INVALID RANGES IN SCRIPT INFO ARRAYS:
733 : : //
734 : :
735 [ + + ]: 13602 : if( nChg )
736 : : {
737 : : // if change position = 0 we do not use any data from the arrays
738 : : // because by deleting all characters of the first group at the beginning
739 : : // of a paragraph nScript is set to a wrong value
740 : : SAL_WARN_IF( !CountScriptChg(), "sw.core", "Where're my changes of script?" );
741 [ + - ]: 3939 : while( nCnt < CountScriptChg() )
742 : : {
743 [ + - ][ - + ]: 3939 : if ( nChg > GetScriptChg( nCnt ) )
744 : 0 : nCnt++;
745 : : else
746 : : {
747 [ + - ]: 3939 : nScript = GetScriptType( nCnt );
748 : 3939 : break;
749 : : }
750 : : }
751 [ - + ]: 3939 : if( CHARCOMPRESS_NONE != aCompEnum )
752 : : {
753 [ # # ]: 0 : while( nCntComp < CountCompChg() )
754 : : {
755 [ # # ][ # # ]: 0 : if ( nChg > GetCompStart( nCntComp ) )
756 : 0 : nCntComp++;
757 : : else
758 : 0 : break;
759 : : }
760 : : }
761 [ - + ]: 3939 : if ( bAdjustBlock )
762 : : {
763 [ # # ]: 0 : while( nCntKash < CountKashida() )
764 : : {
765 [ # # ][ # # ]: 0 : if ( nChg > GetKashida( nCntKash ) )
766 : 0 : nCntKash++;
767 : : else
768 : 0 : break;
769 : : }
770 : : }
771 : : }
772 : :
773 : : //
774 : : // ADJUST nChg VALUE:
775 : : //
776 : :
777 : : // by stepping back one position we know that we are inside a group
778 : : // declared as an nScript group
779 [ + + ]: 13602 : if ( nChg )
780 : 3939 : --nChg;
781 : :
782 [ - + ][ # # ]: 13602 : const xub_StrLen nGrpStart = nCnt ? GetScriptChg( nCnt - 1 ) : 0;
783 : :
784 : : // we go back in our group until we reach the first character of
785 : : // type nScript
786 [ + + ][ + + ]: 34846 : while ( nChg > nGrpStart &&
[ + + ]
787 [ + - ][ + - ]: 19930 : nScript != pBreakIt->GetBreakIter()->getScriptType( rTxt, nChg ) )
[ + - ][ + - ]
[ + + ][ + + ]
[ # # # # ]
788 : 1314 : --nChg;
789 : :
790 : : // If we are at the start of a group, we do not trust nScript,
791 : : // we better get nScript from the breakiterator:
792 [ + + ]: 13602 : if ( nChg == nGrpStart )
793 [ + - ][ + - ]: 9902 : nScript = (sal_uInt8)pBreakIt->GetBreakIter()->getScriptType( rTxt, nChg );
[ + - ][ + - ]
794 : :
795 : : //
796 : : // INVALID DATA FROM THE SCRIPT INFO ARRAYS HAS TO BE DELETED:
797 : : //
798 : :
799 : : // remove invalid entries from script information arrays
800 [ + - ][ + - ]: 13602 : aScriptChanges.erase( aScriptChanges.begin() + nCnt, aScriptChanges.end() );
801 : :
802 : : // get the start of the last compression group
803 : 13602 : sal_uInt16 nLastCompression = nChg;
804 [ - + ]: 13602 : if( nCntComp )
805 : : {
806 : 0 : --nCntComp;
807 [ # # ]: 0 : nLastCompression = GetCompStart( nCntComp );
808 [ # # ][ # # ]: 0 : if( nChg >= nLastCompression + GetCompLen( nCntComp ) )
809 : : {
810 : 0 : nLastCompression = nChg;
811 : 0 : ++nCntComp;
812 : : }
813 : : }
814 : :
815 : : // remove invalid entries from compression information arrays
816 [ + - ][ + - ]: 13602 : aCompressionChanges.erase(aCompressionChanges.begin() + nCntComp, aCompressionChanges.end() );
817 : :
818 : : // get the start of the last kashida group
819 : 13602 : sal_uInt16 nLastKashida = nChg;
820 [ - + ][ # # ]: 13602 : if( nCntKash && i18n::ScriptType::COMPLEX == nScript )
821 : : {
822 : 0 : --nCntKash;
823 [ # # ]: 0 : nLastKashida = GetKashida( nCntKash );
824 : : }
825 : :
826 : : // remove invalid entries from kashida array
827 [ + - ][ + - ]: 13602 : aKashida.erase( aKashida.begin() + nCntKash, aKashida.end() );
828 : :
829 : : //
830 : : // TAKE CARE OF WEAK CHARACTERS: WE MUST FIND AN APPROPRIATE
831 : : // SCRIPT FOR WEAK CHARACTERS AT THE BEGINNING OF A PARAGRAPH
832 : : //
833 : :
834 [ + - ][ + - ]: 13602 : if( WEAK == pBreakIt->GetBreakIter()->getScriptType( rTxt, nChg ) )
[ + - ][ + - ]
[ + + ]
835 : : {
836 : : // If the beginning of the current group is weak, this means that
837 : : // all of the characters in this grounp are weak. We have to assign
838 : : // the scripts to these characters depending on the fonts which are
839 : : // set for these characters to display them.
840 : : xub_StrLen nEnd =
841 [ + - ][ + - ]: 4997 : (xub_StrLen)pBreakIt->GetBreakIter()->endOfScript( rTxt, nChg, WEAK );
[ + - ][ + - ]
842 : :
843 [ + + ]: 4997 : if( nEnd > rTxt.Len() )
844 : 1761 : nEnd = rTxt.Len();
845 : :
846 [ + - ][ + - ]: 4997 : nScript = (sal_uInt8)GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() );
847 : :
848 : : SAL_WARN_IF( i18n::ScriptType::LATIN != nScript &&
849 : : i18n::ScriptType::ASIAN != nScript &&
850 : : i18n::ScriptType::COMPLEX != nScript, "sw.core", "Wrong default language" );
851 : :
852 : 4997 : nChg = nEnd;
853 : :
854 : : // Get next script type or set to weak in order to exit
855 : 4997 : sal_uInt8 nNextScript = ( nEnd < rTxt.Len() ) ?
856 [ + - ][ + - ]: 7196 : (sal_uInt8)pBreakIt->GetBreakIter()->getScriptType( rTxt, nEnd ) :
[ + - ][ + - ]
[ + + ][ + + ]
[ # # # # ]
857 [ + + ]: 7196 : (sal_uInt8)WEAK;
858 : :
859 [ + + ]: 4997 : if ( nScript != nNextScript )
860 : : {
861 [ + - ]: 2798 : aScriptChanges.push_back( ScriptChangeInfo(nEnd, nScript) );
862 : 2798 : nCnt++;
863 : 2798 : nScript = nNextScript;
864 : : }
865 : : }
866 : :
867 : : //
868 : : // UPDATE THE SCRIPT INFO ARRAYS:
869 : : //
870 : :
871 [ + + ][ - + ]: 24406 : while ( nChg < rTxt.Len() || ( aScriptChanges.empty() && !rTxt.Len() ) )
[ # # ][ + + ]
872 : : {
873 : : SAL_WARN_IF( i18n::ScriptType::WEAK == nScript,
874 : : "sw.core", "Inserting WEAK into SwScriptInfo structure" );
875 : : SAL_WARN_IF( STRING_LEN == nChg, "sw.core", "65K? Strange length of script section" );
876 : :
877 : 10804 : xub_StrLen nSearchStt = nChg;
878 [ + - ][ + - ]: 10804 : nChg = (xub_StrLen)pBreakIt->GetBreakIter()->endOfScript( rTxt, nSearchStt, nScript );
[ + - ][ + - ]
879 : :
880 [ - + ]: 10804 : if ( nChg > rTxt.Len() )
881 : 0 : nChg = rTxt.Len();
882 : :
883 : : // #i28203#
884 : : // for 'complex' portions, we make sure that a portion does not contain more
885 : : // than one script:
886 [ - + ]: 10804 : if( i18n::ScriptType::COMPLEX == nScript )
887 : : {
888 [ # # ][ # # ]: 0 : const short nScriptType = ScriptTypeDetector::getCTLScriptType( rTxt, nSearchStt );
889 : 0 : xub_StrLen nNextCTLScriptStart = nSearchStt;
890 : 0 : short nCurrentScriptType = nScriptType;
891 [ # # ][ # # ]: 0 : while( com::sun::star::i18n::CTLScriptType::CTL_UNKNOWN == nCurrentScriptType || nScriptType == nCurrentScriptType )
[ # # ]
892 : : {
893 [ # # ][ # # ]: 0 : nNextCTLScriptStart = (xub_StrLen)ScriptTypeDetector::endOfCTLScriptType( rTxt, nNextCTLScriptStart );
894 [ # # ][ # # ]: 0 : if( nNextCTLScriptStart < rTxt.Len() && nNextCTLScriptStart < nChg )
[ # # ]
895 [ # # ][ # # ]: 0 : nCurrentScriptType = ScriptTypeDetector::getCTLScriptType( rTxt, nNextCTLScriptStart );
896 : : else
897 : 0 : break;
898 : : }
899 : 0 : nChg = Min( nChg, nNextCTLScriptStart );
900 : : }
901 : :
902 : : // special case for dotted circle since it can be used with complex
903 : : // before a mark, so we want it associated with the mark's script
904 [ - + ][ # # ]: 21608 : if (nChg < rTxt.Len() && nChg > 0 && (i18n::ScriptType::WEAK ==
[ # # ][ - + ]
905 [ # # ][ # # ]: 10804 : pBreakIt->GetBreakIter()->getScriptType(rTxt,nChg - 1)))
[ # # ][ # # ]
[ - + ][ - + ]
[ # # # # ]
906 : : {
907 [ # # ]: 0 : int8_t nType = u_charType(rTxt.GetChar(nChg) );
908 [ # # ][ # # ]: 0 : if (nType == U_NON_SPACING_MARK || nType == U_ENCLOSING_MARK ||
[ # # ]
909 : : nType == U_COMBINING_SPACING_MARK )
910 : : {
911 [ # # ]: 0 : aScriptChanges.push_back( ScriptChangeInfo(nChg-1, nScript) );
912 : : }
913 : : else
914 : : {
915 [ # # ]: 0 : aScriptChanges.push_back( ScriptChangeInfo(nChg, nScript) );
916 : : }
917 : : }
918 : : else
919 : : {
920 [ + - ]: 10804 : aScriptChanges.push_back( ScriptChangeInfo(nChg, nScript) );
921 : : }
922 : 10804 : ++nCnt;
923 : :
924 : : // if current script is asian, we search for compressable characters
925 : : // in this range
926 [ - + ][ # # ]: 10804 : if ( CHARCOMPRESS_NONE != aCompEnum &&
927 : : i18n::ScriptType::ASIAN == nScript )
928 : : {
929 : 0 : sal_uInt8 ePrevState = NONE;
930 : : sal_uInt8 eState;
931 : 0 : sal_uInt16 nPrevChg = nLastCompression;
932 : :
933 [ # # ]: 0 : while ( nLastCompression < nChg )
934 : : {
935 : 0 : xub_Unicode cChar = rTxt.GetChar( nLastCompression );
936 : :
937 : : // examine current character
938 [ # # # ]: 0 : switch ( cChar )
939 : : {
940 : : // Left punctuation found
941 : : case 0x3008: case 0x300A: case 0x300C: case 0x300E:
942 : : case 0x3010: case 0x3014: case 0x3016: case 0x3018:
943 : : case 0x301A: case 0x301D:
944 : 0 : eState = SPECIAL_LEFT;
945 : 0 : break;
946 : : // Right punctuation found
947 : : case 0x3001: case 0x3002: case 0x3009: case 0x300B:
948 : : case 0x300D: case 0x300F: case 0x3011: case 0x3015:
949 : : case 0x3017: case 0x3019: case 0x301B: case 0x301E:
950 : : case 0x301F:
951 : 0 : eState = SPECIAL_RIGHT;
952 : 0 : break;
953 : : default:
954 [ # # ][ # # ]: 0 : eState = static_cast<sal_uInt8>( ( 0x3040 <= cChar && 0x3100 > cChar ) ? KANA : NONE );
955 : : }
956 : :
957 : : // insert range of compressable characters
958 [ # # ]: 0 : if( ePrevState != eState )
959 : : {
960 [ # # ]: 0 : if ( ePrevState != NONE )
961 : : {
962 : : // insert start and type
963 [ # # ][ # # ]: 0 : if ( CHARCOMPRESS_PUNCTUATION_KANA == aCompEnum ||
964 : : ePrevState != KANA )
965 : : {
966 [ # # ]: 0 : aCompressionChanges.push_back( CompressionChangeInfo(nPrevChg, nLastCompression - nPrevChg, ePrevState) );
967 : : }
968 : : }
969 : :
970 : 0 : ePrevState = eState;
971 : 0 : nPrevChg = nLastCompression;
972 : : }
973 : :
974 : 0 : nLastCompression++;
975 : : }
976 : :
977 : : // we still have to examine last entry
978 [ # # ]: 0 : if ( ePrevState != NONE )
979 : : {
980 : : // insert start and type
981 [ # # ][ # # ]: 0 : if ( CHARCOMPRESS_PUNCTUATION_KANA == aCompEnum ||
982 : : ePrevState != KANA )
983 : : {
984 [ # # ]: 0 : aCompressionChanges.push_back( CompressionChangeInfo(nPrevChg, nLastCompression - nPrevChg, ePrevState) );
985 : : }
986 : 0 : }
987 : : }
988 : :
989 : : // we search for connecting opportunities (kashida)
990 [ - + ][ # # ]: 10804 : else if ( bAdjustBlock && i18n::ScriptType::COMPLEX == nScript )
991 : : {
992 : 0 : SwScanner aScanner( rNode, rNode.GetTxt(), 0, ModelToViewHelper(),
993 : : i18n::WordType::DICTIONARY_WORD,
994 [ # # # # ]: 0 : nLastKashida, nChg );
[ # # ]
995 : :
996 : : // the search has to be performed on a per word base
997 [ # # ][ # # ]: 0 : while ( aScanner.NextWord() )
998 : : {
999 [ # # ]: 0 : const XubString& rWord = aScanner.GetWord();
1000 : :
1001 : 0 : xub_StrLen nIdx = 0;
1002 : 0 : xub_StrLen nKashidaPos = STRING_LEN;
1003 : : xub_Unicode cCh;
1004 : 0 : xub_Unicode cPrevCh = 0;
1005 : :
1006 : 0 : sal_uInt16 nPriorityLevel = 7; // 0..6 = level found
1007 : : // 7 not found
1008 : :
1009 : 0 : xub_StrLen nWordLen = rWord.Len();
1010 : :
1011 : : // ignore trailing vowel chars
1012 [ # # ][ # # ]: 0 : while( nWordLen && isTransparentChar( rWord.GetChar( nWordLen - 1 )))
[ # # ][ # # ]
1013 : 0 : --nWordLen;
1014 : :
1015 [ # # ]: 0 : while (nIdx < nWordLen)
1016 : : {
1017 : 0 : cCh = rWord.GetChar( nIdx );
1018 : :
1019 : : // 1. Priority:
1020 : : // after user inserted kashida
1021 [ # # ]: 0 : if ( 0x640 == cCh )
1022 : : {
1023 : 0 : nKashidaPos = aScanner.GetBegin() + nIdx;
1024 : 0 : nPriorityLevel = 0;
1025 : : }
1026 : :
1027 : : // 2. Priority:
1028 : : // after a Seen or Sad
1029 [ # # ][ # # ]: 0 : if (nPriorityLevel >= 1 && nIdx < nWordLen - 1)
1030 : : {
1031 [ # # ][ # # ]: 0 : if( isSeenOrSadChar( cCh )
[ # # ]
[ # # # # ]
[ # # ]
1032 : 0 : && (rWord.GetChar( nIdx+1 ) != 0x200C) ) // #i98410#: prevent ZWNJ expansion
1033 : : {
1034 : 0 : nKashidaPos = aScanner.GetBegin() + nIdx;
1035 : 0 : nPriorityLevel = 1;
1036 : : }
1037 : : }
1038 : :
1039 : : // 3. Priority:
1040 : : // before final form of Teh Marbuta, Hah, Dal
1041 [ # # ][ # # ]: 0 : if ( nPriorityLevel >= 2 && nIdx > 0 )
1042 : : {
1043 [ # # ][ # # ]: 0 : if ( isTehMarbutaChar ( cCh ) || // Teh Marbuta (right joining)
[ # # ][ # # ]
[ # # ][ # # ]
1044 [ # # ]: 0 : isDalChar ( cCh ) || // Dal (right joining) final form may appear in the middle of word
1045 [ # # ]: 0 : ( isHahChar ( cCh ) && nIdx == nWordLen - 1)) // Hah (dual joining) only at end of word
1046 : : {
1047 : :
1048 : : SAL_WARN_IF( 0 == cPrevCh, "sw.core", "No previous character" );
1049 : : // check if character is connectable to previous character,
1050 [ # # ][ # # ]: 0 : if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
1051 : : {
1052 : 0 : nKashidaPos = aScanner.GetBegin() + nIdx - 1;
1053 : 0 : nPriorityLevel = 2;
1054 : : }
1055 : : }
1056 : : }
1057 : :
1058 : : // 4. Priority:
1059 : : // before final form of Alef, Lam or Kaf
1060 [ # # ][ # # ]: 0 : if ( nPriorityLevel >= 3 && nIdx > 0 )
1061 : : {
1062 [ # # ][ # # ]: 0 : if ( isAlefChar ( cCh ) || // Alef (right joining) final form may appear in the middle of word
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1063 [ # # ]: 0 : (( isLamChar ( cCh ) || // Lam
1064 [ # # ]: 0 : isKafChar ( cCh ) || // Kaf (both dual joining)
1065 [ # # ]: 0 : isGafChar ( cCh ) )
1066 : : && nIdx == nWordLen - 1)) // only at end of word
1067 : : {
1068 : : SAL_WARN_IF( 0 == cPrevCh, "sw.core", "No previous character" );
1069 : : // check if character is connectable to previous character,
1070 [ # # ][ # # ]: 0 : if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
1071 : : {
1072 : 0 : nKashidaPos = aScanner.GetBegin() + nIdx - 1;
1073 : 0 : nPriorityLevel = 3;
1074 : : }
1075 : : }
1076 : : }
1077 : :
1078 : : // 5. Priority:
1079 : : // before media Bah
1080 [ # # ][ # # ]: 0 : if ( nPriorityLevel >= 4 && nIdx > 0 && nIdx < nWordLen - 1 )
[ # # ]
1081 : : {
1082 [ # # ][ # # ]: 0 : if ( isBaaChar ( cCh )) // Bah
1083 : : {
1084 : : // check if next character is Reh, Yeh or Alef Maksura
1085 : 0 : xub_Unicode cNextCh = rWord.GetChar( nIdx + 1 );
1086 [ # # ][ # # ]: 0 : if ( isRehChar ( cNextCh ) || isYehChar ( cNextCh ))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1087 : : {
1088 : : SAL_WARN_IF( 0 == cPrevCh, "sw.core", "No previous character" );
1089 : : // check if character is connectable to previous character,
1090 [ # # ][ # # ]: 0 : if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
1091 : : {
1092 : 0 : nKashidaPos = aScanner.GetBegin() + nIdx - 1;
1093 : 0 : nPriorityLevel = 4;
1094 : : }
1095 : : }
1096 : : }
1097 : : }
1098 : :
1099 : : // 6. Priority:
1100 : : // before the final form of Waw, Ain, Qaf and Fa
1101 [ # # ][ # # ]: 0 : if ( nPriorityLevel >= 5 && nIdx > 0 )
1102 : : {
1103 [ # # ][ # # ]: 0 : if ( isWawChar ( cCh ) || // Wav (right joining)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1104 : : // final form may appear in the middle of word
1105 [ # # ]: 0 : (( isAinChar ( cCh ) || // Ain (dual joining)
1106 [ # # ]: 0 : isQafChar ( cCh ) || // Qaf (dual joining)
1107 [ # # ]: 0 : isFehChar ( cCh ) ) // Feh (dual joining)
1108 : : && nIdx == nWordLen - 1)) // only at end of word
1109 : : {
1110 : : SAL_WARN_IF( 0 == cPrevCh, "sw.core", "No previous character" );
1111 : : // check if character is connectable to previous character,
1112 [ # # ][ # # ]: 0 : if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
1113 : : {
1114 : 0 : nKashidaPos = aScanner.GetBegin() + nIdx - 1;
1115 : 0 : nPriorityLevel = 5;
1116 : : }
1117 : : }
1118 : : }
1119 : :
1120 : : // other connecting possibilities
1121 [ # # ][ # # ]: 0 : if ( nPriorityLevel >= 6 && nIdx > 0 )
1122 : : {
1123 : : // remaining right joiners
1124 : : // Reh, Zain, Thal,
1125 [ # # ][ # # ]: 0 : if ( isRehChar ( cCh ) || // Reh Zain (right joining)
[ # # ][ # # ]
[ # # ][ # # ]
1126 : : // final form may appear in the middle of word
1127 : : ( 0x60C <= cCh && 0x6FE >= cCh // all others
1128 : : && nIdx == nWordLen - 1)) // only at end of word
1129 : : {
1130 : : SAL_WARN_IF( 0 == cPrevCh, "sw.core", "No previous character" );
1131 : : // check if character is connectable to previous character,
1132 [ # # ][ # # ]: 0 : if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
1133 : : {
1134 : 0 : nKashidaPos = aScanner.GetBegin() + nIdx - 1;
1135 : 0 : nPriorityLevel = 6;
1136 : : }
1137 : : }
1138 : : }
1139 : :
1140 : : // Do not consider Fathatan, Dammatan, Kasratan, Fatha,
1141 : : // Damma, Kasra, Shadda and Sukun when checking if
1142 : : // a character can be connected to previous character.
1143 [ # # ][ # # ]: 0 : if ( !isTransparentChar ( cCh) )
1144 : 0 : cPrevCh = cCh;
1145 : :
1146 : 0 : ++nIdx;
1147 : : } // end of current word
1148 : :
1149 [ # # ]: 0 : if ( STRING_LEN != nKashidaPos )
1150 : : {
1151 [ # # ][ # # ]: 0 : aKashida.insert( aKashida.begin() + nCntKash, nKashidaPos);
1152 : 0 : nCntKash++;
1153 : : }
1154 [ # # ]: 0 : } // end of kashida search
1155 : : }
1156 : :
1157 [ - + ]: 10804 : if ( nChg < rTxt.Len() )
1158 [ # # ][ # # ]: 0 : nScript = (sal_uInt8)pBreakIt->GetBreakIter()->getScriptType( rTxt, nChg );
[ # # ][ # # ]
1159 : :
1160 : 10804 : nLastCompression = nChg;
1161 : 10804 : nLastKashida = nChg;
1162 : : }
1163 : :
1164 : : #if OSL_DEBUG_LEVEL > 0
1165 : : // check kashida data
1166 : : long nTmpKashidaPos = -1;
1167 : : sal_Bool bWrongKash = sal_False;
1168 : : for (i = 0; i < aKashida.size(); ++i )
1169 : : {
1170 : : long nCurrKashidaPos = GetKashida( i );
1171 : : if ( nCurrKashidaPos <= nTmpKashidaPos )
1172 : : {
1173 : : bWrongKash = sal_True;
1174 : : break;
1175 : : }
1176 : : nTmpKashidaPos = nCurrKashidaPos;
1177 : : }
1178 : : SAL_WARN_IF( bWrongKash, "sw.core", "Kashida array contains wrong data" );
1179 : : #endif
1180 : :
1181 : : // remove invalid entries from direction information arrays
1182 : 13602 : aDirectionChanges.clear();
1183 : :
1184 : : // Perform Unicode Bidi Algorithm for text direction information
1185 : 13602 : bool bPerformUBA = UBIDI_LTR != nDefaultDir;
1186 : 13602 : nCnt = 0;
1187 [ + - ][ + + ]: 27204 : while( !bPerformUBA && nCnt < CountScriptChg() )
[ + + ]
1188 : : {
1189 [ + - ][ - + ]: 13602 : if ( i18n::ScriptType::COMPLEX == GetScriptType( nCnt++ ) )
1190 : 0 : bPerformUBA = true;
1191 : : }
1192 : :
1193 : : // do not call the unicode bidi algorithm if not required
1194 [ - + ]: 13602 : if ( bPerformUBA )
1195 : : {
1196 [ # # ]: 0 : UpdateBidiInfo( rTxt );
1197 : :
1198 : : // #i16354# Change script type for RTL text to CTL:
1199 : : // 1. All text in RTL runs will use the CTL font
1200 : : // #i89825# change the script type also to CTL (hennerdrewes)
1201 : : // 2. Text in embedded LTR runs that does not have any strong LTR characters (numbers!)
1202 [ # # ]: 0 : for ( sal_uInt32 nDirIdx = 0; nDirIdx < aDirectionChanges.size(); ++nDirIdx )
1203 : : {
1204 [ # # ]: 0 : const sal_uInt8 nCurrDirType = GetDirType( nDirIdx );
1205 : : // nStart ist start of RTL run:
1206 [ # # ][ # # ]: 0 : const xub_StrLen nStart = nDirIdx > 0 ? GetDirChg( nDirIdx - 1 ) : 0;
1207 : : // nEnd is end of RTL run:
1208 [ # # ]: 0 : const xub_StrLen nEnd = GetDirChg( nDirIdx );
1209 : :
1210 [ # # ][ # # ]: 0 : if ( nCurrDirType % 2 == UBIDI_RTL || // text in RTL run
[ # # ][ # # ]
1211 [ # # ]: 0 : ( nCurrDirType > UBIDI_LTR && !lcl_HasStrongLTR( rTxt, nStart, nEnd ) ) ) // non-strong text in embedded LTR run
1212 : : {
1213 : : // nScriptIdx points into the ScriptArrays:
1214 : 0 : size_t nScriptIdx = 0;
1215 : :
1216 : : // Skip entries in ScriptArray which are not inside the RTL run:
1217 : : // Make nScriptIdx become the index of the script group with
1218 : : // 1. nStartPosOfGroup <= nStart and
1219 : : // 2. nEndPosOfGroup > nStart
1220 [ # # ][ # # ]: 0 : while ( GetScriptChg( nScriptIdx ) <= nStart )
1221 : 0 : ++nScriptIdx;
1222 : :
1223 [ # # ][ # # ]: 0 : const xub_StrLen nStartPosOfGroup = nScriptIdx ? GetScriptChg( nScriptIdx - 1 ) : 0;
1224 [ # # ]: 0 : const sal_uInt8 nScriptTypeOfGroup = GetScriptType( nScriptIdx );
1225 : :
1226 : : SAL_WARN_IF( nStartPosOfGroup > nStart || GetScriptChg( nScriptIdx ) <= nStart,
1227 : : "sw.core", "Script override with CTL font trouble" );
1228 : :
1229 : : // Check if we have to insert a new script change at
1230 : : // position nStart. If nStartPosOfGroup < nStart,
1231 : : // we have to insert a new script change:
1232 [ # # ][ # # ]: 0 : if ( nStart > 0 && nStartPosOfGroup < nStart )
1233 : : {
1234 : 0 : aScriptChanges.insert(aScriptChanges.begin() + nScriptIdx,
1235 [ # # ][ # # ]: 0 : ScriptChangeInfo(nStart, nScriptTypeOfGroup) );
1236 : 0 : ++nScriptIdx;
1237 : : }
1238 : :
1239 : : // Remove entries in ScriptArray which end inside the RTL run:
1240 [ # # ][ # # ]: 0 : while ( nScriptIdx < aScriptChanges.size() && GetScriptChg( nScriptIdx ) <= nEnd )
[ # # ][ # # ]
1241 : : {
1242 [ # # ][ # # ]: 0 : aScriptChanges.erase(aScriptChanges.begin() + nScriptIdx);
1243 : : }
1244 : :
1245 : : // Insert a new entry in ScriptArray for the end of the RTL run:
1246 : 0 : aScriptChanges.insert(aScriptChanges.begin() + nScriptIdx,
1247 [ # # ][ # # ]: 0 : ScriptChangeInfo(nEnd, i18n::ScriptType::COMPLEX) );
1248 : :
1249 : : #if OSL_DEBUG_LEVEL > 0
1250 : : // Check that ScriptChangeInfos are in increasing order of
1251 : : // position and that we don't have "empty" changes.
1252 : : sal_uInt8 nLastTyp = i18n::ScriptType::WEAK;
1253 : : xub_StrLen nLastPos = 0;
1254 : : for (std::vector<ScriptChangeInfo>::const_iterator i2 = aScriptChanges.begin(); i2 < aScriptChanges.end(); ++i2)
1255 : : {
1256 : : SAL_WARN_IF( nLastTyp == i2->type ||
1257 : : nLastPos >= i2->position,
1258 : : "sw.core", "Heavy InitScriptType() confusion" );
1259 : : nLastPos = i2->position;
1260 : : nLastTyp = i2->type;
1261 : : }
1262 : : #endif
1263 : : }
1264 : : }
1265 [ + - ]: 13602 : }
1266 : : }
1267 : :
1268 : 0 : void SwScriptInfo::UpdateBidiInfo( const String& rTxt )
1269 : : {
1270 : : // remove invalid entries from direction information arrays
1271 : 0 : aDirectionChanges.clear();
1272 : : //
1273 : : // Bidi functions from icu 2.0
1274 : : //
1275 : 0 : UErrorCode nError = U_ZERO_ERROR;
1276 [ # # ]: 0 : UBiDi* pBidi = ubidi_openSized( rTxt.Len(), 0, &nError );
1277 : 0 : nError = U_ZERO_ERROR;
1278 : :
1279 : 0 : ubidi_setPara( pBidi, reinterpret_cast<const UChar *>(rTxt.GetBuffer()), rTxt.Len(), // UChar != sal_Unicode in MinGW
1280 [ # # ]: 0 : nDefaultDir, NULL, &nError );
1281 : 0 : nError = U_ZERO_ERROR;
1282 [ # # ]: 0 : long nCount = ubidi_countRuns( pBidi, &nError );
1283 : 0 : int32_t nStart = 0;
1284 : : int32_t nEnd;
1285 : : UBiDiLevel nCurrDir;
1286 [ # # ]: 0 : for ( sal_uInt16 nIdx = 0; nIdx < nCount; ++nIdx )
1287 : : {
1288 [ # # ]: 0 : ubidi_getLogicalRun( pBidi, nStart, &nEnd, &nCurrDir );
1289 [ # # ]: 0 : aDirectionChanges.push_back( DirectionChangeInfo(nEnd, nCurrDir) );
1290 : 0 : nStart = nEnd;
1291 : : }
1292 : :
1293 [ # # ]: 0 : ubidi_close( pBidi );
1294 : 0 : }
1295 : :
1296 : :
1297 : : /*************************************************************************
1298 : : * SwScriptInfo::NextScriptChg(..)
1299 : : * returns the position of the next character which belongs to another script
1300 : : * than the character of the actual (input) position.
1301 : : * If there's no script change until the end of the paragraph, it will return
1302 : : * STRING_LEN.
1303 : : * Scripts are Asian (Chinese, Japanese, Korean),
1304 : : * Latin ( English etc.)
1305 : : * and Complex ( Hebrew, Arabian )
1306 : : *************************************************************************/
1307 : :
1308 : 61937 : xub_StrLen SwScriptInfo::NextScriptChg( const xub_StrLen nPos ) const
1309 : : {
1310 : 61937 : sal_uInt16 nEnd = CountScriptChg();
1311 [ + - ]: 61937 : for( sal_uInt16 nX = 0; nX < nEnd; ++nX )
1312 : : {
1313 [ + - ]: 61937 : if( nPos < GetScriptChg( nX ) )
1314 : 61937 : return GetScriptChg( nX );
1315 : : }
1316 : :
1317 : 61937 : return STRING_LEN;
1318 : : }
1319 : :
1320 : : /*************************************************************************
1321 : : * SwScriptInfo::ScriptType(..)
1322 : : * returns the script of the character at the input position
1323 : : *************************************************************************/
1324 : :
1325 : 333863 : sal_uInt8 SwScriptInfo::ScriptType( const xub_StrLen nPos ) const
1326 : : {
1327 : 333863 : sal_uInt16 nEnd = CountScriptChg();
1328 [ + + ]: 344005 : for( sal_uInt16 nX = 0; nX < nEnd; ++nX )
1329 : : {
1330 [ + + ]: 333863 : if( nPos < GetScriptChg( nX ) )
1331 : 323721 : return GetScriptType( nX );
1332 : : }
1333 : :
1334 : : // the default is the application language script
1335 : 333863 : return (sal_uInt8)GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() );
1336 : : }
1337 : :
1338 : 51271 : xub_StrLen SwScriptInfo::NextDirChg( const xub_StrLen nPos,
1339 : : const sal_uInt8* pLevel ) const
1340 : : {
1341 [ - + ]: 51271 : sal_uInt8 nCurrDir = pLevel ? *pLevel : 62;
1342 : 51271 : sal_uInt16 nEnd = CountDirChg();
1343 [ - + ]: 51271 : for( sal_uInt16 nX = 0; nX < nEnd; ++nX )
1344 : : {
1345 [ # # ]: 0 : if( nPos < GetDirChg( nX ) &&
[ # # # # ]
[ # # ]
1346 : 0 : ( nX + 1 == nEnd || GetDirType( nX + 1 ) <= nCurrDir ) )
1347 : 0 : return GetDirChg( nX );
1348 : : }
1349 : :
1350 : 51271 : return STRING_LEN;
1351 : : }
1352 : :
1353 : 64101 : sal_uInt8 SwScriptInfo::DirType( const xub_StrLen nPos ) const
1354 : : {
1355 : 64101 : sal_uInt16 nEnd = CountDirChg();
1356 [ - + ]: 64101 : for( sal_uInt16 nX = 0; nX < nEnd; ++nX )
1357 : : {
1358 [ # # ]: 0 : if( nPos < GetDirChg( nX ) )
1359 : 0 : return GetDirType( nX );
1360 : : }
1361 : :
1362 : 64101 : return 0;
1363 : : }
1364 : :
1365 : : /*************************************************************************
1366 : : * SwScriptInfo::MaskHiddenRanges(..)
1367 : : * Takes a string and replaced the hidden ranges with cChar.
1368 : : **************************************************************************/
1369 : :
1370 : 6641 : sal_uInt16 SwScriptInfo::MaskHiddenRanges( const SwTxtNode& rNode, XubString& rText,
1371 : : const xub_StrLen nStt, const xub_StrLen nEnd,
1372 : : const xub_Unicode cChar )
1373 : : {
1374 : : assert(rNode.GetTxt().Len() == rText.Len());
1375 : :
1376 [ + - ]: 6641 : PositionList aList;
1377 : : xub_StrLen nHiddenStart;
1378 : : xub_StrLen nHiddenEnd;
1379 : 6641 : sal_uInt16 nNumOfHiddenChars = 0;
1380 [ + - ]: 6641 : GetBoundsOfHiddenRange( rNode, 0, nHiddenStart, nHiddenEnd, &aList );
1381 [ + - ][ + - ]: 6641 : PositionList::const_reverse_iterator rFirst( aList.end() );
1382 [ + - ][ + - ]: 6641 : PositionList::const_reverse_iterator rLast( aList.begin() );
1383 [ + - ][ + + ]: 6663 : while ( rFirst != rLast )
1384 : : {
1385 [ + - ][ + - ]: 22 : nHiddenEnd = *(rFirst++);
1386 [ + - ][ + - ]: 22 : nHiddenStart = *(rFirst++);
1387 : :
1388 [ + - ][ - + ]: 22 : if ( nHiddenEnd < nStt || nHiddenStart > nEnd )
1389 : 0 : continue;
1390 : :
1391 [ + + ][ + - ]: 50 : while ( nHiddenStart < nHiddenEnd && nHiddenStart < nEnd )
[ + + ]
1392 : : {
1393 [ + - ][ + - ]: 28 : if ( nHiddenStart >= nStt && nHiddenStart < nEnd )
1394 : : {
1395 [ + - ]: 28 : rText.SetChar( nHiddenStart, cChar );
1396 : 28 : ++nNumOfHiddenChars;
1397 : : }
1398 : 28 : ++nHiddenStart;
1399 : : }
1400 : : }
1401 : :
1402 : 6641 : return nNumOfHiddenChars;
1403 : : }
1404 : :
1405 : : /*************************************************************************
1406 : : * SwScriptInfo::DeleteHiddenRanges(..)
1407 : : * Takes a SwTxtNode and deletes the hidden ranges from the node.
1408 : : **************************************************************************/
1409 : :
1410 : 0 : void SwScriptInfo::DeleteHiddenRanges( SwTxtNode& rNode )
1411 : : {
1412 [ # # ]: 0 : PositionList aList;
1413 : : xub_StrLen nHiddenStart;
1414 : : xub_StrLen nHiddenEnd;
1415 [ # # ]: 0 : GetBoundsOfHiddenRange( rNode, 0, nHiddenStart, nHiddenEnd, &aList );
1416 [ # # ][ # # ]: 0 : PositionList::const_reverse_iterator rFirst( aList.end() );
1417 [ # # ][ # # ]: 0 : PositionList::const_reverse_iterator rLast( aList.begin() );
1418 [ # # ][ # # ]: 0 : while ( rFirst != rLast )
1419 : : {
1420 [ # # ][ # # ]: 0 : nHiddenEnd = *(rFirst++);
1421 [ # # ][ # # ]: 0 : nHiddenStart = *(rFirst++);
1422 : :
1423 [ # # ]: 0 : SwPaM aPam( rNode, nHiddenStart, rNode, nHiddenEnd );
1424 [ # # ][ # # ]: 0 : rNode.getIDocumentContentOperations()->DeleteRange( aPam );
1425 [ # # ]: 0 : }
1426 : 0 : }
1427 : :
1428 : : /*************************************************************************
1429 : : * SwScriptInfo::GetBoundsOfHiddenRange(..)
1430 : : * static version
1431 : : **************************************************************************/
1432 : :
1433 : 21821 : bool SwScriptInfo::GetBoundsOfHiddenRange( const SwTxtNode& rNode, xub_StrLen nPos,
1434 : : xub_StrLen& rnStartPos, xub_StrLen& rnEndPos,
1435 : : PositionList* pList )
1436 : : {
1437 : 21821 : rnStartPos = STRING_LEN;
1438 : 21821 : rnEndPos = 0;
1439 : :
1440 : 21821 : bool bNewContainsHiddenChars = false;
1441 : :
1442 : : //
1443 : : // Optimization: First examine the flags at the text node:
1444 : : //
1445 [ + + ]: 21821 : if ( !rNode.IsCalcHiddenCharFlags() )
1446 : : {
1447 : 7707 : bool bWholePara = rNode.HasHiddenCharAttribute( true );
1448 : 7707 : bool bContainsHiddenChars = rNode.HasHiddenCharAttribute( false );
1449 [ + + ]: 7707 : if ( !bContainsHiddenChars )
1450 : 7685 : return false;
1451 : :
1452 [ + - ]: 22 : if ( bWholePara )
1453 : : {
1454 [ + - ]: 22 : if ( pList )
1455 : : {
1456 [ + - ]: 22 : pList->push_back( 0 );
1457 [ + - ]: 22 : pList->push_back( rNode.GetTxt().Len() );
1458 : : }
1459 : :
1460 : 22 : rnStartPos = 0;
1461 : 22 : rnEndPos = rNode.GetTxt().Len();
1462 : 22 : return true;
1463 : : }
1464 : : }
1465 : :
1466 : 14114 : const SwScriptInfo* pSI = SwScriptInfo::GetScriptInfo( rNode );
1467 [ + + ]: 14114 : if ( pSI )
1468 : : {
1469 : : //
1470 : : // Check first, if we have a valid SwScriptInfo object for this text node:
1471 : : //
1472 : 182 : bNewContainsHiddenChars = pSI->GetBoundsOfHiddenRange( nPos, rnStartPos, rnEndPos, pList );
1473 [ # # ][ - + ]: 182 : const bool bNewHiddenCharsHidePara = ( rnStartPos == 0 && rnEndPos >= rNode.GetTxt().Len() );
1474 : 182 : rNode.SetHiddenCharAttribute( bNewHiddenCharsHidePara, bNewContainsHiddenChars );
1475 : : }
1476 : : else
1477 : : {
1478 : : //
1479 : : // No valid SwScriptInfo Object, we have to do it the hard way:
1480 : : //
1481 [ + + ]: 13932 : Range aRange( 0, rNode.GetTxt().Len() ? rNode.GetTxt().Len() - 1 : 0 );
1482 [ + - ]: 13932 : MultiSelection aHiddenMulti( aRange );
1483 [ + - ]: 13932 : SwScriptInfo::CalcHiddenRanges( rNode, aHiddenMulti );
1484 [ + + ]: 13932 : for( sal_uInt16 i = 0; i < aHiddenMulti.GetRangeCount(); ++i )
1485 : : {
1486 [ + - ]: 170 : const Range& rRange = aHiddenMulti.GetRange( i );
1487 : 170 : const xub_StrLen nHiddenStart = (xub_StrLen)rRange.Min();
1488 : 170 : const xub_StrLen nHiddenEnd = (xub_StrLen)rRange.Max() + 1;
1489 : :
1490 [ - + ]: 170 : if ( nHiddenStart > nPos )
1491 : 0 : break;
1492 [ + - ][ + - ]: 170 : else if ( nHiddenStart <= nPos && nPos < nHiddenEnd )
1493 : : {
1494 : 170 : rnStartPos = nHiddenStart;
1495 : 170 : rnEndPos = Min( nHiddenEnd, rNode.GetTxt().Len() );
1496 : 170 : break;
1497 : : }
1498 : : }
1499 : :
1500 [ + + ]: 13932 : if ( pList )
1501 : : {
1502 [ - + ]: 79 : for( sal_uInt16 i = 0; i < aHiddenMulti.GetRangeCount(); ++i )
1503 : : {
1504 [ # # ]: 0 : const Range& rRange = aHiddenMulti.GetRange( i );
1505 [ # # ]: 0 : pList->push_back( (xub_StrLen)rRange.Min() );
1506 [ # # ]: 0 : pList->push_back( (xub_StrLen)rRange.Max() + 1 );
1507 : : }
1508 : : }
1509 : :
1510 [ + - ]: 13932 : bNewContainsHiddenChars = aHiddenMulti.GetRangeCount() > 0;
1511 : : }
1512 : :
1513 : 21821 : return bNewContainsHiddenChars;
1514 : : }
1515 : :
1516 : : /*************************************************************************
1517 : : * SwScriptInfo::GetBoundsOfHiddenRange(..)
1518 : : * non-static version
1519 : : **************************************************************************/
1520 : :
1521 : 66997 : bool SwScriptInfo::GetBoundsOfHiddenRange( xub_StrLen nPos, xub_StrLen& rnStartPos,
1522 : : xub_StrLen& rnEndPos, PositionList* pList ) const
1523 : : {
1524 : 66997 : rnStartPos = STRING_LEN;
1525 : 66997 : rnEndPos = 0;
1526 : :
1527 : 66997 : sal_uInt16 nEnd = CountHiddenChg();
1528 [ - + ]: 66997 : for( sal_uInt16 nX = 0; nX < nEnd; ++nX )
1529 : : {
1530 : 0 : const xub_StrLen nHiddenStart = GetHiddenChg( nX++ );
1531 : 0 : const xub_StrLen nHiddenEnd = GetHiddenChg( nX );
1532 : :
1533 [ # # ]: 0 : if ( nHiddenStart > nPos )
1534 : 0 : break;
1535 [ # # ][ # # ]: 0 : else if ( nHiddenStart <= nPos && nPos < nHiddenEnd )
1536 : : {
1537 : 0 : rnStartPos = nHiddenStart;
1538 : 0 : rnEndPos = nHiddenEnd;
1539 : 0 : break;
1540 : : }
1541 : : }
1542 : :
1543 [ + + ]: 66997 : if ( pList )
1544 : : {
1545 [ - + ]: 14 : for( sal_uInt16 nX = 0; nX < nEnd; ++nX )
1546 : : {
1547 [ # # ]: 0 : pList->push_back( GetHiddenChg( nX++ ) );
1548 [ # # ]: 0 : pList->push_back( GetHiddenChg( nX ) );
1549 : : }
1550 : : }
1551 : :
1552 : 66997 : return CountHiddenChg() > 0;
1553 : : }
1554 : :
1555 : 83 : bool SwScriptInfo::IsInHiddenRange( const SwTxtNode& rNode, xub_StrLen nPos )
1556 : : {
1557 : : xub_StrLen nStartPos;
1558 : : xub_StrLen nEndPos;
1559 [ + - ]: 83 : SwScriptInfo::GetBoundsOfHiddenRange( rNode, nPos, nStartPos, nEndPos );
1560 : 83 : return nStartPos != STRING_LEN;
1561 : : }
1562 : :
1563 : :
1564 : : #ifdef DBG_UTIL
1565 : : /*************************************************************************
1566 : : * SwScriptInfo::CompType(..)
1567 : : * returns the type of the compressed character
1568 : : *************************************************************************/
1569 : :
1570 : : sal_uInt8 SwScriptInfo::CompType( const xub_StrLen nPos ) const
1571 : : {
1572 : : sal_uInt16 nEnd = CountCompChg();
1573 : : for( sal_uInt16 nX = 0; nX < nEnd; ++nX )
1574 : : {
1575 : : xub_StrLen nChg = GetCompStart( nX );
1576 : :
1577 : : if ( nPos < nChg )
1578 : : return NONE;
1579 : :
1580 : : if( nPos < nChg + GetCompLen( nX ) )
1581 : : return GetCompType( nX );
1582 : : }
1583 : : return NONE;
1584 : : }
1585 : : #endif
1586 : :
1587 : : /*************************************************************************
1588 : : * SwScriptInfo::HasKana()
1589 : : * returns, if there are compressable kanas or specials
1590 : : * between nStart and nEnd
1591 : : *************************************************************************/
1592 : :
1593 : 0 : sal_uInt16 SwScriptInfo::HasKana( xub_StrLen nStart, const xub_StrLen nLen ) const
1594 : : {
1595 : 0 : sal_uInt16 nCnt = CountCompChg();
1596 : 0 : xub_StrLen nEnd = nStart + nLen;
1597 : :
1598 [ # # ]: 0 : for( sal_uInt16 nX = 0; nX < nCnt; ++nX )
1599 : : {
1600 : 0 : xub_StrLen nKanaStart = GetCompStart( nX );
1601 : 0 : xub_StrLen nKanaEnd = nKanaStart + GetCompLen( nX );
1602 : :
1603 [ # # ]: 0 : if ( nKanaStart >= nEnd )
1604 : 0 : return USHRT_MAX;
1605 : :
1606 [ # # ]: 0 : if ( nStart < nKanaEnd )
1607 : 0 : return nX;
1608 : : }
1609 : :
1610 : 0 : return USHRT_MAX;
1611 : : }
1612 : :
1613 : 0 : long SwScriptInfo::Compress( sal_Int32* pKernArray, xub_StrLen nIdx, xub_StrLen nLen,
1614 : : const sal_uInt16 nCompress, const sal_uInt16 nFontHeight,
1615 : : Point* pPoint ) const
1616 : : {
1617 : : SAL_WARN_IF( !nCompress, "sw.core", "Compression without compression?!" );
1618 : : SAL_WARN_IF( !nLen, "sw.core", "Compression without text?!" );
1619 : 0 : sal_uInt16 nCompCount = CountCompChg();
1620 : :
1621 : : // In asian typography, there are full width and half width characters.
1622 : : // Full width punctuation characters can be compressed by 50 %
1623 : : // to determine this, we compare the font width with 75 % of its height
1624 : 0 : sal_uInt16 nMinWidth = ( 3 * nFontHeight ) / 4;
1625 : :
1626 : 0 : sal_uInt16 nCompIdx = HasKana( nIdx, nLen );
1627 : :
1628 [ # # ]: 0 : if ( USHRT_MAX == nCompIdx )
1629 : 0 : return 0;
1630 : :
1631 : 0 : xub_StrLen nChg = GetCompStart( nCompIdx );
1632 : 0 : xub_StrLen nCompLen = GetCompLen( nCompIdx );
1633 : 0 : sal_uInt16 nI = 0;
1634 : 0 : nLen = nLen + nIdx;
1635 : :
1636 [ # # ]: 0 : if( nChg > nIdx )
1637 : : {
1638 : 0 : nI = nChg - nIdx;
1639 : 0 : nIdx = nChg;
1640 : : }
1641 [ # # ]: 0 : else if( nIdx < nChg + nCompLen )
1642 : 0 : nCompLen -= nIdx - nChg;
1643 : :
1644 [ # # ][ # # ]: 0 : if( nIdx > nLen || nCompIdx >= nCompCount )
1645 : 0 : return 0;
1646 : :
1647 : 0 : long nSub = 0;
1648 [ # # ]: 0 : long nLast = nI ? pKernArray[ nI - 1 ] : 0;
1649 [ # # ]: 0 : do
1650 : : {
1651 : 0 : sal_uInt16 nType = GetCompType( nCompIdx );
1652 : : #ifdef DBG_UTIL
1653 : : SAL_WARN_IF( nType != CompType( nIdx ), "sw.core", "Gimme the right type!" );
1654 : : #endif
1655 : 0 : nCompLen = nCompLen + nIdx;
1656 [ # # ]: 0 : if( nCompLen > nLen )
1657 : 0 : nCompLen = nLen;
1658 : :
1659 : : // are we allowed to compress the character?
1660 [ # # ]: 0 : if ( pKernArray[ nI ] - nLast < nMinWidth )
1661 : : {
1662 : 0 : nIdx++; nI++;
1663 : : }
1664 : : else
1665 : : {
1666 [ # # ]: 0 : while( nIdx < nCompLen )
1667 : : {
1668 : : SAL_WARN_IF( SwScriptInfo::NONE == nType, "sw.core", "None compression?!" );
1669 : :
1670 : : // nLast is width of current character
1671 : 0 : nLast -= pKernArray[ nI ];
1672 : :
1673 : 0 : nLast *= nCompress;
1674 : 0 : long nMove = 0;
1675 [ # # ]: 0 : if( SwScriptInfo::KANA != nType )
1676 : : {
1677 : 0 : nLast /= 20000;
1678 [ # # ][ # # ]: 0 : if( pPoint && SwScriptInfo::SPECIAL_LEFT == nType )
1679 : : {
1680 [ # # ]: 0 : if( nI )
1681 : 0 : nMove = nLast;
1682 : : else
1683 : : {
1684 : 0 : pPoint->X() += nLast;
1685 : 0 : nLast = 0;
1686 : : }
1687 : : }
1688 : : }
1689 : : else
1690 : 0 : nLast /= 100000;
1691 : 0 : nSub -= nLast;
1692 : 0 : nLast = pKernArray[ nI ];
1693 [ # # ]: 0 : if( nMove )
1694 : 0 : pKernArray[ nI - 1 ] += nMove;
1695 : 0 : pKernArray[ nI++ ] -= nSub;
1696 : 0 : ++nIdx;
1697 : : }
1698 : : }
1699 : :
1700 [ # # ]: 0 : if( nIdx < nLen )
1701 : : {
1702 : : xub_StrLen nTmpChg;
1703 [ # # ]: 0 : if( ++nCompIdx < nCompCount )
1704 : : {
1705 : 0 : nTmpChg = GetCompStart( nCompIdx );
1706 [ # # ]: 0 : if( nTmpChg > nLen )
1707 : 0 : nTmpChg = nLen;
1708 : 0 : nCompLen = GetCompLen( nCompIdx );
1709 : : }
1710 : : else
1711 : 0 : nTmpChg = nLen;
1712 [ # # ]: 0 : while( nIdx < nTmpChg )
1713 : : {
1714 : 0 : nLast = pKernArray[ nI ];
1715 : 0 : pKernArray[ nI++ ] -= nSub;
1716 : 0 : ++nIdx;
1717 : : }
1718 : : }
1719 : : else
1720 : 0 : break;
1721 : : } while( nIdx < nLen );
1722 : 0 : return nSub;
1723 : : }
1724 : :
1725 : : /*************************************************************************
1726 : : * SwScriptInfo::KashidaJustify()
1727 : : *************************************************************************/
1728 : :
1729 : : // Note on calling KashidaJustify():
1730 : : // Kashida positions may be marked as invalid. Therefore KashidaJustify may return the clean
1731 : : // total number of kashida positions, or the number of kashida positions after some positions
1732 : : // have been dropped, depending on the state of the aKashidaInvalid array.
1733 : :
1734 : 0 : sal_uInt16 SwScriptInfo::KashidaJustify( sal_Int32* pKernArray,
1735 : : sal_Int32* pScrArray,
1736 : : xub_StrLen nStt,
1737 : : xub_StrLen nLen,
1738 : : long nSpaceAdd ) const
1739 : : {
1740 : : SAL_WARN_IF( !nLen, "sw.core", "Kashida justification without text?!" );
1741 : :
1742 [ # # ]: 0 : if( !IsKashidaLine(nStt))
1743 : 0 : return STRING_LEN;
1744 : :
1745 : : // evaluate kashida information in collected in SwScriptInfo
1746 : :
1747 : 0 : sal_uInt16 nCntKash = 0;
1748 [ # # ]: 0 : while( nCntKash < CountKashida() )
1749 : : {
1750 [ # # ]: 0 : if ( nStt <= GetKashida( nCntKash ) )
1751 : 0 : break;
1752 : : else
1753 : 0 : nCntKash++;
1754 : : }
1755 : :
1756 : 0 : const xub_StrLen nEnd = nStt + nLen;
1757 : :
1758 : 0 : sal_uInt16 nCntKashEnd = nCntKash;
1759 [ # # ]: 0 : while ( nCntKashEnd < CountKashida() )
1760 : : {
1761 [ # # ]: 0 : if ( nEnd <= GetKashida( nCntKashEnd ) )
1762 : 0 : break;
1763 : : else
1764 : 0 : nCntKashEnd++;
1765 : : }
1766 : :
1767 : 0 : sal_uInt16 nActualKashCount = nCntKashEnd - nCntKash;
1768 [ # # ]: 0 : for ( sal_uInt16 i = nCntKash; i < nCntKashEnd; ++i )
1769 : : {
1770 [ # # ][ # # ]: 0 : if ( nActualKashCount && !IsKashidaValid ( i ) )
[ # # ]
1771 : 0 : --nActualKashCount;
1772 : : }
1773 : :
1774 [ # # ]: 0 : if ( !pKernArray )
1775 : 0 : return nActualKashCount;
1776 : :
1777 : : // do nothing if there is no more kashida
1778 [ # # ]: 0 : if ( nCntKash < CountKashida() )
1779 : : {
1780 : : // skip any invalid kashidas
1781 [ # # ][ # # ]: 0 : while ( ! IsKashidaValid ( nCntKash ) && nCntKash < nCntKashEnd )
[ # # ]
1782 : 0 : ++nCntKash;
1783 : :
1784 : 0 : xub_StrLen nKashidaPos = GetKashida( nCntKash );
1785 : 0 : xub_StrLen nIdx = nKashidaPos;
1786 : 0 : long nKashAdd = nSpaceAdd;
1787 : :
1788 [ # # ]: 0 : while ( nIdx < nEnd )
1789 : : {
1790 : 0 : sal_uInt16 nArrayPos = nIdx - nStt;
1791 : :
1792 : : // next kashida position
1793 : 0 : ++nCntKash;
1794 [ # # ][ # # ]: 0 : while ( ! IsKashidaValid ( nCntKash ) && nCntKash < nCntKashEnd )
[ # # ]
1795 : 0 : ++nCntKash;
1796 : :
1797 [ # # ][ # # ]: 0 : nIdx = nCntKash < CountKashida() && IsKashidaValid ( nCntKash ) ? GetKashida( nCntKash ) : nEnd;
1798 [ # # ]: 0 : if ( nIdx > nEnd )
1799 : 0 : nIdx = nEnd;
1800 : :
1801 : 0 : const sal_uInt16 nArrayEnd = nIdx - nStt;
1802 : :
1803 [ # # ]: 0 : while ( nArrayPos < nArrayEnd )
1804 : : {
1805 : 0 : pKernArray[ nArrayPos ] += nKashAdd;
1806 [ # # ]: 0 : if ( pScrArray )
1807 : 0 : pScrArray[ nArrayPos ] += nKashAdd;
1808 : 0 : ++nArrayPos;
1809 : : }
1810 : 0 : nKashAdd += nSpaceAdd;
1811 : : }
1812 : : }
1813 : :
1814 : 0 : return 0;
1815 : : }
1816 : :
1817 : : /*************************************************************************
1818 : : * SwScriptInfo::IsArabicText()
1819 : : *
1820 : : * Checks if the current text is 'Arabic' text. Note that only the first
1821 : : * character has to be checked because a ctl portion only contains one
1822 : : * script, see NewTxtPortion
1823 : : *************************************************************************/
1824 : 0 : bool SwScriptInfo::IsArabicText( const rtl::OUString& rTxt, sal_Int32 nStt, sal_Int32 nLen )
1825 : : {
1826 : : using namespace ::com::sun::star::i18n;
1827 : : static ScriptTypeList typeList[] = {
1828 : : { UnicodeScript_kArabic, UnicodeScript_kArabic, UnicodeScript_kArabic }, // 11,
1829 : : { UnicodeScript_kScriptCount, UnicodeScript_kScriptCount, UnicodeScript_kScriptCount } // 88
1830 : : };
1831 : :
1832 : : // go forward if current position does not hold a regular character:
1833 : 0 : const CharClass& rCC = GetAppCharClass();
1834 : 0 : sal_Int32 nIdx = nStt;
1835 : 0 : const sal_Int32 nEnd = nStt + nLen;
1836 [ # # ][ # # ]: 0 : while ( nIdx < nEnd && !rCC.isLetterNumeric( rTxt, (xub_StrLen)nIdx ) )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
1837 : : {
1838 : 0 : ++nIdx;
1839 : : }
1840 : :
1841 [ # # ]: 0 : if( nIdx == nEnd )
1842 : : {
1843 : : // no regular character found in this portion. Go backward:
1844 : 0 : --nIdx;
1845 [ # # ][ # # ]: 0 : while ( nIdx >= 0 && !rCC.isLetterNumeric( rTxt, (xub_StrLen)nIdx ) )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
1846 : : {
1847 : 0 : --nIdx;
1848 : : }
1849 : : }
1850 : :
1851 [ # # ]: 0 : if( nIdx >= 0 )
1852 : : {
1853 : 0 : const xub_Unicode cCh = rTxt[nIdx];
1854 : 0 : const sal_Int16 type = unicode::getUnicodeScriptType( cCh, typeList, UnicodeScript_kScriptCount );
1855 : 0 : return type == UnicodeScript_kArabic;
1856 : : }
1857 : 0 : return false;
1858 : : }
1859 : :
1860 : 0 : sal_Bool SwScriptInfo::IsKashidaValid ( xub_StrLen nKashPos ) const
1861 : : {
1862 [ # # ]: 0 : for ( size_t i = 0; i < aKashidaInvalid.size(); ++i )
1863 : : {
1864 [ # # ]: 0 : if ( aKashidaInvalid [ i ] == nKashPos )
1865 : 0 : return false;
1866 : : }
1867 : 0 : return true;
1868 : : }
1869 : :
1870 : 0 : void SwScriptInfo::ClearKashidaInvalid ( xub_StrLen nKashPos )
1871 : : {
1872 [ # # ]: 0 : for ( size_t i = 0; i < aKashidaInvalid.size(); ++i )
1873 : : {
1874 [ # # ]: 0 : if ( aKashidaInvalid [ i ] == nKashPos )
1875 : : {
1876 [ # # ][ # # ]: 0 : aKashidaInvalid.erase ( aKashidaInvalid.begin() + i );
1877 : 0 : return;
1878 : : }
1879 : : }
1880 : : }
1881 : :
1882 : : /*************************************************************************
1883 : : * SwScriptInfo::MarkOrClearKashidaInvalid()
1884 : : *
1885 : : * bMark == true:
1886 : : * marks the first valid kashida in the given text range as invalid
1887 : : *
1888 : : * bMark == false:
1889 : : * clears all kashida invalid flags in the given text range
1890 : : *************************************************************************/
1891 : :
1892 : 0 : bool SwScriptInfo::MarkOrClearKashidaInvalid ( xub_StrLen nStt, xub_StrLen nLen, bool bMark, xub_StrLen nMarkCount )
1893 : : {
1894 : 0 : sal_uInt16 nCntKash = 0;
1895 [ # # ]: 0 : while( nCntKash < CountKashida() )
1896 : : {
1897 [ # # ]: 0 : if ( nStt <= GetKashida( nCntKash ) )
1898 : 0 : break;
1899 : : else
1900 : 0 : nCntKash++;
1901 : : }
1902 : :
1903 : 0 : const xub_StrLen nEnd = nStt + nLen;
1904 : :
1905 [ # # ]: 0 : while ( nCntKash < CountKashida() )
1906 : : {
1907 [ # # ]: 0 : if ( nEnd <= GetKashida( nCntKash ) )
1908 : 0 : break;
1909 : : else
1910 : : {
1911 [ # # ]: 0 : if(bMark)
1912 : : {
1913 [ # # ]: 0 : if ( IsKashidaValid ( nCntKash ) )
1914 : : {
1915 : 0 : MarkKashidaInvalid ( nCntKash );
1916 : 0 : --nMarkCount;
1917 [ # # ]: 0 : if(!nMarkCount)
1918 : 0 : return true;
1919 : : }
1920 : : }
1921 : : else
1922 : : {
1923 : 0 : ClearKashidaInvalid ( nCntKash );
1924 : : }
1925 : 0 : nCntKash++;
1926 : : }
1927 : : }
1928 : 0 : return false;
1929 : : }
1930 : :
1931 : 0 : void SwScriptInfo::MarkKashidaInvalid ( xub_StrLen nKashPos )
1932 : : {
1933 : 0 : aKashidaInvalid.push_back( nKashPos );
1934 : 0 : }
1935 : :
1936 : : /*************************************************************************
1937 : : * SwScriptInfo::GetKashidaPositions()
1938 : : * retrieve the kashida positions in the given text range
1939 : : *************************************************************************/
1940 : :
1941 : 0 : sal_uInt16 SwScriptInfo::GetKashidaPositions ( xub_StrLen nStt, xub_StrLen nLen,
1942 : : xub_StrLen* pKashidaPosition )
1943 : : {
1944 : 0 : sal_uInt16 nCntKash = 0;
1945 [ # # ]: 0 : while( nCntKash < CountKashida() )
1946 : : {
1947 [ # # ]: 0 : if ( nStt <= GetKashida( nCntKash ) )
1948 : 0 : break;
1949 : : else
1950 : 0 : nCntKash++;
1951 : : }
1952 : :
1953 : 0 : const xub_StrLen nEnd = nStt + nLen;
1954 : :
1955 : 0 : sal_uInt16 nCntKashEnd = nCntKash;
1956 [ # # ]: 0 : while ( nCntKashEnd < CountKashida() )
1957 : : {
1958 [ # # ]: 0 : if ( nEnd <= GetKashida( nCntKashEnd ) )
1959 : 0 : break;
1960 : : else
1961 : : {
1962 : 0 : pKashidaPosition [ nCntKashEnd - nCntKash ] = GetKashida ( nCntKashEnd );
1963 : 0 : nCntKashEnd++;
1964 : : }
1965 : : }
1966 : 0 : return nCntKashEnd - nCntKash;
1967 : : }
1968 : :
1969 : 0 : void SwScriptInfo::SetNoKashidaLine ( xub_StrLen nStt, xub_StrLen nLen )
1970 : : {
1971 : 0 : aNoKashidaLine.push_back( nStt );
1972 [ # # ]: 0 : aNoKashidaLineEnd.push_back( nStt+nLen );
1973 : 0 : }
1974 : :
1975 : : /*************************************************************************
1976 : : * SwScriptInfo::IsKashidaLine()
1977 : : * determines if the line uses kashida justification
1978 : : *************************************************************************/
1979 : :
1980 : 0 : bool SwScriptInfo::IsKashidaLine ( xub_StrLen nCharIdx ) const
1981 : : {
1982 [ # # ]: 0 : for( size_t i = 0; i < aNoKashidaLine.size(); ++i )
1983 : : {
1984 [ # # ][ # # ]: 0 : if( nCharIdx >= aNoKashidaLine[ i ] && nCharIdx < aNoKashidaLineEnd[ i ])
[ # # ]
1985 : 0 : return false;
1986 : : }
1987 : 0 : return true;
1988 : : }
1989 : :
1990 : 0 : void SwScriptInfo::ClearNoKashidaLine ( xub_StrLen nStt, xub_StrLen nLen )
1991 : : {
1992 : 0 : size_t i = 0;
1993 [ # # ]: 0 : while( i < aNoKashidaLine.size())
1994 : : {
1995 [ # # ][ # # ]: 0 : if( nStt + nLen >= aNoKashidaLine[ i ] && nStt < aNoKashidaLineEnd [ i ] )
[ # # ]
1996 : : {
1997 [ # # ][ # # ]: 0 : aNoKashidaLine.erase(aNoKashidaLine.begin() + i);
1998 [ # # ][ # # ]: 0 : aNoKashidaLineEnd.erase(aNoKashidaLineEnd.begin() + i);
1999 : : }
2000 : : else
2001 : 0 : ++i;
2002 : : }
2003 : 0 : }
2004 : :
2005 : : /*************************************************************************
2006 : : * SwScriptInfo::MarkKashidasInvalid()
2007 : : *
2008 : : * mark the given character indices as invalid kashida positions
2009 : : ************************************************************************/
2010 : :
2011 : 0 : bool SwScriptInfo::MarkKashidasInvalid ( xub_StrLen nCnt, xub_StrLen* pKashidaPositions )
2012 : : {
2013 : : SAL_WARN_IF( !pKashidaPositions || nCnt == 0, "sw.core", "Where are kashidas?" );
2014 : :
2015 : 0 : sal_uInt16 nCntKash = 0;
2016 : 0 : xub_StrLen nKashidaPosIdx = 0;
2017 : :
2018 [ # # ][ # # ]: 0 : while ( nCntKash < CountKashida() && nKashidaPosIdx < nCnt )
[ # # ]
2019 : : {
2020 [ # # ]: 0 : if ( pKashidaPositions [nKashidaPosIdx] > GetKashida( nCntKash ) )
2021 : : {
2022 : 0 : nCntKash++;
2023 : 0 : continue;
2024 : : }
2025 : :
2026 [ # # ][ # # ]: 0 : if ( pKashidaPositions [nKashidaPosIdx] == GetKashida( nCntKash ) && IsKashidaValid ( nCntKash ) )
[ # # ]
2027 : : {
2028 : 0 : MarkKashidaInvalid ( nCntKash );
2029 : : }
2030 : : else
2031 : 0 : return false; // something is wrong
2032 : 0 : nKashidaPosIdx++;
2033 : : }
2034 : 0 : return true;
2035 : : }
2036 : :
2037 : 0 : sal_Int32 SwScriptInfo::ThaiJustify( const rtl::OUString& rTxt, sal_Int32* pKernArray,
2038 : : sal_Int32* pScrArray, sal_Int32 nStt,
2039 : : sal_Int32 nLen, sal_Int32 nNumberOfBlanks,
2040 : : long nSpaceAdd )
2041 : : {
2042 : : SAL_WARN_IF( nStt + nLen > rTxt.getLength(), "sw.core", "String in ThaiJustify too small" );
2043 : :
2044 : : SwTwips nNumOfTwipsToDistribute = nSpaceAdd * nNumberOfBlanks /
2045 : 0 : SPACING_PRECISION_FACTOR;
2046 : :
2047 : 0 : long nSpaceSum = 0;
2048 : 0 : sal_Int32 nCnt = 0;
2049 : :
2050 [ # # ]: 0 : for (sal_Int32 nI = 0; nI < nLen; ++nI)
2051 : : {
2052 : 0 : const xub_Unicode cCh = rTxt[nStt + nI];
2053 : :
2054 : : // check if character is not above or below base
2055 [ # # ][ # # ]: 0 : if ( ( 0xE34 > cCh || cCh > 0xE3A ) &&
[ # # ][ # # ]
[ # # ]
2056 : : ( 0xE47 > cCh || cCh > 0xE4E ) && cCh != 0xE31 )
2057 : : {
2058 [ # # ]: 0 : if ( nNumberOfBlanks > 0 )
2059 : : {
2060 : 0 : nSpaceAdd = nNumOfTwipsToDistribute / nNumberOfBlanks;
2061 : 0 : --nNumberOfBlanks;
2062 : 0 : nNumOfTwipsToDistribute -= nSpaceAdd;
2063 : : }
2064 : 0 : nSpaceSum += nSpaceAdd;
2065 : 0 : ++nCnt;
2066 : : }
2067 : :
2068 [ # # ]: 0 : if ( pKernArray ) pKernArray[ nI ] += nSpaceSum;
2069 [ # # ]: 0 : if ( pScrArray ) pScrArray[ nI ] += nSpaceSum;
2070 : : }
2071 : :
2072 : 0 : return nCnt;
2073 : : }
2074 : :
2075 : 22457 : SwScriptInfo* SwScriptInfo::GetScriptInfo( const SwTxtNode& rTNd,
2076 : : sal_Bool bAllowInvalid )
2077 : : {
2078 [ + - ]: 22457 : SwIterator<SwTxtFrm,SwTxtNode> aIter( rTNd );
2079 : 22457 : SwScriptInfo* pScriptInfo = 0;
2080 : :
2081 [ + - ][ + - ]: 43338 : for( SwTxtFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
[ + + ]
2082 : : {
2083 [ + - ]: 24096 : pScriptInfo = (SwScriptInfo*)pLast->GetScriptInfo();
2084 [ + + ]: 24096 : if ( pScriptInfo )
2085 : : {
2086 [ + + ][ + + ]: 13122 : if ( !bAllowInvalid && STRING_LEN != pScriptInfo->GetInvalidity() )
[ + + ]
2087 : 9907 : pScriptInfo = 0;
2088 : 3215 : else break;
2089 : : }
2090 : : }
2091 : :
2092 [ + - ]: 22457 : return pScriptInfo;
2093 : : }
2094 : :
2095 [ + - ]: 5091 : SwParaPortion::SwParaPortion()
2096 : : {
2097 : 5091 : FormatReset();
2098 : 5091 : bFlys = bFtnNum = bMargin = sal_False;
2099 : 5091 : SetWhichPor( POR_PARA );
2100 : 5091 : }
2101 : :
2102 : 5091 : SwParaPortion::~SwParaPortion()
2103 : : {
2104 [ - + ]: 10182 : }
2105 : :
2106 : 54 : xub_StrLen SwParaPortion::GetParLen() const
2107 : : {
2108 : 54 : xub_StrLen nLen = 0;
2109 : 54 : const SwLineLayout *pLay = this;
2110 [ + + ]: 108 : while( pLay )
2111 : : {
2112 : 54 : nLen = nLen + pLay->GetLen();
2113 : 54 : pLay = pLay->GetNext();
2114 : : }
2115 : 54 : return nLen;
2116 : : }
2117 : :
2118 : 94315 : const SwDropPortion *SwParaPortion::FindDropPortion() const
2119 : : {
2120 : 94315 : const SwLineLayout *pLay = this;
2121 [ + + ][ + + ]: 98027 : while( pLay && pLay->IsDummy() )
[ + + ]
2122 : 3712 : pLay = pLay->GetNext();
2123 [ + + ]: 185054 : while( pLay )
2124 : : {
2125 : 90739 : const SwLinePortion *pPos = pLay->GetPortion();
2126 [ + + ][ + + ]: 92012 : while ( pPos && !pPos->GetLen() )
[ + + ]
2127 : 1273 : pPos = pPos->GetPortion();
2128 [ + + ][ - + ]: 90739 : if( pPos && pPos->IsDropPortion() )
[ - + ]
2129 : 0 : return (SwDropPortion *)pPos;
2130 [ + + ]: 90739 : pLay = pLay->GetLen() ? NULL : pLay->GetNext();
2131 : : }
2132 : 94315 : return NULL;
2133 : : }
2134 : :
2135 : 59216 : void SwLineLayout::Init( SwLinePortion* pNextPortion )
2136 : : {
2137 : 59216 : Height( 0 );
2138 : 59216 : Width( 0 );
2139 : 59216 : SetLen( 0 );
2140 : 59216 : SetAscent( 0 );
2141 : 59216 : SetRealHeight( 0 );
2142 : 59216 : SetPortion( pNextPortion );
2143 : 59216 : }
2144 : :
2145 : : /*--------------------------------------------------
2146 : : * HangingMargin()
2147 : : * looks for hanging punctuation portions in the paragraph
2148 : : * and return the maximum right offset of them.
2149 : : * If no such portion is found, the Margin/Hanging-flags will be updated.
2150 : : * --------------------------------------------------*/
2151 : :
2152 : 104312 : SwTwips SwLineLayout::_GetHangingMargin() const
2153 : : {
2154 : 104312 : SwLinePortion* pPor = GetPortion();
2155 : 104312 : sal_Bool bFound = sal_False;
2156 : 104312 : SwTwips nDiff = 0;
2157 [ + + ]: 117122 : while( pPor)
2158 : : {
2159 [ - + ]: 12810 : if( pPor->IsHangingPortion() )
2160 : : {
2161 : 0 : nDiff = ((SwHangingPortion*)pPor)->GetInnerWidth() - pPor->Width();
2162 [ # # ]: 0 : if( nDiff )
2163 : 0 : bFound = sal_True;
2164 : : }
2165 : : // the last post its portion
2166 [ + + ][ - + ]: 12810 : else if ( pPor->IsPostItsPortion() && ! pPor->GetPortion() )
[ - + ]
2167 : 0 : nDiff = nAscent;
2168 : :
2169 : 12810 : pPor = pPor->GetPortion();
2170 : : }
2171 [ + - ]: 104312 : if( !bFound ) // update the hanging-flag
2172 : 104312 : ((SwLineLayout*)this)->SetHanging( sal_False );
2173 : 104312 : return nDiff;
2174 : : }
2175 : :
2176 : 28224 : SwTwips SwTxtFrm::HangingMargin() const
2177 : : {
2178 : : SAL_WARN_IF( !HasPara(), "sw.core", "Don't call me without a paraportion" );
2179 [ + - ]: 28224 : if( !GetPara()->IsMargin() )
2180 : 28224 : return 0;
2181 : 0 : const SwLineLayout* pLine = GetPara();
2182 : 0 : SwTwips nRet = 0;
2183 [ # # ]: 0 : do
2184 : : {
2185 : 0 : SwTwips nDiff = pLine->GetHangingMargin();
2186 [ # # ]: 0 : if( nDiff > nRet )
2187 : 0 : nRet = nDiff;
2188 : 0 : pLine = pLine->GetNext();
2189 : : } while ( pLine );
2190 [ # # ]: 0 : if( !nRet ) // update the margin-flag
2191 : 0 : ((SwParaPortion*)GetPara())->SetMargin( sal_False );
2192 : 28224 : return nRet;
2193 : : }
2194 : :
2195 : 30105 : void SwScriptInfo::selectHiddenTextProperty(const SwTxtNode& rNode, MultiSelection &rHiddenMulti)
2196 : : {
2197 : : assert((!rNode.GetTxt().Len() && rHiddenMulti.GetTotalRange().Len() == 1) ||
2198 : : (rNode.GetTxt().Len() == rHiddenMulti.GetTotalRange().Len()));
2199 : :
2200 : 30105 : const SfxPoolItem* pItem = 0;
2201 [ + - ][ + - ]: 30267 : if( SFX_ITEM_SET == rNode.GetSwAttrSet().GetItemState( RES_CHRATR_HIDDEN, sal_True, &pItem ) &&
[ + + + - ]
[ + + ]
2202 : 162 : ((SvxCharHiddenItem*)pItem)->GetValue() )
2203 : : {
2204 [ + - ]: 162 : rHiddenMulti.SelectAll();
2205 : : }
2206 : :
2207 : 30105 : const SwpHints* pHints = rNode.GetpSwpHints();
2208 : :
2209 [ + + ]: 30105 : if( pHints )
2210 : : {
2211 : 5951 : MSHORT nTmp = 0;
2212 : :
2213 [ + + ]: 15389 : while( nTmp < pHints->GetStartCount() )
2214 : : {
2215 [ + - ]: 9438 : const SwTxtAttr* pTxtAttr = pHints->GetStart( nTmp++ );
2216 : : const SvxCharHiddenItem* pHiddenItem =
2217 [ + - ]: 9438 : static_cast<const SvxCharHiddenItem*>( CharFmt::GetItem( *pTxtAttr, RES_CHRATR_HIDDEN ) );
2218 [ + + ]: 9438 : if( pHiddenItem )
2219 : : {
2220 : 272 : xub_StrLen nSt = *pTxtAttr->GetStart();
2221 [ + - ]: 272 : xub_StrLen nEnd = *pTxtAttr->GetEnd();
2222 [ + + ]: 272 : if( nEnd > nSt )
2223 : : {
2224 : 20 : Range aTmp( nSt, nEnd - 1 );
2225 [ + - ]: 20 : rHiddenMulti.Select( aTmp, pHiddenItem->GetValue() );
2226 : : }
2227 : : }
2228 : : }
2229 : : }
2230 : 30105 : }
2231 : :
2232 : 30105 : void SwScriptInfo::selectRedLineDeleted(const SwTxtNode& rNode, MultiSelection &rHiddenMulti, bool bSelect)
2233 : : {
2234 : : assert((!rNode.GetTxt().Len() && rHiddenMulti.GetTotalRange().Len() == 1) ||
2235 : : (rNode.GetTxt().Len() == rHiddenMulti.GetTotalRange().Len()));
2236 : :
2237 : 30105 : const IDocumentRedlineAccess& rIDRA = *rNode.getIDocumentRedlineAccess();
2238 [ + + ]: 30105 : if ( IDocumentRedlineAccess::IsShowChanges( rIDRA.GetRedlineMode() ) )
2239 : : {
2240 : 29974 : sal_uInt16 nAct = rIDRA.GetRedlinePos( rNode, USHRT_MAX );
2241 : :
2242 [ + + ]: 29989 : for ( ; nAct < rIDRA.GetRedlineTbl().size(); nAct++ )
2243 : : {
2244 [ + - ][ + - ]: 15 : const SwRedline* pRed = rIDRA.GetRedlineTbl()[ nAct ];
2245 : :
2246 [ + - ][ + - ]: 15 : if ( pRed->Start()->nNode > rNode.GetIndex() )
2247 : : break;
2248 : :
2249 : : xub_StrLen nRedlStart;
2250 : : xub_StrLen nRedlnEnd;
2251 [ + - ]: 15 : pRed->CalcStartEnd( rNode.GetIndex(), nRedlStart, nRedlnEnd );
2252 : : //clip it if the redline extends past the end of the nodes text
2253 [ + - ]: 15 : nRedlnEnd = std::min(nRedlnEnd, rNode.GetTxt().Len());
2254 [ + - ]: 15 : if ( nRedlnEnd > nRedlStart )
2255 : : {
2256 : 15 : Range aTmp( nRedlStart, nRedlnEnd - 1 );
2257 [ + - ]: 15 : rHiddenMulti.Select( aTmp, bSelect );
2258 : : }
2259 : : }
2260 : : }
2261 : 30105 : }
2262 : :
2263 : : /*************************************************************************
2264 : : * SwScriptInfo::CalcHiddenRanges()
2265 : : *
2266 : : * Returns a MultiSection indicating the hidden ranges.
2267 : : *************************************************************************/
2268 : :
2269 : 27534 : void SwScriptInfo::CalcHiddenRanges( const SwTxtNode& rNode, MultiSelection& rHiddenMulti )
2270 : : {
2271 : 27534 : selectHiddenTextProperty(rNode, rHiddenMulti);
2272 : :
2273 : : // If there are any hidden ranges in the current text node, we have
2274 : : // to unhide the redlining ranges:
2275 : 27534 : selectRedLineDeleted(rNode, rHiddenMulti, false);
2276 : :
2277 : : //
2278 : : // We calculated a lot of stuff. Finally we can update the flags at the text node.
2279 : : //
2280 : 27534 : const bool bNewContainsHiddenChars = rHiddenMulti.GetRangeCount() > 0;
2281 : 27534 : bool bNewHiddenCharsHidePara = false;
2282 [ + + ]: 27534 : if ( bNewContainsHiddenChars )
2283 : : {
2284 : 170 : const Range& rRange = rHiddenMulti.GetRange( 0 );
2285 : 170 : const xub_StrLen nHiddenStart = (xub_StrLen)rRange.Min();
2286 : 170 : const xub_StrLen nHiddenEnd = (xub_StrLen)rRange.Max() + 1;
2287 [ + - ][ + - ]: 170 : bNewHiddenCharsHidePara = ( nHiddenStart == 0 && nHiddenEnd >= rNode.GetTxt().Len() );
2288 : : }
2289 : 27534 : rNode.SetHiddenCharAttribute( bNewHiddenCharsHidePara, bNewContainsHiddenChars );
2290 : 27534 : }
2291 : :
2292 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|