summaryrefslogtreecommitdiff
path: root/bf_sw/source/core/text/sw_porlay.cxx
blob: 6a4beb03d7c696a9219cd4b0048a5b81a29921af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#ifdef _MSC_VER
#pragma hdrstop
#endif


#include "txtcfg.hxx"
#include "itrform2.hxx"
#include "porfly.hxx"   // SwFlyCntPortion
#include <porrst.hxx>       // SwHangingPortion
#include <pormulti.hxx>     // SwMultiPortion
#include <breakit.hxx>
#include <com/sun/star/i18n/ScriptType.hdl>
#include <com/sun/star/i18n/WordType.hdl>

#include <horiornt.hxx>

#include <doc.hxx>
#ifdef BIDI
#include <paratr.hxx>
#include <bf_svx/adjitem.hxx>
#endif
#include <bf_svx/scripttypeitem.hxx>

using namespace ::com::sun::star;
using namespace ::com::sun::star::i18n::ScriptType;

#ifdef BIDI
#include <unicode/ubidi.h>
#endif
namespace binfilter {

/*************************************************************************
 *                 SwLineLayout::~SwLineLayout()
 *
 * class SwLineLayout: Das Layout einer einzelnen Zeile. Dazu
 * gehoeren vor allen Dingen die Dimension, die Anzahl der
 * Character und der Wortzwischenraeume in der Zeile.
 * Zeilenobjekte werden in einem eigenen Pool verwaltet, um zu
 * erreichen, dass sie im Speicher moeglichst beeinander liegen
 * (d.h. zusammen gepaged werden und den Speicher nicht
 * fragmentieren).
 *************************************************************************/

/*N*/ SwLineLayout::~SwLineLayout()
/*N*/ {
/*N*/   Truncate();
/*N*/   if( GetNext() )
/*N*/       delete GetNext();
/*N*/   delete pSpaceAdd;
/*N*/     if ( pKanaComp )
/*?*/         delete pKanaComp;
/*N*/ }

/*************************************************************************
 *                virtual SwLineLayout::Insert()
 *************************************************************************/

SwLinePortion *SwLineLayout::Insert( SwLinePortion *pIns )
/*N*/ {
/*N*/   // Erster Attributwechsel, Masse und Laengen
/*N*/   // aus *pCurr in die erste Textportion kopieren.
/*N*/   if( !pPortion )
/*N*/   {
/*N*/       if( GetLen() )
/*N*/       {
/*N*/           pPortion = new SwTxtPortion( *(SwLinePortion*)this );
/*N*/       }
/*N*/       else
/*N*/       {
/*N*/           SetPortion( pIns );
/*N*/           return pIns;
/*N*/       }
/*N*/   }
/*N*/   // mit Skope aufrufen, sonst Rekursion !
/*N*/   return pPortion->SwLinePortion::Insert( pIns );
/*N*/ }

/*************************************************************************
 *                virtual SwLineLayout::Format()
 *************************************************************************/

// fuer die Sonderbehandlung bei leeren Zeilen

/*N*/ sal_Bool SwLineLayout::Format( SwTxtFormatInfo &rInf )
/*N*/ {
/*N*/   if( GetLen() )
/*N*/       return SwTxtPortion::Format( rInf );
/*N*/   else
/*N*/   {
/*?*/       Height( rInf.GetTxtHeight() );
/*?*/       return sal_True;
/*N*/   }
/*N*/ }

/*************************************************************************
 *                    SwLineLayout::CalcLeftMargin()
 *
 * Wir sammeln alle FlyPortions am Anfang der Zeile zu einer MarginPortion.
 *************************************************************************/

/*N*/ SwMarginPortion *SwLineLayout::CalcLeftMargin()
/*N*/ {
/*N*/   SwMarginPortion *pLeft = (GetPortion() && GetPortion()->IsMarginPortion()) ?
/*N*/       (SwMarginPortion *)GetPortion() : 0;
/*N*/   if( !GetPortion() )
/*N*/        SetPortion( new SwTxtPortion( *(SwLinePortion*)this ) );
/*N*/   if( !pLeft )
/*N*/   {
/*N*/       pLeft = new SwMarginPortion( 0 );
/*N*/       pLeft->SetPortion( GetPortion() );
/*N*/       SetPortion( pLeft );
/*N*/   }
/*N*/   else
/*N*/   {
/*?*/       pLeft->Height( 0 );
/*?*/       pLeft->Width( 0 );
/*?*/       pLeft->SetLen( 0 );
/*?*/       pLeft->SetAscent( 0 );
/*?*/       pLeft->SetPortion( NULL );
/*?*/       pLeft->SetFixWidth(0);
/*N*/   }
/*N*/
/*N*/   SwLinePortion *pPos = pLeft->GetPortion();
/*N*/   while( pPos )
/*N*/   {
///*N*/         DBG_LOOP;
/*N*/       if( pPos->IsFlyPortion() )
/*N*/       {
/*N*/           // Die FlyPortion wird ausgesogen ...
/*N*/           pLeft->Join( (SwGluePortion*)pPos );
/*N*/           pPos = pLeft->GetPortion();
/*N*/           if( GetpKanaComp() )
/*N*/               GetKanaComp().Remove( 0, 1 );
/*N*/       }
/*N*/       else
/*N*/           pPos = 0;
/*N*/   }
/*N*/   return pLeft;
/*N*/ }

/*************************************************************************
 *                    SwLineLayout::CreateSpaceAdd()
 *************************************************************************/

/*N*/ void SwLineLayout::CreateSpaceAdd( const short nInit )
/*N*/ {
/*N*/   pSpaceAdd = new SvShorts;
/*N*/   pSpaceAdd->Insert( nInit, 0 );
/*N*/ }

/*************************************************************************
 *                    SwLineLayout::CalcLine()
 *
 * Aus FormatLine() ausgelagert.
 *************************************************************************/

/*N*/ void SwLineLayout::CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf )
/*N*/ {
/*N*/   const KSHORT nLineWidth = rInf.RealWidth();
/*N*/
/*N*/   KSHORT nFlyAscent(0);
/*N*/   KSHORT nFlyHeight(0);
/*N*/   KSHORT nFlyDescent(0);
/*N*/   sal_Bool bOnlyPostIts = sal_True;
/*N*/   SetHanging( sal_False );
/*N*/
/*N*/   sal_Bool bTmpDummy = ( 0 == GetLen() );
/*N*/   SwFlyCntPortion* pFlyCnt = 0;
/*N*/   if( bTmpDummy )
/*N*/   {
/*N*/       nFlyAscent = 0;
/*N*/       nFlyHeight = 0;
/*N*/       nFlyDescent = 0;
/*N*/   }
/*N*/
/*N*/   if( pPortion )
/*N*/   {
/*N*/       SetCntnt( sal_False );
/*N*/       if( pPortion->IsBreakPortion() )
/*N*/       {
/*N*/           SetLen( pPortion->GetLen() );
/*N*/           if( GetLen() )
/*N*/               bTmpDummy = sal_False;
/*N*/       }
/*N*/       else
/*N*/       {
/*N*/           Init( GetPortion() );
/*N*/           SwLinePortion *pPos = pPortion;
/*N*/           SwLinePortion *pLast = this;
/*N*/           KSHORT nMaxDescent = 0;
/*N*/
/*N*/           //  Eine Gruppe ist ein Abschnitt in der Portion-Kette von
/*N*/           //  pCurr oder einer Fix-Portion bis zum Ende bzw. zur naechsten
/*N*/           //  Fix-Portion.
/*N*/           while( pPos )
/*N*/           {
///*N*/                 DBG_LOOP;
/*N*/               OSL_ENSURE( POR_LIN != pPos->GetWhichPor(),
/*N*/                       "SwLineLayout::CalcLine: don't use SwLinePortions !" );
/*N*/               // Null-Portions werden eliminiert. Sie koennen entstehen,
/*N*/               // wenn zwei FlyFrms ueberlappen.
/*N*/               if( !pPos->Compress() )
/*N*/               {
/*N*/                   // 8110: Hoehe und Ascent nur uebernehmen, wenn sonst in der
/*N*/                   // Zeile nichts mehr los ist.
/*N*/                   if( !pPos->GetPortion() )
/*N*/                   {
/*N*/                       if( !Height() )
/*N*/                           Height( pPos->Height() );
/*N*/                       if( !GetAscent() )
/*N*/                           SetAscent( pPos->GetAscent() );
/*N*/                   }
/*N*/                   delete pLast->Cut( pPos );
/*N*/                   pPos = pLast->GetPortion();
/*N*/                   continue;
/*N*/               }
/*N*/
/*N*/               // Es gab Attributwechsel: Laengen und Masse aufaddieren;
/*N*/               // bzw.Maxima bilden.
/*N*/
/*N*/               nLineLength += pPos->GetLen();
/*N*/
/*N*/                 KSHORT nPosHeight = pPos->Height();
/*N*/               KSHORT nPosAscent = pPos->GetAscent();
/*N*/               AddPrtWidth( pPos->Width() );
/*N*/
/*N*/               OSL_ENSURE( nPosHeight >= nPosAscent,
/*N*/                       "SwLineLayout::CalcLine: bad ascent or height" );
/*N*/               if( pPos->IsHangingPortion() )
/*N*/               {
/*?*/                   SetHanging( sal_True );
/*?*/                   rInf.GetParaPortion()->SetMargin( sal_True );
/*N*/               }
/*N*/
/*N*/               // Damit ein Paragraphende-Zeichen nicht durch ein Descent zu einer
/*N*/               // geaenderten Zeilenhoehe und zum Umformatieren fuehrt.
/*N*/               if ( !pPos->IsBreakPortion() || !Height() )
/*N*/               {
/*N*/                   bOnlyPostIts &= pPos->IsPostItsPortion();
/*N*/                   if( bTmpDummy && !nLineLength )
/*N*/                   {
/*N*/                       if( pPos->IsFlyPortion() )
/*N*/                       {
/*N*/                           if( nFlyHeight < nPosHeight )
/*N*/                               nFlyHeight = nPosHeight;
/*N*/                           if( nFlyAscent < nPosAscent )
/*N*/                               nFlyAscent = nPosAscent;
/*N*/                           if( nFlyDescent < nPosHeight - nPosAscent )
/*N*/                               nFlyDescent = nPosHeight - nPosAscent;
/*N*/                       }
/*N*/                       else
/*N*/                       {
/*N*/                           if( pPos->InNumberGrp() )
/*N*/                           {
/*N*/                               KSHORT nTmp = rInf.GetFont()->GetAscent(
/*N*/                                               rInf.GetVsh(), rInf.GetOut() );
/*N*/                               if( nTmp > nPosAscent )
/*N*/                               {
/*N*/                                   nPosHeight += nTmp - nPosAscent;
/*N*/                                   nPosAscent = nTmp;
/*N*/                               }
/*N*/                               nTmp = rInf.GetFont()->GetHeight( rInf.GetVsh(),
/*N*/                                                               rInf.GetOut() );
/*N*/                               if( nTmp > nPosHeight )
/*N*/                                   nPosHeight = nTmp;
/*N*/                           }
/*N*/                           Height( nPosHeight );
/*N*/                           nAscent = nPosAscent;
/*N*/                           nMaxDescent = nPosHeight - nPosAscent;
/*N*/                       }
/*N*/                   }
/*N*/                   else if( !pPos->IsFlyPortion() )
/*N*/                   {
/*N*/                       if( Height() < nPosHeight )
/*N*/                           Height( nPosHeight );
/*N*/                       if( pPos->IsFlyCntPortion() || ( pPos->IsMultiPortion()
/*N*/                           && ((SwMultiPortion*)pPos)->HasFlyInCntnt() ) )
/*N*/                           rLine.SetFlyInCntBase();
/*N*/                       if( pPos->IsFlyCntPortion() &&
/*N*/                           ((SwFlyCntPortion*)pPos)->GetAlign() )
/*N*/                       {
/*N*/                           ((SwFlyCntPortion*)pPos)->SetMax( sal_False );
/*N*/                           if( !pFlyCnt || pPos->Height() > pFlyCnt->Height() )
/*N*/                               pFlyCnt = (SwFlyCntPortion*)pPos;
/*N*/                       }
/*N*/                       else
/*N*/                       {
/*N*/                           if( nAscent < nPosAscent )
/*N*/                               nAscent = nPosAscent;
/*N*/                           if( nMaxDescent < nPosHeight - nPosAscent )
/*N*/                               nMaxDescent = nPosHeight - nPosAscent;
/*N*/                       }
/*N*/                   }
/*N*/               }
/*N*/               else if( pPos->GetLen() )
/*N*/                   bTmpDummy = sal_False;
/*N*/               if( !HasCntnt() && !pPos->InNumberGrp() )
/*N*/               {
/*N*/                   if ( pPos->InExpGrp() )
/*N*/                   {
/*N*/                       XubString aTxt;
/*N*/                       if( pPos->GetExpTxt( rInf, aTxt ) && aTxt.Len() )
/*N*/                           SetCntnt( sal_True );
/*N*/                   }
/*N*/                     else if( ( pPos->InTxtGrp() || pPos->IsMultiPortion() ) &&
/*N*/                              pPos->GetLen() )
/*N*/                       SetCntnt( sal_True );
/*N*/               }
/*N*/               bTmpDummy = bTmpDummy && !HasCntnt() &&
/*N*/                           ( !pPos->Width() || pPos->IsFlyPortion() );
/*N*/
/*N*/               pLast = pPos;
/*N*/               pPos = pPos->GetPortion();
/*N*/           }
/*N*/           if( pFlyCnt )
/*N*/           {
/*N*/               if( pFlyCnt->Height() == Height() )
/*N*/               {
/*N*/                   pFlyCnt->SetMax( sal_True );
/*N*/                   if( Height() > nMaxDescent + nAscent )
/*N*/                   {
/*N*/                       if( 3 == pFlyCnt->GetAlign() ) // Bottom
/*?*/                           nAscent = Height() - nMaxDescent;
/*N*/                       else if( 2 == pFlyCnt->GetAlign() ) // Center
/*N*/                           nAscent = ( Height() + nAscent - nMaxDescent ) / 2;
/*N*/                   }
/*N*/                   pFlyCnt->SetAscent( nAscent );
/*N*/               }
/*N*/           }
/*N*/           if( bTmpDummy && nFlyHeight )
/*N*/           {
/*N*/               nAscent = nFlyAscent;
/*N*/               if( nFlyDescent > nFlyHeight - nFlyAscent )
/*?*/                   Height( nFlyHeight + nFlyDescent );
/*N*/               else
/*N*/                   Height( nFlyHeight );
/*N*/           }
/*N*/           else if( nMaxDescent > Height() - nAscent )
/*N*/               Height( nMaxDescent + nAscent );
/*N*/           if( bOnlyPostIts )
/*N*/           {
/*?*/               Height( rInf.GetFont()->GetHeight( rInf.GetVsh(), rInf.GetOut() ) );
/*?*/               nAscent = rInf.GetFont()->GetAscent( rInf.GetVsh(), rInf.GetOut() );
/*N*/           }
/*N*/       }
/*N*/   }
/*N*/   else
/*N*/       SetCntnt( !bTmpDummy );
/*N*/   // Robust:
/*N*/   if( nLineWidth < Width() )
/*N*/       Width( nLineWidth );
/*N*/   OSL_ENSURE( nLineWidth >= Width(), "SwLineLayout::CalcLine: line is bursting" );
/*N*/   SetDummy( bTmpDummy );
/*N*/   SetRedline( sal_False );
/*N*/ }

