File: KoCharacterStyle.cpp

package info (click to toggle)
krita 1%3A3.1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 430,944 kB
  • ctags: 68,203
  • sloc: cpp: 798,916; xml: 7,448; ansic: 3,844; perl: 434; sh: 140; makefile: 20
file content (2268 lines) | stat: -rw-r--r-- 84,103 bytes parent folder | download
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
/* This file is part of the KDE project
 * Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
 * Copyright (C) 2007 Sebastian Sauer <mail@dipe.org>
 *  Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
 * Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in>
 * Copyright (C) 2011 Stuart Dickson <stuart@furkinfantasic.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
#include "KoCharacterStyle.h"

#include "Styles_p.h"

#include <QTextBlock>
#include <QTextCursor>
#include <QFontDatabase>

#include <KoOdfLoadingContext.h>
#include <KoOdfStylesReader.h>
#include <KoXmlNS.h>
#include <KoXmlReader.h>
#include <KoUnit.h>
#include <KoStore.h>
#include <KoStoreDevice.h>
#include <KoGenStyle.h>
#include <KoShadowStyle.h>
#include <KoShapeLoadingContext.h>
#include <KoStyleStack.h>
#include "KoTextDocument.h"

#ifdef SHOULD_BUILD_FONT_CONVERSION
#include <string.h>
#include <fontconfig/fontconfig.h>
#include <fontconfig/fcfreetype.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include FT_TYPES_H
#include FT_OUTLINE_H
#include FT_RENDER_H
#include FT_TRUETYPE_TABLES_H
#include FT_SFNT_NAMES_H
#endif

#include "TextDebug.h"
#include "KoTextDebug.h"

#ifdef SHOULD_BUILD_FONT_CONVERSION
    QMap<QString,qreal> textScaleMap;
#endif //SHOULD_BUILD_FONT_CONVERSION

class Q_DECL_HIDDEN KoCharacterStyle::Private
{
public:
    Private();
    ~Private() { }

    void setProperty(int key, const QVariant &value) {
        stylesPrivate.add(key, value);
    }
    qreal propertyDouble(int key) const {
        QVariant variant = stylesPrivate.value(key);
        if (variant.isNull()) {
            if (parentStyle)
                return parentStyle->d->propertyDouble(key);
            else if (defaultStyle)
                return defaultStyle->d->propertyDouble(key);
            return 0.0;
        }
        return variant.toDouble();
    }
    int propertyInt(int key) const {
        QVariant variant = stylesPrivate.value(key);
        if (variant.isNull()) {
            if (parentStyle)
                return parentStyle->d->propertyInt(key);
            else if (defaultStyle)
                return defaultStyle->d->propertyInt(key);
            return 0;
        }
        return variant.toInt();
    }
    QString propertyString(int key) const {
        QVariant variant = stylesPrivate.value(key);
        if (variant.isNull()) {
            if (parentStyle)
                return parentStyle->d->propertyString(key);
            else if (defaultStyle)
                return defaultStyle->d->propertyString(key);
            return QString();
        }
        return qvariant_cast<QString>(variant);
    }
    bool propertyBoolean(int key) const {
        QVariant variant = stylesPrivate.value(key);
        if (variant.isNull()) {
            if (parentStyle)
                return parentStyle->d->propertyBoolean(key);
            else if (defaultStyle)
                return defaultStyle->d->propertyBoolean(key);
            return false;
        }
        return variant.toBool();
    }
    QColor propertyColor(int key) const {
        QVariant variant = stylesPrivate.value(key);
        if (variant.isNull()) {
            if (parentStyle)
                return parentStyle->d->propertyColor(key);
            else if (defaultStyle)
                return defaultStyle->d->propertyColor(key);
            return QColor();
        }
        return variant.value<QColor>();
    }

    // problem with fonts in linux and windows is that true type fonts have more than one metric
    // they have normal metric placed in font header table
    //           microsoft metric placed in os2 table
    //           apple metric placed in os2 table
    // ms-word is probably using CreateFontIndirect and GetOutlineTextMetric function to calculate line height
    // and this functions are using windows gdi environment which is using microsoft font metric placed in os2 table
    // qt on linux is using normal font metric
    // this two metrics are different and change from font to font
    // this font stretch is needed if we want to have exact line height as in ms-word and oo
    //
    // font_size * font_stretch = windows_font_height
    qreal calculateFontYStretch(const QString &fontFamily);


    StylePrivate hardCodedDefaultStyle;

    QString name;
    StylePrivate stylesPrivate;
    KoCharacterStyle *parentStyle;
    KoCharacterStyle *defaultStyle;
    bool m_inUse;
};

KoCharacterStyle::Private::Private()
    : parentStyle(0), defaultStyle(0), m_inUse(false)
{
    //set the minimal default properties
    hardCodedDefaultStyle.add(QTextFormat::FontFamily, QString("Sans Serif"));
    hardCodedDefaultStyle.add(QTextFormat::FontPointSize, 12.0);
    hardCodedDefaultStyle.add(QTextFormat::ForegroundBrush, QBrush(Qt::black));
    hardCodedDefaultStyle.add(KoCharacterStyle::FontYStretch, 1);
    hardCodedDefaultStyle.add(QTextFormat::FontHintingPreference, QFont::PreferNoHinting);
}


void KoCharacterStyle::ensureMinimalProperties(QTextCharFormat &format) const
{
    if (d->defaultStyle) {
        QMap<int, QVariant> props = d->defaultStyle->d->stylesPrivate.properties();
        QMap<int, QVariant>::const_iterator it = props.constBegin();
        while (it != props.constEnd()) {
            // in case there is already a foreground color don't apply the use window font color as then the forground color
            // should be used.
            if (it.key() == KoCharacterStyle::UseWindowFontColor && format.hasProperty(QTextFormat::ForegroundBrush)) {
                ++it;
                continue;
            }
            // in case there is already a use window font color don't apply the forground brush as this overwrite the foreground color
            if (it.key() == QTextFormat::ForegroundBrush && format.hasProperty(KoCharacterStyle::UseWindowFontColor)) {
                ++it;
                continue;
            }

            if (!it.value().isNull() && !format.hasProperty(it.key())) {
                format.setProperty(it.key(), it.value());
            }
            ++it;
        }
    }
    QMap<int, QVariant> props = d->hardCodedDefaultStyle.properties();
    QMap<int, QVariant>::const_iterator it = props.constBegin();
    while (it != props.constEnd()) {
        if (!it.value().isNull() && !format.hasProperty(it.key())) {
            if (it.key() == QTextFormat::ForegroundBrush && format.hasProperty(KoCharacterStyle::UseWindowFontColor)) {
                ++it;
                continue;
            }

            format.setProperty(it.key(), it.value());
        }
        ++it;
    }
}

qreal KoCharacterStyle::Private::calculateFontYStretch(const QString &fontFamily)
{
    qreal stretch = 1;
#ifdef SHOULD_BUILD_FONT_CONVERSION

    if (textScaleMap.contains(fontFamily)) {
        return textScaleMap.value(fontFamily);
    }

    FcResult result = FcResultMatch;
    FT_Library  library;
    FT_Face face;
    int id = 0;
    int error = 0;
    QByteArray fontName = fontFamily.toLatin1();

    //TODO http://freedesktop.org/software/fontconfig/fontconfig-devel/x19.html
    // we should specify slant and weight too
    FcPattern *font = FcPatternBuild (0, FC_FAMILY, FcTypeString,fontName.data(), FC_SIZE, FcTypeDouble, (qreal)11, 0);
    if (font == 0) {
        return 1;
    }

    // find font
    FcPattern *matched = 0;
    matched = FcFontMatch (0, font, &result);
    if (matched == 0) {
        FcPatternDestroy (font);
        return 1;
    }

    // get font family name
    char * str = 0;
    result = FcPatternGetString (matched, FC_FAMILY, 0,(FcChar8**) &str);
    if (result != FcResultMatch || str == 0) {
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // check if right font was found
    QByteArray foundFontFamily = QByteArray::fromRawData(str, strlen(str));
    if (foundFontFamily != fontName) {
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // get path to font
    str = 0;
    result = FcPatternGetString (matched, FC_FILE, 0,(FcChar8**) &str);
    if (result != FcResultMatch) {
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // get index of font inside the font file
    result = FcPatternGetInteger (matched, FC_INDEX, 0, &id);
    if (result != FcResultMatch) {
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // initialize freetype
    error = FT_Init_FreeType( &library );
    if (error) {
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // get font metric
    error = FT_New_Face (library,(char *) str, id, &face);
    if (error) {
        FT_Done_FreeType(library);
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // get font metric os2 table
    TT_OS2      *os2;
    os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
    if(os2 == 0) {
        FT_Done_Face(face);
        FT_Done_FreeType(library);
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // get font metric header table
    TT_Header   *header;
    header = (TT_Header *) FT_Get_Sfnt_Table (face, ft_sfnt_head);
    if(header == 0) {
        FT_Done_Face(face);
        FT_Done_FreeType(library);
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // check if the data is valid
    if (header->Units_Per_EM == 0 || (os2->usWinAscent + os2->usWinDescent) == 0) {
        FT_Done_Face(face);
        FT_Done_FreeType(library);
        FcPatternDestroy (font);
        FcPatternDestroy (matched);
        return 1;
    }

    // compute font height stretch
    // font_size * font_stretch = windows_font_height
    qreal height = os2->usWinAscent + os2->usWinDescent;
    height = height * (2048 / header->Units_Per_EM);
    stretch = (1.215 * height)/2500;
    stretch = (1.15 * height)/2500; // seems a better guess but probably not right

    FT_Done_Face(face);
    FT_Done_FreeType(library);
    FcPatternDestroy (font);
    FcPatternDestroy (matched);

    textScaleMap.insert(fontFamily, stretch);
#else
    Q_UNUSED(fontFamily);
#endif //SHOULD_BUILD_FONT_CONVERSION

    return stretch;
}
KoCharacterStyle::KoCharacterStyle(QObject *parent)
        : QObject(parent), d(new Private())
{
}

KoCharacterStyle::KoCharacterStyle(const QTextCharFormat &format, QObject *parent)
        : QObject(parent), d(new Private())
{
    copyProperties(format);
}

KoCharacterStyle::Type KoCharacterStyle::styleType() const
{
    return KoCharacterStyle::CharacterStyle;
}

void KoCharacterStyle::copyProperties(const KoCharacterStyle *style)
{
    d->stylesPrivate = style->d->stylesPrivate;
    setName(style->name()); // make sure we emit property change
    d->parentStyle = style->d->parentStyle;
    d->defaultStyle = style->d->defaultStyle;
}

void KoCharacterStyle::copyProperties(const QTextCharFormat &format)
{
    d->stylesPrivate = format.properties();
}

KoCharacterStyle *KoCharacterStyle::clone(QObject *parent) const
{
    KoCharacterStyle *newStyle = new KoCharacterStyle(parent);
    newStyle->copyProperties(this);
    return newStyle;
}

KoCharacterStyle::~KoCharacterStyle()
{
    delete d;
}

void KoCharacterStyle::setDefaultStyle(KoCharacterStyle *defaultStyle)
{
    d->defaultStyle = defaultStyle;
}

void KoCharacterStyle::setParentStyle(KoCharacterStyle *parent)
{
    d->parentStyle = parent;
}

KoCharacterStyle *KoCharacterStyle::parentStyle() const
{
    return d->parentStyle;
}

QPen KoCharacterStyle::textOutline() const
{
    QVariant variant = value(QTextFormat::TextOutline);
    if (variant.isNull()) {
        return QPen(Qt::NoPen);
    }
    return qvariant_cast<QPen>(variant);
}

QBrush KoCharacterStyle::background() const
{
    QVariant variant = value(QTextFormat::BackgroundBrush);

    if (variant.isNull()) {
        return QBrush();
    }
    return qvariant_cast<QBrush>(variant);
}

void KoCharacterStyle::clearBackground()
{
    d->stylesPrivate.remove(QTextCharFormat::BackgroundBrush);
}

QBrush KoCharacterStyle::foreground() const
{
    QVariant variant = value(QTextFormat::ForegroundBrush);
    if (variant.isNull()) {
        return QBrush();
    }
    return qvariant_cast<QBrush>(variant);
}

void KoCharacterStyle::clearForeground()
{
    d->stylesPrivate.remove(QTextCharFormat::ForegroundBrush);
}

void KoCharacterStyle::applyStyle(QTextCharFormat &format, bool emitSignal) const
{
    if (d->parentStyle) {
        d->parentStyle->applyStyle(format);
    }

    bool fontSizeSet = false; // if this style has already set size don't apply the relatives
    const QMap<int, QVariant> props = d->stylesPrivate.properties();
    QMap<int, QVariant>::const_iterator it = props.begin();
    QList<int> clearProperty;
    while (it != props.end()) {
        if (!it.value().isNull()) {
            if (it.key() == KoCharacterStyle::PercentageFontSize && !fontSizeSet) {
                qreal size = it.value().toDouble() / 100.0;
                if (format.hasProperty(QTextFormat::FontPointSize)) {
                    size *= format.doubleProperty(QTextFormat::FontPointSize);
                } else {
                    size *= 12.0;
                }
                format.setProperty(QTextFormat::FontPointSize, size);
            }
            else if (it.key() == KoCharacterStyle::AdditionalFontSize && !fontSizeSet) {
                qreal size = it.value().toDouble() / 100.0;
                if (format.hasProperty(QTextFormat::FontPointSize)) {
                    size += format.doubleProperty(QTextFormat::FontPointSize);
                } else {
                    size += 12.0;
                }
                format.setProperty(QTextFormat::FontPointSize, size);
            }
            else if (it.key() == QTextFormat::FontFamily) {
                if (!props.contains(QTextFormat::FontStyleHint)) {
                    clearProperty.append(QTextFormat::FontStyleHint);
                }
                if (!props.contains(QTextFormat::FontFixedPitch)) {
                    clearProperty.append(QTextFormat::FontFixedPitch);
                }
                if (!props.contains(KoCharacterStyle::FontCharset)) {
                    clearProperty.append(KoCharacterStyle::FontCharset);
                }
                format.setProperty(it.key(), it.value());
            }
            else {
                debugText << "setProperty" << it.key() << it.value();
                format.setProperty(it.key(), it.value());
            }

            if (it.key() == QTextFormat::FontPointSize) {
                fontSizeSet = true;
            }

            if (it.key() == QTextFormat::ForegroundBrush) {
                clearProperty.append(KoCharacterStyle::UseWindowFontColor);
            }
            else if (it.key() == KoCharacterStyle::UseWindowFontColor) {
                clearProperty.append(QTextFormat::ForegroundBrush);
            }
        }
        ++it;
    }

    foreach (int property, clearProperty) {
        debugText << "clearProperty" << property;
        format.clearProperty(property);
    }
    if (emitSignal) {
        emit styleApplied(this);
        d->m_inUse = true;
    }
}

KoCharacterStyle *KoCharacterStyle::autoStyle(const QTextCharFormat &format, QTextCharFormat blockCharFormat) const
{
    KoCharacterStyle *autoStyle = new KoCharacterStyle(format);
    applyStyle(blockCharFormat, false);
    ensureMinimalProperties(blockCharFormat);
    autoStyle->removeDuplicates(blockCharFormat);
    autoStyle->setParentStyle(const_cast<KoCharacterStyle*>(this));
    // remove StyleId if it is there as it is not a property of the style itself and will not be written out
    // so it should not be part of the autostyle. As otherwise it can happen that the StyleId is the only
    // property left and then we write out an empty style which is unneeded.
    // we also need to remove the properties of links as they are saved differently
    autoStyle->d->stylesPrivate.remove(StyleId);
    autoStyle->d->stylesPrivate.remove(QTextFormat::IsAnchor);
    autoStyle->d->stylesPrivate.remove(QTextFormat::AnchorHref);
    autoStyle->d->stylesPrivate.remove(QTextFormat::AnchorName);
    return autoStyle;
}

struct FragmentData
{
    FragmentData(const QTextCharFormat &format, int position, int length)
    : format(format)
    , position(position)
    , length(length)
    {}

    QTextCharFormat format;
    int position;
    int length;
};

void KoCharacterStyle::applyStyle(QTextBlock &block) const
{
    QTextCursor cursor(block);
    QTextCharFormat cf = block.charFormat();

    if (!cf.isTableCellFormat()) {
        cf = KoTextDocument(block.document()).frameCharFormat();
    }

    applyStyle(cf);
    ensureMinimalProperties(cf);
    cursor.setBlockCharFormat(cf);

    // be sure that we keep the InlineInstanceId, anchor information and ChangeTrackerId when applying a style

    QList<FragmentData> fragments;
    for (QTextBlock::iterator it = block.begin(); it != block.end(); ++it) {
        QTextFragment currentFragment = it.fragment();
        if (currentFragment.isValid()) {
            QTextCharFormat format(cf);
            QVariant v = currentFragment.charFormat().property(InlineInstanceId);
            if (!v.isNull()) {
                format.setProperty(InlineInstanceId, v);
            }

            v = currentFragment.charFormat().property(ChangeTrackerId);
            if (!v.isNull()) {
                format.setProperty(ChangeTrackerId, v);
            }

            if (currentFragment.charFormat().isAnchor()) {
                format.setAnchor(true);
                format.setAnchorHref(currentFragment.charFormat().anchorHref());
            }
            fragments.append(FragmentData(format, currentFragment.position(), currentFragment.length()));
        }
    }

    foreach (const FragmentData &fragment, fragments) {
        cursor.setPosition(fragment.position);
        cursor.setPosition(fragment.position + fragment.length, QTextCursor::KeepAnchor);
        cursor.setCharFormat(fragment.format);
    }
}

void KoCharacterStyle::applyStyle(QTextCursor *selection) const
{
// FIXME below should be done for each frament in the selection
    QTextCharFormat cf = selection->charFormat();
    applyStyle(cf);
    ensureMinimalProperties(cf);
    selection->setCharFormat(cf);
}

void KoCharacterStyle::unapplyStyle(QTextCharFormat &format) const
{
    if (d->parentStyle)
        d->parentStyle->unapplyStyle(format);

    QMap<int, QVariant> props = d->stylesPrivate.properties();
    QMap<int, QVariant>::const_iterator it = props.constBegin();
    while (it != props.constEnd()) {
        if (!it.value().isNull() && it.value() == format.property(it.key())) {
           format.clearProperty(it.key());
        }
        ++it;
    }

    props = d->hardCodedDefaultStyle.properties();
    it = props.constBegin();
    while (it != props.constEnd()) {
        if (!it.value().isNull() && !format.hasProperty(it.key())) {
            format.setProperty(it.key(), it.value());
        }
        ++it;
    }
}

bool KoCharacterStyle::isApplied() const
{
    return d->m_inUse;
}

void KoCharacterStyle::unapplyStyle(QTextBlock &block) const
{
    QTextCursor cursor(block);
    QTextCharFormat cf = cursor.blockCharFormat();
    unapplyStyle(cf);
    cursor.setBlockCharFormat(cf);

    if (block.length() == 1) // only the linefeed
        return;
    QTextBlock::iterator iter = block.end();
    do {
        --iter;
        QTextFragment fragment = iter.fragment();
        cursor.setPosition(fragment.position() + 1);
        cf = cursor.charFormat();
        unapplyStyle(cf);
        cursor.setPosition(fragment.position());
        cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
        cursor.setCharFormat(cf);
    } while (iter != block.begin());
}

// OASIS 14.2.29
static void parseOdfLineWidth(const QString &width, KoCharacterStyle::LineWeight &lineWeight, qreal &lineWidth)
{
    lineWidth = 0;
    lineWeight = KoCharacterStyle::AutoLineWeight;
    if (width.isEmpty() || width == "auto")
        lineWeight = KoCharacterStyle::AutoLineWeight;
    else if (width == "normal")
        lineWeight = KoCharacterStyle::NormalLineWeight;
    else if (width == "bold")
        lineWeight = KoCharacterStyle::BoldLineWeight;
    else if (width == "thin")
        lineWeight = KoCharacterStyle::ThinLineWeight;
    else if (width == "dash")
        lineWeight = KoCharacterStyle::DashLineWeight;
    else if (width == "medium")
        lineWeight = KoCharacterStyle::MediumLineWeight;
    else if (width == "thick")
        lineWeight = KoCharacterStyle::ThickLineWeight;
    else if (width.endsWith('%')) {
        lineWeight = KoCharacterStyle::PercentLineWeight;
        lineWidth = width.mid(0, width.length() - 1).toDouble();
    } else if (width[width.length()-1].isNumber()) {
        lineWeight = KoCharacterStyle::LengthLineWeight;
        lineWidth = width.toDouble();
    } else {
        lineWeight = KoCharacterStyle::LengthLineWeight;
        lineWidth = KoUnit::parseValue(width);
    }
}

// OASIS 14.2.29
static void importOdfLine(const QString &type, const QString &style, KoCharacterStyle::LineStyle &lineStyle, KoCharacterStyle::LineType &lineType)
{
    lineStyle = KoCharacterStyle::NoLineStyle;
    lineType = KoCharacterStyle::NoLineType;

    QString fixedType = type;
    QString fixedStyle = style;
    if (fixedStyle == "none")
        fixedType.clear();
    else if (fixedType.isEmpty() && !fixedStyle.isEmpty())
        fixedType = "single";
    else if (!fixedType.isEmpty() && fixedType != "none" && fixedStyle.isEmpty()) {
        // don't set a style when the type is none
        fixedStyle = "solid";
    }

    if (fixedType == "single")
        lineType = KoCharacterStyle::SingleLine;
    else if (fixedType == "double")
        lineType = KoCharacterStyle::DoubleLine;

    if (fixedStyle == "solid")
        lineStyle = KoCharacterStyle::SolidLine;
    else if (fixedStyle == "dotted")
        lineStyle = KoCharacterStyle::DottedLine;
    else if (fixedStyle == "dash")
        lineStyle = KoCharacterStyle::DashLine;
    else if (fixedStyle == "long-dash")
        lineStyle = KoCharacterStyle::LongDashLine;
    else if (fixedStyle == "dot-dash")
        lineStyle = KoCharacterStyle::DotDashLine;
    else if (fixedStyle == "dot-dot-dash")
        lineStyle = KoCharacterStyle::DotDotDashLine;
    else if (fixedStyle == "wave")
        lineStyle = KoCharacterStyle::WaveLine;
}

static QString exportOdfLineType(KoCharacterStyle::LineType lineType)
{
    switch (lineType) {
    case KoCharacterStyle::NoLineType:
        return "none";
    case KoCharacterStyle::SingleLine:
        return "single";
    case KoCharacterStyle::DoubleLine:
        return "double";
    default:
        return "";
    }
}

static QString exportOdfLineStyle(KoCharacterStyle::LineStyle lineStyle)
{
    switch (lineStyle) {
    case KoCharacterStyle::NoLineStyle:
        return "none";
    case KoCharacterStyle::SolidLine:
        return "solid";
    case KoCharacterStyle::DottedLine:
        return "dotted";
    case KoCharacterStyle::DashLine:
        return "dash";
    case KoCharacterStyle::LongDashLine:
        return "long-dash";
    case KoCharacterStyle::DotDashLine:
        return "dot-dash";
    case KoCharacterStyle::DotDotDashLine:
        return "dot-dot-dash";
    case KoCharacterStyle::WaveLine:
        return "wave";
    default:
        return "";
    }
}
static QString exportOdfLineMode(KoCharacterStyle::LineMode lineMode)
{
    switch (lineMode) {
    case KoCharacterStyle::ContinuousLineMode:
        return "continuous";
    case KoCharacterStyle::SkipWhiteSpaceLineMode:
        return "skip-white-space";
    default:
        return "";
    }
}

static QString exportOdfLineWidth(KoCharacterStyle::LineWeight lineWeight, qreal lineWidth)
{
    switch (lineWeight) {
    case KoCharacterStyle::AutoLineWeight:
        return "auto";
    case KoCharacterStyle::NormalLineWeight:
        return "normal";
    case KoCharacterStyle::BoldLineWeight:
        return "bold";
    case KoCharacterStyle::ThinLineWeight:
        return "thin";
    case KoCharacterStyle::DashLineWeight:
        return "dash";
    case KoCharacterStyle::MediumLineWeight:
        return "medium";
    case KoCharacterStyle::ThickLineWeight:
        return "thick";
    case KoCharacterStyle::PercentLineWeight:
        return QString("%1%").arg(lineWidth);
    case KoCharacterStyle::LengthLineWeight:
        return QString("%1pt").arg(lineWidth);
    default:
        return QString();
    }
}

static QString exportOdfFontStyleHint(QFont::StyleHint hint)
{
    switch (hint) {
    case QFont::Serif:
        return "roman";
    case QFont::SansSerif:
        return "swiss";
    case QFont::TypeWriter:
        return "modern";
    case QFont::Decorative:
        return "decorative";
    case QFont::System:
        return "system";
        /*case QFont::Script */
    default:
        return "";
    }
}

