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
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
|
/* -*- 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 <tools/diagnose_ex.h>
#include <com/sun/star/rendering/PathCapType.hpp>
#include <com/sun/star/rendering/PathJoinType.hpp>
#include <com/sun/star/rendering/XCanvas.hpp>
#include <com/sun/star/rendering/XCanvasFont.hpp>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/vector/b2dsize.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <tools/gen.hxx>
#include <vcl/canvastools.hxx>
#include <vcl/virdev.hxx>
#include <basegfx/tools/canvastools.hxx>
#include <canvas/canvastools.hxx>
#include <memory>
#include <boost/noncopyable.hpp>
#include "textaction.hxx"
#include "outdevstate.hxx"
#include "mtftools.hxx"
using namespace ::com::sun::star;
namespace cppcanvas
{
namespace internal
{
namespace
{
void init( rendering::RenderState& o_rRenderState,
const ::basegfx::B2DPoint& rStartPoint,
const OutDevState& rState,
const CanvasSharedPtr& rCanvas )
{
tools::initRenderState(o_rRenderState,rState);
// #i36950# Offset clip back to origin (as it's also moved
// by rStartPoint)
// #i53964# Also take VCL font rotation into account,
// since this, opposed to the FontMatrix rotation
// elsewhere, _does_ get incorporated into the render
// state transform.
tools::modifyClip( o_rRenderState,
rState,
rCanvas,
rStartPoint,
NULL,
&rState.fontRotation );
basegfx::B2DHomMatrix aLocalTransformation(basegfx::tools::createRotateB2DHomMatrix(rState.fontRotation));
aLocalTransformation.translate( rStartPoint.getX(),
rStartPoint.getY() );
::canvas::tools::appendToRenderState( o_rRenderState,
aLocalTransformation );
o_rRenderState.DeviceColor = rState.textColor;
}
void init( rendering::RenderState& o_rRenderState,
const ::basegfx::B2DPoint& rStartPoint,
const OutDevState& rState,
const CanvasSharedPtr& rCanvas,
const ::basegfx::B2DHomMatrix& rTextTransform )
{
init( o_rRenderState, rStartPoint, rState, rCanvas );
// TODO(F2): Also inversely-transform clip with
// rTextTransform (which is actually rather hard, as the
// text transform is _prepended_ to the render state)!
// prepend extra font transform to render state
// (prepend it, because it's interpreted in the unit
// rect coordinate space)
::canvas::tools::prependToRenderState( o_rRenderState,
rTextTransform );
}
void init( rendering::RenderState& o_rRenderState,
uno::Reference< rendering::XCanvasFont >& o_rFont,
const ::basegfx::B2DPoint& rStartPoint,
const OutDevState& rState,
const CanvasSharedPtr& rCanvas )
{
// ensure that o_rFont is valid. It is possible that
// text actions are generated without previously
// setting a font. Then, just take a default font
if( !o_rFont.is() )
{
// Use completely default FontRequest
const rendering::FontRequest aFontRequest;
geometry::Matrix2D aFontMatrix;
::canvas::tools::setIdentityMatrix2D( aFontMatrix );
o_rFont = rCanvas->getUNOCanvas()->createFont(
aFontRequest,
uno::Sequence< beans::PropertyValue >(),
aFontMatrix );
}
init( o_rRenderState,
rStartPoint,
rState,
rCanvas );
}
void init( rendering::RenderState& o_rRenderState,
uno::Reference< rendering::XCanvasFont >& o_rFont,
const ::basegfx::B2DPoint& rStartPoint,
const OutDevState& rState,
const CanvasSharedPtr& rCanvas,
const ::basegfx::B2DHomMatrix& rTextTransform )
{
init( o_rRenderState, o_rFont, rStartPoint, rState, rCanvas );
// TODO(F2): Also inversely-transform clip with
// rTextTransform (which is actually rather hard, as the
// text transform is _prepended_ to the render state)!
// prepend extra font transform to render state
// (prepend it, because it's interpreted in the unit
// rect coordinate space)
::canvas::tools::prependToRenderState( o_rRenderState,
rTextTransform );
}
::basegfx::B2DPolyPolygon textLinesFromLogicalOffsets( const uno::Sequence< double >& rOffsets,
const tools::TextLineInfo& rTextLineInfo )
{
return tools::createTextLinesPolyPolygon(
0.0,
// extract character cell furthest to the right
*(::std::max_element(
rOffsets.getConstArray(),
rOffsets.getConstArray() + rOffsets.getLength() )),
rTextLineInfo );
}
uno::Sequence< double > setupDXArray( const long* pCharWidths,
sal_Int32 nLen,
const OutDevState& rState )
{
// convert character widths from logical units
uno::Sequence< double > aCharWidthSeq( nLen );
double* pOutputWidths( aCharWidthSeq.getArray() );
// #143885# maintain (nearly) full precision of DX
// array, by circumventing integer-based
// OutDev-mapping
const double nScale( rState.mapModeTransform.get(0,0) );
for( int i = 0; i < nLen; ++i )
{
// TODO(F2): use correct scale direction
*pOutputWidths++ = *pCharWidths++ * nScale;
}
return aCharWidthSeq;
}
uno::Sequence< double > setupDXArray( const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
VirtualDevice& rVDev,
const OutDevState& rState )
{
// no external DX array given, create one from given
// string
::std::unique_ptr< long []> pCharWidths( new long[nLen] );
rVDev.GetTextArray( rText, pCharWidths.get(),
nStartPos, nLen );
return setupDXArray( pCharWidths.get(), nLen, rState );
}
::basegfx::B2DPoint adaptStartPoint( const ::basegfx::B2DPoint& rStartPoint,
const OutDevState& rState,
const uno::Sequence< double >& rOffsets )
{
::basegfx::B2DPoint aLocalPoint( rStartPoint );
if( rState.textAlignment )
{
// text origin is right, not left. Modify start point
// accordingly, because XCanvas::drawTextLayout()
// always aligns left!
const double nOffset( rOffsets[ rOffsets.getLength()-1 ] );
// correct start point for rotated text: rotate around
// former start point
aLocalPoint.setX( aLocalPoint.getX() + cos( rState.fontRotation )*nOffset );
aLocalPoint.setY( aLocalPoint.getY() + sin( rState.fontRotation )*nOffset );
}
return aLocalPoint;
}
/** Perform common setup for array text actions
This method creates the XTextLayout object and
initializes it, e.g. with the logical advancements.
*/
void initArrayAction( rendering::RenderState& o_rRenderState,
uno::Reference< rendering::XTextLayout >& o_rTextLayout,
const ::basegfx::B2DPoint& rStartPoint,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix* pTextTransform )
{
ENSURE_OR_THROW( rOffsets.getLength(),
"::cppcanvas::internal::initArrayAction(): zero-length DX array" );
const ::basegfx::B2DPoint aLocalStartPoint(
adaptStartPoint( rStartPoint, rState, rOffsets ) );
uno::Reference< rendering::XCanvasFont > xFont( rState.xFont );
if( pTextTransform )
init( o_rRenderState, xFont, aLocalStartPoint, rState, rCanvas, *pTextTransform );
else
init( o_rRenderState, xFont, aLocalStartPoint, rState, rCanvas );
o_rTextLayout = xFont->createTextLayout(
rendering::StringContext( rText, nStartPos, nLen ),
rState.textDirection,
0 );
ENSURE_OR_THROW( o_rTextLayout.is(),
"::cppcanvas::internal::initArrayAction(): Invalid font" );
o_rTextLayout->applyLogicalAdvancements( rOffsets );
}
double getLineWidth( ::VirtualDevice& rVDev,
const OutDevState& rState,
const rendering::StringContext& rStringContext )
{
// TODO(F2): use correct scale direction
const ::basegfx::B2DSize aSize( rVDev.GetTextWidth( rStringContext.Text,
static_cast<sal_uInt16>(rStringContext.StartPosition),
static_cast<sal_uInt16>(rStringContext.Length) ),
0 );
return (rState.mapModeTransform * aSize).getX();
}
uno::Sequence< double >
calcSubsetOffsets( rendering::RenderState& io_rRenderState,
double& o_rMinPos,
double& o_rMaxPos,
const uno::Reference< rendering::XTextLayout >& rOrigTextLayout,
const ::cppcanvas::internal::Action::Subset& rSubset )
{
ENSURE_OR_THROW( rSubset.mnSubsetEnd > rSubset.mnSubsetBegin,
"::cppcanvas::internal::calcSubsetOffsets(): invalid subset range range" );
uno::Sequence< double > aOrigOffsets( rOrigTextLayout->queryLogicalAdvancements() );
const double* pOffsets( aOrigOffsets.getConstArray() );
ENSURE_OR_THROW( aOrigOffsets.getLength() >= rSubset.mnSubsetEnd,
"::cppcanvas::internal::calcSubsetOffsets(): invalid subset range range" );
// TODO(F3): It currently seems that for RTL text, the
// DX offsets are nevertheless increasing in logical
// text order (I'd expect they are decreasing,
// mimicking the fact that the text is output
// right-to-left). This breaks text effects for ALL
// RTL languages.
// determine leftmost position in given subset range -
// as the DX array contains the output positions
// starting with the second character (the first is
// assumed to have output position 0), correct begin
// iterator.
const double nMinPos( rSubset.mnSubsetBegin <= 0 ? 0 :
*(::std::min_element( pOffsets+rSubset.mnSubsetBegin-1,
pOffsets+rSubset.mnSubsetEnd )) );
// determine rightmost position in given subset range
// - as the DX array contains the output positions
// starting with the second character (the first is
// assumed to have output position 0), correct begin
// iterator.
const double nMaxPos(
*(::std::max_element( pOffsets + (rSubset.mnSubsetBegin <= 0 ?
0 : rSubset.mnSubsetBegin-1),
pOffsets + rSubset.mnSubsetEnd )) );
// adapt render state, to move text output to given offset
// TODO(F1): Strictly speaking, we also have to adapt
// the clip here, which normally should _not_ move
// with the output offset. Neglected for now, as it
// does not matter for drawing layer output
if( rSubset.mnSubsetBegin > 0 )
{
::basegfx::B2DHomMatrix aTranslation;
if( rOrigTextLayout->getFont()->getFontRequest().FontDescription.IsVertical )
{
// vertical text -> offset in y direction
aTranslation.translate( 0.0, nMinPos );
}
else
{
// horizontal text -> offset in x direction
aTranslation.translate( nMinPos, 0.0 );
}
::canvas::tools::appendToRenderState( io_rRenderState,
aTranslation );
}
// reduce DX array to given substring
const sal_Int32 nNewElements( rSubset.mnSubsetEnd - rSubset.mnSubsetBegin );
uno::Sequence< double > aAdaptedOffsets( nNewElements );
double* pAdaptedOffsets( aAdaptedOffsets.getArray() );
// move to new output position (subtract nMinPos,
// which is the new '0' position), copy only the range
// as given by rSubset.
::std::transform( pOffsets + rSubset.mnSubsetBegin,
pOffsets + rSubset.mnSubsetEnd,
pAdaptedOffsets,
[nMinPos](double aPos) { return aPos - nMinPos; } );
o_rMinPos = nMinPos;
o_rMaxPos = nMaxPos;
return aAdaptedOffsets;
}
uno::Reference< rendering::XTextLayout >
createSubsetLayout( const rendering::StringContext& rOrigContext,
const ::cppcanvas::internal::Action::Subset& rSubset,
const uno::Reference< rendering::XTextLayout >& rOrigTextLayout )
{
// create temporary new text layout with subset string
const sal_Int32 nNewStartPos( rOrigContext.StartPosition + ::std::min(
rSubset.mnSubsetBegin, rOrigContext.Length-1 ) );
const sal_Int32 nNewLength( ::std::max(
::std::min(
rSubset.mnSubsetEnd - rSubset.mnSubsetBegin,
rOrigContext.Length ),
sal_Int32( 0 ) ) );
const rendering::StringContext aContext( rOrigContext.Text,
nNewStartPos,
nNewLength );
uno::Reference< rendering::XTextLayout > xTextLayout(
rOrigTextLayout->getFont()->createTextLayout( aContext,
rOrigTextLayout->getMainTextDirection(),
0 ),
uno::UNO_QUERY_THROW );
return xTextLayout;
}
/** Setup subset text layout
@param io_rTextLayout
Must contain original (full set) text layout on input,
will contain subsetted text layout (or empty
reference, for empty subsets) on output.
@param io_rRenderState
Must contain original render state on input, will
contain shifted render state concatenated with
rTransformation on output.
@param rTransformation
Additional transformation, to be prepended to render
state
@param rSubset
Subset to prepare
*/
void createSubsetLayout( uno::Reference< rendering::XTextLayout >& io_rTextLayout,
rendering::RenderState& io_rRenderState,
double& o_rMinPos,
double& o_rMaxPos,
const ::basegfx::B2DHomMatrix& rTransformation,
const Action::Subset& rSubset )
{
::canvas::tools::prependToRenderState(io_rRenderState, rTransformation);
if( rSubset.mnSubsetBegin == rSubset.mnSubsetEnd )
{
// empty range, empty layout
io_rTextLayout.clear();
return;
}
ENSURE_OR_THROW( io_rTextLayout.is(),
"createSubsetLayout(): Invalid input layout" );
const rendering::StringContext& rOrigContext( io_rTextLayout->getText() );
if( rSubset.mnSubsetBegin == 0 &&
rSubset.mnSubsetEnd == rOrigContext.Length )
{
// full range, no need for subsetting
return;
}
uno::Reference< rendering::XTextLayout > xTextLayout(
createSubsetLayout( rOrigContext, rSubset, io_rTextLayout ) );
if( xTextLayout.is() )
{
xTextLayout->applyLogicalAdvancements(
calcSubsetOffsets( io_rRenderState,
o_rMinPos,
o_rMaxPos,
io_rTextLayout,
rSubset ) );
}
io_rTextLayout = xTextLayout;
}
/** Interface for renderEffectText functor below.
This is interface is used from the renderEffectText()
method below, to call the client implementation.
*/
class TextRenderer
{
public:
virtual ~TextRenderer() {}
/// Render text with given RenderState
virtual bool operator()( const rendering::RenderState& rRenderState ) const = 0;
};
/** Render effect text.
@param rRenderer
Functor object, will be called to render the actual
part of the text effect (the text itself and the means
to render it are unknown to this method)
*/
bool renderEffectText( const TextRenderer& rRenderer,
const rendering::RenderState& rRenderState,
const rendering::ViewState& /*rViewState*/,
const uno::Reference< rendering::XCanvas >& xCanvas,
const ::Color& rShadowColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rReliefOffset )
{
::Color aEmptyColor( COL_AUTO );
uno::Reference<rendering::XColorSpace> xColorSpace(
xCanvas->getDevice()->getDeviceColorSpace() );
// draw shadow text, if enabled
if( rShadowColor != aEmptyColor )
{
rendering::RenderState aShadowState( rRenderState );
::basegfx::B2DHomMatrix aTranslate;
aTranslate.translate( rShadowOffset.getX(),
rShadowOffset.getY() );
::canvas::tools::appendToRenderState(aShadowState, aTranslate);
aShadowState.DeviceColor =
vcl::unotools::colorToDoubleSequence( rShadowColor,
xColorSpace );
rRenderer( aShadowState );
}
// draw relief text, if enabled
if( rReliefColor != aEmptyColor )
{
rendering::RenderState aReliefState( rRenderState );
::basegfx::B2DHomMatrix aTranslate;
aTranslate.translate( rReliefOffset.getX(),
rReliefOffset.getY() );
::canvas::tools::appendToRenderState(aReliefState, aTranslate);
aReliefState.DeviceColor =
vcl::unotools::colorToDoubleSequence( rReliefColor,
xColorSpace );
rRenderer( aReliefState );
}
// draw normal text
rRenderer( rRenderState );
return true;
}
::basegfx::B2DRange calcEffectTextBounds( const ::basegfx::B2DRange& rTextBounds,
const ::basegfx::B2DRange& rLineBounds,
const ::basegfx::B2DSize& rReliefOffset,
const ::basegfx::B2DSize& rShadowOffset,
const rendering::RenderState& rRenderState,
const rendering::ViewState& rViewState )
{
::basegfx::B2DRange aBounds( rTextBounds );
// add extends of text lines
aBounds.expand( rLineBounds );
// TODO(Q3): Provide this functionality at the B2DRange
::basegfx::B2DRange aTotalBounds( aBounds );
aTotalBounds.expand(
::basegfx::B2DRange( aBounds.getMinX() + rReliefOffset.getX(),
aBounds.getMinY() + rReliefOffset.getY(),
aBounds.getMaxX() + rReliefOffset.getX(),
aBounds.getMaxY() + rReliefOffset.getY() ) );
aTotalBounds.expand(
::basegfx::B2DRange( aBounds.getMinX() + rShadowOffset.getX(),
aBounds.getMinY() + rShadowOffset.getY(),
aBounds.getMaxX() + rShadowOffset.getX(),
aBounds.getMaxY() + rShadowOffset.getY() ) );
return tools::calcDevicePixelBounds( aTotalBounds,
rViewState,
rRenderState );
}
void initEffectLinePolyPolygon( ::basegfx::B2DSize& o_rOverallSize,
uno::Reference< rendering::XPolyPolygon2D >& o_rTextLines,
const CanvasSharedPtr& rCanvas,
const uno::Sequence< double >& rOffsets,
const tools::TextLineInfo& rLineInfo )
{
const ::basegfx::B2DPolyPolygon aPoly(
textLinesFromLogicalOffsets(
rOffsets,
rLineInfo ) );
o_rOverallSize = ::basegfx::tools::getRange( aPoly ).getRange();
o_rTextLines = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
rCanvas->getUNOCanvas()->getDevice(),
aPoly );
}
void initEffectLinePolyPolygon( ::basegfx::B2DSize& o_rOverallSize,
uno::Reference< rendering::XPolyPolygon2D >& o_rTextLines,
const CanvasSharedPtr& rCanvas,
double nLineWidth,
const tools::TextLineInfo& rLineInfo )
{
const ::basegfx::B2DPolyPolygon aPoly(
tools::createTextLinesPolyPolygon( 0.0, nLineWidth,
rLineInfo ) );
o_rOverallSize = ::basegfx::tools::getRange( aPoly ).getRange();
o_rTextLines = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
rCanvas->getUNOCanvas()->getDevice(),
aPoly );
}
class TextAction : public Action, private ::boost::noncopyable
{
public:
TextAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState );
TextAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform );
virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual sal_Int32 getActionCount() const override;
private:
// TODO(P2): This is potentially a real mass object
// (every character might be a separate TextAction),
// thus, make it as lightweight as possible. For
// example, share common RenderState among several
// TextActions, maybe using maOffsets for the
// translation.
uno::Reference< rendering::XCanvasFont > mxFont;
const rendering::StringContext maStringContext;
const CanvasSharedPtr mpCanvas;
rendering::RenderState maState;
const sal_Int8 maTextDirection;
};
TextAction::TextAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState ) :
mxFont( rState.xFont ),
maStringContext( rString, nStartPos, nLen ),
mpCanvas( rCanvas ),
maState(),
maTextDirection( rState.textDirection )
{
init( maState, mxFont,
rStartPoint,
rState, rCanvas );
ENSURE_OR_THROW( mxFont.is(),
"::cppcanvas::internal::TextAction(): Invalid font" );
}
TextAction::TextAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform ) :
mxFont( rState.xFont ),
maStringContext( rString, nStartPos, nLen ),
mpCanvas( rCanvas ),
maState(),
maTextDirection( rState.textDirection )
{
init( maState, mxFont,
rStartPoint,
rState, rCanvas, rTextTransform );
ENSURE_OR_THROW( mxFont.is(),
"::cppcanvas::internal::TextAction(): Invalid font" );
}
bool TextAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextAction::render()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
mpCanvas->getUNOCanvas()->drawText( maStringContext, mxFont,
mpCanvas->getViewState(), aLocalState, maTextDirection );
return true;
}
bool TextAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& /*rSubset*/ ) const
{
SAL_WARN( "cppcanvas.emf", "TextAction::renderSubset(): Subset not supported by this object" );
// TODO(P1): Retrieve necessary font metric info for
// TextAction from XCanvas. Currently, the
// TextActionFactory does not generate this object for
// _subsettable_ text
return render( rTransformation );
}
::basegfx::B2DRange TextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
// create XTextLayout, to have the
// XTextLayout::queryTextBounds() method available
uno::Reference< rendering::XTextLayout > xTextLayout(
mxFont->createTextLayout(
maStringContext,
maTextDirection,
0 ) );
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return tools::calcDevicePixelBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D(
xTextLayout->queryTextBounds() ),
mpCanvas->getViewState(),
aLocalState );
}
::basegfx::B2DRange TextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& /*rSubset*/ ) const
{
SAL_WARN( "cppcanvas.emf", "TextAction::getBounds(): Subset not supported by this object" );
// TODO(P1): Retrieve necessary font metric info for
// TextAction from XCanvas. Currently, the
// TextActionFactory does not generate this object for
// _subsettable_ text
return getBounds( rTransformation );
}
sal_Int32 TextAction::getActionCount() const
{
// TODO(P1): Retrieve necessary font metric info for
// TextAction from XCanvas. Currently, the
// TextActionFactory does not generate this object for
// _subsettable_ text
return 1;
}
class EffectTextAction :
public Action,
public TextRenderer,
private ::boost::noncopyable
{
public:
EffectTextAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState );
EffectTextAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform );
virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual sal_Int32 getActionCount() const override;
private:
/// Interface TextRenderer
virtual bool operator()( const rendering::RenderState& rRenderState ) const override;
// TODO(P2): This is potentially a real mass object
// (every character might be a separate TextAction),
// thus, make it as lightweight as possible. For
// example, share common RenderState among several
// TextActions, maybe using maOffsets for the
// translation.
uno::Reference< rendering::XCanvasFont > mxFont;
const rendering::StringContext maStringContext;
const CanvasSharedPtr mpCanvas;
rendering::RenderState maState;
const tools::TextLineInfo maTextLineInfo;
::basegfx::B2DSize maLinesOverallSize;
const double mnLineWidth;
uno::Reference< rendering::XPolyPolygon2D > mxTextLines;
const ::basegfx::B2DSize maReliefOffset;
const ::Color maReliefColor;
const ::basegfx::B2DSize maShadowOffset;
const ::Color maShadowColor;
const sal_Int8 maTextDirection;
};
EffectTextAction::EffectTextAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState ) :
mxFont( rState.xFont ),
maStringContext( rText, nStartPos, nLen ),
mpCanvas( rCanvas ),
maState(),
maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ),
maLinesOverallSize(),
mnLineWidth( getLineWidth( rVDev, rState, maStringContext ) ),
mxTextLines(),
maReliefOffset( rReliefOffset ),
maReliefColor( rReliefColor ),
maShadowOffset( rShadowOffset ),
maShadowColor( rShadowColor ),
maTextDirection( rState.textDirection )
{
initEffectLinePolyPolygon( maLinesOverallSize,
mxTextLines,
rCanvas,
mnLineWidth,
maTextLineInfo );
init( maState, mxFont,
rStartPoint,
rState, rCanvas );
ENSURE_OR_THROW( mxFont.is() && mxTextLines.is(),
"::cppcanvas::internal::EffectTextAction(): Invalid font or lines" );
}
EffectTextAction::EffectTextAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform ) :
mxFont( rState.xFont ),
maStringContext( rText, nStartPos, nLen ),
mpCanvas( rCanvas ),
maState(),
maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ),
maLinesOverallSize(),
mnLineWidth( getLineWidth( rVDev, rState, maStringContext ) ),
mxTextLines(),
maReliefOffset( rReliefOffset ),
maReliefColor( rReliefColor ),
maShadowOffset( rShadowOffset ),
maShadowColor( rShadowColor ),
maTextDirection( rState.textDirection )
{
initEffectLinePolyPolygon( maLinesOverallSize,
mxTextLines,
rCanvas,
mnLineWidth,
maTextLineInfo );
init( maState, mxFont,
rStartPoint,
rState, rCanvas, rTextTransform );
ENSURE_OR_THROW( mxFont.is() && mxTextLines.is(),
"::cppcanvas::internal::EffectTextAction(): Invalid font or lines" );
}
bool EffectTextAction::operator()( const rendering::RenderState& rRenderState ) const
{
const rendering::ViewState& rViewState( mpCanvas->getViewState() );
const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() );
rCanvas->fillPolyPolygon( mxTextLines,
rViewState,
rRenderState );
rCanvas->drawText( maStringContext, mxFont,
rViewState,
rRenderState,
maTextDirection );
return true;
}
bool EffectTextAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextAction::render()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return renderEffectText( *this,
aLocalState,
mpCanvas->getViewState(),
mpCanvas->getUNOCanvas(),
maShadowColor,
maShadowOffset,
maReliefColor,
maReliefOffset );
}
bool EffectTextAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& /*rSubset*/ ) const
{
SAL_WARN( "cppcanvas.emf", "EffectTextAction::renderSubset(): Subset not supported by this object" );
// TODO(P1): Retrieve necessary font metric info for
// TextAction from XCanvas. Currently, the
// TextActionFactory does not generate this object for
// subsettable text
return render( rTransformation );
}
::basegfx::B2DRange EffectTextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
// create XTextLayout, to have the
// XTextLayout::queryTextBounds() method available
uno::Reference< rendering::XTextLayout > xTextLayout(
mxFont->createTextLayout(
maStringContext,
maTextDirection,
0 ) );
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return calcEffectTextBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D(
xTextLayout->queryTextBounds() ),
::basegfx::B2DRange( 0,0,
maLinesOverallSize.getX(),
maLinesOverallSize.getY() ),
maReliefOffset,
maShadowOffset,
aLocalState,
mpCanvas->getViewState() );
}
::basegfx::B2DRange EffectTextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& /*rSubset*/ ) const
{
SAL_WARN( "cppcanvas.emf", "EffectTextAction::getBounds(): Subset not supported by this object" );
// TODO(P1): Retrieve necessary font metric info for
// TextAction from XCanvas. Currently, the
// TextActionFactory does not generate this object for
// _subsettable_ text
return getBounds( rTransformation );
}
sal_Int32 EffectTextAction::getActionCount() const
{
// TODO(P1): Retrieve necessary font metric info for
// TextAction from XCanvas. Currently, the
// TextActionFactory does not generate this object for
// subsettable text
return 1;
}
class TextArrayAction : public Action, private ::boost::noncopyable
{
public:
TextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState );
TextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform );
virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual sal_Int32 getActionCount() const override;
private:
// TODO(P2): This is potentially a real mass object
// (every character might be a separate TextAction),
// thus, make it as lightweight as possible. For
// example, share common RenderState among several
// TextActions, maybe using maOffsets for the
// translation.
uno::Reference< rendering::XTextLayout > mxTextLayout;
const CanvasSharedPtr mpCanvas;
rendering::RenderState maState;
};
TextArrayAction::TextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState ) :
mxTextLayout(),
mpCanvas( rCanvas ),
maState()
{
initArrayAction( maState,
mxTextLayout,
rStartPoint,
rString,
nStartPos,
nLen,
rOffsets,
rCanvas,
rState, NULL );
}
TextArrayAction::TextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const OUString& rString,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform ) :
mxTextLayout(),
mpCanvas( rCanvas ),
maState()
{
initArrayAction( maState,
mxTextLayout,
rStartPoint,
rString,
nStartPos,
nLen,
rOffsets,
rCanvas,
rState,
&rTextTransform );
}
bool TextArrayAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextArrayAction::render()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextArrayAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
mpCanvas->getUNOCanvas()->drawTextLayout( mxTextLayout,
mpCanvas->getViewState(),
aLocalState );
return true;
}
bool TextArrayAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextArrayAction::renderSubset()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextArrayAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout );
double nDummy0, nDummy1;
createSubsetLayout( xTextLayout,
aLocalState,
nDummy0,
nDummy1,
rTransformation,
rSubset );
if( !xTextLayout.is() )
return true; // empty layout, render nothing
mpCanvas->getUNOCanvas()->drawTextLayout( xTextLayout,
mpCanvas->getViewState(),
aLocalState );
return true;
}
::basegfx::B2DRange TextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return tools::calcDevicePixelBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D(
mxTextLayout->queryTextBounds() ),
mpCanvas->getViewState(),
aLocalState );
}
::basegfx::B2DRange TextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextArrayAction::getBounds( subset )" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::TextArrayAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout );
double nDummy0, nDummy1;
createSubsetLayout( xTextLayout,
aLocalState,
nDummy0,
nDummy1,
rTransformation,
rSubset );
if( !xTextLayout.is() )
return ::basegfx::B2DRange(); // empty layout, empty bounds
return tools::calcDevicePixelBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D(
xTextLayout->queryTextBounds() ),
mpCanvas->getViewState(),
aLocalState );
}
sal_Int32 TextArrayAction::getActionCount() const
{
const rendering::StringContext& rOrigContext( mxTextLayout->getText() );
return rOrigContext.Length;
}
class EffectTextArrayAction :
public Action,
public TextRenderer,
private ::boost::noncopyable
{
public:
EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState );
EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform );
virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual sal_Int32 getActionCount() const override;
private:
// TextRenderer interface
virtual bool operator()( const rendering::RenderState& rRenderState ) const override;
// TODO(P2): This is potentially a real mass object
// (every character might be a separate TextAction),
// thus, make it as lightweight as possible. For
// example, share common RenderState among several
// TextActions, maybe using maOffsets for the
// translation.
uno::Reference< rendering::XTextLayout > mxTextLayout;
const CanvasSharedPtr mpCanvas;
rendering::RenderState maState;
const tools::TextLineInfo maTextLineInfo;
::basegfx::B2DSize maLinesOverallSize;
uno::Reference< rendering::XPolyPolygon2D > mxTextLines;
const ::basegfx::B2DSize maReliefOffset;
const ::Color maReliefColor;
const ::basegfx::B2DSize maShadowOffset;
const ::Color maShadowColor;
};
EffectTextArrayAction::EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState ) :
mxTextLayout(),
mpCanvas( rCanvas ),
maState(),
maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ),
maLinesOverallSize(),
mxTextLines(),
maReliefOffset( rReliefOffset ),
maReliefColor( rReliefColor ),
maShadowOffset( rShadowOffset ),
maShadowColor( rShadowColor )
{
initEffectLinePolyPolygon( maLinesOverallSize,
mxTextLines,
rCanvas,
rOffsets,
maTextLineInfo );
initArrayAction( maState,
mxTextLayout,
rStartPoint,
rText,
nStartPos,
nLen,
rOffsets,
rCanvas,
rState, NULL );
}
EffectTextArrayAction::EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform ) :
mxTextLayout(),
mpCanvas( rCanvas ),
maState(),
maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ),
maLinesOverallSize(),
mxTextLines(),
maReliefOffset( rReliefOffset ),
maReliefColor( rReliefColor ),
maShadowOffset( rShadowOffset ),
maShadowColor( rShadowColor )
{
initEffectLinePolyPolygon( maLinesOverallSize,
mxTextLines,
rCanvas,
rOffsets,
maTextLineInfo );
initArrayAction( maState,
mxTextLayout,
rStartPoint,
rText,
nStartPos,
nLen,
rOffsets,
rCanvas,
rState,
&rTextTransform );
}
bool EffectTextArrayAction::operator()( const rendering::RenderState& rRenderState ) const
{
const rendering::ViewState& rViewState( mpCanvas->getViewState() );
const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() );
rCanvas->fillPolyPolygon( mxTextLines,
rViewState,
rRenderState );
rCanvas->drawTextLayout( mxTextLayout,
rViewState,
rRenderState );
return true;
}
bool EffectTextArrayAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction::render()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return renderEffectText( *this,
aLocalState,
mpCanvas->getViewState(),
mpCanvas->getUNOCanvas(),
maShadowColor,
maShadowOffset,
maReliefColor,
maReliefOffset );
}
class EffectTextArrayRenderHelper : public TextRenderer
{
public:
EffectTextArrayRenderHelper( const uno::Reference< rendering::XCanvas >& rCanvas,
const uno::Reference< rendering::XTextLayout >& rTextLayout,
const uno::Reference< rendering::XPolyPolygon2D >& rLinePolygon,
const rendering::ViewState& rViewState ) :
mrCanvas( rCanvas ),
mrTextLayout( rTextLayout ),
mrLinePolygon( rLinePolygon ),
mrViewState( rViewState )
{
}
// TextRenderer interface
virtual bool operator()( const rendering::RenderState& rRenderState ) const override
{
mrCanvas->fillPolyPolygon( mrLinePolygon,
mrViewState,
rRenderState );
mrCanvas->drawTextLayout( mrTextLayout,
mrViewState,
rRenderState );
return true;
}
private:
const uno::Reference< rendering::XCanvas >& mrCanvas;
const uno::Reference< rendering::XTextLayout >& mrTextLayout;
const uno::Reference< rendering::XPolyPolygon2D >& mrLinePolygon;
const rendering::ViewState& mrViewState;
};
bool EffectTextArrayAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction::renderSubset()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout );
const geometry::RealRectangle2D aTextBounds( mxTextLayout->queryTextBounds() );
double nMinPos(0.0);
double nMaxPos(aTextBounds.X2 - aTextBounds.X1);
createSubsetLayout( xTextLayout,
aLocalState,
nMinPos,
nMaxPos,
rTransformation,
rSubset );
if( !xTextLayout.is() )
return true; // empty layout, render nothing
// create and setup local line polygon
// ===================================
uno::Reference< rendering::XCanvas > xCanvas( mpCanvas->getUNOCanvas() );
const rendering::ViewState& rViewState( mpCanvas->getViewState() );
uno::Reference< rendering::XPolyPolygon2D > xTextLines(
::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
xCanvas->getDevice(),
tools::createTextLinesPolyPolygon(
0.0, nMaxPos - nMinPos,
maTextLineInfo ) ) );
// render everything
// =================
return renderEffectText(
EffectTextArrayRenderHelper( xCanvas,
xTextLayout,
xTextLines,
rViewState ),
aLocalState,
rViewState,
xCanvas,
maShadowColor,
maShadowOffset,
maReliefColor,
maReliefOffset );
}
::basegfx::B2DRange EffectTextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return calcEffectTextBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D(
mxTextLayout->queryTextBounds() ),
::basegfx::B2DRange( 0,0,
maLinesOverallSize.getX(),
maLinesOverallSize.getY() ),
maReliefOffset,
maShadowOffset,
aLocalState,
mpCanvas->getViewState() );
}
::basegfx::B2DRange EffectTextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction::getBounds( subset )" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout );
const geometry::RealRectangle2D aTextBounds( mxTextLayout->queryTextBounds() );
double nMinPos(0.0);
double nMaxPos(aTextBounds.X2 - aTextBounds.X1);
createSubsetLayout( xTextLayout,
aLocalState,
nMinPos,
nMaxPos,
rTransformation,
rSubset );
if( !xTextLayout.is() )
return ::basegfx::B2DRange(); // empty layout, empty bounds
// create and setup local line polygon
// ===================================
const ::basegfx::B2DPolyPolygon aPoly(
tools::createTextLinesPolyPolygon(
0.0, nMaxPos - nMinPos,
maTextLineInfo ) );
return calcEffectTextBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D(
xTextLayout->queryTextBounds() ),
::basegfx::tools::getRange( aPoly ),
maReliefOffset,
maShadowOffset,
aLocalState,
mpCanvas->getViewState() );
}
sal_Int32 EffectTextArrayAction::getActionCount() const
{
const rendering::StringContext& rOrigContext( mxTextLayout->getText() );
return rOrigContext.Length;
}
class OutlineAction :
public Action,
public TextRenderer,
private ::boost::noncopyable
{
public:
OutlineAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const ::basegfx::B2DRectangle& rOutlineBounds,
const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly,
const ::std::vector< sal_Int32 >& rPolygonGlyphMap,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState );
OutlineAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const ::basegfx::B2DRectangle& rOutlineBounds,
const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly,
const ::std::vector< sal_Int32 >& rPolygonGlyphMap,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform );
virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const override;
virtual sal_Int32 getActionCount() const override;
private:
// TextRenderer interface
virtual bool operator()( const rendering::RenderState& rRenderState ) const override;
// TODO(P2): This is potentially a real mass object
// (every character might be a separate TextAction),
// thus, make it as lightweight as possible. For
// example, share common RenderState among several
// TextActions, maybe using maOffsets for the
// translation.
uno::Reference< rendering::XPolyPolygon2D > mxTextPoly;
/** This vector denotes the index of the start polygon
for the respective glyph sequence.
To get a polygon index range for a given character
index i, take [ maPolygonGlyphMap[i],
maPolygonGlyphMap[i+1] ). Note that this is wrong
for BiDi
*/
const ::std::vector< sal_Int32 > maPolygonGlyphMap;
const uno::Sequence< double > maOffsets;
const CanvasSharedPtr mpCanvas;
rendering::RenderState maState;
double mnOutlineWidth;
const uno::Sequence< double > maFillColor;
const tools::TextLineInfo maTextLineInfo;
::basegfx::B2DSize maLinesOverallSize;
const ::basegfx::B2DRectangle maOutlineBounds;
uno::Reference< rendering::XPolyPolygon2D > mxTextLines;
const ::basegfx::B2DSize maReliefOffset;
const ::Color maReliefColor;
const ::basegfx::B2DSize maShadowOffset;
const ::Color maShadowColor;
};
double calcOutlineWidth( const OutDevState& rState,
VirtualDevice& rVDev )
{
const ::basegfx::B2DSize aFontSize( 0,
rVDev.GetFont().GetHeight() / 64.0 );
const double nOutlineWidth(
(rState.mapModeTransform * aFontSize).getY() );
return nOutlineWidth < 1.0 ? 1.0 : nOutlineWidth;
}
OutlineAction::OutlineAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const ::basegfx::B2DRectangle& rOutlineBounds,
const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly,
const ::std::vector< sal_Int32 >& rPolygonGlyphMap,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState ) :
mxTextPoly( rTextPoly ),
maPolygonGlyphMap( rPolygonGlyphMap ),
maOffsets( rOffsets ),
mpCanvas( rCanvas ),
maState(),
mnOutlineWidth( calcOutlineWidth(rState,rVDev) ),
maFillColor(
vcl::unotools::colorToDoubleSequence(
::Color( COL_WHITE ),
rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() )),
maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ),
maLinesOverallSize(),
maOutlineBounds( rOutlineBounds ),
mxTextLines(),
maReliefOffset( rReliefOffset ),
maReliefColor( rReliefColor ),
maShadowOffset( rShadowOffset ),
maShadowColor( rShadowColor )
{
initEffectLinePolyPolygon( maLinesOverallSize,
mxTextLines,
rCanvas,
rOffsets,
maTextLineInfo );
init( maState,
rStartPoint,
rState,
rCanvas );
}
OutlineAction::OutlineAction( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const ::basegfx::B2DRectangle& rOutlineBounds,
const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly,
const ::std::vector< sal_Int32 >& rPolygonGlyphMap,
const uno::Sequence< double >& rOffsets,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const ::basegfx::B2DHomMatrix& rTextTransform ) :
mxTextPoly( rTextPoly ),
maPolygonGlyphMap( rPolygonGlyphMap ),
maOffsets( rOffsets ),
mpCanvas( rCanvas ),
maState(),
mnOutlineWidth( calcOutlineWidth(rState,rVDev) ),
maFillColor(
vcl::unotools::colorToDoubleSequence(
::Color( COL_WHITE ),
rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() )),
maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ),
maLinesOverallSize(),
maOutlineBounds( rOutlineBounds ),
mxTextLines(),
maReliefOffset( rReliefOffset ),
maReliefColor( rReliefColor ),
maShadowOffset( rShadowOffset ),
maShadowColor( rShadowColor )
{
initEffectLinePolyPolygon( maLinesOverallSize,
mxTextLines,
rCanvas,
rOffsets,
maTextLineInfo );
init( maState,
rStartPoint,
rState,
rCanvas,
rTextTransform );
}
bool OutlineAction::operator()( const rendering::RenderState& rRenderState ) const
{
const rendering::ViewState& rViewState( mpCanvas->getViewState() );
const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() );
rendering::StrokeAttributes aStrokeAttributes;
aStrokeAttributes.StrokeWidth = mnOutlineWidth;
aStrokeAttributes.MiterLimit = 1.0;
aStrokeAttributes.StartCapType = rendering::PathCapType::BUTT;
aStrokeAttributes.EndCapType = rendering::PathCapType::BUTT;
aStrokeAttributes.JoinType = rendering::PathJoinType::MITER;
rendering::RenderState aLocalState( rRenderState );
aLocalState.DeviceColor = maFillColor;
// TODO(P1): implement caching
// background of text
rCanvas->fillPolyPolygon( mxTextPoly,
rViewState,
aLocalState );
// border line of text
rCanvas->strokePolyPolygon( mxTextPoly,
rViewState,
rRenderState,
aStrokeAttributes );
// underlines/strikethrough - background
rCanvas->fillPolyPolygon( mxTextLines,
rViewState,
aLocalState );
// underlines/strikethrough - border
rCanvas->strokePolyPolygon( mxTextLines,
rViewState,
rRenderState,
aStrokeAttributes );
return true;
}
bool OutlineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction::render()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::EffectTextArrayAction: 0x" << std::hex << this );
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return renderEffectText( *this,
aLocalState,
mpCanvas->getViewState(),
mpCanvas->getUNOCanvas(),
maShadowColor,
maShadowOffset,
maReliefColor,
maReliefOffset );
}
#if 0 // see #if'ed out use in OutlineAction::renderSubset below:
class OutlineTextArrayRenderHelper : public TextRenderer
{
public:
OutlineTextArrayRenderHelper( const uno::Reference< rendering::XCanvas >& rCanvas,
const uno::Reference< rendering::XPolyPolygon2D >& rTextPolygon,
const uno::Reference< rendering::XPolyPolygon2D >& rLinePolygon,
const rendering::ViewState& rViewState,
double nOutlineWidth ) :
maFillColor(
vcl::unotools::colorToDoubleSequence(
::Color( COL_WHITE ),
rCanvas->getDevice()->getDeviceColorSpace() )),
mnOutlineWidth( nOutlineWidth ),
mrCanvas( rCanvas ),
mrTextPolygon( rTextPolygon ),
mrLinePolygon( rLinePolygon ),
mrViewState( rViewState )
{
}
// TextRenderer interface
virtual bool operator()( const rendering::RenderState& rRenderState ) const
{
rendering::StrokeAttributes aStrokeAttributes;
aStrokeAttributes.StrokeWidth = mnOutlineWidth;
aStrokeAttributes.MiterLimit = 1.0;
aStrokeAttributes.StartCapType = rendering::PathCapType::BUTT;
aStrokeAttributes.EndCapType = rendering::PathCapType::BUTT;
aStrokeAttributes.JoinType = rendering::PathJoinType::MITER;
rendering::RenderState aLocalState( rRenderState );
aLocalState.DeviceColor = maFillColor;
// TODO(P1): implement caching
// background of text
mrCanvas->fillPolyPolygon( mrTextPolygon,
mrViewState,
aLocalState );
// border line of text
mrCanvas->strokePolyPolygon( mrTextPolygon,
mrViewState,
rRenderState,
aStrokeAttributes );
// underlines/strikethrough - background
mrCanvas->fillPolyPolygon( mrLinePolygon,
mrViewState,
aLocalState );
// underlines/strikethrough - border
mrCanvas->strokePolyPolygon( mrLinePolygon,
mrViewState,
rRenderState,
aStrokeAttributes );
return true;
}
private:
const uno::Sequence< double > maFillColor;
double mnOutlineWidth;
const uno::Reference< rendering::XCanvas >& mrCanvas;
const uno::Reference< rendering::XPolyPolygon2D >& mrTextPolygon;
const uno::Reference< rendering::XPolyPolygon2D >& mrLinePolygon;
const rendering::ViewState& mrViewState;
};
#endif
bool OutlineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& rSubset ) const
{
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::OutlineAction::renderSubset()" );
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::OutlineAction: 0x" << std::hex << this );
if( rSubset.mnSubsetBegin == rSubset.mnSubsetEnd )
return true; // empty range, render nothing
#if 1
// TODO(F3): Subsetting NYI for outline text!
return render( rTransformation );
#else
const rendering::StringContext rOrigContext( mxTextLayout->getText() );
if( rSubset.mnSubsetBegin == 0 &&
rSubset.mnSubsetEnd == rOrigContext.Length )
{
// full range, no need for subsetting
return render( rTransformation );
}
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
// create and setup local Text polygon
// ===================================
uno::Reference< rendering::XPolyPolygon2D > xTextPolygon();
// TODO(P3): Provide an API method for that!
if( !xTextLayout.is() )
return false;
// render everything
// =================
return renderEffectText(
OutlineTextArrayRenderHelper(
xCanvas,
mnOutlineWidth,
xTextLayout,
xTextLines,
rViewState ),
aLocalState,
rViewState,
xCanvas,
maShadowColor,
maShadowOffset,
maReliefColor,
maReliefOffset );
#endif
}
::basegfx::B2DRange OutlineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
{
rendering::RenderState aLocalState( maState );
::canvas::tools::prependToRenderState(aLocalState, rTransformation);
return calcEffectTextBounds( maOutlineBounds,
::basegfx::B2DRange( 0,0,
maLinesOverallSize.getX(),
maLinesOverallSize.getY() ),
maReliefOffset,
maShadowOffset,
aLocalState,
mpCanvas->getViewState() );
}
::basegfx::B2DRange OutlineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
const Subset& /*rSubset*/ ) const
{
SAL_WARN( "cppcanvas.emf", "OutlineAction::getBounds(): Subset not yet supported by this object" );
return getBounds( rTransformation );
}
sal_Int32 OutlineAction::getActionCount() const
{
// TODO(F3): Subsetting NYI for outline text!
return maOffsets.getLength();
}
// Action factory methods
/** Create an outline action
This method extracts the polygonal outline from the
text, and creates a properly setup OutlineAction from
it.
*/
ActionSharedPtr createOutline( const ::basegfx::B2DPoint& rStartPoint,
const ::basegfx::B2DSize& rReliefOffset,
const ::Color& rReliefColor,
const ::basegfx::B2DSize& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
const long* pDXArray,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const Renderer::Parameters& rParms )
{
// operate on raw DX array here (in logical coordinate
// system), to have a higher resolution
// PolyPolygon. That polygon is then converted to
// device coordinate system.
// #i68512# Temporarily switch off font rotation
// (which is already contained in the render state
// transformation matrix - otherwise, glyph polygons
// will be rotated twice)
const vcl::Font aOrigFont( rVDev.GetFont() );
vcl::Font aUnrotatedFont( aOrigFont );
aUnrotatedFont.SetOrientation(0);
rVDev.SetFont( aUnrotatedFont );
// TODO(F3): Don't understand parameter semantics of
// GetTextOutlines()
::basegfx::B2DPolyPolygon aResultingPolyPolygon;
PolyPolyVector aVCLPolyPolyVector;
const bool bHaveOutlines( rVDev.GetTextOutlines( aVCLPolyPolyVector, rText,
static_cast<sal_uInt16>(nStartPos),
static_cast<sal_uInt16>(nStartPos),
static_cast<sal_uInt16>(nLen),
true, 0, pDXArray ) );
rVDev.SetFont(aOrigFont);
if( !bHaveOutlines )
return ActionSharedPtr();
::std::vector< sal_Int32 > aPolygonGlyphMap;
// first glyph starts at polygon index 0
aPolygonGlyphMap.push_back( 0 );
// remove offsetting from mapmode transformation
// (outline polygons must stay at origin, only need to
// be scaled)
::basegfx::B2DHomMatrix aMapModeTransform(
rState.mapModeTransform );
aMapModeTransform.set(0,2, 0.0);
aMapModeTransform.set(1,2, 0.0);
PolyPolyVector::const_iterator aIter( aVCLPolyPolyVector.begin() );
const PolyPolyVector::const_iterator aEnd( aVCLPolyPolyVector.end() );
for( ; aIter!= aEnd; ++aIter )
{
::basegfx::B2DPolyPolygon aPolyPolygon;
aPolyPolygon = aIter->getB2DPolyPolygon();
aPolyPolygon.transform( aMapModeTransform );
// append result to collecting polypoly
for( sal_uInt32 i=0; i<aPolyPolygon.count(); ++i )
{
// #i47795# Ensure closed polygons (since
// FreeType returns the glyph outlines
// open)
const ::basegfx::B2DPolygon& rPoly( aPolyPolygon.getB2DPolygon( i ) );
const sal_uInt32 nCount( rPoly.count() );
if( nCount<3 ||
rPoly.isClosed() )
{
// polygon either degenerate, or
// already closed.
aResultingPolyPolygon.append( rPoly );
}
else
{
::basegfx::B2DPolygon aPoly(rPoly);
aPoly.setClosed(true);
aResultingPolyPolygon.append( aPoly );
}
}
// TODO(F3): Depending on the semantics of
// GetTextOutlines(), this here is wrong!
// calc next glyph index
aPolygonGlyphMap.push_back( aResultingPolyPolygon.count() );
}
const uno::Sequence< double > aCharWidthSeq(
pDXArray ?
setupDXArray( pDXArray, nLen, rState ) :
setupDXArray( rText,
nStartPos,
nLen,
rVDev,
rState ));
const uno::Reference< rendering::XPolyPolygon2D > xTextPoly(
::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
rCanvas->getUNOCanvas()->getDevice(),
aResultingPolyPolygon ) );
if( rParms.maTextTransformation.is_initialized() )
{
return ActionSharedPtr(
new OutlineAction(
rStartPoint,
rReliefOffset,
rReliefColor,
rShadowOffset,
rShadowColor,
::basegfx::tools::getRange(aResultingPolyPolygon),
xTextPoly,
aPolygonGlyphMap,
aCharWidthSeq,
rVDev,
rCanvas,
rState,
*rParms.maTextTransformation ) );
}
else
{
return ActionSharedPtr(
new OutlineAction(
rStartPoint,
rReliefOffset,
rReliefColor,
rShadowOffset,
rShadowColor,
::basegfx::tools::getRange(aResultingPolyPolygon),
xTextPoly,
aPolygonGlyphMap,
aCharWidthSeq,
rVDev,
rCanvas,
rState ) );
}
}
} // namespace
ActionSharedPtr TextActionFactory::createTextAction( const ::Point& rStartPoint,
const ::Size& rReliefOffset,
const ::Color& rReliefColor,
const ::Size& rShadowOffset,
const ::Color& rShadowColor,
const OUString& rText,
sal_Int32 nStartPos,
sal_Int32 nLen,
const long* pDXArray,
VirtualDevice& rVDev,
const CanvasSharedPtr& rCanvas,
const OutDevState& rState,
const Renderer::Parameters& rParms,
bool bSubsettable )
{
const ::Size aBaselineOffset( tools::getBaselineOffset( rState,
rVDev ) );
// #143885# maintain (nearly) full precision positioning,
// by circumventing integer-based OutDev-mapping
const ::basegfx::B2DPoint aStartPoint(
rState.mapModeTransform *
::basegfx::B2DPoint(rStartPoint.X() + aBaselineOffset.Width(),
rStartPoint.Y() + aBaselineOffset.Height()) );
const ::basegfx::B2DSize aReliefOffset(
rState.mapModeTransform * vcl::unotools::b2DSizeFromSize( rReliefOffset ) );
const ::basegfx::B2DSize aShadowOffset(
rState.mapModeTransform * vcl::unotools::b2DSizeFromSize( rShadowOffset ) );
if( rState.isTextOutlineModeSet )
{
return createOutline(
aStartPoint,
aReliefOffset,
rReliefColor,
aShadowOffset,
rShadowColor,
rText,
nStartPos,
nLen,
pDXArray,
rVDev,
rCanvas,
rState,
rParms );
}
// convert DX array to device coordinate system (and
// create it in the first place, if pDXArray is NULL)
const uno::Sequence< double > aCharWidths(
pDXArray ?
setupDXArray( pDXArray, nLen, rState ) :
setupDXArray( rText,
nStartPos,
nLen,
rVDev,
rState ));
// determine type of text action to create
// =======================================
const ::Color aEmptyColor( COL_AUTO );
ActionSharedPtr ret;
// no DX array, and no need to subset - no need to store
// DX array, then.
if( !pDXArray && !bSubsettable )
{
// effects, or not?
if( !rState.textOverlineStyle &&
!rState.textUnderlineStyle &&
!rState.textStrikeoutStyle &&
rReliefColor == aEmptyColor &&
rShadowColor == aEmptyColor )
{
// nope
if( rParms.maTextTransformation.is_initialized() )
{
ret = ActionSharedPtr( new TextAction(
aStartPoint,
rText,
nStartPos,
nLen,
rCanvas,
rState,
*rParms.maTextTransformation ) );
}
else
{
ret = ActionSharedPtr( new TextAction(
aStartPoint,
rText,
nStartPos,
nLen,
rCanvas,
rState ) );
}
}
else
{
// at least one of the effects requested
if( rParms.maTextTransformation.is_initialized() )
ret = ActionSharedPtr( new EffectTextAction(
aStartPoint,
aReliefOffset,
rReliefColor,
aShadowOffset,
rShadowColor,
rText,
nStartPos,
nLen,
rVDev,
rCanvas,
rState,
*rParms.maTextTransformation ) );
else
ret = ActionSharedPtr( new EffectTextAction(
aStartPoint,
aReliefOffset,
rReliefColor,
aShadowOffset,
rShadowColor,
rText,
nStartPos,
nLen,
rVDev,
rCanvas,
rState ) );
}
}
else
{
// DX array necessary - any effects?
if( !rState.textOverlineStyle &&
!rState.textUnderlineStyle &&
!rState.textStrikeoutStyle &&
rReliefColor == aEmptyColor &&
rShadowColor == aEmptyColor )
{
// nope
if( rParms.maTextTransformation.is_initialized() )
ret = ActionSharedPtr( new TextArrayAction(
aStartPoint,
rText,
nStartPos,
nLen,
aCharWidths,
rCanvas,
rState,
*rParms.maTextTransformation ) );
else
ret = ActionSharedPtr( new TextArrayAction(
aStartPoint,
rText,
nStartPos,
nLen,
aCharWidths,
rCanvas,
rState ) );
}
else
{
// at least one of the effects requested
if( rParms.maTextTransformation.is_initialized() )
ret = ActionSharedPtr( new EffectTextArrayAction(
aStartPoint,
aReliefOffset,
rReliefColor,
aShadowOffset,
rShadowColor,
rText,
nStartPos,
nLen,
aCharWidths,
rVDev,
rCanvas,
rState,
*rParms.maTextTransformation ) );
else
ret = ActionSharedPtr( new EffectTextArrayAction(
aStartPoint,
aReliefOffset,
rReliefColor,
aShadowOffset,
rShadowColor,
rText,
nStartPos,
nLen,
aCharWidths,
rVDev,
rCanvas,
rState ) );
}
}
return ret;
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|