/*************************************************************************
 *                      class SwCharRange
 *************************************************************************/

/*N*/ SwCharRange &SwCharRange::operator+=(const SwCharRange &rRange)
/*N*/ {
/*N*/   if(0 != rRange.nLen ) {
/*N*/       if(0 == nLen) {
/*N*/           nStart = rRange.nStart;
/*N*/           nLen = rRange.nLen ;
/*N*/       }
/*N*/       else {
/*N*/           if(rRange.nStart + rRange.nLen > nStart + nLen) {
/*N*/               nLen = rRange.nStart + rRange.nLen - nStart;
/*N*/           }
/*N*/           if(rRange.nStart < nStart) {
/*N*/               nLen += nStart - rRange.nStart;
/*N*/               nStart = rRange.nStart;
/*N*/           }
/*N*/       }
/*N*/   }
/*N*/   return *this;
/*N*/ }

/*************************************************************************
 *                      WhichFont()
 *
 * Converts i18n Script Type (LATIN, ASIAN, COMPLEX, WEAK) to
 * Sw Script Types (SW_LATIN, SW_CJK, SW_CTL), used to identify the font
 *************************************************************************/

/*N*/ BYTE WhichFont( xub_StrLen nIdx, const String* pTxt, const SwScriptInfo* pSI )
/*N*/ {
/*N*/     OSL_ENSURE( pTxt || pSI,"How should I determine the script type?" );
/*N*/     USHORT nScript;
/*N*/
/*N*/     // First we try to use our SwScriptInfo
/*N*/     if ( pSI )
/*N*/         nScript = pSI->ScriptType( nIdx );
/*N*/     else
/*N*/         // Ok, we have to ask the break iterator
/*N*/         nScript = pBreakIt->GetRealScriptOfText( *pTxt, nIdx );
/*N*/
/*N*/     switch ( nScript ) {
/*N*/         case i18n::ScriptType::LATIN : return SW_LATIN;
/*?*/         case i18n::ScriptType::ASIAN : return SW_CJK;
/*?*/         case i18n::ScriptType::COMPLEX : return SW_CTL;
/*?*/     }
/*?*/
/*?*/     OSL_FAIL( "Somebody tells lies about the script type!" );
/*?*/     return SW_LATIN;
/*N*/ }