void KoCharacterStyle::setFontFamily(const QString &family)
{
    d->setProperty(QTextFormat::FontFamily, family);
    setFontYStretch(d->calculateFontYStretch(family));
}
QString KoCharacterStyle::fontFamily() const
{
    return d->propertyString(QTextFormat::FontFamily);
}
void KoCharacterStyle::setFontPointSize(qreal size)
{
    d->setProperty(QTextFormat::FontPointSize, size);
}
void KoCharacterStyle::clearFontPointSize() {
    d->stylesPrivate.remove(QTextFormat::FontPointSize);
}
qreal KoCharacterStyle::fontPointSize() const
{
    return d->propertyDouble(QTextFormat::FontPointSize);
}
void KoCharacterStyle::setFontWeight(int weight)
{
    d->setProperty(QTextFormat::FontWeight, weight);
}
int KoCharacterStyle::fontWeight() const
{
    return d->propertyInt(QTextFormat::FontWeight);
}
void KoCharacterStyle::setFontItalic(bool italic)
{
    d->setProperty(QTextFormat::FontItalic, italic);
}
bool KoCharacterStyle::fontItalic() const
{
    return d->propertyBoolean(QTextFormat::FontItalic);
}
///TODO Review legacy fontOverline functions and testing (consider removal)
/*
void KoCharacterStyle::setFontOverline(bool overline)
{
    d->setProperty(QTextFormat::FontOverline, overline);
}
bool KoCharacterStyle::fontOverline() const
{
    return d->propertyBoolean(QTextFormat::FontOverline);
}
*/
void KoCharacterStyle::setFontFixedPitch(bool fixedPitch)
{
    d->setProperty(QTextFormat::FontFixedPitch, fixedPitch);
}
bool KoCharacterStyle::fontFixedPitch() const
{
    return d->propertyBoolean(QTextFormat::FontFixedPitch);
}
void KoCharacterStyle::setFontStyleHint(QFont::StyleHint styleHint)
{
    d->setProperty(QTextFormat::FontStyleHint, styleHint);
}
QFont::StyleHint KoCharacterStyle::fontStyleHint() const
{
    return static_cast<QFont::StyleHint>(d->propertyInt(QTextFormat::FontStyleHint));
}
void KoCharacterStyle::setFontKerning(bool enable)
{
    d->setProperty(QTextFormat::FontKerning, enable);
}
bool KoCharacterStyle::fontKerning() const
{
    return d->propertyBoolean(QTextFormat::FontKerning);
}
void KoCharacterStyle::setVerticalAlignment(QTextCharFormat::VerticalAlignment alignment)
{
    d->setProperty(QTextFormat::TextVerticalAlignment, alignment);
}
QTextCharFormat::VerticalAlignment KoCharacterStyle::verticalAlignment() const
{
    return static_cast<QTextCharFormat::VerticalAlignment>(d->propertyInt(QTextFormat::TextVerticalAlignment));
}
void KoCharacterStyle::setTextOutline(const QPen &pen)
{
    d->setProperty(QTextFormat::TextOutline, pen);
}
void KoCharacterStyle::setBackground(const QBrush &brush)
{
    d->setProperty(QTextFormat::BackgroundBrush, brush);
}
void KoCharacterStyle::setForeground(const QBrush &brush)
{
    d->setProperty(QTextFormat::ForegroundBrush, brush);
}
void KoCharacterStyle::setFontAutoColor(bool use)
{
    d->setProperty(KoCharacterStyle::UseWindowFontColor, use);
}

