Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtextboundaryfinder.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:trivial-impl-only
4
5#ifndef QTEXTBOUNDARYFINDER_H
6#define QTEXTBOUNDARYFINDER_H
7
8#include <QtCore/qchar.h>
9#include <QtCore/qstring.h>
10
11#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
12# include <array>
13#endif
14
16
17struct QCharAttributes;
18
19class Q_CORE_EXPORT QTextBoundaryFinder
20{
21public:
22 QTextBoundaryFinder();
23 QTextBoundaryFinder(const QTextBoundaryFinder &other);
24 QTextBoundaryFinder(QTextBoundaryFinder &&other) noexcept
25 : s{std::move(other.s)},
26 sv{other.sv},
27 pos{other.pos},
28 attributes{std::exchange(other.attributes, nullptr)}
29 {
30 t = other.t;
31 freeBuffer = other.freeBuffer;
32 QT7_ONLY(reserved = other.reserved;)
33 }
34 QTextBoundaryFinder &operator=(const QTextBoundaryFinder &other);
35 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QTextBoundaryFinder)
36 ~QTextBoundaryFinder();
37
38 void swap(QTextBoundaryFinder &other) noexcept
39 {
40 std::swap(t, other.t);
41 s.swap(other.s);
42 std::swap(sv, other.sv);
43 std::swap(pos, other.pos);
44 std::swap(freeBuffer, other.freeBuffer);
45 qt_ptr_swap(attributes, other.attributes);
46 QT7_ONLY(reserved.swap(other.reserved);)
47 }
48
49 enum BoundaryType QT7_ONLY(: quint8) {
50 Grapheme,
51 Word,
52 Sentence,
53 Line
54 };
55
56 enum BoundaryReason {
57 NotAtBoundary = 0,
58 BreakOpportunity = 0x1f,
59 StartOfItem = 0x20,
60 EndOfItem = 0x40,
61 MandatoryBreak = 0x80,
62 SoftHyphen = 0x100
63 };
64 Q_DECLARE_FLAGS( BoundaryReasons, BoundaryReason )
65
66 QTextBoundaryFinder(BoundaryType type, const QString &string);
67 QTextBoundaryFinder(BoundaryType type, const QChar *chars, qsizetype length, unsigned char *buffer = nullptr, qsizetype bufferSize = 0)
68 : QTextBoundaryFinder(type, QStringView(chars, length), buffer, bufferSize)
69 {}
70 QTextBoundaryFinder(BoundaryType type, QStringView str, unsigned char *buffer = nullptr, qsizetype bufferSize = 0);
71
72 inline bool isValid() const { return attributes; }
73
74 inline BoundaryType type() const { return t; }
75 QString string() const;
76
77 void toStart();
78 void toEnd();
79 qsizetype position() const;
80 void setPosition(qsizetype position);
81
82 qsizetype toNextBoundary();
83 qsizetype toPreviousBoundary();
84
85 bool isAtBoundary() const;
86 BoundaryReasons boundaryReasons() const;
87
88private:
89 QT6_ONLY(BoundaryType t = Grapheme;)
90 QString s;
91 QStringView sv;
92 qsizetype pos = 0;
93 QT6_ONLY(uint freeBuffer = true;)
94 QCharAttributes *attributes = nullptr;
95#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
96 bool freeBuffer = true;
97 BoundaryType t = Grapheme;
98 std::array<quint8, sizeof(void *) - 2> reserved = {};
99#endif
100};
101
103
104Q_DECLARE_OPERATORS_FOR_FLAGS(QTextBoundaryFinder::BoundaryReasons)
105
106QT_END_NAMESPACE
107
108#endif
friend class QFontEngine
Definition qpainter.h:432
friend class QTextEngine
Definition qpainter.h:445
Internal QTextItem.
void initWithScriptItem(const QScriptItem &si)
QTextItemInt midItem(QFontEngine *fontEngine, int firstGlyphIndex, int numGlyphs) const
const QFont * f
const unsigned short * logClusters
QTextItemInt(const QGlyphLayout &g, QFont *font, const QChar *chars, int numChars, QFontEngine *fe, const QTextCharFormat &format=QTextCharFormat())
QFontEngine * fontEngine
QTextItemInt(const QScriptItem &si, QFont *font, const QTextCharFormat &format=QTextCharFormat())
#define QStringLiteral(str)
Definition qstring.h:1826
QTransform qt_true_matrix(qreal w, qreal h, const QTransform &x)
Q_DECLARE_TYPEINFO(QJustificationPoint, Q_PRIMITIVE_TYPE)
JustificationClass
@ Justification_Arabic_Alef
@ Justification_Arabic_Waw
@ Justification_Arabic_Kashida
@ Justification_Space
@ Justification_Prohibited
@ Justification_Arabic_BaRa
@ Justification_Character
@ Justification_Arabic_Space
@ Justification_Arabic_HahDal
@ Justification_Arabic_Seen
@ Justification_Arabic_Normal
static bool prevCharJoins(const QString &string, int pos)
static QString stringMidRetainingBidiCC(const QString &string, const QString &ellidePrefix, const QString &ellideSuffix, int subStringFrom, int subStringTo, int midStart, int midLength)
static void applyVisibilityRules(ushort ucs, QGlyphLayout *glyphs, uint glyphPosition, QFontEngine *fontEngine)
static void set(QJustificationPoint *point, int type, const QGlyphLayout &glyph, QFontEngine *fe)
static bool nextCharJoins(const QString &string, int pos)
static constexpr bool isRetainableControlCode(char16_t c) noexcept
#define BIDI_DEBUG
static void releaseCachedFontEngine(QFontEngine *fontEngine)
QList< QScriptItem > QScriptItemArray
QGlyphJustification * justifications
void grow(char *address, int totalGlyphs)
void copy(QGlyphLayout *other)
QGlyphLayout(char *address, int totalGlyphs)
void clear(int first=0, int last=-1)
QGlyphAttributes * attributes
glyph_t * glyphs
QGlyphLayout mid(int position, int n=-1) const
unsigned short num_glyphs
bool getSelectionBounds(QFixed *selectionX, QFixed *selectionWidth) const