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());
391 case QTextFormat::FontFeatures:
393 const auto fontFeatures = props.at(i).value.value<QHash<QFont::Tag, quint32>>();
394 for (
auto it = fontFeatures.constBegin(); it != fontFeatures.constEnd(); ++it)
395 f.setFeature(it.key(), it.value());
398 case QTextFormat::FontVariableAxes:
400 const auto fontVariableAxes = props.at(i).value.value<QHash<QFont::Tag,
float>>();
401 for (
auto it = fontVariableAxes.constBegin(); it != fontVariableAxes.constEnd(); ++it)
402 f.setVariableAxis(it.key(), it.value());
410 if (hasSpacingInformation)
411 f.setLetterSpacing(spacingType, letterSpacing);
417#ifndef QT_NO_DATASTREAM
418Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextFormat &fmt)
420 QMap<
int, QVariant> properties = fmt.properties();
421 if (stream.version() < QDataStream::Qt_6_11) {
422 auto it = properties.constFind(QTextFormat::FontFeatures);
423 if (it != properties.cend())
424 properties.erase(it);
426 it = properties.constFind(QTextFormat::FontVariableAxes);
427 if (it != properties.cend())
428 properties.erase(it);
431 if (stream.version() < QDataStream::Qt_6_0) {
432 auto it = properties.constFind(QTextFormat::FontLetterSpacingType);
433 if (it != properties.cend()) {
434 properties[QTextFormat::OldFontLetterSpacingType] = it.value();
435 properties.erase(it);
438 it = properties.constFind(QTextFormat::FontStretch);
439 if (it != properties.cend()) {
440 properties[QTextFormat::OldFontStretch] = it.value();
441 properties.erase(it);
444 it = properties.constFind(QTextFormat::TextUnderlineColor);
445 if (it != properties.cend()) {
446 properties[QTextFormat::OldTextUnderlineColor] = it.value();
447 properties.erase(it);
450 it = properties.constFind(QTextFormat::FontFamilies);
451 if (it != properties.cend()) {
452 properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().constFirst());
453 properties.erase(it);
457 stream << fmt.format_type << properties;
461Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
463 QMap<qint32, QVariant> properties;
464 stream >> fmt.format_type >> properties;
469 fmt.d =
new QTextFormatPrivate();
471 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();
472 it != properties.constEnd(); ++it) {
473 qint32 key = it.key();
475 if (stream.version() < QDataStream::Qt_6_0) {
476 if (key == QTextFormat::OldFontLetterSpacingType)
477 key = QTextFormat::FontLetterSpacingType;
478 else if (key == QTextFormat::OldFontStretch)
479 key = QTextFormat::FontStretch;
480 else if (key == QTextFormat::OldTextUnderlineColor)
481 key = QTextFormat::TextUnderlineColor;
482 else if (key == QTextFormat::OldFontFamily)
483 key = QTextFormat::FontFamilies;
485 fmt.d->insertProperty(key, it.value());
491Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextCharFormat &fmt)
493 return stream <<
static_cast<
const QTextFormat &>(fmt);
496Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextCharFormat &fmt)
498 return stream >>
static_cast<QTextFormat &>(fmt);
501Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextBlockFormat &fmt)
503 return stream <<
static_cast<
const QTextFormat &>(fmt);
506Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextBlockFormat &fmt)
508 return stream >>
static_cast<QTextFormat &>(fmt);
511Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextListFormat &fmt)
513 return stream <<
static_cast<
const QTextFormat &>(fmt);
516Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextListFormat &fmt)
518 return stream >>
static_cast<QTextFormat &>(fmt);
521Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextFrameFormat &fmt)
523 return stream <<
static_cast<
const QTextFormat &>(fmt);
526Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextFrameFormat &fmt)
528 return stream >>
static_cast<QTextFormat &>(fmt);
531Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextTableCellFormat &fmt)
533 return stream <<
static_cast<
const QTextFormat &>(fmt);
536Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextTableCellFormat &fmt)
538 return stream >>
static_cast<QTextFormat &>(fmt);
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
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
798
799
800
801
802
803
804
805
806
807
808
809
812
813
814
815
816
817
818
819
820
821
822
823
824
825
828
829
830
831
832
835
836
837
838
839
840
841
844
845
846
847
848
852
853
854
855
856
860
861
862
863
864
868
869
870
871
872
876
877
878
879
880
884
885
886
887
888
892
893
894
895
896
897
901
902
903
904
905QTextFormat::QTextFormat()
906 : format_type(InvalidFormat)
911
912
913
914
915QTextFormat::QTextFormat(
int type)
922
923
924
925
926
927QTextFormat::QTextFormat(
const QTextFormat &rhs)
928 : d(rhs.d), format_type(rhs.format_type)
933
934
935
936
937
938QTextFormat &QTextFormat::operator=(
const QTextFormat &rhs)
941 format_type = rhs.format_type;
946
947
948
949
952
953
954QTextFormat::~QTextFormat()
960
961
962QTextFormat::operator QVariant()
const
964 return QVariant::fromValue(*
this);
968
969
970
971void QTextFormat::merge(
const QTextFormat &other)
973 if (format_type != other.format_type)
984 QTextFormatPrivate *p = d.data();
986 const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props;
987 p->props.reserve(p->props.size() + otherProps.size());
988 for (
int i = 0; i < otherProps.size(); ++i) {
989 const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i);
990 if (prop.value.isValid()) {
991 p->insertProperty(prop.key, prop.value);
993 p->clearProperty(prop.key);
999
1000
1001
1002
1003int QTextFormat::type()
const
1009
1010
1011QTextBlockFormat QTextFormat::toBlockFormat()
const
1013 return QTextBlockFormat(*
this);
1017
1018
1019QTextCharFormat QTextFormat::toCharFormat()
const
1021 return QTextCharFormat(*
this);
1025
1026
1027QTextListFormat QTextFormat::toListFormat()
const
1029 return QTextListFormat(*
this);
1033
1034
1035QTextTableFormat QTextFormat::toTableFormat()
const
1037 return QTextTableFormat(*
this);
1041
1042
1043QTextFrameFormat QTextFormat::toFrameFormat()
const
1045 return QTextFrameFormat(*
this);
1049
1050
1051QTextImageFormat QTextFormat::toImageFormat()
const
1053 return QTextImageFormat(*
this);
1057
1058
1059
1060
1061QTextTableCellFormat QTextFormat::toTableCellFormat()
const
1063 return QTextTableCellFormat(*
this);
1067
1068
1069
1070
1071
1072
1073bool QTextFormat::boolProperty(
int propertyId)
const
1077 const QVariant prop = d->property(propertyId);
1078 if (prop.userType() != QMetaType::Bool)
1080 return prop.toBool();
1084
1085
1086
1087
1088
1089
1090int QTextFormat::intProperty(
int propertyId)
const
1093 int def = (propertyId == QTextFormat::LayoutDirection) ?
int(Qt::LayoutDirectionAuto) : 0;
1097 const QVariant prop = d->property(propertyId);
1098 if (prop.userType() != QMetaType::Int)
1100 return prop.toInt();
1104
1105
1106
1107
1108
1109
1110
1111qreal QTextFormat::doubleProperty(
int propertyId)
const
1115 const QVariant prop = d->property(propertyId);
1116 if (prop.userType() != QMetaType::Double && prop.userType() != QMetaType::Float)
1118 return qvariant_cast<qreal>(prop);
1122
1123
1124
1125
1126
1127
1128
1129QString QTextFormat::stringProperty(
int propertyId)
const
1133 const QVariant prop = d->property(propertyId);
1134 if (prop.userType() != QMetaType::QString)
1136 return prop.toString();
1140
1141
1142
1143
1144
1145
1146
1147QColor QTextFormat::colorProperty(
int propertyId)
const
1151 const QVariant prop = d->property(propertyId);
1152 if (prop.userType() != QMetaType::QColor)
1154 return qvariant_cast<QColor>(prop);
1158
1159
1160
1161
1162
1163
1164
1165QPen QTextFormat::penProperty(
int propertyId)
const
1168 return QPen(Qt::NoPen);
1169 const QVariant prop = d->property(propertyId);
1170 if (prop.userType() != QMetaType::QPen)
1171 return QPen(Qt::NoPen);
1172 return qvariant_cast<QPen>(prop);
1176
1177
1178
1179
1180
1181
1182
1183QBrush QTextFormat::brushProperty(
int propertyId)
const
1186 return QBrush(Qt::NoBrush);
1187 const QVariant prop = d->property(propertyId);
1188 if (prop.userType() != QMetaType::QBrush)
1189 return QBrush(Qt::NoBrush);
1190 return qvariant_cast<QBrush>(prop);
1194
1195
1196
1197
1198
1199QTextLength QTextFormat::lengthProperty(
int propertyId)
const
1202 return QTextLength();
1203 return qvariant_cast<QTextLength>(d->property(propertyId));
1207
1208
1209
1210
1211
1212
1213
1214QList<QTextLength> QTextFormat::lengthVectorProperty(
int propertyId)
const
1216 QList<QTextLength> list;
1219 const QVariant prop = d->property(propertyId);
1220 if (prop.userType() != QMetaType::QVariantList)
1223 const QList<QVariant> propertyList = prop.toList();
1224 for (
const auto &var : propertyList) {
1225 if (var.userType() == QMetaType::QTextLength)
1226 list.append(qvariant_cast<QTextLength>(var));
1233
1234
1235
1236
1237QVariant QTextFormat::property(
int propertyId)
const
1239 return d ? d->property(propertyId) : QVariant();
1243
1244
1245
1246
1247void QTextFormat::setProperty(
int propertyId,
const QVariant &value)
1250 d =
new QTextFormatPrivate;
1252 d->insertProperty(propertyId, value);
1256
1257
1258
1259
1260void QTextFormat::setProperty(
int propertyId,
const QList<QTextLength> &value)
1263 d =
new QTextFormatPrivate;
1265 const int numValues = value.size();
1266 list.reserve(numValues);
1267 for (
int i = 0; i < numValues; ++i)
1268 list << value.at(i);
1269 d->insertProperty(propertyId, list);
1273
1274
1275
1276
1277void QTextFormat::clearProperty(
int propertyId)
1281 d->clearProperty(propertyId);
1286
1287
1288
1289
1290
1291
1295
1296
1297
1298
1299
1300
1304
1305
1306
1307
1308int QTextFormat::objectIndex()
const
1312 const QVariant prop = d->property(ObjectIndex);
1313 if (prop.userType() != QMetaType::Int)
1315 return prop.toInt();
1319
1320
1321
1322
1323
1324
1325void QTextFormat::setObjectIndex(
int o)
1329 d->clearProperty(ObjectIndex);
1332 d =
new QTextFormatPrivate;
1334 d->insertProperty(ObjectIndex, o);
1339
1340
1341
1342
1343
1344bool QTextFormat::hasProperty(
int propertyId)
const
1346 return d ? d->hasProperty(propertyId) :
false;
1350
1351
1352
1353
1356
1357
1358QMap<
int, QVariant> QTextFormat::properties()
const
1360 QMap<
int, QVariant> map;
1362 for (
int i = 0; i < d->props.size(); ++i)
1363 map.insert(d->props.at(i).key, d->props.at(i).value);
1369
1370
1371
1372int QTextFormat::propertyCount()
const
1374 return d ? d->props.size() : 0;
1378
1379
1380
1381
1382
1386
1387
1388
1389
1390
1391bool QTextFormat::operator==(
const QTextFormat &rhs)
const
1393 if (format_type != rhs.format_type)
1399 if (d && d->props.isEmpty() && !rhs.d)
1402 if (!d && rhs.d && rhs.d->props.isEmpty())
1408 return *d == *rhs.d;
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
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1483
1484
1485
1486
1487QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}
1490
1491
1492
1493
1494
1495
1496QTextCharFormat::QTextCharFormat(
const QTextFormat &fmt)
1502
1503
1504
1505
1506
1510
1511
1512
1513
1514
1515
1516
1520
1521
1522
1523
1524
1525
1526
1529
1530
1531
1532
1533
1534
1535
1537#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1552
1553
1554
1555
1556
1557
1558
1562
1563
1564
1565
1566
1567
1568
1570#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1585
1586
1587
1588
1589
1590
1591
1595
1596
1597
1598
1599
1600
1604
1605
1606
1607
1608
1609
1613
1614
1615
1616
1617
1618
1622
1623
1624
1625
1626
1627
1631
1632
1633
1634
1635
1636
1637
1641
1642
1643
1644
1645
1646
1647
1651
1652
1653
1654
1655
1656
1657
1661
1662
1663
1664
1665
1666
1667
1668bool QTextCharFormat::fontUnderline()
const
1670 if (hasProperty(TextUnderlineStyle))
1671 return underlineStyle() == SingleUnderline;
1672 return boolProperty(FontUnderline);
1676
1677
1678
1679
1680
1683
1684
1685
1686
1687
1688void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1690 setProperty(TextUnderlineStyle, style);
1692 setProperty(FontUnderline, style == SingleUnderline);
1696
1697
1698
1699
1700
1701
1702
1706
1707
1708
1709
1710
1711
1712
1716
1717
1718
1719
1720
1721
1722
1723
1727
1728
1729
1730
1731
1732
1733
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1750
1751
1752
1753
1754
1755
1756
1757
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1774
1775
1776
1777
1778
1779
1780
1784
1785
1786
1787
1788
1789
1790
1791
1795
1796
1797
1798
1799
1800
1801
1805
1806
1807
1808
1809
1810
1811
1815
1816
1817
1818
1819
1820
1821
1824
1825
1826
1827
1828
1829
1830
1831
1834
1835
1836
1837
1838
1839
1840
1841
1844
1845
1846
1847
1848
1849
1850void QTextCharFormat::setFontFeatures(
const QHash<QFont::Tag, quint32> &fontFeatures)
1852 setProperty(FontFeatures, QVariant::fromValue(fontFeatures));
1856
1857
1858
1859
1860
1861
1862QHash<QFont::Tag, quint32> QTextCharFormat::fontFeatures()
const
1864 return property(FontFeatures).value<QHash<QFont::Tag, quint32>>();
1868
1869
1870
1871
1872
1873
1874void QTextCharFormat::setFontVariableAxes(
const QHash<QFont::Tag,
float> &fontVariableAxes)
1876 setProperty(FontVariableAxes, QVariant::fromValue(fontVariableAxes));
1880
1881
1882
1883
1884
1885
1886QHash<QFont::Tag,
float> QTextCharFormat::fontVariableAxes()
const
1888 return property(FontVariableAxes).value<QHash<QFont::Tag,
float>>();
1893
1894
1895
1896
1900
1901
1902
1903
1906
1907
1908
1909
1910
1913
1914
1915
1916
1917
1920
1921
1922
1923
1924
1925
1926
1930
1931
1932
1933
1934
1935
1936
1939
1940
1941
1942
1943
1944
1945
1948
1949
1950
1951
1952
1953
1954
1955
1958
1959
1960
1961
1962
1963
1964
1967
1968
1969
1970
1971
1972
1973
1974
1977
1978
1979
1980
1981
1982
1983
1986
1987
1988
1989
1990
1991
1992
1993
1996
1997
1998
1999
2000
2001
2002
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2021
2022
2023
2024
2025
2026
2027
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2044
2045
2046
2047
2048
2051
2052
2053
2054
2055
2056
2057
2060
2061
2062
2063
2064
2065
2066
2067QStringList QTextCharFormat::anchorNames()
const
2069 QVariant prop = property(AnchorName);
2070 if (prop.userType() == QMetaType::QStringList)
2071 return prop.toStringList();
2072 else if (prop.userType() != QMetaType::QString)
2073 return QStringList();
2074 return QStringList(prop.toString());
2079
2080
2081
2082
2083
2084
2088
2089
2090
2091
2092
2093
2094
2097
2098
2099
2100
2101
2102
2106
2107
2108
2109
2110
2111
2112
2115
2116
2117
2118
2119
2120
2121
2124
2125
2126
2127
2128
2129
2130
2133
2134
2135
2136
2137
2138
2139
2142
2143
2144
2145
2146
2147
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177void QTextCharFormat::setFont(
const QFont &font, FontPropertiesInheritanceBehavior behavior)
2179 const uint mask = behavior == FontPropertiesAll ? uint(QFont::AllPropertiesResolved)
2180 : font.resolveMask();
2182 if (mask & QFont::FamiliesResolved)
2183 setFontFamilies(font.families());
2184 if (mask & QFont::StyleNameResolved)
2185 setFontStyleName(font.styleName());
2187 if (mask & QFont::SizeResolved) {
2188 const qreal pointSize = font.pointSizeF();
2189 if (pointSize > 0) {
2190 setFontPointSize(pointSize);
2192 const int pixelSize = font.pixelSize();
2194 setProperty(QTextFormat::FontPixelSize, pixelSize);
2198 if (mask & QFont::WeightResolved)
2199 setFontWeight(font.weight());
2200 if (mask & QFont::StyleResolved)
2201 setFontItalic(font.style() != QFont::StyleNormal);
2202 if (mask & QFont::UnderlineResolved)
2203 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
2204 if (mask & QFont::OverlineResolved)
2205 setFontOverline(font.overline());
2206 if (mask & QFont::StrikeOutResolved)
2207 setFontStrikeOut(font.strikeOut());
2208 if (mask & QFont::FixedPitchResolved)
2209 setFontFixedPitch(font.fixedPitch());
2210 if (mask & QFont::CapitalizationResolved)
2211 setFontCapitalization(font.capitalization());
2212 if (mask & QFont::WordSpacingResolved)
2213 setFontWordSpacing(font.wordSpacing());
2214 if (mask & QFont::LetterSpacingResolved) {
2215 setFontLetterSpacingType(font.letterSpacingType());
2216 setFontLetterSpacing(font.letterSpacing());
2218 if (mask & QFont::StretchResolved)
2219 setFontStretch(font.stretch());
2220 if (mask & QFont::StyleHintResolved)
2221 setFontStyleHint(font.styleHint());
2222 if (mask & QFont::StyleStrategyResolved)
2223 setFontStyleStrategy(font.styleStrategy());
2224 if (mask & QFont::HintingPreferenceResolved)
2225 setFontHintingPreference(font.hintingPreference());
2226 if (mask & QFont::KerningResolved)
2227 setFontKerning(font.kerning());
2228 if (mask & QFont::FeaturesResolved) {
2229 const auto tags = font.featureTags();
2231 QHash<QFont::Tag, quint32> fontFeatures;
2232 for (QFont::Tag tag : tags)
2233 fontFeatures.insert(tag, font.featureValue(tag));
2234 setFontFeatures(fontFeatures);
2236 if (mask & QFont::VariableAxesResolved) {
2237 const auto tags = font.variableAxisTags();
2239 QHash<QFont::Tag,
float> fontVariableAxes;
2240 for (QFont::Tag tag : tags)
2241 fontVariableAxes.insert(tag, font.variableAxisValue(tag));
2242 setFontVariableAxes(fontVariableAxes);
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260QFont QTextCharFormat::font()
const
2262 return d ? d->font() : QFont();
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2324
2325
2326
2327
2328QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}
2331
2332
2333
2334
2335
2336
2337QTextBlockFormat::QTextBlockFormat(
const QTextFormat &fmt)
2343
2344
2345
2346
2347
2348
2349void QTextBlockFormat::setTabPositions(
const QList<QTextOption::Tab> &tabs)
2351 QList<QVariant> list;
2352 list.reserve(tabs.size());
2353 for (
const auto &e : tabs)
2354 list.append(QVariant::fromValue(e));
2355 setProperty(TabPositions, list);
2359
2360
2361
2362
2363
2364QList<QTextOption::Tab> QTextBlockFormat::tabPositions()
const
2366 QVariant variant = property(TabPositions);
2367 if (variant.isNull())
2368 return QList<QTextOption::Tab>();
2369 QList<QTextOption::Tab> answer;
2370 const QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
2371 answer.reserve(variantsList.size());
2372 for (
const auto &e: variantsList)
2373 answer.append(qvariant_cast<QTextOption::Tab>(e));
2378
2379
2380
2381
2382
2385
2386
2387
2388
2389
2390
2394
2395
2396
2397
2398
2399
2403
2404
2405
2406
2407
2408
2412
2413
2414
2415
2416
2417
2421
2422
2423
2424
2425
2426
2430
2431
2432
2433
2434
2435
2439
2440
2441
2442
2443
2444
2448
2449
2450
2451
2452
2453
2457
2458
2459
2460
2461
2462
2463
2467
2468
2469
2470
2471
2472
2476
2477
2478
2479
2480
2481
2485
2486
2487
2488
2489
2490
2494
2495
2496
2497
2498
2499
2500
2501
2505
2506
2507
2508
2509
2510
2514
2515
2516
2517
2518
2519
2520
2521
2522
2526
2527
2528
2529
2530
2531
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2553
2554
2555
2556
2557
2558
2559
2563
2564
2565
2566
2567
2568
2569
2570
2571
2575
2576
2577
2578
2579
2580
2581
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2607
2608
2609
2610
2611
2612
2613
2614
2615
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2638
2639
2640
2641
2642
2643
2644
2648
2649
2650
2651
2652
2653
2654
2658
2659
2660
2661
2662
2663
2664
2668
2669
2670
2671
2672
2673
2674
2677
2678
2679
2680
2681
2682
2683
2684
2687
2688
2689
2690
2691
2692
2693
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2747
2748
2749
2750
2751QTextListFormat::QTextListFormat()
2752 : QTextFormat(ListFormat)
2759
2760
2761
2762
2763
2764
2765QTextListFormat::QTextListFormat(
const QTextFormat &fmt)
2771
2772
2773
2774
2775
2778
2779
2780
2781
2782
2783
2786
2787
2788
2789
2790
2791
2795
2796
2797
2798
2799
2800
2801
2802
2806
2807
2808
2809
2810
2811
2812
2813
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2829
2830
2831
2832
2833
2834
2835
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2851
2852
2853
2854
2855
2856
2857
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2876
2877
2878
2879
2880
2881
2882
2883
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2955
2956
2957
2958
2959QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)
2961 setBorderStyle(BorderStyle_Outset);
2962 setBorderBrush(Qt::darkGray);
2966
2967
2968
2969
2970
2971
2972QTextFrameFormat::QTextFrameFormat(
const QTextFormat &fmt)
2978
2979
2980
2981
2984
2985
2986
2987
2988
2991
2992
2993
2994
2997
2998
2999
3000
3003
3004
3005
3006
3009
3010
3011
3012
3013
3016
3017
3018
3019
3020
3023
3024
3025
3026
3027
3030
3031
3032
3033
3034
3037
3038
3039
3040
3041
3042
3043
3044void QTextFrameFormat::setMargin(qreal amargin)
3046 setProperty(FrameMargin, amargin);
3047 setProperty(FrameTopMargin, amargin);
3048 setProperty(FrameBottomMargin, amargin);
3049 setProperty(FrameLeftMargin, amargin);
3050 setProperty(FrameRightMargin, amargin);
3055
3056
3057
3058
3061
3062
3063
3064
3065
3068
3069
3070
3071
3072
3073qreal QTextFrameFormat::topMargin()
const
3075 if (!hasProperty(FrameTopMargin))
3077 return doubleProperty(FrameTopMargin);
3081
3082
3083
3084
3085
3088
3089
3090
3091
3092
3093qreal QTextFrameFormat::bottomMargin()
const
3095 if (!hasProperty(FrameBottomMargin))
3097 return doubleProperty(FrameBottomMargin);
3101
3102
3103
3104
3105
3108
3109
3110
3111
3112
3113qreal QTextFrameFormat::leftMargin()
const
3115 if (!hasProperty(FrameLeftMargin))
3117 return doubleProperty(FrameLeftMargin);
3121
3122
3123
3124
3125
3128
3129
3130
3131
3132
3133qreal QTextFrameFormat::rightMargin()
const
3135 if (!hasProperty(FrameRightMargin))
3137 return doubleProperty(FrameRightMargin);
3141
3142
3143
3144
3147
3148
3149
3150
3153
3154
3155
3156
3157
3158
3161
3162
3163
3164
3165
3166
3169
3170
3171
3172
3173
3174
3175
3176
3179
3180
3181
3182
3183
3184
3185
3188
3189
3190
3191
3192
3193
3196
3197
3198
3199
3202
3203
3204
3205
3206
3209
3210
3211
3212
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3261
3262
3263
3264
3265QTextTableFormat::QTextTableFormat()
3266 : QTextFrameFormat()
3268 setObjectType(TableObject);
3270 setBorderCollapse(
true);
3275
3276
3277
3278
3279
3280
3281QTextTableFormat::QTextTableFormat(
const QTextFormat &fmt)
3282 : QTextFrameFormat(fmt)
3287
3288
3289
3290
3291
3295
3296
3297
3298
3302
3303
3304
3305
3306
3307
3308
3311
3312
3313
3314
3315
3316
3319
3320
3321
3322
3323
3324
3327
3328
3329
3330
3331
3332
3333
3336
3337
3338
3339
3340
3343
3344
3345
3346
3347
3348
3349
3352
3353
3354
3355
3356
3359
3360
3361
3362
3363
3366
3367
3368
3369
3370
3371
3374
3375
3376
3377
3378
3379
3382
3383
3384
3385
3386
3387
3388
3391
3392
3393
3394
3395
3396
3397
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3431
3432
3433
3434
3435
3436
3437
3440
3441
3442
3443
3444
3445
3446
3449
3450
3451
3452
3453
3454
3457
3458
3459
3460
3461
3462
3463
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3492
3493
3494
3495
3496QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }
3499
3500
3501
3502
3503
3504
3505QTextImageFormat::QTextImageFormat(
const QTextFormat &fmt)
3506 : QTextCharFormat(fmt)
3511
3512
3513
3514
3518
3519
3520
3521
3522
3523
3524
3528
3529
3530
3531
3532
3533
3534
3537
3538
3539
3540
3541
3542
3546
3547
3548
3549
3550
3551
3554
3555
3556
3557
3558
3559
3560
3564
3565
3566
3567
3568
3569
3573
3574
3575
3576
3577
3578
3582
3583
3584
3585
3586
3587
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3603
3604
3605
3606
3607
3608
3609
3612
3613
3614
3615
3616
3617
3618
3619
3620
3623
3624
3625
3626
3627
3630
3631
3632
3633
3634
3635
3636
3637
3638
3641
3642
3643
3644
3645
3646
3647
3648
3649
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3667
3668
3669
3670
3671
3672
3673
3674
3675
3678
3679
3680
3681
3682
3683
3684
3687
3688
3689
3690
3691
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3707
3708
3709
3710
3711
3712
3715
3716
3717
3718
3719
3720
3721
3724
3725
3726
3727
3728
3729
3730
3733
3734
3735
3736
3737
3738
3739
3742
3743
3744
3745
3746
3747
3748
3751
3752
3753
3754
3755
3756
3757
3760
3761
3762
3763
3764
3765
3766
3769
3770
3771
3772
3773
3774
3775
3778
3779
3780
3781
3782
3783
3784
3787
3788
3789
3790
3791
3792
3793
3796
3797
3798
3799
3800
3801
3802
3805
3806
3807
3808
3809
3812
3813
3814
3815
3816
3817
3818
3821
3822
3823
3824
3825
3828
3829
3830
3831
3832
3833
3834
3837
3838
3839
3840
3841
3844
3845
3846
3847
3848
3849
3850
3853
3854
3855
3856
3857
3860
3861
3862
3863
3864
3865
3866
3867
3870
3871
3872
3873
3874
3875
3876
3879
3880
3881
3882
3883
3886
3887
3888
3889
3890
3891
3892
3895
3896
3897
3898
3899
3902
3903
3904
3905
3906
3907
3908
3911
3912
3913
3914
3915
3918
3919
3920
3921
3922
3923
3924
3927
3928
3929
3930
3931
3934
3935
3936
3937
3938
3939
3940
3941
3944
3945
3946
3947
3948
3949
3950
3953
3954
3955
3956
3957
3960
3961
3962
3963
3964
3965
3966
3969
3970
3971
3972
3973
3976
3977
3978
3979
3980
3981
3982
3985
3986
3987
3988
3989
3992
3993
3994
3995
3996
3997
3998
4001
4002
4003
4004
4005
4008
4009
4010
4011
4012
4013
4014
4015
4018
4019
4020
4021
4022
4025
4026
4027
4028
4029
4030QTextTableCellFormat::QTextTableCellFormat()
4033 setObjectType(TableCellObject);
4037
4038
4039
4040
4041
4042
4043QTextTableCellFormat::QTextTableCellFormat(
const QTextFormat &fmt)
4044 : QTextCharFormat(fmt)
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4072QTextFormatCollection::~QTextFormatCollection()
4076void QTextFormatCollection::clear()
4083int QTextFormatCollection::indexForFormat(
const QTextFormat &format)
4085 size_t hash = getHash(format.d, format.format_type);
4086 auto i = hashes.constFind(hash);
4087 while (i != hashes.constEnd() && i.key() == hash) {
4088 if (formats.value(i.value()) == format) {
4094 int idx = formats.size();
4095 formats.append(format);
4098 QTextFormat &f = formats.last();
4100 f.d =
new QTextFormatPrivate;
4101 f.d->resolveFont(defaultFnt);
4103 hashes.insert(hash, idx);
4112bool QTextFormatCollection::hasFormatCached(
const QTextFormat &format)
const
4114 size_t hash = getHash(format.d, format.format_type);
4115 auto i = hashes.constFind(hash);
4116 while (i != hashes.constEnd() && i.key() == hash) {
4117 if (formats.value(i.value()) == format) {
4125int QTextFormatCollection::objectFormatIndex(
int objectIndex)
const
4127 if (objectIndex == -1 || objectIndex >= objFormats.size())
4129 return objFormats.at(objectIndex);
4132void QTextFormatCollection::setObjectFormatIndex(
int objectIndex,
int formatIndex)
4134 objFormats[objectIndex] = formatIndex;
4137int QTextFormatCollection::createObjectIndex(
const QTextFormat &f)
4139 const int objectIndex = objFormats.size();
4140 objFormats.append(indexForFormat(f));
4144QTextFormat QTextFormatCollection::format(
int idx)
const
4146 if (idx < 0 || idx >= formats.size())
4147 return QTextFormat();
4149 return formats.at(idx);
4152void QTextFormatCollection::setDefaultFont(
const QFont &f)
4155 for (
int i = 0; i < formats.size(); ++i)
4156 if (formats.at(i).d)
4157 formats[i].d->resolveFont(defaultFnt);
4160#ifndef QT_NO_DEBUG_STREAM
4163 QDebugStateSaver saver(dbg);
4164 dbg.nospace() <<
"QTextLength(QTextLength::Type(" << l.type() <<
"))";
4170 QDebugStateSaver saver(dbg);
4171 dbg.nospace() <<
"QTextFormat(QTextFormat::FormatType(" << f.type() <<
"))";
4179#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)