8#include <qdatastream.h>
11#include <qhashfunctions.h>
12#include <private/qfont_p.h>
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
42
43
44
45
48
49
50
51
54
55
56
57
58
59
62
63
64
65
66
67
68
71
72
73
74
75
76
77
80
81
82
83
84
87
88
89
90
91
94
95
96
97
98
99
100
101
102
103
104
105
108
109
110QTextLength::operator QVariant()
const
112 return QVariant::fromValue(*
this);
115#ifndef QT_NO_DATASTREAM
116QDataStream &operator<<(QDataStream &stream,
const QTextLength &length)
118 return stream << qint32(length.lengthType) <<
double(length.fixedValueOrPercentage);
121QDataStream &
operator>>(QDataStream &stream, QTextLength &length)
124 double fixedValueOrPercentage;
125 stream >> type >> fixedValueOrPercentage;
126 length.fixedValueOrPercentage = fixedValueOrPercentage;
127 length.lengthType = QTextLength::Type(type);
135 inline Property(qint32 k,
const QVariant &v) : key(k), value(v) {}
141 inline bool operator==(
const Property &other)
const
142 {
return key == other.key && value == other.value; }
160 if (hash() != rhs.hash())
163 return props == rhs.props;
169 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
172 for (
int i = 0; i < props.size(); ++i)
173 if (props.at(i).key == key) {
174 props[i].value = value;
177 props.append(Property(key, value));
182 for (
int i = 0; i < props.size(); ++i)
183 if (props.at(i).key == key) {
185 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
194 for (
int i = 0; i < props.size(); ++i)
195 if (props.at(i).key == key)
202 const int idx = propertyIndex(key);
205 return props.at(idx).value;
209 {
return propertyIndex(key) != -1; }
213 inline const QFont &
font()
const {
222 size_t recalcHash()
const;
223 void recalcFont()
const;
225 mutable bool hashDirty;
226 mutable bool fontDirty;
227 mutable size_t hashValue;
230 friend QDataStream &operator<<(QDataStream &,
const QTextFormat &);
231 friend QDataStream &
operator>>(QDataStream &, QTextFormat &);
236 return (color.isValid()) ? color.rgba() : 0x234109;
241 return hash(pen.color()) + qHash(pen.widthF());
246 return hash(brush.color()) + (brush.style() << 3);
252 switch (variant.userType()) {
253 case QMetaType::QString:
return qHash(variant.toString());
254 case QMetaType::Double:
return qHash(variant.toDouble());
255 case QMetaType::Int:
return 0x811890U + variant.toInt();
256 case QMetaType::QBrush:
257 return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
258 case QMetaType::Bool:
return 0x371818 + variant.toBool();
259 case QMetaType::QPen:
return 0x02020202 + hash(qvariant_cast<QPen>(variant));
260 case QMetaType::QVariantList:
261 return 0x8377U + qvariant_cast<QVariantList>(variant).size();
262 case QMetaType::QColor:
return hash(qvariant_cast<QColor>(variant));
263 case QMetaType::QTextLength:
264 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
265 case QMetaType::Float:
return qHash(variant.toFloat());
266 case QMetaType::UnknownType:
return 0;
269 return qHash(variant.typeName());
274 return (d ? d->hash() : 0) + format;
280 const auto end = props.constEnd();
281 for (
auto it = props.constBegin(); it != end; ++it)
282 hashValue += (
static_cast<quint32>(it->key) << 16) + variantHash(it->value);
292 const uint oldMask = fnt.resolveMask();
293 fnt = fnt.resolve(defaultFont);
295 if (hasProperty(QTextFormat::FontSizeAdjustment)) {
296 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
298 const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);
301 if (defaultFont.pointSize() <= 0) {
302 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
303 fnt.setPixelSize(qRound(pixelSize));
305 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
306 fnt.setPointSizeF(pointSize);
310 fnt.setResolveMask(oldMask);
318 bool hasSpacingInformation =
false;
319 QFont::SpacingType spacingType = QFont::PercentageSpacing;
320 qreal letterSpacing = 0.0;
322 for (
int i = 0; i < props.size(); ++i) {
323 switch (props.at(i).key) {
324 case QTextFormat::FontFamilies:
325 f.setFamilies(props.at(i).value.toStringList());
327 case QTextFormat::FontStyleName:
328 f.setStyleName(props.at(i).value.toString());
330 case QTextFormat::FontPointSize:
331 f.setPointSizeF(props.at(i).value.toReal());
333 case QTextFormat::FontPixelSize:
334 f.setPixelSize(props.at(i).value.toInt());
336 case QTextFormat::FontWeight: {
337 const QVariant weightValue = props.at(i).value;
338 int weight = weightValue.toInt();
339 if (weight >= 0 && weightValue.isValid())
340 f.setWeight(QFont::Weight(weight));
342 case QTextFormat::FontItalic:
343 f.setItalic(props.at(i).value.toBool());
345 case QTextFormat::FontUnderline:
346 if (! hasProperty(QTextFormat::TextUnderlineStyle))
347 f.setUnderline(props.at(i).value.toBool());
349 case QTextFormat::TextUnderlineStyle:
350 f.setUnderline(
static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
352 case QTextFormat::FontOverline:
353 f.setOverline(props.at(i).value.toBool());
355 case QTextFormat::FontStrikeOut:
356 f.setStrikeOut(props.at(i).value.toBool());
358 case QTextFormat::FontLetterSpacingType:
359 spacingType =
static_cast<QFont::SpacingType>(props.at(i).value.toInt());
360 hasSpacingInformation =
true;
362 case QTextFormat::FontLetterSpacing:
363 letterSpacing = props.at(i).value.toReal();
364 hasSpacingInformation =
true;
366 case QTextFormat::FontWordSpacing:
367 f.setWordSpacing(props.at(i).value.toReal());
369 case QTextFormat::FontCapitalization:
370 f.setCapitalization(
static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
372 case QTextFormat::FontFixedPitch: {
373 const bool value = props.at(i).value.toBool();
374 if (f.fixedPitch() != value)
375 f.setFixedPitch(value);
377 case QTextFormat::FontStretch:
378 f.setStretch(props.at(i).value.toInt());
380 case QTextFormat::FontStyleHint:
381 f.setStyleHint(
static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
383 case QTextFormat::FontHintingPreference:
384 f.setHintingPreference(
static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
386 case QTextFormat::FontStyleStrategy:
387 f.setStyleStrategy(
static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
389 case QTextFormat::FontKerning:
390 f.setKerning(props.at(i).value.toBool());
392 case QTextFormat::FontFeatures:
394 const auto fontFeatures = props.at(i).value.value<QMap<QFont::Tag, quint32>>();
395 for (
auto it = fontFeatures.constBegin(); it != fontFeatures.constEnd(); ++it)
396 f.setFeature(it.key(), it.value());
399 case QTextFormat::FontVariableAxes:
401 const auto fontVariableAxes = props.at(i).value.value<QMap<QFont::Tag,
float>>();
402 for (
auto it = fontVariableAxes.constBegin(); it != fontVariableAxes.constEnd(); ++it)
403 f.setVariableAxis(it.key(), it.value());
411 if (hasSpacingInformation)
412 f.setLetterSpacing(spacingType, letterSpacing);
418#ifndef QT_NO_DATASTREAM
419Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextFormat &fmt)
421 QMap<
int, QVariant> properties = fmt.properties();
422 if (stream.version() < QDataStream::Qt_6_11) {
423 auto it = properties.constFind(QTextFormat::FontFeatures);
424 if (it != properties.cend())
425 properties.erase(it);
427 it = properties.constFind(QTextFormat::FontVariableAxes);
428 if (it != properties.cend())
429 properties.erase(it);
432 if (stream.version() < QDataStream::Qt_6_0) {
433 auto it = properties.constFind(QTextFormat::FontLetterSpacingType);
434 if (it != properties.cend()) {
435 properties[QTextFormat::OldFontLetterSpacingType] = it.value();
436 properties.erase(it);
439 it = properties.constFind(QTextFormat::FontStretch);
440 if (it != properties.cend()) {
441 properties[QTextFormat::OldFontStretch] = it.value();
442 properties.erase(it);
445 it = properties.constFind(QTextFormat::TextUnderlineColor);
446 if (it != properties.cend()) {
447 properties[QTextFormat::OldTextUnderlineColor] = it.value();
448 properties.erase(it);
451 it = properties.constFind(QTextFormat::FontFamilies);
452 if (it != properties.cend()) {
453 properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().constFirst());
454 properties.erase(it);
458 stream << fmt.format_type << properties;
462Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
464 QMap<qint32, QVariant> properties;
465 stream >> fmt.format_type >> properties;
470 fmt.d =
new QTextFormatPrivate();
472 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();
473 it != properties.constEnd(); ++it) {
474 qint32 key = it.key();
476 if (stream.version() < QDataStream::Qt_6_0) {
477 if (key == QTextFormat::OldFontLetterSpacingType)
478 key = QTextFormat::FontLetterSpacingType;
479 else if (key == QTextFormat::OldFontStretch)
480 key = QTextFormat::FontStretch;
481 else if (key == QTextFormat::OldTextUnderlineColor)
482 key = QTextFormat::TextUnderlineColor;
483 else if (key == QTextFormat::OldFontFamily)
484 key = QTextFormat::FontFamilies;
486 fmt.d->insertProperty(key, it.value());
492Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextCharFormat &fmt)
494 return stream <<
static_cast<
const QTextFormat &>(fmt);
497Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextCharFormat &fmt)
499 return stream >>
static_cast<QTextFormat &>(fmt);
502Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextBlockFormat &fmt)
504 return stream <<
static_cast<
const QTextFormat &>(fmt);
507Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextBlockFormat &fmt)
509 return stream >>
static_cast<QTextFormat &>(fmt);
512Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextListFormat &fmt)
514 return stream <<
static_cast<
const QTextFormat &>(fmt);
517Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextListFormat &fmt)
519 return stream >>
static_cast<QTextFormat &>(fmt);
522Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextFrameFormat &fmt)
524 return stream <<
static_cast<
const QTextFormat &>(fmt);
527Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextFrameFormat &fmt)
529 return stream >>
static_cast<QTextFormat &>(fmt);
532Q_GUI_EXPORT
QDataStream &operator<<(QDataStream &stream,
const QTextTableCellFormat &fmt)
534 return stream <<
static_cast<
const QTextFormat &>(fmt);
537Q_GUI_EXPORT
QDataStream &operator>>(QDataStream &stream, QTextTableCellFormat &fmt)
539 return stream >>
static_cast<QTextFormat &>(fmt);
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
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
799
800
801
802
803
804
805
806
807
808
809
810
813
814
815
816
817
818
819
820
821
822
823
824
825
826
829
830
831
832
833
836
837
838
839
840
841
842
845
846
847
848
849
853
854
855
856
857
861
862
863
864
865
869
870
871
872
873
877
878
879
880
881
885
886
887
888
889
893
894
895
896
897
898
902
903
904
905
906QTextFormat::QTextFormat()
907 : format_type(InvalidFormat)
912
913
914
915
916QTextFormat::QTextFormat(
int type)
923
924
925
926
927
928QTextFormat::QTextFormat(
const QTextFormat &rhs)
929 : d(rhs.d), format_type(rhs.format_type)
934
935
936
937
938
939QTextFormat &QTextFormat::operator=(
const QTextFormat &rhs)
942 format_type = rhs.format_type;
947
948
949
950
953
954
955QTextFormat::~QTextFormat()
961
962
963QTextFormat::operator QVariant()
const
965 return QVariant::fromValue(*
this);
969
970
971
972void QTextFormat::merge(
const QTextFormat &other)
974 if (format_type != other.format_type)
985 QTextFormatPrivate *p = d.data();
987 const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props;
988 p->props.reserve(p->props.size() + otherProps.size());
989 for (
int i = 0; i < otherProps.size(); ++i) {
990 const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i);
991 if (prop.value.isValid()) {
992 p->insertProperty(prop.key, prop.value);
994 p->clearProperty(prop.key);
1000
1001
1002
1003
1004int QTextFormat::type()
const
1010
1011
1012QTextBlockFormat QTextFormat::toBlockFormat()
const
1014 return QTextBlockFormat(*
this);
1018
1019
1020QTextCharFormat QTextFormat::toCharFormat()
const
1022 return QTextCharFormat(*
this);
1026
1027
1028QTextListFormat QTextFormat::toListFormat()
const
1030 return QTextListFormat(*
this);
1034
1035
1036QTextTableFormat QTextFormat::toTableFormat()
const
1038 return QTextTableFormat(*
this);
1042
1043
1044QTextFrameFormat QTextFormat::toFrameFormat()
const
1046 return QTextFrameFormat(*
this);
1050
1051
1052QTextImageFormat QTextFormat::toImageFormat()
const
1054 return QTextImageFormat(*
this);
1058
1059
1060
1061
1062QTextTableCellFormat QTextFormat::toTableCellFormat()
const
1064 return QTextTableCellFormat(*
this);
1068
1069
1070
1071
1072
1073
1074bool QTextFormat::boolProperty(
int propertyId)
const
1078 const QVariant prop = d->property(propertyId);
1079 if (prop.userType() != QMetaType::Bool)
1081 return prop.toBool();
1085
1086
1087
1088
1089
1090
1091int QTextFormat::intProperty(
int propertyId)
const
1094 int def = (propertyId == QTextFormat::LayoutDirection) ?
int(Qt::LayoutDirectionAuto) : 0;
1098 const QVariant prop = d->property(propertyId);
1099 if (prop.userType() != QMetaType::Int)
1101 return prop.toInt();
1105
1106
1107
1108
1109
1110
1111
1112qreal QTextFormat::doubleProperty(
int propertyId)
const
1116 const QVariant prop = d->property(propertyId);
1117 if (prop.userType() != QMetaType::Double && prop.userType() != QMetaType::Float)
1119 return qvariant_cast<qreal>(prop);
1123
1124
1125
1126
1127
1128
1129
1130QString QTextFormat::stringProperty(
int propertyId)
const
1134 const QVariant prop = d->property(propertyId);
1135 if (prop.userType() != QMetaType::QString)
1137 return prop.toString();
1141
1142
1143
1144
1145
1146
1147
1148QColor QTextFormat::colorProperty(
int propertyId)
const
1152 const QVariant prop = d->property(propertyId);
1153 if (prop.userType() != QMetaType::QColor)
1155 return qvariant_cast<QColor>(prop);
1159
1160
1161
1162
1163
1164
1165
1166QPen QTextFormat::penProperty(
int propertyId)
const
1169 return QPen(Qt::NoPen);
1170 const QVariant prop = d->property(propertyId);
1171 if (prop.userType() != QMetaType::QPen)
1172 return QPen(Qt::NoPen);
1173 return qvariant_cast<QPen>(prop);
1177
1178
1179
1180
1181
1182
1183
1184QBrush QTextFormat::brushProperty(
int propertyId)
const
1187 return QBrush(Qt::NoBrush);
1188 const QVariant prop = d->property(propertyId);
1189 if (prop.userType() != QMetaType::QBrush)
1190 return QBrush(Qt::NoBrush);
1191 return qvariant_cast<QBrush>(prop);
1195
1196
1197
1198
1199
1200QTextLength QTextFormat::lengthProperty(
int propertyId)
const
1203 return QTextLength();
1204 return qvariant_cast<QTextLength>(d->property(propertyId));
1208
1209
1210
1211
1212
1213
1214
1215QList<QTextLength> QTextFormat::lengthVectorProperty(
int propertyId)
const
1217 QList<QTextLength> list;
1220 const QVariant prop = d->property(propertyId);
1221 if (prop.userType() != QMetaType::QVariantList)
1224 const QList<QVariant> propertyList = prop.toList();
1225 for (
const auto &var : propertyList) {
1226 if (var.userType() == QMetaType::QTextLength)
1227 list.append(qvariant_cast<QTextLength>(var));
1234
1235
1236
1237
1238QVariant QTextFormat::property(
int propertyId)
const
1240 return d ? d->property(propertyId) : QVariant();
1244
1245
1246
1247
1248void QTextFormat::setProperty(
int propertyId,
const QVariant &value)
1251 d =
new QTextFormatPrivate;
1253 d->insertProperty(propertyId, value);
1257
1258
1259
1260
1261void QTextFormat::setProperty(
int propertyId,
const QList<QTextLength> &value)
1264 d =
new QTextFormatPrivate;
1266 const int numValues = value.size();
1267 list.reserve(numValues);
1268 for (
int i = 0; i < numValues; ++i)
1269 list << value.at(i);
1270 d->insertProperty(propertyId, list);
1274
1275
1276
1277
1278void QTextFormat::clearProperty(
int propertyId)
1282 d->clearProperty(propertyId);
1287
1288
1289
1290
1291
1292
1296
1297
1298
1299
1300
1301
1305
1306
1307
1308
1309int QTextFormat::objectIndex()
const
1313 const QVariant prop = d->property(ObjectIndex);
1314 if (prop.userType() != QMetaType::Int)
1316 return prop.toInt();
1320
1321
1322
1323
1324
1325
1326void QTextFormat::setObjectIndex(
int o)
1330 d->clearProperty(ObjectIndex);
1333 d =
new QTextFormatPrivate;
1335 d->insertProperty(ObjectIndex, o);
1340
1341
1342
1343
1344
1345bool QTextFormat::hasProperty(
int propertyId)
const
1347 return d ? d->hasProperty(propertyId) :
false;
1351
1352
1353
1354
1357
1358
1359QMap<
int, QVariant> QTextFormat::properties()
const
1361 QMap<
int, QVariant> map;
1363 for (
int i = 0; i < d->props.size(); ++i)
1364 map.insert(d->props.at(i).key, d->props.at(i).value);
1370
1371
1372
1373int QTextFormat::propertyCount()
const
1375 return d ? d->props.size() : 0;
1379
1380
1381
1382
1383
1387
1388
1389
1390
1391
1392bool QTextFormat::operator==(
const QTextFormat &rhs)
const
1394 if (format_type != rhs.format_type)
1400 if (d && d->props.isEmpty() && !rhs.d)
1403 if (!d && rhs.d && rhs.d->props.isEmpty())
1409 return *d == *rhs.d;
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
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1484
1485
1486
1487
1488QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}
1491
1492
1493
1494
1495
1496
1497QTextCharFormat::QTextCharFormat(
const QTextFormat &fmt)
1503
1504
1505
1506
1507
1511
1512
1513
1514
1515
1516
1517
1521
1522
1523
1524
1525
1526
1527
1530
1531
1532
1533
1534
1535
1536
1538#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1553
1554
1555
1556
1557
1558
1559
1563
1564
1565
1566
1567
1568
1569
1571#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1586
1587
1588
1589
1590
1591
1592
1596
1597
1598
1599
1600
1601
1605
1606
1607
1608
1609
1610
1614
1615
1616
1617
1618
1619
1623
1624
1625
1626
1627
1628
1632
1633
1634
1635
1636
1637
1638
1642
1643
1644
1645
1646
1647
1648
1652
1653
1654
1655
1656
1657
1658
1662
1663
1664
1665
1666
1667
1668
1669bool QTextCharFormat::fontUnderline()
const
1671 if (hasProperty(TextUnderlineStyle))
1672 return underlineStyle() == SingleUnderline;
1673 return boolProperty(FontUnderline);
1677
1678
1679
1680
1681
1684
1685
1686
1687
1688
1689void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1691 setProperty(TextUnderlineStyle, style);
1693 setProperty(FontUnderline, style == SingleUnderline);
1697
1698
1699
1700
1701
1702
1703
1707
1708
1709
1710
1711
1712
1713
1717
1718
1719
1720
1721
1722
1723
1724
1728
1729
1730
1731
1732
1733
1734
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1751
1752
1753
1754
1755
1756
1757
1758
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1775
1776
1777
1778
1779
1780
1781
1785
1786
1787
1788
1789
1790
1791
1792
1796
1797
1798
1799
1800
1801
1802
1806
1807
1808
1809
1810
1811
1812
1816
1817
1818
1819
1820
1821
1822
1825
1826
1827
1828
1829
1830
1831
1832
1835
1836
1837
1838
1839
1840
1841
1842
1845
1846
1847
1848
1849
1850
1851void QTextCharFormat::setFontFeatures(
const QMap<QFont::Tag, quint32> &fontFeatures)
1853 setProperty(FontFeatures, QVariant::fromValue(fontFeatures));
1857
1858
1859
1860
1861
1862
1863QMap<QFont::Tag, quint32> QTextCharFormat::fontFeatures()
const
1865 return property(FontFeatures).value<QMap<QFont::Tag, quint32>>();
1869
1870
1871
1872
1873
1874
1875void QTextCharFormat::setFontVariableAxes(
const QMap<QFont::Tag,
float> &fontVariableAxes)
1877 setProperty(FontVariableAxes, QVariant::fromValue(fontVariableAxes));
1881
1882
1883
1884
1885
1886
1887QMap<QFont::Tag,
float> QTextCharFormat::fontVariableAxes()
const
1889 return property(FontVariableAxes).value<QMap<QFont::Tag,
float>>();
1894
1895
1896
1897
1901
1902
1903
1904
1907
1908
1909
1910
1911
1914
1915
1916
1917
1918
1921
1922
1923
1924
1925
1926
1927
1931
1932
1933
1934
1935
1936
1937
1940
1941
1942
1943
1944
1945
1946
1949
1950
1951
1952
1953
1954
1955
1956
1959
1960
1961
1962
1963
1964
1965
1968
1969
1970
1971
1972
1973
1974
1975
1978
1979
1980
1981
1982
1983
1984
1987
1988
1989
1990
1991
1992
1993
1994
1997
1998
1999
2000
2001
2002
2003
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2022
2023
2024
2025
2026
2027
2028
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2045
2046
2047
2048
2049
2052
2053
2054
2055
2056
2057
2058
2061
2062
2063
2064
2065
2066
2067
2068QStringList QTextCharFormat::anchorNames()
const
2070 QVariant prop = property(AnchorName);
2071 if (prop.userType() == QMetaType::QStringList)
2072 return prop.toStringList();
2073 else if (prop.userType() != QMetaType::QString)
2074 return QStringList();
2075 return QStringList(prop.toString());
2080
2081
2082
2083
2084
2085
2089
2090
2091
2092
2093
2094
2095
2098
2099
2100
2101
2102
2103
2107
2108
2109
2110
2111
2112
2113
2116
2117
2118
2119
2120
2121
2122
2125
2126
2127
2128
2129
2130
2131
2134
2135
2136
2137
2138
2139
2140
2143
2144
2145
2146
2147
2148
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178void QTextCharFormat::setFont(
const QFont &font, FontPropertiesInheritanceBehavior behavior)
2180 const uint mask = behavior == FontPropertiesAll ? uint(QFont::AllPropertiesResolved)
2181 : font.resolveMask();
2183 if (mask & QFont::FamiliesResolved)
2184 setFontFamilies(font.families());
2185 if (mask & QFont::StyleNameResolved)
2186 setFontStyleName(font.styleName());
2188 if (mask & QFont::SizeResolved) {
2189 const qreal pointSize = font.pointSizeF();
2190 if (pointSize > 0) {
2191 setFontPointSize(pointSize);
2193 const int pixelSize = font.pixelSize();
2195 setProperty(QTextFormat::FontPixelSize, pixelSize);
2199 if (mask & QFont::WeightResolved)
2200 setFontWeight(font.weight());
2201 if (mask & QFont::StyleResolved)
2202 setFontItalic(font.style() != QFont::StyleNormal);
2203 if (mask & QFont::UnderlineResolved)
2204 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
2205 if (mask & QFont::OverlineResolved)
2206 setFontOverline(font.overline());
2207 if (mask & QFont::StrikeOutResolved)
2208 setFontStrikeOut(font.strikeOut());
2209 if (mask & QFont::FixedPitchResolved)
2210 setFontFixedPitch(font.fixedPitch());
2211 if (mask & QFont::CapitalizationResolved)
2212 setFontCapitalization(font.capitalization());
2213 if (mask & QFont::WordSpacingResolved)
2214 setFontWordSpacing(font.wordSpacing());
2215 if (mask & QFont::LetterSpacingResolved) {
2216 setFontLetterSpacingType(font.letterSpacingType());
2217 setFontLetterSpacing(font.letterSpacing());
2219 if (mask & QFont::StretchResolved)
2220 setFontStretch(font.stretch());
2221 if (mask & QFont::StyleHintResolved)
2222 setFontStyleHint(font.styleHint());
2223 if (mask & QFont::StyleStrategyResolved)
2224 setFontStyleStrategy(font.styleStrategy());
2225 if (mask & QFont::HintingPreferenceResolved)
2226 setFontHintingPreference(font.hintingPreference());
2227 if (mask & QFont::KerningResolved)
2228 setFontKerning(font.kerning());
2230 if (mask & QFont::FeaturesResolved) {
2231 QFontPrivate *fd = QFontPrivate::get(font);
2232 setFontFeatures(fd->features);
2234 if (mask & QFont::VariableAxesResolved) {
2235 QFontPrivate *fd = QFontPrivate::get(font);
2236 setFontVariableAxes(fd->request.variableAxisValues);
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254QFont QTextCharFormat::font()
const
2256 return d ? d->font() : QFont();
2260
2261
2262
2263
2264
2265
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
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2318
2319
2320
2321
2322QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}
2325
2326
2327
2328
2329
2330
2331QTextBlockFormat::QTextBlockFormat(
const QTextFormat &fmt)
2337
2338
2339
2340
2341
2342
2343void QTextBlockFormat::setTabPositions(
const QList<QTextOption::Tab> &tabs)
2345 QList<QVariant> list;
2346 list.reserve(tabs.size());
2347 for (
const auto &e : tabs)
2348 list.append(QVariant::fromValue(e));
2349 setProperty(TabPositions, list);
2353
2354
2355
2356
2357
2358QList<QTextOption::Tab> QTextBlockFormat::tabPositions()
const
2360 QVariant variant = property(TabPositions);
2361 if (variant.isNull())
2362 return QList<QTextOption::Tab>();
2363 QList<QTextOption::Tab> answer;
2364 const QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
2365 answer.reserve(variantsList.size());
2366 for (
const auto &e: variantsList)
2367 answer.append(qvariant_cast<QTextOption::Tab>(e));
2372
2373
2374
2375
2376
2379
2380
2381
2382
2383
2384
2388
2389
2390
2391
2392
2393
2397
2398
2399
2400
2401
2402
2406
2407
2408
2409
2410
2411
2415
2416
2417
2418
2419
2420
2424
2425
2426
2427
2428
2429
2433
2434
2435
2436
2437
2438
2442
2443
2444
2445
2446
2447
2451
2452
2453
2454
2455
2456
2457
2461
2462
2463
2464
2465
2466
2470
2471
2472
2473
2474
2475
2479
2480
2481
2482
2483
2484
2488
2489
2490
2491
2492
2493
2494
2495
2499
2500
2501
2502
2503
2504
2508
2509
2510
2511
2512
2513
2514
2515
2516
2520
2521
2522
2523
2524
2525
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2547
2548
2549
2550
2551
2552
2553
2557
2558
2559
2560
2561
2562
2563
2564
2565
2569
2570
2571
2572
2573
2574
2575
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2601
2602
2603
2604
2605
2606
2607
2608
2609
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2632
2633
2634
2635
2636
2637
2638
2642
2643
2644
2645
2646
2647
2648
2652
2653
2654
2655
2656
2657
2658
2662
2663
2664
2665
2666
2667
2668
2671
2672
2673
2674
2675
2676
2677
2678
2681
2682
2683
2684
2685
2686
2687
2690
2691
2692
2693
2694
2695
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
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2741
2742
2743
2744
2745QTextListFormat::QTextListFormat()
2746 : QTextFormat(ListFormat)
2753
2754
2755
2756
2757
2758
2759QTextListFormat::QTextListFormat(
const QTextFormat &fmt)
2765
2766
2767
2768
2769
2772
2773
2774
2775
2776
2777
2780
2781
2782
2783
2784
2785
2789
2790
2791
2792
2793
2794
2795
2796
2800
2801
2802
2803
2804
2805
2806
2807
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2823
2824
2825
2826
2827
2828
2829
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2845
2846
2847
2848
2849
2850
2851
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2870
2871
2872
2873
2874
2875
2876
2877
2880
2881
2882
2883
2884
2885
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
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2949
2950
2951
2952
2953QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)
2955 setBorderStyle(BorderStyle_Outset);
2956 setBorderBrush(Qt::darkGray);
2960
2961
2962
2963
2964
2965
2966QTextFrameFormat::QTextFrameFormat(
const QTextFormat &fmt)
2972
2973
2974
2975
2978
2979
2980
2981
2982
2985
2986
2987
2988
2991
2992
2993
2994
2997
2998
2999
3000
3003
3004
3005
3006
3007
3010
3011
3012
3013
3014
3017
3018
3019
3020
3021
3024
3025
3026
3027
3028
3031
3032
3033
3034
3035
3036
3037
3038void QTextFrameFormat::setMargin(qreal amargin)
3040 setProperty(FrameMargin, amargin);
3041 setProperty(FrameTopMargin, amargin);
3042 setProperty(FrameBottomMargin, amargin);
3043 setProperty(FrameLeftMargin, amargin);
3044 setProperty(FrameRightMargin, amargin);
3049
3050
3051
3052
3055
3056
3057
3058
3059
3062
3063
3064
3065
3066
3067qreal QTextFrameFormat::topMargin()
const
3069 if (!hasProperty(FrameTopMargin))
3071 return doubleProperty(FrameTopMargin);
3075
3076
3077
3078
3079
3082
3083
3084
3085
3086
3087qreal QTextFrameFormat::bottomMargin()
const
3089 if (!hasProperty(FrameBottomMargin))
3091 return doubleProperty(FrameBottomMargin);
3095
3096
3097
3098
3099
3102
3103
3104
3105
3106
3107qreal QTextFrameFormat::leftMargin()
const
3109 if (!hasProperty(FrameLeftMargin))
3111 return doubleProperty(FrameLeftMargin);
3115
3116
3117
3118
3119
3122
3123
3124
3125
3126
3127qreal QTextFrameFormat::rightMargin()
const
3129 if (!hasProperty(FrameRightMargin))
3131 return doubleProperty(FrameRightMargin);
3135
3136
3137
3138
3141
3142
3143
3144
3147
3148
3149
3150
3151
3152
3155
3156
3157
3158
3159
3160
3163
3164
3165
3166
3167
3168
3169
3170
3173
3174
3175
3176
3177
3178
3179
3182
3183
3184
3185
3186
3187
3190
3191
3192
3193
3196
3197
3198
3199
3200
3203
3204
3205
3206
3209
3210
3211
3212
3213
3214
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
3255
3256
3257
3258
3259QTextTableFormat::QTextTableFormat()
3260 : QTextFrameFormat()
3262 setObjectType(TableObject);
3264 setBorderCollapse(
true);
3269
3270
3271
3272
3273
3274
3275QTextTableFormat::QTextTableFormat(
const QTextFormat &fmt)
3276 : QTextFrameFormat(fmt)
3281
3282
3283
3284
3285
3289
3290
3291
3292
3296
3297
3298
3299
3300
3301
3302
3305
3306
3307
3308
3309
3310
3313
3314
3315
3316
3317
3318
3321
3322
3323
3324
3325
3326
3327
3330
3331
3332
3333
3334
3337
3338
3339
3340
3341
3342
3343
3346
3347
3348
3349
3350
3353
3354
3355
3356
3357
3360
3361
3362
3363
3364
3365
3368
3369
3370
3371
3372
3373
3376
3377
3378
3379
3380
3381
3382
3385
3386
3387
3388
3389
3390
3391
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3425
3426
3427
3428
3429
3430
3431
3434
3435
3436
3437
3438
3439
3440
3443
3444
3445
3446
3447
3448
3451
3452
3453
3454
3455
3456
3457
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3486
3487
3488
3489
3490QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }
3493
3494
3495
3496
3497
3498
3499QTextImageFormat::QTextImageFormat(
const QTextFormat &fmt)
3500 : QTextCharFormat(fmt)
3505
3506
3507
3508
3512
3513
3514
3515
3516
3517
3518
3522
3523
3524
3525
3526
3527
3528
3531
3532
3533
3534
3535
3536
3540
3541
3542
3543
3544
3545
3548
3549
3550
3551
3552
3553
3554
3558
3559
3560
3561
3562
3563
3567
3568
3569
3570
3571
3572
3576
3577
3578
3579
3580
3581
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3597
3598
3599
3600
3601
3602
3603
3606
3607
3608
3609
3610
3611
3612
3613
3614
3617
3618
3619
3620
3621
3624
3625
3626
3627
3628
3629
3630
3631
3632
3635
3636
3637
3638
3639
3640
3641
3642
3643
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3661
3662
3663
3664
3665
3666
3667
3668
3669
3672
3673
3674
3675
3676
3677
3678
3681
3682
3683
3684
3685
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3701
3702
3703
3704
3705
3706
3709
3710
3711
3712
3713
3714
3715
3718
3719
3720
3721
3722
3723
3724
3727
3728
3729
3730
3731
3732
3733
3736
3737
3738
3739
3740
3741
3742
3745
3746
3747
3748
3749
3750
3751
3754
3755
3756
3757
3758
3759
3760
3763
3764
3765
3766
3767
3768
3769
3772
3773
3774
3775
3776
3777
3778
3781
3782
3783
3784
3785
3786
3787
3790
3791
3792
3793
3794
3795
3796
3799
3800
3801
3802
3803
3806
3807
3808
3809
3810
3811
3812
3815
3816
3817
3818
3819
3822
3823
3824
3825
3826
3827
3828
3831
3832
3833
3834
3835
3838
3839
3840
3841
3842
3843
3844
3847
3848
3849
3850
3851
3854
3855
3856
3857
3858
3859
3860
3861
3864
3865
3866
3867
3868
3869
3870
3873
3874
3875
3876
3877
3880
3881
3882
3883
3884
3885
3886
3889
3890
3891
3892
3893
3896
3897
3898
3899
3900
3901
3902
3905
3906
3907
3908
3909
3912
3913
3914
3915
3916
3917
3918
3921
3922
3923
3924
3925
3928
3929
3930
3931
3932
3933
3934
3935
3938
3939
3940
3941
3942
3943
3944
3947
3948
3949
3950
3951
3954
3955
3956
3957
3958
3959
3960
3963
3964
3965
3966
3967
3970
3971
3972
3973
3974
3975
3976
3979
3980
3981
3982
3983
3986
3987
3988
3989
3990
3991
3992
3995
3996
3997
3998
3999
4002
4003
4004
4005
4006
4007
4008
4009
4012
4013
4014
4015
4016
4019
4020
4021
4022
4023
4024QTextTableCellFormat::QTextTableCellFormat()
4027 setObjectType(TableCellObject);
4031
4032
4033
4034
4035
4036
4037QTextTableCellFormat::QTextTableCellFormat(
const QTextFormat &fmt)
4038 : QTextCharFormat(fmt)
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4066QTextFormatCollection::~QTextFormatCollection()
4070void QTextFormatCollection::clear()
4077int QTextFormatCollection::indexForFormat(
const QTextFormat &format)
4079 size_t hash = getHash(format.d, format.format_type);
4080 auto i = hashes.constFind(hash);
4081 while (i != hashes.constEnd() && i.key() == hash) {
4082 if (formats.value(i.value()) == format) {
4088 int idx = formats.size();
4089 formats.append(format);
4092 QTextFormat &f = formats.last();
4094 f.d =
new QTextFormatPrivate;
4095 f.d->resolveFont(defaultFnt);
4097 hashes.insert(hash, idx);
4106bool QTextFormatCollection::hasFormatCached(
const QTextFormat &format)
const
4108 size_t hash = getHash(format.d, format.format_type);
4109 auto i = hashes.constFind(hash);
4110 while (i != hashes.constEnd() && i.key() == hash) {
4111 if (formats.value(i.value()) == format) {
4119int QTextFormatCollection::objectFormatIndex(
int objectIndex)
const
4121 if (objectIndex == -1 || objectIndex >= objFormats.size())
4123 return objFormats.at(objectIndex);
4126void QTextFormatCollection::setObjectFormatIndex(
int objectIndex,
int formatIndex)
4128 objFormats[objectIndex] = formatIndex;
4131int QTextFormatCollection::createObjectIndex(
const QTextFormat &f)
4133 const int objectIndex = objFormats.size();
4134 objFormats.append(indexForFormat(f));
4138QTextFormat QTextFormatCollection::format(
int idx)
const
4140 if (idx < 0 || idx >= formats.size())
4141 return QTextFormat();
4143 return formats.at(idx);
4146void QTextFormatCollection::setDefaultFont(
const QFont &f)
4149 for (
int i = 0; i < formats.size(); ++i)
4150 if (formats.at(i).d)
4151 formats[i].d->resolveFont(defaultFnt);
4154#ifndef QT_NO_DEBUG_STREAM
4157 QDebugStateSaver saver(dbg);
4158 dbg.nospace() <<
"QTextLength(QTextLength::Type(" << l.type() <<
"))";
4164 QDebugStateSaver saver(dbg);
4165 dbg.nospace() <<
"QTextFormat(QTextFormat::FormatType(" << f.type() <<
"))";
4173#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)