Skip to content

PythonQt.QtGui.QRawFont

QRawFont

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

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 Linux platforms and CoreText on macOS. For other font back-ends, the APIs will be disabled.

QRawFont can be constructed in a number of ways:

  • It can be constructed by calling QTextLayout::glyphs() or QTextFragment::glyphs(). The returned QGlyphs objects will contain QRawFont objects which represent the actual fonts used to render each portion of the text.
  • It can be constructed by passing a QFont object to QRawFont::fromFont(). The function will return a QRawFont object representing the font that will be selected as response to the QFont query and the selected writing system.
  • It can be constructed by passing a file name or QByteArray directly to the QRawFont constructor, or by calling loadFromFile() or loadFromData(). In this case, the font will not be registered in QFontDatabase, and it will not be available as part of regular font selection.

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.

Source: https://doc.qt.io/archives/qt-5.15/qrawfont.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
AntialiasingType attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
KernedAdvances attribute Any
LayoutFlag attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
LayoutFlags attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
PixelAntialiasing attribute Any
SeparateAdvances attribute Any
SubPixelAntialiasing attribute Any
UseDesignMetrics attribute Any
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
advancesForGlyphIndexes function (self, glyphIndexes: Any, advances: Any, numGlyphs: Any, layoutFlags: Any) -> tuple X.advancesForGlyphIndexes(glyphIndexes, advances, numGlyphs, layoutFlags) -> tuple
alphaMapForGlyph function (self, glyphIndex: int, antialiasingType: Any, transform: Any) -> Any X.alphaMapForGlyph(glyphIndex, antialiasingType, transform) -> PythonQt.QtGui.QImage
ascent function (self) -> float X.ascent() -> float
averageCharWidth function (self) -> float X.averageCharWidth() -> float
boundingRect function (self, glyphIndex: int) -> Any X.boundingRect(glyphIndex) -> PythonQt.QtCore.QRectF
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
descent function (self) -> float X.descent() -> float
familyName function (self) -> str X.familyName() -> str
fontTable function (self, tagName: str) -> Any X.fontTable(tagName) -> PythonQt.QtCore.QByteArray
fromFont function (self, font: Any, writingSystem: Any) -> Any X.fromFont(font, writingSystem) -> PythonQt.QtGui.QRawFont
glyphIndexesForChars function (self, chars: Any, numChars: Any, glyphIndexes: Any, numGlyphs: Any) -> bool X.glyphIndexesForChars(chars, numChars, glyphIndexes, numGlyphs) -> bool
glyphIndexesForString function (self, text: str) -> tuple X.glyphIndexesForString(text) -> tuple
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
hintingPreference function (self) -> Any Returns the hinting preference used to construct this [QRawFont](https://doc.qt.io/archives/qt-5.15/qrawfont.html).
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isValid function (self) -> bool X.isValid() -> bool
leading function (self) -> float X.leading() -> float
lineThickness function (self) -> float X.lineThickness() -> float
loadFromData function (self, fontData: Any, pixelSize: float, hintingPreference: Any) -> None X.loadFromData(fontData, pixelSize, hintingPreference)
loadFromFile function (self, fileName: str, pixelSize: float, hintingPreference: Any) -> None X.loadFromFile(fileName, pixelSize, hintingPreference)
maxCharWidth function (self) -> float X.maxCharWidth() -> float
operator_assign function (self, other: Any) -> Any X.operator_assign(other) -> PythonQt.QtGui.QRawFont
pathForGlyph function (self, glyphIndex: int) -> Any X.pathForGlyph(glyphIndex) -> PythonQt.QtGui.QPainterPath
pixelSize function (self) -> float X.pixelSize() -> float
setPixelSize function (self, pixelSize: float) -> None Sets the pixel size with which this font should be rendered to pixelSize.
style function (self) -> Any Returns the style of this [QRawFont](https://doc.qt.io/archives/qt-5.15/qrawfont.html).
styleName function (self) -> str X.styleName() -> str
supportedWritingSystems function (self) -> tuple X.supportedWritingSystems() -> tuple
supportsCharacter function (self, character: Any) -> bool X.supportsCharacter(character) -> bool
swap function (self, other: Any) -> None Swaps this raw font with other.
underlinePosition function (self) -> float X.underlinePosition() -> float
unitsPerEm function (self) -> float X.unitsPerEm() -> float
weight function (self) -> int X.weight() -> int
xHeight function (self) -> float X.xHeight() -> float