Qt 4.8
Public Types | Public Functions | Static Public Functions | Properties | Friends | List of all members
QRawFont Class Reference

The QRawFont class provides access to a single physical instance of a font. More...

#include <qrawfont.h>

Public Types

enum  AntialiasingType { PixelAntialiasing, SubPixelAntialiasing }
 This enum represents the different ways a glyph can be rasterized in the function alphaMapForGlyph(). More...
 

Public Functions

QVector< QPointFadvancesForGlyphIndexes (const QVector< quint32 > &glyphIndexes) const
 Returns the QRawFont's advances for each of the glyphIndexes in pixel units. More...
 
bool advancesForGlyphIndexes (const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const
 Returns the QRawFont's advances for each of the glyphIndexes in pixel units. More...
 
QImage alphaMapForGlyph (quint32 glyphIndex, AntialiasingType antialiasingType=SubPixelAntialiasing, const QTransform &transform=QTransform()) const
 This function returns a rasterized image of the glyph at the given glyphIndex in the underlying font, using the transform specified. More...
 
qreal ascent () const
 Returns the ascent of this QRawFont in pixel units. More...
 
qreal averageCharWidth () const
 Returns the average character width of this QRawFont in pixel units. More...
 
qreal descent () const
 Returns the descent of this QRawFont in pixel units. More...
 
QString familyName () const
 Returns the family name of this QRawFont. More...
 
QByteArray fontTable (const char *tagName) const
 Retrieves the sfnt table named tagName from the underlying physical font, or an empty byte array if no such table was found. More...
 
bool glyphIndexesForChars (const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const
 Converts a string of unicode points to glyph indexes using the CMAP table in the underlying font. More...
 
QVector< quint32glyphIndexesForString (const QString &text) const
 Converts the string of unicode points given by text to glyph indexes using the CMAP table in the underlying font, and returns a vector containing the result. More...
 
QFont::HintingPreference hintingPreference () const
 Returns the hinting preference used to construct this QRawFont. More...
 
bool isValid () const
 Returns true if the QRawFont is valid and false otherwise. More...
 
qreal leading () const
 Returns the leading of this QRawFont in pixel units. More...
 
void loadFromData (const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference)
 Replaces the current QRawFont with the font contained in the supplied fontData for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference. More...
 
void loadFromFile (const QString &fileName, qreal pixelSize, QFont::HintingPreference hintingPreference)
 Replaces the current QRawFont with the contents of the file referenced by fileName for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference. More...
 
qreal maxCharWidth () const
 Returns the width of the widest character in the font. More...
 
bool operator!= (const QRawFont &other) const
 Returns true if this QRawFont is not equal to other. More...
 
QRawFontoperator= (const QRawFont &other)
 Assigns other to this QRawFont. More...
 
bool operator== (const QRawFont &other) const
 Returns true if this QRawFont is equal to other. More...
 
QPainterPath pathForGlyph (quint32 glyphIndex) const
 This function returns the shape of the glyph at a given glyphIndex in the underlying font if the QRawFont is valid. More...
 
qreal pixelSize () const
 Returns the pixel size set for this QRawFont. More...
 
 QRawFont ()
 Constructs an invalid QRawFont. More...
 
 QRawFont (const QString &fileName, qreal pixelSize, QFont::HintingPreference hintingPreference=QFont::PreferDefaultHinting)
 Constructs a QRawFont representing the font contained in the file referenced by fileName for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference. More...
 
 QRawFont (const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference=QFont::PreferDefaultHinting)
 Constructs a QRawFont representing the font contained in the supplied fontData for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference. More...
 
 QRawFont (const QRawFont &other)
 Creates a QRawFont which is a copy of other. More...
 
void setPixelSize (qreal pixelSize)
 Sets the pixel size with which this font should be rendered to pixelSize. More...
 
QFont::Style style () const
 Returns the style of this QRawFont. More...
 
QString styleName () const
 Returns the style name of this QRawFont. More...
 
QList< QFontDatabase::WritingSystemsupportedWritingSystems () const
 Returns a list of writing systems supported by the font according to designer supplied information in the font file. More...
 
bool supportsCharacter (quint32 ucs4) const
 Returns true if the font has a glyph that corresponds to the UCS-4 encoded character ucs4. More...
 
bool supportsCharacter (QChar character) const
 Returns true if the font has a glyph that corresponds to the given character. More...
 
qreal unitsPerEm () const
 Returns the number of design units define the width and height of the em square for this QRawFont. More...
 
int weight () const
 Returns the weight of this QRawFont. More...
 
qreal xHeight () const
 Returns the xHeight of this QRawFont in pixel units. More...
 
 ~QRawFont ()
 Destroys the QRawFont. More...
 

Static Public Functions

static QRawFont fromFont (const QFont &font, QFontDatabase::WritingSystem writingSystem=QFontDatabase::Any)
 Fetches the physical representation based on a font query. More...
 

Properties

QExplicitlySharedDataPointer< QRawFontPrivated
 

Friends

class QRawFontPrivate
 

Detailed Description

The QRawFont class provides access to a single physical instance of a font.

Since
4.8
Note
QRawFont is a low level class. For most purposes QFont is a more appropriate class.

Most commonly, when presenting text in a user interface, the exact fonts used to render the characters is to some extent unknown. This can be the case for several reasons: For instance, the actual, physical fonts present on the target system could be unexpected to the developers, or the text could contain user selected styles, sizes or writing systems that are not supported by font chosen in the code.

Therefore, Qt's QFont class really represents a query for fonts. When text is interpreted, Qt will do its best to match the text to the query, but depending on the support, different fonts can be used behind the scenes.

For most use cases, this is both expected and necessary, as it minimizes the possibility of text in the user interface being undisplayable. In some cases, however, more direct control over the process might be useful. It is for these use cases the QRawFont class exists.

A QRawFont object represents a single, physical instance of a given font in a given pixel size. I.e. in the typical case it represents a set of TrueType or OpenType font tables and uses a user specified pixel size to convert metrics into logical pixel units. It can be used in combination with the QGlyphRun class to draw specific glyph indexes at specific positions, and also have accessors to some relevant data in the physical font.

QRawFont only provides support for the main font technologies: GDI and DirectWrite on Windows platforms, FreeType on Symbian and Linux platforms and CoreText on Mac OS X. For other font back-ends, the APIs will be disabled.

QRawFont can be constructed in a number of ways:

QRawFont is considered local to the thread in which it is constructed (either using a constructor, or by calling loadFromData() or loadFromFile()). The QRawFont cannot be moved to a different thread, but will have to be recreated in the thread in question.

Note
For the requirement of caching glyph indexes and font selections for static text to avoid reshaping and relayouting in the inner loop of an application, a better choice is the QStaticText class, since it optimizes the memory cost of the cache and also provides the possibility of paint engine specific caches for an additional speed-up.

Definition at line 63 of file qrawfont.h.

Enumerations

◆ AntialiasingType

This enum represents the different ways a glyph can be rasterized in the function alphaMapForGlyph().

  • PixelAntialiasing Will rasterize by measuring the coverage of the shape on whole pixels. The returned image contains the alpha values of each pixel based on the coverage of the glyph shape.
  • SubPixelAntialiasing Will rasterize by measuring the coverage of each subpixel, returning a separate alpha value for each of the red, green and blue components of each pixel.
Enumerator
PixelAntialiasing 
SubPixelAntialiasing 

Definition at line 66 of file qrawfont.h.

Constructors and Destructors

◆ QRawFont() [1/4]

QRawFont::QRawFont ( )

Constructs an invalid QRawFont.

Definition at line 134 of file qrawfont.cpp.

135  : d(new QRawFontPrivate)
136 {
137 }
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ QRawFont() [2/4]

QRawFont::QRawFont ( const QString fileName,
qreal  pixelSize,
QFont::HintingPreference  hintingPreference = QFont::PreferDefaultHinting 
)

Constructs a QRawFont representing the font contained in the file referenced by fileName for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference.

Note
The referenced file must contain a TrueType or OpenType font.

Definition at line 146 of file qrawfont.cpp.

149  : d(new QRawFontPrivate)
150 {
152 }
qreal pixelSize() const
Returns the pixel size set for this QRawFont.
Definition: qrawfont.cpp:367
void loadFromFile(const QString &fileName, qreal pixelSize, QFont::HintingPreference hintingPreference)
Replaces the current QRawFont with the contents of the file referenced by fileName for the size (in p...
Definition: qrawfont.cpp:210
QFont::HintingPreference hintingPreference() const
Returns the hinting preference used to construct this QRawFont.
Definition: qrawfont.cpp:539
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ QRawFont() [3/4]

QRawFont::QRawFont ( const QByteArray fontData,
qreal  pixelSize,
QFont::HintingPreference  hintingPreference = QFont::PreferDefaultHinting 
)

Constructs a QRawFont representing the font contained in the supplied fontData for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference.

Note
The data must contain a TrueType or OpenType font.

Definition at line 161 of file qrawfont.cpp.

164  : d(new QRawFontPrivate)
165 {
167 }
void loadFromData(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference)
Replaces the current QRawFont with the font contained in the supplied fontData for the size (in pixel...
Definition: qrawfont.cpp:228
qreal pixelSize() const
Returns the pixel size set for this QRawFont.
Definition: qrawfont.cpp:367
QFont::HintingPreference hintingPreference() const
Returns the hinting preference used to construct this QRawFont.
Definition: qrawfont.cpp:539
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ QRawFont() [4/4]

QRawFont::QRawFont ( const QRawFont other)

Creates a QRawFont which is a copy of other.

Definition at line 172 of file qrawfont.cpp.

173 {
174  d = other.d;
175 }
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ ~QRawFont()

QRawFont::~QRawFont ( )

Destroys the QRawFont.

Definition at line 180 of file qrawfont.cpp.

181 {
182 }

Functions

◆ advancesForGlyphIndexes() [1/2]

QVector< QPointF > QRawFont::advancesForGlyphIndexes ( const QVector< quint32 > &  glyphIndexes) const

Returns the QRawFont's advances for each of the glyphIndexes in pixel units.

The advances give the distance from the position of a given glyph to where the next glyph should be drawn to make it appear as if the two glyphs are unspaced.

See also
QTextLine::horizontalAdvance(), QFontMetricsF::width()

Definition at line 486 of file qrawfont.cpp.

487 {
488  if (!d->isValid())
489  return QVector<QPointF>();
490 
491  int numGlyphs = glyphIndexes.size();
492  QVarLengthGlyphLayoutArray glyphs(numGlyphs);
493  qMemCopy(glyphs.glyphs, glyphIndexes.data(), numGlyphs * sizeof(quint32));
494 
495  d->fontEngine->recalcAdvances(&glyphs, 0);
496 
497  QVector<QPointF> advances;
498  for (int i=0; i<numGlyphs; ++i)
499  advances.append(QPointF(glyphs.advances_x[i].toReal(), glyphs.advances_y[i].toReal()));
500 
501  return advances;
502 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const
void * qMemCopy(void *dest, const void *src, size_t n)
Definition: qglobal.cpp:2508
bool isValid() const
Definition: qrawfont_p.h:97
unsigned int quint32
Definition: qglobal.h:938
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ advancesForGlyphIndexes() [2/2]

bool QRawFont::advancesForGlyphIndexes ( const quint32 glyphIndexes,
QPointF advances,
int  numGlyphs 
) const

Returns the QRawFont's advances for each of the glyphIndexes in pixel units.

The advances give the distance from the position of a given glyph to where the next glyph should be drawn to make it appear as if the two glyphs are unspaced. The glyph indexes are given with the array glyphIndexes while the results are returned through advances, both of them must have numGlyphs elements.

See also
QTextLine::horizontalAdvance(), QFontMetricsF::width()

Definition at line 513 of file qrawfont.cpp.

514 {
515  if (!d->isValid())
516  return false;
517 
518  QGlyphLayout glyphs;
519  glyphs.glyphs = const_cast<HB_Glyph *>(glyphIndexes);
520  glyphs.numGlyphs = numGlyphs;
521  QVarLengthArray<QFixed> advances_x(numGlyphs);
522  QVarLengthArray<QFixed> advances_y(numGlyphs);
523  glyphs.advances_x = advances_x.data();
524  glyphs.advances_y = advances_y.data();
525 
526  d->fontEngine->recalcAdvances(&glyphs, 0);
527 
528  for (int i=0; i<numGlyphs; ++i)
529  advances[i] = QPointF(glyphs.advances_x[i].toReal(), glyphs.advances_y[i].toReal());
530 
531  return true;
532 }
QFixed * advances_y
QFixed * advances_x
HB_Glyph * glyphs
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const
bool isValid() const
Definition: qrawfont_p.h:97
qreal toReal() const
Definition: qfixed_p.h:77
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ alphaMapForGlyph()

QImage QRawFont::alphaMapForGlyph ( quint32  glyphIndex,
AntialiasingType  antialiasingType = SubPixelAntialiasing,
const QTransform transform = QTransform() 
) const

This function returns a rasterized image of the glyph at the given glyphIndex in the underlying font, using the transform specified.

If the QRawFont is not valid, this function will return an invalid QImage.

If antialiasingType is set to QRawFont::SubPixelAntialiasing, then the resulting image will be in QImage::Format_RGB32 and the RGB values of each pixel will represent the subpixel opacities of the pixel in the rasterization of the glyph. Otherwise, the image will be in the format of QImage::Format_Indexed8 and each pixel will contain the opacity of the pixel in the rasterization.

See also
pathForGlyph(), QPainter::drawGlyphRun()

Definition at line 252 of file qrawfont.cpp.

254 {
255  if (!d->isValid())
256  return QImage();
257 
258  if (antialiasingType == SubPixelAntialiasing)
259  return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), 0, transform);
260 
261  return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
262 }
virtual QImage alphaMapForGlyph(glyph_t)
virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, int margin, const QTransform &t)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ ascent()

qreal QRawFont::ascent ( ) const

Returns the ascent of this QRawFont in pixel units.

See also
QFontMetricsF::ascent()

Definition at line 305 of file qrawfont.cpp.

306 {
307  return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
308 }
virtual QFixed ascent() const =0
bool isValid() const
Definition: qrawfont_p.h:97
qreal toReal() const
Definition: qfixed_p.h:77
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ averageCharWidth()

qreal QRawFont::averageCharWidth ( ) const

Returns the average character width of this QRawFont in pixel units.

See also
QFontMetricsF::averageCharWidth()

Definition at line 345 of file qrawfont.cpp.

346 {
347  return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
348 }
virtual QFixed averageCharWidth() const
bool isValid() const
Definition: qrawfont_p.h:97
qreal toReal() const
Definition: qfixed_p.h:77
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ descent()

qreal QRawFont::descent ( ) const

Returns the descent of this QRawFont in pixel units.

See also
QFontMetricsF::descent()

Definition at line 315 of file qrawfont.cpp.

316 {
317  return d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
318 }
virtual QFixed descent() const =0
bool isValid() const
Definition: qrawfont_p.h:97
qreal toReal() const
Definition: qfixed_p.h:77
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ familyName()

QString QRawFont::familyName ( ) const

Returns the family name of this QRawFont.

Definition at line 388 of file qrawfont.cpp.

Referenced by fromFont().

389 {
390  return d->isValid() ? d->fontEngine->fontDef.family : QString();
391 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QFontDef fontDef
QString family
Definition: qfont_p.h:82
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ fontTable()

QByteArray QRawFont::fontTable ( const char *  tagName) const

Retrieves the sfnt table named tagName from the underlying physical font, or an empty byte array if no such table was found.

The returned font table's byte order is Big Endian, like the sfnt format specifies. The tagName must be four characters long and should be formatted in the default endianness of the current platform.

Definition at line 550 of file qrawfont.cpp.

Referenced by supportedWritingSystems().

551 {
552  if (!d->isValid())
553  return QByteArray();
554 
555  const quint32 *tagId = reinterpret_cast<const quint32 *>(tagName);
556  return d->fontEngine->getSfntTable(qToBigEndian(*tagId));
557 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
T qToBigEndian(T source)
Definition: qendian.h:337
bool isValid() const
Definition: qrawfont_p.h:97
unsigned int quint32
Definition: qglobal.h:938
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138
QByteArray getSfntTable(uint) const

◆ fromFont()

QRawFont QRawFont::fromFont ( const QFont font,
QFontDatabase::WritingSystem  writingSystem = QFontDatabase::Any 
)
static

Fetches the physical representation based on a font query.

The physical font returned is the font that will be preferred by Qt in order to display text in the selected writingSystem.

Definition at line 640 of file qrawfont.cpp.

641 {
642  QRawFont rawFont;
643 #if defined(Q_WS_MAC)
645  layout.beginLayout();
646  QTextLine line = layout.createLine();
647  layout.endLayout();
648  QList<QGlyphRun> list = layout.glyphRuns();
649  if (list.size()) {
650  // Pick the one matches the family name we originally requested,
651  // if none of them match, just pick the first one
652  for (int i = 0; i < list.size(); i++) {
653  rawFont = list.at(i).rawFont();
654  if (rawFont.familyName() == font.family())
655  return rawFont;
656  }
657  return list.at(0).rawFont();
658  }
659 #else
660  QFontPrivate *font_d = QFontPrivate::get(font);
661  int script = qt_script_for_writing_system(writingSystem);
662  QFontEngine *fe = font_d->engineForScript(script);
663 
664  if (fe != 0 && fe->type() == QFontEngine::Multi) {
665  QFontEngineMulti *multiEngine = static_cast<QFontEngineMulti *>(fe);
666  fe = multiEngine->engine(0);
667  if (fe == 0) {
668  multiEngine->loadEngine(0);
669  fe = multiEngine->engine(0);
670  }
671  }
672 
673  if (fe != 0) {
674  rawFont.d.data()->fontEngine = fe;
675  rawFont.d.data()->fontEngine->ref.ref();
676  rawFont.d.data()->hintingPreference = font.hintingPreference();
677  }
678 #endif
679  return rawFont;
680 }
QAtomicInt ref
HintingPreference hintingPreference() const
Returns the currently preferred hinting level for glyphs rendered with this font. ...
Definition: qfont.cpp:1088
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static QFontPrivate * get(const QFont &font)
Definition: qfont_p.h:202
bool ref()
Atomically increments the value of this QAtomicInt.
virtual Type type() const =0
int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem)
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const char * layout
QRawFont rawFont() const
Returns the font selected for this QGlyphRun object.
Definition: qglyphrun.cpp:180
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
static QString writingSystemSample(WritingSystem writingSystem)
Returns a string with sample characters from writingSystem.
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
virtual void loadEngine(int at)=0
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
The QRawFont class provides access to a single physical instance of a font.
Definition: qrawfont.h:63
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QFont::HintingPreference hintingPreference
Definition: qrawfont_p.h:112
QString familyName() const
Returns the family name of this QRawFont.
Definition: qrawfont.cpp:388
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138
QFontEngine * engine(int at) const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ glyphIndexesForChars()

bool QRawFont::glyphIndexesForChars ( const QChar chars,
int  numChars,
quint32 glyphIndexes,
int *  numGlyphs 
) const

Converts a string of unicode points to glyph indexes using the CMAP table in the underlying font.

The function works like glyphIndexesForString() except it take an array (chars), the results will be returned though glyphIndexes array and number of glyphs will be set in numGlyphs. The size of glyphIndexes array must be at least numChars, if that's still not enough, this function will return false, then you can resize glyphIndexes from the size returned in numGlyphs.

See also
glyphIndexesForString(), advancesForGlyphIndexes(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns()

Definition at line 469 of file qrawfont.cpp.

Referenced by glyphIndexesForString().

470 {
471  if (!d->isValid())
472  return false;
473 
474  QGlyphLayout glyphs;
475  glyphs.glyphs = glyphIndexes;
476  return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QTextEngine::GlyphIndicesOnly);
477 }
HB_Glyph * glyphs
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ glyphIndexesForString()

QVector< quint32 > QRawFont::glyphIndexesForString ( const QString text) const

Converts the string of unicode points given by text to glyph indexes using the CMAP table in the underlying font, and returns a vector containing the result.

Note that, in cases where there are other tables in the font that affect the shaping of the text, the returned glyph indexes will not correctly represent the rendering of the text. To get the correctly shaped text, you can use QTextLayout to lay out and shape the text, then call QTextLayout::glyphs() to get the set of glyph index list and QRawFont pairs.

See also
advancesForGlyphIndexes(), glyphIndexesForChars(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns()

Definition at line 436 of file qrawfont.cpp.

437 {
438  if (!d->isValid())
439  return QVector<quint32>();
440 
441  int nglyphs = text.size();
442  QVarLengthGlyphLayoutArray glyphs(nglyphs);
443  if (!glyphIndexesForChars(text.data(), text.size(), glyphs.glyphs, &nglyphs)) {
444  glyphs.resize(nglyphs);
445  if (!glyphIndexesForChars(text.data(), text.size(), glyphs.glyphs, &nglyphs)) {
446  Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice");
447  return QVector<quint32>();
448  }
449  }
450 
451  QVector<quint32> glyphIndexes;
452  for (int i=0; i<nglyphs; ++i)
453  glyphIndexes.append(glyphs.glyphs[i]);
454 
455  return glyphIndexes;
456 }
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
bool isValid() const
Definition: qrawfont_p.h:97
bool glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const
Converts a string of unicode points to glyph indexes using the CMAP table in the underlying font...
Definition: qrawfont.cpp:469
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ hintingPreference()

QFont::HintingPreference QRawFont::hintingPreference ( ) const

Returns the hinting preference used to construct this QRawFont.

See also
QFont::hintingPreference()

Definition at line 539 of file qrawfont.cpp.

Referenced by QRawFontPrivate::cleanUp(), loadFromData(), and loadFromFile().

540 {
542 }
bool isValid() const
Definition: qrawfont_p.h:97
QFont::HintingPreference hintingPreference
Definition: qrawfont_p.h:112
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ isValid()

bool QRawFont::isValid ( ) const

Returns true if the QRawFont is valid and false otherwise.

Definition at line 196 of file qrawfont.cpp.

Referenced by QPainter::drawGlyphRun().

197 {
198  return d->isValid();
199 }
bool isValid() const
Definition: qrawfont_p.h:97
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ leading()

qreal QRawFont::leading ( ) const

Returns the leading of this QRawFont in pixel units.

See also
QFontMetricsF::leading()

Definition at line 335 of file qrawfont.cpp.

336 {
337  return d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
338 }
bool isValid() const
Definition: qrawfont_p.h:97
qreal toReal() const
Definition: qfixed_p.h:77
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138
virtual QFixed leading() const =0

◆ loadFromData()

void QRawFont::loadFromData ( const QByteArray fontData,
qreal  pixelSize,
QFont::HintingPreference  hintingPreference 
)

Replaces the current QRawFont with the font contained in the supplied fontData for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference.

The fontData must contain a TrueType or OpenType font.

See also
loadFromFile()

Definition at line 228 of file qrawfont.cpp.

Referenced by loadFromFile(), and QRawFont().

231 {
232  d.detach();
233  d->cleanUp();
237 }
qreal pixelSize() const
Returns the pixel size set for this QRawFont.
Definition: qrawfont.cpp:367
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
void platformLoadFromData(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference)
QFont::HintingPreference hintingPreference
Definition: qrawfont_p.h:112
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
QThread * thread
Definition: qrawfont_p.h:113
QFont::HintingPreference hintingPreference() const
Returns the hinting preference used to construct this QRawFont.
Definition: qrawfont.cpp:539
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ loadFromFile()

void QRawFont::loadFromFile ( const QString fileName,
qreal  pixelSize,
QFont::HintingPreference  hintingPreference 
)

Replaces the current QRawFont with the contents of the file referenced by fileName for the size (in pixels) given by pixelSize, and using the hinting preference specified by hintingPreference.

The file must reference a TrueType or OpenType font.

See also
loadFromData()

Definition at line 210 of file qrawfont.cpp.

Referenced by QRawFont().

213 {
214  QFile file(fileName);
215  if (file.open(QIODevice::ReadOnly))
216  loadFromData(file.readAll(), pixelSize, hintingPreference);
217 }
void loadFromData(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference)
Replaces the current QRawFont with the font contained in the supplied fontData for the size (in pixel...
Definition: qrawfont.cpp:228
qreal pixelSize() const
Returns the pixel size set for this QRawFont.
Definition: qrawfont.cpp:367
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
QFont::HintingPreference hintingPreference() const
Returns the hinting preference used to construct this QRawFont.
Definition: qrawfont.cpp:539

◆ maxCharWidth()

qreal QRawFont::maxCharWidth ( ) const

Returns the width of the widest character in the font.

See also
QFontMetricsF::maxWidth()

Definition at line 355 of file qrawfont.cpp.

356 {
357  return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
358 }
virtual qreal maxCharWidth() const =0
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ operator!=()

bool QRawFont::operator!= ( const QRawFont other) const
inline

Returns true if this QRawFont is not equal to other.

Otherwise, returns false.

Definition at line 86 of file qrawfont.h.

87  { return !operator==(other); }
bool operator==(const QRawFont &other) const
Returns true if this QRawFont is equal to other.
Definition: qrawfont.cpp:286

◆ operator=()

QRawFont & QRawFont::operator= ( const QRawFont other)

Assigns other to this QRawFont.

Definition at line 187 of file qrawfont.cpp.

188 {
189  d = other.d;
190  return *this;
191 }
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ operator==()

bool QRawFont::operator== ( const QRawFont other) const

Returns true if this QRawFont is equal to other.

Otherwise, returns false.

Definition at line 286 of file qrawfont.cpp.

287 {
288  return d->fontEngine == other.d->fontEngine;
289 }
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ pathForGlyph()

QPainterPath QRawFont::pathForGlyph ( quint32  glyphIndex) const

This function returns the shape of the glyph at a given glyphIndex in the underlying font if the QRawFont is valid.

Otherwise, it returns an empty QPainterPath.

The returned glyph will always be unhinted.

See also
alphaMapForGlyph(), QPainterPath::addText()

Definition at line 272 of file qrawfont.cpp.

273 {
274  if (!d->isValid())
275  return QPainterPath();
276 
278  QPainterPath path;
279  d->fontEngine->addGlyphsToPath(&glyphIndex, &position, 1, &path, 0);
280  return path;
281 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ pixelSize()

qreal QRawFont::pixelSize ( ) const

Returns the pixel size set for this QRawFont.

The pixel size affects how glyphs are rasterized, the size of glyphs returned by pathForGlyph(), and is used to convert internal metrics from design units to logical pixel units.

See also
setPixelSize()

Definition at line 367 of file qrawfont.cpp.

Referenced by loadFromFile().

368 {
369  return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
370 }
qreal pixelSize
Definition: qfont_p.h:90
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QFontDef fontDef
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ setPixelSize()

void QRawFont::setPixelSize ( qreal  pixelSize)

Sets the pixel size with which this font should be rendered to pixelSize.

Definition at line 685 of file qrawfont.cpp.

686 {
687  if (d->fontEngine == 0)
688  return;
689 
690  d.detach();
691  QFontEngine *oldFontEngine = d->fontEngine;
692 
694  if (d->fontEngine != 0)
695  d->fontEngine->ref.ref();
696 
697  oldFontEngine->ref.deref();
698  if (oldFontEngine->cache_count == 0 && oldFontEngine->ref == 0)
699  delete oldFontEngine;
700 }
QAtomicInt ref
qreal pixelSize() const
Returns the pixel size set for this QRawFont.
Definition: qrawfont.cpp:367
bool ref()
Atomically increments the value of this QAtomicInt.
virtual QFontEngine * cloneWithSize(qreal) const
bool deref()
Atomically decrements the value of this QAtomicInt.
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
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ style()

QFont::Style QRawFont::style ( ) const

Returns the style of this QRawFont.

See also
QFont::style()

Definition at line 408 of file qrawfont.cpp.

409 {
410  return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
411 }
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
bool isValid() const
Definition: qrawfont_p.h:97
uint style
Definition: qfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QFontDef fontDef
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ styleName()

QString QRawFont::styleName ( ) const

Returns the style name of this QRawFont.

See also
QFont::styleName()

Definition at line 398 of file qrawfont.cpp.

399 {
400  return d->isValid() ? d->fontEngine->fontDef.styleName : QString();
401 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isValid() const
Definition: qrawfont_p.h:97
QString styleName
Definition: qfont_p.h:83
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QFontDef fontDef
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ supportedWritingSystems()

QList< QFontDatabase::WritingSystem > QRawFont::supportedWritingSystems ( ) const

Returns a list of writing systems supported by the font according to designer supplied information in the font file.

Please note that this does not guarantee support for a specific unicode point in the font. You can use the supportsCharacter() to check support for a single, specific character.

Note
The list is determined based on the unicode ranges and codepage ranges set in the font's OS/2 table and requires such a table to be present in the underlying font file.
See also
supportsCharacter()

Definition at line 573 of file qrawfont.cpp.

574 {
575  if (d->isValid()) {
576  QByteArray os2Table = fontTable("OS/2");
577  if (os2Table.size() > 86) {
578  char *data = os2Table.data();
579  quint32 *bigEndianUnicodeRanges = reinterpret_cast<quint32 *>(data + 42);
580  quint32 *bigEndianCodepageRanges = reinterpret_cast<quint32 *>(data + 78);
581 
582  quint32 unicodeRanges[4];
583  quint32 codepageRanges[2];
584 
585  for (int i=0; i<4; ++i) {
586  if (i < 2)
587  codepageRanges[i] = qFromBigEndian(bigEndianCodepageRanges[i]);
588  unicodeRanges[i] = qFromBigEndian(bigEndianUnicodeRanges[i]);
589  }
590 
591  return qt_determine_writing_systems_from_truetype_bits(unicodeRanges, codepageRanges);
592  }
593  }
594 
596 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
T qFromBigEndian(const uchar *src)
QByteArray fontTable(const char *tagName) const
Retrieves the sfnt table named tagName from the underlying physical font, or an empty byte array if n...
Definition: qrawfont.cpp:550
static const char * data(const QByteArray &arr)
QList< QFontDatabase::WritingSystem > qt_determine_writing_systems_from_truetype_bits(quint32 unicodeRange[4], quint32 codePageRange[2])
bool isValid() const
Definition: qrawfont_p.h:97
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ supportsCharacter() [1/2]

bool QRawFont::supportsCharacter ( quint32  ucs4) const

Returns true if the font has a glyph that corresponds to the UCS-4 encoded character ucs4.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
supportedWritingSystems()

Definition at line 617 of file qrawfont.cpp.

618 {
619  QChar str[2];
620  int len;
621  if (!QChar::requiresSurrogates(ucs4)) {
622  str[0] = QChar(ucs4);
623  len = 1;
624  } else {
625  str[0] = QChar(QChar::highSurrogate(ucs4));
626  str[1] = QChar(QChar::lowSurrogate(ucs4));
627  len = 2;
628  }
629 
630  return d->isValid() && d->fontEngine->canRender(str, len);
631 }
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static ushort highSurrogate(uint ucs4)
Returns the high surrogate value of a ucs4 code point.
Definition: qchar.h:303
static ushort lowSurrogate(uint ucs4)
Returns the low surrogate value of a ucs4 code point.
Definition: qchar.h:306
static bool requiresSurrogates(uint ucs4)
Returns true if the UCS-4-encoded character specified by ucs4 can be split into the high and low part...
Definition: qchar.h:294
virtual bool canRender(const QChar *string, int len)=0
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ supportsCharacter() [2/2]

bool QRawFont::supportsCharacter ( QChar  character) const

Returns true if the font has a glyph that corresponds to the given character.

See also
supportedWritingSystems()

Definition at line 603 of file qrawfont.cpp.

604 {
605  return d->isValid() && d->fontEngine->canRender(&character, 1);
606 }
virtual bool canRender(const QChar *string, int len)=0
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ unitsPerEm()

qreal QRawFont::unitsPerEm ( ) const

Returns the number of design units define the width and height of the em square for this QRawFont.

This value is used together with the pixel size when converting design metrics to pixel units, as the internal metrics are specified in design units and the pixel size gives the size of 1 em in pixels.

See also
pixelSize(), setPixelSize()

Definition at line 380 of file qrawfont.cpp.

381 {
382  return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
383 }
bool isValid() const
Definition: qrawfont_p.h:97
virtual QFixed emSquareSize() const
qreal toReal() const
Definition: qfixed_p.h:77
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ weight()

int QRawFont::weight ( ) const

Returns the weight of this QRawFont.

See also
QFont::weight()

Definition at line 418 of file qrawfont.cpp.

419 {
420  return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
421 }
uint weight
Definition: qfont_p.h:95
bool isValid() const
Definition: qrawfont_p.h:97
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QFontDef fontDef
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

◆ xHeight()

qreal QRawFont::xHeight ( ) const

Returns the xHeight of this QRawFont in pixel units.

See also
QFontMetricsF::xHeight()

Definition at line 325 of file qrawfont.cpp.

326 {
327  return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
328 }
virtual QFixed xHeight() const
bool isValid() const
Definition: qrawfont_p.h:97
qreal toReal() const
Definition: qfixed_p.h:77
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QExplicitlySharedDataPointer< QRawFontPrivate > d
Definition: qrawfont.h:138

Friends and Related Functions

◆ QRawFontPrivate

friend class QRawFontPrivate
friend

Definition at line 137 of file qrawfont.h.

Properties

◆ d


The documentation for this class was generated from the following files: