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
|
/* -*- 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 "xexptran.hxx"
#include <tools/debug.hxx>
#include <rtl/ustrbuf.hxx>
#include <sax/tools/converter.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/xmlexp.hxx>
#include <xmloff/xmlimp.hxx>
#include <tools/helpers.hxx>
#include <basegfx/vector/b2dvector.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/tuple/b3dtuple.hxx>
#include <basegfx/matrix/b3dhommatrix.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/tools/unotools.hxx>
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using namespace ::com::sun::star;
//////////////////////////////////////////////////////////////////////////////
// Defines
#define BORDER_INTEGERS_ARE_EQUAL (4)
//////////////////////////////////////////////////////////////////////////////
// Predeclarations
void Imp_SkipDouble(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen);
void Imp_CalcVectorValues(::basegfx::B2DVector& aVec1, ::basegfx::B2DVector& aVec2, bool& bSameLength, bool& bSameDirection)
{
const sal_Int32 nLen1(FRound(aVec1.getLength()));
const sal_Int32 nLen2(FRound(aVec2.getLength()));
aVec1.normalize();
aVec2.normalize();
aVec1 += aVec2;
const sal_Int32 nLen3(FRound(aVec1.getLength() * ((nLen1 + nLen2) / 2.0)));
bSameLength = (abs(nLen1 - nLen2) <= BORDER_INTEGERS_ARE_EQUAL);
bSameDirection = (nLen3 <= BORDER_INTEGERS_ARE_EQUAL);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// parsing help functions for simple chars
void Imp_SkipSpaces(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen)
{
while(rPos < nLen
&& sal_Unicode(' ') == rStr[rPos])
rPos++;
}
void Imp_SkipSpacesAndOpeningBraces(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen)
{
while(rPos < nLen
&& (sal_Unicode(' ') == rStr[rPos] || sal_Unicode('(') == rStr[rPos]))
rPos++;
}
void Imp_SkipSpacesAndCommas(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen)
{
while(rPos < nLen
&& (sal_Unicode(' ') == rStr[rPos] || sal_Unicode(',') == rStr[rPos]))
rPos++;
}
void Imp_SkipSpacesAndClosingBraces(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen)
{
while(rPos < nLen
&& (sal_Unicode(' ') == rStr[rPos] || sal_Unicode(')') == rStr[rPos]))
rPos++;
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// parsing help functions for integer numbers
bool Imp_IsOnNumberChar(const OUString& rStr, const sal_Int32 nPos, bool bSignAllowed = true)
{
sal_Unicode aChar(rStr[nPos]);
if((sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
|| (bSignAllowed && sal_Unicode('+') == aChar)
|| (bSignAllowed && sal_Unicode('-') == aChar)
)
return true;
return false;
}
bool Imp_IsOnUnitChar(const OUString& rStr, const sal_Int32 nPos)
{
sal_Unicode aChar(rStr[nPos]);
if((sal_Unicode('a') <= aChar && sal_Unicode('z') >= aChar)
|| (sal_Unicode('A') <= aChar && sal_Unicode('Z') >= aChar)
|| sal_Unicode('%') == aChar
)
return true;
return false;
}
void Imp_SkipNumber(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen)
{
bool bSignAllowed(true);
while(rPos < nLen && Imp_IsOnNumberChar(rStr, rPos, bSignAllowed))
{
bSignAllowed = false;
rPos++;
}
}
void Imp_SkipNumberAndSpacesAndCommas(const OUString& rStr, sal_Int32& rPos,
const sal_Int32 nLen)
{
Imp_SkipNumber(rStr, rPos, nLen);
Imp_SkipSpacesAndCommas(rStr, rPos, nLen);
}
void Imp_PutNumberChar(OUString& rStr, sal_Int32 nValue)
{
OUStringBuffer sStringBuffer;
::sax::Converter::convertNumber(sStringBuffer, nValue);
rStr += OUString(sStringBuffer.makeStringAndClear());
}
void Imp_PutNumberCharWithSpace(OUString& rStr, sal_Int32 nValue)
{
const sal_Int32 aLen(rStr.getLength());
if(aLen)
if(Imp_IsOnNumberChar(rStr, aLen - 1, false) && nValue >= 0)
rStr += rtl::OUString(static_cast<sal_Unicode>(' '));
Imp_PutNumberChar(rStr, nValue);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// parsing help functions for double numbers
void Imp_SkipDouble(const OUString& rStr, sal_Int32& rPos, const sal_Int32)
{
sal_Unicode aChar(rStr[rPos]);
if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
aChar = rStr[++rPos];
while((sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
|| sal_Unicode('.') == aChar)
{
aChar = rStr[++rPos];
}
if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar)
{
aChar = rStr[++rPos];
if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
aChar = rStr[++rPos];
while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
{
aChar = rStr[++rPos];
}
}
}
double Imp_GetDoubleChar(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen,
const SvXMLUnitConverter& rConv, double fRetval, bool bLookForUnits = false)
{
sal_Unicode aChar(rStr[rPos]);
OUStringBuffer sNumberString;
if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
{
sNumberString.append(rStr[rPos]);
aChar = rStr[++rPos];
}
while((sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
|| sal_Unicode('.') == aChar)
{
sNumberString.append(rStr[rPos]);
aChar = rStr[++rPos];
}
if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar)
{
sNumberString.append(rStr[rPos]);
aChar = rStr[++rPos];
if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
{
sNumberString.append(rStr[rPos]);
aChar = rStr[++rPos];
}
while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
{
sNumberString.append(rStr[rPos]);
aChar = rStr[++rPos];
}
}
if(bLookForUnits)
{
Imp_SkipSpaces(rStr, rPos, nLen);
while(rPos < nLen && Imp_IsOnUnitChar(rStr, rPos))
sNumberString.append(rStr[rPos++]);
}
if(sNumberString.getLength())
{
if(bLookForUnits)
rConv.convertDouble(fRetval, sNumberString.makeStringAndClear(), true);
else
{
::sax::Converter::convertDouble(fRetval,
sNumberString.makeStringAndClear());
}
}
return fRetval;
}
void Imp_PutDoubleChar(OUString& rStr, const SvXMLUnitConverter& rConv, double fValue,
bool bConvertUnits = false)
{
OUStringBuffer sStringBuffer;
if(bConvertUnits)
rConv.convertDouble(sStringBuffer, fValue, true);
else
{
::sax::Converter::convertDouble(sStringBuffer, fValue);
}
rStr += OUString(sStringBuffer.makeStringAndClear());
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// base class of all 2D transform objects
struct ImpSdXMLExpTransObj2DBase
{
sal_uInt16 mnType;
ImpSdXMLExpTransObj2DBase(sal_uInt16 nType)
: mnType(nType) {}
};
//////////////////////////////////////////////////////////////////////////////
// possible object types for 2D
#define IMP_SDXMLEXP_TRANSOBJ2D_ROTATE 0x0000
#define IMP_SDXMLEXP_TRANSOBJ2D_SCALE 0x0001
#define IMP_SDXMLEXP_TRANSOBJ2D_TRANSLATE 0x0002
#define IMP_SDXMLEXP_TRANSOBJ2D_SKEWX 0x0003
#define IMP_SDXMLEXP_TRANSOBJ2D_SKEWY 0x0004
#define IMP_SDXMLEXP_TRANSOBJ2D_MATRIX 0x0005
//////////////////////////////////////////////////////////////////////////////
// classes of objects, different sizes
struct ImpSdXMLExpTransObj2DRotate : public ImpSdXMLExpTransObj2DBase
{
double mfRotate;
ImpSdXMLExpTransObj2DRotate(double fVal)
: ImpSdXMLExpTransObj2DBase(IMP_SDXMLEXP_TRANSOBJ2D_ROTATE), mfRotate(fVal) {}
};
struct ImpSdXMLExpTransObj2DScale : public ImpSdXMLExpTransObj2DBase
{
::basegfx::B2DTuple maScale;
ImpSdXMLExpTransObj2DScale(const ::basegfx::B2DTuple& rNew)
: ImpSdXMLExpTransObj2DBase(IMP_SDXMLEXP_TRANSOBJ2D_SCALE), maScale(rNew) {}
};
struct ImpSdXMLExpTransObj2DTranslate : public ImpSdXMLExpTransObj2DBase
{
::basegfx::B2DTuple maTranslate;
ImpSdXMLExpTransObj2DTranslate(const ::basegfx::B2DTuple& rNew)
: ImpSdXMLExpTransObj2DBase(IMP_SDXMLEXP_TRANSOBJ2D_TRANSLATE), maTranslate(rNew) {}
};
struct ImpSdXMLExpTransObj2DSkewX : public ImpSdXMLExpTransObj2DBase
{
double mfSkewX;
ImpSdXMLExpTransObj2DSkewX(double fVal)
: ImpSdXMLExpTransObj2DBase(IMP_SDXMLEXP_TRANSOBJ2D_SKEWX), mfSkewX(fVal) {}
};
struct ImpSdXMLExpTransObj2DSkewY : public ImpSdXMLExpTransObj2DBase
{
double mfSkewY;
ImpSdXMLExpTransObj2DSkewY(double fVal)
: ImpSdXMLExpTransObj2DBase(IMP_SDXMLEXP_TRANSOBJ2D_SKEWY), mfSkewY(fVal) {}
};
struct ImpSdXMLExpTransObj2DMatrix : public ImpSdXMLExpTransObj2DBase
{
::basegfx::B2DHomMatrix maMatrix;
ImpSdXMLExpTransObj2DMatrix(const ::basegfx::B2DHomMatrix& rNew)
: ImpSdXMLExpTransObj2DBase(IMP_SDXMLEXP_TRANSOBJ2D_MATRIX), maMatrix(rNew) {}
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// delete all entries in list
void SdXMLImExTransform2D::EmptyList()
{
const sal_uInt32 nCount = maList.size();
for(sal_uInt32 a(0L); a < nCount; a++)
{
ImpSdXMLExpTransObj2DBase* pObj = maList[a];
switch(pObj->mnType)
{
case IMP_SDXMLEXP_TRANSOBJ2D_ROTATE :
{
delete (ImpSdXMLExpTransObj2DRotate*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SCALE :
{
delete (ImpSdXMLExpTransObj2DScale*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_TRANSLATE :
{
delete (ImpSdXMLExpTransObj2DTranslate*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SKEWX :
{
delete (ImpSdXMLExpTransObj2DSkewX*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SKEWY :
{
delete (ImpSdXMLExpTransObj2DSkewY*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_MATRIX :
{
delete (ImpSdXMLExpTransObj2DMatrix*)pObj;
break;
}
default :
{
OSL_FAIL("SdXMLImExTransform2D: impossible entry!");
break;
}
}
}
maList.clear();
}
//////////////////////////////////////////////////////////////////////////////
// add members
void SdXMLImExTransform2D::AddRotate(double fNew)
{
if(fNew != 0.0)
maList.push_back(new ImpSdXMLExpTransObj2DRotate(fNew));
}
void SdXMLImExTransform2D::AddTranslate(const ::basegfx::B2DTuple& rNew)
{
if(!rNew.equalZero())
maList.push_back(new ImpSdXMLExpTransObj2DTranslate(rNew));
}
void SdXMLImExTransform2D::AddSkewX(double fNew)
{
if(fNew != 0.0)
maList.push_back(new ImpSdXMLExpTransObj2DSkewX(fNew));
}
//////////////////////////////////////////////////////////////////////////////
// gen string for export
const OUString& SdXMLImExTransform2D::GetExportString(const SvXMLUnitConverter& rConv)
{
OUString aNewString;
OUString aClosingBrace(sal_Unicode(')'));
OUString aEmptySpace(sal_Unicode(' '));
const sal_uInt32 nCount = maList.size();
for(sal_uInt32 a(0L); a < nCount; a++)
{
ImpSdXMLExpTransObj2DBase* pObj = maList[a];
switch(pObj->mnType)
{
case IMP_SDXMLEXP_TRANSOBJ2D_ROTATE :
{
aNewString += "rotate (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DRotate*)pObj)->mfRotate);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SCALE :
{
aNewString += "scale (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DScale*)pObj)->maScale.getX());
aNewString += aEmptySpace;
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DScale*)pObj)->maScale.getY());
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_TRANSLATE :
{
aNewString += "translate (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DTranslate*)pObj)->maTranslate.getX(), true);
aNewString += aEmptySpace;
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DTranslate*)pObj)->maTranslate.getY(), true);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SKEWX :
{
aNewString += "skewX (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DSkewX*)pObj)->mfSkewX);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SKEWY :
{
aNewString += "skewY (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DSkewY*)pObj)->mfSkewY);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_MATRIX :
{
aNewString += "matrix (";
// a
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DMatrix*)pObj)->maMatrix.get(0, 0));
aNewString += aEmptySpace;
// b
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DMatrix*)pObj)->maMatrix.get(1, 0));
aNewString += aEmptySpace;
// c
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DMatrix*)pObj)->maMatrix.get(0, 1));
aNewString += aEmptySpace;
// d
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DMatrix*)pObj)->maMatrix.get(1, 1));
aNewString += aEmptySpace;
// e
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DMatrix*)pObj)->maMatrix.get(0, 2), true);
aNewString += aEmptySpace;
// f
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj2DMatrix*)pObj)->maMatrix.get(1, 2), true);
aNewString += aClosingBrace;
break;
}
default :
{
OSL_FAIL("SdXMLImExTransform2D: impossible entry!");
break;
}
}
// if not the last entry, add one space to next tag
if(a + 1UL != maList.size())
{
aNewString += aEmptySpace;
}
}
// fill string form OUString
msString = aNewString;
return msString;
}
//////////////////////////////////////////////////////////////////////////////
// sets new string, parses it and generates entries
void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConverter& rConv)
{
msString = rNew;
EmptyList();
if(!msString.isEmpty())
{
const OUString aStr(msString.getStr(), (sal_uInt16)msString.getLength());
const sal_Int32 nLen(aStr.getLength());
const OUString aString_rotate( "rotate" );
const OUString aString_scale( "scale" );
const OUString aString_translate( "translate" );
const OUString aString_skewX( "skewX" );
const OUString aString_skewY( "skewY" );
const OUString aString_matrix( "matrix" );
sal_Int32 nPos(0);
while(nPos < nLen)
{
// skip spaces
Imp_SkipSpaces(aStr, nPos, nLen);
// look for tag
if(nPos < nLen)
{
if(nPos == aStr.indexOf(aString_rotate, nPos))
{
double fValue(0.0);
nPos += 6;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue);
if(fValue != 0.0)
maList.push_back(new ImpSdXMLExpTransObj2DRotate(fValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_scale, nPos))
{
::basegfx::B2DTuple aValue(1.0, 1.0);
nPos += 5;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
aValue.setX(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getX()));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY()));
if(aValue.getX() != 1.0 || aValue.getY() != 1.0)
maList.push_back(new ImpSdXMLExpTransObj2DScale(aValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_translate, nPos))
{
::basegfx::B2DTuple aValue;
nPos += 9;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
aValue.setX(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getX(), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY(), true));
if(!aValue.equalZero())
maList.push_back(new ImpSdXMLExpTransObj2DTranslate(aValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_skewX, nPos))
{
double fValue(0.0);
nPos += 5;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue);
if(fValue != 0.0)
maList.push_back(new ImpSdXMLExpTransObj2DSkewX(fValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_skewY, nPos))
{
double fValue(0.0);
nPos += 5;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue);
if(fValue != 0.0)
maList.push_back(new ImpSdXMLExpTransObj2DSkewY(fValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_matrix, nPos))
{
::basegfx::B2DHomMatrix aValue;
nPos += 6;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
// a
aValue.set(0, 0, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(0, 0)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// b
aValue.set(1, 0, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(1, 0)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// c
aValue.set(0, 1, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(0, 1)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// d
aValue.set(1, 1, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(1, 1)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// e
aValue.set(0, 2, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(0, 2), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// f
aValue.set(1, 2, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(1, 2), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
if(!aValue.isIdentity())
maList.push_back(new ImpSdXMLExpTransObj2DMatrix(aValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else
{
nPos++;
}
}
}
}
}
void SdXMLImExTransform2D::GetFullTransform(::basegfx::B2DHomMatrix& rFullTrans)
{
rFullTrans.identity();
const sal_uInt32 nCount = maList.size();
for(sal_uInt32 a(0L); a < nCount; a++)
{
ImpSdXMLExpTransObj2DBase* pObj = maList[a];
switch(pObj->mnType)
{
case IMP_SDXMLEXP_TRANSOBJ2D_ROTATE :
{
// #i78696#
// mfRotate is mathematically wrong oriented since we export/import the angle
// values mirrored. This error is fixed in the API, but not yet in the FileFormat.
// For the FileFormat there is a follow-up task (#i78698#) to fix this in the next
// ODF FileFormat version. For now - to emulate the old behaviour - it is necessary
// to mirror the value here
rFullTrans.rotate(((ImpSdXMLExpTransObj2DRotate*)pObj)->mfRotate * -1.0);
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SCALE :
{
const ::basegfx::B2DTuple& rScale = ((ImpSdXMLExpTransObj2DScale*)pObj)->maScale;
rFullTrans.scale(rScale.getX(), rScale.getY());
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_TRANSLATE :
{
const ::basegfx::B2DTuple& rTranslate = ((ImpSdXMLExpTransObj2DTranslate*)pObj)->maTranslate;
rFullTrans.translate(rTranslate.getX(), rTranslate.getY());
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SKEWX :
{
rFullTrans.shearX(tan(((ImpSdXMLExpTransObj2DSkewX*)pObj)->mfSkewX));
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_SKEWY :
{
rFullTrans.shearY(tan(((ImpSdXMLExpTransObj2DSkewY*)pObj)->mfSkewY));
break;
}
case IMP_SDXMLEXP_TRANSOBJ2D_MATRIX :
{
rFullTrans *= ((ImpSdXMLExpTransObj2DMatrix*)pObj)->maMatrix;
break;
}
default :
{
OSL_FAIL("SdXMLImExTransform2D: impossible entry!");
break;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// base class of all 3D transform objects
struct ImpSdXMLExpTransObj3DBase
{
sal_uInt16 mnType;
ImpSdXMLExpTransObj3DBase(sal_uInt16 nType)
: mnType(nType) {}
};
//////////////////////////////////////////////////////////////////////////////
// possible object types for 3D
#define IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X 0x0000
#define IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Y 0x0001
#define IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Z 0x0002
#define IMP_SDXMLEXP_TRANSOBJ3D_SCALE 0x0003
#define IMP_SDXMLEXP_TRANSOBJ3D_TRANSLATE 0x0004
#define IMP_SDXMLEXP_TRANSOBJ3D_MATRIX 0x0005
//////////////////////////////////////////////////////////////////////////////
// classes of objects, different sizes
struct ImpSdXMLExpTransObj3DRotateX : public ImpSdXMLExpTransObj3DBase
{
double mfRotateX;
ImpSdXMLExpTransObj3DRotateX(double fVal)
: ImpSdXMLExpTransObj3DBase(IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X), mfRotateX(fVal) {}
};
struct ImpSdXMLExpTransObj3DRotateY : public ImpSdXMLExpTransObj3DBase
{
double mfRotateY;
ImpSdXMLExpTransObj3DRotateY(double fVal)
: ImpSdXMLExpTransObj3DBase(IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Y), mfRotateY(fVal) {}
};
struct ImpSdXMLExpTransObj3DRotateZ : public ImpSdXMLExpTransObj3DBase
{
double mfRotateZ;
ImpSdXMLExpTransObj3DRotateZ(double fVal)
: ImpSdXMLExpTransObj3DBase(IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Z), mfRotateZ(fVal) {}
};
struct ImpSdXMLExpTransObj3DScale : public ImpSdXMLExpTransObj3DBase
{
::basegfx::B3DTuple maScale;
ImpSdXMLExpTransObj3DScale(const ::basegfx::B3DTuple& rNew)
: ImpSdXMLExpTransObj3DBase(IMP_SDXMLEXP_TRANSOBJ3D_SCALE), maScale(rNew) {}
};
struct ImpSdXMLExpTransObj3DTranslate : public ImpSdXMLExpTransObj3DBase
{
::basegfx::B3DTuple maTranslate;
ImpSdXMLExpTransObj3DTranslate(const ::basegfx::B3DTuple& rNew)
: ImpSdXMLExpTransObj3DBase(IMP_SDXMLEXP_TRANSOBJ3D_TRANSLATE), maTranslate(rNew) {}
};
struct ImpSdXMLExpTransObj3DMatrix : public ImpSdXMLExpTransObj3DBase
{
::basegfx::B3DHomMatrix maMatrix;
ImpSdXMLExpTransObj3DMatrix(const ::basegfx::B3DHomMatrix& rNew)
: ImpSdXMLExpTransObj3DBase(IMP_SDXMLEXP_TRANSOBJ3D_MATRIX), maMatrix(rNew) {}
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// delete all entries in list
void SdXMLImExTransform3D::EmptyList()
{
const sal_uInt32 nCount = maList.size();
for(sal_uInt32 a(0L); a < nCount; a++)
{
ImpSdXMLExpTransObj3DBase* pObj = maList[a];
switch(pObj->mnType)
{
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X :
{
delete (ImpSdXMLExpTransObj3DRotateX*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Y :
{
delete (ImpSdXMLExpTransObj3DRotateY*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Z :
{
delete (ImpSdXMLExpTransObj3DRotateZ*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_SCALE :
{
delete (ImpSdXMLExpTransObj3DScale*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_TRANSLATE :
{
delete (ImpSdXMLExpTransObj3DTranslate*)pObj;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_MATRIX :
{
delete (ImpSdXMLExpTransObj3DMatrix*)pObj;
break;
}
default :
{
OSL_FAIL("SdXMLImExTransform3D: impossible entry!");
break;
}
}
}
maList.clear();
}
//////////////////////////////////////////////////////////////////////////////
// add members
void SdXMLImExTransform3D::AddMatrix(const ::basegfx::B3DHomMatrix& rNew)
{
if(!rNew.isIdentity())
maList.push_back(new ImpSdXMLExpTransObj3DMatrix(rNew));
}
void SdXMLImExTransform3D::AddHomogenMatrix(const drawing::HomogenMatrix& xHomMat)
{
::basegfx::B3DHomMatrix aExportMatrix;
aExportMatrix.set(0, 0, xHomMat.Line1.Column1);
aExportMatrix.set(0, 1, xHomMat.Line1.Column2);
aExportMatrix.set(0, 2, xHomMat.Line1.Column3);
aExportMatrix.set(0, 3, xHomMat.Line1.Column4);
aExportMatrix.set(1, 0, xHomMat.Line2.Column1);
aExportMatrix.set(1, 1, xHomMat.Line2.Column2);
aExportMatrix.set(1, 2, xHomMat.Line2.Column3);
aExportMatrix.set(1, 3, xHomMat.Line2.Column4);
aExportMatrix.set(2, 0, xHomMat.Line3.Column1);
aExportMatrix.set(2, 1, xHomMat.Line3.Column2);
aExportMatrix.set(2, 2, xHomMat.Line3.Column3);
aExportMatrix.set(2, 3, xHomMat.Line3.Column4);
AddMatrix(aExportMatrix);
}
//////////////////////////////////////////////////////////////////////////////
// gen string for export
const OUString& SdXMLImExTransform3D::GetExportString(const SvXMLUnitConverter& rConv)
{
OUString aNewString;
OUString aClosingBrace(sal_Unicode(')'));
OUString aEmptySpace(sal_Unicode(' '));
const sal_uInt32 nCount = maList.size();
for(sal_uInt32 a(0L); a < nCount; a++)
{
ImpSdXMLExpTransObj3DBase* pObj = maList[a];
switch(pObj->mnType)
{
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X :
{
aNewString += "rotatex (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DRotateX*)pObj)->mfRotateX);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Y :
{
aNewString += "rotatey (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DRotateY*)pObj)->mfRotateY);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Z :
{
aNewString += "rotatez (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DRotateZ*)pObj)->mfRotateZ);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_SCALE :
{
aNewString += "scale (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DScale*)pObj)->maScale.getX());
aNewString += aEmptySpace;
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DScale*)pObj)->maScale.getY());
aNewString += aEmptySpace;
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DScale*)pObj)->maScale.getZ());
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_TRANSLATE :
{
aNewString += "translate (";
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DTranslate*)pObj)->maTranslate.getX(), true);
aNewString += aEmptySpace;
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DTranslate*)pObj)->maTranslate.getY(), true);
aNewString += aEmptySpace;
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DTranslate*)pObj)->maTranslate.getZ(), true);
aNewString += aClosingBrace;
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_MATRIX :
{
aNewString += "matrix (";
// a
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(0, 0));
aNewString += aEmptySpace;
// b
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(1, 0));
aNewString += aEmptySpace;
// c
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(2, 0));
aNewString += aEmptySpace;
// d
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(0, 1));
aNewString += aEmptySpace;
// e
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(1, 1));
aNewString += aEmptySpace;
// f
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(2, 1));
aNewString += aEmptySpace;
// g
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(0, 2));
aNewString += aEmptySpace;
// h
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(1, 2));
aNewString += aEmptySpace;
// i
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(2, 2));
aNewString += aEmptySpace;
// j
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(0, 3), true);
aNewString += aEmptySpace;
// k
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(1, 3), true);
aNewString += aEmptySpace;
// l
Imp_PutDoubleChar(aNewString, rConv, ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix.get(2, 3), true);
aNewString += aClosingBrace;
break;
}
default :
{
OSL_FAIL("SdXMLImExTransform3D: impossible entry!");
break;
}
}
// if not the last entry, add one space to next tag
if(a + 1UL != maList.size())
{
aNewString += aEmptySpace;
}
}
// fill string form OUString
msString = aNewString;
return msString;
}
//////////////////////////////////////////////////////////////////////////////
// for Import: constructor with string, parses it and generates entries
SdXMLImExTransform3D::SdXMLImExTransform3D(const OUString& rNew, const SvXMLUnitConverter& rConv)
{
SetString(rNew, rConv);
}
//////////////////////////////////////////////////////////////////////////////
// sets new string, parses it and generates entries
void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConverter& rConv)
{
msString = rNew;
EmptyList();
if(!msString.isEmpty())
{
const OUString aStr(msString.getStr(), (sal_uInt16)msString.getLength());
const sal_Int32 nLen(aStr.getLength());
const OUString aString_rotatex( "rotatex" );
const OUString aString_rotatey( "rotatey" );
const OUString aString_rotatez( "rotatez" );
const OUString aString_scale( "scale" );
const OUString aString_translate( "translate" );
const OUString aString_matrix( "matrix" );
sal_Int32 nPos(0);
while(nPos < nLen)
{
// skip spaces
Imp_SkipSpaces(aStr, nPos, nLen);
// look for tag
if(nPos < nLen)
{
if(nPos == aStr.indexOf(aString_rotatex, nPos))
{
double fValue(0.0);
nPos += 7;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue);
if(fValue != 0.0)
maList.push_back(new ImpSdXMLExpTransObj3DRotateX(fValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_rotatey, nPos))
{
double fValue(0.0);
nPos += 7;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue);
if(fValue != 0.0)
maList.push_back(new ImpSdXMLExpTransObj3DRotateY(fValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_rotatez, nPos))
{
double fValue(0.0);
nPos += 7;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue);
if(fValue != 0.0)
maList.push_back(new ImpSdXMLExpTransObj3DRotateZ(fValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_scale, nPos))
{
::basegfx::B3DTuple aValue(1.0, 1.0, 1.0);
nPos += 5;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
aValue.setX(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getX()));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY()));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
aValue.setZ(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getZ()));
if(1.0 != aValue.getX() || 1.0 != aValue.getY() || 1.0 != aValue.getZ())
maList.push_back(new ImpSdXMLExpTransObj3DScale(aValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_translate, nPos))
{
::basegfx::B3DTuple aValue;
nPos += 9;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
aValue.setX(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getX(), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY(), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
aValue.setZ(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getZ(), true));
if(!aValue.equalZero())
maList.push_back(new ImpSdXMLExpTransObj3DTranslate(aValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else if(nPos == aStr.indexOf(aString_matrix, nPos))
{
::basegfx::B3DHomMatrix aValue;
nPos += 6;
Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen);
// a
aValue.set(0, 0, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(0, 0)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// b
aValue.set(1, 0, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(1, 0)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// c
aValue.set(2, 0, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(2, 0)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// d
aValue.set(0, 1, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(0, 1)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// e
aValue.set(1, 1, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(1, 1)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// f
aValue.set(2, 1, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(2, 1)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// g
aValue.set(0, 2, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(0, 2)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// h
aValue.set(1, 2, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(1, 2)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// i
aValue.set(2, 2, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(2, 2)));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// j
aValue.set(0, 3, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(0, 3), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// k
aValue.set(1, 3, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(1, 3), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// l
aValue.set(2, 3, Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.get(2, 3), true));
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
if(!aValue.isIdentity())
maList.push_back(new ImpSdXMLExpTransObj3DMatrix(aValue));
Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen);
}
else
{
nPos++;
}
}
}
}
}
bool SdXMLImExTransform3D::GetFullHomogenTransform(com::sun::star::drawing::HomogenMatrix& xHomMat)
{
::basegfx::B3DHomMatrix aFullTransform;
GetFullTransform(aFullTransform);
if(!aFullTransform.isIdentity())
{
xHomMat.Line1.Column1 = aFullTransform.get(0, 0);
xHomMat.Line1.Column2 = aFullTransform.get(0, 1);
xHomMat.Line1.Column3 = aFullTransform.get(0, 2);
xHomMat.Line1.Column4 = aFullTransform.get(0, 3);
xHomMat.Line2.Column1 = aFullTransform.get(1, 0);
xHomMat.Line2.Column2 = aFullTransform.get(1, 1);
xHomMat.Line2.Column3 = aFullTransform.get(1, 2);
xHomMat.Line2.Column4 = aFullTransform.get(1, 3);
xHomMat.Line3.Column1 = aFullTransform.get(2, 0);
xHomMat.Line3.Column2 = aFullTransform.get(2, 1);
xHomMat.Line3.Column3 = aFullTransform.get(2, 2);
xHomMat.Line3.Column4 = aFullTransform.get(2, 3);
xHomMat.Line4.Column1 = aFullTransform.get(3, 0);
xHomMat.Line4.Column2 = aFullTransform.get(3, 1);
xHomMat.Line4.Column3 = aFullTransform.get(3, 2);
xHomMat.Line4.Column4 = aFullTransform.get(3, 3);
return true;
}
return false;
}
void SdXMLImExTransform3D::GetFullTransform(::basegfx::B3DHomMatrix& rFullTrans)
{
rFullTrans.identity();
const sal_uInt32 nCount = maList.size();
for(sal_uInt32 a(0L); a < nCount; a++)
{
ImpSdXMLExpTransObj3DBase* pObj = maList[a];
switch(pObj->mnType)
{
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X :
{
rFullTrans.rotate(((ImpSdXMLExpTransObj3DRotateX*)pObj)->mfRotateX, 0.0, 0.0);
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Y :
{
rFullTrans.rotate(0.0, ((ImpSdXMLExpTransObj3DRotateY*)pObj)->mfRotateY, 0.0);
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Z :
{
rFullTrans.rotate(0.0, 0.0, ((ImpSdXMLExpTransObj3DRotateZ*)pObj)->mfRotateZ);
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_SCALE :
{
const ::basegfx::B3DTuple& rScale = ((ImpSdXMLExpTransObj3DScale*)pObj)->maScale;
rFullTrans.scale(rScale.getX(), rScale.getY(), rScale.getZ());
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_TRANSLATE :
{
const ::basegfx::B3DTuple& rTranslate = ((ImpSdXMLExpTransObj3DTranslate*)pObj)->maTranslate;
rFullTrans.translate(rTranslate.getX(), rTranslate.getY(), rTranslate.getZ());
break;
}
case IMP_SDXMLEXP_TRANSOBJ3D_MATRIX :
{
rFullTrans *= ((ImpSdXMLExpTransObj3DMatrix*)pObj)->maMatrix;
break;
}
default :
{
OSL_FAIL("SdXMLImExTransform3D: impossible entry!");
break;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
SdXMLImExViewBox::SdXMLImExViewBox(sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH)
: mnX( nX ),
mnY( nY ),
mnW( nW ),
mnH( nH )
{
}
// #100617# Asked vincent hardy: svg:viewBox values may be double precision.
SdXMLImExViewBox::SdXMLImExViewBox(const OUString& rNew, const SvXMLUnitConverter& rConv)
: msString(rNew),
mnX( 0L ),
mnY( 0L ),
mnW( 1000L ),
mnH( 1000L )
{
if(!msString.isEmpty())
{
const OUString aStr(msString.getStr(), (sal_uInt16)msString.getLength());
const sal_Int32 nLen(aStr.getLength());
sal_Int32 nPos(0);
// skip starting spaces
Imp_SkipSpaces(aStr, nPos, nLen);
// get mX, #100617# be prepared for doubles
mnX = FRound(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, (double)mnX));
// skip spaces and commas
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// get mY, #100617# be prepared for doubles
mnY = FRound(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, (double)mnY));
// skip spaces and commas
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// get mW, #100617# be prepared for doubles
mnW = FRound(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, (double)mnW));
// skip spaces and commas
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// get mH, #100617# be prepared for doubles
mnH = FRound(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, (double)mnH));
}
}
const OUString& SdXMLImExViewBox::GetExportString()
{
OUString aNewString;
OUString aEmptySpace(sal_Unicode(' '));
Imp_PutNumberChar(aNewString, mnX);
aNewString += aEmptySpace;
Imp_PutNumberChar(aNewString, mnY);
aNewString += aEmptySpace;
Imp_PutNumberChar(aNewString, mnW);
aNewString += aEmptySpace;
Imp_PutNumberChar(aNewString, mnH);
// set new string
msString = aNewString;
return msString;
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
SdXMLImExPointsElement::SdXMLImExPointsElement(drawing::PointSequence* pPoints,
const SdXMLImExViewBox& rViewBox,
const awt::Point& rObjectPos,
const awt::Size& rObjectSize,
// #96328#
const bool bClosed)
: maPoly( 0L )
{
DBG_ASSERT(pPoints, "Empty PointSequence handed over to SdXMLImExPointsElement(!)");
// add polygon to string
sal_Int32 nCnt(pPoints->getLength());
// #104076# Convert to string only when at last one point included
if(nCnt > 0)
{
OUString aNewString;
awt::Point* pArray = pPoints->getArray();
// last point same? Ignore it.
// #96328# ...but only when polygon is CLOSED
if(bClosed && (pArray->X == (pArray + (nCnt - 1))->X) && (pArray->Y == (pArray + (nCnt - 1))->Y))
nCnt--;
// object size and ViewBox size different?
bool bScale(rObjectSize.Width != rViewBox.GetWidth()
|| rObjectSize.Height != rViewBox.GetHeight());
bool bTranslate(rViewBox.GetX() != 0L || rViewBox.GetY() != 0L);
for(sal_Int32 a(0L); a < nCnt; a++)
{
// prepare coordinates
sal_Int32 nX( pArray->X - rObjectPos.X );
sal_Int32 nY( pArray->Y - rObjectPos.Y );
if(bScale && rObjectSize.Width && rObjectSize.Height)
{
nX = (nX * rViewBox.GetWidth()) / rObjectSize.Width;
nY = (nY * rViewBox.GetHeight()) / rObjectSize.Height;
}
if(bTranslate)
{
nX += rViewBox.GetX();
nY += rViewBox.GetY();
}
// X and comma
Imp_PutNumberChar(aNewString, nX);
aNewString += rtl::OUString(static_cast<sal_Unicode>(','));
// Y and space (not for last)
Imp_PutNumberChar(aNewString, nY);
if(a + 1 != nCnt)
aNewString += rtl::OUString(static_cast<sal_Unicode>(' '));
// next point
pArray++;
}
// set new string
msString = aNewString;
}
}
// #100617# svg:polyline or svg:polygon values may be double precision.
SdXMLImExPointsElement::SdXMLImExPointsElement(const OUString& rNew,
const SdXMLImExViewBox& rViewBox,
const awt::Point& rObjectPos,
const awt::Size& rObjectSize,
const SvXMLUnitConverter& rConv)
: msString( rNew ),
maPoly( 0L )
{
// convert string to polygon
const OUString aStr(msString.getStr(), (sal_uInt16)msString.getLength());
const sal_Int32 nLen(aStr.getLength());
sal_Int32 nPos(0);
sal_Int32 nNumPoints(0L);
// skip starting spaces
Imp_SkipSpaces(aStr, nPos, nLen);
// count points in first loop
while(nPos < nLen)
{
// skip number, #100617# be prepared for doubles
Imp_SkipDouble(aStr, nPos, nLen);
// skip spaces and commas
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// skip number, #100617# be prepared for doubles
Imp_SkipDouble(aStr, nPos, nLen);
// skip spaces and commas
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// one more point
nNumPoints++;
}
// second loop
if(nNumPoints)
{
nPos = 0;
maPoly.realloc(1);
drawing::PointSequence* pOuterSequence = maPoly.getArray();
pOuterSequence->realloc(nNumPoints);
awt::Point* pInnerSequence = pOuterSequence->getArray();
// object size and ViewBox size different?
bool bScale(rObjectSize.Width != rViewBox.GetWidth()
|| rObjectSize.Height != rViewBox.GetHeight());
bool bTranslate(rViewBox.GetX() != 0L || rViewBox.GetY() != 0L);
// skip starting spaces
Imp_SkipSpaces(aStr, nPos, nLen);
while(nPos < nLen)
{
// prepare new parameter pair
sal_Int32 nX(0L);
sal_Int32 nY(0L);
// get mX, #100617# be prepared for doubles
nX = FRound(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, (double)nX));
// skip spaces and commas
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// get mY, #100617# be prepared for doubles
nY = FRound(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, (double)nY));
// skip spaces and commas
Imp_SkipSpacesAndCommas(aStr, nPos, nLen);
// prepare parameters
if(bTranslate)
{
nX -= rViewBox.GetX();
nY -= rViewBox.GetY();
}
if(bScale && rViewBox.GetWidth() && rViewBox.GetHeight() )
{
nX = (nX * rObjectSize.Width) / rViewBox.GetWidth();
nY = (nY * rObjectSize.Height) / rViewBox.GetHeight();
}
nX += rObjectPos.X;
nY += rObjectPos.Y;
// add new point
*pInnerSequence = awt::Point( nX, nY );
pInnerSequence++;
}
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
SdXMLImExSvgDElement::SdXMLImExSvgDElement(const SdXMLImExViewBox& rViewBox,
const SvXMLExport& rExport)
: mrViewBox( rViewBox ),
mbIsClosed( false ),
mbIsCurve( false ),
// fdo#47406 - handle writing svg:d path slightly different for
// old ODF versions and ODF1.2 compat mode - since ~all the legacy
// ODF ecosystem interprets relative svg:d paths incorrectly,
// write out absolute paths in those cases.
mbRelative( rExport.getDefaultVersion() >= SvtSaveOptions::ODFVER_012 &&
rExport.getDefaultVersion() != SvtSaveOptions::ODFVER_012_EXT_COMPAT ),
mnLastX( 0L ),
mnLastY( 0L ),
maPoly()
{
}
void Imp_GetPrevPos(awt::Point*& pPrevPos1,
drawing::PolygonFlags& aPrevFlag1,
const bool bClosed, awt::Point* pPoints,
drawing::PolygonFlags* pFlags, const sal_Int32 nPos,
const sal_Int32 nCnt, const sal_Int32 nAdd)
{
if(bClosed)
{
pPrevPos1 = pPoints + ((nPos + nCnt - nAdd) % nCnt);
aPrevFlag1 = *(pFlags + ((nPos + nCnt - nAdd) % nCnt));
}
else if(nPos > (nAdd - 1))
{
pPrevPos1 = pPoints + (nPos - nAdd);
aPrevFlag1 = *(pFlags + (nPos - nAdd));
}
else
pPrevPos1 = 0L;
}
void Imp_PrepareCoorExport(sal_Int32& nX, sal_Int32& nY,
const awt::Point* pPointArray, const awt::Point& rObjectPos,
const awt::Size& rObjectSize, const SdXMLImExViewBox& mrViewBox,
const bool bScale, const bool bTranslate)
{
nX = pPointArray->X - rObjectPos.X;
nY = pPointArray->Y - rObjectPos.Y;
if(bScale && rObjectSize.Width && rObjectSize.Height )
{
nX = (nX * mrViewBox.GetWidth()) / rObjectSize.Width;
nY = (nY * mrViewBox.GetHeight()) / rObjectSize.Height;
}
if(bTranslate)
{
nX += mrViewBox.GetX();
nY += mrViewBox.GetY();
}
}
//#define TEST_QUADRATIC_CURVES
#ifdef TEST_QUADRATIC_CURVES
// To be able to test quadratic curve code: The code concerning to
// bDoTestHere can be used (see below). Construct shapes which have their control
// points on equal coordinates. When these are written, they can be
// forced to create correct 'Q' and 'T' statements using this flag.
// These may then be tested for import/exporting.
static bool bDoTestHere(true);
#endif // TEST_QUADRATIC_CURVES
void SdXMLImExSvgDElement::AddPolygon(
drawing::PointSequence* pPoints,
drawing::FlagSequence* pFlags,
const awt::Point& rObjectPos,
const awt::Size& rObjectSize,
bool bClosed)
{
// Leaving the export stuff for the while, should eventually also
// consolidated with basegfx svg support
DBG_ASSERT(pPoints, "Empty PointSequence handed over to SdXMLImExSvgDElement(!)");
sal_Int32 nCnt(pPoints->getLength());
// #104076# Convert to string only when at last one point included
if(nCnt > 0)
{
// append polygon to string
OUString aNewString;
sal_Unicode aLastCommand = ' ';
awt::Point* pPointArray = pPoints->getArray();
// are the flags used at all? If not forget about them
if(pFlags)
{
sal_Int32 nFlagCnt(pFlags->getLength());
if(nFlagCnt)
{
bool bFlagsUsed(false);
drawing::PolygonFlags* pFlagArray = pFlags->getArray();
for(sal_Int32 a(0); !bFlagsUsed && a < nFlagCnt; a++)
if(drawing::PolygonFlags_NORMAL != *pFlagArray++)
bFlagsUsed = true;
if(!bFlagsUsed)
pFlags = 0L;
}
else
{
pFlags = 0L;
}
}
// object size and ViewBox size different?
bool bScale(rObjectSize.Width != mrViewBox.GetWidth()
|| rObjectSize.Height != mrViewBox.GetHeight());
bool bTranslate(mrViewBox.GetX() != 0L || mrViewBox.GetY() != 0L);
// #87202# rework of point reduction:
// Test for Last point same -> closed, ignore last point. Take
// some more circumstances in account when looking at curve segments.
drawing::PolygonFlags* pFlagArray = (pFlags) ? pFlags->getArray() : 0L;
if((pPointArray->X == (pPointArray + (nCnt - 1))->X) && (pPointArray->Y == (pPointArray + (nCnt - 1))->Y))
{
if(pFlags)
{
// point needs to be ignored if point before it is
// NO control point. Else the last point is needed
// for exporting the last segment of the curve. That means
// that the last and the first point will be saved double,
// but SVG does not support a better solution here.
if(nCnt >= 2 && drawing::PolygonFlags_CONTROL != *(pFlagArray + (nCnt - 2)))
{
nCnt--;
}
}
else
{
// no curve, ignore last point
nCnt--;
}
}
// bezier poly, handle curves
bool bDidWriteStart(false);
sal_Int32 nStartX(0), nStartY(0);
for(sal_Int32 a(0L); a < nCnt; a++)
{
if(!pFlags || drawing::PolygonFlags_CONTROL != *pFlagArray++)
{
bool bDidWriteAsCurve(false);
if(bDidWriteStart)
{
if(pFlags)
{
// real curve point, get previous to see if it's a control point
awt::Point* pPrevPos1;
drawing::PolygonFlags aPrevFlag1;
Imp_GetPrevPos(pPrevPos1, aPrevFlag1, bClosed, pPoints->getArray(),
pFlags->getArray(), a, nCnt, 1);
if(pPrevPos1 && drawing::PolygonFlags_CONTROL == aPrevFlag1)
{
// get previous2 to see if it's a control point, too
awt::Point* pPrevPos2;
drawing::PolygonFlags aPrevFlag2;
Imp_GetPrevPos(pPrevPos2, aPrevFlag2, bClosed, pPoints->getArray(),
pFlags->getArray(), a, nCnt, 2);
if(pPrevPos2 && drawing::PolygonFlags_CONTROL == aPrevFlag2)
{
// get previous3 to see if it's a curve point and if,
// if it is fully symmetric or not
awt::Point* pPrevPos3;
drawing::PolygonFlags aPrevFlag3;
Imp_GetPrevPos(pPrevPos3, aPrevFlag3, bClosed, pPoints->getArray(),
pFlags->getArray(), a, nCnt, 3);
if(pPrevPos3)
{
// prepare coordinates
sal_Int32 nX, nY;
Imp_PrepareCoorExport(nX, nY, pPointArray, rObjectPos, rObjectSize,
mrViewBox, bScale, bTranslate);
// #100617# test if this curve segment may be written as
// a quadratic bezier
// That's the case if both control points are in the same place
// when they are prolonged to the common quadratic control point
// Left: P = (3P1 - P0) / 2
// Right: P = (3P2 - P3) / 2
bool bIsQuadratic(false);
const bool bEnableSaveQuadratic(false);
sal_Int32 nPX_L(FRound((double)((3 * pPrevPos2->X) - pPrevPos3->X) / 2.0));
sal_Int32 nPY_L(FRound((double)((3 * pPrevPos2->Y) - pPrevPos3->Y) / 2.0));
sal_Int32 nPX_R(FRound((double)((3 * pPrevPos1->X) - pPointArray->X) / 2.0));
sal_Int32 nPY_R(FRound((double)((3 * pPrevPos1->Y) - pPointArray->Y) / 2.0));
sal_Int32 nDist(0);
if(nPX_L != nPX_R)
{
nDist += abs(nPX_L - nPX_R);
}
if(nPY_L != nPY_R)
{
nDist += abs(nPY_L - nPY_R);
}
if(nDist <= BORDER_INTEGERS_ARE_EQUAL)
{
if(bEnableSaveQuadratic)
{
bIsQuadratic = true;
}
}
#ifdef TEST_QUADRATIC_CURVES
if(bDoTestHere)
{
bIsQuadratic = false;
if(pPrevPos1->X == pPrevPos2->X && pPrevPos1->Y == pPrevPos2->Y)
bIsQuadratic = true;
}
#endif // TEST_QUADRATIC_CURVES
if(bIsQuadratic)
{
#ifdef TEST_QUADRATIC_CURVES
if(bDoTestHere)
{
bool bPrevPointIsSymmetric(false);
if(drawing::PolygonFlags_SYMMETRIC == aPrevFlag3)
{
// get previous4 to see if it's a control point
awt::Point* pPrevPos4;
drawing::PolygonFlags aPrevFlag4;
Imp_GetPrevPos(pPrevPos4, aPrevFlag4, bClosed, pPoints->getArray(),
pFlags->getArray(), a, nCnt, 4);
if(drawing::PolygonFlags_CONTROL == aPrevFlag4)
{
// okay, prevPos3 is symmetric (c2) and prevPos4
// is existing control point, the 's' statement can be used
bPrevPointIsSymmetric = true;
}
}
if(bPrevPointIsSymmetric)
{
// write a shorthand/smooth quadratic curveto entry (T)
if(mbRelative)
{
if(aLastCommand != sal_Unicode('t'))
aNewString += OUString(sal_Unicode('t'));
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('t');
}
else
{
if(aLastCommand != sal_Unicode('T'))
aNewString += OUString(sal_Unicode('T'));
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('T');
}
}
else
{
// prepare coordinates
sal_Int32 nX1, nY1;
Imp_PrepareCoorExport(nX1, nY1, pPrevPos1, rObjectPos, rObjectSize,
mrViewBox, bScale, bTranslate);
// write a quadratic curveto entry (Q)
if(mbRelative)
{
if(aLastCommand != sal_Unicode('q'))
aNewString += OUString(sal_Unicode('q'));
Imp_PutNumberCharWithSpace(aNewString, nX1 - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY1 - mnLastY);
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('q');
}
else
{
if(aLastCommand != sal_Unicode('Q'))
aNewString += OUString(sal_Unicode('Q'));
Imp_PutNumberCharWithSpace(aNewString, nX1);
Imp_PutNumberCharWithSpace(aNewString, nY1);
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('Q');
}
}
}
else
{
#endif // TEST_QUADRATIC_CURVES
awt::Point aNewPoint(nPX_L, nPY_L);
bool bPrevPointIsSmooth(false);
if(drawing::PolygonFlags_SMOOTH == aPrevFlag3)
{
// get previous4 to see if it's a control point
awt::Point* pPrevPos4;
drawing::PolygonFlags aPrevFlag4;
Imp_GetPrevPos(pPrevPos4, aPrevFlag4, bClosed, pPoints->getArray(),
pFlags->getArray(), a, nCnt, 4);
if(drawing::PolygonFlags_CONTROL == aPrevFlag4)
{
// okay, prevPos3 is smooth (c1) and prevPos4
// is existing control point. Test if it's even symmetric
// and thus the 'T' statement may be used.
::basegfx::B2DVector aVec1(pPrevPos4->X - pPrevPos3->X, pPrevPos4->Y - pPrevPos3->Y);
::basegfx::B2DVector aVec2(aNewPoint.X - pPrevPos3->X, aNewPoint.Y - pPrevPos3->Y);
bool bSameLength(false);
bool bSameDirection(false);
// get vector values
Imp_CalcVectorValues(aVec1, aVec2, bSameLength, bSameDirection);
if(bSameLength && bSameDirection)
bPrevPointIsSmooth = true;
}
}
if(bPrevPointIsSmooth)
{
// write a shorthand/smooth quadratic curveto entry (T)
if(mbRelative)
{
if(aLastCommand != sal_Unicode('t'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('t'));
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('t');
}
else
{
if(aLastCommand != sal_Unicode('T'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('T'));
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('T');
}
}
else
{
// prepare coordinates
sal_Int32 nX1, nY1;
Imp_PrepareCoorExport(nX1, nY1, &aNewPoint, rObjectPos, rObjectSize,
mrViewBox, bScale, bTranslate);
// write a quadratic curveto entry (Q)
if(mbRelative)
{
if(aLastCommand != sal_Unicode('q'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('q'));
Imp_PutNumberCharWithSpace(aNewString, nX1 - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY1 - mnLastY);
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('q');
}
else
{
if(aLastCommand != sal_Unicode('Q'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('Q'));
Imp_PutNumberCharWithSpace(aNewString, nX1);
Imp_PutNumberCharWithSpace(aNewString, nY1);
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('Q');
}
}
#ifdef TEST_QUADRATIC_CURVES
}
#endif // TEST_QUADRATIC_CURVES
}
else
{
bool bPrevPointIsSymmetric(false);
if(drawing::PolygonFlags_SYMMETRIC == aPrevFlag3)
{
// get previous4 to see if it's a control point
awt::Point* pPrevPos4;
drawing::PolygonFlags aPrevFlag4;
Imp_GetPrevPos(pPrevPos4, aPrevFlag4, bClosed, pPoints->getArray(),
pFlags->getArray(), a, nCnt, 4);
if(drawing::PolygonFlags_CONTROL == aPrevFlag4)
{
// okay, prevPos3 is symmetric (c2) and prevPos4
// is existing control point, the 's' statement can be used
bPrevPointIsSymmetric = true;
}
}
// prepare coordinates
sal_Int32 nX2, nY2;
Imp_PrepareCoorExport(nX2, nY2, pPrevPos1, rObjectPos, rObjectSize,
mrViewBox, bScale, bTranslate);
if(bPrevPointIsSymmetric)
{
// write a shorthand/smooth curveto entry (S)
if(mbRelative)
{
if(aLastCommand != sal_Unicode('s'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('s'));
Imp_PutNumberCharWithSpace(aNewString, nX2 - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY2 - mnLastY);
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('s');
}
else
{
if(aLastCommand != sal_Unicode('S'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('S'));
Imp_PutNumberCharWithSpace(aNewString, nX2);
Imp_PutNumberCharWithSpace(aNewString, nY2);
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('S');
}
}
else
{
// prepare coordinates
sal_Int32 nX1, nY1;
Imp_PrepareCoorExport(nX1, nY1, pPrevPos2, rObjectPos, rObjectSize,
mrViewBox, bScale, bTranslate);
// write a curveto entry (C)
if(mbRelative)
{
if(aLastCommand != sal_Unicode('c'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('c'));
Imp_PutNumberCharWithSpace(aNewString, nX1 - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY1 - mnLastY);
Imp_PutNumberCharWithSpace(aNewString, nX2 - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY2 - mnLastY);
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('c');
}
else
{
if(aLastCommand != sal_Unicode('C'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('C'));
Imp_PutNumberCharWithSpace(aNewString, nX1);
Imp_PutNumberCharWithSpace(aNewString, nY1);
Imp_PutNumberCharWithSpace(aNewString, nX2);
Imp_PutNumberCharWithSpace(aNewString, nY2);
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('C');
}
}
}
// remember that current point IS written
bDidWriteAsCurve = true;
// remember new last position
mnLastX = nX;
mnLastY = nY;
}
}
}
}
}
if(!bDidWriteAsCurve)
{
// current point not yet written, prepare coordinates
sal_Int32 nX, nY;
Imp_PrepareCoorExport(nX, nY, pPointArray, rObjectPos, rObjectSize,
mrViewBox, bScale, bTranslate);
if(bDidWriteStart)
{
// write as normal point
if(mnLastX == nX)
{
if(mbRelative)
{
if(aLastCommand != sal_Unicode('v'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('v'));
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('v');
}
else
{
if(aLastCommand != sal_Unicode('V'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('V'));
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('V');
}
}
else if(mnLastY == nY)
{
if(mbRelative)
{
if(aLastCommand != sal_Unicode('h'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('h'));
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
aLastCommand = sal_Unicode('h');
}
else
{
if(aLastCommand != sal_Unicode('H'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('H'));
Imp_PutNumberCharWithSpace(aNewString, nX);
aLastCommand = sal_Unicode('H');
}
}
else
{
if(mbRelative)
{
if(aLastCommand != sal_Unicode('l'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('l'));
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('l');
}
else
{
if(aLastCommand != sal_Unicode('L'))
aNewString += rtl::OUString(static_cast<sal_Unicode>('L'));
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('L');
}
}
}
else
{
// write as start point
if(mbRelative)
{
aNewString += rtl::OUString(static_cast<sal_Unicode>('m'));
Imp_PutNumberCharWithSpace(aNewString, nX - mnLastX);
Imp_PutNumberCharWithSpace(aNewString, nY - mnLastY);
aLastCommand = sal_Unicode('l');
}
else
{
aNewString += rtl::OUString(static_cast<sal_Unicode>('M'));
Imp_PutNumberCharWithSpace(aNewString, nX);
Imp_PutNumberCharWithSpace(aNewString, nY);
aLastCommand = sal_Unicode('L');
}
// remember start written
bDidWriteStart = true;
nStartX = nX;
nStartY = nY;
}
// remember new last position
mnLastX = nX;
mnLastY = nY;
}
}
// next point
pPointArray++;
}
// close path if closed poly
if(bClosed)
{
if(mbRelative)
aNewString += rtl::OUString(static_cast<sal_Unicode>('z'));
else
aNewString += rtl::OUString(static_cast<sal_Unicode>('Z'));
// update current point - we're back at the start
if( bDidWriteStart )
{
mnLastX = nStartX;
mnLastY = nStartY;
}
}
// append new string
msString += aNewString;
}
}
SdXMLImExSvgDElement::SdXMLImExSvgDElement(const OUString& rNew,
const SdXMLImExViewBox& rViewBox,
const awt::Point& rObjectPos,
const awt::Size& rObjectSize,
const SvXMLImport& rImport)
: msString( rNew ),
mrViewBox( rViewBox ),
mbIsClosed( false ),
mbIsCurve( false ),
mbRelative( true ),
mnLastX( 0L ),
mnLastY( 0L ),
maPoly()
{
bool bWrongPositionAfterZ( false );
sal_Int32 nUPD( 0 );
sal_Int32 nBuildId( 0 );
if ( rImport.getBuildIds( nUPD, nBuildId ) &&
( ( nUPD == 641 ) || ( nUPD == 645 ) || ( nUPD == 680 ) || ( nUPD == 300 ) ||
( nUPD == 310 ) || ( nUPD == 320 ) || ( nUPD == 330 ) || ( nUPD == 340 ) ||
( nUPD == 350 && nBuildId < 202 ) ) )
{
bWrongPositionAfterZ = true;
}
// convert string to polygon
basegfx::B2DPolyPolygon aPoly;
basegfx::tools::importFromSvgD(aPoly,msString,bWrongPositionAfterZ);
mbIsCurve = aPoly.areControlPointsUsed();
mbIsClosed = aPoly.isClosed();
// object size and ViewBox size different?
basegfx::B2DHomMatrix aTransform;
const bool bScale(rObjectSize.Width != mrViewBox.GetWidth()
|| rObjectSize.Height != mrViewBox.GetHeight());
const bool bTranslate(mrViewBox.GetX() != 0L || mrViewBox.GetY() != 0L);
if( bTranslate )
aTransform.translate(
-mrViewBox.GetX(),
-mrViewBox.GetY());
if( bScale )
aTransform.scale(
(mrViewBox.GetWidth() ? rObjectSize.Width / mrViewBox.GetWidth() : 0),
(mrViewBox.GetHeight() ? rObjectSize.Height / mrViewBox.GetHeight() : 0));
aTransform.translate( rObjectPos.X, rObjectPos.Y );
aPoly.transform(aTransform);
basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier(aPoly,maPoly);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|