/*************************************************************************
 *                      SwScriptInfo::InitScriptInfo()
 *
 * searches for script changes in rTxt and stores them
 *************************************************************************/

/*N*/ void SwScriptInfo::InitScriptInfo( const SwTxtNode& rNode, sal_Bool bRTL )
/*N*/ {
/*N*/     if( !pBreakIt->xBreak.is() )
/*N*/       return;
/*N*/
/*N*/     xub_StrLen nChg = nInvalidityPos;
/*N*/
/*N*/     // STRING_LEN means the data structure is up to date
/*N*/   nInvalidityPos = STRING_LEN;
/*N*/
/*N*/     // this is the default direction
/*N*/     nDefaultDir = bRTL ? UBIDI_RTL : UBIDI_LTR;
/*N*/
/*N*/     // counter for script info arrays
/*N*/     USHORT nCnt = 0;
/*N*/     // counter for compression information arrays
/*N*/     USHORT nCntComp = 0;
/*N*/ #ifdef BIDI
/*N*/     // counter for kashida array
/*N*/     USHORT nCntKash = 0;
/*N*/ #endif
/*N*/     BYTE nScript = 0;
/*N*/
/*N*/     const String& rTxt = rNode.GetTxt();
/*N*/
/*N*/     // compression type
/*N*/     const SwCharCompressType aCompEnum = rNode.GetDoc()->GetCharCompressType();
/*N*/
/*N*/ #ifdef BIDI
/*N*/     // justification type
/*N*/     const sal_Bool bAdjustBlock = SVX_ADJUST_BLOCK ==
/*N*/                                   rNode.GetSwAttrSet().GetAdjust().GetAdjust();
/*N*/ #endif
/*N*/
/*N*/
/*N*/     //
/*N*/     // FIND INVALID RANGES IN SCRIPT INFO ARRAYS:
/*N*/     //
/*N*/
/*N*/     if( nChg )
/*N*/   {
/*N*/         // if change position = 0 we do not use any data from the arrays
/*N*/         // because by deleting all characters of the first group at the beginning
/*N*/         // of a paragraph nScript is set to a wrong value
/*N*/         OSL_ENSURE( CountScriptChg(), "Where're my changes of script?" );
/*N*/       while( nCnt < CountScriptChg() )
/*N*/       {
/*N*/           if ( nChg <= GetScriptChg( nCnt ) )
/*N*/           {
/*N*/               nScript = GetScriptType( nCnt );
/*N*/               break;
/*N*/           }
/*N*/           else
/*N*/               nCnt++;
/*N*/       }
/*N*/         if( CHARCOMPRESS_NONE != aCompEnum )
/*N*/       {
/*N*/             while( nCntComp < CountCompChg() )
/*N*/           {
/*N*/               if ( nChg <= GetCompStart( nCntComp ) )
/*N*/                   break;
/*N*/               else
/*N*/                   nCntComp++;
/*N*/           }
/*N*/       }
/*N*/ #ifdef BIDI
/*N*/         if ( bAdjustBlock )
/*N*/         {
/*N*/             while( nCntKash < CountKashida() )
/*N*/             {
/*N*/                 if ( nChg <= GetKashida( nCntKash ) )
/*N*/                     break;
/*N*/                 else
/*N*/                     nCntKash++;
/*N*/             }
/*N*/         }
/*N*/ #endif
/*N*/   }
/*N*/   else
/*N*/         nScript = (BYTE)pBreakIt->xBreak->getScriptType( rTxt, 0 );
/*N*/
/*N*/
/*N*/     //
/*N*/     // ADJUST nChg VALUE:
/*N*/     //
/*N*/
/*N*/     // by stepping back one position we know that we are inside a group
/*N*/     // declared as an nScript group
/*N*/     if ( nChg )
/*N*/         --nChg;
/*N*/
/*N*/     const xub_StrLen nGrpStart = nCnt ? GetScriptChg( nCnt - 1 ) : 0;
/*N*/
/*N*/ #ifdef BIDI
/*N*/     // we go back in our group until we reach the first character of
/*N*/     // type nScript
/*N*/     while ( nChg > nGrpStart &&
/*N*/             nScript != pBreakIt->xBreak->getScriptType( rTxt, nChg ) )
/*N*/         --nChg;
/*N*/ #else
/*N*/     // we go back in our group until we reach a non-weak character
/*N*/     while ( nChg > nGrpStart &&
/*N*/             WEAK == pBreakIt->xBreak->getScriptType( rTxt, nChg ) )
/*N*/         --nChg;
/*N*/ #endif
/*N*/
/*N*/
/*N*/     //
/*N*/     // INVALID DATA FROM THE SCRIPT INFO ARRAYS HAS TO BE DELETED:
/*N*/     //
/*N*/
/*N*/     // remove invalid entries from script information arrays
/*N*/     const USHORT nScriptRemove = aScriptChg.Count() - nCnt;
/*N*/     aScriptChg.Remove( nCnt, nScriptRemove );
/*N*/     aScriptType.Remove( nCnt, nScriptRemove );
/*N*/
/*N*/     // get the start of the last compression group
/*N*/     USHORT nLastCompression = nChg;
/*N*/   if( nCntComp )
/*N*/   {
/*N*/       --nCntComp;
/*N*/         nLastCompression = GetCompStart( nCntComp );
/*N*/         if( nChg >= nLastCompression + GetCompLen( nCntComp ) )
/*N*/       {
/*N*/             nLastCompression = nChg;
/*N*/           ++nCntComp;
/*N*/       }
/*N*/     }
/*N*/
/*N*/     // remove invalid entries from compression information arrays
/*N*/     const USHORT nCompRemove = aCompChg.Count() - nCntComp;
/*N*/     aCompChg.Remove( nCntComp, nCompRemove );
/*N*/     aCompLen.Remove( nCntComp, nCompRemove );
/*N*/     aCompType.Remove( nCntComp, nCompRemove );
/*N*/
/*N*/ #ifdef BIDI
/*N*/     // get the start of the last kashida group
/*N*/     if( nCntKash && i18n::ScriptType::COMPLEX == nScript )
/*N*/         --nCntKash;
/*N*/
/*N*/     // remove invalid entries from kashida array
/*N*/     aKashida.Remove( nCntKash, aKashida.Count() - nCntKash );
/*N*/ #endif
/*N*/
/*N*/
/*N*/     //
/*N*/     // TAKE CARE OF WEAK CHARACTERS: WE MUST FIND AN APPROPRIATE
/*N*/     // SCRIPT FOR WEAK CHARACTERS AT THE BEGINNING OF A PARAGRAPH
/*N*/     //
/*N*/
/*N*/     if( WEAK == pBreakIt->xBreak->getScriptType( rTxt, nChg ) )
/*N*/   {
/*N*/         // If the beginning of the current group is weak, this means that
/*N*/         // all of the characters in this grounp are weak. We have to assign
/*N*/         // the scripts to these characters depending on the fonts which are
/*N*/         // set for these characters to display them.
/*N*/         xub_StrLen nEnd =
/*N*/                 (xub_StrLen)pBreakIt->xBreak->endOfScript( rTxt, nChg, WEAK );
/*N*/
/*N*/         if( nEnd > rTxt.Len() )
/*N*/             nEnd = rTxt.Len();
/*N*/
/*N*/         nScript = (BYTE)GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage() );
/*N*/
/*N*/         OSL_ENSURE( i18n::ScriptType::LATIN == nScript ||
/*N*/                 i18n::ScriptType::ASIAN == nScript ||
/*N*/                 i18n::ScriptType::COMPLEX == nScript, "Wrong default language" );
/*N*/
/*N*/         nChg = nEnd;
/*N*/         aScriptChg.Insert( nEnd, nCnt );
/*N*/         aScriptType.Insert( nScript, nCnt++ );
/*N*/
/*N*/         // Get next script type or set to weak in order to exit
/*N*/         nScript = ( nEnd < rTxt.Len() ) ?
/*N*/                   (BYTE)pBreakIt->xBreak->getScriptType( rTxt, nEnd ) :
/*N*/                   (BYTE)WEAK;
/*N*/     }
/*N*/
/*N*/     //
/*N*/     // UPDATE THE SCRIPT INFO ARRAYS:
/*N*/     //
/*N*/
/*N*/     // if there are only weak characters in paragraph we are finished
/*N*/     if ( WEAK == nScript )
/*N*/         return;
/*N*/
/*N*/     OSL_ENSURE( WEAK != (BYTE)pBreakIt->xBreak->getScriptType( rTxt, nChg ),
/*N*/             "Oh my god, it's weak again" );
/*N*/
/*N*/     do
/*N*/   {
/*N*/         OSL_ENSURE( i18n::ScriptType::WEAK != nScript,
/*N*/                 "Inserting WEAK into SwScriptInfo structure" );
/*N*/         OSL_ENSURE( STRING_LEN != nChg, "65K? Strange length of script section" );
/*N*/
/*N*/         nChg = (xub_StrLen)pBreakIt->xBreak->endOfScript( rTxt, nChg, nScript );
/*N*/
/*N*/         if ( nChg > rTxt.Len() )
/*N*/             nChg = rTxt.Len();
/*N*/
/*N*/         aScriptChg.Insert( nChg, nCnt );
/*N*/         aScriptType.Insert( nScript, nCnt++ );
/*N*/
/*N*/         // if current script is asian, we search for compressable characters
/*N*/         // in this range
/*N*/         if ( CHARCOMPRESS_NONE != aCompEnum &&
/*N*/              i18n::ScriptType::ASIAN == nScript )
/*N*/         {
/*?*/             BYTE ePrevState = NONE;
/*?*/             BYTE eState;
/*?*/             USHORT nPrevChg = nLastCompression;
/*?*/
/*?*/             while ( nLastCompression < nChg )
/*?*/             {
/*?*/                 xub_Unicode cChar = rTxt.GetChar( nLastCompression );
/*?*/
/*?*/                 // examine current character
/*?*/                 switch ( cChar )
/*?*/                 {
/*?*/                 // Left punctuation found
/*?*/                 case 0x3008: case 0x300A: case 0x300C: case 0x300E:
/*?*/                 case 0x3010: case 0x3014: case 0x3016: case 0x3018:
/*?*/                 case 0x301A: case 0x301D:
/*?*/                     eState = SPECIAL_LEFT;
/*?*/                     break;
/*?*/                 // Right punctuation found
/*?*/                 case 0x3001: case 0x3002: case 0x3009: case 0x300B:
/*?*/                 case 0x300D: case 0x300F: case 0x3011: case 0x3015:
/*?*/                 case 0x3017: case 0x3019: case 0x301B: case 0x301E:
/*?*/                 case 0x301F:
/*?*/                     eState = SPECIAL_RIGHT;
/*?*/                     break;
/*?*/                 default:
/*?*/                     eState = ( 0x3040 <= cChar && 0x3100 > cChar ) ?
/*?*/                                KANA :
/*?*/                                NONE;
/*?*/                 }
/*?*/
/*?*/                 // insert range of compressable characters
/*?*/                 if( ePrevState != eState )
/*?*/                 {
/*?*/                     if ( ePrevState != NONE )
/*?*/                     {
/*?*/                         // insert start and type
/*?*/                         if ( CHARCOMPRESS_PUNCTUATION_KANA == aCompEnum ||
/*?*/                              ePrevState != KANA )
/*?*/                         {
/*?*/                             aCompChg.Insert( nPrevChg, nCntComp );
/*?*/                             BYTE nTmpType = ePrevState;
/*?*/                             aCompType.Insert( nTmpType, nCntComp );
/*?*/                             aCompLen.Insert( nLastCompression - nPrevChg, nCntComp++ );
/*?*/                         }
/*?*/                     }
/*?*/
/*?*/                     ePrevState = eState;
/*?*/                     nPrevChg = nLastCompression;
/*?*/                 }
/*?*/
/*?*/                 nLastCompression++;
/*?*/             }
/*?*/
/*?*/             // we still have to examine last entry
/*?*/             if ( ePrevState != NONE )
/*?*/             {
/*?*/                 // insert start and type
/*?*/                 if ( CHARCOMPRESS_PUNCTUATION_KANA == aCompEnum ||
/*?*/                      ePrevState != KANA )
/*?*/                 {
/*?*/                     aCompChg.Insert( nPrevChg, nCntComp );
/*?*/                     BYTE nTmpType = ePrevState;
/*?*/                     aCompType.Insert( nTmpType, nCntComp );
/*?*/                     aCompLen.Insert( nLastCompression - nPrevChg, nCntComp++ );
/*?*/                 }
/*?*/             }
/*N*/         }
/*N*/
/*N*/         if ( nChg >= rTxt.Len() )
/*N*/             break;
/*N*/
/*N*/         nScript = (BYTE)pBreakIt->xBreak->getScriptType( rTxt, nChg );
/*N*/         nLastCompression = nChg;
/*N*/     } while ( TRUE );
/*N*/
/*N*/ #ifdef DBG_UTIL
/*N*/     // check kashida data
/*N*/     long nTmpKashidaPos = -1;
/*N*/     sal_Bool bWrongKash = sal_False;
/*N*/     for ( USHORT i = 0; i < aKashida.Count(); ++i )
/*N*/     {
/*N*/         long nCurrKashidaPos = GetKashida( i );
/*N*/         if ( nCurrKashidaPos <= nTmpKashidaPos )
/*N*/         {
/*N*/             bWrongKash = sal_True;
/*N*/             break;
/*N*/         }
/*N*/         nTmpKashidaPos = nCurrKashidaPos;
/*N*/     }
/*N*/     OSL_ENSURE( ! bWrongKash, "Kashida array contains wrong data" );
/*N*/ #endif
/*N*/
/*N*/     // remove invalid entries from direction information arrays
/*N*/     const USHORT nDirRemove = aDirChg.Count();
/*N*/     aDirChg.Remove( 0, nDirRemove );
/*N*/     aDirType.Remove( 0, nDirRemove );
/*N*/
/*N*/     // Perform Unicode Bidi Algorithm for text direction information
/*N*/     nCnt = 0;
/*N*/     sal_Bool bComplex = sal_False;
/*N*/
/*N*/     while( nCnt < CountScriptChg() )
/*N*/     {
/*N*/         nScript = GetScriptType( nCnt++ );
/*N*/         switch ( nScript )
/*N*/         {
/*N*/         case i18n::ScriptType::LATIN:
/*N*/         case i18n::ScriptType::ASIAN:
/*N*/             break;
/*N*/         case i18n::ScriptType::COMPLEX:
/*N*/             bComplex = sal_True;
/*N*/             break;
/*N*/         default:
/*N*/             OSL_ENSURE( ! rTxt.Len(), "Wrong script found" );
/*N*/         }
/*N*/     }
/*N*/
/*N*/     // do not call the unicode bidi algorithm if not required
/*N*/     if ( UBIDI_LTR != nDefaultDir || bComplex )
/*N*/         UpdateBidiInfo( rTxt );
/*N*/ }