QString KoCharacterStyle::name() const
{
    return d->name;
}
void KoCharacterStyle::setName(const QString &name)
{
    if (name == d->name)
        return;
    d->name = name;
    emit nameChanged(name);
}
int KoCharacterStyle::styleId() const
{
    return d->propertyInt(StyleId);
}
void KoCharacterStyle::setStyleId(int id)
{
    d->setProperty(StyleId, id);
}
QFont KoCharacterStyle::font() const
{
    QFont font;
    if (d->stylesPrivate.contains(QTextFormat::FontFamily))
        font.setFamily(fontFamily());
    if (d->stylesPrivate.contains(QTextFormat::FontPointSize))
        font.setPointSizeF(fontPointSize());
    if (d->stylesPrivate.contains(QTextFormat::FontWeight))
        font.setWeight(fontWeight());
    if (d->stylesPrivate.contains(QTextFormat::FontItalic))
        font.setItalic(fontItalic());
    return font;
}
void KoCharacterStyle::setHasHyphenation(bool on)
{
    d->setProperty(HasHyphenation, on);
}
bool KoCharacterStyle::hasHyphenation() const
{
    return d->propertyBoolean(HasHyphenation);
}

void KoCharacterStyle::setHyphenationPushCharCount(int count)
{
    if (count > 0)
        d->setProperty(HyphenationPushCharCount, count);
    else
        d->stylesPrivate.remove(HyphenationPushCharCount);
}

int KoCharacterStyle::hyphenationPushCharCount() const
{
    if (hasProperty(HyphenationPushCharCount))
        return d->propertyInt(HyphenationPushCharCount);
    return 0;
}

void KoCharacterStyle::setHyphenationRemainCharCount(int count)
{
    if (count > 0)
        d->setProperty(HyphenationRemainCharCount, count);
    else
        d->stylesPrivate.remove(HyphenationRemainCharCount);
}

int KoCharacterStyle::hyphenationRemainCharCount() const
{
    if (hasProperty(HyphenationRemainCharCount))
        return d->propertyInt(HyphenationRemainCharCount);
    return 0;
}

void KoCharacterStyle::setStrikeOutStyle(KoCharacterStyle::LineStyle strikeOut)
{
    d->setProperty(StrikeOutStyle, strikeOut);
}

KoCharacterStyle::LineStyle KoCharacterStyle::strikeOutStyle() const
{
    return (KoCharacterStyle::LineStyle) d->propertyInt(StrikeOutStyle);
}

void KoCharacterStyle::setStrikeOutType(LineType lineType)
{
    d->setProperty(StrikeOutType, lineType);
}

KoCharacterStyle::LineType KoCharacterStyle::strikeOutType() const
{
    return (KoCharacterStyle::LineType) d->propertyInt(StrikeOutType);
}

void KoCharacterStyle::setStrikeOutColor(const QColor &color)
{
    d->setProperty(StrikeOutColor, color);
}

