8#include <qdatastream.h>
11#include <qhashfunctions.h>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
41
42
43
44
47
48
49
50
53
54
55
56
57
58
61
62
63
64
65
66
67
70
71
72
73
74
75
76
79
80
81
82
83
86
87
88
89
90
93
94
95
96
97
98
99
100
101
102
103
104
107
108
109QTextLength::operator QVariant()
const
111 return QVariant::fromValue(*
this);
114#ifndef QT_NO_DATASTREAM
115QDataStream &operator<<(QDataStream &stream,
const QTextLength &length)
117 return stream << qint32(length.lengthType) <<
double(length.fixedValueOrPercentage);
120QDataStream &
operator>>(QDataStream &stream, QTextLength &length)
123 double fixedValueOrPercentage;
124 stream >> type >> fixedValueOrPercentage;
125 length.fixedValueOrPercentage = fixedValueOrPercentage;
126 length.lengthType = QTextLength::Type(type);
134 inline Property(qint32 k,
const QVariant &v) : key(k), value(v) {}
140 inline bool operator==(
const Property &other)
const
141 {
return key == other.key && value == other.value; }
159 if (hash() != rhs.hash())
162 return props == rhs.props;
168 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
171 for (
int i = 0; i < props.size(); ++i)
172 if (props.at(i).key == key) {
173 props[i].value = value;
176 props.append(Property(key, value));
181 for (
int i = 0; i < props.size(); ++i)
182 if (props.at(i).key == key) {
184 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
193 for (
int i = 0; i < props.size(); ++i)
194 if (props.at(i).key == key)
201 const int idx = propertyIndex(key);
204 return props.at(idx).value;
208 {
return propertyIndex(key) != -1; }
212 inline const QFont &
font()
const {
221 size_t recalcHash()
const;
222 void recalcFont()
const;
224 mutable bool hashDirty;
225 mutable bool fontDirty;
226 mutable size_t hashValue;
229 friend QDataStream &operator<<(QDataStream &,
const QTextFormat &);
230 friend QDataStream &
operator>>(QDataStream &, QTextFormat &);
235 return (color.isValid()) ? color.rgba() : 0x234109;
240 return hash(pen.color()) + qHash(pen.widthF());
245 return hash(brush.color()) + (brush.style() << 3);
251 switch (variant.userType()) {
252 case QMetaType::QString:
return qHash(variant.toString());
253 case QMetaType::Double:
return qHash(variant.toDouble());
254 case QMetaType::Int:
return 0x811890U + variant.toInt();
255 case QMetaType::QBrush:
256 return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
257 case QMetaType::Bool:
return 0x371818 + variant.toBool();
258 case QMetaType::QPen:
return 0x02020202 + hash(qvariant_cast<QPen>(variant));
259 case QMetaType::QVariantList:
260 return 0x8377U + qvariant_cast<QVariantList>(variant).size();
261 case QMetaType::QColor:
return hash(qvariant_cast<QColor>(variant));
262 case QMetaType::QTextLength:
263 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
264 case QMetaType::Float:
return qHash(variant.toFloat());
265 case QMetaType::UnknownType:
return 0;
268 return qHash(variant.typeName());
273 return (d ? d->hash() : 0) + format;
279 const auto end = props.constEnd();
280 for (
auto it = props.constBegin(); it != end; ++it)
281 hashValue += (
static_cast<quint32>(it->key) << 16) + variantHash(it->value);
291 const uint oldMask = fnt.resolveMask();
292 fnt = fnt.resolve(defaultFont);
294 if (hasProperty(QTextFormat::FontSizeAdjustment)) {
295 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
297 const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);
300 if (defaultFont.pointSize() <= 0) {
301 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
302 fnt.setPixelSize(qRound(pixelSize));
304 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
305 fnt.setPointSizeF(pointSize);
309 fnt.setResolveMask(oldMask);
317 bool hasSpacingInformation =
false;
318 QFont::SpacingType spacingType = QFont::PercentageSpacing;
319 qreal letterSpacing = 0.0;
321 for (
int i = 0; i < props.size(); ++i) {
322 switch (props.at(i).key) {
323 case QTextFormat::FontFamilies:
324 f.setFamilies(props.at(i).value.toStringList());
326 case QTextFormat::FontStyleName:
327 f.setStyleName(props.at(i).value.toString());
329 case QTextFormat::FontPointSize:
330 f.setPointSizeF(props.at(i).value.toReal());
332 case QTextFormat::FontPixelSize:
333 f.setPixelSize(props.at(i).value.toInt());
335 case QTextFormat::FontWeight: {
336 const QVariant weightValue = props.at(i).value;
337 int weight = weightValue.toInt();
338 if (weight >= 0 && weightValue.isValid())
339 f.setWeight(QFont::Weight(weight));
341 case QTextFormat::FontItalic:
342 f.setItalic(props.at(i).value.toBool());
344 case QTextFormat::FontUnderline:
345 if (! hasProperty(QTextFormat::TextUnderlineStyle))
346 f.setUnderline(props.at(i).value.toBool());
348 case QTextFormat::TextUnderlineStyle:
349 f.setUnderline(
static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
351 case QTextFormat::FontOverline:
352 f.setOverline(props.at(i).value.toBool());
354 case QTextFormat::FontStrikeOut:
355 f.setStrikeOut(props.at(i).value.toBool());
357 case QTextFormat::FontLetterSpacingType:
358 spacingType =
static_cast<QFont::SpacingType>(props.at(i).value.toInt());
359 hasSpacingInformation =
true;
361 case QTextFormat::FontLetterSpacing:
362 letterSpacing = props.at(i).value.toReal();
363 hasSpacingInformation =
true;
365 case QTextFormat::FontWordSpacing:
366 f.setWordSpacing(props.at(i).value.toReal());
368 case QTextFormat::FontCapitalization:
369 f.setCapitalization(
static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
371 case QTextFormat::FontFixedPitch: {
372 const bool value = props.at(i).value.toBool();
373 if (f.fixedPitch() != value)
374 f.setFixedPitch(value);
376 case QTextFormat::FontStretch:
377 f.setStretch(props.at(i).value.toInt());
379 case QTextFormat::FontStyleHint:
380 f.setStyleHint(
static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
382 case QTextFormat::FontHintingPreference:
383 f.setHintingPreference(
static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
385 case QTextFormat::FontStyleStrategy:
386 f.setStyleStrategy(
static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
388 case QTextFormat::FontKerning:
389 f.setKerning(props.at(i).value.toBool());
396 if (hasSpacingInformation)
397 f.setLetterSpacing(spacingType, letterSpacing);
403#ifndef QT_NO_DATASTREAM
404Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextFormat &fmt)
406 QMap<
int, QVariant> properties = fmt.properties();
407 if (stream.version() < QDataStream::Qt_6_0) {
408 auto it = properties.constFind(QTextFormat::FontLetterSpacingType);
409 if (it != properties.cend()) {
410 properties[QTextFormat::OldFontLetterSpacingType] = it.value();
411 properties.erase(it);
414 it = properties.constFind(QTextFormat::FontStretch);
415 if (it != properties.cend()) {
416 properties[QTextFormat::OldFontStretch] = it.value();
417 properties.erase(it);
420 it = properties.constFind(QTextFormat::TextUnderlineColor);
421 if (it != properties.cend()) {
422 properties[QTextFormat::OldTextUnderlineColor] = it.value();
423 properties.erase(it);
426 it = properties.constFind(QTextFormat::FontFamilies);
427 if (it != properties.cend()) {
428 properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().constFirst());
429 properties.erase(it);
433 stream << fmt.format_type << properties;
437Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
439 QMap<qint32, QVariant> properties;
440 stream >> fmt.format_type >> properties;
445 fmt.d =
new QTextFormatPrivate();
447 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();
448 it != properties.constEnd(); ++it) {
449 qint32 key = it.key();
450 if (key == QTextFormat::OldFontLetterSpacingType)
451 key = QTextFormat::FontLetterSpacingType;
452 else if (key == QTextFormat::OldFontStretch)
453 key = QTextFormat::FontStretch;
454 else if (key == QTextFormat::OldTextUnderlineColor)
455 key = QTextFormat::TextUnderlineColor;
456 else if (key == QTextFormat::OldFontFamily)
457 key = QTextFormat::FontFamilies;
458 fmt.d->insertProperty(key, it.value());
464Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextCharFormat &fmt)
466 return stream <<
static_cast<
const QTextFormat &>(fmt);
469Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextCharFormat &fmt)
471 return stream >>
static_cast<QTextFormat &>(fmt);
474Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextBlockFormat &fmt)
476 return stream <<
static_cast<
const QTextFormat &>(fmt);
479Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextBlockFormat &fmt)
481 return stream >>
static_cast<QTextFormat &>(fmt);
484Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextListFormat &fmt)
486 return stream <<
static_cast<
const QTextFormat &>(fmt);
489Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextListFormat &fmt)
491 return stream >>
static_cast<QTextFormat &>(fmt);
494Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextFrameFormat &fmt)
496 return stream <<
static_cast<
const QTextFormat &>(fmt);
499Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextFrameFormat &fmt)
501 return stream >>
static_cast<QTextFormat &>(fmt);
504Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextTableCellFormat &fmt)
506 return stream <<
static_cast<
const QTextFormat &>(fmt);
509Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextTableCellFormat &fmt)
511 return stream >>
static_cast<QTextFormat &>(fmt);
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
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
767
768
769
770
771
772
773
774
775
776
777
778
781
782
783
784
785
786
787
788
789
790
791
792
793
794
797
798
799
800
801
804
805
806
807
808
809
810
813
814
815
816
817
821
822
823
824
825
829
830
831
832
833
837
838
839
840
841
845
846
847
848
849
853
854
855
856
857
861
862
863
864
865
866
870
871
872
873
874QTextFormat::QTextFormat()
875 : format_type(InvalidFormat)
880
881
882
883
884QTextFormat::QTextFormat(
int type)
891
892
893
894
895
896QTextFormat::QTextFormat(
const QTextFormat &rhs)
897 : d(rhs.d), format_type(rhs.format_type)
902
903
904
905
906
907QTextFormat &QTextFormat::operator=(
const QTextFormat &rhs)
910 format_type = rhs.format_type;
915
916
917
918
921
922
923QTextFormat::~QTextFormat()
929
930
931QTextFormat::operator QVariant()
const
933 return QVariant::fromValue(*
this);
937
938
939
940void QTextFormat::merge(
const QTextFormat &other)
942 if (format_type != other.format_type)
953 QTextFormatPrivate *p = d.data();
955 const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props;
956 p->props.reserve(p->props.size() + otherProps.size());
957 for (
int i = 0; i < otherProps.size(); ++i) {
958 const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i);
959 if (prop.value.isValid()) {
960 p->insertProperty(prop.key, prop.value);
962 p->clearProperty(prop.key);
968
969
970
971
972int QTextFormat::type()
const
978
979
980QTextBlockFormat QTextFormat::toBlockFormat()
const
982 return QTextBlockFormat(*
this);
986
987
988QTextCharFormat QTextFormat::toCharFormat()
const
990 return QTextCharFormat(*
this);
994
995
996QTextListFormat QTextFormat::toListFormat()
const
998 return QTextListFormat(*
this);
1002
1003
1004QTextTableFormat QTextFormat::toTableFormat()
const
1006 return QTextTableFormat(*
this);
1010
1011
1012QTextFrameFormat QTextFormat::toFrameFormat()
const
1014 return QTextFrameFormat(*
this);
1018
1019
1020QTextImageFormat QTextFormat::toImageFormat()
const
1022 return QTextImageFormat(*
this);
1026
1027
1028
1029
1030QTextTableCellFormat QTextFormat::toTableCellFormat()
const
1032 return QTextTableCellFormat(*
this);
1036
1037
1038
1039
1040
1041
1042bool QTextFormat::boolProperty(
int propertyId)
const
1046 const QVariant prop = d->property(propertyId);
1047 if (prop.userType() != QMetaType::Bool)
1049 return prop.toBool();
1053
1054
1055
1056
1057
1058
1059int QTextFormat::intProperty(
int propertyId)
const
1062 int def = (propertyId == QTextFormat::LayoutDirection) ?
int(Qt::LayoutDirectionAuto) : 0;
1066 const QVariant prop = d->property(propertyId);
1067 if (prop.userType() != QMetaType::Int)
1069 return prop.toInt();
1073
1074
1075
1076
1077
1078
1079
1080qreal QTextFormat::doubleProperty(
int propertyId)
const
1084 const QVariant prop = d->property(propertyId);
1085 if (prop.userType() != QMetaType::Double && prop.userType() != QMetaType::Float)
1087 return qvariant_cast<qreal>(prop);
1091
1092
1093
1094
1095
1096
1097
1098QString QTextFormat::stringProperty(
int propertyId)
const
1102 const QVariant prop = d->property(propertyId);
1103 if (prop.userType() != QMetaType::QString)
1105 return prop.toString();
1109
1110
1111
1112
1113
1114
1115
1116QColor QTextFormat::colorProperty(
int propertyId)
const
1120 const QVariant prop = d->property(propertyId);
1121 if (prop.userType() != QMetaType::QColor)
1123 return qvariant_cast<QColor>(prop);
1127
1128
1129
1130
1131
1132
1133
1134QPen QTextFormat::penProperty(
int propertyId)
const
1137 return QPen(Qt::NoPen);
1138 const QVariant prop = d->property(propertyId);
1139 if (prop.userType() != QMetaType::QPen)
1140 return QPen(Qt::NoPen);
1141 return qvariant_cast<QPen>(prop);
1145
1146
1147
1148
1149
1150
1151
1152QBrush QTextFormat::brushProperty(
int propertyId)
const
1155 return QBrush(Qt::NoBrush);
1156 const QVariant prop = d->property(propertyId);
1157 if (prop.userType() != QMetaType::QBrush)
1158 return QBrush(Qt::NoBrush);
1159 return qvariant_cast<QBrush>(prop);
1163
1164
1165
1166
1167
1168QTextLength QTextFormat::lengthProperty(
int propertyId)
const
1171 return QTextLength();
1172 return qvariant_cast<QTextLength>(d->property(propertyId));
1176
1177
1178
1179
1180
1181
1182
1183QList<QTextLength> QTextFormat::lengthVectorProperty(
int propertyId)
const
1185 QList<QTextLength> list;
1188 const QVariant prop = d->property(propertyId);
1189 if (prop.userType() != QMetaType::QVariantList)
1192 const QList<QVariant> propertyList = prop.toList();
1193 for (
const auto &var : propertyList) {
1194 if (var.userType() == QMetaType::QTextLength)
1195 list.append(qvariant_cast<QTextLength>(var));
1202
1203
1204
1205
1206QVariant QTextFormat::property(
int propertyId)
const
1208 return d ? d->property(propertyId) : QVariant();
1212
1213
1214
1215
1216void QTextFormat::setProperty(
int propertyId,
const QVariant &value)
1219 d =
new QTextFormatPrivate;
1221 d->insertProperty(propertyId, value);
1225
1226
1227
1228
1229void QTextFormat::setProperty(
int propertyId,
const QList<QTextLength> &value)
1232 d =
new QTextFormatPrivate;
1234 const int numValues = value.size();
1235 list.reserve(numValues);
1236 for (
int i = 0; i < numValues; ++i)
1237 list << value.at(i);
1238 d->insertProperty(propertyId, list);
1242
1243
1244
1245
1246void QTextFormat::clearProperty(
int propertyId)
1250 d->clearProperty(propertyId);
1255
1256
1257
1258
1259
1260
1264
1265
1266
1267
1268
1269
1273
1274
1275
1276
1277int QTextFormat::objectIndex()
const
1281 const QVariant prop = d->property(ObjectIndex);
1282 if (prop.userType() != QMetaType::Int)
1284 return prop.toInt();
1288
1289
1290
1291
1292
1293
1294void QTextFormat::setObjectIndex(
int o)
1298 d->clearProperty(ObjectIndex);
1301 d =
new QTextFormatPrivate;
1303 d->insertProperty(ObjectIndex, o);
1308
1309
1310
1311
1312
1313bool QTextFormat::hasProperty(
int propertyId)
const
1315 return d ? d->hasProperty(propertyId) :
false;
1319
1320
1321
1322
1325
1326
1327QMap<
int, QVariant> QTextFormat::properties()
const
1329 QMap<
int, QVariant> map;
1331 for (
int i = 0; i < d->props.size(); ++i)
1332 map.insert(d->props.at(i).key, d->props.at(i).value);
1338
1339
1340
1341int QTextFormat::propertyCount()
const
1343 return d ? d->props.size() : 0;
1347
1348
1349
1350
1351
1355
1356
1357
1358
1359
1360bool QTextFormat::operator==(
const QTextFormat &rhs)
const
1362 if (format_type != rhs.format_type)
1368 if (d && d->props.isEmpty() && !rhs.d)
1371 if (!d && rhs.d && rhs.d->props.isEmpty())
1377 return *d == *rhs.d;
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
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1452
1453
1454
1455
1456QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}
1459
1460
1461
1462
1463
1464
1465QTextCharFormat::QTextCharFormat(
const QTextFormat &fmt)
1471
1472
1473
1474
1475
1479
1480
1481
1482
1483
1484
1485
1489
1490
1491
1492
1493
1494
1495
1498
1499
1500
1501
1502
1503
1504
1506#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1521
1522
1523
1524
1525
1526
1527
1531
1532
1533
1534
1535
1536
1537
1539#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1554
1555
1556
1557
1558
1559
1560
1564
1565
1566
1567
1568
1569
1573
1574
1575
1576
1577
1578
1582
1583
1584
1585
1586
1587
1591
1592
1593
1594
1595
1596
1600
1601
1602
1603
1604
1605
1606
1610
1611
1612
1613
1614
1615
1616
1620
1621
1622
1623
1624
1625
1626
1630
1631
1632
1633
1634
1635
1636
1637bool QTextCharFormat::fontUnderline()
const
1639 if (hasProperty(TextUnderlineStyle))
1640 return underlineStyle() == SingleUnderline;
1641 return boolProperty(FontUnderline);
1645
1646
1647
1648
1649
1652
1653
1654
1655
1656
1657void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1659 setProperty(TextUnderlineStyle, style);
1661 setProperty(FontUnderline, style == SingleUnderline);
1665
1666
1667
1668
1669
1670
1671
1675
1676
1677
1678
1679
1680
1681
1685
1686
1687
1688
1689
1690
1691
1692
1696
1697
1698
1699
1700
1701
1702
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1719
1720
1721
1722
1723
1724
1725
1726
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1743
1744
1745
1746
1747
1748
1749
1753
1754
1755
1756
1757
1758
1759
1760
1764
1765
1766
1767
1768
1769
1770
1774
1775
1776
1777
1778
1779
1780
1784
1785
1786
1787
1788
1789
1790
1793
1794
1795
1796
1797
1798
1799
1800
1803
1804
1805
1806
1807
1808
1809
1810
1813
1814
1815
1816
1820
1821
1822
1823
1826
1827
1828
1829
1830
1833
1834
1835
1836
1837
1840
1841
1842
1843
1844
1845
1846
1850
1851
1852
1853
1854
1855
1856
1859
1860
1861
1862
1863
1864
1865
1868
1869
1870
1871
1872
1873
1874
1875
1878
1879
1880
1881
1882
1883
1884
1887
1888
1889
1890
1891
1892
1893
1894
1897
1898
1899
1900
1901
1902
1903
1906
1907
1908
1909
1910
1911
1912
1913
1916
1917
1918
1919
1920
1921
1922
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1941
1942
1943
1944
1945
1946
1947
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1964
1965
1966
1967
1968
1971
1972
1973
1974
1975
1976
1977
1980
1981
1982
1983
1984
1985
1986
1987QStringList QTextCharFormat::anchorNames()
const
1989 QVariant prop = property(AnchorName);
1990 if (prop.userType() == QMetaType::QStringList)
1991 return prop.toStringList();
1992 else if (prop.userType() != QMetaType::QString)
1993 return QStringList();
1994 return QStringList(prop.toString());
1999
2000
2001
2002
2003
2004
2008
2009
2010
2011
2012
2013
2014
2017
2018
2019
2020
2021
2022
2026
2027
2028
2029
2030
2031
2032
2035
2036
2037
2038
2039
2040
2041
2044
2045
2046
2047
2048
2049
2050
2053
2054
2055
2056
2057
2058
2059
2062
2063
2064
2065
2066
2067
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097void QTextCharFormat::setFont(
const QFont &font, FontPropertiesInheritanceBehavior behavior)
2099 const uint mask = behavior == FontPropertiesAll ? uint(QFont::AllPropertiesResolved)
2100 : font.resolveMask();
2102 if (mask & QFont::FamiliesResolved)
2103 setFontFamilies(font.families());
2104 if (mask & QFont::StyleNameResolved)
2105 setFontStyleName(font.styleName());
2107 if (mask & QFont::SizeResolved) {
2108 const qreal pointSize = font.pointSizeF();
2109 if (pointSize > 0) {
2110 setFontPointSize(pointSize);
2112 const int pixelSize = font.pixelSize();
2114 setProperty(QTextFormat::FontPixelSize, pixelSize);
2118 if (mask & QFont::WeightResolved)
2119 setFontWeight(font.weight());
2120 if (mask & QFont::StyleResolved)
2121 setFontItalic(font.style() != QFont::StyleNormal);
2122 if (mask & QFont::UnderlineResolved)
2123 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
2124 if (mask & QFont::OverlineResolved)
2125 setFontOverline(font.overline());
2126 if (mask & QFont::StrikeOutResolved)
2127 setFontStrikeOut(font.strikeOut());
2128 if (mask & QFont::FixedPitchResolved)
2129 setFontFixedPitch(font.fixedPitch());
2130 if (mask & QFont::CapitalizationResolved)
2131 setFontCapitalization(font.capitalization());
2132 if (mask & QFont::WordSpacingResolved)
2133 setFontWordSpacing(font.wordSpacing());
2134 if (mask & QFont::LetterSpacingResolved) {
2135 setFontLetterSpacingType(font.letterSpacingType());
2136 setFontLetterSpacing(font.letterSpacing());
2138 if (mask & QFont::StretchResolved)
2139 setFontStretch(font.stretch());
2140 if (mask & QFont::StyleHintResolved)
2141 setFontStyleHint(font.styleHint());
2142 if (mask & QFont::StyleStrategyResolved)
2143 setFontStyleStrategy(font.styleStrategy());
2144 if (mask & QFont::HintingPreferenceResolved)
2145 setFontHintingPreference(font.hintingPreference());
2146 if (mask & QFont::KerningResolved)
2147 setFontKerning(font.kerning());
2151
2152
2153QFont QTextCharFormat::font()
const
2155 return d ? d->font() : QFont();
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
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2217
2218
2219
2220
2221QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}
2224
2225
2226
2227
2228
2229
2230QTextBlockFormat::QTextBlockFormat(
const QTextFormat &fmt)
2236
2237
2238
2239
2240
2241
2242void QTextBlockFormat::setTabPositions(
const QList<QTextOption::Tab> &tabs)
2244 QList<QVariant> list;
2245 list.reserve(tabs.size());
2246 for (
const auto &e : tabs)
2247 list.append(QVariant::fromValue(e));
2248 setProperty(TabPositions, list);
2252
2253
2254
2255
2256
2257QList<QTextOption::Tab> QTextBlockFormat::tabPositions()
const
2259 QVariant variant = property(TabPositions);
2260 if (variant.isNull())
2261 return QList<QTextOption::Tab>();
2262 QList<QTextOption::Tab> answer;
2263 const QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
2264 answer.reserve(variantsList.size());
2265 for (
const auto &e: variantsList)
2266 answer.append(qvariant_cast<QTextOption::Tab>(e));
2271
2272
2273
2274
2275
2278
2279
2280
2281
2282
2283
2287
2288
2289
2290
2291
2292
2296
2297
2298
2299
2300
2301
2305
2306
2307
2308
2309
2310
2314
2315
2316
2317
2318
2319
2323
2324
2325
2326
2327
2328
2332
2333
2334
2335
2336
2337
2341
2342
2343
2344
2345
2346
2350
2351
2352
2353
2354
2355
2356
2360
2361
2362
2363
2364
2365
2369
2370
2371
2372
2373
2374
2378
2379
2380
2381
2382
2383
2387
2388
2389
2390
2391
2392
2393
2394
2398
2399
2400
2401
2402
2403
2407
2408
2409
2410
2411
2412
2413
2414
2415
2419
2420
2421
2422
2423
2424
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2446
2447
2448
2449
2450
2451
2452
2456
2457
2458
2459
2460
2461
2462
2463
2464
2468
2469
2470
2471
2472
2473
2474
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2500
2501
2502
2503
2504
2505
2506
2507
2508
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2531
2532
2533
2534
2535
2536
2537
2541
2542
2543
2544
2545
2546
2547
2551
2552
2553
2554
2555
2556
2557
2561
2562
2563
2564
2565
2566
2567
2570
2571
2572
2573
2574
2575
2576
2577
2580
2581
2582
2583
2584
2585
2586
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2640
2641
2642
2643
2644QTextListFormat::QTextListFormat()
2645 : QTextFormat(ListFormat)
2652
2653
2654
2655
2656
2657
2658QTextListFormat::QTextListFormat(
const QTextFormat &fmt)
2664
2665
2666
2667
2668
2671
2672
2673
2674
2675
2676
2679
2680
2681
2682
2683
2684
2688
2689
2690
2691
2692
2693
2694
2695
2699
2700
2701
2702
2703
2704
2705
2706
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2722
2723
2724
2725
2726
2727
2728
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2744
2745
2746
2747
2748
2749
2750
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2769
2770
2771
2772
2773
2774
2775
2776
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2847
2848
2849
2850
2851QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)
2853 setBorderStyle(BorderStyle_Outset);
2854 setBorderBrush(Qt::darkGray);
2858
2859
2860
2861
2862
2863
2864QTextFrameFormat::QTextFrameFormat(
const QTextFormat &fmt)
2870
2871
2872
2873
2876
2877
2878
2879
2880
2883
2884
2885
2886
2889
2890
2891
2892
2895
2896
2897
2898
2901
2902
2903
2904
2905
2908
2909
2910
2911
2912
2915
2916
2917
2918
2919
2922
2923
2924
2925
2926
2929
2930
2931
2932
2933
2934
2935
2936void QTextFrameFormat::setMargin(qreal amargin)
2938 setProperty(FrameMargin, amargin);
2939 setProperty(FrameTopMargin, amargin);
2940 setProperty(FrameBottomMargin, amargin);
2941 setProperty(FrameLeftMargin, amargin);
2942 setProperty(FrameRightMargin, amargin);
2947
2948
2949
2950
2953
2954
2955
2956
2957
2960
2961
2962
2963
2964
2965qreal QTextFrameFormat::topMargin()
const
2967 if (!hasProperty(FrameTopMargin))
2969 return doubleProperty(FrameTopMargin);
2973
2974
2975
2976
2977
2980
2981
2982
2983
2984
2985qreal QTextFrameFormat::bottomMargin()
const
2987 if (!hasProperty(FrameBottomMargin))
2989 return doubleProperty(FrameBottomMargin);
2993
2994
2995
2996
2997
3000
3001
3002
3003
3004
3005qreal QTextFrameFormat::leftMargin()
const
3007 if (!hasProperty(FrameLeftMargin))
3009 return doubleProperty(FrameLeftMargin);
3013
3014
3015
3016
3017
3020
3021
3022
3023
3024
3025qreal QTextFrameFormat::rightMargin()
const
3027 if (!hasProperty(FrameRightMargin))
3029 return doubleProperty(FrameRightMargin);
3033
3034
3035
3036
3039
3040
3041
3042
3045
3046
3047
3048
3049
3050
3053
3054
3055
3056
3057
3058
3061
3062
3063
3064
3065
3066
3067
3068
3071
3072
3073
3074
3075
3076
3077
3080
3081
3082
3083
3084
3085
3088
3089
3090
3091
3094
3095
3096
3097
3098
3101
3102
3103
3104
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3152
3153
3154
3155
3156QTextTableFormat::QTextTableFormat()
3157 : QTextFrameFormat()
3159 setObjectType(TableObject);
3161 setBorderCollapse(
true);
3166
3167
3168
3169
3170
3171
3172QTextTableFormat::QTextTableFormat(
const QTextFormat &fmt)
3173 : QTextFrameFormat(fmt)
3178
3179
3180
3181
3182
3186
3187
3188
3189
3193
3194
3195
3196
3197
3198
3199
3202
3203
3204
3205
3206
3207
3210
3211
3212
3213
3214
3215
3218
3219
3220
3221
3222
3223
3224
3227
3228
3229
3230
3231
3234
3235
3236
3237
3238
3239
3240
3243
3244
3245
3246
3247
3250
3251
3252
3253
3254
3257
3258
3259
3260
3261
3262
3265
3266
3267
3268
3269
3270
3273
3274
3275
3276
3277
3278
3279
3282
3283
3284
3285
3286
3287
3288
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3322
3323
3324
3325
3326
3327
3328
3331
3332
3333
3334
3335
3336
3337
3340
3341
3342
3343
3344
3345
3348
3349
3350
3351
3352
3353
3354
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3383
3384
3385
3386
3387QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }
3390
3391
3392
3393
3394
3395
3396QTextImageFormat::QTextImageFormat(
const QTextFormat &fmt)
3397 : QTextCharFormat(fmt)
3402
3403
3404
3405
3409
3410
3411
3412
3413
3414
3415
3419
3420
3421
3422
3423
3424
3425
3428
3429
3430
3431
3432
3433
3437
3438
3439
3440
3441
3442
3445
3446
3447
3448
3449
3450
3451
3455
3456
3457
3458
3459
3460
3464
3465
3466
3467
3468
3469
3473
3474
3475
3476
3477
3478
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3494
3495
3496
3497
3498
3499
3500
3503
3504
3505
3506
3507
3508
3509
3510
3511
3514
3515
3516
3517
3518
3521
3522
3523
3524
3525
3526
3527
3528
3529
3532
3533
3534
3535
3536
3537
3538
3539
3540
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3558
3559
3560
3561
3562
3563
3564
3565
3566
3569
3570
3571
3572
3573
3574
3575
3578
3579
3580
3581
3582
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3598
3599
3600
3601
3602
3603
3606
3607
3608
3609
3610
3611
3612
3615
3616
3617
3618
3619
3620
3621
3624
3625
3626
3627
3628
3629
3630
3633
3634
3635
3636
3637
3638
3639
3642
3643
3644
3645
3646
3647
3648
3651
3652
3653
3654
3655
3656
3657
3660
3661
3662
3663
3664
3665
3666
3669
3670
3671
3672
3673
3674
3675
3678
3679
3680
3681
3682
3683
3684
3687
3688
3689
3690
3691
3692
3693
3696
3697
3698
3699
3700
3703
3704
3705
3706
3707
3708
3709
3712
3713
3714
3715
3716
3719
3720
3721
3722
3723
3724
3725
3728
3729
3730
3731
3732
3735
3736
3737
3738
3739
3740
3741
3744
3745
3746
3747
3748
3751
3752
3753
3754
3755
3756
3757
3758
3761
3762
3763
3764
3765
3766
3767
3770
3771
3772
3773
3774
3777
3778
3779
3780
3781
3782
3783
3786
3787
3788
3789
3790
3793
3794
3795
3796
3797
3798
3799
3802
3803
3804
3805
3806
3809
3810
3811
3812
3813
3814
3815
3818
3819
3820
3821
3822
3825
3826
3827
3828
3829
3830
3831
3832
3835
3836
3837
3838
3839
3840
3841
3844
3845
3846
3847
3848
3851
3852
3853
3854
3855
3856
3857
3860
3861
3862
3863
3864
3867
3868
3869
3870
3871
3872
3873
3876
3877
3878
3879
3880
3883
3884
3885
3886
3887
3888
3889
3892
3893
3894
3895
3896
3899
3900
3901
3902
3903
3904
3905
3906
3909
3910
3911
3912
3913
3916
3917
3918
3919
3920
3921QTextTableCellFormat::QTextTableCellFormat()
3924 setObjectType(TableCellObject);
3928
3929
3930
3931
3932
3933
3934QTextTableCellFormat::QTextTableCellFormat(
const QTextFormat &fmt)
3935 : QTextCharFormat(fmt)
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3963QTextFormatCollection::~QTextFormatCollection()
3967void QTextFormatCollection::clear()
3974int QTextFormatCollection::indexForFormat(
const QTextFormat &format)
3976 size_t hash = getHash(format.d, format.format_type);
3977 auto i = hashes.constFind(hash);
3978 while (i != hashes.constEnd() && i.key() == hash) {
3979 if (formats.value(i.value()) == format) {
3985 int idx = formats.size();
3986 formats.append(format);
3989 QTextFormat &f = formats.last();
3991 f.d =
new QTextFormatPrivate;
3992 f.d->resolveFont(defaultFnt);
3994 hashes.insert(hash, idx);
4003bool QTextFormatCollection::hasFormatCached(
const QTextFormat &format)
const
4005 size_t hash = getHash(format.d, format.format_type);
4006 auto i = hashes.constFind(hash);
4007 while (i != hashes.constEnd() && i.key() == hash) {
4008 if (formats.value(i.value()) == format) {
4016int QTextFormatCollection::objectFormatIndex(
int objectIndex)
const
4018 if (objectIndex == -1 || objectIndex >= objFormats.size())
4020 return objFormats.at(objectIndex);
4023void QTextFormatCollection::setObjectFormatIndex(
int objectIndex,
int formatIndex)
4025 objFormats[objectIndex] = formatIndex;
4028int QTextFormatCollection::createObjectIndex(
const QTextFormat &f)
4030 const int objectIndex = objFormats.size();
4031 objFormats.append(indexForFormat(f));
4035QTextFormat QTextFormatCollection::format(
int idx)
const
4037 if (idx < 0 || idx >= formats.size())
4038 return QTextFormat();
4040 return formats.at(idx);
4043void QTextFormatCollection::setDefaultFont(
const QFont &f)
4046 for (
int i = 0; i < formats.size(); ++i)
4047 if (formats.at(i).d)
4048 formats[i].d->resolveFont(defaultFnt);
4051#ifndef QT_NO_DEBUG_STREAM
4054 QDebugStateSaver saver(dbg);
4055 dbg.nospace() <<
"QTextLength(QTextLength::Type(" << l.type() <<
"))";
4061 QDebugStateSaver saver(dbg);
4062 dbg.nospace() <<
"QTextFormat(QTextFormat::FormatType(" << f.type() <<
"))";
4070#include "moc_qtextformat.cpp"
\inmodule QtCore\reentrant
const QFont & font() const
friend QDataStream & operator>>(QDataStream &, QTextFormat &)
bool hasProperty(qint32 key) const
bool operator==(const QTextFormatPrivate &rhs) const
void resolveFont(const QFont &defaultFont)
void insertProperty(qint32 key, const QVariant &value)
QVariant property(qint32 key) const
int propertyIndex(qint32 key) const
void clearProperty(qint32 key)
static size_t hash(const QColor &color)
QDataStream & operator>>(QDataStream &stream, QTextLength &length)
QDebug operator<<(QDebug dbg, const QTextLength &l)
Q_DECLARE_TYPEINFO(Property, Q_RELOCATABLE_TYPE)
QDebug operator<<(QDebug dbg, const QTextFormat &f)
static size_t getHash(const QTextFormatPrivate *d, int format)
static size_t variantHash(const QVariant &variant)