/*N*/ void SwScriptInfo::UpdateBidiInfo( const String& rTxt )
/*N*/ {
/*N*/     // remove invalid entries from direction information arrays
/*N*/     const USHORT nDirRemove = aDirChg.Count();
/*N*/     aDirChg.Remove( 0, nDirRemove );
/*N*/     aDirType.Remove( 0, nDirRemove );
/*N*/
/*N*/     //
/*N*/     // Bidi functions from icu 2.0
/*N*/     //
/*N*/     UErrorCode nError = U_ZERO_ERROR;
/*N*/     UBiDi* pBidi = ubidi_openSized( rTxt.Len(), 0, &nError );
/*N*/     nError = U_ZERO_ERROR;
/*N*/
/*N*/     ubidi_setPara( pBidi, reinterpret_cast<const UChar *>(rTxt.GetBuffer()), rTxt.Len(),  // UChar != sal_Unicode in MinGW
/*N*/                    nDefaultDir, NULL, &nError );
/*N*/     nError = U_ZERO_ERROR;
/*N*/     long nCount = ubidi_countRuns( pBidi, &nError );
/*N*/     int32_t nStart = 0;
/*N*/     int32_t nEnd;
/*N*/     UBiDiLevel nCurrDir;
/*N*/     // counter for direction information arrays
/*N*/     USHORT nCntDir = 0;
/*N*/
/*N*/     for ( USHORT nIdx = 0; nIdx < nCount; ++nIdx )
/*N*/     {
/*N*/         ubidi_getLogicalRun( pBidi, nStart, &nEnd, &nCurrDir );
/*N*/         aDirChg.Insert( (USHORT)nEnd, nCntDir );
/*N*/         aDirType.Insert( (BYTE)nCurrDir, nCntDir++ );
/*N*/         nStart = nEnd;
/*N*/     }
/*N*/
/*N*/     ubidi_close( pBidi );
/*N*/ }


