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
|
/* -*- 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 <editeng/tstpitem.hxx>
#include <editeng/colritem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/crossedoutitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/flditem.hxx>
#include <editeng/postitem.hxx>
#include <editeng/kernitem.hxx>
#include <editeng/wrlmitem.hxx>
#include <editeng/wghtitem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/cmapitem.hxx>
#include <editeng/contouritem.hxx>
#include <editeng/escapementitem.hxx>
#include <editeng/shdditem.hxx>
#include <editeng/autokernitem.hxx>
#include <editeng/langitem.hxx>
#include <editeng/emphasismarkitem.hxx>
#include <editeng/charscaleitem.hxx>
#include <editeng/charreliefitem.hxx>
#include <editeng/editids.hrc>
#include <editeng/editdata.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/lspcitem.hxx>
#include <editdoc.hxx>
#include <editeng/eerdll.hxx>
#include <eerdll2.hxx>
#include "impedit.hxx"
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <svl/grabbagitem.hxx>
#include <svl/voiditem.hxx>
#include <tools/debug.hxx>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <libxml/xmlwriter.h>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <limits>
#include <memory>
#include <set>
#include <string_view>
#include <utility>
using namespace ::com::sun::star;
sal_uInt16 GetScriptItemId( sal_uInt16 nItemId, SvtScriptType nScriptType )
{
sal_uInt16 nId = nItemId;
if ( ( nScriptType == SvtScriptType::ASIAN ) ||
( nScriptType == SvtScriptType::COMPLEX ) )
{
switch ( nItemId )
{
case EE_CHAR_LANGUAGE:
nId = ( nScriptType == SvtScriptType::ASIAN ) ? EE_CHAR_LANGUAGE_CJK : EE_CHAR_LANGUAGE_CTL;
break;
case EE_CHAR_FONTINFO:
nId = ( nScriptType == SvtScriptType::ASIAN ) ? EE_CHAR_FONTINFO_CJK : EE_CHAR_FONTINFO_CTL;
break;
case EE_CHAR_FONTHEIGHT:
nId = ( nScriptType == SvtScriptType::ASIAN ) ? EE_CHAR_FONTHEIGHT_CJK : EE_CHAR_FONTHEIGHT_CTL;
break;
case EE_CHAR_WEIGHT:
nId = ( nScriptType == SvtScriptType::ASIAN ) ? EE_CHAR_WEIGHT_CJK : EE_CHAR_WEIGHT_CTL;
break;
case EE_CHAR_ITALIC:
nId = ( nScriptType == SvtScriptType::ASIAN ) ? EE_CHAR_ITALIC_CJK : EE_CHAR_ITALIC_CTL;
break;
}
}
return nId;
}
bool IsScriptItemValid( sal_uInt16 nItemId, short nScriptType )
{
bool bValid = true;
switch ( nItemId )
{
case EE_CHAR_LANGUAGE:
bValid = nScriptType == i18n::ScriptType::LATIN;
break;
case EE_CHAR_LANGUAGE_CJK:
bValid = nScriptType == i18n::ScriptType::ASIAN;
break;
case EE_CHAR_LANGUAGE_CTL:
bValid = nScriptType == i18n::ScriptType::COMPLEX;
break;
case EE_CHAR_FONTINFO:
bValid = nScriptType == i18n::ScriptType::LATIN;
break;
case EE_CHAR_FONTINFO_CJK:
bValid = nScriptType == i18n::ScriptType::ASIAN;
break;
case EE_CHAR_FONTINFO_CTL:
bValid = nScriptType == i18n::ScriptType::COMPLEX;
break;
case EE_CHAR_FONTHEIGHT:
bValid = nScriptType == i18n::ScriptType::LATIN;
break;
case EE_CHAR_FONTHEIGHT_CJK:
bValid = nScriptType == i18n::ScriptType::ASIAN;
break;
case EE_CHAR_FONTHEIGHT_CTL:
bValid = nScriptType == i18n::ScriptType::COMPLEX;
break;
case EE_CHAR_WEIGHT:
bValid = nScriptType == i18n::ScriptType::LATIN;
break;
case EE_CHAR_WEIGHT_CJK:
bValid = nScriptType == i18n::ScriptType::ASIAN;
break;
case EE_CHAR_WEIGHT_CTL:
bValid = nScriptType == i18n::ScriptType::COMPLEX;
break;
case EE_CHAR_ITALIC:
bValid = nScriptType == i18n::ScriptType::LATIN;
break;
case EE_CHAR_ITALIC_CJK:
bValid = nScriptType == i18n::ScriptType::ASIAN;
break;
case EE_CHAR_ITALIC_CTL:
bValid = nScriptType == i18n::ScriptType::COMPLEX;
break;
}
return bValid;
}
const SfxItemInfo aItemInfos[EDITITEMCOUNT] =
{
// _nItemInfoSlotID, _nItemInfoFlags
{ SID_ATTR_FRAMEDIRECTION, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_WRITINGDIR
{ 0, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, // EE_PARA_XMLATTRIBS
{ SID_ATTR_PARA_HANGPUNCTUATION, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_HANGINGPUNCTUATION
{ SID_ATTR_PARA_FORBIDDEN_RULES, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_FORBIDDENRULES
{ SID_ATTR_PARA_SCRIPTSPACE, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_ASIANCJKSPACING
{ SID_ATTR_NUMBERING_RULE, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_NUMBULL
{ 0, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_HYPHENATE
{ 0, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_HYPHENATE_NO_CAPS
{ 0, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_HYPHENATE_NO_LAST_WORD
{ 0, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_BULLETSTATE
{ 0, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_OUTLLRSPACE
{ SID_ATTR_PARA_OUTLLEVEL, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_OUTLLEVEL
{ SID_ATTR_PARA_BULLET, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_BULLET
{ SID_ATTR_LRSPACE, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_LRSPACE
{ SID_ATTR_ULSPACE, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_ULSPACE
{ SID_ATTR_PARA_LINESPACE, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_SBL
{ SID_ATTR_PARA_ADJUST, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_JUST
{ SID_ATTR_TABSTOP, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_TABS
{ SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_JUST_METHOD
{ SID_ATTR_ALIGN_VER_JUSTIFY, SFX_ITEMINFOFLAG_NONE }, // EE_PARA_VER_JUST
{ SID_ATTR_CHAR_COLOR, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, // EE_CHAR_COLOR
{ SID_ATTR_CHAR_FONT, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, // EE_CHAR_FONTINFO
{ SID_ATTR_CHAR_FONTHEIGHT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_FONTHEIGHT
{ SID_ATTR_CHAR_SCALEWIDTH, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_FONTWIDTH
{ SID_ATTR_CHAR_WEIGHT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_WEIGHT
{ SID_ATTR_CHAR_UNDERLINE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_UNDERLINE
{ SID_ATTR_CHAR_STRIKEOUT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_STRIKEOUT
{ SID_ATTR_CHAR_POSTURE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_ITALIC
{ SID_ATTR_CHAR_CONTOUR, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_OUTLINE
{ SID_ATTR_CHAR_SHADOWED, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_SHADOW
{ SID_ATTR_CHAR_ESCAPEMENT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_ESCAPEMENT
{ SID_ATTR_CHAR_AUTOKERN, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_PAIRKERNING
{ SID_ATTR_CHAR_KERNING, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_KERNING
{ SID_ATTR_CHAR_WORDLINEMODE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_WLM
{ SID_ATTR_CHAR_LANGUAGE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_LANGUAGE
{ SID_ATTR_CHAR_CJK_LANGUAGE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_LANGUAGE_CJK
{ SID_ATTR_CHAR_CTL_LANGUAGE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_LANGUAGE_CTL
{ SID_ATTR_CHAR_CJK_FONT, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, // EE_CHAR_FONTINFO_CJK
{ SID_ATTR_CHAR_CTL_FONT, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, // EE_CHAR_FONTINFO_CTL
{ SID_ATTR_CHAR_CJK_FONTHEIGHT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_FONTHEIGHT_CJK
{ SID_ATTR_CHAR_CTL_FONTHEIGHT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_FONTHEIGHT_CTL
{ SID_ATTR_CHAR_CJK_WEIGHT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_WEIGHT_CJK
{ SID_ATTR_CHAR_CTL_WEIGHT, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_WEIGHT_CTL
{ SID_ATTR_CHAR_CJK_POSTURE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_ITALIC_CJK
{ SID_ATTR_CHAR_CTL_POSTURE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_ITALIC_CTL
{ SID_ATTR_CHAR_EMPHASISMARK, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_EMPHASISMARK
{ SID_ATTR_CHAR_RELIEF, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_RELIEF
{ 0, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, // EE_CHAR_XMLATTRIBS
{ SID_ATTR_CHAR_OVERLINE, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_OVERLINE
{ SID_ATTR_CHAR_CASEMAP, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_CASEMAP
{ SID_ATTR_CHAR_GRABBAG, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_GRABBAG
{ SID_ATTR_CHAR_BACK_COLOR, SFX_ITEMINFOFLAG_NONE }, // EE_CHAR_BKGCOLOR
{ 0, SFX_ITEMINFOFLAG_NONE }, // EE_FEATURE_TAB
{ 0, SFX_ITEMINFOFLAG_NONE }, // EE_FEATURE_LINEBR
{ SID_ATTR_CHAR_CHARSETCOLOR, SFX_ITEMINFOFLAG_NONE }, // EE_FEATURE_NOTCONV
{ SID_FIELD, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, // EE_FEATURE_FIELD
};
EditCharAttrib* MakeCharAttrib( SfxItemPool& rPool, const SfxPoolItem& rAttr, sal_Int32 nS, sal_Int32 nE )
{
// Create a new attribute in the pool
switch( rAttr.Which() )
{
case EE_CHAR_LANGUAGE:
case EE_CHAR_LANGUAGE_CJK:
case EE_CHAR_LANGUAGE_CTL:
{
return new EditCharAttribLanguage(rPool, rAttr, nS, nE);
}
break;
case EE_CHAR_COLOR:
{
return new EditCharAttribColor(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_FONTINFO:
case EE_CHAR_FONTINFO_CJK:
case EE_CHAR_FONTINFO_CTL:
{
return new EditCharAttribFont(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_FONTHEIGHT:
case EE_CHAR_FONTHEIGHT_CJK:
case EE_CHAR_FONTHEIGHT_CTL:
{
return new EditCharAttribFontHeight(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_FONTWIDTH:
{
return new EditCharAttribFontWidth(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_WEIGHT:
case EE_CHAR_WEIGHT_CJK:
case EE_CHAR_WEIGHT_CTL:
{
return new EditCharAttribWeight(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_UNDERLINE:
{
return new EditCharAttribUnderline(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_OVERLINE:
{
return new EditCharAttribOverline(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_EMPHASISMARK:
{
return new EditCharAttribEmphasisMark(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_RELIEF:
{
return new EditCharAttribRelief(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_STRIKEOUT:
{
return new EditCharAttribStrikeout(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_ITALIC:
case EE_CHAR_ITALIC_CJK:
case EE_CHAR_ITALIC_CTL:
{
return new EditCharAttribItalic(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_OUTLINE:
{
return new EditCharAttribOutline(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_SHADOW:
{
return new EditCharAttribShadow(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_ESCAPEMENT:
{
return new EditCharAttribEscapement(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_PAIRKERNING:
{
return new EditCharAttribPairKerning(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_KERNING:
{
return new EditCharAttribKerning(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_WLM:
{
return new EditCharAttribWordLineMode(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_XMLATTRIBS:
{
return new EditCharAttrib(rPool, rAttr, nS, nE); // Attribute is only for holding XML information...
}
break;
case EE_CHAR_CASEMAP:
{
return new EditCharAttribCaseMap(rPool, rAttr, nS, nE );
}
break;
case EE_CHAR_GRABBAG:
{
return new EditCharAttribGrabBag(rPool, rAttr, nS, nE );
}
break;
case EE_FEATURE_TAB:
{
return new EditCharAttribTab(rPool, rAttr, nS );
}
break;
case EE_FEATURE_LINEBR:
{
return new EditCharAttribLineBreak(rPool, rAttr, nS );
}
break;
case EE_FEATURE_FIELD:
{
return new EditCharAttribField(rPool, rAttr, nS );
}
break;
case EE_CHAR_BKGCOLOR:
{
return new EditCharAttribBackgroundColor(rPool, rAttr, nS, nE );
}
break;
default:
break;
}
OSL_FAIL( "Invalid Attribute!" );
return nullptr;
}
void ParaPortion::MarkInvalid( sal_Int32 nStart, sal_Int32 nDiff )
{
if ( !bInvalid )
{
// nInvalidPosEnd = nStart; // ??? => CreateLines
nInvalidPosStart = ( nDiff >= 0 ) ? nStart : ( nStart + nDiff );
nInvalidDiff = nDiff;
}
else
{
// Simple tap in succession
if ( ( nDiff > 0 ) && ( nInvalidDiff > 0 ) &&
( ( nInvalidPosStart+nInvalidDiff ) == nStart ) )
{
nInvalidDiff = nInvalidDiff + nDiff;
}
// Simple delete in succession
else if ( ( nDiff < 0 ) && ( nInvalidDiff < 0 ) && ( nInvalidPosStart == nStart ) )
{
nInvalidPosStart = nInvalidPosStart + nDiff;
nInvalidDiff = nInvalidDiff + nDiff;
}
else
{
// nInvalidPosEnd = pNode->Len();
DBG_ASSERT( ( nDiff >= 0 ) || ( (nStart+nDiff) >= 0 ), "MarkInvalid: Diff out of Range" );
nInvalidPosStart = std::min( nInvalidPosStart, ( nDiff < 0 ? nStart+nDiff : nDiff ) );
nInvalidDiff = 0;
bSimple = false;
}
}
bInvalid = true;
aScriptInfos.clear();
aWritingDirectionInfos.clear();
}
void ParaPortion::MarkSelectionInvalid( sal_Int32 nStart )
{
if ( !bInvalid )
{
nInvalidPosStart = nStart;
}
else
{
nInvalidPosStart = std::min( nInvalidPosStart, nStart );
}
nInvalidDiff = 0;
bInvalid = true;
bSimple = false;
aScriptInfos.clear();
aWritingDirectionInfos.clear();
}
sal_Int32 ParaPortion::GetLineNumber( sal_Int32 nIndex ) const
{
SAL_WARN_IF( !aLineList.Count(), "editeng", "Empty ParaPortion in GetLine!" );
DBG_ASSERT( bVisible, "Why GetLine() on an invisible paragraph?" );
for ( sal_Int32 nLine = 0; nLine < aLineList.Count(); nLine++ )
{
if ( aLineList[nLine].IsIn( nIndex ) )
return nLine;
}
// Then it should be at the end of the last line!
DBG_ASSERT( nIndex == aLineList[ aLineList.Count() - 1 ].GetEnd(), "Index dead wrong!" );
return (aLineList.Count()-1);
}
void ParaPortion::SetVisible( bool bMakeVisible )
{
bVisible = bMakeVisible;
}
void ParaPortion::CorrectValuesBehindLastFormattedLine( sal_Int32 nLastFormattedLine )
{
sal_Int32 nLines = aLineList.Count();
DBG_ASSERT( nLines, "CorrectPortionNumbersFromLine: Empty Portion?" );
if ( nLastFormattedLine < ( nLines - 1 ) )
{
const EditLine& rLastFormatted = aLineList[ nLastFormattedLine ];
const EditLine& rUnformatted = aLineList[ nLastFormattedLine+1 ];
sal_Int32 nPortionDiff = rUnformatted.GetStartPortion() - rLastFormatted.GetEndPortion();
sal_Int32 nTextDiff = rUnformatted.GetStart() - rLastFormatted.GetEnd();
nTextDiff++; // LastFormatted->GetEnd() was included => 1 deducted too much!
// The first unformatted must begin exactly one Portion behind the last
// of the formatted:
// If the modified line was split into one portion, can
// nLastEnd > nNextStart!
int nPDiff = -( nPortionDiff-1 );
int nTDiff = -( nTextDiff-1 );
if ( nPDiff || nTDiff )
{
for ( sal_Int32 nL = nLastFormattedLine+1; nL < nLines; nL++ )
{
EditLine& rLine = aLineList[ nL ];
rLine.GetStartPortion() = rLine.GetStartPortion() + nPDiff;
rLine.GetEndPortion() = rLine.GetEndPortion() + nPDiff;
rLine.GetStart() = rLine.GetStart() + nTDiff;
rLine.GetEnd() = rLine.GetEnd() + nTDiff;
rLine.SetValid();
}
}
}
DBG_ASSERT( aLineList[ aLineList.Count()-1 ].GetEnd() == pNode->Len(), "CorrectLines: The end is not right!" );
}
// Shared reverse lookup acceleration pieces ...
namespace {
template<typename Array, typename Val>
sal_Int32 FastGetPos(const Array& rArray, const Val* p, sal_Int32& rLastPos)
{
sal_Int32 nArrayLen = rArray.size();
// Through certain filter code-paths we do a lot of appends, which in
// turn call GetPos - creating some N^2 nightmares. If we have a
// non-trivially large list, do a few checks from the end first.
if (rLastPos > 16 && nArrayLen > 16)
{
sal_Int32 nEnd;
if (rLastPos > nArrayLen - 2)
nEnd = nArrayLen;
else
nEnd = rLastPos + 2;
for (sal_Int32 nIdx = rLastPos - 2; nIdx < nEnd; ++nIdx)
{
if (rArray.at(nIdx).get() == p)
{
rLastPos = nIdx;
return nIdx;
}
}
}
// The world's lamest linear search from svarray...
for (sal_Int32 nIdx = 0; nIdx < nArrayLen; ++nIdx)
if (rArray.at(nIdx).get() == p)
{
rLastPos = nIdx;
return rLastPos;
}
// XXX "not found" condition for sal_Int32 indexes
return EE_PARA_NOT_FOUND;
}
}
sal_Int32 ParaPortionList::GetPos(const ParaPortion* p) const
{
return FastGetPos(maPortions, p, nLastCache);
}
std::unique_ptr<ParaPortion> ParaPortionList::Release(sal_Int32 nPos)
{
if (nPos < 0 || maPortions.size() <= o3tl::make_unsigned(nPos))
{
SAL_WARN( "editeng", "ParaPortionList::Release - out of bounds pos " << nPos);
return nullptr;
}
std::unique_ptr<ParaPortion> p = std::move(maPortions[nPos]);
maPortions.erase(maPortions.begin()+nPos);
return p;
}
void ParaPortionList::Remove(sal_Int32 nPos)
{
if (nPos < 0 || maPortions.size() <= o3tl::make_unsigned(nPos))
{
SAL_WARN( "editeng", "ParaPortionList::Remove - out of bounds pos " << nPos);
return;
}
maPortions.erase(maPortions.begin()+nPos);
}
void ParaPortionList::Insert(sal_Int32 nPos, std::unique_ptr<ParaPortion> p)
{
if (nPos < 0 || maPortions.size() < o3tl::make_unsigned(nPos))
{
SAL_WARN( "editeng", "ParaPortionList::Insert - out of bounds pos " << nPos);
return;
}
maPortions.insert(maPortions.begin()+nPos, std::move(p));
}
void ParaPortionList::Append(std::unique_ptr<ParaPortion> p)
{
maPortions.push_back(std::move(p));
}
sal_Int32 ParaPortionList::Count() const
{
size_t nSize = maPortions.size();
if (nSize > SAL_MAX_INT32)
{
SAL_WARN( "editeng", "ParaPortionList::Count - overflow " << nSize);
return SAL_MAX_INT32;
}
return nSize;
}
void ParaPortionList::Reset()
{
maPortions.clear();
}
tools::Long ParaPortionList::GetYOffset(const ParaPortion* pPPortion) const
{
tools::Long nHeight = 0;
for (const auto & rPortion : maPortions)
{
const ParaPortion* pTmpPortion = rPortion.get();
if ( pTmpPortion == pPPortion )
return nHeight;
nHeight += pTmpPortion->GetHeight();
}
OSL_FAIL( "GetYOffset: Portion not found" );
return nHeight;
}
sal_Int32 ParaPortionList::FindParagraph(tools::Long nYOffset) const
{
tools::Long nY = 0;
for (size_t i = 0, n = maPortions.size(); i < n; ++i)
{
nY += maPortions[i]->GetHeight(); // should also be correct even in bVisible!
if ( nY > nYOffset )
return i <= SAL_MAX_INT32 ? static_cast<sal_Int32>(i) : SAL_MAX_INT32;
}
return EE_PARA_NOT_FOUND;
}
#if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
void
ParaPortionList::DbgCheck(ParaPortionList const& rParas, EditDoc const& rDoc)
{
assert(rParas.Count() == rDoc.Count());
for (sal_Int32 i = 0; i < rParas.Count(); ++i)
{
assert(rParas.SafeGetObject(i) != nullptr);
assert(rParas.SafeGetObject(i)->GetNode() != nullptr);
assert(rParas.SafeGetObject(i)->GetNode() == rDoc.GetObject(i));
}
}
#endif
ContentAttribsInfo::ContentAttribsInfo( SfxItemSet aParaAttribs ) :
aPrevParaAttribs(std::move( aParaAttribs))
{
}
void ContentAttribsInfo::AppendCharAttrib(EditCharAttrib* pNew)
{
aPrevCharAttribs.push_back(std::unique_ptr<EditCharAttrib>(pNew));
}
void ConvertItem( std::unique_ptr<SfxPoolItem>& rPoolItem, MapUnit eSourceUnit, MapUnit eDestUnit )
{
DBG_ASSERT( eSourceUnit != eDestUnit, "ConvertItem - Why?!" );
switch ( rPoolItem->Which() )
{
case EE_PARA_LRSPACE:
{
assert(dynamic_cast<const SvxLRSpaceItem *>(rPoolItem.get()) != nullptr);
SvxLRSpaceItem& rItem = static_cast<SvxLRSpaceItem&>(*rPoolItem);
rItem.SetTextFirstLineOffset( sal::static_int_cast< short >( OutputDevice::LogicToLogic( rItem.GetTextFirstLineOffset(), eSourceUnit, eDestUnit ) ) );
rItem.SetTextLeft( OutputDevice::LogicToLogic( rItem.GetTextLeft(), eSourceUnit, eDestUnit ) );
rItem.SetRight( OutputDevice::LogicToLogic( rItem.GetRight(), eSourceUnit, eDestUnit ) );
}
break;
case EE_PARA_ULSPACE:
{
assert(dynamic_cast<const SvxULSpaceItem *>(rPoolItem.get()) != nullptr);
SvxULSpaceItem& rItem = static_cast<SvxULSpaceItem&>(*rPoolItem);
rItem.SetUpper( sal::static_int_cast< sal_uInt16 >( OutputDevice::LogicToLogic( rItem.GetUpper(), eSourceUnit, eDestUnit ) ) );
rItem.SetLower( sal::static_int_cast< sal_uInt16 >( OutputDevice::LogicToLogic( rItem.GetLower(), eSourceUnit, eDestUnit ) ) );
}
break;
case EE_PARA_SBL:
{
assert(dynamic_cast<const SvxLineSpacingItem *>(rPoolItem.get()) != nullptr);
SvxLineSpacingItem& rItem = static_cast<SvxLineSpacingItem&>(*rPoolItem);
// SetLineHeight changes also eLineSpace!
if ( rItem.GetLineSpaceRule() == SvxLineSpaceRule::Min )
rItem.SetLineHeight( sal::static_int_cast< sal_uInt16 >( OutputDevice::LogicToLogic( rItem.GetLineHeight(), eSourceUnit, eDestUnit ) ) );
}
break;
case EE_PARA_TABS:
{
assert(dynamic_cast<const SvxTabStopItem *>(rPoolItem.get()) != nullptr);
SvxTabStopItem& rItem = static_cast<SvxTabStopItem&>(*rPoolItem);
SvxTabStopItem* pNewItem(new SvxTabStopItem(EE_PARA_TABS));
if (sal_Int32 nDefTabDistance = rItem.GetDefaultDistance())
{
pNewItem->SetDefaultDistance(
OutputDevice::LogicToLogic(nDefTabDistance, eSourceUnit, eDestUnit));
}
for ( sal_uInt16 i = 0; i < rItem.Count(); i++ )
{
const SvxTabStop& rTab = rItem[i];
SvxTabStop aNewStop( OutputDevice::LogicToLogic( rTab.GetTabPos(), eSourceUnit, eDestUnit ), rTab.GetAdjustment(), rTab.GetDecimal(), rTab.GetFill() );
pNewItem->Insert( aNewStop );
}
rPoolItem.reset(pNewItem);
}
break;
case EE_CHAR_FONTHEIGHT:
case EE_CHAR_FONTHEIGHT_CJK:
case EE_CHAR_FONTHEIGHT_CTL:
{
assert(dynamic_cast<const SvxFontHeightItem *>(rPoolItem.get()) != nullptr);
SvxFontHeightItem& rItem = static_cast<SvxFontHeightItem&>(*rPoolItem);
rItem.SetHeight( OutputDevice::LogicToLogic( rItem.GetHeight(), eSourceUnit, eDestUnit ) );
}
break;
}
}
void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const MapUnit* pSourceUnit, const MapUnit* pDestUnit )
{
const SfxItemPool* pSourcePool = rSource.GetPool();
const SfxItemPool* pDestPool = rDest.GetPool();
for ( sal_uInt16 nWhich = EE_PARA_START; nWhich <= EE_CHAR_END; nWhich++ )
{
// If possible go through SlotID ...
sal_uInt16 nSourceWhich = nWhich;
sal_uInt16 nSlot = pDestPool->GetTrueSlotId( nWhich );
if ( nSlot )
{
sal_uInt16 nW = pSourcePool->GetTrueWhich( nSlot );
if ( nW )
nSourceWhich = nW;
}
if ( rSource.GetItemState( nSourceWhich, false ) == SfxItemState::SET )
{
MapUnit eSourceUnit = pSourceUnit ? *pSourceUnit : pSourcePool->GetMetric( nSourceWhich );
MapUnit eDestUnit = pDestUnit ? *pDestUnit : pDestPool->GetMetric( nWhich );
if ( eSourceUnit != eDestUnit )
{
std::unique_ptr<SfxPoolItem> pItem(rSource.Get( nSourceWhich ).Clone());
ConvertItem( pItem, eSourceUnit, eDestUnit );
pItem->SetWhich(nWhich);
rDest.Put( std::move(pItem) );
}
else
{
rDest.Put( rSource.Get( nSourceWhich ).CloneSetWhich(nWhich) );
}
}
}
}
bool EditPaM::DbgIsBuggy( EditDoc const & rDoc ) const
{
return !pNode ||
rDoc.GetPos( pNode ) >= rDoc.Count() ||
nIndex > pNode->Len();
}
bool EditSelection::DbgIsBuggy( EditDoc const & rDoc ) const
{
return aStartPaM.DbgIsBuggy( rDoc ) || aEndPaM.DbgIsBuggy( rDoc );
}
void EditSelection::Adjust( const EditDoc& rNodes )
{
DBG_ASSERT( aStartPaM.GetIndex() <= aStartPaM.GetNode()->Len(), "Index out of range in Adjust(1)" );
DBG_ASSERT( aEndPaM.GetIndex() <= aEndPaM.GetNode()->Len(), "Index out of range in Adjust(2)" );
const ContentNode* pStartNode = aStartPaM.GetNode();
const ContentNode* pEndNode = aEndPaM.GetNode();
sal_Int32 nStartNode = rNodes.GetPos( pStartNode );
sal_Int32 nEndNode = rNodes.GetPos( pEndNode );
DBG_ASSERT( nStartNode != SAL_MAX_INT32, "Node out of range in Adjust(1)" );
DBG_ASSERT( nEndNode != SAL_MAX_INT32, "Node out of range in Adjust(2)" );
const bool bSwap = ( nStartNode > nEndNode ) ||
( ( nStartNode == nEndNode ) &&
( aStartPaM.GetIndex() > aEndPaM.GetIndex() ) );
if ( bSwap )
{
EditPaM aTmpPaM( aStartPaM );
aStartPaM = aEndPaM;
aEndPaM = aTmpPaM;
}
}
EditDoc::EditDoc( SfxItemPool* pPool ) :
mnLastCache(0),
mpItemPool(pPool ? pPool : new EditEngineItemPool()),
mnDefTab(DEFTAB),
mbIsVertical(false),
mnRotation(TextRotation::NONE),
mbIsFixedCellHeight(false),
mbModified(false),
mbDisableAttributeExpanding(false)
{
// Don't create an empty node, Clear() will be called in EditEngine-CTOR
};
EditDoc::~EditDoc()
{
maContents.clear();
}
void CreateFont( SvxFont& rFont, const SfxItemSet& rSet, bool bSearchInParent, SvtScriptType nScriptType )
{
vcl::Font aPrevFont( rFont );
rFont.SetAlignment( ALIGN_BASELINE );
sal_uInt16 nWhich_FontInfo = GetScriptItemId( EE_CHAR_FONTINFO, nScriptType );
sal_uInt16 nWhich_Language = GetScriptItemId( EE_CHAR_LANGUAGE, nScriptType );
sal_uInt16 nWhich_FontHeight = GetScriptItemId( EE_CHAR_FONTHEIGHT, nScriptType );
sal_uInt16 nWhich_Weight = GetScriptItemId( EE_CHAR_WEIGHT, nScriptType );
sal_uInt16 nWhich_Italic = GetScriptItemId( EE_CHAR_ITALIC, nScriptType );
if ( bSearchInParent || ( rSet.GetItemState( nWhich_FontInfo ) == SfxItemState::SET ) )
{
const SvxFontItem& rFontItem = static_cast<const SvxFontItem&>(rSet.Get( nWhich_FontInfo ));
rFont.SetFamilyName( rFontItem.GetFamilyName() );
rFont.SetFamily( rFontItem.GetFamily() );
rFont.SetPitch( rFontItem.GetPitch() );
rFont.SetCharSet( rFontItem.GetCharSet() );
}
if ( bSearchInParent || ( rSet.GetItemState( nWhich_Language ) == SfxItemState::SET ) )
rFont.SetLanguage( static_cast<const SvxLanguageItem&>(rSet.Get( nWhich_Language )).GetLanguage() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_COLOR ) == SfxItemState::SET ) )
rFont.SetColor( rSet.Get( EE_CHAR_COLOR ).GetValue() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_BKGCOLOR ) == SfxItemState::SET ) )
{
auto& aColor = rSet.Get( EE_CHAR_BKGCOLOR ).GetValue();
rFont.SetTransparent(aColor.IsTransparent());
rFont.SetFillColor(aColor);
}
if ( bSearchInParent || ( rSet.GetItemState( nWhich_FontHeight ) == SfxItemState::SET ) )
rFont.SetFontSize( Size( rFont.GetFontSize().Width(), static_cast<const SvxFontHeightItem&>(rSet.Get( nWhich_FontHeight ) ).GetHeight() ) );
if ( bSearchInParent || ( rSet.GetItemState( nWhich_Weight ) == SfxItemState::SET ) )
rFont.SetWeight( static_cast<const SvxWeightItem&>(rSet.Get( nWhich_Weight )).GetWeight() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_UNDERLINE ) == SfxItemState::SET ) )
rFont.SetUnderline( rSet.Get( EE_CHAR_UNDERLINE ).GetLineStyle() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_OVERLINE ) == SfxItemState::SET ) )
rFont.SetOverline( rSet.Get( EE_CHAR_OVERLINE ).GetLineStyle() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_STRIKEOUT ) == SfxItemState::SET ) )
rFont.SetStrikeout( rSet.Get( EE_CHAR_STRIKEOUT ).GetStrikeout() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_CASEMAP ) == SfxItemState::SET ) )
rFont.SetCaseMap( rSet.Get( EE_CHAR_CASEMAP ).GetCaseMap() );
if ( bSearchInParent || ( rSet.GetItemState( nWhich_Italic ) == SfxItemState::SET ) )
rFont.SetItalic( static_cast<const SvxPostureItem&>(rSet.Get( nWhich_Italic )).GetPosture() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_OUTLINE ) == SfxItemState::SET ) )
rFont.SetOutline( rSet.Get( EE_CHAR_OUTLINE ).GetValue() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_SHADOW ) == SfxItemState::SET ) )
rFont.SetShadow( rSet.Get( EE_CHAR_SHADOW ).GetValue() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_ESCAPEMENT ) == SfxItemState::SET ) )
{
const SvxEscapementItem& rEsc = rSet.Get( EE_CHAR_ESCAPEMENT );
sal_uInt16 const nProp = rEsc.GetProportionalHeight();
rFont.SetPropr( static_cast<sal_uInt8>(nProp) );
short nEsc = rEsc.GetEsc();
rFont.SetNonAutoEscapement( nEsc );
}
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_PAIRKERNING ) == SfxItemState::SET ) )
rFont.SetKerning( rSet.Get( EE_CHAR_PAIRKERNING ).GetValue() ? FontKerning::FontSpecific : FontKerning::NONE );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_KERNING ) == SfxItemState::SET ) )
rFont.SetFixKerning( rSet.Get( EE_CHAR_KERNING ).GetValue() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_WLM ) == SfxItemState::SET ) )
rFont.SetWordLineMode( rSet.Get( EE_CHAR_WLM ).GetValue() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_EMPHASISMARK ) == SfxItemState::SET ) )
rFont.SetEmphasisMark( rSet.Get( EE_CHAR_EMPHASISMARK ).GetEmphasisMark() );
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_RELIEF ) == SfxItemState::SET ) )
rFont.SetRelief( rSet.Get( EE_CHAR_RELIEF ).GetValue() );
// Operator == compares the individual members of the font if the impl pointer is
// not equal. If all members are the same, this assignment makes
// sure that both also point to the same internal instance of the font.
// To avoid this assignment, you would need to check in
// every if statement above whether or not the new value differs from the
// old value before making an assignment.
if ( rFont == aPrevFont )
rFont = aPrevFont; // => The same ImpPointer for IsSameInstance
}
void EditDoc::CreateDefFont( bool bUseStyles )
{
SfxItemSetFixed<EE_PARA_START, EE_CHAR_END> aTmpSet( GetItemPool() );
CreateFont(maDefFont, aTmpSet);
maDefFont.SetVertical( IsEffectivelyVertical() );
maDefFont.SetOrientation( Degree10(IsEffectivelyVertical() ? (IsTopToBottom() ? 2700 : 900) : 0) );
for (std::unique_ptr<ContentNode>& pNode : maContents)
{
pNode->GetCharAttribs().GetDefFont() = maDefFont;
if (bUseStyles)
pNode->CreateDefFont();
}
}
bool EditDoc::IsEffectivelyVertical() const
{
return (mbIsVertical && mnRotation == TextRotation::NONE) ||
(!mbIsVertical && mnRotation != TextRotation::NONE);
}
bool EditDoc::IsTopToBottom() const
{
return (mbIsVertical && mnRotation == TextRotation::NONE) ||
(!mbIsVertical && mnRotation == TextRotation::TOPTOBOTTOM);
}
bool EditDoc::GetVertical() const
{
return mbIsVertical;
}
sal_Int32 EditDoc::GetPos(const ContentNode* pContentNode) const
{
return FastGetPos(maContents, pContentNode, mnLastCache);
}
const ContentNode* EditDoc::GetObject(sal_Int32 nPos) const
{
return 0 <= nPos && o3tl::make_unsigned(nPos) < maContents.size() ? maContents[nPos].get() : nullptr;
}
ContentNode* EditDoc::GetObject(sal_Int32 nPos)
{
return 0 <= nPos && o3tl::make_unsigned(nPos) < maContents.size() ? maContents[nPos].get() : nullptr;
}
void EditDoc::Insert(sal_Int32 nPos, std::unique_ptr<ContentNode> pNode)
{
if (nPos < 0 || nPos == SAL_MAX_INT32)
{
SAL_WARN( "editeng", "EditDoc::Insert - overflow pos " << nPos);
return;
}
maContents.insert(maContents.begin()+nPos, std::move(pNode));
}
void EditDoc::Remove(sal_Int32 nPos)
{
if (nPos < 0 || o3tl::make_unsigned(nPos) >= maContents.size())
{
SAL_WARN( "editeng", "EditDoc::Remove - out of bounds pos " << nPos);
return;
}
maContents.erase(maContents.begin() + nPos);
}
std::unique_ptr<ContentNode> EditDoc::Release(sal_Int32 nPos)
{
if (nPos < 0 || o3tl::make_unsigned(nPos) >= maContents.size())
{
SAL_WARN( "editeng", "EditDoc::Release - out of bounds pos " << nPos);
return nullptr;
}
std::unique_ptr<ContentNode> pNode = std::move(maContents[nPos]);
maContents.erase(maContents.begin() + nPos);
return pNode;
}
sal_Int32 EditDoc::Count() const
{
size_t nSize = maContents.size();
if (nSize > SAL_MAX_INT32)
{
SAL_WARN( "editeng", "EditDoc::Count - overflow " << nSize);
return SAL_MAX_INT32;
}
return nSize;
}
OUString EditDoc::GetSepStr( LineEnd eEnd )
{
if ( eEnd == LINEEND_CR )
return "\015"; // 0x0d
if ( eEnd == LINEEND_LF )
return "\012"; // 0x0a
return "\015\012"; // 0x0d, 0x0a
}
OUString EditDoc::GetText( LineEnd eEnd ) const
{
const sal_Int32 nNodes = Count();
if (nNodes == 0)
return OUString();
const OUString aSep = EditDoc::GetSepStr( eEnd );
const sal_Int32 nSepSize = aSep.getLength();
const sal_Int32 nLen = GetTextLen() + (nNodes - 1)*nSepSize;
OUStringBuffer aBuffer(nLen + 16); // leave some slack
for ( sal_Int32 nNode = 0; nNode < nNodes; nNode++ )
{
if ( nSepSize && nNode>0 )
{
aBuffer.append(aSep);
}
aBuffer.append(GetParaAsString( GetObject(nNode) ));
}
return aBuffer.makeStringAndClear();
}
OUString EditDoc::GetParaAsString( sal_Int32 nNode ) const
{
return GetParaAsString( GetObject( nNode ) );
}
OUString EditDoc::GetParaAsString(
const ContentNode* pNode, sal_Int32 nStartPos, sal_Int32 nEndPos)
{
return pNode->GetExpandedText(nStartPos, nEndPos);
}
EditPaM EditDoc::GetStartPaM() const
{
ContentNode* p = const_cast<ContentNode*>(GetObject(0));
return EditPaM(p, 0);
}
EditPaM EditDoc::GetEndPaM() const
{
ContentNode* pLastNode = const_cast<ContentNode*>(GetObject(Count()-1));
return EditPaM( pLastNode, pLastNode->Len() );
}
sal_Int32 EditDoc::GetTextLen() const
{
sal_Int32 nLen = 0;
for ( sal_Int32 nNode = 0; nNode < Count(); nNode++ )
{
const ContentNode* pNode = GetObject( nNode );
nLen += pNode->GetExpandedLen();
}
return nLen;
}
EditPaM EditDoc::Clear()
{
maContents.clear();
ContentNode* pNode = new ContentNode(GetItemPool());
Insert(0, std::unique_ptr<ContentNode>(pNode));
CreateDefFont(false);
SetModified(false);
return EditPaM( pNode, 0 );
}
namespace
{
struct ClearSpellErrorsHandler
{
void operator() (std::unique_ptr<ContentNode> const & rNode)
{
rNode->DestroyWrongList();
}
};
}
void EditDoc::ClearSpellErrors()
{
std::for_each(maContents.begin(), maContents.end(), ClearSpellErrorsHandler());
}
void EditDoc::SetModified( bool b )
{
mbModified = b;
if (mbModified)
maModifyHdl.Call(nullptr);
}
EditPaM EditDoc::RemoveText()
{
// Keep the old ItemSet, to keep the chart Font.
ContentNode* pPrevFirstNode = GetObject(0);
SfxStyleSheet* pPrevStyle = pPrevFirstNode->GetStyleSheet();
SfxItemSet aPrevSet( pPrevFirstNode->GetContentAttribs().GetItems() );
vcl::Font aPrevFont( pPrevFirstNode->GetCharAttribs().GetDefFont() );
maContents.clear();
ContentNode* pNode = new ContentNode(GetItemPool());
Insert(0, std::unique_ptr<ContentNode>(pNode));
pNode->SetStyleSheet(pPrevStyle, false);
pNode->GetContentAttribs().GetItems().Set( aPrevSet );
pNode->GetCharAttribs().GetDefFont() = aPrevFont;
SetModified(true);
return EditPaM(pNode, 0);
}
EditPaM EditDoc::InsertText( EditPaM aPaM, std::u16string_view rStr )
{
DBG_ASSERT( rStr.find( 0x0A ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
DBG_ASSERT( rStr.find( 0x0D ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
DBG_ASSERT( rStr.find( '\t' ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
assert(aPaM.GetNode());
aPaM.GetNode()->Insert( rStr, aPaM.GetIndex() );
aPaM.GetNode()->ExpandAttribs( aPaM.GetIndex(), rStr.size() );
aPaM.SetIndex( aPaM.GetIndex() + rStr.size() );
SetModified( true );
return aPaM;
}
EditPaM EditDoc::InsertParaBreak( EditPaM aPaM, bool bKeepEndingAttribs )
{
assert(aPaM.GetNode());
ContentNode* pCurNode = aPaM.GetNode();
sal_Int32 nPos = GetPos( pCurNode );
OUString aStr = aPaM.GetNode()->Copy( aPaM.GetIndex() );
aPaM.GetNode()->Erase( aPaM.GetIndex() );
// the paragraph attributes...
ContentAttribs aContentAttribs( aPaM.GetNode()->GetContentAttribs() );
// for a new paragraph we like to have the bullet/numbering visible by default
aContentAttribs.GetItems().Put( SfxBoolItem( EE_PARA_BULLETSTATE, true) );
// ContentNode constructor copies also the paragraph attributes
ContentNode* pNode = new ContentNode(aStr, std::move(aContentAttribs));
// Copy the Default Font
pNode->GetCharAttribs().GetDefFont() = aPaM.GetNode()->GetCharAttribs().GetDefFont();
SfxStyleSheet* pStyle = aPaM.GetNode()->GetStyleSheet();
if ( pStyle )
{
OUString aFollow( pStyle->GetFollow() );
if ( !aFollow.isEmpty() && ( aFollow != pStyle->GetName() ) )
{
SfxStyleSheetBase* pNext = pStyle->GetPool()->Find( aFollow, pStyle->GetFamily() );
pNode->SetStyleSheet( static_cast<SfxStyleSheet*>(pNext) );
}
}
// Character attributes may need to be copied or trimmed:
pNode->CopyAndCutAttribs( aPaM.GetNode(), GetItemPool(), bKeepEndingAttribs );
Insert(nPos+1, std::unique_ptr<ContentNode>(pNode));
SetModified(true);
aPaM.SetNode( pNode );
aPaM.SetIndex( 0 );
return aPaM;
}
EditPaM EditDoc::InsertFeature( EditPaM aPaM, const SfxPoolItem& rItem )
{
assert(aPaM.GetNode());
aPaM.GetNode()->Insert( rtl::OUStringChar(CH_FEATURE), aPaM.GetIndex() );
aPaM.GetNode()->ExpandAttribs( aPaM.GetIndex(), 1 );
// Create a feature-attribute for the feature...
EditCharAttrib* pAttrib = MakeCharAttrib( GetItemPool(), rItem, aPaM.GetIndex(), aPaM.GetIndex()+1 );
assert(pAttrib);
aPaM.GetNode()->GetCharAttribs().InsertAttrib( pAttrib );
SetModified( true );
aPaM.SetIndex( aPaM.GetIndex() + 1 );
return aPaM;
}
EditPaM EditDoc::ConnectParagraphs( ContentNode* pLeft, ContentNode* pRight )
{
const EditPaM aPaM( pLeft, pLeft->Len() );
// First the attributes, otherwise nLen will not be correct!
pLeft->AppendAttribs( pRight );
// then the Text...
pLeft->Append(pRight->GetString());
// the one to the right disappears.
sal_Int32 nRight = GetPos( pRight );
Remove( nRight );
SetModified(true);
return aPaM;
}
void EditDoc::RemoveChars( EditPaM aPaM, sal_Int32 nChars )
{
// Maybe remove Features!
aPaM.GetNode()->Erase( aPaM.GetIndex(), nChars );
aPaM.GetNode()->CollapseAttribs( aPaM.GetIndex(), nChars );
SetModified( true );
}
void EditDoc::InsertAttribInSelection( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, const SfxPoolItem& rPoolItem )
{
assert(pNode);
DBG_ASSERT( nEnd <= pNode->Len(), "InsertAttrib: Attribute too large!" );
// for Optimization:
// This ends at the beginning of the selection => can be expanded
EditCharAttrib* pEndingAttrib = nullptr;
// This starts at the end of the selection => can be expanded
EditCharAttrib* pStartingAttrib = nullptr;
DBG_ASSERT( nStart <= nEnd, "Small miscalculations in InsertAttribInSelection" );
RemoveAttribs( pNode, nStart, nEnd, pStartingAttrib, pEndingAttrib, rPoolItem.Which() );
// tdf#132288 By default inserting an attribute beside another that is of
// the same type expands the original instead of inserting another. But the
// spell check dialog doesn't want that behaviour
if (mbDisableAttributeExpanding)
{
pStartingAttrib = nullptr;
pEndingAttrib = nullptr;
}
if ( pStartingAttrib && pEndingAttrib &&
( *(pStartingAttrib->GetItem()) == rPoolItem ) &&
( *(pEndingAttrib->GetItem()) == rPoolItem ) )
{
// Will become a large Attribute.
pEndingAttrib->GetEnd() = pStartingAttrib->GetEnd();
pNode->GetCharAttribs().Remove(pStartingAttrib);
}
else if ( pStartingAttrib && ( *(pStartingAttrib->GetItem()) == rPoolItem ) )
pStartingAttrib->GetStart() = nStart;
else if ( pEndingAttrib && ( *(pEndingAttrib->GetItem()) == rPoolItem ) )
pEndingAttrib->GetEnd() = nEnd;
else
InsertAttrib( rPoolItem, pNode, nStart, nEnd );
if ( pStartingAttrib )
pNode->GetCharAttribs().ResortAttribs();
SetModified(true);
}
bool EditDoc::RemoveAttribs( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, sal_uInt16 nWhich )
{
EditCharAttrib* pStarting;
EditCharAttrib* pEnding;
return RemoveAttribs( pNode, nStart, nEnd, pStarting, pEnding, nWhich );
}
bool EditDoc::RemoveAttribs( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, EditCharAttrib*& rpStarting, EditCharAttrib*& rpEnding, sal_uInt16 nWhich )
{
assert(pNode);
DBG_ASSERT( nEnd <= pNode->Len(), "InsertAttrib: Attribute too large!" );
// This ends at the beginning of the selection => can be expanded
rpEnding = nullptr;
// This starts at the end of the selection => can be expanded
rpStarting = nullptr;
bool bChanged = false;
bool bNeedsSorting = false;
DBG_ASSERT( nStart <= nEnd, "Small miscalculations in InsertAttribInSelection" );
#if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
CharAttribList::DbgCheckAttribs(pNode->GetCharAttribs());
#endif
// iterate over the attributes ...
std::size_t nAttr = 0;
CharAttribList::AttribsType& rAttribs = pNode->GetCharAttribs().GetAttribs();
EditCharAttrib* pAttr = GetAttrib(rAttribs, nAttr);
while ( pAttr )
{
bool bRemoveAttrib = false;
sal_uInt16 nAttrWhich = pAttr->Which();
if ( ( nAttrWhich < EE_FEATURE_START ) && ( !nWhich || ( nAttrWhich == nWhich ) ) )
{
// Attribute starts in Selection
if ( ( pAttr->GetStart() >= nStart ) && ( pAttr->GetStart() <= nEnd ) )
{
bChanged = true;
if ( pAttr->GetEnd() > nEnd )
{
bNeedsSorting = true;
pAttr->GetStart() = nEnd; // then it starts after this
rpStarting = pAttr;
if ( nWhich )
break; // There can be no further attributes here
}
else if ( !pAttr->IsFeature() || ( pAttr->GetStart() == nStart ) )
{
// Delete feature only if on the exact spot
bRemoveAttrib = true;
}
}
// Attribute ends in Selection
else if ( ( pAttr->GetEnd() >= nStart ) && ( pAttr->GetEnd() <= nEnd ) )
{
bChanged = true;
if ( ( pAttr->GetStart() < nStart ) && !pAttr->IsFeature() )
{
pAttr->GetEnd() = nStart; // then it ends here
rpEnding = pAttr;
}
else if ( !pAttr->IsFeature() || ( pAttr->GetStart() == nStart ) )
{
// Delete feature only if on the exact spot
bRemoveAttrib = true;
}
}
// Attribute overlaps the selection
else if ( ( pAttr->GetStart() <= nStart ) && ( pAttr->GetEnd() >= nEnd ) )
{
bChanged = true;
if ( pAttr->GetStart() == nStart )
{
bNeedsSorting = true;
pAttr->GetStart() = nEnd;
rpStarting = pAttr;
if ( nWhich )
break; // There can be further attributes!
}
else if ( pAttr->GetEnd() == nEnd )
{
pAttr->GetEnd() = nStart;
rpEnding = pAttr;
if ( nWhich )
break; // There can be further attributes!
}
else // Attribute must be split ...
{
bNeedsSorting = true;
sal_Int32 nOldEnd = pAttr->GetEnd();
pAttr->GetEnd() = nStart;
rpEnding = pAttr;
InsertAttrib( *pAttr->GetItem(), pNode, nEnd, nOldEnd );
if ( nWhich )
break; // There can be further attributes!
}
}
}
if ( bRemoveAttrib )
{
DBG_ASSERT( ( pAttr != rpStarting ) && ( pAttr != rpEnding ), "Delete and retain the same attribute?" );
DBG_ASSERT( !pAttr->IsFeature(), "RemoveAttribs: Remove a feature?!" );
rAttribs.erase(rAttribs.begin()+nAttr);
}
else
{
nAttr++;
}
pAttr = GetAttrib(rAttribs, nAttr);
}
if ( bChanged )
{
// char attributes need to be sorted by start again
if (bNeedsSorting)
pNode->GetCharAttribs().ResortAttribs();
SetModified(true);
}
#if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
CharAttribList::DbgCheckAttribs(pNode->GetCharAttribs());
#endif
return bChanged;
}
void EditDoc::InsertAttrib( const SfxPoolItem& rPoolItem, ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd )
{
// This method no longer checks whether a corresponding attribute already
// exists at this place!
EditCharAttrib* pAttrib = MakeCharAttrib( GetItemPool(), rPoolItem, nStart, nEnd );
assert(pAttrib);
pNode->GetCharAttribs().InsertAttrib( pAttrib );
SetModified( true );
}
void EditDoc::InsertAttrib( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, const SfxPoolItem& rPoolItem )
{
if ( nStart != nEnd )
{
InsertAttribInSelection( pNode, nStart, nEnd, rPoolItem );
}
else
{
// Check whether already a new attribute with WhichId exists at this place:
CharAttribList& rAttrList = pNode->GetCharAttribs();
EditCharAttrib* pAttr = rAttrList.FindEmptyAttrib( rPoolItem.Which(), nStart );
if ( pAttr )
{
// Remove attribute...
rAttrList.Remove(pAttr);
}
// check whether 'the same' attribute exist at this place.
pAttr = rAttrList.FindAttrib( rPoolItem.Which(), nStart );
if ( pAttr )
{
if ( pAttr->IsInside( nStart ) ) // split
{
// check again if really splitting, or return !
sal_Int32 nOldEnd = pAttr->GetEnd();
pAttr->GetEnd() = nStart;
EditCharAttrib* pNew = MakeCharAttrib( GetItemPool(), *(pAttr->GetItem()), nStart, nOldEnd );
rAttrList.InsertAttrib(pNew);
}
else if ( pAttr->GetEnd() == nStart )
{
DBG_ASSERT( !pAttr->IsEmpty(), "Still an empty attribute?" );
// Check if exactly the same attribute
if ( *(pAttr->GetItem()) == rPoolItem )
return;
}
}
InsertAttrib( rPoolItem, pNode, nStart, nStart );
}
SetModified( true );
}
void EditDoc::FindAttribs( ContentNode* pNode, sal_Int32 nStartPos, sal_Int32 nEndPos, SfxItemSet& rCurSet )
{
assert(pNode);
DBG_ASSERT( nStartPos <= nEndPos, "Invalid region!" );
std::size_t nAttr = 0;
EditCharAttrib* pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
// No Selection...
if ( nStartPos == nEndPos )
{
while ( pAttr && ( pAttr->GetStart() <= nEndPos) )
{
const SfxPoolItem* pItem = nullptr;
// Attribute is about...
if ( ( pAttr->GetStart() < nStartPos ) && ( pAttr->GetEnd() > nStartPos ) )
pItem = pAttr->GetItem();
// Attribute ending here is not empty
else if ( ( pAttr->GetStart() < nStartPos ) && ( pAttr->GetEnd() == nStartPos ) )
{
if ( !pNode->GetCharAttribs().FindEmptyAttrib( pAttr->GetItem()->Which(), nStartPos ) )
pItem = pAttr->GetItem();
}
// Attribute ending here is empty
else if ( ( pAttr->GetStart() == nStartPos ) && ( pAttr->GetEnd() == nStartPos ) )
{
pItem = pAttr->GetItem();
}
// Attribute starts here
else if ( ( pAttr->GetStart() == nStartPos ) && ( pAttr->GetEnd() > nStartPos ) )
{
if ( nStartPos == 0 ) // special case
pItem = pAttr->GetItem();
}
if ( pItem )
{
sal_uInt16 nWhich = pItem->Which();
if ( rCurSet.GetItemState( nWhich ) == SfxItemState::DEFAULT )
{
rCurSet.Put( *pItem );
}
else if ( rCurSet.GetItemState( nWhich ) == SfxItemState::SET )
{
const SfxPoolItem& rItem = rCurSet.Get( nWhich );
if ( rItem != *pItem )
{
rCurSet.InvalidateItem( nWhich );
}
}
}
nAttr++;
pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
}
}
else // Selection
{
while ( pAttr && ( pAttr->GetStart() < nEndPos) )
{
const SfxPoolItem* pItem = nullptr;
// Attribute is about...
if ( ( pAttr->GetStart() <= nStartPos ) && ( pAttr->GetEnd() >= nEndPos ) )
pItem = pAttr->GetItem();
// Attribute starts right in the middle ...
else if ( pAttr->GetStart() >= nStartPos )
{
// !!! pItem = pAttr->GetItem();
// PItem is simply not enough, since one for example in case
// of Shadow, would never find an unequal item, since such a
// item represents its presence by absence!
// If (...)
// It needs to be examined on exactly the same attribute at the
// break point, which is quite expensive.
// Since optimization is done when inserting the attributes
// this case does not appear so fast...
// So based on the need for speed:
rCurSet.InvalidateItem( pAttr->GetItem()->Which() );
}
// Attribute ends in the middle of it ...
else if ( pAttr->GetEnd() > nStartPos )
{
rCurSet.InvalidateItem( pAttr->GetItem()->Which() );
}
if ( pItem )
{
sal_uInt16 nWhich = pItem->Which();
if ( rCurSet.GetItemState( nWhich ) == SfxItemState::DEFAULT )
{
rCurSet.Put( *pItem );
}
else if ( rCurSet.GetItemState( nWhich ) == SfxItemState::SET )
{
const SfxPoolItem& rItem = rCurSet.Get( nWhich );
if ( rItem != *pItem )
{
rCurSet.InvalidateItem( nWhich );
}
}
}
nAttr++;
pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
}
}
}
void EditDoc::dumpAsXml(xmlTextWriterPtr pWriter) const
{
bool bOwns = false;
if (!pWriter)
{
pWriter = xmlNewTextWriterFilename("editdoc.xml", 0);
xmlTextWriterSetIndent(pWriter,1);
(void)xmlTextWriterSetIndentString(pWriter, BAD_CAST(" "));
(void)xmlTextWriterStartDocument(pWriter, nullptr, nullptr, nullptr);
bOwns = true;
}
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("EditDoc"));
for (auto const & i : maContents)
{
i->dumpAsXml(pWriter);
}
(void)xmlTextWriterEndElement(pWriter);
if (bOwns)
{
(void)xmlTextWriterEndDocument(pWriter);
xmlFreeTextWriter(pWriter);
}
}
EditEngineItemPool::EditEngineItemPool()
: SfxItemPool( "EditEngineItemPool", EE_ITEMS_START, EE_ITEMS_END,
aItemInfos, nullptr )
{
m_xDefItems = EditDLL::Get().GetGlobalData()->GetDefItems();
SetDefaults(&m_xDefItems->getDefaults());
}
EditEngineItemPool::~EditEngineItemPool()
{
ClearDefaults();
SetSecondaryPool(nullptr);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|