QColor KoCharacterStyle::strikeOutColor() const
{
    return d->propertyColor(StrikeOutColor);
}

void KoCharacterStyle::setStrikeOutWidth(LineWeight weight, qreal width)
{
    d->setProperty(KoCharacterStyle::StrikeOutWeight, weight);
    d->setProperty(KoCharacterStyle::StrikeOutWidth, width);
}

void KoCharacterStyle::strikeOutWidth(LineWeight &weight, qreal &width) const
{
    weight = (KoCharacterStyle::LineWeight) d->propertyInt(KoCharacterStyle::StrikeOutWeight);
    width = d->propertyDouble(KoCharacterStyle::StrikeOutWidth);
}
void KoCharacterStyle::setStrikeOutMode(LineMode lineMode)
{
    d->setProperty(StrikeOutMode, lineMode);
}

void KoCharacterStyle::setStrikeOutText(const QString &text)
{
    d->setProperty(StrikeOutText, text);
}
QString KoCharacterStyle::strikeOutText() const
{
    return d->propertyString(StrikeOutText);
}
KoCharacterStyle::LineMode KoCharacterStyle::strikeOutMode() const
{
    return (KoCharacterStyle::LineMode) d->propertyInt(StrikeOutMode);
}

void KoCharacterStyle::setOverlineStyle(KoCharacterStyle::LineStyle overline)
{
    d->setProperty(OverlineStyle, overline);
}

KoCharacterStyle::LineStyle KoCharacterStyle::overlineStyle() const
{
    return (KoCharacterStyle::LineStyle) d->propertyInt(OverlineStyle);
}

void KoCharacterStyle::setOverlineType(LineType lineType)
{
    d->setProperty(OverlineType, lineType);
}

KoCharacterStyle::LineType KoCharacterStyle::overlineType() const
{
    return (KoCharacterStyle::LineType) d->propertyInt(OverlineType);
}

void KoCharacterStyle::setOverlineColor(const QColor &color)
{
    d->setProperty(KoCharacterStyle::OverlineColor, color);
}

QColor KoCharacterStyle::overlineColor() const
{
    return d->propertyColor(KoCharacterStyle::OverlineColor);
}

void KoCharacterStyle::setOverlineWidth(LineWeight weight, qreal width)
{
    d->setProperty(KoCharacterStyle::OverlineWeight, weight);
    d->setProperty(KoCharacterStyle::OverlineWidth, width);
}

void KoCharacterStyle::overlineWidth(LineWeight &weight, qreal &width) const
{
    weight = (KoCharacterStyle::LineWeight) d->propertyInt(KoCharacterStyle::OverlineWeight);
    width = d->propertyDouble(KoCharacterStyle::OverlineWidth);
}

void KoCharacterStyle::setOverlineMode(LineMode mode)
{
    d->setProperty(KoCharacterStyle::OverlineMode, mode);
}

KoCharacterStyle::LineMode KoCharacterStyle::overlineMode() const
{
    return static_cast<KoCharacterStyle::LineMode>(d->propertyInt(KoCharacterStyle::OverlineMode));
}

void KoCharacterStyle::setUnderlineStyle(KoCharacterStyle::LineStyle underline)
{
    d->setProperty(UnderlineStyle, underline);
}

KoCharacterStyle::LineStyle KoCharacterStyle::underlineStyle() const
{
    return (KoCharacterStyle::LineStyle) d->propertyInt(UnderlineStyle);
}

void KoCharacterStyle::setUnderlineType(LineType lineType)
{
    d->setProperty(UnderlineType, lineType);
}

KoCharacterStyle::LineType KoCharacterStyle::underlineType() const
{
    return (KoCharacterStyle::LineType) d->propertyInt(UnderlineType);
}

void KoCharacterStyle::setUnderlineColor(const QColor &color)
{
    d->setProperty(QTextFormat::TextUnderlineColor, color);
}

QColor KoCharacterStyle::underlineColor() const
{
    return d->propertyColor(QTextFormat::TextUnderlineColor);
}

void KoCharacterStyle::setUnderlineWidth(LineWeight weight, qreal width)
{
    d->setProperty(KoCharacterStyle::UnderlineWeight, weight);
    d->setProperty(KoCharacterStyle::UnderlineWidth, width);
}

void KoCharacterStyle::underlineWidth(LineWeight &weight, qreal &width) const
{
    weight = (KoCharacterStyle::LineWeight) d->propertyInt(KoCharacterStyle::UnderlineWeight);
    width = d->propertyDouble(KoCharacterStyle::UnderlineWidth);
}

void KoCharacterStyle::setUnderlineMode(LineMode mode)
{
    d->setProperty(KoCharacterStyle::UnderlineMode, mode);
}

KoCharacterStyle::LineMode KoCharacterStyle::underlineMode() const
{
    return static_cast<KoCharacterStyle::LineMode>(d->propertyInt(KoCharacterStyle::UnderlineMode));
}

void KoCharacterStyle::setFontLetterSpacing(qreal spacing)
{
    d->setProperty(KoCharacterStyle::FontLetterSpacing, spacing);
}

qreal KoCharacterStyle::fontLetterSpacing() const
{
    return d->propertyDouble(KoCharacterStyle::FontLetterSpacing);
}

void KoCharacterStyle::setFontWordSpacing(qreal spacing)
{
    d->setProperty(QTextCharFormat::FontWordSpacing, spacing);
}

qreal KoCharacterStyle::fontWordSpacing() const
{
    return d->propertyDouble(QTextCharFormat::FontWordSpacing);
}


void KoCharacterStyle::setFontCapitalization(QFont::Capitalization capitalization)
{
    d->setProperty(QTextFormat::FontCapitalization, capitalization);
}

QFont::Capitalization KoCharacterStyle::fontCapitalization() const
{
    return (QFont::Capitalization) d->propertyInt(QTextFormat::FontCapitalization);
}


void KoCharacterStyle::setFontYStretch(qreal stretch)
{
    d->setProperty(KoCharacterStyle::FontYStretch, stretch);
}

qreal KoCharacterStyle::fontYStretch() const
{
    return d->propertyDouble(KoCharacterStyle::FontYStretch);
}

void KoCharacterStyle::setCountry(const QString &country)
{
    if (country.isEmpty())
        d->stylesPrivate.remove(KoCharacterStyle::Country);
    else
        d->setProperty(KoCharacterStyle::Country, country);
}

void KoCharacterStyle::setLanguage(const QString &language)
{
    if (language.isEmpty())
        d->stylesPrivate.remove(KoCharacterStyle::Language);
    else
        d->setProperty(KoCharacterStyle::Language, language);
}

QString KoCharacterStyle::country() const
{
    return value(KoCharacterStyle::Country).toString();
}

QString KoCharacterStyle::language() const
{
    return d->propertyString(KoCharacterStyle::Language);
}

bool KoCharacterStyle::blinking() const
{
    return d->propertyBoolean(Blink);
}

void KoCharacterStyle::setBlinking(bool blink)
{
    d->setProperty(KoCharacterStyle::Blink, blink);
}

bool KoCharacterStyle::hasProperty(int key) const
{
    return d->stylesPrivate.contains(key);
}

static QString rotationScaleToString(KoCharacterStyle::RotationScale rotationScale)
{
    QString scale = "line-height";
    if (rotationScale == KoCharacterStyle::Fixed) {
        scale = "fixed";
    }
    return scale;
}

static KoCharacterStyle::RotationScale stringToRotationScale(const QString &scale)
{
    KoCharacterStyle::RotationScale rotationScale = KoCharacterStyle::LineHeight;
    if (scale == "fixed") {
        rotationScale = KoCharacterStyle::Fixed;
    }
    return rotationScale;
}

void KoCharacterStyle::setTextRotationAngle(qreal angle)
{
    d->setProperty(TextRotationAngle, angle);
}

qreal KoCharacterStyle::textRotationAngle() const
{
    return d->propertyDouble(TextRotationAngle);
}

void KoCharacterStyle::setTextRotationScale(RotationScale scale)
{
    d->setProperty(TextRotationScale, rotationScaleToString(scale));
}

KoCharacterStyle::RotationScale KoCharacterStyle::textRotationScale() const
{
    return stringToRotationScale(d->propertyString(TextRotationScale));
}

void KoCharacterStyle::setTextScale(int scale)
{
    d->setProperty(TextScale, scale);
}

int KoCharacterStyle::textScale() const
{
    return d->propertyInt(TextScale);
}

void KoCharacterStyle::setTextShadow(const KoShadowStyle& shadow)
{
    d->setProperty(TextShadow, qVariantFromValue<KoShadowStyle>(shadow));
}

KoShadowStyle KoCharacterStyle::textShadow() const
{
    if (hasProperty(TextShadow)) {
        QVariant shadow = value(TextShadow);
        if (shadow.canConvert<KoShadowStyle>())
            return shadow.value<KoShadowStyle>();
    }
    return KoShadowStyle();
}

void KoCharacterStyle::setTextCombine(KoCharacterStyle::TextCombineType type)
{
    d->setProperty(TextCombine, type);
}

KoCharacterStyle::TextCombineType KoCharacterStyle::textCombine() const
{
    if (hasProperty(TextCombine)) {
        return (KoCharacterStyle::TextCombineType) d->propertyInt(TextCombine);
    }
    return NoTextCombine;
}

QChar KoCharacterStyle::textCombineEndChar() const
{
    if (hasProperty(TextCombineEndChar)) {
        QString val = d->propertyString(TextCombineEndChar);
        if (val.length() > 0)
            return val.at(0);
    }
    return QChar();
}

void KoCharacterStyle::setTextCombineEndChar(const QChar& character)
{
    d->setProperty(TextCombineEndChar, character);
}

QChar KoCharacterStyle::textCombineStartChar() const
{
    if (hasProperty(TextCombineStartChar)) {
        QString val = d->propertyString(TextCombineStartChar);
        if (val.length() > 0)
            return val.at(0);
    }
    return QChar();
}

void KoCharacterStyle::setTextCombineStartChar(const QChar& character)
{
    d->setProperty(TextCombineStartChar, character);
}

void KoCharacterStyle::setFontRelief(KoCharacterStyle::ReliefType relief)
{
    d->setProperty(FontRelief, relief);
}

KoCharacterStyle::ReliefType KoCharacterStyle::fontRelief() const
{
    if (hasProperty(FontRelief))
        return (KoCharacterStyle::ReliefType) d->propertyInt(FontRelief);
    return KoCharacterStyle::NoRelief;
}