/*************************************************************************
 *                        SwScriptInfo::NextScriptChg(..)
 * returns the position of the next character which belongs to another script
 * than the character of the actual (input) position.
 * If there's no script change until the end of the paragraph, it will return
 * STRING_LEN.
 * Scripts are Asian (Chinese, Japanese, Korean),
 *             Latin ( English etc.)
 *         and Complex ( Hebrew, Arabian )
 *************************************************************************/

/*N*/ xub_StrLen SwScriptInfo::NextScriptChg( const xub_StrLen nPos )  const
/*N*/ {
/*N*/     USHORT nEnd = CountScriptChg();
/*N*/     for( USHORT nX = 0; nX < nEnd; ++nX )
/*N*/     {
/*N*/       if( nPos < GetScriptChg( nX ) )
/*N*/           return GetScriptChg( nX );
/*N*/     }
/*N*/
/*N*/   return STRING_LEN;
/*N*/ }

/*************************************************************************
 *                        SwScriptInfo::ScriptType(..)
 * returns the script of the character at the input position
 *************************************************************************/

/*N*/ BYTE SwScriptInfo::ScriptType( const xub_StrLen nPos ) const
/*N*/ {
/*N*/     USHORT nEnd = CountScriptChg();
/*N*/     for( USHORT nX = 0; nX < nEnd; ++nX )
/*N*/     {
/*N*/         if( nPos < GetScriptChg( nX ) )
/*N*/           return GetScriptType( nX );
/*N*/     }
/*N*/
/*N*/     // the default is the application language script
/*N*/     return (BYTE)GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage() );
/*N*/ }

