Qt 4.8
qglyphrun.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qglobal.h"
43 
44 #if !defined(QT_NO_RAWFONT)
45 
46 #include "qglyphrun.h"
47 #include "qglyphrun_p.h"
48 
50 
95 {
96 }
97 
102 {
103  d = other.d;
104 }
105 
110 {
111  // Required for QExplicitlySharedDataPointer
112 }
113 
118 {
119  if (d->ref != 1)
120  d.detach();
121 }
122 
127 {
128  d = other.d;
129  return *this;
130 }
131 
136 bool QGlyphRun::operator==(const QGlyphRun &other) const
137 {
138  if (d == other.d)
139  return true;
140 
141  if ((d->glyphIndexDataSize != other.d->glyphIndexDataSize)
143  return false;
144  }
145 
146  if (d->glyphIndexData != other.d->glyphIndexData) {
147  for (int i = 0; i < d->glyphIndexDataSize; ++i) {
148  if (d->glyphIndexData[i] != other.d->glyphIndexData[i])
149  return false;
150  }
151  }
152  if (d->glyphPositionData != other.d->glyphPositionData) {
153  for (int i = 0; i < d->glyphPositionDataSize; ++i) {
154  if (d->glyphPositionData[i] != other.d->glyphPositionData[i])
155  return false;
156  }
157  }
158 
159  return (d->overline == other.d->overline
160  && d->underline == other.d->underline
161  && d->strikeOut == other.d->strikeOut
162  && d->rawFont == other.d->rawFont);
163 }
164 
181 {
182  return d->rawFont;
183 }
184 
192 {
193  detach();
194  d->rawFont = rawFont;
195 }
196 
203 {
204  if (d->glyphIndexes.constData() == d->glyphIndexData) {
205  return d->glyphIndexes;
206  } else {
208  qMemCopy(indexes.data(), d->glyphIndexData, d->glyphIndexDataSize * sizeof(quint32));
209  return indexes;
210  }
211 }
212 
218 {
219  detach();
220  d->glyphIndexes = glyphIndexes; // Keep a reference to the QVector to avoid copying
221  d->glyphIndexData = glyphIndexes.constData();
222  d->glyphIndexDataSize = glyphIndexes.size();
223 }
224 
229 {
231  return d->glyphPositions;
232  } else {
233  QVector<QPointF> glyphPositions(d->glyphPositionDataSize);
234  qMemCopy(glyphPositions.data(), d->glyphPositionData,
235  d->glyphPositionDataSize * sizeof(QPointF));
236  return glyphPositions;
237  }
238 }
239 
245 {
246  detach();
247  d->glyphPositions = positions; // Keep a reference to the vector to avoid copying
248  d->glyphPositionData = positions.constData();
249  d->glyphPositionDataSize = positions.size();
250 }
251 
256 {
257  detach();
258  d->rawFont = QRawFont();
259  d->strikeOut = false;
260  d->overline = false;
261  d->underline = false;
262 
265 }
266 
275 void QGlyphRun::setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray,
276  int size)
277 {
278  detach();
279  d->glyphIndexes.clear();
281 
282  d->glyphIndexData = glyphIndexArray;
283  d->glyphPositionData = glyphPositionArray;
285 }
286 
293 {
294  return d->overline;
295 }
296 
304 {
305  if (d->overline == overline)
306  return;
307 
308  detach();
309  d->overline = overline;
310 }
311 
318 {
319  return d->underline;
320 }
321 
329 {
330  if (d->underline == underline)
331  return;
332 
333  detach();
334  d->underline = underline;
335 }
336 
343 {
344  return d->strikeOut;
345 }
346 
354 {
355  if (d->strikeOut == strikeOut)
356  return;
357 
358  detach();
359  d->strikeOut = strikeOut;
360 }
361 
363 
364 #endif // QT_NO_RAWFONT
QAtomicInt ref
Definition: qshareddata.h:59
bool operator==(const QGlyphRun &other) const
Compares other to this QGlyphRun object.
Definition: qglyphrun.cpp:136
double d
Definition: qnumeric_p.h:62
QGlyphRun()
Constructs an empty QGlyphRun object.
Definition: qglyphrun.cpp:94
bool overline() const
Returns true if this QGlyphRun should be painted with an overline decoration.
Definition: qglyphrun.cpp:292
void setStrikeOut(bool strikeOut)
Indicates that this QGlyphRun should be painted with an strike out decoration if strikeOut is true...
Definition: qglyphrun.cpp:353
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
~QGlyphRun()
Destroys the QGlyphRun.
Definition: qglyphrun.cpp:109
void setUnderline(bool underline)
Indicates that this QGlyphRun should be painted with an underline decoration if underline is true...
Definition: qglyphrun.cpp:328
QExplicitlySharedDataPointer< QGlyphRunPrivate > d
Definition: qglyphrun.h:104
void setPositions(const QVector< QPointF > &positions)
Sets the positions of the edge of the baseline for each glyph in this set of glyph indexes to positio...
Definition: qglyphrun.cpp:244
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QVector< quint32 > glyphIndexes
Definition: qglyphrun_p.h:96
QVector< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes...
Definition: qglyphrun.cpp:228
const quint32 * glyphIndexData
Definition: qglyphrun_p.h:104
QRawFont rawFont
Definition: qglyphrun_p.h:98
void detach()
Definition: qglyphrun.cpp:117
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QVector< quint32 > glyphIndexes() const
Returns the glyph indexes for this QGlyphRun object.
Definition: qglyphrun.cpp:202
The QGlyphRun class provides direct access to the internal glyphs in a font.
Definition: qglyphrun.h:59
QRawFont rawFont() const
Returns the font selected for this QGlyphRun object.
Definition: qglyphrun.cpp:180
const QPointF * glyphPositionData
Definition: qglyphrun_p.h:107
void * qMemCopy(void *dest, const void *src, size_t n)
Definition: qglobal.cpp:2508
void clear()
Clears all data in the QGlyphRun object.
Definition: qglyphrun.cpp:255
bool underline() const
Returns true if this QGlyphRun should be painted with an underline decoration.
Definition: qglyphrun.cpp:317
void setOverline(bool overline)
Indicates that this QGlyphRun should be painted with an overline decoration if overline is true...
Definition: qglyphrun.cpp:303
The QRawFont class provides access to a single physical instance of a font.
Definition: qrawfont.h:63
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...
Definition: qglyphrun.cpp:275
QVector< QPointF > glyphPositions
Definition: qglyphrun_p.h:97
unsigned int quint32
Definition: qglobal.h:938
void detach()
If the shared data object&#39;s reference count is greater than 1, this function creates a deep copy of t...
Definition: qshareddata.h:148
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
bool strikeOut() const
Returns true if this QGlyphRun should be painted with a strike out decoration.
Definition: qglyphrun.cpp:342
QGlyphRun & operator=(const QGlyphRun &other)
Assigns other to this QGlyphRun object.
Definition: qglyphrun.cpp:126
void setGlyphIndexes(const QVector< quint32 > &glyphIndexes)
Set the glyph indexes for this QGlyphRun object to glyphIndexes.
Definition: qglyphrun.cpp:217
void setRawFont(const QRawFont &rawFont)
Sets the font specified by rawFont to be the font used to look up the glyph indexes.
Definition: qglyphrun.cpp:191