Qt 4.8
|
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< QPointF > | advancesForGlyphIndexes (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< quint32 > | 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. 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... | |
QRawFont & | operator= (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::WritingSystem > | supportedWritingSystems () 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< QRawFontPrivate > | d |
Friends | |
class | QRawFontPrivate |
The QRawFont class provides access to a single physical instance of a font.
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.
Definition at line 63 of file qrawfont.h.
This enum represents the different ways a glyph can be rasterized in the function alphaMapForGlyph().
Enumerator | |
---|---|
PixelAntialiasing | |
SubPixelAntialiasing |
Definition at line 66 of file qrawfont.h.
QRawFont::QRawFont | ( | ) |
Constructs an invalid QRawFont.
Definition at line 134 of file qrawfont.cpp.
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.
Definition at line 146 of file qrawfont.cpp.
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.
Definition at line 161 of file qrawfont.cpp.
QRawFont::QRawFont | ( | const QRawFont & | other | ) |
QRawFont::~QRawFont | ( | ) |
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.
Definition at line 486 of file qrawfont.cpp.
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.
Definition at line 513 of file qrawfont.cpp.
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.
Definition at line 252 of file qrawfont.cpp.
qreal QRawFont::ascent | ( | ) | const |
Returns the ascent of this QRawFont in pixel units.
Definition at line 305 of file qrawfont.cpp.
qreal QRawFont::averageCharWidth | ( | ) | const |
Returns the average character width of this QRawFont in pixel units.
Definition at line 345 of file qrawfont.cpp.
qreal QRawFont::descent | ( | ) | const |
Returns the descent of this QRawFont in pixel units.
Definition at line 315 of file qrawfont.cpp.
QString QRawFont::familyName | ( | ) | const |
Returns the family name of this QRawFont.
Definition at line 388 of file qrawfont.cpp.
Referenced by fromFont().
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().
|
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.
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.
Definition at line 469 of file qrawfont.cpp.
Referenced by glyphIndexesForString().
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.
Definition at line 436 of file qrawfont.cpp.
QFont::HintingPreference QRawFont::hintingPreference | ( | ) | const |
Returns the hinting preference used to construct this QRawFont.
Definition at line 539 of file qrawfont.cpp.
Referenced by QRawFontPrivate::cleanUp(), loadFromData(), and loadFromFile().
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().
qreal QRawFont::leading | ( | ) | const |
Returns the leading of this QRawFont in pixel units.
Definition at line 335 of file qrawfont.cpp.
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.
Definition at line 228 of file qrawfont.cpp.
Referenced by loadFromFile(), and QRawFont().
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.
Definition at line 210 of file qrawfont.cpp.
Referenced by QRawFont().
qreal QRawFont::maxCharWidth | ( | ) | const |
Returns the width of the widest character in the font.
Definition at line 355 of file qrawfont.cpp.
|
inline |
Returns true if this QRawFont is not equal to other.
Otherwise, returns false.
Definition at line 86 of file qrawfont.h.
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.
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.
Definition at line 272 of file qrawfont.cpp.
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.
Definition at line 367 of file qrawfont.cpp.
Referenced by loadFromFile().
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.
QFont::Style QRawFont::style | ( | ) | const |
Returns the style of this QRawFont.
Definition at line 408 of file qrawfont.cpp.
QString QRawFont::styleName | ( | ) | const |
Returns the style name of this QRawFont.
Definition at line 398 of file qrawfont.cpp.
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.
Definition at line 573 of file qrawfont.cpp.
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.
Definition at line 617 of file qrawfont.cpp.
bool QRawFont::supportsCharacter | ( | QChar | character | ) | const |
Returns true if the font has a glyph that corresponds to the given character.
Definition at line 603 of file qrawfont.cpp.
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.
Definition at line 380 of file qrawfont.cpp.
int QRawFont::weight | ( | ) | const |
Returns the weight of this QRawFont.
Definition at line 418 of file qrawfont.cpp.
qreal QRawFont::xHeight | ( | ) | const |
Returns the xHeight of this QRawFont in pixel units.
Definition at line 325 of file qrawfont.cpp.
|
friend |
Definition at line 137 of file qrawfont.h.
|
private |
Definition at line 138 of file qrawfont.h.
Referenced by advancesForGlyphIndexes(), alphaMapForGlyph(), ascent(), averageCharWidth(), descent(), familyName(), fontTable(), fromFont(), glyphIndexesForChars(), glyphIndexesForString(), hintingPreference(), isValid(), leading(), loadFromData(), maxCharWidth(), operator=(), operator==(), pathForGlyph(), pixelSize(), QRawFont(), setPixelSize(), style(), styleName(), supportedWritingSystems(), supportsCharacter(), unitsPerEm(), weight(), and xHeight().