#ifdef BIDI

/*N*/ xub_StrLen SwScriptInfo::NextDirChg( const xub_StrLen nPos,
/*N*/                                      const BYTE* pLevel )  const
/*N*/ {
/*N*/     BYTE nCurrDir = pLevel ? *pLevel : 62;
/*N*/     USHORT nEnd = CountDirChg();
/*N*/     for( USHORT nX = 0; nX < nEnd; ++nX )
/*N*/     {
/*N*/         if( nPos < GetDirChg( nX ) &&
/*N*/             ( nX + 1 == nEnd || GetDirType( nX + 1 ) <= nCurrDir ) )
/*?*/             return GetDirChg( nX );
/*N*/     }
/*N*/
/*N*/   return STRING_LEN;
/*N*/ }

#endif

/*************************************************************************
 *                      class SwParaPortion
 *************************************************************************/

/*N*/ SwParaPortion::SwParaPortion()
/*N*/ {
/*N*/   FormatReset();
/*N*/   bFlys = bFtnNum = bMargin = sal_False;
/*N*/   SetWhichPor( POR_PARA );
/*N*/ }

/*************************************************************************
 *                      SwParaPortion::GetParLen()
 *************************************************************************/

/*N*/ xub_StrLen SwParaPortion::GetParLen() const
/*N*/ {
/*N*/   xub_StrLen nLen = 0;
/*N*/   const SwLineLayout *pLay = this;
/*N*/   while( pLay )
/*N*/   {
///*N*/         DBG_LOOP;
/*N*/       nLen += pLay->GetLen();
/*N*/       pLay = pLay->GetNext();
/*N*/   }
/*N*/   return nLen;
/*N*/ }