KoCharacterStyle::EmphasisPosition KoCharacterStyle::textEmphasizePosition() const
{
    if (hasProperty(TextEmphasizePosition))
        return (KoCharacterStyle::EmphasisPosition) d->propertyInt(TextEmphasizePosition);
    return KoCharacterStyle::EmphasisAbove;
}

void KoCharacterStyle::setTextEmphasizePosition(KoCharacterStyle::EmphasisPosition position)
{
    d->setProperty(TextEmphasizePosition, position);
}

KoCharacterStyle::EmphasisStyle KoCharacterStyle::textEmphasizeStyle() const
{
    if (hasProperty(TextEmphasizeStyle))
        return (KoCharacterStyle::EmphasisStyle) d->propertyInt(TextEmphasizeStyle);
    return KoCharacterStyle::NoEmphasis;
}

void KoCharacterStyle::setTextEmphasizeStyle(KoCharacterStyle::EmphasisStyle emphasis)
{
    d->setProperty(TextEmphasizeStyle, emphasis);
}

void KoCharacterStyle::setPercentageFontSize(qreal percent)
{
    d->setProperty(KoCharacterStyle::PercentageFontSize, percent);
}

qreal KoCharacterStyle::percentageFontSize() const
{
    return d->propertyDouble(KoCharacterStyle::PercentageFontSize);
}

void KoCharacterStyle::setAdditionalFontSize(qreal percent)
{
    d->setProperty(KoCharacterStyle::AdditionalFontSize, percent);
}

qreal KoCharacterStyle::additionalFontSize() const
{
    return d->propertyDouble(KoCharacterStyle::AdditionalFontSize);
}

void KoCharacterStyle::loadOdf(const KoXmlElement *element, KoShapeLoadingContext &scontext,
    bool loadParents)
{
    KoOdfLoadingContext &context = scontext.odfLoadingContext();
    const QString name(element->attributeNS(KoXmlNS::style, "display-name", QString()));
    if (!name.isEmpty()) {
        d->name = name;
    }
    else {
        d->name = element->attributeNS(KoXmlNS::style, "name", QString());
    }

    QString family = element->attributeNS(KoXmlNS::style, "family", "text");

    context.styleStack().save();
    if (loadParents) {
        context.addStyles(element, family.toLocal8Bit().constData());   // Load all parent
    } else {
        context.styleStack().push(*element);
    }
    context.styleStack().setTypeProperties("text");  // load the style:text-properties
    loadOdfProperties(scontext);
    context.styleStack().restore();
}

