Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qglyphrun.cpp
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
4#include "qglobal.h"
5
6#if !defined(QT_NO_RAWFONT)
7
8#include "qglyphrun.h"
9#include "qglyphrun_p.h"
10#include <qdebug.h>
11
13
80{
81}
82
87{
88 d = other.d;
89}
90
95{
96 // Required for QExplicitlySharedDataPointer
97}
98
102void QGlyphRun::detach()
103{
104 if (d->ref.loadRelaxed() != 1)
105 d.detach();
106}
107
112{
113 d = other.d;
114 return *this;
115}
116
130{
131 if (d == other.d)
132 return true;
133
134 if ((d->glyphIndexDataSize != other.d->glyphIndexDataSize)
135 || (d->glyphPositionDataSize != other.d->glyphPositionDataSize)) {
136 return false;
137 }
138
139 if (d->glyphIndexData != other.d->glyphIndexData) {
140 for (int i = 0; i < d->glyphIndexDataSize; ++i) {
141 if (d->glyphIndexData[i] != other.d->glyphIndexData[i])
142 return false;
143 }
144 }
145 if (d->glyphPositionData != other.d->glyphPositionData) {
146 for (int i = 0; i < d->glyphPositionDataSize; ++i) {
147 if (d->glyphPositionData[i] != other.d->glyphPositionData[i])
148 return false;
149 }
150 }
151
152 return (d->flags == other.d->flags && d->rawFont == other.d->rawFont);
153}
154
168{
169 return d->rawFont;
170}
171
178void QGlyphRun::setRawFont(const QRawFont &rawFont)
179{
180 detach();
181 d->rawFont = rawFont;
182}
183
190{
191 if (d->glyphIndexes.constData() == d->glyphIndexData) {
192 return d->glyphIndexes;
193 } else {
195 memcpy(indexes.data(), d->glyphIndexData, d->glyphIndexDataSize * sizeof(quint32));
196 return indexes;
197 }
198}
199
205{
206 detach();
207 d->glyphIndexes = glyphIndexes; // Keep a reference to the QList to avoid copying
210}
211
216{
218 return d->glyphPositions;
219 } else {
220 QList<QPointF> glyphPositions(d->glyphPositionDataSize);
221 memcpy(glyphPositions.data(), d->glyphPositionData,
222 d->glyphPositionDataSize * sizeof(QPointF));
223 return glyphPositions;
224 }
225}
226
232{
233 detach();
234 d->glyphPositions = positions; // Keep a reference to the list to avoid copying
237}
238
243{
244 detach();
245 d->rawFont = QRawFont();
246 d->flags = { };
247
250}
251
260void QGlyphRun::setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray,
261 int size)
262{
263 detach();
264 d->glyphIndexes.clear();
266
267 d->glyphIndexData = glyphIndexArray;
268 d->glyphPositionData = glyphPositionArray;
270}
271
278{
279 return d->flags & Overline;
280}
281
288void QGlyphRun::setOverline(bool overline)
289{
291}
292
299{
300 return d->flags & Underline;
301}
302
309void QGlyphRun::setUnderline(bool underline)
310{
312}
313
320{
321 return d->flags & StrikeOut;
322}
323
330void QGlyphRun::setStrikeOut(bool strikeOut)
331{
333}
334
342{
343 return d->flags & RightToLeft;
344}
345
353void QGlyphRun::setRightToLeft(bool rightToLeft)
354{
355 setFlag(RightToLeft, rightToLeft);
356}
357
364QGlyphRun::GlyphRunFlags QGlyphRun::flags() const
365{
366 return d->flags;
367}
368
376{
377 if (d->flags.testFlag(flag) == enabled)
378 return;
379
380 detach();
381 d->flags.setFlag(flag, enabled);
382}
383
390void QGlyphRun::setFlags(GlyphRunFlags flags)
391{
392 if (d->flags == flags)
393 return;
394
395 detach();
396 d->flags = flags;
397}
398
421{
422 detach();
424}
425
434{
435 if (!d->boundingRect.isNull() || !d->rawFont.isValid())
436 return d->boundingRect;
437
438 qreal minX, minY, maxX, maxY;
439 minX = minY = maxX = maxY = 0;
440
441 for (int i = 0, n = qMin(d->glyphIndexDataSize, d->glyphPositionDataSize); i < n; ++i) {
442 QRectF glyphRect = d->rawFont.boundingRect(d->glyphIndexData[i]);
443 glyphRect.translate(d->glyphPositionData[i]);
444
445 if (i == 0) {
446 minX = glyphRect.left();
447 minY = glyphRect.top();
448 maxX = glyphRect.right();
449 maxY = glyphRect.bottom();
450 } else {
451 minX = qMin(glyphRect.left(), minX);
452 minY = qMin(glyphRect.top(), minY);
453 maxX = qMax(glyphRect.right(),maxX);
454 maxY = qMax(glyphRect.bottom(), maxY);
455 }
456 }
457
458 return QRectF(QPointF(minX, minY), QPointF(maxX, maxY));
459}
460
467{
468 return d->glyphIndexDataSize == 0
469 && d->glyphPositionDataSize == 0
470 && d->stringIndexes.isEmpty()
471 && d->sourceString.isEmpty();
472}
473
498{
499 return d->stringIndexes;
500}
501
512{
513 detach();
515}
516
526{
527 return d->sourceString;
528}
529
538void QGlyphRun::setSourceString(const QString &sourceString)
539{
540 detach();
542}
543
545
546#endif // QT_NO_RAWFONT
T loadRelaxed() const noexcept
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
QList< quint32 > glyphIndexes
Definition qglyphrun_p.h:60
QString sourceString
Definition qglyphrun_p.h:65
QGlyphRun::GlyphRunFlags flags
Definition qglyphrun_p.h:67
const quint32 * glyphIndexData
Definition qglyphrun_p.h:69
QList< QPointF > glyphPositions
Definition qglyphrun_p.h:61
const QPointF * glyphPositionData
Definition qglyphrun_p.h:72
QList< qsizetype > stringIndexes
Definition qglyphrun_p.h:62
The QGlyphRun class provides direct access to the internal glyphs in a font.
Definition qglyphrun.h:20
QList< qsizetype > stringIndexes() const
void setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray, int size)
Sets the glyph indexes and positions of this QGlyphRun to use the first size elements in the arrays g...
void setOverline(bool overline)
Indicates that this QGlyphRun should be painted with an overline decoration if overline is true.
bool overline() const
Returns true if this QGlyphRun should be painted with an overline decoration.
void setSourceString(const QString &sourceString)
void setStringIndexes(const QList< qsizetype > &stringIndexes)
bool strikeOut() const
Returns true if this QGlyphRun should be painted with a strike out decoration.
QGlyphRun()
Constructs an empty QGlyphRun object.
Definition qglyphrun.cpp:79
void setPositions(const QList< QPointF > &positions)
Sets the positions of the edge of the baseline for each glyph in this set of glyph indexes to positio...
void setFlag(GlyphRunFlag flag, bool enabled=true)
If enabled is true, then flag is enabled; otherwise, it is disabled.
void setUnderline(bool underline)
Indicates that this QGlyphRun should be painted with an underline decoration if underline is true.
void setRawFont(const QRawFont &rawFont)
Sets the font in which to look up the glyph indexes to the rawFont specified.
QString sourceString() const
QList< quint32 > glyphIndexes() const
Returns the glyph indexes for this QGlyphRun object.
bool operator==(const QGlyphRun &other) const
Compares other to this QGlyphRun object.
void setBoundingRect(const QRectF &boundingRect)
Sets the bounding rect of the glyphs in this QGlyphRun to be boundingRect.
void setRightToLeft(bool on)
Indicates that this QGlyphRun contains glyphs that should be ordered from the right to left if rightT...
QGlyphRun & operator=(const QGlyphRun &other)
Assigns other to this QGlyphRun object.
QRawFont rawFont() const
Returns the font selected for this QGlyphRun object.
GlyphRunFlags flags() const
Returns the flags set for this QGlyphRun.
@ RightToLeft
Definition qglyphrun.h:26
void setFlags(GlyphRunFlags flags)
Sets the flags of this QGlyphRun to flags.
void clear()
Clears all data in the QGlyphRun object.
void setGlyphIndexes(const QList< quint32 > &glyphIndexes)
Set the glyph indexes for this QGlyphRun object to glyphIndexes.
bool isRightToLeft() const
Returns true if this QGlyphRun contains glyphs that are painted from the right to the left.
bool isEmpty() const
Returns true if the QGlyphRun does not contain any glyphs.
~QGlyphRun()
Destroys the QGlyphRun.
Definition qglyphrun.cpp:94
void setStrikeOut(bool strikeOut)
Indicates that this QGlyphRun should be painted with an strike out decoration if strikeOut is true.
QRectF boundingRect() const
Returns the smallest rectangle that contains all glyphs in this QGlyphRun.
QList< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes.
bool underline() const
Returns true if this QGlyphRun should be painted with an underline decoration.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_pointer constData() const noexcept
Definition qlist.h:416
bool isEmpty() const noexcept
Definition qlist.h:390
pointer data()
Definition qlist.h:414
void clear()
Definition qlist.h:417
\inmodule QtCore\reentrant
Definition qpoint.h:214
The QRawFont class provides access to a single physical instance of a font.
Definition qrawfont.h:24
QRectF boundingRect(quint32 glyphIndex) const
Returns the smallest rectangle containing the glyph with the given glyphIndex.
Definition qrawfont.cpp:784
bool isValid() const
Returns true if the QRawFont is valid and false otherwise.
Definition qrawfont.cpp:182
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:499
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:496
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:644
constexpr void translate(qreal dx, qreal dy) noexcept
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position.
Definition qrect.h:724
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:497
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:498
QAtomicInt ref
Definition qshareddata.h:21
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
Combined button and popup list for selecting options.
static const QCssKnownValue positions[NumKnownPositionModes - 1]
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat minY
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbitfield flags
GLfloat n
GLfloat GLfloat GLfloat GLfloat maxX
static const QRectF boundingRect(const QPointF *points, int pointCount)
unsigned int quint32
Definition qtypes.h:45
double qreal
Definition qtypes.h:92
QSharedPointer< T > other(t)
[5]