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
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
|
/* -*- 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 <svx/svdetc.hxx>
#include <svx/svdoutl.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdotext.hxx>
#include <svx/svdmodel.hxx>
#include <svx/textchain.hxx>
#include <svx/textchainflow.hxx>
#include <basegfx/vector/b2dvector.hxx>
#include <sdr/primitive2d/sdrtextprimitive2d.hxx>
#include <drawinglayer/primitive2d/textprimitive2d.hxx>
#include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
#include <basegfx/range/b2drange.hxx>
#include <editeng/editstat.hxx>
#include <tools/helpers.hxx>
#include <svx/sdtfchim.hxx>
#include <svl/itemset.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <drawinglayer/animation/animationtiming.hxx>
#include <basegfx/color/bcolor.hxx>
#include <vcl/svapp.hxx>
#include <editeng/eeitemid.hxx>
#include <editeng/escapementitem.hxx>
#include <editeng/svxenum.hxx>
#include <editeng/flditem.hxx>
#include <editeng/adjustitem.hxx>
#include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
#include <vcl/metaact.hxx>
#include <drawinglayer/primitive2d/wrongspellprimitive2d.hxx>
#include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
#include <svx/unoapi.hxx>
#include <drawinglayer/geometry/viewinformation2d.hxx>
#include <editeng/outlobj.hxx>
#include <editeng/editobj.hxx>
#include <editeng/overflowingtxt.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
using namespace com::sun::star;
// helpers
namespace
{
class impTextBreakupHandler
{
private:
drawinglayer::primitive2d::Primitive2DContainer maTextPortionPrimitives;
drawinglayer::primitive2d::Primitive2DContainer maLinePrimitives;
drawinglayer::primitive2d::Primitive2DContainer maParagraphPrimitives;
SdrOutliner& mrOutliner;
basegfx::B2DHomMatrix maNewTransformA;
basegfx::B2DHomMatrix maNewTransformB;
// the visible area for contour text decomposition
basegfx::B2DVector maScale;
// ClipRange for BlockText decomposition; only text portions completely
// inside are to be accepted, so this is different from geometric clipping
// (which would allow e.g. upper parts of portions to remain). Only used for
// BlockText (see there)
basegfx::B2DRange maClipRange;
DECL_LINK(decomposeContourTextPrimitive, DrawPortionInfo*, void);
DECL_LINK(decomposeBlockTextPrimitive, DrawPortionInfo*, void);
DECL_LINK(decomposeStretchTextPrimitive, DrawPortionInfo*, void);
DECL_LINK(decomposeContourBulletPrimitive, DrawBulletInfo*, void);
DECL_LINK(decomposeBlockBulletPrimitive, DrawBulletInfo*, void);
DECL_LINK(decomposeStretchBulletPrimitive, DrawBulletInfo*, void);
static bool impIsUnderlineAbove(const vcl::Font& rFont);
void impCreateTextPortionPrimitive(const DrawPortionInfo& rInfo);
static drawinglayer::primitive2d::BasePrimitive2D* impCheckFieldPrimitive(drawinglayer::primitive2d::BasePrimitive2D* pPrimitive, const DrawPortionInfo& rInfo);
void impFlushTextPortionPrimitivesToLinePrimitives();
void impFlushLinePrimitivesToParagraphPrimitives();
void impHandleDrawPortionInfo(const DrawPortionInfo& rInfo);
void impHandleDrawBulletInfo(const DrawBulletInfo& rInfo);
public:
explicit impTextBreakupHandler(SdrOutliner& rOutliner)
: maTextPortionPrimitives(),
maLinePrimitives(),
maParagraphPrimitives(),
mrOutliner(rOutliner),
maNewTransformA(),
maNewTransformB(),
maScale(),
maClipRange()
{
}
void decomposeContourTextPrimitive(const basegfx::B2DHomMatrix& rNewTransformA, const basegfx::B2DHomMatrix& rNewTransformB, const basegfx::B2DVector& rScale)
{
maScale = rScale;
maNewTransformA = rNewTransformA;
maNewTransformB = rNewTransformB;
mrOutliner.SetDrawPortionHdl(LINK(this, impTextBreakupHandler, decomposeContourTextPrimitive));
mrOutliner.SetDrawBulletHdl(LINK(this, impTextBreakupHandler, decomposeContourBulletPrimitive));
mrOutliner.StripPortions();
mrOutliner.SetDrawPortionHdl(Link<DrawPortionInfo*,void>());
mrOutliner.SetDrawBulletHdl(Link<DrawBulletInfo*,void>());
}
void decomposeBlockTextPrimitive(
const basegfx::B2DHomMatrix& rNewTransformA,
const basegfx::B2DHomMatrix& rNewTransformB,
const basegfx::B2DRange& rClipRange)
{
maNewTransformA = rNewTransformA;
maNewTransformB = rNewTransformB;
maClipRange = rClipRange;
mrOutliner.SetDrawPortionHdl(LINK(this, impTextBreakupHandler, decomposeBlockTextPrimitive));
mrOutliner.SetDrawBulletHdl(LINK(this, impTextBreakupHandler, decomposeBlockBulletPrimitive));
mrOutliner.StripPortions();
mrOutliner.SetDrawPortionHdl(Link<DrawPortionInfo*,void>());
mrOutliner.SetDrawBulletHdl(Link<DrawBulletInfo*,void>());
}
void decomposeStretchTextPrimitive(const basegfx::B2DHomMatrix& rNewTransformA, const basegfx::B2DHomMatrix& rNewTransformB)
{
maNewTransformA = rNewTransformA;
maNewTransformB = rNewTransformB;
mrOutliner.SetDrawPortionHdl(LINK(this, impTextBreakupHandler, decomposeStretchTextPrimitive));
mrOutliner.SetDrawBulletHdl(LINK(this, impTextBreakupHandler, decomposeStretchBulletPrimitive));
mrOutliner.StripPortions();
mrOutliner.SetDrawPortionHdl(Link<DrawPortionInfo*,void>());
mrOutliner.SetDrawBulletHdl(Link<DrawBulletInfo*,void>());
}
drawinglayer::primitive2d::Primitive2DContainer const & getPrimitive2DSequence();
};
bool impTextBreakupHandler::impIsUnderlineAbove(const vcl::Font& rFont)
{
if(!rFont.IsVertical())
{
return false;
}
if((LANGUAGE_JAPANESE == rFont.GetLanguage()) || (LANGUAGE_JAPANESE == rFont.GetCJKContextLanguage()))
{
// the underline is right for Japanese only
return true;
}
return false;
}
void impTextBreakupHandler::impCreateTextPortionPrimitive(const DrawPortionInfo& rInfo)
{
if(rInfo.maText.isEmpty() || !rInfo.mnTextLen)
return;
OUString caseMappedText = rInfo.mrFont.CalcCaseMap( rInfo.maText );
basegfx::B2DVector aFontScaling;
drawinglayer::attribute::FontAttribute aFontAttribute(
drawinglayer::primitive2d::getFontAttributeFromVclFont(
aFontScaling,
rInfo.mrFont,
rInfo.IsRTL(),
false));
basegfx::B2DHomMatrix aNewTransform;
// add font scale to new transform
aNewTransform.scale(aFontScaling.getX(), aFontScaling.getY());
// look for proportional font scaling, if necessary, scale accordingly
if(100 != rInfo.mrFont.GetPropr())
{
const double fFactor(rInfo.mrFont.GetPropr() / 100.0);
aNewTransform.scale(fFactor, fFactor);
}
// apply font rotate
if(rInfo.mrFont.GetOrientation())
{
aNewTransform.rotate(-rInfo.mrFont.GetOrientation() * F_PI1800);
}
// look for escapement, if necessary, translate accordingly
if(rInfo.mrFont.GetEscapement())
{
sal_Int16 nEsc(rInfo.mrFont.GetEscapement());
if(DFLT_ESC_AUTO_SUPER == nEsc)
{
nEsc = 33;
}
else if(DFLT_ESC_AUTO_SUB == nEsc)
{
nEsc = -20;
}
if(nEsc > 100)
{
nEsc = 100;
}
else if(nEsc < -100)
{
nEsc = -100;
}
const double fEscapement(nEsc / -100.0);
aNewTransform.translate(0.0, fEscapement * aFontScaling.getY());
}
// apply transformA
aNewTransform *= maNewTransformA;
// apply local offset
aNewTransform.translate(rInfo.mrStartPos.X(), rInfo.mrStartPos.Y());
// also apply embedding object's transform
aNewTransform *= maNewTransformB;
// prepare DXArray content. To make it independent from font size (and such from
// the text transformation), scale it to unit coordinates
::std::vector< double > aDXArray;
static bool bDisableTextArray(false);
if(!bDisableTextArray && rInfo.mpDXArray && rInfo.mnTextLen)
{
aDXArray.reserve(rInfo.mnTextLen);
for(sal_Int32 a=0; a < rInfo.mnTextLen; a++)
{
aDXArray.push_back((double)rInfo.mpDXArray[a]);
}
}
// create complex text primitive and append
const Color aFontColor(rInfo.mrFont.GetColor());
const basegfx::BColor aBFontColor(aFontColor.getBColor());
const Color aTextFillColor(rInfo.mrFont.GetFillColor());
// prepare wordLineMode (for underline and strikeout)
// NOT for bullet texts. It is set (this may be an error by itself), but needs to be suppressed to hinder e.g. '1)'
// to be split which would not look like the original
const bool bWordLineMode(rInfo.mrFont.IsWordLineMode() && !rInfo.mbEndOfBullet);
// prepare new primitive
drawinglayer::primitive2d::BasePrimitive2D* pNewPrimitive = nullptr;
const bool bDecoratedIsNeeded(
LINESTYLE_NONE != rInfo.mrFont.GetOverline()
|| LINESTYLE_NONE != rInfo.mrFont.GetUnderline()
|| STRIKEOUT_NONE != rInfo.mrFont.GetStrikeout()
|| FontEmphasisMark::NONE != (rInfo.mrFont.GetEmphasisMark() & FontEmphasisMark::Style)
|| FontRelief::NONE != rInfo.mrFont.GetRelief()
|| rInfo.mrFont.IsShadow()
|| bWordLineMode);
if(bDecoratedIsNeeded)
{
// TextDecoratedPortionPrimitive2D needed, prepare some more data
// get overline and underline color. If it's on automatic (0xffffffff) use FontColor instead
const Color aUnderlineColor(rInfo.maTextLineColor);
const basegfx::BColor aBUnderlineColor((0xffffffff == aUnderlineColor.GetColor()) ? aBFontColor : aUnderlineColor.getBColor());
const Color aOverlineColor(rInfo.maOverlineColor);
const basegfx::BColor aBOverlineColor((0xffffffff == aOverlineColor.GetColor()) ? aBFontColor : aOverlineColor.getBColor());
// prepare overline and underline data
const drawinglayer::primitive2d::TextLine eFontOverline(
drawinglayer::primitive2d::mapFontLineStyleToTextLine(rInfo.mrFont.GetOverline()));
const drawinglayer::primitive2d::TextLine eFontLineStyle(
drawinglayer::primitive2d::mapFontLineStyleToTextLine(rInfo.mrFont.GetUnderline()));
// check UnderlineAbove
const bool bUnderlineAbove(
drawinglayer::primitive2d::TEXT_LINE_NONE != eFontLineStyle && impIsUnderlineAbove(rInfo.mrFont));
// prepare strikeout data
const drawinglayer::primitive2d::TextStrikeout eTextStrikeout(
drawinglayer::primitive2d::mapFontStrikeoutToTextStrikeout(rInfo.mrFont.GetStrikeout()));
// prepare emphasis mark data
drawinglayer::primitive2d::TextEmphasisMark eTextEmphasisMark(drawinglayer::primitive2d::TEXT_FONT_EMPHASIS_MARK_NONE);
switch(rInfo.mrFont.GetEmphasisMark() & FontEmphasisMark::Style)
{
case FontEmphasisMark::Dot : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_FONT_EMPHASIS_MARK_DOT; break;
case FontEmphasisMark::Circle : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_FONT_EMPHASIS_MARK_CIRCLE; break;
case FontEmphasisMark::Disc : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_FONT_EMPHASIS_MARK_DISC; break;
case FontEmphasisMark::Accent : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_FONT_EMPHASIS_MARK_ACCENT; break;
default: break;
}
const bool bEmphasisMarkAbove(rInfo.mrFont.GetEmphasisMark() & FontEmphasisMark::PosAbove);
const bool bEmphasisMarkBelow(rInfo.mrFont.GetEmphasisMark() & FontEmphasisMark::PosBelow);
// prepare font relief data
drawinglayer::primitive2d::TextRelief eTextRelief(drawinglayer::primitive2d::TEXT_RELIEF_NONE);
switch(rInfo.mrFont.GetRelief())
{
case FontRelief::Embossed : eTextRelief = drawinglayer::primitive2d::TEXT_RELIEF_EMBOSSED; break;
case FontRelief::Engraved : eTextRelief = drawinglayer::primitive2d::TEXT_RELIEF_ENGRAVED; break;
default : break; // RELIEF_NONE, FontRelief_FORCE_EQUAL_SIZE
}
// prepare shadow/outline data
const bool bShadow(rInfo.mrFont.IsShadow());
// TextDecoratedPortionPrimitive2D is needed, create one
pNewPrimitive = new drawinglayer::primitive2d::TextDecoratedPortionPrimitive2D(
// attributes for TextSimplePortionPrimitive2D
aNewTransform,
caseMappedText,
rInfo.mnTextStart,
rInfo.mnTextLen,
aDXArray,
aFontAttribute,
rInfo.mpLocale ? *rInfo.mpLocale : css::lang::Locale(),
aBFontColor,
aTextFillColor,
// attributes for TextDecoratedPortionPrimitive2D
aBOverlineColor,
aBUnderlineColor,
eFontOverline,
eFontLineStyle,
bUnderlineAbove,
eTextStrikeout,
bWordLineMode,
eTextEmphasisMark,
bEmphasisMarkAbove,
bEmphasisMarkBelow,
eTextRelief,
bShadow);
}
else
{
// TextSimplePortionPrimitive2D is enough
pNewPrimitive = new drawinglayer::primitive2d::TextSimplePortionPrimitive2D(
aNewTransform,
caseMappedText,
rInfo.mnTextStart,
rInfo.mnTextLen,
aDXArray,
aFontAttribute,
rInfo.mpLocale ? *rInfo.mpLocale : css::lang::Locale(),
aBFontColor,
rInfo.mbFilled,
rInfo.mnWidthToFill,
aTextFillColor);
}
if(rInfo.mbEndOfBullet)
{
// embed in TextHierarchyBulletPrimitive2D
const drawinglayer::primitive2d::Primitive2DReference aNewReference(pNewPrimitive);
const drawinglayer::primitive2d::Primitive2DContainer aNewSequence { aNewReference } ;
pNewPrimitive = new drawinglayer::primitive2d::TextHierarchyBulletPrimitive2D(aNewSequence);
}
if(rInfo.mpFieldData)
{
pNewPrimitive = impCheckFieldPrimitive(pNewPrimitive, rInfo);
}
maTextPortionPrimitives.push_back(pNewPrimitive);
// support for WrongSpellVector. Create WrongSpellPrimitives as needed
if(rInfo.mpWrongSpellVector && !aDXArray.empty())
{
const sal_Int32 nSize(rInfo.mpWrongSpellVector->size());
const sal_Int32 nDXCount(aDXArray.size());
const basegfx::BColor aSpellColor(1.0, 0.0, 0.0); // red, hard coded
for(sal_Int32 a(0); a < nSize; a++)
{
const EEngineData::WrongSpellClass& rCandidate = (*rInfo.mpWrongSpellVector)[a];
if(rCandidate.nStart >= rInfo.mnTextStart && rCandidate.nEnd >= rInfo.mnTextStart && rCandidate.nEnd > rCandidate.nStart)
{
const sal_Int32 nStart(rCandidate.nStart - rInfo.mnTextStart);
const sal_Int32 nEnd(rCandidate.nEnd - rInfo.mnTextStart);
double fStart(0.0);
double fEnd(0.0);
if(nStart > 0 && nStart - 1 < nDXCount)
{
fStart = aDXArray[nStart - 1];
}
if(nEnd > 0 && nEnd - 1 < nDXCount)
{
fEnd = aDXArray[nEnd - 1];
}
if(!basegfx::fTools::equal(fStart, fEnd))
{
if(rInfo.IsRTL())
{
// #i98523#
// When the portion is RTL, mirror the redlining using the
// full portion width
const double fTextWidth(aDXArray[aDXArray.size() - 1]);
fStart = fTextWidth - fStart;
fEnd = fTextWidth - fEnd;
}
// need to take FontScaling out of values; it's already part of
// aNewTransform and would be double applied
const double fFontScaleX(aFontScaling.getX());
if(!basegfx::fTools::equal(fFontScaleX, 1.0)
&& !basegfx::fTools::equalZero(fFontScaleX))
{
fStart /= fFontScaleX;
fEnd /= fFontScaleX;
}
maTextPortionPrimitives.push_back(new drawinglayer::primitive2d::WrongSpellPrimitive2D(
aNewTransform,
fStart,
fEnd,
aSpellColor));
}
}
}
}
}
drawinglayer::primitive2d::BasePrimitive2D* impTextBreakupHandler::impCheckFieldPrimitive(drawinglayer::primitive2d::BasePrimitive2D* pPrimitive, const DrawPortionInfo& rInfo)
{
if(rInfo.mpFieldData)
{
// Support for FIELD_SEQ_BEGIN, FIELD_SEQ_END. If used, create a TextHierarchyFieldPrimitive2D
// which holds the field type and, if applicable, the URL
const SvxURLField* pURLField = dynamic_cast< const SvxURLField* >(rInfo.mpFieldData);
const SvxPageField* pPageField = dynamic_cast< const SvxPageField* >(rInfo.mpFieldData);
// embed current primitive to a sequence
drawinglayer::primitive2d::Primitive2DContainer aSequence;
if(pPrimitive)
{
aSequence.resize(1);
aSequence[0] = drawinglayer::primitive2d::Primitive2DReference(pPrimitive);
}
if(pURLField)
{
// extended this to hold more of the contents of the original
// SvxURLField since that stuff is still used in HitTest and e.g. Calc
std::vector< std::pair< OUString, OUString>> meValues;
meValues.emplace_back("URL", pURLField->GetURL());
meValues.emplace_back("Representation", pURLField->GetRepresentation());
meValues.emplace_back("TargetFrame", pURLField->GetTargetFrame());
meValues.emplace_back("SvxURLFormat", OUString::number(static_cast<sal_uInt16>(pURLField->GetFormat())));
pPrimitive = new drawinglayer::primitive2d::TextHierarchyFieldPrimitive2D(aSequence, drawinglayer::primitive2d::FIELD_TYPE_URL, &meValues);
}
else if(pPageField)
{
pPrimitive = new drawinglayer::primitive2d::TextHierarchyFieldPrimitive2D(aSequence, drawinglayer::primitive2d::FIELD_TYPE_PAGE);
}
else
{
pPrimitive = new drawinglayer::primitive2d::TextHierarchyFieldPrimitive2D(aSequence, drawinglayer::primitive2d::FIELD_TYPE_COMMON);
}
}
return pPrimitive;
}
void impTextBreakupHandler::impFlushTextPortionPrimitivesToLinePrimitives()
{
// only create a line primitive when we had content; there is no need for
// empty line primitives (contrary to paragraphs, see below).
if(!maTextPortionPrimitives.empty())
{
maLinePrimitives.push_back(new drawinglayer::primitive2d::TextHierarchyLinePrimitive2D(maTextPortionPrimitives));
maTextPortionPrimitives.clear();
}
}
void impTextBreakupHandler::impFlushLinePrimitivesToParagraphPrimitives()
{
// ALWAYS create a paragraph primitive, even when no content was added. This is done to
// have the correct paragraph count even with empty paragraphs. Those paragraphs will
// have an empty sub-PrimitiveSequence.
maParagraphPrimitives.push_back(new drawinglayer::primitive2d::TextHierarchyParagraphPrimitive2D(maLinePrimitives));
maLinePrimitives.clear();
}
void impTextBreakupHandler::impHandleDrawPortionInfo(const DrawPortionInfo& rInfo)
{
impCreateTextPortionPrimitive(rInfo);
if(rInfo.mbEndOfLine || rInfo.mbEndOfParagraph)
{
impFlushTextPortionPrimitivesToLinePrimitives();
}
if(rInfo.mbEndOfParagraph)
{
impFlushLinePrimitivesToParagraphPrimitives();
}
}
void impTextBreakupHandler::impHandleDrawBulletInfo(const DrawBulletInfo& rInfo)
{
basegfx::B2DHomMatrix aNewTransform;
// add size to new transform
aNewTransform.scale(rInfo.maBulletSize.getWidth(), rInfo.maBulletSize.getHeight());
// apply transformA
aNewTransform *= maNewTransformA;
// apply local offset
aNewTransform.translate(rInfo.maBulletPosition.X(), rInfo.maBulletPosition.Y());
// also apply embedding object's transform
aNewTransform *= maNewTransformB;
// prepare empty GraphicAttr
const GraphicAttr aGraphicAttr;
// create GraphicPrimitive2D
const drawinglayer::primitive2d::Primitive2DReference aNewReference(new drawinglayer::primitive2d::GraphicPrimitive2D(
aNewTransform,
rInfo.maBulletGraphicObject,
aGraphicAttr));
// embed in TextHierarchyBulletPrimitive2D
const drawinglayer::primitive2d::Primitive2DContainer aNewSequence { aNewReference };
drawinglayer::primitive2d::BasePrimitive2D* pNewPrimitive = new drawinglayer::primitive2d::TextHierarchyBulletPrimitive2D(aNewSequence);
// add to output
maTextPortionPrimitives.push_back(pNewPrimitive);
}
IMPL_LINK(impTextBreakupHandler, decomposeContourTextPrimitive, DrawPortionInfo*, pInfo, void)
{
// for contour text, ignore (clip away) all portions which are below
// the visible area given by maScale
if(pInfo && (double)pInfo->mrStartPos.Y() < maScale.getY())
{
impHandleDrawPortionInfo(*pInfo);
}
}
IMPL_LINK(impTextBreakupHandler, decomposeBlockTextPrimitive, DrawPortionInfo*, pInfo, void)
{
if(pInfo)
{
// Is clipping wanted? This is text clipping; only accept a portion
// if it's completely in the range
if(!maClipRange.isEmpty())
{
// Test start position first; this allows to not get the text range at
// all if text is far outside
const basegfx::B2DPoint aStartPosition(pInfo->mrStartPos.X(), pInfo->mrStartPos.Y());
if(!maClipRange.isInside(aStartPosition))
{
return;
}
// Start position is inside. Get TextBoundRect and TopLeft next
drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
aTextLayouterDevice.setFont(pInfo->mrFont);
const basegfx::B2DRange aTextBoundRect(
aTextLayouterDevice.getTextBoundRect(
pInfo->maText, pInfo->mnTextStart, pInfo->mnTextLen));
const basegfx::B2DPoint aTopLeft(aTextBoundRect.getMinimum() + aStartPosition);
if(!maClipRange.isInside(aTopLeft))
{
return;
}
// TopLeft is inside. Get BottomRight and check
const basegfx::B2DPoint aBottomRight(aTextBoundRect.getMaximum() + aStartPosition);
if(!maClipRange.isInside(aBottomRight))
{
return;
}
// all inside, clip was successful
}
impHandleDrawPortionInfo(*pInfo);
}
}
IMPL_LINK(impTextBreakupHandler, decomposeStretchTextPrimitive, DrawPortionInfo*, pInfo, void)
{
if(pInfo)
{
impHandleDrawPortionInfo(*pInfo);
}
}
IMPL_LINK(impTextBreakupHandler, decomposeContourBulletPrimitive, DrawBulletInfo*, pInfo, void)
{
if(pInfo)
{
impHandleDrawBulletInfo(*pInfo);
}
}
IMPL_LINK(impTextBreakupHandler, decomposeBlockBulletPrimitive, DrawBulletInfo*, pInfo, void)
{
if(pInfo)
{
impHandleDrawBulletInfo(*pInfo);
}
}
IMPL_LINK(impTextBreakupHandler, decomposeStretchBulletPrimitive, DrawBulletInfo*, pInfo, void)
{
if(pInfo)
{
impHandleDrawBulletInfo(*pInfo);
}
}
drawinglayer::primitive2d::Primitive2DContainer const & impTextBreakupHandler::getPrimitive2DSequence()
{
if(!maTextPortionPrimitives.empty())
{
// collect non-closed lines
impFlushTextPortionPrimitivesToLinePrimitives();
}
if(!maLinePrimitives.empty())
{
// collect non-closed paragraphs
impFlushLinePrimitivesToParagraphPrimitives();
}
return maParagraphPrimitives;
}
} // end of anonymous namespace
// primitive decompositions
void SdrTextObj::impDecomposeContourTextPrimitive(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
const drawinglayer::primitive2d::SdrContourTextPrimitive2D& rSdrContourTextPrimitive,
const drawinglayer::geometry::ViewInformation2D& aViewInformation) const
{
// decompose matrix to have position and size of text
basegfx::B2DVector aScale, aTranslate;
double fRotate, fShearX;
rSdrContourTextPrimitive.getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
// prepare contour polygon, force to non-mirrored for laying out
basegfx::B2DPolyPolygon aPolyPolygon(rSdrContourTextPrimitive.getUnitPolyPolygon());
aPolyPolygon.transform(basegfx::utils::createScaleB2DHomMatrix(fabs(aScale.getX()), fabs(aScale.getY())));
// prepare outliner
SolarMutexGuard aSolarGuard;
SdrOutliner& rOutliner = ImpGetDrawOutliner();
const Size aNullSize;
rOutliner.SetPaperSize(aNullSize);
rOutliner.SetPolygon(aPolyPolygon);
rOutliner.SetUpdateMode(true);
rOutliner.SetText(rSdrContourTextPrimitive.getOutlinerParaObject());
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
// prepare matrices to apply to newly created primitives
basegfx::B2DHomMatrix aNewTransformA;
// mirroring. We are now in the polygon sizes. When mirroring in X and Y,
// move the null point which was top left to bottom right.
const bool bMirrorX(basegfx::fTools::less(aScale.getX(), 0.0));
const bool bMirrorY(basegfx::fTools::less(aScale.getY(), 0.0));
// in-between the translations of the single primitives will take place. Afterwards,
// the object's transformations need to be applied
const basegfx::B2DHomMatrix aNewTransformB(basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
bMirrorX ? -1.0 : 1.0, bMirrorY ? -1.0 : 1.0,
fShearX, fRotate, aTranslate.getX(), aTranslate.getY()));
// now break up text primitives.
impTextBreakupHandler aConverter(rOutliner);
aConverter.decomposeContourTextPrimitive(aNewTransformA, aNewTransformB, aScale);
// cleanup outliner
rOutliner.Clear();
rOutliner.setVisualizedPage(nullptr);
rTarget = aConverter.getPrimitive2DSequence();
}
void SdrTextObj::impDecomposeAutoFitTextPrimitive(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
const drawinglayer::primitive2d::SdrAutoFitTextPrimitive2D& rSdrAutofitTextPrimitive,
const drawinglayer::geometry::ViewInformation2D& aViewInformation) const
{
// decompose matrix to have position and size of text
basegfx::B2DVector aScale, aTranslate;
double fRotate, fShearX;
rSdrAutofitTextPrimitive.getTextRangeTransform().decompose(aScale, aTranslate, fRotate, fShearX);
// use B2DRange aAnchorTextRange for calculations
basegfx::B2DRange aAnchorTextRange(aTranslate);
aAnchorTextRange.expand(aTranslate + aScale);
// prepare outliner
const SfxItemSet& rTextItemSet = rSdrAutofitTextPrimitive.getSdrText()->GetItemSet();
SolarMutexGuard aSolarGuard;
SdrOutliner& rOutliner = ImpGetDrawOutliner();
SdrTextVertAdjust eVAdj = GetTextVerticalAdjust(rTextItemSet);
SdrTextHorzAdjust eHAdj = GetTextHorizontalAdjust(rTextItemSet);
const EEControlBits nOriginalControlWord(rOutliner.GetControlWord());
const Size aNullSize;
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
rOutliner.SetControlWord(nOriginalControlWord|EEControlBits::AUTOPAGESIZE|EEControlBits::STRETCHING);
rOutliner.SetMinAutoPaperSize(aNullSize);
rOutliner.SetMaxAutoPaperSize(Size(1000000,1000000));
// add one to rage sizes to get back to the old Rectangle and outliner measurements
const sal_uInt32 nAnchorTextWidth(FRound(aAnchorTextRange.getWidth() + 1));
const sal_uInt32 nAnchorTextHeight(FRound(aAnchorTextRange.getHeight() + 1));
const OutlinerParaObject* pOutlinerParaObject = rSdrAutofitTextPrimitive.getSdrText()->GetOutlinerParaObject();
OSL_ENSURE(pOutlinerParaObject, "impDecomposeBlockTextPrimitive used with no OutlinerParaObject (!)");
const bool bVerticalWriting(pOutlinerParaObject->IsVertical());
const bool bTopToBottom(pOutlinerParaObject->IsTopToBottom());
const Size aAnchorTextSize(Size(nAnchorTextWidth, nAnchorTextHeight));
if(rSdrAutofitTextPrimitive.getWordWrap() || IsTextFrame())
{
rOutliner.SetMaxAutoPaperSize(aAnchorTextSize);
}
if(SDRTEXTHORZADJUST_BLOCK == eHAdj && !bVerticalWriting)
{
rOutliner.SetMinAutoPaperSize(Size(nAnchorTextWidth, 0));
}
if(SDRTEXTVERTADJUST_BLOCK == eVAdj && bVerticalWriting)
{
rOutliner.SetMinAutoPaperSize(Size(0, nAnchorTextHeight));
}
rOutliner.SetPaperSize(aNullSize);
rOutliner.SetUpdateMode(true);
rOutliner.SetText(*pOutlinerParaObject);
ImpAutoFitText(rOutliner,aAnchorTextSize,bVerticalWriting);
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
// now get back the layouted text size from outliner
const Size aOutlinerTextSize(rOutliner.GetPaperSize());
const basegfx::B2DVector aOutlinerScale(aOutlinerTextSize.Width(), aOutlinerTextSize.Height());
basegfx::B2DVector aAdjustTranslate(0.0, 0.0);
// correct horizontal translation using the now known text size
if(SDRTEXTHORZADJUST_CENTER == eHAdj || SDRTEXTHORZADJUST_RIGHT == eHAdj)
{
const double fFree(aAnchorTextRange.getWidth() - aOutlinerScale.getX());
if(SDRTEXTHORZADJUST_CENTER == eHAdj)
{
aAdjustTranslate.setX(fFree / 2.0);
}
if(SDRTEXTHORZADJUST_RIGHT == eHAdj)
{
aAdjustTranslate.setX(fFree);
}
}
// correct vertical translation using the now known text size
if(SDRTEXTVERTADJUST_CENTER == eVAdj || SDRTEXTVERTADJUST_BOTTOM == eVAdj)
{
const double fFree(aAnchorTextRange.getHeight() - aOutlinerScale.getY());
if(SDRTEXTVERTADJUST_CENTER == eVAdj)
{
aAdjustTranslate.setY(fFree / 2.0);
}
if(SDRTEXTVERTADJUST_BOTTOM == eVAdj)
{
aAdjustTranslate.setY(fFree);
}
}
// prepare matrices to apply to newly created primitives. aNewTransformA
// will get coordinates in aOutlinerScale size and positive in X, Y.
basegfx::B2DHomMatrix aNewTransformA;
basegfx::B2DHomMatrix aNewTransformB;
// translate relative to given primitive to get same rotation and shear
// as the master shape we are working on. For vertical, use the top-right
// corner
const double fStartInX(bVerticalWriting && bTopToBottom ? aAdjustTranslate.getX() + aOutlinerScale.getX() : aAdjustTranslate.getX());
const double fStartInY(bVerticalWriting && !bTopToBottom ? aAdjustTranslate.getY() + aOutlinerScale.getY() : aAdjustTranslate.getY());
aNewTransformA.translate(fStartInX, fStartInY);
// mirroring. We are now in aAnchorTextRange sizes. When mirroring in X and Y,
// move the null point which was top left to bottom right.
const bool bMirrorX(basegfx::fTools::less(aScale.getX(), 0.0));
const bool bMirrorY(basegfx::fTools::less(aScale.getY(), 0.0));
aNewTransformB.scale(bMirrorX ? -1.0 : 1.0, bMirrorY ? -1.0 : 1.0);
// in-between the translations of the single primitives will take place. Afterwards,
// the object's transformations need to be applied
aNewTransformB.shearX(fShearX);
aNewTransformB.rotate(fRotate);
aNewTransformB.translate(aTranslate.getX(), aTranslate.getY());
basegfx::B2DRange aClipRange;
// now break up text primitives.
impTextBreakupHandler aConverter(rOutliner);
aConverter.decomposeBlockTextPrimitive(aNewTransformA, aNewTransformB, aClipRange);
// cleanup outliner
rOutliner.Clear();
rOutliner.setVisualizedPage(nullptr);
rOutliner.SetControlWord(nOriginalControlWord);
rTarget = aConverter.getPrimitive2DSequence();
}
void SdrTextObj::impDecomposeBlockTextPrimitive(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
const drawinglayer::primitive2d::SdrBlockTextPrimitive2D& rSdrBlockTextPrimitive,
const drawinglayer::geometry::ViewInformation2D& aViewInformation) const
{
// decompose matrix to have position and size of text
basegfx::B2DVector aScale, aTranslate;
double fRotate, fShearX;
rSdrBlockTextPrimitive.getTextRangeTransform().decompose(aScale, aTranslate, fRotate, fShearX);
// use B2DRange aAnchorTextRange for calculations
basegfx::B2DRange aAnchorTextRange(aTranslate);
aAnchorTextRange.expand(aTranslate + aScale);
// prepare outliner
const bool bIsCell(rSdrBlockTextPrimitive.getCellText());
SolarMutexGuard aSolarGuard;
SdrOutliner& rOutliner = ImpGetDrawOutliner();
SdrTextHorzAdjust eHAdj = rSdrBlockTextPrimitive.getSdrTextHorzAdjust();
SdrTextVertAdjust eVAdj = rSdrBlockTextPrimitive.getSdrTextVertAdjust();
const EEControlBits nOriginalControlWord(rOutliner.GetControlWord());
const Size aNullSize;
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
rOutliner.SetFixedCellHeight(rSdrBlockTextPrimitive.isFixedCellHeight());
rOutliner.SetControlWord(nOriginalControlWord|EEControlBits::AUTOPAGESIZE);
rOutliner.SetMinAutoPaperSize(aNullSize);
rOutliner.SetMaxAutoPaperSize(Size(1000000,1000000));
// Resolves: fdo#35779 set background color of this shape as the editeng background if there
// is one. Check the shape itself, then the host page, then that page's master page.
// That color needs to be restored on leaving this method
Color aOriginalBackColor(rOutliner.GetBackgroundColor());
const SfxItemSet* pBackgroundFillSet = &GetObjectItemSet();
if (drawing::FillStyle_NONE == pBackgroundFillSet->Get(XATTR_FILLSTYLE).GetValue())
{
SdrPage *pOwnerPage = GetPage();
if (pOwnerPage)
{
pBackgroundFillSet = &pOwnerPage->getSdrPageProperties().GetItemSet();
if (drawing::FillStyle_NONE == pBackgroundFillSet->Get(XATTR_FILLSTYLE).GetValue())
{
if (!pOwnerPage->IsMasterPage() && pOwnerPage->TRG_HasMasterPage())
{
pBackgroundFillSet = &pOwnerPage->TRG_GetMasterPage().getSdrPageProperties().GetItemSet();
}
}
}
}
if (drawing::FillStyle_NONE != pBackgroundFillSet->Get(XATTR_FILLSTYLE).GetValue())
{
Color aColor(rOutliner.GetBackgroundColor());
GetDraftFillColor(*pBackgroundFillSet, aColor);
rOutliner.SetBackgroundColor(aColor);
}
// add one to rage sizes to get back to the old Rectangle and outliner measurements
const sal_uInt32 nAnchorTextWidth(FRound(aAnchorTextRange.getWidth() + 1));
const sal_uInt32 nAnchorTextHeight(FRound(aAnchorTextRange.getHeight() + 1));
const bool bVerticalWriting(rSdrBlockTextPrimitive.getOutlinerParaObject().IsVertical());
const bool bTopToBottom(rSdrBlockTextPrimitive.getOutlinerParaObject().IsTopToBottom());
const Size aAnchorTextSize(Size(nAnchorTextWidth, nAnchorTextHeight));
if(bIsCell)
{
// cell text is formatted neither like a text object nor like a object
// text, so use a special setup here
rOutliner.SetMaxAutoPaperSize(aAnchorTextSize);
// #i106214# To work with an unchangeable PaperSize (CellSize in
// this case) Set(Min|Max)AutoPaperSize and SetPaperSize have to be used.
// #i106214# This was not completely correct; to still measure the real
// text height to allow vertical adjust (and vice versa for VerticalWritintg)
// only one aspect has to be set, but the other one to zero
if(bVerticalWriting)
{
// measure the horizontal text size
rOutliner.SetMinAutoPaperSize(Size(0, aAnchorTextSize.Height()));
}
else
{
// measure the vertical text size
rOutliner.SetMinAutoPaperSize(Size(aAnchorTextSize.Width(), 0));
}
rOutliner.SetPaperSize(aAnchorTextSize);
rOutliner.SetUpdateMode(true);
rOutliner.SetText(rSdrBlockTextPrimitive.getOutlinerParaObject());
}
else
{
// check if block text is used (only one of them can be true)
const bool bHorizontalIsBlock(SDRTEXTHORZADJUST_BLOCK == eHAdj && !bVerticalWriting);
const bool bVerticalIsBlock(SDRTEXTVERTADJUST_BLOCK == eVAdj && bVerticalWriting);
// set minimal paper size horizontally/vertically if needed
if(bHorizontalIsBlock)
{
rOutliner.SetMinAutoPaperSize(Size(nAnchorTextWidth, 0));
}
else if(bVerticalIsBlock)
{
rOutliner.SetMinAutoPaperSize(Size(0, nAnchorTextHeight));
}
if((rSdrBlockTextPrimitive.getWordWrap() || IsTextFrame()) && !rSdrBlockTextPrimitive.getUnlimitedPage())
{
// #i103454# maximal paper size hor/ver needs to be limited to text
// frame size. If it's block text, still allow the 'other' direction
// to grow to get a correct real text size when using GetPaperSize().
// When just using aAnchorTextSize as maximum, GetPaperSize()
// would just return aAnchorTextSize again: this means, the wanted
// 'measurement' of the real size of block text would not work
Size aMaxAutoPaperSize(aAnchorTextSize);
// Usual processing - always grow in one of directions
bool bAllowGrowVertical = !bVerticalWriting;
bool bAllowGrowHorizontal = bVerticalWriting;
// Compatibility mode for tdf#99729
if (pModel->IsAnchoredTextOverflowLegacy())
{
bAllowGrowVertical = bHorizontalIsBlock;
bAllowGrowHorizontal = bVerticalIsBlock;
}
if (bAllowGrowVertical)
{
// allow to grow vertical for horizontal texts
aMaxAutoPaperSize.setHeight(1000000);
}
else if (bAllowGrowHorizontal)
{
// allow to grow horizontal for vertical texts
aMaxAutoPaperSize.setWidth(1000000);
}
rOutliner.SetMaxAutoPaperSize(aMaxAutoPaperSize);
}
rOutliner.SetPaperSize(aNullSize);
rOutliner.SetUpdateMode(true);
rOutliner.SetText(rSdrBlockTextPrimitive.getOutlinerParaObject());
}
rOutliner.SetControlWord(nOriginalControlWord);
// now get back the layouted text size from outliner
const Size aOutlinerTextSize(rOutliner.GetPaperSize());
const basegfx::B2DVector aOutlinerScale(aOutlinerTextSize.Width(), aOutlinerTextSize.Height());
basegfx::B2DVector aAdjustTranslate(0.0, 0.0);
// For draw objects containing text correct hor/ver alignment if text is bigger
// than the object itself. Without that correction, the text would always be
// formatted to the left edge (or top edge when vertical) of the draw object.
if(!IsTextFrame() && !bIsCell)
{
if(aAnchorTextRange.getWidth() < aOutlinerScale.getX() && !bVerticalWriting)
{
// Horizontal case here. Correct only if eHAdj == SDRTEXTHORZADJUST_BLOCK,
// else the alignment is wanted.
if(SDRTEXTHORZADJUST_BLOCK == eHAdj)
{
SvxAdjust eAdjust = GetObjectItemSet().Get(EE_PARA_JUST).GetAdjust();
switch(eAdjust)
{
case SvxAdjust::Left: eHAdj = SDRTEXTHORZADJUST_LEFT; break;
case SvxAdjust::Right: eHAdj = SDRTEXTHORZADJUST_RIGHT; break;
case SvxAdjust::Center: eHAdj = SDRTEXTHORZADJUST_CENTER; break;
default: break;
}
}
}
if(aAnchorTextRange.getHeight() < aOutlinerScale.getY() && bVerticalWriting)
{
// Vertical case here. Correct only if eHAdj == SDRTEXTVERTADJUST_BLOCK,
// else the alignment is wanted.
if(SDRTEXTVERTADJUST_BLOCK == eVAdj)
{
eVAdj = SDRTEXTVERTADJUST_CENTER;
}
}
}
// correct horizontal translation using the now known text size
if(SDRTEXTHORZADJUST_CENTER == eHAdj || SDRTEXTHORZADJUST_RIGHT == eHAdj)
{
const double fFree(aAnchorTextRange.getWidth() - aOutlinerScale.getX());
if(SDRTEXTHORZADJUST_CENTER == eHAdj)
{
aAdjustTranslate.setX(fFree / 2.0);
}
if(SDRTEXTHORZADJUST_RIGHT == eHAdj)
{
aAdjustTranslate.setX(fFree);
}
}
// correct vertical translation using the now known text size
if(SDRTEXTVERTADJUST_CENTER == eVAdj || SDRTEXTVERTADJUST_BOTTOM == eVAdj)
{
const double fFree(aAnchorTextRange.getHeight() - aOutlinerScale.getY());
if(SDRTEXTVERTADJUST_CENTER == eVAdj)
{
aAdjustTranslate.setY(fFree / 2.0);
}
if(SDRTEXTVERTADJUST_BOTTOM == eVAdj)
{
aAdjustTranslate.setY(fFree);
}
}
// prepare matrices to apply to newly created primitives. aNewTransformA
// will get coordinates in aOutlinerScale size and positive in X, Y.
// Translate relative to given primitive to get same rotation and shear
// as the master shape we are working on. For vertical, use the top-right
// corner
const double fStartInX(bVerticalWriting && bTopToBottom ? aAdjustTranslate.getX() + aOutlinerScale.getX() : aAdjustTranslate.getX());
const double fStartInY(bVerticalWriting && !bTopToBottom ? aAdjustTranslate.getY() + aOutlinerScale.getY() : aAdjustTranslate.getY());
const basegfx::B2DTuple aAdjOffset(fStartInX, fStartInY);
basegfx::B2DHomMatrix aNewTransformA(basegfx::utils::createTranslateB2DHomMatrix(aAdjOffset.getX(), aAdjOffset.getY()));
// mirroring. We are now in aAnchorTextRange sizes. When mirroring in X and Y,
// move the null point which was top left to bottom right.
const bool bMirrorX(basegfx::fTools::less(aScale.getX(), 0.0));
const bool bMirrorY(basegfx::fTools::less(aScale.getY(), 0.0));
// in-between the translations of the single primitives will take place. Afterwards,
// the object's transformations need to be applied
const basegfx::B2DHomMatrix aNewTransformB(basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
bMirrorX ? -1.0 : 1.0, bMirrorY ? -1.0 : 1.0,
fShearX, fRotate, aTranslate.getX(), aTranslate.getY()));
// create ClipRange (if needed)
basegfx::B2DRange aClipRange;
if(rSdrBlockTextPrimitive.getClipOnBounds())
{
aClipRange.expand(-aAdjOffset);
aClipRange.expand(basegfx::B2DTuple(aAnchorTextSize.Width(), aAnchorTextSize.Height()) - aAdjOffset);
}
// now break up text primitives.
impTextBreakupHandler aConverter(rOutliner);
aConverter.decomposeBlockTextPrimitive(aNewTransformA, aNewTransformB, aClipRange);
// cleanup outliner
rOutliner.SetBackgroundColor(aOriginalBackColor);
rOutliner.Clear();
rOutliner.setVisualizedPage(nullptr);
rTarget = aConverter.getPrimitive2DSequence();
}
void SdrTextObj::impDecomposeStretchTextPrimitive(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
const drawinglayer::primitive2d::SdrStretchTextPrimitive2D& rSdrStretchTextPrimitive,
const drawinglayer::geometry::ViewInformation2D& aViewInformation) const
{
// decompose matrix to have position and size of text
basegfx::B2DVector aScale, aTranslate;
double fRotate, fShearX;
rSdrStretchTextPrimitive.getTextRangeTransform().decompose(aScale, aTranslate, fRotate, fShearX);
// use non-mirrored B2DRange aAnchorTextRange for calculations
basegfx::B2DRange aAnchorTextRange(aTranslate);
aAnchorTextRange.expand(aTranslate + aScale);
// prepare outliner
SolarMutexGuard aSolarGuard;
SdrOutliner& rOutliner = ImpGetDrawOutliner();
const EEControlBits nOriginalControlWord(rOutliner.GetControlWord());
const Size aNullSize;
rOutliner.SetControlWord(nOriginalControlWord|EEControlBits::STRETCHING|EEControlBits::AUTOPAGESIZE);
rOutliner.SetFixedCellHeight(rSdrStretchTextPrimitive.isFixedCellHeight());
rOutliner.SetMinAutoPaperSize(aNullSize);
rOutliner.SetMaxAutoPaperSize(Size(1000000,1000000));
rOutliner.SetPaperSize(aNullSize);
rOutliner.SetUpdateMode(true);
rOutliner.SetText(rSdrStretchTextPrimitive.getOutlinerParaObject());
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
// now get back the laid out text size from outliner
const Size aOutlinerTextSize(rOutliner.CalcTextSize());
const basegfx::B2DVector aOutlinerScale(
basegfx::fTools::equalZero(aOutlinerTextSize.Width()) ? 1.0 : aOutlinerTextSize.Width(),
basegfx::fTools::equalZero(aOutlinerTextSize.Height()) ? 1.0 : aOutlinerTextSize.Height());
// prepare matrices to apply to newly created primitives
basegfx::B2DHomMatrix aNewTransformA;
// #i101957# Check for vertical text. If used, aNewTransformA
// needs to translate the text initially around object width to orient
// it relative to the topper right instead of the topper left
const bool bVertical(rSdrStretchTextPrimitive.getOutlinerParaObject().IsVertical());
const bool bTopToBottom(rSdrStretchTextPrimitive.getOutlinerParaObject().IsTopToBottom());
if(bVertical)
{
if(bTopToBottom)
aNewTransformA.translate(aScale.getX(), 0.0);
else
aNewTransformA.translate(0.0, aScale.getY());
}
// calculate global char stretching scale parameters. Use non-mirrored sizes
// to layout without mirroring
const double fScaleX(fabs(aScale.getX()) / aOutlinerScale.getX());
const double fScaleY(fabs(aScale.getY()) / aOutlinerScale.getY());
rOutliner.SetGlobalCharStretching((sal_Int16)FRound(fScaleX * 100.0), (sal_Int16)FRound(fScaleY * 100.0));
// mirroring. We are now in aAnchorTextRange sizes. When mirroring in X and Y,
// move the null point which was top left to bottom right.
const bool bMirrorX(basegfx::fTools::less(aScale.getX(), 0.0));
const bool bMirrorY(basegfx::fTools::less(aScale.getY(), 0.0));
// in-between the translations of the single primitives will take place. Afterwards,
// the object's transformations need to be applied
const basegfx::B2DHomMatrix aNewTransformB(basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
bMirrorX ? -1.0 : 1.0, bMirrorY ? -1.0 : 1.0,
fShearX, fRotate, aTranslate.getX(), aTranslate.getY()));
// now break up text primitives.
impTextBreakupHandler aConverter(rOutliner);
aConverter.decomposeStretchTextPrimitive(aNewTransformA, aNewTransformB);
// cleanup outliner
rOutliner.SetControlWord(nOriginalControlWord);
rOutliner.Clear();
rOutliner.setVisualizedPage(nullptr);
rTarget = aConverter.getPrimitive2DSequence();
}
// timing generators
#define ENDLESS_LOOP (0xffffffff)
#define ENDLESS_TIME ((double)0xffffffff)
#define PIXEL_DPI (96.0)
void SdrTextObj::impGetBlinkTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList) const
{
if(SdrTextAniKind::Blink != GetTextAniKind())
return;
// get values
const SfxItemSet& rSet = GetObjectItemSet();
const sal_uInt32 nRepeat((sal_uInt32)rSet.Get(SDRATTR_TEXT_ANICOUNT).GetValue());
double fDelay((double)rSet.Get(SDRATTR_TEXT_ANIDELAY).GetValue());
if(0.0 == fDelay)
{
// use default
fDelay = 250.0;
}
// prepare loop and add
drawinglayer::animation::AnimationEntryLoop aLoop(nRepeat ? nRepeat : ENDLESS_LOOP);
drawinglayer::animation::AnimationEntryFixed aStart(fDelay, 0.0);
aLoop.append(aStart);
drawinglayer::animation::AnimationEntryFixed aEnd(fDelay, 1.0);
aLoop.append(aEnd);
rAnimList.append(aLoop);
// add stopped state if loop is not endless
if(0L != nRepeat)
{
bool bVisibleWhenStopped(rSet.Get(SDRATTR_TEXT_ANISTOPINSIDE).GetValue());
drawinglayer::animation::AnimationEntryFixed aStop(ENDLESS_TIME, bVisibleWhenStopped ? 0.0 : 1.0);
rAnimList.append(aStop);
}
}
void impCreateScrollTiming(const SfxItemSet& rSet, drawinglayer::animation::AnimationEntryList& rAnimList, bool bForward, double fTimeFullPath, double fFrequency)
{
bool bVisibleWhenStopped(rSet.Get(SDRATTR_TEXT_ANISTOPINSIDE).GetValue());
bool bVisibleWhenStarted(rSet.Get(SDRATTR_TEXT_ANISTARTINSIDE).GetValue());
const sal_uInt32 nRepeat(rSet.Get(SDRATTR_TEXT_ANICOUNT).GetValue());
if(bVisibleWhenStarted)
{
// move from center to outside
drawinglayer::animation::AnimationEntryLinear aInOut(fTimeFullPath * 0.5, fFrequency, 0.5, bForward ? 1.0 : 0.0);
rAnimList.append(aInOut);
}
// loop. In loop, move through
drawinglayer::animation::AnimationEntryLoop aLoop(nRepeat ? nRepeat : ENDLESS_LOOP);
drawinglayer::animation::AnimationEntryLinear aThrough(fTimeFullPath, fFrequency, bForward ? 0.0 : 1.0, bForward ? 1.0 : 0.0);
aLoop.append(aThrough);
rAnimList.append(aLoop);
if(0L != nRepeat && bVisibleWhenStopped)
{
// move from outside to center
drawinglayer::animation::AnimationEntryLinear aOutIn(fTimeFullPath * 0.5, fFrequency, bForward ? 0.0 : 1.0, 0.5);
rAnimList.append(aOutIn);
// add timing for staying at the end
drawinglayer::animation::AnimationEntryFixed aEnd(ENDLESS_TIME, 0.5);
rAnimList.append(aEnd);
}
}
void impCreateAlternateTiming(const SfxItemSet& rSet, drawinglayer::animation::AnimationEntryList& rAnimList, double fRelativeTextLength, bool bForward, double fTimeFullPath, double fFrequency)
{
if(basegfx::fTools::more(fRelativeTextLength, 0.5))
{
// this is the case when fTextLength > fFrameLength, text is bigger than animation frame.
// In that case, correct direction
bForward = !bForward;
}
const double fStartPosition(bForward ? fRelativeTextLength : 1.0 - fRelativeTextLength);
const double fEndPosition(bForward ? 1.0 - fRelativeTextLength : fRelativeTextLength);
bool bVisibleWhenStarted(rSet.Get(SDRATTR_TEXT_ANISTARTINSIDE).GetValue());
const sal_uInt32 nRepeat(rSet.Get(SDRATTR_TEXT_ANICOUNT).GetValue());
if(!bVisibleWhenStarted)
{
// move from outside to center
drawinglayer::animation::AnimationEntryLinear aOutIn(fTimeFullPath * 0.5, fFrequency, bForward ? 0.0 : 1.0, 0.5);
rAnimList.append(aOutIn);
}
// loop. In loop, move out and in again. fInnerMovePath may be negative when text is bigger then frame,
// so use absolute value
const double fInnerMovePath(fabs(1.0 - (fRelativeTextLength * 2.0)));
const double fTimeForInnerPath(fTimeFullPath * fInnerMovePath);
const double fHalfInnerPath(fTimeForInnerPath * 0.5);
const sal_uInt32 nDoubleRepeat(nRepeat / 2L);
if(nDoubleRepeat || 0 == nRepeat)
{
// double forth and back loop
drawinglayer::animation::AnimationEntryLoop aLoop(nDoubleRepeat ? nDoubleRepeat : ENDLESS_LOOP);
drawinglayer::animation::AnimationEntryLinear aTime0(fHalfInnerPath, fFrequency, 0.5, fEndPosition);
aLoop.append(aTime0);
drawinglayer::animation::AnimationEntryLinear aTime1(fTimeForInnerPath, fFrequency, fEndPosition, fStartPosition);
aLoop.append(aTime1);
drawinglayer::animation::AnimationEntryLinear aTime2(fHalfInnerPath, fFrequency, fStartPosition, 0.5);
aLoop.append(aTime2);
rAnimList.append(aLoop);
}
if(nRepeat % 2L)
{
// repeat is uneven, so we need one more forth and back to center
drawinglayer::animation::AnimationEntryLinear aTime0(fHalfInnerPath, fFrequency, 0.5, fEndPosition);
rAnimList.append(aTime0);
drawinglayer::animation::AnimationEntryLinear aTime1(fHalfInnerPath, fFrequency, fEndPosition, 0.5);
rAnimList.append(aTime1);
}
if(0L != nRepeat)
{
bool bVisibleWhenStopped(rSet.Get(SDRATTR_TEXT_ANISTOPINSIDE).GetValue());
if(bVisibleWhenStopped)
{
// add timing for staying at the end
drawinglayer::animation::AnimationEntryFixed aEnd(ENDLESS_TIME, 0.5);
rAnimList.append(aEnd);
}
else
{
// move from center to outside
drawinglayer::animation::AnimationEntryLinear aInOut(fTimeFullPath * 0.5, fFrequency, 0.5, bForward ? 1.0 : 0.0);
rAnimList.append(aInOut);
}
}
}
void impCreateSlideTiming(const SfxItemSet& rSet, drawinglayer::animation::AnimationEntryList& rAnimList, bool bForward, double fTimeFullPath, double fFrequency)
{
// move in from outside, start outside
const double fStartPosition(bForward ? 0.0 : 1.0);
const sal_uInt32 nRepeat(rSet.Get(SDRATTR_TEXT_ANICOUNT).GetValue());
// move from outside to center
drawinglayer::animation::AnimationEntryLinear aOutIn(fTimeFullPath * 0.5, fFrequency, fStartPosition, 0.5);
rAnimList.append(aOutIn);
// loop. In loop, move out and in again
if(nRepeat > 1 || 0 == nRepeat)
{
drawinglayer::animation::AnimationEntryLoop aLoop(nRepeat ? nRepeat - 1 : ENDLESS_LOOP);
drawinglayer::animation::AnimationEntryLinear aTime0(fTimeFullPath * 0.5, fFrequency, 0.5, fStartPosition);
aLoop.append(aTime0);
drawinglayer::animation::AnimationEntryLinear aTime1(fTimeFullPath * 0.5, fFrequency, fStartPosition, 0.5);
aLoop.append(aTime1);
rAnimList.append(aLoop);
}
// always visible when stopped, so add timing for staying at the end when not endless
if(0L != nRepeat)
{
drawinglayer::animation::AnimationEntryFixed aEnd(ENDLESS_TIME, 0.5);
rAnimList.append(aEnd);
}
}
void SdrTextObj::impGetScrollTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList, double fFrameLength, double fTextLength) const
{
const SdrTextAniKind eAniKind(GetTextAniKind());
if(SdrTextAniKind::Scroll != eAniKind && SdrTextAniKind::Alternate != eAniKind && SdrTextAniKind::Slide != eAniKind)
return;
// get data. Goal is to calculate fTimeFullPath which is the time needed to
// move animation from (0.0) to (1.0) state
const SfxItemSet& rSet = GetObjectItemSet();
double fAnimationDelay((double)rSet.Get(SDRATTR_TEXT_ANIDELAY).GetValue());
double fSingleStepWidth((double)rSet.Get(SDRATTR_TEXT_ANIAMOUNT).GetValue());
const SdrTextAniDirection eDirection(GetTextAniDirection());
const bool bForward(SdrTextAniDirection::Right == eDirection || SdrTextAniDirection::Down == eDirection);
if(basegfx::fTools::equalZero(fAnimationDelay))
{
// default to 1/20 second
fAnimationDelay = 50.0;
}
if(basegfx::fTools::less(fSingleStepWidth, 0.0))
{
// data is in pixels, convert to logic. Imply PIXEL_DPI dpi.
// It makes no sense to keep the view-transformation centered
// definitions, so get rid of them here.
fSingleStepWidth = (-fSingleStepWidth * (2540.0 / PIXEL_DPI));
}
if(basegfx::fTools::equalZero(fSingleStepWidth))
{
// default to 1 millimeter
fSingleStepWidth = 100.0;
}
// use the length of the full animation path and the number of steps
// to get the full path time
const double fFullPathLength(fFrameLength + fTextLength);
const double fNumberOfSteps(fFullPathLength / fSingleStepWidth);
double fTimeFullPath(fNumberOfSteps * fAnimationDelay);
if(fTimeFullPath < fAnimationDelay)
{
fTimeFullPath = fAnimationDelay;
}
switch(eAniKind)
{
case SdrTextAniKind::Scroll :
{
impCreateScrollTiming(rSet, rAnimList, bForward, fTimeFullPath, fAnimationDelay);
break;
}
case SdrTextAniKind::Alternate :
{
double fRelativeTextLength(fTextLength / (fFrameLength + fTextLength));
impCreateAlternateTiming(rSet, rAnimList, fRelativeTextLength, bForward, fTimeFullPath, fAnimationDelay);
break;
}
case SdrTextAniKind::Slide :
{
impCreateSlideTiming(rSet, rAnimList, bForward, fTimeFullPath, fAnimationDelay);
break;
}
default : break; // SdrTextAniKind::NONE, SdrTextAniKind::Blink
}
}
void SdrTextObj::impHandleChainingEventsDuringDecomposition(SdrOutliner &rOutliner) const
{
if (GetTextChain()->GetNilChainingEvent(this))
return;
GetTextChain()->SetNilChainingEvent(this, true);
TextChainFlow aTxtChainFlow(const_cast<SdrTextObj*>(this));
bool bIsOverflow;
// Some debug output
size_t nObjCount = pPage->GetObjCount();
for (size_t i = 0; i < nObjCount; i++) {
SdrTextObj *pCurObj = static_cast<SdrTextObj *>(pPage->GetObj(i));
if (pCurObj == this) {
SAL_INFO("svx.chaining", "Working on TextBox " << i);
break;
}
}
aTxtChainFlow.CheckForFlowEvents(&rOutliner);
if (aTxtChainFlow.IsUnderflow() && !IsInEditMode())
{
// underflow-induced overflow
aTxtChainFlow.ExecuteUnderflow(&rOutliner);
bIsOverflow = aTxtChainFlow.IsOverflow();
} else {
// standard overflow (no underflow before)
bIsOverflow = aTxtChainFlow.IsOverflow();
}
if (bIsOverflow && !IsInEditMode()) {
// Initialize Chaining Outliner
SdrOutliner &rChainingOutl = pModel->GetChainingOutliner(this);
ImpInitDrawOutliner( rChainingOutl );
rChainingOutl.SetUpdateMode(true);
// We must pass the chaining outliner otherwise we would mess up decomposition
aTxtChainFlow.ExecuteOverflow(&rOutliner, &rChainingOutl);
}
GetTextChain()->SetNilChainingEvent(this, false);
}
void SdrTextObj::impDecomposeChainedTextPrimitive(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
const drawinglayer::primitive2d::SdrChainedTextPrimitive2D& rSdrChainedTextPrimitive,
const drawinglayer::geometry::ViewInformation2D& aViewInformation) const
{
// decompose matrix to have position and size of text
basegfx::B2DVector aScale, aTranslate;
double fRotate, fShearX;
rSdrChainedTextPrimitive.getTextRangeTransform().decompose(aScale, aTranslate, fRotate, fShearX);
// use B2DRange aAnchorTextRange for calculations
basegfx::B2DRange aAnchorTextRange(aTranslate);
aAnchorTextRange.expand(aTranslate + aScale);
// prepare outliner
const SfxItemSet& rTextItemSet = rSdrChainedTextPrimitive.getSdrText()->GetItemSet();
SolarMutexGuard aSolarGuard;
SdrOutliner& rOutliner = ImpGetDrawOutliner();
SdrTextVertAdjust eVAdj = GetTextVerticalAdjust(rTextItemSet);
SdrTextHorzAdjust eHAdj = GetTextHorizontalAdjust(rTextItemSet);
const EEControlBits nOriginalControlWord(rOutliner.GetControlWord());
const Size aNullSize;
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
rOutliner.SetControlWord(nOriginalControlWord|EEControlBits::AUTOPAGESIZE|EEControlBits::STRETCHING);
rOutliner.SetMinAutoPaperSize(aNullSize);
rOutliner.SetMaxAutoPaperSize(Size(1000000,1000000));
// add one to rage sizes to get back to the old Rectangle and outliner measurements
const sal_uInt32 nAnchorTextWidth(FRound(aAnchorTextRange.getWidth() + 1));
const sal_uInt32 nAnchorTextHeight(FRound(aAnchorTextRange.getHeight() + 1));
// Text
const OutlinerParaObject* pOutlinerParaObject = rSdrChainedTextPrimitive.getSdrText()->GetOutlinerParaObject();
OSL_ENSURE(pOutlinerParaObject, "impDecomposeBlockTextPrimitive used with no OutlinerParaObject (!)");
const bool bVerticalWriting(pOutlinerParaObject->IsVertical());
const bool bTopToBottom(pOutlinerParaObject->IsTopToBottom());
const Size aAnchorTextSize(Size(nAnchorTextWidth, nAnchorTextHeight));
if(IsTextFrame())
{
rOutliner.SetMaxAutoPaperSize(aAnchorTextSize);
}
if(SDRTEXTHORZADJUST_BLOCK == eHAdj && !bVerticalWriting)
{
rOutliner.SetMinAutoPaperSize(Size(nAnchorTextWidth, 0));
}
if(SDRTEXTVERTADJUST_BLOCK == eVAdj && bVerticalWriting)
{
rOutliner.SetMinAutoPaperSize(Size(0, nAnchorTextHeight));
}
rOutliner.SetPaperSize(aNullSize);
rOutliner.SetUpdateMode(true);
// Sets original text
rOutliner.SetText(*pOutlinerParaObject);
/* Begin overflow/underflow handling */
impHandleChainingEventsDuringDecomposition(rOutliner);
/* End overflow/underflow handling */
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
// now get back the layouted text size from outliner
const Size aOutlinerTextSize(rOutliner.GetPaperSize());
const basegfx::B2DVector aOutlinerScale(aOutlinerTextSize.Width(), aOutlinerTextSize.Height());
basegfx::B2DVector aAdjustTranslate(0.0, 0.0);
// correct horizontal translation using the now known text size
if(SDRTEXTHORZADJUST_CENTER == eHAdj || SDRTEXTHORZADJUST_RIGHT == eHAdj)
{
const double fFree(aAnchorTextRange.getWidth() - aOutlinerScale.getX());
if(SDRTEXTHORZADJUST_CENTER == eHAdj)
{
aAdjustTranslate.setX(fFree / 2.0);
}
if(SDRTEXTHORZADJUST_RIGHT == eHAdj)
{
aAdjustTranslate.setX(fFree);
}
}
// correct vertical translation using the now known text size
if(SDRTEXTVERTADJUST_CENTER == eVAdj || SDRTEXTVERTADJUST_BOTTOM == eVAdj)
{
const double fFree(aAnchorTextRange.getHeight() - aOutlinerScale.getY());
if(SDRTEXTVERTADJUST_CENTER == eVAdj)
{
aAdjustTranslate.setY(fFree / 2.0);
}
if(SDRTEXTVERTADJUST_BOTTOM == eVAdj)
{
aAdjustTranslate.setY(fFree);
}
}
// prepare matrices to apply to newly created primitives. aNewTransformA
// will get coordinates in aOutlinerScale size and positive in X, Y.
basegfx::B2DHomMatrix aNewTransformA;
basegfx::B2DHomMatrix aNewTransformB;
// translate relative to given primitive to get same rotation and shear
// as the master shape we are working on. For vertical, use the top-right
// corner
const double fStartInX(bVerticalWriting && bTopToBottom ? aAdjustTranslate.getX() + aOutlinerScale.getX() : aAdjustTranslate.getX());
const double fStartInY(bVerticalWriting && !bTopToBottom ? aAdjustTranslate.getY() + aOutlinerScale.getY() : aAdjustTranslate.getY());
aNewTransformA.translate(fStartInX, fStartInY);
// mirroring. We are now in aAnchorTextRange sizes. When mirroring in X and Y,
// move the null point which was top left to bottom right.
const bool bMirrorX(basegfx::fTools::less(aScale.getX(), 0.0));
const bool bMirrorY(basegfx::fTools::less(aScale.getY(), 0.0));
aNewTransformB.scale(bMirrorX ? -1.0 : 1.0, bMirrorY ? -1.0 : 1.0);
// in-between the translations of the single primitives will take place. Afterwards,
// the object's transformations need to be applied
aNewTransformB.shearX(fShearX);
aNewTransformB.rotate(fRotate);
aNewTransformB.translate(aTranslate.getX(), aTranslate.getY());
basegfx::B2DRange aClipRange;
// now break up text primitives.
impTextBreakupHandler aConverter(rOutliner);
aConverter.decomposeBlockTextPrimitive(aNewTransformA, aNewTransformB, aClipRange);
// cleanup outliner
rOutliner.Clear();
rOutliner.setVisualizedPage(nullptr);
rOutliner.SetControlWord(nOriginalControlWord);
rTarget = aConverter.getPrimitive2DSequence();
}
// Direct decomposer for text visualization when you already have a prepared
// Outliner containing all the needed information
void SdrTextObj::impDecomposeBlockTextPrimitiveDirect(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
SdrOutliner& rOutliner,
const basegfx::B2DHomMatrix& rNewTransformA,
const basegfx::B2DHomMatrix& rNewTransformB,
const basegfx::B2DRange& rClipRange)
{
impTextBreakupHandler aConverter(rOutliner);
aConverter.decomposeBlockTextPrimitive(rNewTransformA, rNewTransformB, rClipRange);
rTarget.append(aConverter.getPrimitive2DSequence());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|