void KoCharacterStyle::loadOdfProperties(KoShapeLoadingContext &scontext)
{
    KoStyleStack &styleStack = scontext.odfLoadingContext().styleStack();

    d->stylesPrivate = StylePrivate();

    // The fo:color attribute specifies the foreground color of text.
    const QString color(styleStack.property(KoXmlNS::fo, "color"));
    if (!color.isEmpty()) {
        QColor c(color);
        if (c.isValid()) {     // 3.10.3
            setForeground(QBrush(c));
        }
    }

    QString fontName(styleStack.property(KoXmlNS::fo, "font-family"));
    if (!fontName.isEmpty()) {
        // Specify whether a font has a fixed or variable width.
        // These attributes are ignored if there is no corresponding fo:font-family attribute attached to the same formatting properties element.
        const QString fontPitch(styleStack.property(KoXmlNS::style, "font-pitch"));
        if (!fontPitch.isEmpty()) {
            setFontFixedPitch(fontPitch == "fixed");
        }

        const QString genericFamily(styleStack.property(KoXmlNS::style, "font-family-generic"));
        if (!genericFamily.isEmpty()) {
            if (genericFamily == "roman")
                setFontStyleHint(QFont::Serif);
            else if (genericFamily == "swiss")
                setFontStyleHint(QFont::SansSerif);
            else if (genericFamily == "modern")
                setFontStyleHint(QFont::TypeWriter);
            else if (genericFamily == "decorative")
                setFontStyleHint(QFont::Decorative);
            else if (genericFamily == "system")
                setFontStyleHint(QFont::System);
            else if (genericFamily == "script") {
                ; // TODO: no hint available in Qt yet, we should at least store it as a property internally!
            }
        }

        const QString fontCharset(styleStack.property(KoXmlNS::style, "font-charset"));
        if (!fontCharset.isEmpty()) {
            // this property is not required by Qt, since Qt auto selects the right font based on the text
            // The only charset of interest to us is x-symbol - this should disable spell checking
            d->setProperty(KoCharacterStyle::FontCharset, fontCharset);
        }
    }

    const QString fontFamily(styleStack.property(KoXmlNS::style, "font-family"));
    if (!fontFamily.isEmpty())
        fontName = fontFamily;

    if (styleStack.hasProperty(KoXmlNS::style, "font-name")) {
        // This font name is a reference to a font face declaration.
        KoOdfStylesReader &stylesReader = scontext.odfLoadingContext().stylesReader();
        const KoXmlElement *fontFace = stylesReader.findStyle(styleStack.property(KoXmlNS::style, "font-name"));
        if (fontFace != 0) {
            fontName = fontFace->attributeNS(KoXmlNS::svg, "font-family", "");

            KoXmlElement fontFaceElem;
            forEachElement(fontFaceElem, (*fontFace)) {
                if (fontFaceElem.tagName() == "font-face-src") {
                    KoXmlElement fontUriElem;
                    forEachElement(fontUriElem, fontFaceElem) {
                        if (fontUriElem.tagName() == "font-face-uri") {
                            QString filename = fontUriElem.attributeNS(KoXmlNS::xlink, "href");
                            KoStore *store = scontext.odfLoadingContext().store();
                            if (store->open(filename)) {
                                KoStoreDevice device(store);
                                QByteArray data = device.readAll();
                                if (device.open(QIODevice::ReadOnly)) {
                                    QFontDatabase::addApplicationFontFromData(data);
                                }
                            }
                        }
                    }
                }
            }
        }
     }

    if (!fontName.isEmpty()) {
        // Hmm, the remove "'" could break it's in the middle of the fontname...
        fontName = fontName.remove('\'');

        // 'Thorndale' is not known outside OpenOffice so we substitute it
        // with 'Times New Roman' that looks nearly the same.
        if (fontName == "Thorndale")
            fontName = "Times New Roman";

        // 'StarSymbol' is written by OpenOffice but they actually mean
        //  'OpenSymbol'.
        if (fontName == "StarSymbol")
            fontName = "OpenSymbol";

        fontName.remove(QRegExp("\\sCE$")); // Arial CE -> Arial
        setFontFamily(fontName);
    }

    // Specify the size of a font. The value of these attribute is either an absolute length or a percentage
    if (styleStack.hasProperty(KoXmlNS::fo, "font-size")) {
        const QString fontSize(styleStack.property(KoXmlNS::fo, "font-size"));
        if (!fontSize.isEmpty()) {
            if (fontSize.endsWith('%')) {
                setPercentageFontSize(fontSize.left(fontSize.length() - 1).toDouble());
            } else {
                setFontPointSize(KoUnit::parseValue(fontSize));
            }
        }
    }
    else {
        const QString fontSizeRel(styleStack.property(KoXmlNS::style, "font-size-rel"));
        if (!fontSizeRel.isEmpty()) {
            setAdditionalFontSize(KoUnit::parseValue(fontSizeRel));
        }
    }

    // Specify the weight of a font. The permitted values are normal, bold, and numeric values 100-900, in steps of 100. Unsupported numerical values are rounded off to the next supported value.
    const QString fontWeight(styleStack.property(KoXmlNS::fo, "font-weight"));
    if (!fontWeight.isEmpty()) {     // 3.10.24
        int boldness;
        if (fontWeight == "normal")
            boldness = 50;
        else if (fontWeight == "bold")
            boldness = 75;
        else
            // XSL/CSS has 100,200,300...900. Not the same scale as Qt!
            // See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#font-weight
            boldness = fontWeight.toInt() / 10;
        setFontWeight(boldness);
    }

    // Specify whether to use normal or italic font face.
    const QString fontStyle(styleStack.property(KoXmlNS::fo, "font-style" ));
    if (!fontStyle.isEmpty()) {     // 3.10.19
        if (fontStyle == "italic" || fontStyle == "oblique") {    // no difference in kotext
            setFontItalic(true);
        } else {
            setFontItalic(false);
        }
    }

//TODO
#if 0
    d->m_bWordByWord = styleStack.property(KoXmlNS::style, "text-underline-mode") == "skip-white-space";
    // TODO style:text-line-through-mode

    /*
    // OO compat code, to move to OO import filter
    d->m_bWordByWord = (styleStack.hasProperty( KoXmlNS::fo, "score-spaces")) // 3.10.25
                      && (styleStack.property( KoXmlNS::fo, "score-spaces") == "false");
    if( styleStack.hasProperty( KoXmlNS::style, "text-crossing-out" )) { // 3.10.6
        QString strikeOutType = styleStack.property( KoXmlNS::style, "text-crossing-out" );
        if( strikeOutType =="double-line")
            m_strikeOutType = S_DOUBLE;
        else if( strikeOutType =="single-line")
            m_strikeOutType = S_SIMPLE;
        else if( strikeOutType =="thick-line")
            m_strikeOutType = S_SIMPLE_BOLD;
        // not supported by Words: "slash" and "X"
        // not supported by OO: stylelines (solid, dash, dot, dashdot, dashdotdot)
    }
    */
#endif

    // overline modes
    const QString textOverlineMode(styleStack.property( KoXmlNS::style, "text-overline-mode"));
    if (!textOverlineMode.isEmpty()) {
        if (textOverlineMode == "skip-white-space") {
            setOverlineMode(SkipWhiteSpaceLineMode);
        } else if (textOverlineMode == "continuous") {
            setOverlineMode(ContinuousLineMode);
        }
    }

    // Specifies whether text is overlined, and if so, whether a single or qreal line will be used for overlining.
    const QString textOverlineType(styleStack.property(KoXmlNS::style, "text-overline-type"));
    const QString textOverlineStyle(styleStack.property(KoXmlNS::style, "text-overline-style"));
    if (!textOverlineType.isEmpty() || !textOverlineStyle.isEmpty()) {    // OASIS 14.4.28
        LineStyle overlineStyle;
        LineType overlineType;

        importOdfLine(textOverlineType, textOverlineStyle,
                      overlineStyle, overlineType);
        setOverlineStyle(overlineStyle);
        setOverlineType(overlineType);
    }

    const QString textOverlineWidth(styleStack.property(KoXmlNS::style, "text-overline-width"));
    if (!textOverlineWidth.isEmpty()) {
        qreal overlineWidth;
        LineWeight overlineWeight;
        parseOdfLineWidth(textOverlineWidth, overlineWeight, overlineWidth);
        setOverlineWidth(overlineWeight, overlineWidth);
    }

    // Specifies the color that is used to overline text. The value of this attribute is either font-color or a color. If the value is font-color, the current text color is used for overlining.
    QString overLineColor = styleStack.property(KoXmlNS::style, "text-overline-color");   // OO 3.10.23, OASIS 14.4.31
    if (!overLineColor.isEmpty() && overLineColor != "font-color") {
        setOverlineColor(QColor(overLineColor));
    } else if (overLineColor == "font-color") {
        setOverlineColor(QColor());
    }

    // underline modes
    const QString textUndelineMode(styleStack.property( KoXmlNS::style, "text-underline-mode"));
    if (!textUndelineMode.isEmpty()) {
        if (textUndelineMode == "skip-white-space") {
            setUnderlineMode(SkipWhiteSpaceLineMode);
        } else if (textUndelineMode == "continuous") {
            setUnderlineMode(ContinuousLineMode);
        }
    }

    // Specifies whether text is underlined, and if so, whether a single or qreal line will be used for underlining.
    const QString textUnderlineType(styleStack.property(KoXmlNS::style, "text-underline-type"));
    const QString textUnderlineStyle(styleStack.property(KoXmlNS::style, "text-underline-style"));
    if (!textUnderlineType.isEmpty() || !textUnderlineStyle.isEmpty()) {    // OASIS 14.4.28
        LineStyle underlineStyle;
        LineType underlineType;

        importOdfLine(textUnderlineType, textUnderlineStyle,
                      underlineStyle, underlineType);
        setUnderlineStyle(underlineStyle);
        setUnderlineType(underlineType);
    }

    const QString textUnderlineWidth(styleStack.property(KoXmlNS::style, "text-underline-width"));
    if (!textUnderlineWidth.isEmpty()) {
        qreal underlineWidth;
        LineWeight underlineWeight;
        parseOdfLineWidth(textUnderlineWidth, underlineWeight, underlineWidth);
        setUnderlineWidth(underlineWeight, underlineWidth);
    }

    // Specifies the color that is used to underline text. The value of this attribute is either font-color or a color. If the value is font-color, the current text color is used for underlining.
    QString underLineColor = styleStack.property(KoXmlNS::style, "text-underline-color");   // OO 3.10.23, OASIS 14.4.31
    if (!underLineColor.isEmpty() && underLineColor != "font-color") {
        setUnderlineColor(QColor(underLineColor));
    } else if (underLineColor == "font-color") {
        setUnderlineColor(QColor());
    }


    const QString textLineThroughType(styleStack.property(KoXmlNS::style, "text-line-through-type"));
    const QString textLineThroughStyle(styleStack.property(KoXmlNS::style, "text-line-through-style"));
    if (!textLineThroughType.isEmpty() || !textLineThroughStyle.isEmpty()) { // OASIS 14.4.7
        KoCharacterStyle::LineStyle throughStyle;
        LineType throughType;

        importOdfLine(textLineThroughType,textLineThroughStyle,
                      throughStyle, throughType);

        setStrikeOutStyle(throughStyle);
        setStrikeOutType(throughType);
        const QString textLineThroughText(styleStack.property(KoXmlNS::style, "text-line-through-text"));
        if (!textLineThroughText.isEmpty()) {
            setStrikeOutText(textLineThroughText);
        }
    }

    const QString textLineThroughWidth(styleStack.property(KoXmlNS::style, "text-line-through-width"));
    if (!textLineThroughWidth.isEmpty()) {
        qreal throughWidth;
        LineWeight throughWeight;
        parseOdfLineWidth(textLineThroughWidth, throughWeight, throughWidth);
        setStrikeOutWidth(throughWeight, throughWidth);
    }

    const QString lineThroughColor(styleStack.property(KoXmlNS::style, "text-line-through-color"));   // OO 3.10.23, OASIS 14.4.31
    if (!lineThroughColor.isEmpty() && lineThroughColor != "font-color") {
        setStrikeOutColor(QColor(lineThroughColor));
    }

    const QString lineThroughMode(styleStack.property(KoXmlNS::style, "text-line-through-mode"));
    if (lineThroughMode == "continuous") {
        setStrikeOutMode(ContinuousLineMode);
    }
    else if (lineThroughMode == "skip-white-space") {
        setStrikeOutMode(SkipWhiteSpaceLineMode);
    }

    const QString textPosition(styleStack.property(KoXmlNS::style, "text-position"));
    if (!textPosition.isEmpty()) {  // OO 3.10.7
        if (textPosition.startsWith("super"))
            setVerticalAlignment(QTextCharFormat::AlignSuperScript);
        else if (textPosition.startsWith("sub"))
            setVerticalAlignment(QTextCharFormat::AlignSubScript);
        else {
            QRegExp re("(-?[\\d.]+)%.*");
            if (re.exactMatch(textPosition)) {
                int percent = re.capturedTexts()[1].toInt();
                if (percent > 0)
                    setVerticalAlignment(QTextCharFormat::AlignSuperScript);
                else if (percent < 0)
                    setVerticalAlignment(QTextCharFormat::AlignSubScript);
                else // set explicit to overwrite inherited text-position's
                    setVerticalAlignment(QTextCharFormat::AlignNormal);
            }
        }
    }

    // The fo:font-variant attribute provides the option to display text as small capitalized letters.
    const QString textVariant(styleStack.property(KoXmlNS::fo, "font-variant"));
    if (!textVariant.isEmpty()) {
        if (textVariant == "small-caps")
            setFontCapitalization(QFont::SmallCaps);
        else if (textVariant == "normal")
            setFontCapitalization(QFont::MixedCase);
    }
    // The fo:text-transform attribute specifies text transformations to uppercase, lowercase, and capitalization.
    else {
        const QString textTransform(styleStack.property(KoXmlNS::fo, "text-transform"));
        if (!textTransform.isEmpty()) {
            if (textTransform == "uppercase")
                setFontCapitalization(QFont::AllUppercase);
            else if (textTransform == "lowercase")
                setFontCapitalization(QFont::AllLowercase);
            else if (textTransform == "capitalize")
                setFontCapitalization(QFont::Capitalize);
            else if (textTransform == "none")
                setFontCapitalization(QFont::MixedCase);
        }
    }

    const QString foLanguage(styleStack.property(KoXmlNS::fo, "language"));
    if (!foLanguage.isEmpty()) {
        setLanguage(foLanguage);
    }

    const QString foCountry(styleStack.property(KoXmlNS::fo, "country"));
    if (!foCountry.isEmpty()) {
        setCountry(foCountry);
    }

    // The fo:background-color attribute specifies the background color of a paragraph.
    const QString bgcolor(styleStack.property(KoXmlNS::fo, "background-color"));
    if (!bgcolor.isEmpty()) {
        QBrush brush = background();
        if (bgcolor == "transparent")
            brush.setStyle(Qt::NoBrush);
        else {
            if (brush.style() == Qt::NoBrush)
                brush.setStyle(Qt::SolidPattern);
            brush.setColor(bgcolor); // #rrggbb format
        }
        setBackground(brush);
    }

    // The style:use-window-font-color attribute specifies whether or not the window foreground color should be as used as the foreground color for a light background color and white for a dark background color.
    const QString useWindowFont(styleStack.property(KoXmlNS::style, "use-window-font-color"));
    if (!useWindowFont.isEmpty()) {
        setFontAutoColor(useWindowFont == "true");
    }

    const QString letterKerning(styleStack.property( KoXmlNS::style, "letter-kerning"));
    if (!letterKerning.isEmpty()) {
        setFontKerning(letterKerning == "true");
    }

    const QString letterSpacing(styleStack.property(KoXmlNS::fo, "letter-spacing"));
    if ((!letterSpacing.isEmpty()) && (letterSpacing != "normal")) {
        qreal space = KoUnit::parseValue(letterSpacing);
        setFontLetterSpacing(space);
    }

    const QString textOutline(styleStack.property(KoXmlNS::style, "text-outline"));
    if (!textOutline.isEmpty()) {
        if (textOutline == "true") {
            setTextOutline(QPen((foreground().style() != Qt::NoBrush)?foreground():QBrush(Qt::black) , 0));
            setForeground(Qt::transparent);
        } else {
            setTextOutline(QPen(Qt::NoPen));
        }
    }

    const QString textRotationAngle(styleStack.property(KoXmlNS::style, "text-rotation-angle"));
    if (!textRotationAngle.isEmpty()) {
        setTextRotationAngle(KoUnit::parseAngle(textRotationAngle));
    }

    const QString textRotationScale(styleStack.property(KoXmlNS::style, "text-rotation-scale"));
    if (!textRotationScale.isEmpty()) {
        setTextRotationScale(stringToRotationScale(textRotationScale));
    }

    const QString textScale(styleStack.property(KoXmlNS::style, "text-scale"));
    if (!textScale.isEmpty()) {
        const int scale = (textScale.endsWith('%') ? textScale.left(textScale.length()-1) : textScale).toInt();
        setTextScale(scale);
    }

    const QString textShadow(styleStack.property(KoXmlNS::fo, "text-shadow"));
    if (!textShadow.isEmpty()) {
        KoShadowStyle shadow;
        if (shadow.loadOdf(textShadow))
            setTextShadow(shadow);
    }

    const QString textCombine(styleStack.property(KoXmlNS::style, "text-combine"));
    if (!textCombine.isEmpty()) {
        if (textCombine == "letters")
            setTextCombine(TextCombineLetters);
        else if (textCombine == "lines")
            setTextCombine(TextCombineLines);
        else if (textCombine == "none")
            setTextCombine(NoTextCombine);
    }

    const QString textCombineEndChar(styleStack.property(KoXmlNS::style, "text-combine-end-char"));
    if (!textCombineEndChar.isEmpty()) {
        setTextCombineEndChar(textCombineEndChar.at(0));
    }
    const QString textCombineStartChar(styleStack.property(KoXmlNS::style, "text-combine-start-char"));
    if (!textCombineStartChar.isEmpty()) {
        setTextCombineStartChar(textCombineStartChar.at(0));
    }


    const QString fontRelief(styleStack.property(KoXmlNS::style, "font-relief"));
    if (!fontRelief.isEmpty()) {
        if (fontRelief == "none")
            setFontRelief(KoCharacterStyle::NoRelief);
        else if (fontRelief == "embossed")
            setFontRelief(KoCharacterStyle::Embossed);
        else if (fontRelief == "engraved")
            setFontRelief(KoCharacterStyle::Engraved);
    }

    const QString fontEmphasize(styleStack.property(KoXmlNS::style, "text-emphasize"));
    if (!fontEmphasize.isEmpty()) {
        QString style, position;
        QStringList parts = fontEmphasize.split(' ');
        style = parts[0];
        if (parts.length() > 1)
            position = parts[1];

        if (style == "none") {
            setTextEmphasizeStyle(NoEmphasis);
        } else if (style == "accent") {
            setTextEmphasizeStyle(AccentEmphasis);
        } else if (style == "circle") {
            setTextEmphasizeStyle(CircleEmphasis);
        } else if (style == "disc") {
            setTextEmphasizeStyle(DiscEmphasis);
        } else if (style == "dot") {
            setTextEmphasizeStyle(DotEmphasis);
        }

        if (position == "below") {
            setTextEmphasizePosition(EmphasisBelow);
        } else if (position == "above") {
            setTextEmphasizePosition(EmphasisAbove);
        }
    }

    if (styleStack.hasProperty(KoXmlNS::fo, "hyphenate"))
        setHasHyphenation(styleStack.property(KoXmlNS::fo, "hyphenate") == "true");

    if (styleStack.hasProperty(KoXmlNS::fo, "hyphenation-remain-char-count")) {
        bool ok = false;
        int count = styleStack.property(KoXmlNS::fo, "hyphenation-remain-char-count").toInt(&ok);
        if (ok)
            setHyphenationRemainCharCount(count);
    }
    if (styleStack.hasProperty(KoXmlNS::fo, "hyphenation-push-char-count")) {
        bool ok = false;
        int count = styleStack.property(KoXmlNS::fo, "hyphenation-push-char-count").toInt(&ok);
        if (ok)
            setHyphenationPushCharCount(count);
    }

    if (styleStack.hasProperty(KoXmlNS::style, "text-blinking")) {
        setBlinking(styleStack.property(KoXmlNS::style, "text-blinking") == "true");
    }


//TODO
#if 0
    /*
      Missing properties:
      style:font-style-name, 3.10.11 - can be ignored, says DV, the other ways to specify a font are more precise
      fo:letter-spacing, 3.10.16 - not implemented in kotext
      style:text-relief, 3.10.20 - not implemented in kotext
      style:text-blinking, 3.10.27 - not implemented in kotext IIRC
      style:text-combine, 3.10.29/30 - not implemented, see http://www.w3.org/TR/WD-i18n-format/
      style:text-emphasis, 3.10.31 - not implemented in kotext
      style:text-scale, 3.10.33 - not implemented in kotext
      style:text-rotation-angle, 3.10.34 - not implemented in kotext (kpr rotates whole objects)
      style:text-rotation-scale, 3.10.35 - not implemented in kotext (kpr rotates whole objects)
      style:punctuation-wrap, 3.10.36 - not implemented in kotext
    */

    d->m_underLineWidth = 1.0;

    generateKey();
    addRef();
#endif
}

