QtBase  v6.3.1
qglyphrun.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qglobal.h"
41 
42 #if !defined(QT_NO_RAWFONT)
43 
44 #include "qglyphrun.h"
45 #include "qglyphrun_p.h"
46 #include <qdebug.h>
47 
49 
116 {
117 }
118 
123 {
124  d = other.d;
125 }
126 
131 {
132  // Required for QExplicitlySharedDataPointer
133 }
134 
138 void QGlyphRun::detach()
139 {
140  if (d->ref.loadRelaxed() != 1)
141  d.detach();
142 }
143 
148 {
149  d = other.d;
150  return *this;
151 }
152 
166 {
167  if (d == other.d)
168  return true;
169 
170  if ((d->glyphIndexDataSize != other.d->glyphIndexDataSize)
171  || (d->glyphPositionDataSize != other.d->glyphPositionDataSize)) {
172  return false;
173  }
174 
175  if (d->glyphIndexData != other.d->glyphIndexData) {
176  for (int i = 0; i < d->glyphIndexDataSize; ++i) {
177  if (d->glyphIndexData[i] != other.d->glyphIndexData[i])
178  return false;
179  }
180  }
181  if (d->glyphPositionData != other.d->glyphPositionData) {
182  for (int i = 0; i < d->glyphPositionDataSize; ++i) {
183  if (d->glyphPositionData[i] != other.d->glyphPositionData[i])
184  return false;
185  }
186  }
187 
188  return (d->flags == other.d->flags && d->rawFont == other.d->rawFont);
189 }
190 
204 {
205  return d->rawFont;
206 }
207 
214 void QGlyphRun::setRawFont(const QRawFont &rawFont)
215 {
216  detach();
217  d->rawFont = rawFont;
218 }
219 
226 {
227  if (d->glyphIndexes.constData() == d->glyphIndexData) {
228  return d->glyphIndexes;
229  } else {
231  memcpy(indexes.data(), d->glyphIndexData, d->glyphIndexDataSize * sizeof(quint32));
232  return indexes;
233  }
234 }
235 
241 {
242  detach();
243  d->glyphIndexes = glyphIndexes; // Keep a reference to the QList to avoid copying
246 }
247 
252 {
253  if (d->glyphPositions.constData() == d->glyphPositionData) {
254  return d->glyphPositions;
255  } else {
256  QList<QPointF> glyphPositions(d->glyphPositionDataSize);
257  memcpy(glyphPositions.data(), d->glyphPositionData,
258  d->glyphPositionDataSize * sizeof(QPointF));
259  return glyphPositions;
260  }
261 }
262 
268 {
269  detach();
270  d->glyphPositions = positions; // Keep a reference to the list to avoid copying
273 }
274 
279 {
280  detach();
281  d->rawFont = QRawFont();
282  d->flags = { };
283 
286 }
287 
296 void QGlyphRun::setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray,
297  int size)
298 {
299  detach();
300  d->glyphIndexes.clear();
301  d->glyphPositions.clear();
302 
303  d->glyphIndexData = glyphIndexArray;
304  d->glyphPositionData = glyphPositionArray;
306 }
307 
314 {
315  return d->flags & Overline;
316 }
317 
324 void QGlyphRun::setOverline(bool overline)
325 {
327 }
328 
335 {
336  return d->flags & Underline;
337 }
338 
345 void QGlyphRun::setUnderline(bool underline)
346 {
348 }
349 
356 {
357  return d->flags & StrikeOut;
358 }
359 
366 void QGlyphRun::setStrikeOut(bool strikeOut)
367 {
369 }
370 
378 {
379  return d->flags & RightToLeft;
380 }
381 
389 void QGlyphRun::setRightToLeft(bool rightToLeft)
390 {
391  setFlag(RightToLeft, rightToLeft);
392 }
393 
400 QGlyphRun::GlyphRunFlags QGlyphRun::flags() const
401 {
402  return d->flags;
403 }
404 
412 {
413  if (d->flags.testFlag(flag) == enabled)
414  return;
415 
416  detach();
417  d->flags.setFlag(flag, enabled);
418 }
419 
426 void QGlyphRun::setFlags(GlyphRunFlags flags)
427 {
428  if (d->flags == flags)
429  return;
430 
431  detach();
432  d->flags = flags;
433 }
434 
456 void QGlyphRun::setBoundingRect(const QRectF &boundingRect)
457 {
458  detach();
460 }
461 
470 {
471  if (!d->boundingRect.isNull() || !d->rawFont.isValid())
472  return d->boundingRect;
473 
474  qreal minX, minY, maxX, maxY;
475  minX = minY = maxX = maxY = 0;
476 
477  for (int i = 0, n = qMin(d->glyphIndexDataSize, d->glyphPositionDataSize); i < n; ++i) {
478  QRectF glyphRect = d->rawFont.boundingRect(d->glyphIndexData[i]);
479  glyphRect.translate(d->glyphPositionData[i]);
480 
481  if (i == 0) {
482  minX = glyphRect.left();
483  minY = glyphRect.top();
484  maxX = glyphRect.right();
485  maxY = glyphRect.bottom();
486  } else {
487  minX = qMin(glyphRect.left(), minX);
488  minY = qMin(glyphRect.top(), minY);
489  maxX = qMax(glyphRect.right(),maxX);
490  maxY = qMax(glyphRect.bottom(), maxY);
491  }
492  }
493 
494  return QRectF(QPointF(minX, minY), QPointF(maxX, maxY));
495 }
496 
502 bool QGlyphRun::isEmpty() const
503 {
504  return d->glyphIndexDataSize == 0;
505 }
506 
508 
509 #endif // QT_NO_RAWFONT
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
T loadRelaxed() const noexcept
Definition: qbasicatomic.h:90
The QGlyphRun class provides direct access to the internal glyphs in a font.
Definition: qglyphrun.h:56
void setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray, int size)
Definition: qglyphrun.cpp:296
void setOverline(bool overline)
Definition: qglyphrun.cpp:324
bool overline() const
Definition: qglyphrun.cpp:313
bool strikeOut() const
Definition: qglyphrun.cpp:355
void setPositions(const QList< QPointF > &positions)
Definition: qglyphrun.cpp:267
void setFlag(GlyphRunFlag flag, bool enabled=true)
Definition: qglyphrun.cpp:411
void setUnderline(bool underline)
Definition: qglyphrun.cpp:345
void setRawFont(const QRawFont &rawFont)
Definition: qglyphrun.cpp:214
QList< quint32 > glyphIndexes() const
Definition: qglyphrun.cpp:225
bool operator==(const QGlyphRun &other) const
Definition: qglyphrun.cpp:165
void setBoundingRect(const QRectF &boundingRect)
Definition: qglyphrun.cpp:456
void setRightToLeft(bool on)
Definition: qglyphrun.cpp:389
QGlyphRun & operator=(const QGlyphRun &other)
Definition: qglyphrun.cpp:147
QRawFont rawFont() const
Definition: qglyphrun.cpp:203
GlyphRunFlags flags() const
Definition: qglyphrun.cpp:400
@ StrikeOut
Definition: qglyphrun.h:61
@ RightToLeft
Definition: qglyphrun.h:62
@ Overline
Definition: qglyphrun.h:59
@ Underline
Definition: qglyphrun.h:60
void setFlags(GlyphRunFlags flags)
Definition: qglyphrun.cpp:426
void clear()
Definition: qglyphrun.cpp:278
void setGlyphIndexes(const QList< quint32 > &glyphIndexes)
Definition: qglyphrun.cpp:240
bool isRightToLeft() const
Definition: qglyphrun.cpp:377
bool isEmpty() const
Definition: qglyphrun.cpp:502
void setStrikeOut(bool strikeOut)
Definition: qglyphrun.cpp:366
QRectF boundingRect() const
Definition: qglyphrun.cpp:469
QList< QPointF > positions() const
Definition: qglyphrun.cpp:251
bool underline() const
Definition: qglyphrun.cpp:334
QList< quint32 > glyphIndexes
Definition: qglyphrun_p.h:93
QGlyphRun::GlyphRunFlags flags
Definition: qglyphrun_p.h:98
QRectF boundingRect
Definition: qglyphrun_p.h:96
const quint32 * glyphIndexData
Definition: qglyphrun_p.h:100
QList< QPointF > glyphPositions
Definition: qglyphrun_p.h:94
const QPointF * glyphPositionData
Definition: qglyphrun_p.h:103
QRawFont rawFont
Definition: qglyphrun_p.h:95
qsizetype size() const noexcept
Definition: qlist.h:414
const_pointer constData() const noexcept
Definition: qlist.h:444
pointer data()
Definition: qlist.h:442
void clear()
Definition: qlist.h:445
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QRawFont class provides access to a single physical instance of a font.
Definition: qrawfont.h:60
QRectF boundingRect(quint32 glyphIndex) const
Definition: qrawfont.cpp:820
bool isValid() const
Definition: qrawfont.cpp:218
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
constexpr qreal bottom() const noexcept
Definition: qrect.h:527
constexpr qreal left() const noexcept
Definition: qrect.h:524
constexpr bool isNull() const noexcept
Definition: qrect.h:667
constexpr void translate(qreal dx, qreal dy) noexcept
Definition: qrect.h:747
constexpr qreal top() const noexcept
Definition: qrect.h:525
constexpr qreal right() const noexcept
Definition: qrect.h:526
QAtomicInt ref
Definition: qshareddata.h:57
unsigned int quint32
Definition: qglobal.h:288
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
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
QSharedPointer< T > other(t)
[5]