CopperSpice API
1.9.2
|
Provides access to a single physical instance of a given font. More...
Public Types | |
enum | AntialiasingType |
Public Methods | |
QRawFont () | |
QRawFont (const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference=QFont::PreferDefaultHinting) | |
QRawFont (const QRawFont &other) | |
QRawFont (const QString &fileName, qreal pixelSize, QFont::HintingPreference hintingPreference=QFont::PreferDefaultHinting) | |
~QRawFont () | |
bool | advancesForGlyphIndexes (const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const |
bool | advancesForGlyphIndexes (const quint32 *glyphIndexes, QPointF *advances, int numGlyphs, LayoutFlags layoutFlags) const |
QVector< QPointF > | advancesForGlyphIndexes (const QVector< quint32 > &glyphIndexes) const |
QVector< QPointF > | advancesForGlyphIndexes (const QVector< quint32 > &glyphIndexes, LayoutFlags layoutFlags) const |
QImage | alphaMapForGlyph (quint32 glyphIndex, AntialiasingType antialiasingType=SubPixelAntialiasing, const QTransform &transform=QTransform ()) const |
qreal | ascent () const |
qreal | averageCharWidth () const |
QRectF | boundingRect (quint32 glyphIndex) const |
qreal | descent () const |
QString | familyName () const |
QByteArray | fontTable (const char *tagName) const |
bool | glyphIndexesForChars (QStringView str, quint32 *glyphIndexes, int *numGlyphs) const |
QVector< quint32 > | glyphIndexesForString (const QString &text) const |
QFont::HintingPreference | hintingPreference () const |
bool | isValid () const |
qreal | leading () const |
qreal | lineThickness () const |
void | loadFromData (const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) |
void | loadFromFile (const QString &fileName, qreal pixelSize, QFont::HintingPreference hintingPreference) |
qreal | maxCharWidth () const |
bool | operator!= (const QRawFont &other) const |
QRawFont & | operator= (const QRawFont &other) |
QRawFont & | operator= (QRawFont &&other) |
bool | operator== (const QRawFont &other) const |
QPainterPath | pathForGlyph (quint32 glyphIndex) const |
qreal | pixelSize () const |
void | setPixelSize (qreal pixelSize) |
QFont::Style | style () const |
QString | styleName () const |
QList< QFontDatabase::WritingSystem > | supportedWritingSystems () const |
bool | supportsCharacter (QChar character) const |
bool | supportsCharacter (quint32 ucs4) const |
void | swap (QRawFont &other) |
qreal | underlinePosition () const |
qreal | unitsPerEm () const |
int | weight () const |
qreal | xHeight () const |
Static Public Methods | |
static QRawFont | fromFont (const QFont &font, QFontDatabase::WritingSystem writingSystem=QFontDatabase::Any) |
Friends | |
class | QTextLayout |
The QRawFont class provides access to a single specific font using an existing font file. The font family, point size, and font style are all required when specifying a QRawFont. An example would be "Helvetica 14 Bold". This is a low level class and for most use cased using the QFont class will be a better choice.
When using the QFont class to display text the rendering system will attempt to find each character in the specified font. If there is no match a different font may be used. This happens on a character by character basis. This may not produce the desired result. If your application needs to select a specific font then using QRawFont will be necessary.
This class can be used in combination with the QGlyphRun class to draw specific glyph indexes at specific positions.
A QRawFont object can be constructed in one of the following ways. The object belongs to the thread where it was constructed and can not be moved to a different thread.
This enum represents the different ways a glyph can be rasterized in the function alphaMapForGlyph().
Constant | Value | Description |
---|---|---|
QRawFont::PixelAntialiasing | 0 | 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. |
QRawFont::SubPixelAntialiasing | 1 | 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. |
QRawFont::QRawFont | ( | ) |
Constructs an invalid QRawFont.
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.
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.
QRawFont::QRawFont | ( | const QRawFont & | other | ) |
Creates a QRawFont which is a copy of other.
QRawFont::~QRawFont | ( | ) |
Destroys the QRawFont
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.
bool QRawFont::advancesForGlyphIndexes | ( | const quint32 * | glyphIndexes, |
QPointF * | advances, | ||
int | numGlyphs, | ||
LayoutFlags | layoutFlags | ||
) | 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. How the advances are calculated is controlled by layoutFlags.
|
inline |
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.
|
inline |
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. How the advances are calculated is controlled by layoutFlags.
QImage QRawFont::alphaMapForGlyph | ( | quint32 | glyphIndex, |
AntialiasingType | antialiasingType = SubPixelAntialiasing , |
||
const QTransform & | transform = QTransform() |
||
) | const |
This method 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.
qreal QRawFont::ascent | ( | ) | const |
Returns the ascent of this QRawFont in pixel units.
qreal QRawFont::averageCharWidth | ( | ) | const |
Returns the average character width of this QRawFont in pixel units.
Returns the smallest rectangle containing the glyph with the given glyphIndex.
qreal QRawFont::descent | ( | ) | const |
Returns the descent of this QRawFont in pixel units.
QString QRawFont::familyName | ( | ) | const |
Returns the family name of this QRawFont.
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.
|
static |
Fetches the physical representation based on a font query. The physical font returned is the font that will be preferred by CopperSpice in order to display text in the selected writingSystem.
bool QRawFont::glyphIndexesForChars | ( | QStringView | str, |
quint32 * | glyphIndexes, | ||
int * | numGlyphs | ||
) | const |
Converts a string of unicode points to glyph indexes using the CMAP table in the underlying font. The method works like glyphIndexesForString() except it receive an array (char), 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 not large enough this method will return false, then resize glyphIndexes from the size returned in numGlyphs.
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.
QFont::HintingPreference QRawFont::hintingPreference | ( | ) | const |
Returns the hinting preference used to construct this QRawFont.
bool QRawFont::isValid | ( | ) | const |
Returns true if the QRawFont is valid and false otherwise.
qreal QRawFont::leading | ( | ) | const |
Returns the leading of this QRawFont in pixel units.
qreal QRawFont::lineThickness | ( | ) | const |
Returns the thickness for drawing lines (underline, overline, etc.) along with text drawn in this font.
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.
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.
qreal QRawFont::maxCharWidth | ( | ) | const |
Returns the width of the widest character in the font.
|
inline |
Returns true if this QRawFont is not equal to other. Otherwise, returns false.
QRawFont & QRawFont::operator= | ( | const QRawFont & | other | ) |
Copy assigns from other and returns a reference to this object.
|
inline |
Move assigns from other and returns a reference to this object.
bool QRawFont::operator== | ( | const QRawFont & | other | ) | const |
Returns true if this QRawFont is equal to other. Otherwise, returns false.
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.
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.
void QRawFont::setPixelSize | ( | qreal | pixelSize | ) |
Sets the pixel size with which this font should be rendered to pixelSize.
QFont::Style QRawFont::style | ( | ) | const |
Returns the style of this QRawFont.
QString QRawFont::styleName | ( | ) | const |
Returns the style name of this QRawFont.
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.
bool QRawFont::supportsCharacter | ( | QChar | character | ) | const |
Returns true if the font has a glyph that corresponds to the given character.
bool QRawFont::supportsCharacter | ( | quint32 | ucs4 | ) | const |
Returns true if the font has a glyph that corresponds to the UCS-4 encoded character ucs4.
|
inline |
Swaps the raw font other with this raw font. This operation is very fast and never fails.
qreal QRawFont::underlinePosition | ( | ) | const |
Returns the position from baseline for drawing underlines below the text rendered with this font.
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.
int QRawFont::weight | ( | ) | const |
Returns the weight of this QRawFont.
qreal QRawFont::xHeight | ( | ) | const |
Returns the xHeight of this QRawFont in pixel units.