bool KoCharacterStyle::operator==(const KoCharacterStyle &other) const
{
     return compareCharacterProperties(other);
}

bool KoCharacterStyle::operator!=(const KoCharacterStyle &other) const
{
     return !compareCharacterProperties(other);
}

bool KoCharacterStyle::compareCharacterProperties(const KoCharacterStyle &other) const
{
    return other.d->stylesPrivate == d->stylesPrivate;
}

void KoCharacterStyle::removeDuplicates(const KoCharacterStyle &other)
{
    // In case the current style doesn't have the flag UseWindowFontColor set but the other has it set and they use the same color
    // remove duplicates will remove the color. However to make it work correctly we need to store the color with the style so it
    // will be loaded again. We don't store a use-window-font-color="false" as that is not compatible to the way OO/LO does work.
    // So save the color and restore it after the remove duplicates
    QBrush brush;
    if (other.d->propertyBoolean(KoCharacterStyle::UseWindowFontColor) && !d->propertyBoolean(KoCharacterStyle::UseWindowFontColor)) {
        brush = foreground();
    }

    // this properties should need to be kept if there is a font family defined as these are only evaluated if there is also a font family
    int keepProperties[] = { QTextFormat::FontStyleHint, QTextFormat::FontFixedPitch, KoCharacterStyle::FontCharset };

    QMap<int, QVariant> keep;
    for (unsigned int i = 0; i < sizeof(keepProperties)/sizeof(*keepProperties); ++i) {
        if (hasProperty(keepProperties[i])) {
            keep.insert(keepProperties[i], value(keepProperties[i]));
        }
    }
    this->d->stylesPrivate.removeDuplicates(other.d->stylesPrivate);
    if (brush.style() != Qt::NoBrush) {
        setForeground(brush);
    }

    // in case the char style has any of the following properties it also needs to have the fontFamily as otherwise
    // these values will be ignored when loading according to the odf spec
    if (!hasProperty(QTextFormat::FontFamily)) {
        if (hasProperty(QTextFormat::FontStyleHint) || hasProperty(QTextFormat::FontFixedPitch) || hasProperty(KoCharacterStyle::FontCharset)) {
            QString fontFamily = other.fontFamily();
            if (!fontFamily.isEmpty()) {
                setFontFamily(fontFamily);
            }
        }
    }
    else {
        for (QMap<int, QVariant>::const_iterator it(keep.constBegin()); it != keep.constEnd(); ++it) {
            this->d->stylesPrivate.add(it.key(), it.value());
        }
    }
}

void KoCharacterStyle::removeDuplicates(const QTextCharFormat &otherFormat)
{
    KoCharacterStyle other(otherFormat);
    removeDuplicates(other);
}

void KoCharacterStyle::remove(int key)
{
    d->stylesPrivate.remove(key);
}

bool KoCharacterStyle::isEmpty() const
{
    return d->stylesPrivate.isEmpty();
}