/*************************************************************************
 *                      SwParaPortion::FindDropPortion()
 *************************************************************************/

/*N*/ const SwDropPortion *SwParaPortion::FindDropPortion() const
/*N*/ {
/*N*/   const SwLineLayout *pLay = this;
/*N*/   while( pLay && pLay->IsDummy() )
/*N*/       pLay = pLay->GetNext();
/*N*/   while( pLay )
/*N*/   {
/*N*/       const SwLinePortion *pPos = pLay->GetPortion();
/*N*/       while ( pPos && !pPos->GetLen() )
/*N*/           pPos = pPos->GetPortion();
/*N*/       if( pPos && pPos->IsDropPortion() )
/*N*/           return (SwDropPortion *)pPos;
/*N*/       pLay = pLay->GetLen() ? NULL : pLay->GetNext();
/*N*/   }
/*N*/   return NULL;
/*N*/ }

/*************************************************************************
 *                      SwLineLayout::Init()
 *************************************************************************/

/*N*/ void SwLineLayout::Init( SwLinePortion* pNextPortion )
/*N*/ {
/*N*/   Height( 0 );
/*N*/   Width( 0 );
/*N*/   SetLen( 0 );
/*N*/   SetAscent( 0 );
/*N*/     SetRealHeight( 0 );
/*N*/   SetPortion( pNextPortion );
/*N*/ }

