The QRawFont class provides access to a single physical instance of a font. 更多...
The QRawFont class provides access to a single physical instance of a font.
注意: 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 () 或 loadFromFile ()). The QRawFont cannot be moved to a different thread, but will have to be recreated in the thread in question.
注意: 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.
This enum represents the different ways a glyph can be rasterized in the function alphaMapForGlyph ().
| 常量 | 值 | 描述 |
|---|---|---|
| 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. |
Constructs an invalid QRawFont .
构造 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 .
注意: The referenced file must contain a TrueType or OpenType font.
构造 QRawFont representing the font contained in the supplied fontData for the size (in pixels) given by pixelSize , and using the hinting preference 指定通过 hintingPreference .
注意: The data must contain a TrueType or OpenType font.
创建 QRawFont which is a copy of other .
返回 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.
另请参阅 QTextLine.horizontalAdvance () and QFontMetricsF.width ().
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 .
若 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.
另请参阅 pathForGlyph () 和 QPainter.drawGlyphRun ().
Returns the ascent of this QRawFont in pixel units.
另请参阅 QFontMetricsF.ascent ().
Returns the average character width of this QRawFont in pixel units.
另请参阅 QFontMetricsF.averageCharWidth ().
Returns the descent of this QRawFont in pixel units.
另请参阅 QFontMetricsF.descent ().
Returns the family name of this QRawFont .
Retrieves the sfnt table named tagName 从 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.
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 .
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.
另请参阅 advancesForGlyphIndexes (), glyphIndexesForChars (), QGlyphRun , QTextLayout.glyphRuns (),和 QTextFragment.glyphRuns ().
Returns the hinting preference used to construct this QRawFont .
另请参阅 QFont.hintingPreference ().
返回 true 若 QRawFont is valid and false otherwise.
Returns the leading of this QRawFont in pixel units.
另请参阅 QFontMetricsF.leading ().
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 指定通过 hintingPreference .
fontData must contain a TrueType or OpenType font.
另请参阅 loadFromFile ().
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.
另请参阅 loadFromData ().
Returns the width of the widest character in the font.
另请参阅 QFontMetricsF.maxWidth ().
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.
另请参阅 alphaMapForGlyph () 和 QPainterPath.addText ().
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.
另请参阅 setPixelSize ().
Sets the pixel size with which this font should be rendered to pixelSize .
另请参阅 pixelSize ().
Returns the style of this QRawFont .
另请参阅 QFont.style ().
Returns the style name of this QRawFont .
另请参阅 QFont.styleName ().
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.
注意: 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.
另请参阅 supportsCharacter ().
Returns true if the font has a glyph that corresponds to the given character .
另请参阅 supportedWritingSystems ().
这是重载函数。
Returns true if the font has a glyph that corresponds to the UCS-4 encoded character ucs4 .
另请参阅 supportedWritingSystems ().
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.
另请参阅 pixelSize () 和 setPixelSize ().
Returns the weight of this QRawFont .
另请参阅 QFont.weight ().
Returns the xHeight of this QRawFont in pixel units.
另请参阅 QFontMetricsF.xHeight ().