void KoCharacterStyle::saveOdf(KoGenStyle &style) const
{
    if (!d->name.isEmpty() && !style.isDefaultStyle()) {
        style.addAttribute("style:display-name", d->name);
    }
    QList<int> keys = d->stylesPrivate.keys();
    Q_FOREACH (int key, keys) {
        if (key == QTextFormat::FontWeight) {
            bool ok = false;
            int boldness = d->stylesPrivate.value(key).toInt(&ok);
            if (ok) {
                if (boldness == QFont::Normal) {
                    style.addProperty("fo:font-weight", "normal", KoGenStyle::TextType);
                } else if (boldness == QFont::Bold) {
                    style.addProperty("fo:font-weight", "bold", KoGenStyle::TextType);
                } else {
                    // Remember : Qt and CSS/XSL doesn't have the same scale. Its 100-900 instead of Qts 0-100
                    style.addProperty("fo:font-weight", qBound(10, boldness, 90) * 10, KoGenStyle::TextType);
                }
            }
        } else if (key == QTextFormat::FontItalic) {
            if (d->stylesPrivate.value(key).toBool()) {
                style.addProperty("fo:font-style", "italic", KoGenStyle::TextType);
            } else {
                style.addProperty("fo:font-style", "normal", KoGenStyle::TextType);
            }
        } else if (key == QTextFormat::FontFamily) {
            QString fontFamily = d->stylesPrivate.value(key).toString();
            style.addProperty("fo:font-family", fontFamily, KoGenStyle::TextType);
        } else if (key == QTextFormat::FontFixedPitch) {
            bool fixedPitch = d->stylesPrivate.value(key).toBool();
            style.addProperty("style:font-pitch", fixedPitch ? "fixed" : "variable", KoGenStyle::TextType);
            // if this property is saved we also need to save the fo:font-family attribute as otherwise it will be ignored on loading as defined in the spec
            style.addProperty("fo:font-family", fontFamily(), KoGenStyle::TextType);
        } else if (key == QTextFormat::FontStyleHint) {
            bool ok = false;
            int styleHint = d->stylesPrivate.value(key).toInt(&ok);
            if (ok) {
                QString generic = exportOdfFontStyleHint((QFont::StyleHint) styleHint);
                if (!generic.isEmpty()) {
                    style.addProperty("style:font-family-generic", generic, KoGenStyle::TextType);
                }
                // if this property is saved we also need to save the fo:font-family attribute as otherwise it will be ignored on loading as defined in the spec
                style.addProperty("fo:font-family", fontFamily(), KoGenStyle::TextType);
            }
        } else if (key == QTextFormat::FontKerning) {
            style.addProperty("style:letter-kerning", fontKerning() ? "true" : "false", KoGenStyle::TextType);
        } else if (key == QTextFormat::FontCapitalization) {
            switch (fontCapitalization()) {
            case QFont::SmallCaps:
                style.addProperty("fo:font-variant", "small-caps", KoGenStyle::TextType);
                break;
            case QFont::MixedCase:
                style.addProperty("fo:font-variant", "normal", KoGenStyle::TextType);
                style.addProperty("fo:text-transform", "none", KoGenStyle::TextType);
                break;
            case QFont::AllUppercase:
                style.addProperty("fo:text-transform", "uppercase", KoGenStyle::TextType);
                break;
            case QFont::AllLowercase:
                style.addProperty("fo:text-transform", "lowercase", KoGenStyle::TextType);
                break;
            case QFont::Capitalize:
                style.addProperty("fo:text-transform", "capitalize", KoGenStyle::TextType);
                break;
            }
        } else if (key == OverlineStyle) {
            bool ok = false;
            int styleId = d->stylesPrivate.value(key).toInt(&ok);
            if (ok) {
                style.addProperty("style:text-overline-style", exportOdfLineStyle((KoCharacterStyle::LineStyle) styleId), KoGenStyle::TextType);
        }
        } else if (key == OverlineType) {
            bool ok = false;
            int type = d->stylesPrivate.value(key).toInt(&ok);
            if (ok) {
                style.addProperty("style:text-overline-type", exportOdfLineType((KoCharacterStyle::LineType) type), KoGenStyle::TextType);
        }
        } else if (key == OverlineColor) {
            QColor color = d->stylesPrivate.value(key).value<QColor>();
            if (color.isValid())
                style.addProperty("style:text-overline-color", color.name(), KoGenStyle::TextType);
            else
                style.addProperty("style:text-overline-color", "font-color", KoGenStyle::TextType);
        } else if (key == OverlineMode) {
            bool ok = false;
            int mode = d->stylesPrivate.value(key).toInt(&ok);
            if (ok) {
                style.addProperty("style:text-overline-mode", exportOdfLineMode((KoCharacterStyle::LineMode) mode), KoGenStyle::TextType);
        }
        } else if (key == OverlineWidth) {
            KoCharacterStyle::LineWeight weight;
            qreal width;
            overlineWidth(weight, width);
            style.addProperty("style:text-overline-width", exportOdfLineWidth(weight, width), KoGenStyle::TextType);
        } else if (key == UnderlineStyle) {
            bool ok = false;
            int styleId = d->stylesPrivate.value(key).toInt(&ok);
            if (ok)
                style.addProperty("style:text-underline-style", exportOdfLineStyle((KoCharacterStyle::LineStyle) styleId), KoGenStyle::TextType);
        } else if (key == UnderlineType) {
            bool ok = false;
            int type = d->stylesPrivate.value(key).toInt(&ok);
            if (ok)
                style.addProperty("style:text-underline-type", exportOdfLineType((KoCharacterStyle::LineType) type), KoGenStyle::TextType);
        } else if (key == QTextFormat::TextUnderlineColor) {
            QColor color = d->stylesPrivate.value(key).value<QColor>();
            if (color.isValid())
                style.addProperty("style:text-underline-color", color.name(), KoGenStyle::TextType);
            else
                style.addProperty("style:text-underline-color", "font-color", KoGenStyle::TextType);
        } else if (key == UnderlineMode) {
            bool ok = false;
            int mode = d->stylesPrivate.value(key).toInt(&ok);
            if (ok)
                style.addProperty("style:text-underline-mode", exportOdfLineMode((KoCharacterStyle::LineMode) mode), KoGenStyle::TextType);
        } else if (key == UnderlineWidth) {
            KoCharacterStyle::LineWeight weight;
            qreal width;
            underlineWidth(weight, width);
            style.addProperty("style:text-underline-width", exportOdfLineWidth(weight, width), KoGenStyle::TextType);
        } else if (key == StrikeOutStyle) {
            bool ok = false;
            int styleId = d->stylesPrivate.value(key).toInt(&ok);
            if (ok)
                style.addProperty("style:text-line-through-style", exportOdfLineStyle((KoCharacterStyle::LineStyle) styleId), KoGenStyle::TextType);
        } else if (key == StrikeOutType) {
            bool ok = false;
            int type = d->stylesPrivate.value(key).toInt(&ok);
            if (ok)
                style.addProperty("style:text-line-through-type", exportOdfLineType((KoCharacterStyle::LineType) type), KoGenStyle::TextType);
        } else if (key == StrikeOutText) {
            style.addProperty("style:text-line-through-text", d->stylesPrivate.value(key).toString(), KoGenStyle::TextType);
        } else if (key == StrikeOutColor) {
            QColor color = d->stylesPrivate.value(key).value<QColor>();
            if (color.isValid())
                style.addProperty("style:text-line-through-color", color.name(), KoGenStyle::TextType);
        } else if (key == StrikeOutMode) {
            bool ok = false;
            int mode = d->stylesPrivate.value(key).toInt(&ok);
            if (ok)
                style.addProperty("style:text-line-through-mode", exportOdfLineMode((KoCharacterStyle::LineMode) mode), KoGenStyle::TextType);
        } else if (key == StrikeOutWidth) {
            KoCharacterStyle::LineWeight weight;
            qreal width;
            strikeOutWidth(weight, width);
            style.addProperty("style:text-line-through-width", exportOdfLineWidth(weight, width), KoGenStyle::TextType);
        } else if (key == QTextFormat::BackgroundBrush) {
            QBrush brush = d->stylesPrivate.value(key).value<QBrush>();
            if (brush.style() == Qt::NoBrush)
                style.addProperty("fo:background-color", "transparent", KoGenStyle::TextType);
            else
                style.addProperty("fo:background-color", brush.color().name(), KoGenStyle::TextType);
        } else if (key == QTextFormat::ForegroundBrush) {
            QBrush brush = d->stylesPrivate.value(key).value<QBrush>();
            if (brush.style() != Qt::NoBrush) {
                style.addProperty("fo:color", brush.color().name(), KoGenStyle::TextType);
            }
        } else if (key == KoCharacterStyle::UseWindowFontColor) {
            bool use = d->stylesPrivate.value(key).toBool();
            style.addProperty("style:use-window-font-color", use ? "true" : "false", KoGenStyle::TextType);
        } else if (key == QTextFormat::TextVerticalAlignment) {
            if (verticalAlignment() == QTextCharFormat::AlignSuperScript)
                style.addProperty("style:text-position", "super", KoGenStyle::TextType);
            else if (verticalAlignment() == QTextCharFormat::AlignSubScript)
                style.addProperty("style:text-position", "sub", KoGenStyle::TextType);
            else if (d->stylesPrivate.contains(QTextFormat::TextVerticalAlignment)) // no superscript or subscript
                style.addProperty("style:text-position", "0% 100%", KoGenStyle::TextType);
        } else if (key == QTextFormat::FontPointSize) {
            // when there is percentageFontSize!=100% property ignore the fontSize property and store the percentage property
            if ( (!hasProperty(KoCharacterStyle::PercentageFontSize)) || (percentageFontSize()==100))
                style.addPropertyPt("fo:font-size", fontPointSize(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::PercentageFontSize) {
            if(percentageFontSize()!=100) {
                style.addProperty("fo:font-size", QString::number(percentageFontSize()) + '%', KoGenStyle::TextType);
            }
        } else if (key == KoCharacterStyle::Country) {
            style.addProperty("fo:country", d->stylesPrivate.value(KoCharacterStyle::Country).toString(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::Language) {
            style.addProperty("fo:language", d->stylesPrivate.value(KoCharacterStyle::Language).toString(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::FontLetterSpacing) {
            qreal space = fontLetterSpacing();
            style.addPropertyPt("fo:letter-spacing", space, KoGenStyle::TextType);
        } else if (key == QTextFormat::TextOutline) {
            QPen outline = textOutline();
            style.addProperty("style:text-outline", outline.style() == Qt::NoPen ? "false" : "true", KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::FontCharset) {
            style.addProperty("style:font-charset", d->stylesPrivate.value(KoCharacterStyle::FontCharset).toString(), KoGenStyle::TextType);
            // if this property is saved we also need to save the fo:font-family attribute as otherwise it will be ignored on loading as defined in the spec
            style.addProperty("fo:font-family", fontFamily(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::TextRotationAngle) {
            style.addProperty("style:text-rotation-angle", QString::number(textRotationAngle()), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::TextRotationScale) {
            RotationScale scale = textRotationScale();
            style.addProperty("style:text-rotation-scale", rotationScaleToString(scale), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::TextScale) {
            int scale = textScale();
            style.addProperty("style:text-scale", QString::number(scale) + '%', KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::TextShadow) {
            KoShadowStyle shadow = textShadow();
            style.addProperty("fo:text-shadow", shadow.saveOdf(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::TextCombine) {
            KoCharacterStyle::TextCombineType textCombineType = textCombine();
            switch (textCombineType)
            {
                case KoCharacterStyle::NoTextCombine:
                    style.addProperty("style:text-combine", "none", KoGenStyle::TextType);
                    break;
                case KoCharacterStyle::TextCombineLetters:
                    style.addProperty("style:text-combine", "letters", KoGenStyle::TextType);
                    break;
                case KoCharacterStyle::TextCombineLines:
                    style.addProperty("style:text-combine", "lines", KoGenStyle::TextType);
                    break;
            }
        } else if (key == KoCharacterStyle::TextCombineEndChar) {
            style.addProperty("style:text-combine-end-char", textCombineEndChar(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::TextCombineStartChar) {
            style.addProperty("style:text-combine-start-char", textCombineStartChar(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::FontRelief) {
            KoCharacterStyle::ReliefType relief = fontRelief();
            switch (relief)
            {
                case KoCharacterStyle::NoRelief:
                    style.addProperty("style:font-relief", "none", KoGenStyle::TextType);
                    break;
                case KoCharacterStyle::Embossed:
                    style.addProperty("style:font-relief", "embossed", KoGenStyle::TextType);
                    break;
                case KoCharacterStyle::Engraved:
                    style.addProperty("style:font-relief", "engraved", KoGenStyle::TextType);
                    break;
            }
        } else if (key == KoCharacterStyle::TextEmphasizeStyle) {
            KoCharacterStyle::EmphasisStyle emphasisStyle = textEmphasizeStyle();
            KoCharacterStyle::EmphasisPosition position = textEmphasizePosition();
            QString odfEmphasis;
            switch (emphasisStyle)
            {
                case KoCharacterStyle::NoEmphasis:
                    odfEmphasis = "none";
                    break;
                case KoCharacterStyle::AccentEmphasis:
                    odfEmphasis = "accent";
                    break;
                case KoCharacterStyle::CircleEmphasis:
                    odfEmphasis = "circle";
                    break;
                case KoCharacterStyle::DiscEmphasis:
                    odfEmphasis = "disc";
                    break;
                case KoCharacterStyle::DotEmphasis:
                    odfEmphasis = "dot";
                    break;
            }
            if (hasProperty(KoCharacterStyle::TextEmphasizePosition)) {
                if (position == KoCharacterStyle::EmphasisAbove)
                    odfEmphasis += " above";
                else
                    odfEmphasis += " below";
            }
            style.addProperty("style:text-emphasize", odfEmphasis, KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::HasHyphenation) {
            if (hasHyphenation())
                style.addProperty("fo:hyphenate", "true", KoGenStyle::TextType);
            else
                style.addProperty("fo:hyphenate", "false", KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::HyphenationPushCharCount) {
            style.addProperty("fo:hyphenation-push-char-count", hyphenationPushCharCount(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::HyphenationRemainCharCount) {
            style.addProperty("fo:hyphenation-remain-char-count", hyphenationRemainCharCount(), KoGenStyle::TextType);
        } else if (key == KoCharacterStyle::Blink) {
            style.addProperty("style:text-blinking", blinking(), KoGenStyle::TextType);
        }
    }
    //TODO: font name and family
}

QVariant KoCharacterStyle::value(int key) const
{
    QVariant variant = d->stylesPrivate.value(key);
    if (variant.isNull()) {
        if (d->parentStyle)
            variant = d->parentStyle->value(key);
        else if (d->defaultStyle)
            variant = d->defaultStyle->value(key);
    }
    return variant;
}

void KoCharacterStyle::removeHardCodedDefaults()
{
    d->hardCodedDefaultStyle.clearAll();
}