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
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
|
/* -*- 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 .
*/
#include <vcl/outdev.hxx>
#include <pagefrm.hxx>
#include <rootfrm.hxx>
#include <pam.hxx>
#include <swfont.hxx>
#include <swregion.hxx>
#include <dflyobj.hxx>
#include <drawfont.hxx>
#include <flyfrm.hxx>
#include <flyfrms.hxx>
#include <fmtornt.hxx>
#include <frmatr.hxx>
#include <frmtool.hxx>
#include <ndtxt.hxx>
#include <txtfly.hxx>
#include "txtpaint.hxx"
#include <notxtfrm.hxx>
#include <fmtcnct.hxx>
#include <svx/obj3d.hxx>
#include <editeng/txtrange.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <fmtsrnd.hxx>
#include <fmtanchr.hxx>
#include <frmfmt.hxx>
#include <pagedesc.hxx>
#include <sortedobjs.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentSettingAccess.hxx>
#include <svx/svdoedge.hxx>
#ifdef DBG_UTIL
#include <viewsh.hxx>
#include <doc.hxx>
#endif
using namespace ::com::sun::star;
namespace
{
// #i68520#
struct AnchoredObjOrder
{
bool mbR2L;
SwRectFn mfnRect;
AnchoredObjOrder( const bool bR2L,
SwRectFn fnRect )
: mbR2L( bR2L ),
mfnRect( fnRect )
{}
bool operator()( const SwAnchoredObject* pListedAnchoredObj,
const SwAnchoredObject* pNewAnchoredObj )
{
const SwRect& aBoundRectOfListedObj( pListedAnchoredObj->GetObjRectWithSpaces() );
const SwRect& aBoundRectOfNewObj( pNewAnchoredObj->GetObjRectWithSpaces() );
if ( ( mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetRight)() ==
(aBoundRectOfNewObj.*mfnRect->fnGetRight)() ) ) ||
( !mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetLeft)() ==
(aBoundRectOfNewObj.*mfnRect->fnGetLeft)() ) ) )
{
SwTwips nTopDiff =
(*mfnRect->fnYDiff)( (aBoundRectOfNewObj.*mfnRect->fnGetTop)(),
(aBoundRectOfListedObj.*mfnRect->fnGetTop)() );
if ( nTopDiff == 0 &&
( ( mbR2L &&
( (aBoundRectOfNewObj.*mfnRect->fnGetLeft)() >
(aBoundRectOfListedObj.*mfnRect->fnGetLeft)() ) ) ||
( !mbR2L &&
( (aBoundRectOfNewObj.*mfnRect->fnGetRight)() <
(aBoundRectOfListedObj.*mfnRect->fnGetRight)() ) ) ) )
{
return true;
}
else if ( nTopDiff > 0 )
{
return true;
}
}
else if ( ( mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetRight)() >
(aBoundRectOfNewObj.*mfnRect->fnGetRight)() ) ) ||
( !mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetLeft)() <
(aBoundRectOfNewObj.*mfnRect->fnGetLeft)() ) ) )
{
return true;
}
return false;
}
};
}
SwContourCache::SwContourCache() :
nPntCnt( 0 )
{
}
SwContourCache::~SwContourCache()
{
}
void SwContourCache::ClrObject( sal_uInt16 nPos )
{
nPntCnt -= mvItems[ nPos ].mxTextRanger->GetPointCount();
mvItems.erase(mvItems.begin() + nPos);
}
void ClrContourCache( const SdrObject *pObj )
{
if( pContourCache && pObj )
for( sal_uInt16 i = 0; i < pContourCache->GetCount(); ++i )
if( pObj == pContourCache->GetObject( i ) )
{
pContourCache->ClrObject( i );
break;
}
}
void ClrContourCache()
{
if( pContourCache )
{
pContourCache->mvItems.clear();
pContourCache->nPntCnt = 0;
}
}
// #i68520#
SwRect SwContourCache::CalcBoundRect( const SwAnchoredObject* pAnchoredObj,
const SwRect &rLine,
const SwTextFrame* pFrame,
const long nXPos,
const bool bRight )
{
SwRect aRet;
const SwFrameFormat* pFormat = &(pAnchoredObj->GetFrameFormat());
bool bHandleContour(pFormat->GetSurround().IsContour());
if(!bHandleContour)
{
// RotateFlyFrame3: Object has no set contour, but for rotated
// FlyFrames we can create a 'default' contour to make text
// flow around the free, non-covered
const SwFlyFreeFrame* pSwFlyFreeFrame(dynamic_cast< const SwFlyFreeFrame* >(pAnchoredObj));
if(nullptr != pSwFlyFreeFrame && pSwFlyFreeFrame->supportsAutoContour())
{
bHandleContour = true;
}
}
if( bHandleContour &&
( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) == nullptr ||
( static_cast<const SwFlyFrame*>(pAnchoredObj)->Lower() &&
static_cast<const SwFlyFrame*>(pAnchoredObj)->Lower()->IsNoTextFrame() ) ) )
{
aRet = pAnchoredObj->GetObjRectWithSpaces();
if( aRet.IsOver( rLine ) )
{
if( !pContourCache )
pContourCache = new SwContourCache;
aRet = pContourCache->ContourRect(
pFormat, pAnchoredObj->GetDrawObj(), pFrame, rLine, nXPos, bRight );
}
else
aRet.Width( 0 );
}
else
{
aRet = pAnchoredObj->GetObjRectWithSpaces();
}
return aRet;
}
SwRect SwContourCache::ContourRect( const SwFormat* pFormat,
const SdrObject* pObj, const SwTextFrame* pFrame, const SwRect &rLine,
const long nXPos, const bool bRight )
{
SwRect aRet;
sal_uInt16 nPos = 0; // Search in the Cache
while( nPos < GetCount() && pObj != mvItems[ nPos ].mpSdrObj )
++nPos;
if( GetCount() == nPos ) // Not found
{
if( GetCount() == POLY_CNT )
{
nPntCnt -= mvItems.back().mxTextRanger->GetPointCount();
mvItems.pop_back();
}
::basegfx::B2DPolyPolygon aPolyPolygon;
std::unique_ptr<::basegfx::B2DPolyPolygon> pPolyPolygon;
if ( auto pVirtFlyDrawObj = dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) )
{
// GetContour() causes the graphic to be loaded, which may cause
// the graphic to change its size, call ClrObject()
tools::PolyPolygon aPoly;
if( !pVirtFlyDrawObj->GetFlyFrame()->GetContour( aPoly ) )
aPoly = tools::PolyPolygon( static_cast<const SwVirtFlyDrawObj*>(pObj)->
GetFlyFrame()->getFrameArea().SVRect() );
aPolyPolygon.clear();
aPolyPolygon.append(aPoly.getB2DPolyPolygon());
}
else
{
if( dynamic_cast< const E3dObject *>( pObj ) == nullptr )
{
aPolyPolygon = pObj->TakeXorPoly();
}
::basegfx::B2DPolyPolygon aContourPoly(pObj->TakeContour());
pPolyPolygon.reset(new ::basegfx::B2DPolyPolygon(aContourPoly));
}
const SvxLRSpaceItem &rLRSpace = pFormat->GetLRSpace();
const SvxULSpaceItem &rULSpace = pFormat->GetULSpace();
CacheItem item {
pObj, // due to #37347 the Object must be entered only after GetContour()
std::make_unique<TextRanger>( aPolyPolygon, pPolyPolygon.get(), 20,
static_cast<sal_uInt16>(rLRSpace.GetLeft()), static_cast<sal_uInt16>(rLRSpace.GetRight()),
pFormat->GetSurround().IsOutside(), false, pFrame->IsVertical() )
};
mvItems.insert(mvItems.begin(), std::move(item));
mvItems[0].mxTextRanger->SetUpper( rULSpace.GetUpper() );
mvItems[0].mxTextRanger->SetLower( rULSpace.GetLower() );
pPolyPolygon.reset();
nPntCnt += mvItems[0].mxTextRanger->GetPointCount();
while( nPntCnt > POLY_MAX && mvItems.size() > POLY_MIN )
{
nPntCnt -= mvItems.back().mxTextRanger->GetPointCount();
mvItems.pop_back();
}
}
else if( nPos )
{
CacheItem item = std::move(mvItems[nPos]);
mvItems.erase(mvItems.begin() + nPos);
mvItems.insert(mvItems.begin(), std::move(item));
}
SwRectFnSet aRectFnSet(pFrame);
long nTmpTop = aRectFnSet.GetTop(rLine);
// fnGetBottom is top + height
long nTmpBottom = aRectFnSet.GetBottom(rLine);
Range aRange( std::min( nTmpTop, nTmpBottom ), std::max( nTmpTop, nTmpBottom ) );
std::deque<long>* pTmp = mvItems[0].mxTextRanger->GetTextRanges( aRange );
const size_t nCount = pTmp->size();
if( 0 != nCount )
{
size_t nIdx = 0;
while( nIdx < nCount && (*pTmp)[ nIdx ] < nXPos )
++nIdx;
bool bOdd = nIdx % 2;
bool bSet = true;
if( bOdd )
--nIdx; // within interval
else if( ! bRight && ( nIdx >= nCount || (*pTmp)[ nIdx ] != nXPos ) )
{
if( nIdx )
nIdx -= 2; // an interval to the left
else
bSet = false; // before the first interval
}
if( bSet && nIdx < nCount )
{
aRectFnSet.SetTopAndHeight( aRet, aRectFnSet.GetTop(rLine),
aRectFnSet.GetHeight(rLine) );
aRectFnSet.SetLeft( aRet, (*pTmp)[ nIdx ] );
aRectFnSet.SetRight( aRet, (*pTmp)[ nIdx + 1 ] + 1 );
}
}
return aRet;
}
SwTextFly::SwTextFly()
: pPage(nullptr)
, mpCurrAnchoredObj(nullptr)
, m_pCurrFrame(nullptr)
, m_pMaster(nullptr)
, nMinBottom(0)
, nNextTop(0)
, m_nCurrFrameNodeIndex(0)
, bOn(false)
, bTopRule(false)
, mbIgnoreCurrentFrame(false)
, mbIgnoreContour(false)
, mbIgnoreObjsInHeaderFooter(false)
{
}
SwTextFly::SwTextFly( const SwTextFrame *pFrame )
{
CtorInitTextFly( pFrame );
}
SwTextFly::SwTextFly( const SwTextFly& rTextFly )
{
pPage = rTextFly.pPage;
mpCurrAnchoredObj = rTextFly.mpCurrAnchoredObj;
m_pCurrFrame = rTextFly.m_pCurrFrame;
m_pMaster = rTextFly.m_pMaster;
if( rTextFly.mpAnchoredObjList )
{
mpAnchoredObjList.reset( new SwAnchoredObjList( *(rTextFly.mpAnchoredObjList) ) );
}
bOn = rTextFly.bOn;
bTopRule = rTextFly.bTopRule;
nMinBottom = rTextFly.nMinBottom;
nNextTop = rTextFly.nNextTop;
m_nCurrFrameNodeIndex = rTextFly.m_nCurrFrameNodeIndex;
mbIgnoreCurrentFrame = rTextFly.mbIgnoreCurrentFrame;
mbIgnoreContour = rTextFly.mbIgnoreContour;
mbIgnoreObjsInHeaderFooter = rTextFly.mbIgnoreObjsInHeaderFooter;
}
SwTextFly::~SwTextFly()
{
}
void SwTextFly::CtorInitTextFly( const SwTextFrame *pFrame )
{
mbIgnoreCurrentFrame = false;
mbIgnoreContour = false;
mbIgnoreObjsInHeaderFooter = false;
pPage = pFrame->FindPageFrame();
const SwFlyFrame* pTmp = pFrame->FindFlyFrame();
// #i68520#
mpCurrAnchoredObj = pTmp;
m_pCurrFrame = pFrame;
m_pMaster = m_pCurrFrame->IsFollow() ? nullptr : m_pCurrFrame;
// If we're not overlapped by a frame or if a FlyCollection does not exist
// at all, we switch off forever.
// It could be, however, that a line is added while formatting, that
// extends into a frame.
// That's why we do not optimize for: bOn = pSortedFlys && IsAnyFrame();
bOn = pPage->GetSortedObjs() != nullptr;
bTopRule = true;
nMinBottom = 0;
nNextTop = 0;
m_nCurrFrameNodeIndex = ULONG_MAX;
}
SwRect SwTextFly::GetFrame_( const SwRect &rRect ) const
{
SwRect aRet;
if( ForEach( rRect, &aRet, true ) )
{
SwRectFnSet aRectFnSet(m_pCurrFrame);
aRectFnSet.SetTop( aRet, aRectFnSet.GetTop(rRect) );
// Do not always adapt the bottom
const SwTwips nRetBottom = aRectFnSet.GetBottom(aRet);
const SwTwips nRectBottom = aRectFnSet.GetBottom(rRect);
if ( aRectFnSet.YDiff( nRetBottom, nRectBottom ) > 0 ||
aRectFnSet.GetHeight(aRet) < 0 )
aRectFnSet.SetBottom( aRet, nRectBottom );
}
return aRet;
}
bool SwTextFly::IsAnyFrame() const
{
SwSwapIfSwapped swap(const_cast<SwTextFrame *>(m_pCurrFrame));
OSL_ENSURE( bOn, "IsAnyFrame: Why?" );
SwRect aRect(m_pCurrFrame->getFrameArea().Pos() + m_pCurrFrame->getFramePrintArea().Pos(),
m_pCurrFrame->getFramePrintArea().SSize());
return ForEach( aRect, nullptr, false );
}
bool SwTextFly::IsAnyObj( const SwRect &rRect ) const
{
OSL_ENSURE( bOn, "SwTextFly::IsAnyObj: Who's knocking?" );
SwRect aRect( rRect );
if ( aRect.IsEmpty() )
{
aRect = SwRect(m_pCurrFrame->getFrameArea().Pos() + m_pCurrFrame->getFramePrintArea().Pos(),
m_pCurrFrame->getFramePrintArea().SSize());
}
const SwSortedObjs *pSorted = pPage->GetSortedObjs();
if( pSorted ) // bOn actually makes sure that we have objects on the side,
// but who knows who deleted something in the meantime?
{
for ( size_t i = 0; i < pSorted->size(); ++i )
{
const SwAnchoredObject* pObj = (*pSorted)[i];
const SwRect aBound( pObj->GetObjRectWithSpaces() );
// Optimization
if( pObj->GetObjRect().Left() > aRect.Right() )
continue;
// #i68520#
if( mpCurrAnchoredObj != pObj && aBound.IsOver( aRect ) )
return true;
}
}
return false;
}
const SwTextFrame* SwTextFly::GetMaster_()
{
m_pMaster = m_pCurrFrame;
while (m_pMaster && m_pMaster->IsFollow())
m_pMaster = m_pMaster->FindMaster();
return m_pMaster;
}
void SwTextFly::DrawTextOpaque( SwDrawTextInfo &rInf )
{
SwSaveClip aClipSave( rInf.GetpOut() );
SwRect aRect( rInf.GetPos(), rInf.GetSize() );
if( rInf.GetSpace() )
{
TextFrameIndex const nTmpLen = TextFrameIndex(COMPLETE_STRING) == rInf.GetLen()
? TextFrameIndex(rInf.GetText().getLength())
: rInf.GetLen();
if( rInf.GetSpace() > 0 )
{
sal_Int32 nSpaceCnt = 0;
const TextFrameIndex nEndPos = rInf.GetIdx() + nTmpLen;
for (TextFrameIndex nPos = rInf.GetIdx(); nPos < nEndPos; ++nPos)
{
if (CH_BLANK == rInf.GetText()[sal_Int32(nPos)])
++nSpaceCnt;
}
if( nSpaceCnt )
aRect.Width( aRect.Width() + nSpaceCnt * rInf.GetSpace() );
}
else
aRect.Width( aRect.Width() - sal_Int32(nTmpLen) * rInf.GetSpace() );
}
if( aClipSave.IsOn() && rInf.GetOut().IsClipRegion() )
{
SwRect aClipRect( rInf.GetOut().GetClipRegion().GetBoundRect() );
aRect.Intersection( aClipRect );
}
SwRegionRects aRegion( aRect );
bool bOpaque = false;
// #i68520#
const sal_uInt32 nCurrOrd = mpCurrAnchoredObj
? mpCurrAnchoredObj->GetDrawObj()->GetOrdNum()
: SAL_MAX_UINT32;
OSL_ENSURE( !bTopRule, "DrawTextOpaque: Wrong TopRule" );
// #i68520#
const SwAnchoredObjList::size_type nCount( bOn ? GetAnchoredObjList()->size() : 0 );
if (nCount > 0)
{
const SdrLayerID nHellId = pPage->getRootFrame()->GetCurrShell()->getIDocumentDrawModelAccess().GetHellId();
for( SwAnchoredObjList::size_type i = 0; i < nCount; ++i )
{
// #i68520#
const SwAnchoredObject* pTmpAnchoredObj = (*mpAnchoredObjList)[i];
if( dynamic_cast<const SwFlyFrame*>(pTmpAnchoredObj) &&
mpCurrAnchoredObj != pTmpAnchoredObj )
{
// #i68520#
const SwFlyFrame& rFly = dynamic_cast<const SwFlyFrame&>(*pTmpAnchoredObj);
if( aRegion.GetOrigin().IsOver( rFly.getFrameArea() ) )
{
const SwFrameFormat *pFormat = rFly.GetFormat();
const SwFormatSurround &rSur = pFormat->GetSurround();
const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
// Only the ones who are opaque and more to the top
if( ! rFly.IsBackgroundTransparent() &&
css::text::WrapTextMode_THROUGH == rSur.GetSurround() &&
( !rSur.IsAnchorOnly() ||
// #i68520#
GetMaster() == rFly.GetAnchorFrame() ||
((RndStdIds::FLY_AT_PARA != rAnchor.GetAnchorId()) &&
(RndStdIds::FLY_AT_CHAR != rAnchor.GetAnchorId())
)
) &&
// #i68520#
pTmpAnchoredObj->GetDrawObj()->GetLayer() != nHellId &&
nCurrOrd < pTmpAnchoredObj->GetDrawObj()->GetOrdNum()
)
{
// Except for the content is transparent
const SwNoTextFrame *pNoText =
rFly.Lower() && rFly.Lower()->IsNoTextFrame()
? static_cast<const SwNoTextFrame*>(rFly.Lower())
: nullptr;
if ( !pNoText ||
(!pNoText->IsTransparent() && !rSur.IsContour()) )
{
bOpaque = true;
aRegion -= rFly.getFrameArea();
}
}
}
}
}
}
Point aPos( rInf.GetPos().X(), rInf.GetPos().Y() + rInf.GetAscent() );
const Point aOldPos(rInf.GetPos());
rInf.SetPos( aPos );
if( !bOpaque )
{
if( rInf.GetKern() )
rInf.GetFont()->DrawStretchText_( rInf );
else
rInf.GetFont()->DrawText_( rInf );
rInf.SetPos(aOldPos);
return;
}
else if( !aRegion.empty() )
{
// What a huge effort ...
SwSaveClip aClipVout( rInf.GetpOut() );
for( size_t i = 0; i < aRegion.size(); ++i )
{
SwRect &rRect = aRegion[i];
if( rRect != aRegion.GetOrigin() )
aClipVout.ChgClip( rRect );
if( rInf.GetKern() )
rInf.GetFont()->DrawStretchText_( rInf );
else
rInf.GetFont()->DrawText_( rInf );
}
}
rInf.SetPos(aOldPos);
}
void SwTextFly::DrawFlyRect( OutputDevice* pOut, const SwRect &rRect )
{
SwRegionRects aRegion( rRect );
OSL_ENSURE( !bTopRule, "DrawFlyRect: Wrong TopRule" );
// #i68520#
const SwAnchoredObjList::size_type nCount( bOn ? GetAnchoredObjList()->size() : 0 );
if (nCount > 0)
{
const SdrLayerID nHellId = pPage->getRootFrame()->GetCurrShell()->getIDocumentDrawModelAccess().GetHellId();
for( SwAnchoredObjList::size_type i = 0; i < nCount; ++i )
{
// #i68520#
const SwAnchoredObject* pAnchoredObjTmp = (*mpAnchoredObjList)[i];
if (mpCurrAnchoredObj == pAnchoredObjTmp)
continue;
// #i68520#
const SwFlyFrame* pFly = dynamic_cast<const SwFlyFrame*>(pAnchoredObjTmp);
if (pFly)
{
// #i68520#
const SwFormatSurround& rSur = pAnchoredObjTmp->GetFrameFormat().GetSurround();
// OD 24.01.2003 #106593# - correct clipping of fly frame area.
// Consider that fly frame background/shadow can be transparent
// and <SwAlignRect(..)> fly frame area
// #i47804# - consider transparent graphics
// and OLE objects.
bool bClipFlyArea =
( ( css::text::WrapTextMode_THROUGH == rSur.GetSurround() )
// #i68520#
? (pAnchoredObjTmp->GetDrawObj()->GetLayer() != nHellId)
: !rSur.IsContour() ) &&
!pFly->IsBackgroundTransparent() &&
( !pFly->Lower() ||
!pFly->Lower()->IsNoTextFrame() ||
!static_cast<const SwNoTextFrame*>(pFly->Lower())->IsTransparent() );
if ( bClipFlyArea )
{
// #i68520#
SwRect aFly( pAnchoredObjTmp->GetObjRect() );
// OD 24.01.2003 #106593#
::SwAlignRect( aFly, pPage->getRootFrame()->GetCurrShell(), pOut );
if( !aFly.IsEmpty() )
aRegion -= aFly;
}
}
}
}
for( size_t i = 0; i < aRegion.size(); ++i )
{
pOut->DrawRect( aRegion[i].SVRect() );
}
}
/**
* #i26945# - change first parameter
* Now it's the <SwAnchoredObject> instance of the floating screen object
*/
bool SwTextFly::GetTop( const SwAnchoredObject* _pAnchoredObj,
const bool bInFootnote,
const bool bInFooterOrHeader )
{
// #i68520#
// <mpCurrAnchoredObj> is set, if <m_pCurrFrame> is inside a fly frame
if( _pAnchoredObj != mpCurrAnchoredObj )
{
// #i26945#
const SdrObject* pNew = _pAnchoredObj->GetDrawObj();
// #102344# Ignore connectors which have one or more connections
if (const SdrEdgeObj* pEdgeObj = dynamic_cast<const SdrEdgeObj*>(pNew))
{
if (pEdgeObj->GetConnectedNode(true) || pEdgeObj->GetConnectedNode(false))
{
return false;
}
}
if( ( bInFootnote || bInFooterOrHeader ) && bTopRule )
{
// #i26945#
const SwFrameFormat& rFrameFormat = _pAnchoredObj->GetFrameFormat();
const SwFormatAnchor& rNewA = rFrameFormat.GetAnchor();
if (RndStdIds::FLY_AT_PAGE == rNewA.GetAnchorId())
{
if ( bInFootnote )
return false;
if ( bInFooterOrHeader )
{
const SwFormatVertOrient& aVert( rFrameFormat.GetVertOrient() );
bool bVertPrt = aVert.GetRelationOrient() == text::RelOrientation::PRINT_AREA ||
aVert.GetRelationOrient() == text::RelOrientation::PAGE_PRINT_AREA;
if( bVertPrt )
return false;
}
}
}
// #i68520#
// bEvade: consider pNew, if we are not inside a fly
// consider pNew, if pNew is lower of <mpCurrAnchoredObj>
bool bEvade = !mpCurrAnchoredObj ||
Is_Lower_Of( dynamic_cast<const SwFlyFrame*>(mpCurrAnchoredObj), pNew);
if ( !bEvade )
{
// We are currently inside a fly frame and pNew is not
// inside this fly frame. We can do some more checks if
// we have to consider pNew.
// If bTopRule is not set, we ignore the frame types.
// We directly check the z-order
if ( !bTopRule )
bEvade = true;
else
{
// Within chained Flys we only avoid Lower
// #i68520#
const SwFormatChain &rChain = mpCurrAnchoredObj->GetFrameFormat().GetChain();
if ( !rChain.GetPrev() && !rChain.GetNext() )
{
// #i26945#
const SwFormatAnchor& rNewA = _pAnchoredObj->GetFrameFormat().GetAnchor();
// #i68520#
const SwFormatAnchor& rCurrA = mpCurrAnchoredObj->GetFrameFormat().GetAnchor();
// If <mpCurrAnchoredObj> is anchored as character, its content
// does not wrap around pNew
if (RndStdIds::FLY_AS_CHAR == rCurrA.GetAnchorId())
return false;
// If pNew is anchored to page and <mpCurrAnchoredObj is not anchored
// to page, the content of <mpCurrAnchoredObj> does not wrap around pNew
// If both pNew and <mpCurrAnchoredObj> are anchored to page, we can do
// some more checks
if (RndStdIds::FLY_AT_PAGE == rNewA.GetAnchorId())
{
if (RndStdIds::FLY_AT_PAGE == rCurrA.GetAnchorId())
{
bEvade = true;
}
else
return false;
}
else if (RndStdIds::FLY_AT_PAGE == rCurrA.GetAnchorId())
return false; // Page anchored ones only avoid page anchored ones
else if (RndStdIds::FLY_AT_FLY == rNewA.GetAnchorId())
bEvade = true; // Non-page anchored ones avoid frame anchored ones
else if( RndStdIds::FLY_AT_FLY == rCurrA.GetAnchorId() )
return false; // Frame anchored ones do not avoid paragraph anchored ones
// #i57062#
// In order to avoid loop situation, it's decided to adjust
// the wrapping behaviour of content of at-paragraph/at-character
// anchored objects to one in the page header/footer and
// the document body --> content of at-paragraph/at-character
// anchored objects doesn't wrap around each other.
else
return false;
}
}
// But: we never avoid a subordinate one and additionally we only avoid when overlapping.
// #i68520#
bEvade &= ( mpCurrAnchoredObj->GetDrawObj()->GetOrdNum() < pNew->GetOrdNum() );
if( bEvade )
{
// #i68520#
const SwRect& aTmp( _pAnchoredObj->GetObjRectWithSpaces() );
if ( !aTmp.IsOver( mpCurrAnchoredObj->GetObjRectWithSpaces() ) )
bEvade = false;
}
}
if ( bEvade )
{
// #i26945#
const SwFormatAnchor& rNewA = _pAnchoredObj->GetFrameFormat().GetAnchor();
OSL_ENSURE( RndStdIds::FLY_AS_CHAR != rNewA.GetAnchorId(),
"Don't call GetTop with a FlyInContentFrame" );
if (RndStdIds::FLY_AT_PAGE == rNewA.GetAnchorId())
return true; // We always avoid page anchored ones
// If Flys anchored at paragraph are caught in a FlyCnt, then
// their influence ends at the borders of the FlyCnt!
// If we are currently formatting the text of the FlyCnt, then
// it has to get out of the way of the Frame anchored at paragraph!
// m_pCurrFrame is the anchor of pNew?
// #i26945#
const SwFrame* pTmp = _pAnchoredObj->GetAnchorFrame();
if (pTmp == m_pCurrFrame)
return true;
if( pTmp->IsTextFrame() && ( pTmp->IsInFly() || pTmp->IsInFootnote() ) )
{
// #i26945#
Point aPos = _pAnchoredObj->GetObjRect().Pos();
pTmp = GetVirtualUpper( pTmp, aPos );
}
// #i26945#
// If <pTmp> is a text frame inside a table, take the upper
// of the anchor frame, which contains the anchor position.
else if ( pTmp->IsTextFrame() && pTmp->IsInTab() )
{
pTmp = const_cast<SwAnchoredObject*>(_pAnchoredObj)
->GetAnchorFrameContainingAnchPos()->GetUpper();
}
// #i28701# - consider all objects in same context,
// if wrapping style is considered on object positioning.
// Thus, text will wrap around negative positioned objects.
// #i3317# - remove condition on checking,
// if wrappings style is considered on object positioning.
// Thus, text is wrapping around negative positioned objects.
// #i35640# - no consideration of negative
// positioned objects, if wrapping style isn't considered on
// object position and former text wrapping is applied.
// This condition is typically for documents imported from the
// OpenOffice.org file format.
const IDocumentSettingAccess* pIDSA = &m_pCurrFrame->GetDoc().getIDocumentSettingAccess();
if ( ( pIDSA->get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION) ||
!pIDSA->get(DocumentSettingId::USE_FORMER_TEXT_WRAPPING) ) &&
::FindContext( pTmp, SwFrameType::None ) == ::FindContext(m_pCurrFrame, SwFrameType::None))
{
return true;
}
const SwFrame* pHeader = nullptr;
if (m_pCurrFrame->GetNext() != pTmp &&
(IsFrameInSameContext( pTmp, m_pCurrFrame ) ||
// #i13832#, #i24135# wrap around objects in page header
( !pIDSA->get(DocumentSettingId::USE_FORMER_TEXT_WRAPPING) &&
nullptr != ( pHeader = pTmp->FindFooterOrHeader() ) &&
m_pCurrFrame->IsInDocBody())))
{
if( pHeader || RndStdIds::FLY_AT_FLY == rNewA.GetAnchorId() )
return true;
// Compare indices:
// The Index of the other is retrieved from the anchor attr.
sal_uLong nTmpIndex = rNewA.GetContentAnchor()->nNode.GetIndex();
// Now check whether the current paragraph is before the anchor
// of the displaced object in the text, then we don't have to
// get out of its way.
// If possible determine Index via SwFormatAnchor because
// otherwise it's quite expensive.
if (ULONG_MAX == m_nCurrFrameNodeIndex)
m_nCurrFrameNodeIndex = m_pCurrFrame->GetTextNodeFirst()->GetIndex();
if (FrameContainsNode(*m_pCurrFrame, nTmpIndex) || nTmpIndex < m_nCurrFrameNodeIndex)
return true;
}
}
}
return false;
}
// #i68520#
SwAnchoredObjList* SwTextFly::InitAnchoredObjList()
{
OSL_ENSURE( m_pCurrFrame, "InitFlyList: No Frame, no FlyList" );
// #i68520#
OSL_ENSURE( !mpAnchoredObjList, "InitFlyList: FlyList already initialized" );
SwSwapIfSwapped swap(const_cast<SwTextFrame *>(m_pCurrFrame));
const SwSortedObjs *pSorted = pPage->GetSortedObjs();
const size_t nCount = pSorted ? pSorted->size() : 0;
// --> #108724# Page header/footer content doesn't have to wrap around
// floating screen objects
const bool bFooterHeader = nullptr != m_pCurrFrame->FindFooterOrHeader();
const IDocumentSettingAccess* pIDSA = &m_pCurrFrame->GetDoc().getIDocumentSettingAccess();
// #i40155# - check, if frame is marked not to wrap
const bool bWrapAllowed = ( pIDSA->get(DocumentSettingId::USE_FORMER_TEXT_WRAPPING) ||
(!m_pCurrFrame->IsInFootnote() && !bFooterHeader));
bOn = false;
if( nCount && bWrapAllowed )
{
// #i68520#
mpAnchoredObjList.reset(new SwAnchoredObjList );
// #i28701# - consider complete frame area for new
// text wrapping
SwRect aRect;
if ( pIDSA->get(DocumentSettingId::USE_FORMER_TEXT_WRAPPING) )
{
aRect = m_pCurrFrame->getFramePrintArea();
aRect += m_pCurrFrame->getFrameArea().Pos();
}
else
{
aRect = m_pCurrFrame->getFrameArea();
}
// Make ourselves a little smaller than we are,
// so that 1-Twip-overlappings are ignored (#49532)
SwRectFnSet aRectFnSet(m_pCurrFrame);
const long nRight = aRectFnSet.GetRight(aRect) - 1;
const long nLeft = aRectFnSet.GetLeft(aRect) + 1;
const bool bR2L = m_pCurrFrame->IsRightToLeft();
const IDocumentDrawModelAccess& rIDDMA = m_pCurrFrame->GetDoc().getIDocumentDrawModelAccess();
for( size_t i = 0; i < nCount; ++i )
{
// #i68520#
// do not consider hidden objects
// check, if object has to be considered for text wrap
// #118809# - If requested, do not consider
// objects in page header|footer for text frames not in page
// header|footer. This is requested for the calculation of
// the base offset for objects <SwTextFrame::CalcBaseOfstForFly()>
// #i20505# Do not consider oversized objects
SwAnchoredObject* pAnchoredObj = (*pSorted)[ i ];
assert(pAnchoredObj);
if ( !pAnchoredObj ||
!rIDDMA.IsVisibleLayerId( pAnchoredObj->GetDrawObj()->GetLayer() ) ||
!pAnchoredObj->ConsiderForTextWrap() ||
( mbIgnoreObjsInHeaderFooter && !bFooterHeader &&
pAnchoredObj->GetAnchorFrame()->FindFooterOrHeader() ) )
{
continue;
}
const SwRect aBound( pAnchoredObj->GetObjRectWithSpaces() );
if ( nRight < aRectFnSet.GetLeft(aBound) ||
aRectFnSet.YDiff( aRectFnSet.GetTop(aRect),
aRectFnSet.GetBottom(aBound) ) > 0 ||
nLeft > aRectFnSet.GetRight(aBound) ||
aRectFnSet.GetHeight(aBound) >
2 * aRectFnSet.GetHeight(pPage->getFrameArea()) )
{
continue;
}
// #i26945# - pass <pAnchoredObj> to method
// <GetTop(..)> instead of only the <SdrObject> instance of the
// anchored object
if (GetTop(pAnchoredObj, m_pCurrFrame->IsInFootnote(), bFooterHeader))
{
// OD 11.03.2003 #107862# - adjust insert position:
// overlapping objects should be sorted from left to right and
// inside left to right sorting from top to bottom.
// If objects on the same position are found, they are sorted
// on its width.
// #i68520#
{
SwAnchoredObjList::iterator aInsPosIter =
std::lower_bound( mpAnchoredObjList->begin(),
mpAnchoredObjList->end(),
pAnchoredObj,
AnchoredObjOrder( bR2L, aRectFnSet.FnRect() ) );
mpAnchoredObjList->insert( aInsPosIter, pAnchoredObj );
}
const SwFormatSurround &rFlyFormat = pAnchoredObj->GetFrameFormat().GetSurround();
// #i68520#
if ( rFlyFormat.IsAnchorOnly() &&
pAnchoredObj->GetAnchorFrame() == GetMaster() )
{
const SwFormatVertOrient &rTmpFormat =
pAnchoredObj->GetFrameFormat().GetVertOrient();
if( text::VertOrientation::BOTTOM != rTmpFormat.GetVertOrient() )
nMinBottom = ( aRectFnSet.IsVert() && nMinBottom ) ?
std::min( nMinBottom, aBound.Left() ) :
std::max( nMinBottom, aRectFnSet.GetBottom(aBound) );
}
bOn = true;
}
}
if( nMinBottom )
{
SwTwips nMax = aRectFnSet.GetPrtBottom(*m_pCurrFrame->GetUpper());
if( aRectFnSet.YDiff( nMinBottom, nMax ) > 0 )
nMinBottom = nMax;
}
}
else
{
// #i68520#
mpAnchoredObjList.reset( new SwAnchoredObjList );
}
// #i68520#
return mpAnchoredObjList.get();
}
SwTwips SwTextFly::CalcMinBottom() const
{
SwTwips nRet = 0;
const SwContentFrame *pLclMaster = GetMaster();
OSL_ENSURE(pLclMaster, "SwTextFly without master");
const SwSortedObjs *pDrawObj = pLclMaster ? pLclMaster->GetDrawObjs() : nullptr;
const size_t nCount = pDrawObj ? pDrawObj->size() : 0;
if( nCount )
{
SwTwips nEndOfFrame = m_pCurrFrame->getFrameArea().Bottom();
for( size_t i = 0; i < nCount; ++i )
{
SwAnchoredObject* pAnchoredObj = (*pDrawObj)[ i ];
const SwFormatSurround &rFlyFormat = pAnchoredObj->GetFrameFormat().GetSurround();
if( rFlyFormat.IsAnchorOnly() )
{
const SwFormatVertOrient &rTmpFormat =
pAnchoredObj->GetFrameFormat().GetVertOrient();
if( text::VertOrientation::BOTTOM != rTmpFormat.GetVertOrient() )
{
const SwRect& aBound( pAnchoredObj->GetObjRectWithSpaces() );
if( aBound.Top() < nEndOfFrame )
nRet = std::max( nRet, aBound.Bottom() );
}
}
}
SwTwips nMax = m_pCurrFrame->GetUpper()->getFrameArea().Top() +
m_pCurrFrame->GetUpper()->getFramePrintArea().Bottom();
if( nRet > nMax )
nRet = nMax;
}
return nRet;
}
bool SwTextFly::ForEach( const SwRect &rRect, SwRect* pRect, bool bAvoid ) const
{
SwSwapIfSwapped swap(const_cast<SwTextFrame *>(m_pCurrFrame));
// Optimization
SwRectFnSet aRectFnSet(m_pCurrFrame);
// tdf#127235 stop if the area is larger than the page
if( aRectFnSet.GetHeight(pPage->getFrameArea()) < aRectFnSet.GetHeight(rRect))
{
// get the doc model description
const SwPageDesc* pPageDesc = pPage->GetPageDesc();
// if there is no next page style or it is the same as the current
// => stop trying to place the frame (it would end in an infinite loop)
if( pPageDesc &&
( !pPageDesc->GetFollow() || pPageDesc->GetFollow() == pPageDesc) )
{
return false;
}
}
bool bRet = false;
// #i68520#
const SwAnchoredObjList::size_type nCount( bOn ? GetAnchoredObjList()->size() : 0 );
if (nCount > 0)
{
for( SwAnchoredObjList::size_type i = 0; i < nCount; ++i )
{
// #i68520#
const SwAnchoredObject* pAnchoredObj = (*mpAnchoredObjList)[i];
SwRect aRect( pAnchoredObj->GetObjRectWithSpaces() );
if( aRectFnSet.GetLeft(aRect) > aRectFnSet.GetRight(rRect) )
break;
// #i68520#
if ( mpCurrAnchoredObj != pAnchoredObj && aRect.IsOver( rRect ) )
{
// #i68520#
const SwFormat* pFormat( &(pAnchoredObj->GetFrameFormat()) );
const SwFormatSurround &rSur = pFormat->GetSurround();
if( bAvoid )
{
// If the text flows below, it has no influence on
// formatting. In LineIter::DrawText() it is "just"
// necessary to cleverly set the ClippingRegions
const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
if( ( css::text::WrapTextMode_THROUGH == rSur.GetSurround() &&
( !rSur.IsAnchorOnly() ||
// #i68520#
GetMaster() == pAnchoredObj->GetAnchorFrame() ||
((RndStdIds::FLY_AT_PARA != rAnchor.GetAnchorId()) &&
(RndStdIds::FLY_AT_CHAR != rAnchor.GetAnchorId())) ) )
|| aRect.Top() == FAR_AWAY )
continue;
}
// #i58642#
// Compare <GetMaster()> instead of <m_pCurrFrame> with the
// anchor frame of the anchored object, because a follow frame
// has to ignore the anchored objects of its master frame.
// Note: Anchored objects are always registered at the master
// frame, exception are as-character anchored objects,
// but these aren't handled here.
// #i68520#
if ( mbIgnoreCurrentFrame &&
GetMaster() == pAnchoredObj->GetAnchorFrame() )
continue;
if( pRect )
{
// #i68520#
SwRect aFly = AnchoredObjToRect( pAnchoredObj, rRect );
if( aFly.IsEmpty() || !aFly.IsOver( rRect ) )
continue;
if( !bRet || (
(!m_pCurrFrame->IsRightToLeft() &&
( aRectFnSet.GetLeft(aFly) <
aRectFnSet.GetLeft(*pRect) ) ) ||
(m_pCurrFrame->IsRightToLeft() &&
( aRectFnSet.GetRight(aFly) >
aRectFnSet.GetRight(*pRect) ) ) ) )
*pRect = aFly;
if( rSur.IsContour() )
{
bRet = true;
continue;
}
}
bRet = true;
break;
}
}
}
return bRet;
}
// #i68520#
SwAnchoredObjList::size_type SwTextFly::GetPos( const SwAnchoredObject* pAnchoredObj ) const
{
SwAnchoredObjList::size_type nCount = GetAnchoredObjList()->size();
SwAnchoredObjList::size_type nRet = 0;
while ( nRet < nCount && pAnchoredObj != (*mpAnchoredObjList)[ nRet ] )
++nRet;
return nRet;
}
// #i68520#
void SwTextFly::CalcRightMargin( SwRect &rFly,
SwAnchoredObjList::size_type nFlyPos,
const SwRect &rLine ) const
{
// Usually the right margin is the right margin of the Printarea
OSL_ENSURE( !m_pCurrFrame->IsVertical() || !m_pCurrFrame->IsSwapped(),
"SwTextFly::CalcRightMargin with swapped frame" );
SwRectFnSet aRectFnSet(m_pCurrFrame);
// #118796# - correct determination of right of printing area
SwTwips nRight = aRectFnSet.GetPrtRight(*m_pCurrFrame);
SwTwips nFlyRight = aRectFnSet.GetRight(rFly);
SwRect aLine( rLine );
aRectFnSet.SetRight( aLine, nRight );
aRectFnSet.SetLeft( aLine, aRectFnSet.GetLeft(rFly) );
// It is possible that there is another object that is _above_ us
// and protrudes into the same line.
// Flys with run-through are invisible for those below, i.e., they
// are ignored for computing the margins of other Flys.
// 3301: pNext->getFrameArea().IsOver( rLine ) is necessary
// #i68520#
css::text::WrapTextMode eSurroundForTextWrap;
bool bStop = false;
// #i68520#
SwAnchoredObjList::size_type nPos = 0;
// #i68520#
while( nPos < mpAnchoredObjList->size() && !bStop )
{
if( nPos == nFlyPos )
{
++nPos;
continue;
}
// #i68520#
const SwAnchoredObject* pNext = (*mpAnchoredObjList)[ nPos++ ];
if ( pNext == mpCurrAnchoredObj )
continue;
eSurroundForTextWrap = GetSurroundForTextWrap( pNext );
if( css::text::WrapTextMode_THROUGH == eSurroundForTextWrap )
continue;
const SwRect aTmp( SwContourCache::CalcBoundRect
( pNext, aLine, m_pCurrFrame, nFlyRight, true ) );
SwTwips nTmpRight = aRectFnSet.GetRight(aTmp);
// optimization:
// Record in nNextTop at which Y-position frame related changes are
// likely. This is so that, despite only looking at frames in the
// current line height, for frames without wrap the line height is
// incremented so that with a single line the lower border of the frame
// (or possibly the upper border of another frame) is reached.
// Especially in HTML documents there are often (dummy) paragraphs in
// 2 pt font, and they used to only evade big frames after huge numbers
// of empty lines.
const long nTmpTop = aRectFnSet.GetTop(aTmp);
if( aRectFnSet.YDiff( nTmpTop, aRectFnSet.GetTop(aLine) ) > 0 )
{
if( aRectFnSet.YDiff( nNextTop, nTmpTop ) > 0 )
SetNextTop( nTmpTop ); // upper border of next frame
}
else if (!aRectFnSet.GetWidth(aTmp)) // typical for Objects with contour wrap
{ // For Objects with contour wrap that start before the current
// line, and end below it, but do not actually overlap it, the
// optimization has to be disabled, because the circumstances
// can change in the next line.
if( ! aRectFnSet.GetHeight(aTmp) ||
aRectFnSet.YDiff( aRectFnSet.GetBottom(aTmp),
aRectFnSet.GetTop(aLine) ) > 0 )
SetNextTop( 0 );
}
if( aTmp.IsOver( aLine ) && nTmpRight > nFlyRight )
{
nFlyRight = nTmpRight;
if( css::text::WrapTextMode_RIGHT == eSurroundForTextWrap ||
css::text::WrapTextMode_PARALLEL == eSurroundForTextWrap )
{
// overrule the FlyFrame
if( nRight > nFlyRight )
nRight = nFlyRight;
bStop = true;
}
}
}
aRectFnSet.SetRight( rFly, nRight );
}
// #i68520#
void SwTextFly::CalcLeftMargin( SwRect &rFly,
SwAnchoredObjList::size_type nFlyPos,
const SwRect &rLine ) const
{
OSL_ENSURE( !m_pCurrFrame->IsVertical() || !m_pCurrFrame->IsSwapped(),
"SwTextFly::CalcLeftMargin with swapped frame" );
SwRectFnSet aRectFnSet(m_pCurrFrame);
// #118796# - correct determination of left of printing area
SwTwips nLeft = aRectFnSet.GetPrtLeft(*m_pCurrFrame);
const SwTwips nFlyLeft = aRectFnSet.GetLeft(rFly);
if( nLeft > nFlyLeft )
nLeft = rFly.Left();
SwRect aLine( rLine );
aRectFnSet.SetLeft( aLine, nLeft );
// It is possible that there is another object that is _above_ us
// and protrudes into the same line.
// Flys with run-through are invisible for those below, i.e., they
// are ignored for computing the margins of other Flys.
// 3301: pNext->getFrameArea().IsOver( rLine ) is necessary
// #i68520#
SwAnchoredObjList::size_type nMyPos = nFlyPos;
while( ++nFlyPos < mpAnchoredObjList->size() )
{
// #i68520#
const SwAnchoredObject* pNext = (*mpAnchoredObjList)[ nFlyPos ];
const SwRect& aTmp( pNext->GetObjRectWithSpaces() );
if( aRectFnSet.GetLeft(aTmp) >= nFlyLeft )
break;
}
while( nFlyPos )
{
if( --nFlyPos == nMyPos )
continue;
// #i68520#
const SwAnchoredObject* pNext = (*mpAnchoredObjList)[ nFlyPos ];
if( pNext == mpCurrAnchoredObj )
continue;
css::text::WrapTextMode eSurroundForTextWrap = GetSurroundForTextWrap( pNext );
if( css::text::WrapTextMode_THROUGH == eSurroundForTextWrap )
continue;
const SwRect aTmp( SwContourCache::CalcBoundRect
(pNext, aLine, m_pCurrFrame, nFlyLeft, false) );
if( aRectFnSet.GetLeft(aTmp) < nFlyLeft && aTmp.IsOver( aLine ) )
{
// #118796# - no '+1', because <..fnGetRight>
// returns the correct value.
SwTwips nTmpRight = aRectFnSet.GetRight(aTmp);
if ( nLeft <= nTmpRight )
nLeft = nTmpRight;
break;
}
}
aRectFnSet.SetLeft( rFly, nLeft );
}
// #i68520#
SwRect SwTextFly::AnchoredObjToRect( const SwAnchoredObject* pAnchoredObj,
const SwRect &rLine ) const
{
SwRectFnSet aRectFnSet(m_pCurrFrame);
const long nXPos = m_pCurrFrame->IsRightToLeft() ?
rLine.Right() :
aRectFnSet.GetLeft(rLine);
SwRect aFly = mbIgnoreContour ?
pAnchoredObj->GetObjRectWithSpaces() :
SwContourCache::CalcBoundRect(pAnchoredObj, rLine, m_pCurrFrame,
nXPos, !m_pCurrFrame->IsRightToLeft());
if( !aFly.Width() )
return aFly;
// so the line may grow up to the lower edge of the frame
SetNextTop( aRectFnSet.GetBottom(aFly) );
SwAnchoredObjList::size_type nFlyPos = GetPos( pAnchoredObj );
// LEFT and RIGHT, we grow the rectangle.
// We have some problems, when several frames are to be seen.
// At the moment, only the easier case is assumed:
// + LEFT means that the text must flow on the left of the frame,
// that is the frame expands to the right edge of the print area
// or to the next frame.
// + RIGHT is the opposite.
// Otherwise the set distance between text and frame is always
// added up.
switch( GetSurroundForTextWrap( pAnchoredObj ) )
{
case css::text::WrapTextMode_LEFT :
{
CalcRightMargin( aFly, nFlyPos, rLine );
break;
}
case css::text::WrapTextMode_RIGHT :
{
CalcLeftMargin( aFly, nFlyPos, rLine );
break;
}
case css::text::WrapTextMode_NONE :
{
CalcRightMargin( aFly, nFlyPos, rLine );
CalcLeftMargin( aFly, nFlyPos, rLine );
break;
}
default:
break;
}
return aFly;
}
// #i68520#
// Wrap only on sides with at least 2cm space for the text
#define TEXT_MIN 1134
// MS Word wraps on sides with even less space (value guessed).
#define TEXT_MIN_SMALL 300
// Wrap on both sides up to a frame width of 1.5cm
#define FRAME_MAX 850
css::text::WrapTextMode SwTextFly::GetSurroundForTextWrap( const SwAnchoredObject* pAnchoredObj ) const
{
const SwFrameFormat* pFormat = &(pAnchoredObj->GetFrameFormat());
const SwFormatSurround &rFlyFormat = pFormat->GetSurround();
css::text::WrapTextMode eSurroundForTextWrap = rFlyFormat.GetSurround();
if( rFlyFormat.IsAnchorOnly() && pAnchoredObj->GetAnchorFrame() != GetMaster() )
{
const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
if ((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId()) ||
(RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()))
{
return css::text::WrapTextMode_NONE;
}
}
// in cause of run-through and nowrap ignore smartly
if( css::text::WrapTextMode_THROUGH == eSurroundForTextWrap ||
css::text::WrapTextMode_NONE == eSurroundForTextWrap )
return eSurroundForTextWrap;
// left is left and right is right
if (m_pCurrFrame->IsRightToLeft())
{
if ( css::text::WrapTextMode_LEFT == eSurroundForTextWrap )
eSurroundForTextWrap = css::text::WrapTextMode_RIGHT;
else if ( css::text::WrapTextMode_RIGHT == eSurroundForTextWrap )
eSurroundForTextWrap = css::text::WrapTextMode_LEFT;
}
// "ideal page wrap":
if ( css::text::WrapTextMode_DYNAMIC == eSurroundForTextWrap )
{
SwRectFnSet aRectFnSet(m_pCurrFrame);
const long nCurrLeft = aRectFnSet.GetPrtLeft(*m_pCurrFrame);
const long nCurrRight = aRectFnSet.GetPrtRight(*m_pCurrFrame);
const SwRect& aRect( pAnchoredObj->GetObjRectWithSpaces() );
long nFlyLeft = aRectFnSet.GetLeft(aRect);
long nFlyRight = aRectFnSet.GetRight(aRect);
if ( nFlyRight < nCurrLeft || nFlyLeft > nCurrRight )
eSurroundForTextWrap = css::text::WrapTextMode_PARALLEL;
else
{
long nLeft = nFlyLeft - nCurrLeft;
long nRight = nCurrRight - nFlyRight;
if( nFlyRight - nFlyLeft > FRAME_MAX )
{
if( nLeft < nRight )
nLeft = 0;
else
nRight = 0;
}
const int textMin = GetMaster()->GetDoc()
.getIDocumentSettingAccess().get(DocumentSettingId::SURROUND_TEXT_WRAP_SMALL )
? TEXT_MIN_SMALL : TEXT_MIN;
// In case there is no space on either side, then css::text::WrapTextMode_PARALLEL
// gives the same result when doing the initial layout or a layout
// update after editing, so prefer that over css::text::WrapTextMode_NONE.
if (nLeft == 0 && nRight == 0)
return css::text::WrapTextMode_PARALLEL;
if( nLeft < textMin )
nLeft = 0;
if( nRight < textMin )
nRight = 0;
if( nLeft )
eSurroundForTextWrap = nRight ? css::text::WrapTextMode_PARALLEL : css::text::WrapTextMode_LEFT;
else
eSurroundForTextWrap = nRight ? css::text::WrapTextMode_RIGHT: css::text::WrapTextMode_NONE;
}
}
return eSurroundForTextWrap;
}
bool SwTextFly::IsAnyFrame( const SwRect &rLine ) const
{
SwSwapIfSwapped swap(const_cast<SwTextFrame *>(m_pCurrFrame));
OSL_ENSURE( bOn, "IsAnyFrame: Why?" );
return ForEach( rLine, nullptr, false );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|