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
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
|
/* -*- 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 <sal/config.h>
#include <i18nlangtag/mslangid.hxx>
#include <officecfg/Office/Common.hxx>
#include <vcl/outdev.hxx>
#include <vcl/lineinfo.hxx>
#include <vcl/metric.hxx>
#include <vcl/svapp.hxx>
#include <vcl/lazydelete.hxx>
#include <vcl/glyphitemcache.hxx>
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <breakit.hxx>
#include <paintfrm.hxx>
#include <viewsh.hxx>
#include <viewopt.hxx>
#include <fntcache.hxx>
#include <IDocumentSettingAccess.hxx>
#include <swfont.hxx>
#include <wrong.hxx>
#include <txtfrm.hxx>
#include <pagefrm.hxx>
#include <tgrditem.hxx>
#include <scriptinfo.hxx>
#include <editeng/brushitem.hxx>
#include <accessibilityoptions.hxx>
#include <svx/sdr/attribute/sdrallfillattributeshelper.hxx>
#include <doc.hxx>
#include <editeng/fhgtitem.hxx>
#include <vcl/glyphitem.hxx>
#include <vcl/vcllayout.hxx>
#include <docsh.hxx>
#include <strings.hrc>
#include <fntcap.hxx>
#include <vcl/outdev/ScopedStates.hxx>
#include <o3tl/hash_combine.hxx>
#include <cstdint>
#include <memory>
#include "justify.hxx"
using namespace ::com::sun::star;
// global variables declared in fntcache.hxx
// FontCache is created in txtinit.cxx TextInit_ and deleted in TextFinit
SwFntCache *pFntCache = nullptr;
// last Font set by ChgFntCache
SwFntObj *pLastFont = nullptr;
constexpr Color gWaveCol(COL_GRAY);
tools::Long SwFntObj::s_nPixWidth;
MapMode* SwFntObj::s_pPixMap = nullptr;
static vcl::DeleteOnDeinit< VclPtr<OutputDevice> > s_pFntObjPixOut {};
void SwFntCache::Flush( )
{
if ( pLastFont )
{
pLastFont->Unlock();
pLastFont = nullptr;
}
SwCache::Flush( );
}
SwFntObj::SwFntObj(const SwSubFont &rFont, std::uintptr_t nFontCacheId, SwViewShell const *pSh)
: SwCacheObj(reinterpret_cast<void *>(nFontCacheId))
, m_aFont(rFont)
, m_pScrFont(nullptr)
, m_pPrtFont(&m_aFont)
, m_pPrinter(nullptr)
, m_nGuessedLeading(USHRT_MAX)
, m_nExtLeading(USHRT_MAX)
, m_nScrAscent(0)
, m_nPrtAscent(USHRT_MAX)
, m_nScrHeight(0)
, m_nPrtHeight(USHRT_MAX)
, m_nPropWidth(rFont.GetPropWidth())
, m_nScrHangingBaseline(0)
, m_nPrtHangingBaseline(0)
{
m_nZoom = pSh ? pSh->GetViewOptions()->GetZoom() : USHRT_MAX;
m_bSymbol = RTL_TEXTENCODING_SYMBOL == m_aFont.GetCharSet();
m_bPaintBlank = ( LINESTYLE_NONE != m_aFont.GetUnderline()
|| LINESTYLE_NONE != m_aFont.GetOverline()
|| STRIKEOUT_NONE != m_aFont.GetStrikeout() )
&& !m_aFont.IsWordLineMode();
m_aFont.SetLanguage(rFont.GetLanguage());
}
SwFntObj::~SwFntObj()
{
if ( m_pScrFont != m_pPrtFont )
delete m_pScrFont;
if ( m_pPrtFont != &m_aFont )
delete m_pPrtFont;
}
void SwFntObj::CreatePrtFont( const OutputDevice& rPrt )
{
if ( m_nPropWidth == 100 || m_pPrinter == &rPrt )
return;
if( m_pScrFont != m_pPrtFont )
delete m_pScrFont;
if( m_pPrtFont != &m_aFont )
delete m_pPrtFont;
const vcl::Font aOldFnt( rPrt.GetFont() );
const_cast<OutputDevice&>(rPrt).SetFont( m_aFont );
const FontMetric aWinMet( rPrt.GetFontMetric() );
const_cast<OutputDevice&>(rPrt).SetFont( aOldFnt );
auto nWidth = ( aWinMet.GetFontSize().Width() * m_nPropWidth ) / 100;
if( !nWidth )
++nWidth;
m_pPrtFont = new vcl::Font( m_aFont );
m_pPrtFont->SetFontSize( Size( nWidth, m_aFont.GetFontSize().Height() ) );
m_pScrFont = nullptr;
}
/*
* returns whether we have to adjust the output font to resemble
* the formatting font
*
* _Not_ necessary if
*
* 1. RefDef == OutDev (text formatting, online layout...)
* 2. PDF export from online layout
* 3. Prospect/PagePreview printing
*/
static bool lcl_IsFontAdjustNecessary( const vcl::RenderContext& rOutDev,
const vcl::RenderContext& rRefDev )
{
return &rRefDev != &rOutDev &&
OUTDEV_WINDOW != rRefDev.GetOutDevType() &&
( OUTDEV_PRINTER != rRefDev.GetOutDevType() ||
OUTDEV_PRINTER != rOutDev.GetOutDevType() );
}
namespace {
struct CalcLinePosData
{
SwDrawTextInfo& rInf;
vcl::Font& rFont;
TextFrameIndex nCnt;
const bool bSwitchH2V;
const bool bSwitchH2VLRBT;
const bool bSwitchL2R;
tools::Long nHalfSpace;
sal_Int32* pKernArray;
const bool bBidiPor;
CalcLinePosData( SwDrawTextInfo& _rInf, vcl::Font& _rFont,
TextFrameIndex const _nCnt, const bool _bSwitchH2V, const bool _bSwitchH2VLRBT, const bool _bSwitchL2R,
tools::Long _nHalfSpace, sal_Int32* _pKernArray, const bool _bBidiPor) :
rInf( _rInf ),
rFont( _rFont ),
nCnt( _nCnt ),
bSwitchH2V( _bSwitchH2V ),
bSwitchH2VLRBT( _bSwitchH2VLRBT ),
bSwitchL2R( _bSwitchL2R ),
nHalfSpace( _nHalfSpace ),
pKernArray( _pKernArray ),
bBidiPor( _bBidiPor )
{
}
};
}
// Computes the start and end position of an underline. This function is called
// from the DrawText-method (for underlining misspelled words or smarttag terms).
static void lcl_calcLinePos( const CalcLinePosData &rData,
Point &rStart, Point &rEnd, TextFrameIndex const nStart, TextFrameIndex const nWrLen)
{
tools::Long nBlank = 0;
const TextFrameIndex nEnd = nStart + nWrLen;
const tools::Long nTmpSpaceAdd = rData.rInf.GetSpace() / SPACING_PRECISION_FACTOR;
if ( nEnd < rData.nCnt
&& CH_BLANK == rData.rInf.GetText()[sal_Int32(rData.rInf.GetIdx() + nEnd)] )
{
if (nEnd + TextFrameIndex(1) == rData.nCnt)
nBlank -= nTmpSpaceAdd;
else
nBlank -= rData.nHalfSpace;
}
// determine start, end and length of wave line
sal_Int32 nKernStart = nStart ? rData.pKernArray[sal_Int32(nStart) - 1] : 0;
sal_Int32 nKernEnd = rData.pKernArray[sal_Int32(nEnd) - 1];
const Degree10 nDir = rData.bBidiPor ? 1800_deg10
: UnMapDirection(rData.rFont.GetOrientation(),
rData.bSwitchH2V, rData.bSwitchH2VLRBT);
switch ( nDir.get() )
{
case 0 :
rStart.AdjustX(nKernStart );
rEnd.setX( nBlank + rData.rInf.GetPos().X() + nKernEnd );
rEnd.setY( rData.rInf.GetPos().Y() );
break;
case 900 :
rStart.AdjustY( -nKernStart );
rEnd.setX( rData.rInf.GetPos().X() );
rEnd.setY( nBlank + rData.rInf.GetPos().Y() - nKernEnd );
break;
case 1800 :
rStart.AdjustX( -nKernStart );
rEnd.setX( rData.rInf.GetPos().X() - nKernEnd - nBlank );
rEnd.setY( rData.rInf.GetPos().Y() );
break;
case 2700 :
rStart.AdjustY(nKernStart );
rEnd.setX( rData.rInf.GetPos().X() );
rEnd.setY( nBlank + rData.rInf.GetPos().Y() + nKernEnd );
break;
}
if ( rData.bSwitchL2R )
{
rData.rInf.GetFrame()->SwitchLTRtoRTL( rStart );
rData.rInf.GetFrame()->SwitchLTRtoRTL( rEnd );
}
if ( rData.bSwitchH2V )
{
rData.rInf.GetFrame()->SwitchHorizontalToVertical( rStart );
rData.rInf.GetFrame()->SwitchHorizontalToVertical( rEnd );
}
}
// Returns the Ascent of the Font on the given output device;
// it may be necessary to create the screen font first.
sal_uInt16 SwFntObj::GetFontAscent( const SwViewShell *pSh, const OutputDevice& rOut )
{
sal_uInt16 nRet = 0;
const OutputDevice& rRefDev = pSh ? pSh->GetRefDev() : rOut;
if ( pSh && lcl_IsFontAdjustNecessary( rOut, rRefDev ) )
{
CreateScrFont( *pSh, rOut );
OSL_ENSURE( USHRT_MAX != m_nScrAscent, "nScrAscent is going berzerk" );
nRet = m_nScrAscent;
}
else
{
if (m_nPrtAscent == USHRT_MAX) // printer ascent unknown?
{
CreatePrtFont( rOut );
const vcl::Font aOldFnt( rRefDev.GetFont() );
const_cast<OutputDevice&>(rRefDev).SetFont( *m_pPrtFont );
const FontMetric aOutMet( rRefDev.GetFontMetric() );
m_nPrtAscent = o3tl::narrowing<sal_uInt16>(aOutMet.GetAscent());
m_nPrtHangingBaseline = o3tl::narrowing<sal_uInt16>(aOutMet.GetHangingBaseline());
const_cast<OutputDevice&>(rRefDev).SetFont( aOldFnt );
}
nRet = m_nPrtAscent;
}
#if !defined(MACOSX) // #i89844# extleading is below the line for Mac
// TODO: move extleading below the line for all platforms too
nRet += GetFontLeading( pSh, rRefDev );
#endif
OSL_ENSURE( USHRT_MAX != nRet, "GetFontAscent returned USHRT_MAX" );
return nRet;
}
// Returns the height of the Font on the given output device;
// it may be necessary to create the screen font first.
sal_uInt16 SwFntObj::GetFontHeight( const SwViewShell* pSh, const OutputDevice& rOut )
{
sal_uInt16 nRet = 0;
const OutputDevice& rRefDev = pSh ? pSh->GetRefDev() : rOut;
if ( pSh && lcl_IsFontAdjustNecessary( rOut, rRefDev ) )
{
CreateScrFont( *pSh, rOut );
OSL_ENSURE( USHRT_MAX != m_nScrHeight, "nScrHeight is going berzerk" );
nRet = m_nScrHeight + GetFontLeading( pSh, rRefDev );
}
else
{
if (m_nPrtHeight == USHRT_MAX) // printer height unknown?
{
CreatePrtFont( rOut );
const vcl::Font aOldFnt( rRefDev.GetFont() );
const_cast<OutputDevice&>(rRefDev).SetFont( *m_pPrtFont );
m_nPrtHeight = o3tl::narrowing<sal_uInt16>(rRefDev.GetTextHeight());
#if OSL_DEBUG_LEVEL > 0
// Check if vcl did not change the meaning of GetTextHeight
const FontMetric aOutMet( rRefDev.GetFontMetric() );
tools::Long nTmpPrtHeight = o3tl::narrowing<sal_uInt16>(aOutMet.GetAscent()) + aOutMet.GetDescent();
// #i106098#: do not compare with == here due to rounding error
OSL_ENSURE( std::abs(nTmpPrtHeight - m_nPrtHeight) < 3,
"GetTextHeight != Ascent + Descent" );
#endif
const_cast<OutputDevice&>(rRefDev).SetFont( aOldFnt );
}
nRet = m_nPrtHeight + GetFontLeading( pSh, rRefDev );
}
OSL_ENSURE( USHRT_MAX != nRet, "GetFontHeight returned USHRT_MAX" );
return nRet;
}
sal_uInt16 SwFntObj::GetFontLeading( const SwViewShell *pSh, const OutputDevice& rOut )
{
sal_uInt16 nRet = 0;
if ( pSh )
{
if ( USHRT_MAX == m_nGuessedLeading || USHRT_MAX == m_nExtLeading )
{
SolarMutexGuard aGuard;
const vcl::Font aOldFnt( rOut.GetFont() );
const_cast<OutputDevice&>(rOut).SetFont( *m_pPrtFont );
const FontMetric aMet( rOut.GetFontMetric() );
const_cast<OutputDevice&>(rOut).SetFont( aOldFnt );
m_bSymbol = RTL_TEXTENCODING_SYMBOL == aMet.GetCharSet();
GuessLeading( *pSh, aMet );
m_nExtLeading = o3tl::narrowing<sal_uInt16>(aMet.GetExternalLeading());
/* HACK: FIXME There is something wrong with Writer's bullet rendering, causing lines
with bullets to be higher than they should be. I think this is because
Writer uses font's external leading incorrect, as the vertical distance
added to every line instead of only a distance between multiple lines,
which means a single bullet has external leading added even though it
shouldn't, but frankly this is just an educated guess rather than understanding
Writer's layout (heh).
Symbol font in some documents is 'StarSymbol; Arial Unicode MS', and Windows
machines often do not have StarSymbol, falling back to Arial Unicode MS, which
has unusually high external leading. So just reset external leading for fonts
which are used to bullets, as those should not be used on multiple lines anyway,
so in correct rendering external leading should be irrelevant anyway.
Interestingly enough, bSymbol is false for 'StarSymbol; Arial Unicode MS', so
also check explicitly.
*/
if( m_bSymbol || IsStarSymbol( m_pPrtFont->GetFamilyName()))
m_nExtLeading = 0;
}
const IDocumentSettingAccess& rIDSA = pSh->getIDocumentSettingAccess();
const bool bBrowse = ( pSh->GetWin() &&
pSh->GetViewOptions()->getBrowseMode() &&
!pSh->GetViewOptions()->IsPrtFormat() );
if ( !bBrowse && rIDSA.get(DocumentSettingId::ADD_EXT_LEADING) )
nRet = m_nExtLeading;
else
nRet = m_nGuessedLeading;
}
OSL_ENSURE( USHRT_MAX != nRet, "GetFontLeading returned USHRT_MAX" );
return nRet;
}
sal_uInt16 SwFntObj::GetFontHangingBaseline( const SwViewShell* pSh, const OutputDevice& rOut )
{
sal_uInt16 nRet = 0;
const OutputDevice& rRefDev = pSh ? pSh->GetRefDev() : rOut;
GetFontAscent(pSh, rOut);
if ( pSh && lcl_IsFontAdjustNecessary( rOut, rRefDev ) )
nRet = m_nScrHangingBaseline;
else
nRet = m_nPrtHangingBaseline;
return nRet;
}
// pOut is the output device, not the reference device
void SwFntObj::CreateScrFont( const SwViewShell& rSh, const OutputDevice& rOut )
{
if ( m_pScrFont )
return;
// any changes to the output device are reset at the end of the function
OutputDevice* pOut = const_cast<OutputDevice*>(&rOut);
// Save old font
vcl::Font aOldOutFont( pOut->GetFont() );
m_nScrHeight = USHRT_MAX;
// Condition for output font / refdev font adjustment
OutputDevice* pPrt = &rSh.GetRefDev();
if( !rSh.GetWin() ||
!rSh.GetViewOptions()->getBrowseMode() ||
rSh.GetViewOptions()->IsPrtFormat() )
{
// After CreatePrtFont m_pPrtFont is the font which is actually used
// by the reference device
CreatePrtFont( *pPrt );
m_pPrinter = pPrt;
// save old reference device font
vcl::Font aOldPrtFnt( pPrt->GetFont() );
// set the font used at the reference device at the reference device
// and the output device
pPrt->SetFont( *m_pPrtFont );
pOut->SetFont( *m_pPrtFont );
// This should be the default for pScrFont.
m_pScrFont = m_pPrtFont;
FontMetric aMet = pPrt->GetFontMetric( );
// Don't lose "faked" properties of the logical font that don't truly
// exist in the physical font metrics which vcl which fake up for us
aMet.SetWeight(m_pScrFont->GetWeight());
aMet.SetItalic(m_pScrFont->GetItalic());
m_bSymbol = RTL_TEXTENCODING_SYMBOL == aMet.GetCharSet();
if ( USHRT_MAX == m_nGuessedLeading )
GuessLeading( rSh, aMet );
if ( USHRT_MAX == m_nExtLeading )
m_nExtLeading = o3tl::narrowing<sal_uInt16>(aMet.GetExternalLeading());
// reset the original reference device font
pPrt->SetFont( aOldPrtFnt );
}
else
{
m_bSymbol = RTL_TEXTENCODING_SYMBOL == m_aFont.GetCharSet();
if ( m_nGuessedLeading == USHRT_MAX )
m_nGuessedLeading = 0;
// no external leading in browse mode
if ( m_nExtLeading == USHRT_MAX )
m_nExtLeading = 0;
m_pScrFont = m_pPrtFont;
}
m_nScrAscent = o3tl::narrowing<sal_uInt16>(pOut->GetFontMetric().GetAscent());
m_nScrHangingBaseline = o3tl::narrowing<sal_uInt16>(pOut->GetFontMetric().GetHangingBaseline());
if ( USHRT_MAX == m_nScrHeight )
m_nScrHeight = o3tl::narrowing<sal_uInt16>(pOut->GetTextHeight());
// reset original output device font
pOut->SetFont( aOldOutFont );
}
void SwFntObj::GuessLeading( const SwViewShell&
#if defined(_WIN32)
rSh
#endif
, const FontMetric& rMet )
{
// If leading >= 5, this seems to be enough leading.
// Nothing has to be done.
if ( rMet.GetInternalLeading() >= 5 )
{
m_nGuessedLeading = 0;
return;
}
#if defined(_WIN32)
OutputDevice *pWin = rSh.GetWin() ?
rSh.GetWin()->GetOutDev() :
Application::GetDefaultDevice();
if ( pWin )
{
MapMode aTmpMap( MapUnit::MapTwip );
MapMode aOldMap = pWin->GetMapMode( );
pWin->SetMapMode( aTmpMap );
const vcl::Font aOldFnt( pWin->GetFont() );
pWin->SetFont( *m_pPrtFont );
const FontMetric aWinMet( pWin->GetFontMetric() );
const sal_uInt16 nWinHeight = sal_uInt16( aWinMet.GetFontSize().Height() );
if( m_pPrtFont->GetFamilyName().indexOf( aWinMet.GetFamilyName() ) != -1 )
{
// If the Leading on the Window is also 0, then it has to stay
// that way (see also StarMath).
tools::Long nTmpLeading = aWinMet.GetInternalLeading();
if( nTmpLeading <= 0 )
{
pWin->SetFont( rMet );
nTmpLeading = pWin->GetFontMetric().GetInternalLeading();
if( nTmpLeading < 0 )
m_nGuessedLeading = 0;
else
m_nGuessedLeading = sal_uInt16(nTmpLeading);
}
else
{
m_nGuessedLeading = sal_uInt16(nTmpLeading);
// Manta-Hack #50153#:
// Wer beim Leading luegt, luegt moeglicherweise auch beim
// Ascent/Descent, deshalb wird hier ggf. der Font ein wenig
// tiefergelegt, ohne dabei seine Hoehe zu aendern.
// (above original comment preserved for cultural reasons)
// Those who lie about their Leading, may lie about their
// Ascent/Descent as well, hence the Font will be lowered a
// little without changing its height.
tools::Long nDiff = std::min( rMet.GetDescent() - aWinMet.GetDescent(),
aWinMet.GetAscent() - rMet.GetAscent() - nTmpLeading );
if( nDiff > 0 )
{
OSL_ENSURE( m_nPrtAscent < USHRT_MAX, "GuessLeading: PrtAscent-Fault" );
if ( m_nPrtAscent < USHRT_MAX )
m_nPrtAscent = m_nPrtAscent + o3tl::narrowing<sal_uInt16>(( 2 * nDiff ) / 5);
}
}
}
else
{
// If all else fails, take 15% of the height, as empirically
// determined by CL
m_nGuessedLeading = (nWinHeight * 15) / 100;
}
pWin->SetFont( aOldFnt );
pWin->SetMapMode( aOldMap );
}
else
m_nGuessedLeading = 0;
#else
m_nGuessedLeading = 0;
#endif
}
// Set the font at the given output device; for screens it may be
// necessary to do some adjustment first.
void SwFntObj::SetDevFont( const SwViewShell *pSh, OutputDevice& rOut )
{
const OutputDevice& rRefDev = pSh ? pSh->GetRefDev() : rOut;
if ( pSh && lcl_IsFontAdjustNecessary( rOut, rRefDev ) )
{
CreateScrFont( *pSh, rOut );
if( !GetScrFont()->IsSameInstance( rOut.GetFont() ) )
rOut.SetFont( *m_pScrFont );
if( m_pPrinter && ( !m_pPrtFont->IsSameInstance( m_pPrinter->GetFont() ) ) )
m_pPrinter->SetFont( *m_pPrtFont );
}
else
{
CreatePrtFont( rOut );
if( !m_pPrtFont->IsSameInstance( rOut.GetFont() ) )
rOut.SetFont( *m_pPrtFont );
}
// Here, we actually do not need the leading values, but by calling
// GetFontLeading() we assure that the values are calculated for later use.
GetFontLeading( pSh, rRefDev );
}
#define WRONG_SHOW_MIN 5
/*
* Output text:
* on screen => DrawTextArray
* on printer, !Kerning => DrawText
* on printer + Kerning => DrawStretchText
*/
static bool lcl_IsMonoSpaceFont( const vcl::RenderContext& rOut )
{
const tools::Long nWidth1 = rOut.GetTextWidth( OUString( u'\x3008' ) );
const tools::Long nWidth2 = rOut.GetTextWidth( OUString( u'\x307C' ) );
return nWidth1 == nWidth2;
}
static bool lcl_IsFullstopCentered( const vcl::RenderContext& rOut )
{
const FontMetric aMetric( rOut.GetFontMetric() );
return aMetric.IsFullstopCentered() ;
}
/* This helper structure (SwForbidden) contains the already marked parts of the string
to avoid double lines (e.g grammar + spell check error) */
typedef std::vector<std::pair<TextFrameIndex, TextFrameIndex>> SwForbidden;
static void lcl_DrawLineForWrongListData(
SwForbidden &rForbidden,
const SwDrawTextInfo &rInf,
sw::WrongListIterator *pWList,
const CalcLinePosData &rCalcLinePosData,
const Size &rPrtFontSize )
{
if (!pWList) return;
TextFrameIndex nStart = rInf.GetIdx();
TextFrameIndex nWrLen = rInf.GetLen();
// check if respective data is available in the current text range
if (!pWList->Check( nStart, nWrLen ))
{
return;
}
tools::Long nHght = rInf.GetOut().LogicToPixel( rPrtFontSize ).Height();
// Draw wavy lines for spell and grammar errors only if font is large enough.
// Lines for smart tags will always be drawn.
if (pWList != rInf.GetSmartTags() && WRONG_SHOW_MIN >= nHght)
{
return;
}
SwForbidden::iterator pIter = rForbidden.begin();
if (rInf.GetOut().GetConnectMetaFile())
rInf.GetOut().Push();
const Color aCol( rInf.GetOut().GetLineColor() );
// iterate over all ranges stored in the respective SwWrongList
do
{
nStart -= rInf.GetIdx();
const TextFrameIndex nEnd = nStart + nWrLen;
TextFrameIndex nNext = nStart;
while( nNext < nEnd )
{
while( pIter != rForbidden.end() && pIter->second <= nNext )
++pIter;
const TextFrameIndex nNextStart = nNext;
TextFrameIndex nNextEnd = nEnd;
if( pIter == rForbidden.end() || nNextEnd <= pIter->first )
{
// No overlapping mark up found
rForbidden.insert(pIter, std::make_pair(nNextStart, nNextEnd));
pIter = rForbidden.begin();
nNext = nEnd;
}
else
{
nNext = pIter->second;
if( nNextStart < pIter->first )
{
nNextEnd = pIter->first;
pIter->first = nNextStart;
}
else
continue;
}
// determine line pos
Point aStart( rInf.GetPos() );
Point aEnd;
lcl_calcLinePos( rCalcLinePosData, aStart, aEnd, nNextStart, nNextEnd - nNextStart );
SwWrongArea const*const wrongArea = pWList->GetWrongElement(nNextStart + rInf.GetIdx());
if (wrongArea != nullptr)
{
const SwViewShell* pShell = rInf.GetShell();
sal_uInt16 nZoom = pShell ? round(pShell->GetViewOptions()->GetZoom()/100) : 1;
if (WRONGAREA_WAVE == wrongArea->mLineType)
{
vcl::ScopedAntialiasing a(rInf.GetOut(), true);
rInf.GetOut().SetLineColor( wrongArea->mColor );
rInf.GetOut().DrawWaveLine( aStart, aEnd, 1 + nZoom, 3 + nZoom );
}
else if (WRONGAREA_BOLDWAVE == wrongArea->mLineType)
{
vcl::ScopedAntialiasing a(rInf.GetOut(), true);
rInf.GetOut().SetLineColor( wrongArea->mColor );
rInf.GetOut().DrawWaveLine( aStart, aEnd, 2 + nZoom, 4 + nZoom );
}
else if (WRONGAREA_BOLD == wrongArea->mLineType)
{
rInf.GetOut().SetLineColor( wrongArea->mColor );
aStart.AdjustY(30 );
aEnd.AdjustY(30 );
LineInfo aLineInfo( LineStyle::Solid, 26 );
rInf.GetOut().DrawLine( aStart, aEnd, aLineInfo );
}
else if (WRONGAREA_DASHED == wrongArea->mLineType)
{
rInf.GetOut().SetLineColor( wrongArea->mColor );
aStart.AdjustY(30 );
aEnd.AdjustY(30 );
LineInfo aLineInfo( LineStyle::Dash );
aLineInfo.SetDistance( 40 );
aLineInfo.SetDashLen( 1 );
aLineInfo.SetDashCount(1);
rInf.GetOut().DrawLine( aStart, aEnd, aLineInfo );
}
}
}
nStart = nEnd + rInf.GetIdx();
nWrLen = rInf.GetIdx() + rInf.GetLen() - nStart;
}
while (nWrLen && pWList->Check( nStart, nWrLen ));
rInf.GetOut().SetLineColor( aCol );
if (rInf.GetOut().GetConnectMetaFile())
rInf.GetOut().Pop();
}
static void GetTextArray(const OutputDevice& rDevice, const OUString& rStr, std::vector<sal_Int32>& rDXAry,
sal_Int32 nIndex, sal_Int32 nLen, const vcl::text::TextLayoutCache* layoutCache = nullptr)
{
const SalLayoutGlyphs* pLayoutCache = SalLayoutGlyphsCache::self()->GetLayoutGlyphs(&rDevice, rStr, nIndex, nLen,
0, layoutCache);
rDevice.GetTextArray(rStr, &rDXAry, nIndex, nLen, layoutCache, pLayoutCache);
}
static void GetTextArray(const OutputDevice& rOutputDevice, const SwDrawTextInfo& rInf, std::vector<sal_Int32>& rDXAry)
{
return GetTextArray(rOutputDevice, rInf.GetText(), rDXAry, rInf.GetIdx().get(), rInf.GetLen().get(), rInf.GetVclCache());
}
static void GetTextArray(const OutputDevice& rOutputDevice, const SwDrawTextInfo& rInf, std::vector<sal_Int32>& rDXAry, sal_Int32 nLen)
{
// Substring is fine.
assert( nLen <= rInf.GetLen().get());
return GetTextArray(rOutputDevice, rInf.GetText(), rDXAry, rInf.GetIdx().get(), nLen, rInf.GetVclCache());
}
void SwFntObj::DrawText( SwDrawTextInfo &rInf )
{
OSL_ENSURE( rInf.GetShell(), "SwFntObj::DrawText without shell" );
OutputDevice& rRefDev = rInf.GetShell()->GetRefDev();
vcl::Window* pWin = rInf.GetShell()->GetWin();
// true if pOut is the printer and the printer has been used for formatting
const bool bPrt = OUTDEV_PRINTER == rInf.GetOut().GetOutDevType() &&
OUTDEV_PRINTER == rRefDev.GetOutDevType();
const bool bBrowse = ( pWin &&
rInf.GetShell()->GetViewOptions()->getBrowseMode() &&
!rInf.GetShell()->GetViewOptions()->IsPrtFormat() &&
!rInf.GetBullet() &&
( rInf.GetSpace() || !rInf.GetKern() ) &&
!rInf.GetWrong() &&
!rInf.GetGrammarCheck() &&
!rInf.GetSmartTags() &&
!rInf.GetGreyWave() );
// bDirectPrint indicates that we can enter the branch which calls
// the DrawText functions instead of calling the DrawTextArray functions
const bool bDirectPrint = bPrt || bBrowse;
// Condition for output font / refdev font adjustment
const bool bUseScrFont =
lcl_IsFontAdjustNecessary( rInf.GetOut(), rRefDev );
vcl::Font* pTmpFont = bUseScrFont ? m_pScrFont : m_pPrtFont;
// bDirectPrint and bUseScrFont should have these values:
// Outdev / RefDef | Printer | VirtPrinter | Window
// Printer | 1 - 0 | 0 - 1 | -
// VirtPrinter/PDF | 0 - 1 | 0 - 1 | -
// Window/VirtWindow| 0 - 1 | 0 - 1 | 1 - 0
// Exception: During painting of a Writer OLE object, we do not have
// a window. Therefore bUseSrcFont is always 0 in this case.
#if OSL_DEBUG_LEVEL > 0
const bool bNoAdjust = bPrt ||
( pWin &&
rInf.GetShell()->GetViewOptions()->getBrowseMode() &&
!rInf.GetShell()->GetViewOptions()->IsPrtFormat() );
if ( OUTDEV_PRINTER == rInf.GetOut().GetOutDevType() )
{
// Printer output
if ( OUTDEV_PRINTER == rRefDev.GetOutDevType() )
{
OSL_ENSURE( bNoAdjust && !bUseScrFont, "Outdev Check failed" );
}
else if ( rRefDev.IsVirtual() )
{
OSL_ENSURE( !bNoAdjust && bUseScrFont, "Outdev Check failed" );
}
else
{
OSL_FAIL( "Outdev Check failed" );
}
}
else if ( rInf.GetOut().IsVirtual() && ! pWin )
{
// PDF export
if ( OUTDEV_PRINTER == rRefDev.GetOutDevType() )
{
OSL_ENSURE( !bNoAdjust && bUseScrFont, "Outdev Check failed" );
}
else if ( rRefDev.IsVirtual() )
{
OSL_ENSURE( !bNoAdjust && bUseScrFont, "Outdev Check failed" );
}
else
{
OSL_FAIL( "Outdev Check failed" );
}
}
else if ( OUTDEV_WINDOW == rInf.GetOut().GetOutDevType() ||
( rInf.GetOut().IsVirtual() && pWin ) )
{
// Window or virtual window
if ( OUTDEV_PRINTER == rRefDev.GetOutDevType() )
{
OSL_ENSURE( !bNoAdjust && bUseScrFont, "Outdev Check failed" );
}
else if ( rRefDev.IsVirtual() )
{
OSL_ENSURE( !bNoAdjust && bUseScrFont, "Outdev Check failed" );
}
else if ( OUTDEV_WINDOW == rRefDev.GetOutDevType() )
{
OSL_ENSURE( bNoAdjust && !bUseScrFont, "Outdev Check failed" );
}
else
{
OSL_FAIL( "Outdev Check failed" );
}
}
else
{
OSL_FAIL( "Outdev Check failed" );
}
#endif
// robust: better use the printer font instead of using no font at all
OSL_ENSURE( pTmpFont, "No screen or printer font?" );
if ( ! pTmpFont )
pTmpFont = m_pPrtFont;
// HACK: LINESTYLE_WAVE must not be abused any more, hence the grey wave
// line of the ExtendedAttributeSets will appear in the font color first
const bool bSwitchH2V = rInf.GetFrame() && rInf.GetFrame()->IsVertical();
const bool bSwitchH2VLRBT = rInf.GetFrame() && rInf.GetFrame()->IsVertLRBT();
const bool bSwitchL2R = rInf.GetFrame() && rInf.GetFrame()->IsRightToLeft() &&
! rInf.IsIgnoreFrameRTL();
const vcl::text::ComplexTextLayoutFlags nMode = rInf.GetOut().GetLayoutMode();
const bool bBidiPor = ( bSwitchL2R !=
( vcl::text::ComplexTextLayoutFlags::Default != ( vcl::text::ComplexTextLayoutFlags::BiDiRtl & nMode ) ) );
// be sure to have the correct layout mode at the printer
if ( m_pPrinter )
{
m_pPrinter->SetLayoutMode( rInf.GetOut().GetLayoutMode() );
m_pPrinter->SetDigitLanguage( rInf.GetOut().GetDigitLanguage() );
}
Point aTextOriginPos( rInf.GetPos() );
if( !bPrt )
{
if( rInf.GetpOut() != *s_pFntObjPixOut.get() || rInf.GetOut().GetMapMode() != *s_pPixMap )
{
*s_pPixMap = rInf.GetOut().GetMapMode();
(*s_pFntObjPixOut.get()) = rInf.GetpOut();
Size aTmp( 1, 1 );
s_nPixWidth = rInf.GetOut().PixelToLogic( aTmp ).Width();
}
aTextOriginPos.AdjustX(rInf.GetFrame()->IsRightToLeft() ? 0 : s_nPixWidth );
}
Color aOldColor( pTmpFont->GetColor() );
bool bChgColor = rInf.ApplyAutoColor( pTmpFont );
if( !pTmpFont->IsSameInstance( rInf.GetOut().GetFont() ) )
rInf.GetOut().SetFont( *pTmpFont );
if ( bChgColor )
pTmpFont->SetColor( aOldColor );
if (TextFrameIndex(COMPLETE_STRING) == rInf.GetLen())
rInf.SetLen( TextFrameIndex(rInf.GetText().getLength()) );
// ASIAN LINE AND CHARACTER GRID MODE START
if ( rInf.GetFrame() && rInf.SnapToGrid() && rInf.GetFont() &&
SwFontScript::CJK == rInf.GetFont()->GetActual() )
{
SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrame()->FindPageFrame()));
// ASIAN LINE AND CHARACTER GRID MODE
if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
{
//for textgrid refactor
const SwDoc* pDoc = rInf.GetShell()->GetDoc();
const tools::Long nGridWidth = GetGridWidth(*pGrid, *pDoc);
tools::Long nSpaceAdd = rInf.GetSpace() / SPACING_PRECISION_FACTOR;
// kerning array - gives the absolute position of end of each character
std::vector<sal_Int32> aKernArray;
if ( m_pPrinter )
GetTextArray(*m_pPrinter, rInf, aKernArray);
else
GetTextArray(rInf.GetOut(), rInf, aKernArray);
tools::Long nDelta = 0;
if (pGrid->IsSnapToChars())
{
nDelta = Justify::SnapToGrid(aKernArray, rInf.GetText(), sal_Int32(rInf.GetIdx()),
sal_Int32(rInf.GetLen()), nGridWidth, false);
}
else
{
Justify::SnapToGridEdge(aKernArray, sal_Int32(rInf.GetLen()), nGridWidth,
nSpaceAdd, rInf.GetKern());
}
if (nDelta)
aTextOriginPos.AdjustX(nDelta);
if ( bSwitchH2V )
rInf.GetFrame()->SwitchHorizontalToVertical( aTextOriginPos );
rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(),
aKernArray, sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
return;
}
}
// DIRECT PAINTING WITHOUT SCREEN ADJUSTMENT
if ( bDirectPrint )
{
const Fraction aTmp( 1, 1 );
bool bStretch = rInf.GetWidth() && (rInf.GetLen() > TextFrameIndex(1)) && bPrt
&& ( aTmp != rInf.GetOut().GetMapMode().GetScaleX() );
if ( bSwitchL2R )
rInf.GetFrame()->SwitchLTRtoRTL( aTextOriginPos );
if ( bSwitchH2V )
rInf.GetFrame()->SwitchHorizontalToVertical( aTextOriginPos );
// In the good old days we used to have a simple DrawText if the
// output device is the printer. Now we need a DrawTextArray if
// 1. KanaCompression is enabled
// 2. Justified alignment
// Simple kerning is handled by DrawStretchText
if( rInf.GetSpace() || rInf.GetKanaComp() )
{
std::vector<sal_Int32> aKernArray;
GetTextArray(rInf.GetOut(), rInf, aKernArray);
if( bStretch )
{
sal_Int32 nZwi = sal_Int32(rInf.GetLen()) - 1;
tools::Long nDiff = rInf.GetWidth() - aKernArray[ nZwi ]
- sal_Int32(rInf.GetLen()) * rInf.GetKern();
tools::Long nRest = nDiff % nZwi;
tools::Long nAdd;
if( nRest < 0 )
{
nAdd = -1;
nRest += nZwi;
}
else
{
nAdd = +1;
nRest = nZwi - nRest;
}
nDiff /= nZwi;
tools::Long nSum = nDiff;
for( sal_Int32 i = 0; i < nZwi; )
{
aKernArray[ i ] += nSum;
if( ++i == nRest )
nDiff += nAdd;
nSum += nDiff;
}
}
// Modify Array for special justifications
tools::Long nSpaceAdd = rInf.GetSpace() / SPACING_PRECISION_FACTOR;
bool bSpecialJust = false;
if ( rInf.GetFont() && rInf.GetLen() )
{
const SwScriptInfo* pSI = rInf.GetScriptInfo();
const SwFontScript nActual = rInf.GetFont()->GetActual();
// Kana Compression
if ( SwFontScript::CJK == nActual && rInf.GetKanaComp() &&
pSI && pSI->CountCompChg() &&
lcl_IsMonoSpaceFont( rInf.GetOut() ) )
{
pSI->Compress( aKernArray.data(), rInf.GetIdx(), rInf.GetLen(),
rInf.GetKanaComp(),
o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos );
bSpecialJust = true;
}
// Asian Justification
if ( SwFontScript::CJK == nActual && nSpaceAdd )
{
LanguageType aLang = rInf.GetFont()->GetLanguage( SwFontScript::CJK );
if (!MsLangId::isKorean(aLang))
{
SwScriptInfo::CJKJustify( rInf.GetText(), aKernArray.data(),
rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd, rInf.IsSpaceStop() );
bSpecialJust = true;
nSpaceAdd = 0;
}
}
// Kashida Justification
if ( SwFontScript::CTL == nActual && nSpaceAdd )
{
if ( SwScriptInfo::IsArabicText( rInf.GetText(), rInf.GetIdx(), rInf.GetLen() ) )
{
if ( pSI && pSI->CountKashida() &&
pSI->KashidaJustify( aKernArray.data(), rInf.GetIdx(),
rInf.GetLen(), nSpaceAdd ) != -1 )
{
bSpecialJust = true;
nSpaceAdd = 0;
}
}
}
// Thai Justification
if ( SwFontScript::CTL == nActual && nSpaceAdd )
{
LanguageType aLang = rInf.GetFont()->GetLanguage( SwFontScript::CTL );
if ( LANGUAGE_THAI == aLang )
{
// Use rInf.GetSpace() because it has more precision than
// nSpaceAdd:
SwScriptInfo::ThaiJustify( rInf.GetText(), aKernArray.data(),
rInf.GetIdx(), rInf.GetLen(),
rInf.GetNumberOfBlanks(),
rInf.GetSpace() );
// adding space to blanks is already done
bSpecialJust = true;
nSpaceAdd = 0;
}
}
}
tools::Long nKernSum = rInf.GetKern();
if ( bStretch || m_bPaintBlank || rInf.GetKern() || bSpecialJust )
{
for (sal_Int32 i = 0; i < sal_Int32(rInf.GetLen()); i++,
nKernSum += rInf.GetKern() )
{
if (CH_BLANK == rInf.GetText()[sal_Int32(rInf.GetIdx()) + i])
nKernSum += nSpaceAdd;
aKernArray[i] += nKernSum;
}
// In case of underlined/strike-through justified text
// a blank at the end requires special handling:
if( m_bPaintBlank && rInf.GetLen() && ( CH_BLANK ==
rInf.GetText()[sal_Int32(rInf.GetIdx() + rInf.GetLen())-1]))
{
// If it is a single underlined space, output 2 spaces:
if (TextFrameIndex(1) == rInf.GetLen())
{
aKernArray[0] = rInf.GetWidth() + nSpaceAdd;
rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(),
aKernArray, sal_Int32(rInf.GetIdx()), 1 );
}
else
{
aKernArray[ sal_Int32(rInf.GetLen()) - 2 ] += nSpaceAdd;
rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(),
aKernArray, sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
}
}
else
rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(),
aKernArray, sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
}
else
{
Point aTmpPos( aTextOriginPos );
sal_Int32 j = 0;
sal_Int32 i;
for( i = 0; i < sal_Int32(rInf.GetLen()); i++ )
{
if (CH_BLANK == rInf.GetText()[sal_Int32(rInf.GetIdx()) + i])
{
nKernSum += nSpaceAdd;
if( j < i )
rInf.GetOut().DrawText( aTmpPos, rInf.GetText(),
sal_Int32(rInf.GetIdx()) + j, i - j);
j = i + 1;
SwTwips nAdd = aKernArray[ i ] + nKernSum;
if ( ( vcl::text::ComplexTextLayoutFlags::BiDiStrong | vcl::text::ComplexTextLayoutFlags::BiDiRtl ) == nMode )
nAdd *= -1;
aTmpPos.setX( aTextOriginPos.X() + nAdd );
}
}
if( j < i )
rInf.GetOut().DrawText( aTmpPos, rInf.GetText(),
sal_Int32(rInf.GetIdx()) + j, i - j);
}
}
else if( bStretch )
{
tools::Long nTmpWidth = rInf.GetWidth();
if( rInf.GetKern() && rInf.GetLen() && nTmpWidth > rInf.GetKern() )
nTmpWidth -= rInf.GetKern();
rInf.GetOut().DrawStretchText( aTextOriginPos, nTmpWidth,
rInf.GetText(),
sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
}
else if( rInf.GetKern() )
{
const tools::Long nTmpWidth = GetTextSize( rInf ).Width();
const Color aSaveColor( pTmpFont->GetColor() );
const bool bColorChanged = rInf.ApplyAutoColor( pTmpFont );
if( bColorChanged )
{
if( !pTmpFont->IsSameInstance( rInf.GetOut().GetFont() ) )
rInf.GetOut().SetFont( *pTmpFont );
pTmpFont->SetColor( aSaveColor );
}
rInf.GetOut().DrawStretchText( aTextOriginPos, nTmpWidth,
rInf.GetText(),
sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
}
else
rInf.GetOut().DrawText( aTextOriginPos, rInf.GetText(),
sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
}
// PAINTING WITH FORMATTING DEVICE/SCREEN ADJUSTMENT
else
{
const bool bOrigTextRenderModeForResolutionIndependentLayout(rInf.GetOut().GetTextRenderModeForResolutionIndependentLayout());
// set text render mode to suit use of resolution independent text layout
rInf.GetOut().SetTextRenderModeForResolutionIndependentLayout(true);
OUString aBulletOverlay;
bool bBullet = rInf.GetBullet();
if( m_bSymbol )
bBullet = false;
std::vector<sal_Int32> aKernArray;
CreateScrFont( *rInf.GetShell(), rInf.GetOut() );
// OLE: no printer available
// OSL_ENSURE( pPrinter, "DrawText needs pPrinter" )
if ( m_pPrinter )
{
// pTmpFont has already been set as current font for rInf.GetOut()
if ( m_pPrinter.get() != rInf.GetpOut() || pTmpFont != m_pPrtFont )
{
if( !m_pPrtFont->IsSameInstance( m_pPrinter->GetFont() ) )
m_pPrinter->SetFont( *m_pPrtFont );
}
GetTextArray(*m_pPrinter, rInf, aKernArray);
}
else
{
GetTextArray(rInf.GetOut(), rInf, aKernArray);
}
// Modify Printer and ScreenArrays for special justifications
tools::Long nSpaceAdd = rInf.GetSpace() / SPACING_PRECISION_FACTOR;
bool bNoHalfSpace = false;
if ( rInf.GetFont() && rInf.GetLen() )
{
const SwFontScript nActual = rInf.GetFont()->GetActual();
const SwScriptInfo* pSI = rInf.GetScriptInfo();
// Kana Compression
if ( SwFontScript::CJK == nActual && rInf.GetKanaComp() &&
pSI && pSI->CountCompChg() &&
lcl_IsMonoSpaceFont( rInf.GetOut() ) )
{
pSI->Compress( aKernArray.data(), rInf.GetIdx(), rInf.GetLen(),
rInf.GetKanaComp(),
o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos );
}
// Asian Justification
if ( SwFontScript::CJK == nActual && nSpaceAdd )
{
LanguageType aLang = rInf.GetFont()->GetLanguage( SwFontScript::CJK );
if (!MsLangId::isKorean(aLang))
{
SwScriptInfo::CJKJustify( rInf.GetText(), aKernArray.data(),
rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd, rInf.IsSpaceStop() );
nSpaceAdd = 0;
}
}
// Kashida Justification
if ( SwFontScript::CTL == nActual && nSpaceAdd )
{
if ( SwScriptInfo::IsArabicText( rInf.GetText(), rInf.GetIdx(), rInf.GetLen() ) )
{
if ( pSI && pSI->CountKashida() &&
pSI->KashidaJustify( aKernArray.data(), rInf.GetIdx(),
rInf.GetLen(), nSpaceAdd ) != -1 )
nSpaceAdd = 0;
else
bNoHalfSpace = true;
}
}
// Thai Justification
if ( SwFontScript::CTL == nActual && nSpaceAdd )
{
LanguageType aLang = rInf.GetFont()->GetLanguage( SwFontScript::CTL );
if ( LANGUAGE_THAI == aLang )
{
SwScriptInfo::ThaiJustify( rInf.GetText(), aKernArray.data(),
rInf.GetIdx(),
rInf.GetLen(),
rInf.GetNumberOfBlanks(),
rInf.GetSpace() );
// adding space to blanks is already done
nSpaceAdd = 0;
}
}
}
if( bBullet )
{
// Copy the substring that will be painted, and replace spaces with
// bullets, and everything else with space.
sal_Int32 nCopyStart = sal_Int32(rInf.GetIdx());
sal_Int32 nCopyLen = sal_Int32(rInf.GetLen());
aBulletOverlay = rInf.GetText().copy( nCopyStart, nCopyLen );
for( sal_Int32 i = 0; i < aBulletOverlay.getLength(); ++i )
if( CH_BLANK == aBulletOverlay[ i ] )
{
/* fdo#72488 Hack: try to see if the space is zero width
* and don't bother with inserting a bullet in this case.
*/
if ((i + nCopyStart + 1 >= sal_Int32(rInf.GetLen())) ||
aKernArray[i + nCopyStart] != aKernArray[ i + nCopyStart + 1])
{
aBulletOverlay = aBulletOverlay.replaceAt(i, 1, rtl::OUStringChar(CH_BULLET));
}
else
{
aBulletOverlay = aBulletOverlay.replaceAt(i, 1, rtl::OUStringChar(CH_BLANK));
}
}
else
{
aBulletOverlay = aBulletOverlay.replaceAt(i, 1, rtl::OUStringChar(CH_BLANK));
}
}
TextFrameIndex nCnt(rInf.GetText().getLength());
if ( nCnt < rInf.GetIdx() )
assert(false); // layout bug, not handled below
else
nCnt = nCnt - rInf.GetIdx();
nCnt = std::min(nCnt, rInf.GetLen());
sal_Unicode cChPrev = rInf.GetText()[sal_Int32(rInf.GetIdx())];
// In case of a single underlined space in justified text,
// have to output 2 spaces:
if ((nCnt == TextFrameIndex(1)) && rInf.GetSpace() && (cChPrev == CH_BLANK))
{
aKernArray[0] = rInf.GetWidth() +
rInf.GetKern() +
( rInf.GetSpace() / SPACING_PRECISION_FACTOR );
if ( bSwitchL2R )
rInf.GetFrame()->SwitchLTRtoRTL( aTextOriginPos );
if ( bSwitchH2V )
rInf.GetFrame()->SwitchHorizontalToVertical( aTextOriginPos );
rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(),
aKernArray, sal_Int32(rInf.GetIdx()), 1 );
if( bBullet )
rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), aKernArray,
sal_Int32(rInf.GetIdx()), 1 );
}
else
{
if (m_pPrtFont->IsWordLineMode())
bNoHalfSpace = true;
Justify::SpaceDistribution(aKernArray, rInf.GetText(), sal_Int32(rInf.GetIdx()),
sal_Int32(nCnt), nSpaceAdd, rInf.GetKern(), bNoHalfSpace);
if( rInf.GetGreyWave() )
{
if( rInf.GetLen() )
{
tools::Long nHght = rInf.GetOut().LogicToPixel(
m_pPrtFont->GetFontSize() ).Height();
if( WRONG_SHOW_MIN < nHght )
{
if ( rInf.GetOut().GetConnectMetaFile() )
rInf.GetOut().Push();
Color aCol( rInf.GetOut().GetLineColor() );
bool bColSave = aCol != gWaveCol;
if ( bColSave )
rInf.GetOut().SetLineColor( gWaveCol );
Point aEnd;
tools::Long nKernVal = aKernArray[sal_Int32(rInf.GetLen()) - 1];
const Degree10 nDir = bBidiPor
? 1800_deg10
: UnMapDirection(GetFont().GetOrientation(),
bSwitchH2V, bSwitchH2VLRBT);
switch ( nDir.get() )
{
case 0 :
aEnd.setX( rInf.GetPos().X() + nKernVal );
aEnd.setY( rInf.GetPos().Y() );
break;
case 900 :
aEnd.setX( rInf.GetPos().X() );
aEnd.setY( rInf.GetPos().Y() - nKernVal );
break;
case 1800 :
aEnd.setX( rInf.GetPos().X() - nKernVal );
aEnd.setY( rInf.GetPos().Y() );
break;
case 2700 :
aEnd.setX( rInf.GetPos().X() );
aEnd.setY( rInf.GetPos().Y() + nKernVal );
break;
}
Point aCurrPos( rInf.GetPos() );
if ( bSwitchL2R )
{
rInf.GetFrame()->SwitchLTRtoRTL( aCurrPos );
rInf.GetFrame()->SwitchLTRtoRTL( aEnd );
}
if ( bSwitchH2V )
{
rInf.GetFrame()->SwitchHorizontalToVertical( aCurrPos );
rInf.GetFrame()->SwitchHorizontalToVertical( aEnd );
}
{
vcl::ScopedAntialiasing a(rInf.GetOut(), true);
rInf.GetOut().DrawWaveLine( aCurrPos, aEnd );
}
if ( bColSave )
rInf.GetOut().SetLineColor( aCol );
if ( rInf.GetOut().GetConnectMetaFile() )
rInf.GetOut().Pop();
}
}
}
else if( !m_bSymbol && rInf.GetLen() )
{
// anything to do?
if (rInf.GetWrong() || rInf.GetGrammarCheck() || rInf.GetSmartTags())
{
const tools::Long nHalfSpace = bNoHalfSpace ? 0 : nSpaceAdd / 2;
CalcLinePosData aCalcLinePosData(rInf, GetFont(), nCnt, bSwitchH2V,
bSwitchH2VLRBT, bSwitchL2R, nHalfSpace,
aKernArray.data(), bBidiPor);
SwForbidden aForbidden;
// draw line for smart tag data
lcl_DrawLineForWrongListData( aForbidden, rInf, rInf.GetSmartTags(), aCalcLinePosData, Size() );
// draw wave line for spell check errors
// draw them BEFORE the grammar check lines to 'override' the latter in case of conflict.
// reason: some grammar errors can only be found if spelling errors are fixed,
// therefore we don't want the user to miss a spelling error.
lcl_DrawLineForWrongListData( aForbidden, rInf, rInf.GetWrong(), aCalcLinePosData, m_pPrtFont->GetFontSize() );
// draw wave line for grammar check errors
lcl_DrawLineForWrongListData( aForbidden, rInf, rInf.GetGrammarCheck(), aCalcLinePosData, m_pPrtFont->GetFontSize() );
}
}
sal_Int32 nLen = sal_Int32(rInf.GetLen());
if( nLen > 0 )
{
if ( bSwitchL2R )
rInf.GetFrame()->SwitchLTRtoRTL( aTextOriginPos );
if ( bSwitchH2V )
rInf.GetFrame()->SwitchHorizontalToVertical( aTextOriginPos );
sal_Int32 nIdx = sal_Int32(rInf.GetIdx());
const SalLayoutGlyphs* pGlyphs = SalLayoutGlyphsCache::self()->GetLayoutGlyphs(&rInf.GetOut(),
rInf.GetText(), nIdx, nLen);
rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), aKernArray,
nIdx, nLen, SalLayoutFlags::NONE, pGlyphs );
if (bBullet)
{
rInf.GetOut().Push();
Color aPreviousColor = pTmpFont->GetColor();
FontLineStyle aPreviousUnderline = pTmpFont->GetUnderline();
FontLineStyle aPreviousOverline = pTmpFont->GetOverline();
FontStrikeout aPreviousStrikeout = pTmpFont->GetStrikeout();
pTmpFont->SetColor( NON_PRINTING_CHARACTER_COLOR );
pTmpFont->SetUnderline(LINESTYLE_NONE);
pTmpFont->SetOverline(LINESTYLE_NONE);
pTmpFont->SetStrikeout(STRIKEOUT_NONE);
rInf.GetOut().SetFont( *pTmpFont );
tools::Long nShift = rInf.GetOut( ).GetFontMetric( ).GetBulletOffset( );
if ( nShift )
{
tools::Long nAdd = 0;
if ( aBulletOverlay[ 0 ] == CH_BULLET )
{
if (bSwitchH2V)
aTextOriginPos.AdjustY(nShift ) ;
else
aTextOriginPos.AdjustX(nShift ) ;
nAdd = nShift ;
}
for( sal_Int32 i = 1 ; i < nLen ; ++i )
{
if ( aBulletOverlay[ i ] == CH_BULLET )
aKernArray [ i - 1 ] += nShift ;
if ( nAdd )
aKernArray [ i - 1 ] -= nAdd;
}
}
rInf.GetOut().DrawTextArray( aTextOriginPos, aBulletOverlay, aKernArray,
0, nLen );
pTmpFont->SetColor( aPreviousColor );
pTmpFont->SetUnderline(aPreviousUnderline);
pTmpFont->SetOverline(aPreviousOverline);
pTmpFont->SetStrikeout(aPreviousStrikeout);
rInf.GetOut().Pop();
}
}
}
rInf.GetOut().SetTextRenderModeForResolutionIndependentLayout(bOrigTextRenderModeForResolutionIndependentLayout);
}
}
Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf )
{
Size aTextSize;
const TextFrameIndex nLn = (TextFrameIndex(COMPLETE_STRING) != rInf.GetLen())
? rInf.GetLen()
: TextFrameIndex(rInf.GetText().getLength());
// be sure to have the correct layout mode at the printer
if ( m_pPrinter )
{
m_pPrinter->SetLayoutMode( rInf.GetOut().GetLayoutMode() );
m_pPrinter->SetDigitLanguage( rInf.GetOut().GetDigitLanguage() );
}
if ( rInf.GetFrame() && nLn && rInf.SnapToGrid() && rInf.GetFont() &&
SwFontScript::CJK == rInf.GetFont()->GetActual() )
{
SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrame()->FindPageFrame()));
if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
{
const SwDoc* pDoc = rInf.GetShell()->GetDoc();
const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
OutputDevice* pOutDev;
if ( m_pPrinter )
{
if( !m_pPrtFont->IsSameInstance( m_pPrinter->GetFont() ) )
m_pPrinter->SetFont(*m_pPrtFont);
pOutDev = m_pPrinter;
}
else
pOutDev = rInf.GetpOut();
aTextSize.setWidth( pOutDev->GetTextWidth(rInf.GetText(),
sal_Int32(rInf.GetIdx()), sal_Int32(nLn)) );
OSL_ENSURE( !rInf.GetShell() ||
( USHRT_MAX != GetGuessedLeading() && USHRT_MAX != GetExternalLeading() ),
"Leading values should be already calculated" );
aTextSize.setHeight( pOutDev->GetTextHeight() +
GetFontLeading( rInf.GetShell(), rInf.GetOut() ) );
std::vector<sal_Int32> aKernArray;
GetTextArray(*pOutDev, rInf, aKernArray, sal_Int32(rInf.GetLen()));
if (pGrid->IsSnapToChars())
{
Justify::SnapToGrid(aKernArray, rInf.GetText(), sal_Int32(rInf.GetIdx()),
sal_Int32(rInf.GetLen()), nGridWidth, true);
}
else
{
// use 0 to calculate raw width without rInf.GetSpace().
Justify::SnapToGridEdge(aKernArray, sal_Int32(rInf.GetLen()), nGridWidth, 0,
rInf.GetKern());
}
aTextSize.setWidth(aKernArray[sal_Int32(rInf.GetLen()) - 1]);
rInf.SetKanaDiff( 0 );
return aTextSize;
}
}
const bool bCompress = rInf.GetKanaComp() && nLn &&
rInf.GetFont() &&
SwFontScript::CJK == rInf.GetFont()->GetActual() &&
rInf.GetScriptInfo() &&
rInf.GetScriptInfo()->CountCompChg() &&
lcl_IsMonoSpaceFont( rInf.GetOut() );
OSL_ENSURE( !bCompress || ( rInf.GetScriptInfo() && rInf.GetScriptInfo()->
CountCompChg()), "Compression without info" );
// This is the part used e.g., for cursor travelling
// See condition for DrawText or DrawTextArray (bDirectPrint)
std::vector<sal_Int32> aKernArray;
if ( m_pPrinter && m_pPrinter.get() != rInf.GetpOut() )
{
if( !m_pPrtFont->IsSameInstance( m_pPrinter->GetFont() ) )
m_pPrinter->SetFont(*m_pPrtFont);
aTextSize.setHeight( m_pPrinter->GetTextHeight() );
CreateScrFont( *rInf.GetShell(), rInf.GetOut() );
if( !GetScrFont()->IsSameInstance( rInf.GetOut().GetFont() ) )
rInf.GetOut().SetFont( *m_pScrFont );
GetTextArray(*m_pPrinter, rInf.GetText(), aKernArray,
sal_Int32(rInf.GetIdx()), sal_Int32(nLn));
}
else
{
if( !m_pPrtFont->IsSameInstance( rInf.GetOut().GetFont() ) )
rInf.GetOut().SetFont( *m_pPrtFont );
aTextSize.setHeight( rInf.GetOut().GetTextHeight() );
GetTextArray(rInf.GetOut(), rInf, aKernArray, nLn.get());
}
if (bCompress)
{
rInf.SetKanaDiff(rInf.GetScriptInfo()->Compress(aKernArray.data(), rInf.GetIdx(), nLn, rInf.GetKanaComp(),
o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered(rInf.GetOut())));
}
else
rInf.SetKanaDiff( 0 );
if (nLn)
{
aTextSize.setWidth(aKernArray[sal_Int32(nLn) - 1]);
// Note that we can't simply use sal_Int(nLn) - 1 as nSpaceCount
// because a glyph may be made up of more than one characters.
sal_Int32 nSpaceCount = 0;
tools::Long nOldValue = aKernArray[0];
for(sal_Int32 i = 1; i < sal_Int32(nLn); ++i)
{
if (nOldValue != aKernArray[i])
{
++nSpaceCount;
nOldValue = aKernArray[i];
}
}
if (rInf.GetKern())
aTextSize.AdjustWidth(nSpaceCount * rInf.GetKern());
}
OSL_ENSURE( !rInf.GetShell() ||
( USHRT_MAX != GetGuessedLeading() && USHRT_MAX != GetExternalLeading() ),
"Leading values should be already calculated" );
aTextSize.AdjustHeight(GetFontLeading( rInf.GetShell(), rInf.GetOut() ) );
return aTextSize;
}
TextFrameIndex SwFntObj::GetModelPositionForViewPoint(SwDrawTextInfo &rInf)
{
tools::Long nSpaceAdd = rInf.GetSpace() / SPACING_PRECISION_FACTOR;
const tools::Long nCharacterSpacing = -rInf.GetCharacterSpacing() / SPACING_PRECISION_FACTOR;
tools::Long nKern = rInf.GetKern();
if( 0 != nCharacterSpacing )
nKern -= nCharacterSpacing;
std::vector<sal_Int32> aKernArray;
// be sure to have the correct layout mode at the printer
if ( m_pPrinter )
{
m_pPrinter->SetLayoutMode( rInf.GetOut().GetLayoutMode() );
m_pPrinter->SetDigitLanguage( rInf.GetOut().GetDigitLanguage() );
GetTextArray(*m_pPrinter, rInf, aKernArray);
}
else
{
GetTextArray(rInf.GetOut(), rInf, aKernArray);
}
if ( rInf.GetFrame() && rInf.GetLen() && rInf.SnapToGrid() &&
rInf.GetFont() && SwFontScript::CJK == rInf.GetFont()->GetActual() )
{
SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrame()->FindPageFrame()));
if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
{
const SwDoc* pDoc = rInf.GetShell()->GetDoc();
const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
if (pGrid->IsSnapToChars())
{
Justify::SnapToGrid(aKernArray, rInf.GetText(), sal_Int32(rInf.GetIdx()),
sal_Int32(rInf.GetLen()), nGridWidth, true);
}
else
{
Justify::SnapToGridEdge(aKernArray, sal_Int32(rInf.GetLen()), nGridWidth,
nSpaceAdd, rInf.GetKern());
}
return TextFrameIndex(Justify::GetModelPosition(aKernArray, sal_Int32(rInf.GetLen()),
rInf.GetOffset()));
}
}
const SwScriptInfo* pSI = rInf.GetScriptInfo();
if ( rInf.GetFont() && rInf.GetLen() )
{
const SwFontScript nActual = rInf.GetFont()->GetActual();
// Kana Compression
if ( SwFontScript::CJK == nActual && rInf.GetKanaComp() &&
pSI && pSI->CountCompChg() &&
lcl_IsMonoSpaceFont( rInf.GetOut() ) )
{
pSI->Compress( aKernArray.data(), rInf.GetIdx(), rInf.GetLen(),
rInf.GetKanaComp(),
o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()),
lcl_IsFullstopCentered( rInf.GetOut() ) );
}
// Asian Justification
if ( SwFontScript::CJK == rInf.GetFont()->GetActual() )
{
LanguageType aLang = rInf.GetFont()->GetLanguage( SwFontScript::CJK );
if (!MsLangId::isKorean(aLang))
{
SwScriptInfo::CJKJustify( rInf.GetText(), aKernArray.data(),
rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd, rInf.IsSpaceStop() );
nSpaceAdd = 0;
}
}
// Kashida Justification
if ( SwFontScript::CTL == nActual && rInf.GetSpace() )
{
if ( SwScriptInfo::IsArabicText( rInf.GetText(), rInf.GetIdx(), rInf.GetLen() ) )
{
if ( pSI && pSI->CountKashida() &&
pSI->KashidaJustify( aKernArray.data(), rInf.GetIdx(), rInf.GetLen(),
nSpaceAdd ) != -1 )
nSpaceAdd = 0;
}
}
// Thai Justification
if ( SwFontScript::CTL == nActual && nSpaceAdd )
{
LanguageType aLang = rInf.GetFont()->GetLanguage( SwFontScript::CTL );
if ( LANGUAGE_THAI == aLang )
{
SwScriptInfo::ThaiJustify( rInf.GetText(), aKernArray.data(),
rInf.GetIdx(), rInf.GetLen(),
rInf.GetNumberOfBlanks(),
rInf.GetSpace() );
// adding space to blanks is already done
nSpaceAdd = 0;
}
}
}
tools::Long nLeft = 0;
tools::Long nRight = 0;
TextFrameIndex nCnt(0);
tools::Long nSpaceSum = 0;
tools::Long nKernSum = 0;
sal_Int32 nDone = 0;
TextFrameIndex nIdx = rInf.GetIdx();
TextFrameIndex nLastIdx = nIdx;
const TextFrameIndex nEnd = rInf.GetIdx() + rInf.GetLen();
// #i105901#
// skip character cells for all script types
LanguageType aLang = rInf.GetFont()->GetLanguage();
while ( ( nRight < tools::Long( rInf.GetOffset() ) ) && ( nIdx < nEnd ) )
{
if (nSpaceAdd && CH_BLANK == rInf.GetText()[ sal_Int32(nIdx)])
nSpaceSum += nSpaceAdd;
// go to next character (cell).
nLastIdx = nIdx;
nIdx = TextFrameIndex(g_pBreakIt->GetBreakIter()->nextCharacters(
rInf.GetText(), sal_Int32(nIdx),
g_pBreakIt->GetLocale( aLang ),
i18n::CharacterIteratorMode::SKIPCELL, 1, nDone));
if ( nIdx <= nLastIdx )
break;
// the next character might be outside the layout range (e.g tdf124116-1.odt)
if (nIdx > nEnd)
nIdx = nEnd;
nLeft = nRight;
nRight = aKernArray[sal_Int32(nIdx - rInf.GetIdx()) - 1] + nKernSum + nSpaceSum;
nKernSum += nKern;
}
// step back if position is before the middle of the character
// or if we do not want to go to the next character
if ( nIdx > rInf.GetIdx() &&
( rInf.IsPosMatchesBounds() ||
( ( nRight > tools::Long( rInf.GetOffset() ) ) &&
( nRight - rInf.GetOffset() > rInf.GetOffset() - nLeft ) ) ) )
nCnt = nLastIdx - rInf.GetIdx(); // first half
else
nCnt = nIdx - rInf.GetIdx(); // second half
if ( pSI )
rInf.SetCursorBidiLevel( pSI->DirType( nLastIdx ) );
return nCnt;
}
SwFntAccess::SwFntAccess( const void* & rnFontCacheId,
sal_uInt16 &rIndex, const void *pOwn, SwViewShell const *pSh,
bool bCheck ) :
SwCacheAccess( *pFntCache, rnFontCacheId, rIndex ),
m_pShell( pSh )
{
// the used ctor of SwCacheAccess searches for rnFontCacheId+rIndex in the cache
if ( m_pObj )
{
// fast case: known Font (rnFontCacheId), no need to check printer and zoom
if ( !bCheck )
return;
// Font is known, but has to be checked
}
else
{ // Font not known, must be searched
bCheck = false;
}
{
OutputDevice* pOut = nullptr;
sal_uInt16 nZoom = USHRT_MAX;
// Get the reference device
if ( pSh )
{
pOut = &pSh->GetRefDev();
nZoom = pSh->GetViewOptions()->GetZoom();
}
SwFntObj *pFntObj;
if ( bCheck )
{
pFntObj = Get();
if ( ( pFntObj->GetZoom( ) == nZoom ) &&
( pFntObj->m_pPrinter == pOut ) &&
pFntObj->GetPropWidth() ==
static_cast<SwSubFont const *>(pOwn)->GetPropWidth() )
{
return; // result of Check: Drucker+Zoom okay.
}
pFntObj->Unlock(); // forget this object, printer/zoom differs
m_pObj = nullptr;
}
// Search by font comparison, quite expensive!
// Look for same font and same printer
pFntObj = pFntCache->First();
while ( pFntObj && !( pFntObj->m_aFont == *static_cast<vcl::Font const *>(pOwn) &&
pFntObj->GetZoom() == nZoom &&
pFntObj->GetPropWidth() ==
static_cast<SwSubFont const *>(pOwn)->GetPropWidth() &&
( !pFntObj->m_pPrinter || pFntObj->m_pPrinter == pOut ) ) )
pFntObj = SwFntCache::Next( pFntObj );
if( pFntObj && pFntObj->m_pPrinter.get() != pOut )
{
// found one without printer, let's see if there is one with
// the same printer as well
SwFntObj *pTmpObj = pFntObj;
while( pTmpObj && !( pTmpObj->m_aFont == *static_cast<vcl::Font const *>(pOwn) &&
pTmpObj->GetZoom()==nZoom && pTmpObj->m_pPrinter==pOut &&
pTmpObj->GetPropWidth() ==
static_cast<SwSubFont const *>(pOwn)->GetPropWidth() ) )
pTmpObj = SwFntCache::Next( pTmpObj );
if( pTmpObj )
pFntObj = pTmpObj;
}
if ( !pFntObj ) // Font has not been found, create one
{
// Have to create new Object, hence Owner must be a SwFont, later
// the Owner will be the "MagicNumber"
SwCacheAccess::m_pOwner = pOwn;
pFntObj = Get(); // will create via NewObj() and lock
OSL_ENSURE(pFntObj, "No Font, no Fun.");
}
else // Font has been found, so we lock it.
{
pFntObj->Lock();
if (pFntObj->m_pPrinter.get() != pOut) // if no printer is known by now
{
OSL_ENSURE( !pFntObj->m_pPrinter, "SwFntAccess: Printer Changed" );
pFntObj->CreatePrtFont( *pOut );
pFntObj->m_pPrinter = pOut;
pFntObj->m_pScrFont = nullptr;
pFntObj->m_nGuessedLeading = USHRT_MAX;
pFntObj->m_nExtLeading = USHRT_MAX;
pFntObj->m_nPrtAscent = USHRT_MAX;
pFntObj->m_nPrtHeight = USHRT_MAX;
}
m_pObj = pFntObj;
}
// no matter if new or found, now the Owner of the Object is a
// MagicNumber, and will be given to the SwFont, as well as the Index
// for later direct access
rnFontCacheId = reinterpret_cast<void*>(reinterpret_cast<sal_IntPtr>(pFntObj->GetOwner()));
SwCacheAccess::m_pOwner = pFntObj->GetOwner();
rIndex = pFntObj->GetCachePos();
}
}
SwCacheObj *SwFntAccess::NewObj( )
{
// "MagicNumber" used to identify Fonts
static std::uintptr_t fontCacheIdCounter = 0;
// a new Font, a new "MagicNumber".
return new SwFntObj( *static_cast<SwSubFont const *>(m_pOwner), ++fontCacheIdCounter, m_pShell );
}
TextFrameIndex SwFont::GetTextBreak(SwDrawTextInfo const & rInf, tools::Long nTextWidth)
{
ChgFnt( rInf.GetShell(), rInf.GetOut() );
const bool bCompress = rInf.GetKanaComp() && rInf.GetLen() &&
SwFontScript::CJK == GetActual() &&
rInf.GetScriptInfo() &&
rInf.GetScriptInfo()->CountCompChg() &&
lcl_IsMonoSpaceFont( rInf.GetOut() );
OSL_ENSURE( !bCompress || ( rInf.GetScriptInfo() && rInf.GetScriptInfo()->
CountCompChg()), "Compression without info" );
TextFrameIndex nTextBreak(0);
tools::Long nKern = 0;
TextFrameIndex nLn = rInf.GetLen() == TextFrameIndex(COMPLETE_STRING)
? TextFrameIndex(rInf.GetText().getLength()) : rInf.GetLen();
if ( rInf.GetFrame() && nLn && rInf.SnapToGrid() &&
rInf.GetFont() && SwFontScript::CJK == rInf.GetFont()->GetActual() )
{
SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrame()->FindPageFrame()));
if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
{
const SwDoc* pDoc = rInf.GetShell()->GetDoc();
const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
std::vector<sal_Int32> aKernArray;
GetTextArray( rInf.GetOut(), rInf.GetText(), aKernArray,
sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
if (pGrid->IsSnapToChars())
{
Justify::SnapToGrid(aKernArray, rInf.GetText(), sal_Int32(rInf.GetIdx()),
sal_Int32(rInf.GetLen()), nGridWidth, true);
}
else
{
// use 0 to calculate raw width without rInf.GetSpace().
Justify::SnapToGridEdge(aKernArray, sal_Int32(rInf.GetLen()), nGridWidth,
0, rInf.GetKern());
}
while(nTextBreak < rInf.GetLen() && aKernArray[sal_Int32(nTextBreak)] <= nTextWidth)
++nTextBreak;
return nTextBreak + rInf.GetIdx();
}
}
if( m_aSub[m_nActual].IsCapital() && nLn )
{
nTextBreak = GetCapitalBreak( rInf.GetShell(), rInf.GetpOut(),
rInf.GetScriptInfo(), rInf.GetText(), nTextWidth, rInf.GetIdx(),
nLn );
}
else
{
nKern = CheckKerning();
const OUString* pTmpText;
OUString aTmpText;
TextFrameIndex nTmpIdx;
TextFrameIndex nTmpLen;
bool bTextReplaced = false;
if ( !m_aSub[m_nActual].IsCaseMap() )
{
pTmpText = &rInf.GetText();
nTmpIdx = rInf.GetIdx();
nTmpLen = nLn;
}
else
{
const OUString aSnippet(rInf.GetText().copy(sal_Int32(rInf.GetIdx()), sal_Int32(nLn)));
aTmpText = m_aSub[m_nActual].CalcCaseMap( aSnippet );
const bool bTitle = SvxCaseMap::Capitalize == m_aSub[m_nActual].GetCaseMap();
// Uaaaaahhhh!!! In title case mode, we would get wrong results
if ( bTitle && nLn )
{
// check if rInf.GetIdx() is begin of word
if ( !g_pBreakIt->GetBreakIter()->isBeginWord(
rInf.GetText(), sal_Int32(rInf.GetIdx()),
g_pBreakIt->GetLocale( m_aSub[m_nActual].GetLanguage() ),
i18n::WordType::ANYWORD_IGNOREWHITESPACES ) )
{
// In this case, the beginning of aTmpText is wrong.
OUString aSnippetTmp(aSnippet.copy(0, 1));
aSnippetTmp = m_aSub[m_nActual].CalcCaseMap( aSnippetTmp );
aTmpText = aTmpText.replaceAt( 0, aSnippetTmp.getLength(), rtl::OUStringChar(aSnippet[0]) );
}
}
pTmpText = &aTmpText;
nTmpIdx = TextFrameIndex(0);
nTmpLen = TextFrameIndex(aTmpText.getLength());
bTextReplaced = true;
}
if( rInf.GetHyphPos() ) {
sal_Int32 nHyphPos = sal_Int32(*rInf.GetHyphPos());
const SalLayoutGlyphs* pGlyphs = SalLayoutGlyphsCache::self()->GetLayoutGlyphs(
&rInf.GetOut(), *pTmpText, nTmpIdx.get(), nTmpLen.get(), 0, rInf.GetVclCache());
nTextBreak = TextFrameIndex(rInf.GetOut().GetTextBreak(
*pTmpText, nTextWidth,
u'-', nHyphPos,
sal_Int32(nTmpIdx), sal_Int32(nTmpLen),
nKern, rInf.GetVclCache(), pGlyphs));
*rInf.GetHyphPos() = TextFrameIndex((nHyphPos == -1) ? COMPLETE_STRING : nHyphPos);
}
else
{
SwFntAccess aFntAccess(m_aSub[m_nActual].m_nFontCacheId, m_aSub[m_nActual].m_nFontIndex,
&m_aSub[m_nActual], rInf.GetShell());
const SalLayoutGlyphs* pGlyphs = SalLayoutGlyphsCache::self()->GetLayoutGlyphs(&rInf.GetOut(),
*pTmpText, nTmpIdx.get(), nTmpLen.get(), 0, rInf.GetVclCache());
nTextBreak = TextFrameIndex(rInf.GetOut().GetTextBreak(
*pTmpText, nTextWidth,
sal_Int32(nTmpIdx), sal_Int32(nTmpLen),
nKern, rInf.GetVclCache(), pGlyphs));
}
if (bTextReplaced && sal_Int32(nTextBreak) != -1)
{
if ( nTmpLen != nLn )
nTextBreak = sw_CalcCaseMap( *this, rInf.GetText(),
rInf.GetIdx(), nLn, nTextBreak );
else
nTextBreak = nTextBreak + rInf.GetIdx();
}
}
TextFrameIndex nTextBreak2 = sal_Int32(nTextBreak) == -1
? TextFrameIndex(COMPLETE_STRING)
: nTextBreak;
// tdf112290 tdf136588 Break the line correctly only if there is an image inline,
// and the image wider than the line...
if (GetCaseMap() == SvxCaseMap::SmallCaps && TextFrameIndex(COMPLETE_STRING) == nTextBreak2 &&
! bCompress && nTextWidth == 0)
// If nTextWidth == 0 means the line is full, we have to break it
nTextBreak2 = TextFrameIndex(1);
if ( ! bCompress )
return nTextBreak2;
nTextBreak2 = nTextBreak2 - rInf.GetIdx();
if( nTextBreak2 < nLn )
{
if( !nTextBreak2 && nLn )
nLn = TextFrameIndex(1);
else if (nLn > nTextBreak2 + nTextBreak2)
nLn = nTextBreak2 + nTextBreak2;
std::vector<sal_Int32> aKernArray;
GetTextArray( rInf.GetOut(), rInf.GetText(), aKernArray,
sal_Int32(rInf.GetIdx()), sal_Int32(nLn));
if( rInf.GetScriptInfo()->Compress( aKernArray.data(), rInf.GetIdx(), nLn,
rInf.GetKanaComp(), o3tl::narrowing<sal_uInt16>(GetHeight( m_nActual )),
lcl_IsFullstopCentered( rInf.GetOut() ) ) )
{
tools::Long nKernAdd = nKern;
TextFrameIndex const nTmpBreak = nTextBreak2;
if( nKern && nTextBreak2 )
nKern *= sal_Int32(nTextBreak2) - 1;
while (nTextBreak2 < nLn && nTextWidth >= aKernArray[sal_Int32(nTextBreak2)] + nKern)
{
nKern += nKernAdd;
++nTextBreak2;
}
if( rInf.GetHyphPos() )
*rInf.GetHyphPos() += nTextBreak2 - nTmpBreak; // It's not perfect
}
}
nTextBreak2 = nTextBreak2 + rInf.GetIdx();
return nTextBreak2;
}
bool SwDrawTextInfo::ApplyAutoColor( vcl::Font* pFont )
{
const vcl::Font& rFnt = pFont ? *pFont : GetOut().GetFont();
Color nNewColor = COL_BLACK;
bool bChgFntColor = false;
bool bChgLineColor = false;
if (GetShell() && !GetShell()->GetWin() && GetShell()->GetViewOptions()->IsBlackFont())
{
if ( COL_BLACK != rFnt.GetColor() )
bChgFntColor = true;
if ( (COL_BLACK != GetOut().GetLineColor()) ||
(COL_BLACK != GetOut().GetOverlineColor()) )
bChgLineColor = true;
}
else
{
// FontColor has to be changed if:
// 1. FontColor = AUTO or 2. IsAlwaysAutoColor is set
// LineColor has to be changed if:
// 1. IsAlwaysAutoColor is set
bChgLineColor = GetShell() && GetShell()->GetWin() &&
GetShell()->GetAccessibilityOptions()->IsAlwaysAutoColor();
bChgFntColor = COL_AUTO == rFnt.GetColor() || bChgLineColor;
if ( bChgFntColor )
{
// check if current background has a user defined setting
std::optional<Color> pCol;
if (GetFont())
pCol = GetFont()->GetBackColor();
if( ! pCol || COL_TRANSPARENT == *pCol )
{
const SvxBrushItem* pItem;
SwRect aOrigBackRect;
drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
/// OD 21.08.2002
/// consider, that [GetBackgroundBrush(...)] can set <pCol>
/// - see implementation in /core/layout/paintfrm.cxx
/// OD 21.08.2002 #99657#
/// There is a user defined setting for the background, if there
/// is a background brush and its color is *not* "no fill"/"auto fill".
if( GetFrame()->GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false, /*bConsiderTextBox=*/true ) )
{
if (aFillAttributes && aFillAttributes->isUsed())
{
// First see if fill attributes provide a color.
pCol = Color(aFillAttributes->getAverageColor(aGlobalRetoucheColor.getBColor()));
}
// If not, then fall back to the old brush item.
if ( !pCol )
{
pCol = pItem->GetColor();
}
/// OD 30.08.2002 #99657#
/// determined color <pCol> can be <COL_TRANSPARENT>. Thus, check it.
if ( *pCol == COL_TRANSPARENT)
pCol.reset();
}
else
pCol.reset();
}
// no user defined color at paragraph or font background
if ( ! pCol )
pCol = aGlobalRetoucheColor;
if( GetShell() && GetShell()->GetWin() )
{
// here we determine the preferred window text color for painting
const SwViewOption* pViewOption = GetShell()->GetViewOptions();
if(pViewOption->IsPagePreview() &&
!officecfg::Office::Common::Accessibility::IsForPagePreviews::get())
nNewColor = COL_BLACK;
else
// we take the font color from the appearance page
nNewColor = SwViewOption::GetFontColor();
}
// change painting color depending of dark/bright background
Color aTmpColor( nNewColor );
if ( pCol->IsDark() && aTmpColor.IsDark() )
nNewColor = COL_WHITE;
else if ( pCol->IsBright() && aTmpColor.IsBright() )
nNewColor = COL_BLACK;
}
}
if ( bChgFntColor || bChgLineColor )
{
Color aNewColor( nNewColor );
if ( bChgFntColor )
{
if ( pFont && aNewColor != pFont->GetColor() )
{
// only set the new color at the font passed as argument
pFont->SetColor( aNewColor );
}
else if ( aNewColor != GetOut().GetFont().GetColor() )
{
// set new font with new color at output device
vcl::Font aFont( rFnt );
aFont.SetColor( aNewColor );
GetOut().SetFont( aFont );
}
}
// the underline and overline colors have to be set separately
if ( bChgLineColor )
{
// get current font color or color set at output device
aNewColor = pFont ? pFont->GetColor() : GetOut().GetFont().GetColor();
if ( aNewColor != GetOut().GetLineColor() )
GetOut().SetLineColor( aNewColor );
if ( aNewColor != GetOut().GetOverlineColor() )
GetOut().SetOverlineColor( aNewColor );
}
return true;
}
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|