/*--------------------------------------------------
 * HangingMargin()
 * looks for hanging punctuation portions in the paragraph
 * and return the maximum right offset of them.
 * If no such portion is found, the Margin/Hanging-flags will be atualized.
 * --------------------------------------------------*/

/*N*/ SwTwips SwLineLayout::_GetHangingMargin() const
/*N*/ {
/*N*/   SwLinePortion* pPor = GetPortion();
/*N*/   BOOL bFound = sal_False;
/*N*/   SwTwips nDiff = 0;
/*N*/   while( pPor)
/*N*/   {
/*N*/       if( pPor->IsHangingPortion() )
/*N*/       {
/*?*/           nDiff = ((SwHangingPortion*)pPor)->GetInnerWidth() - pPor->Width();
/*?*/           if( nDiff )
/*?*/               bFound = sal_True;
/*N*/       }
/*N*/         // the last post its portion
/*N*/         else if ( pPor->IsPostItsPortion() && ! pPor->GetPortion() )
/*N*/             nDiff = nAscent;
/*N*/
/*N*/         pPor = pPor->GetPortion();
/*N*/   }
/*N*/   if( !bFound ) // actualize the hanging-flag
/*N*/       ((SwLineLayout*)this)->SetHanging( sal_False );
/*N*/   return nDiff;
/*N*/ }

/*N*/ SwTwips SwTxtFrm::HangingMargin() const
/*N*/ {
/*N*/   OSL_ENSURE( HasPara(), "Don't call me without a paraportion" );
/*N*/   if( !GetPara()->IsMargin() )
/*N*/       return 0;
/*?*/   const SwLineLayout* pLine = GetPara();
/*?*/   SwTwips nRet = 0;
/*?*/   do
/*?*/   {
/*?*/       SwTwips nDiff = pLine->GetHangingMargin();
/*?*/       if( nDiff > nRet )
/*?*/           nRet = nDiff;
/*?*/       pLine = pLine->GetNext();
/*?*/   } while ( pLine );
/*?*/   if( !nRet ) // actualize the margin-flag
/*?*/       ((SwParaPortion*)GetPara())->SetMargin( sal_False );
/*?*/   return nRet;
/*N*/ }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */