urclib.ui_qt.visualizer.textrenderer
Classes and functions for rendering text using the Freetype library and OpenGL Author: P. Wingo
- some useful links:
Module Contents
Classes
Convenience container for storing glyph attributes suitable for drawing. |
|
Container for storing a string and some rendering information. |
|
Manages rendering text glyphs in freetype, and copying the results to OpenGL containers suitable for rendering |
- class urclib.ui_qt.visualizer.textrenderer.AtlasEntry(glyph, xOffs, yOffs=0)
Bases:
objectConvenience container for storing glyph attributes suitable for drawing.
Most freetype examples (particularly OpenGL rendering) will utilize a similar structure.
- Parameters:
glyph – The freetype glyph to document.
offs – The pixel x-offset into the atlas texture storing the rendered glyph.
- ax
Horizontal advance step, in pixels.
- ay
Vertical advance step, in pixels.
- bw
The glyph’s bitmap width, in pixels.
- bh
The glyph’s bitmap height, in pixels.
- bl
The glyph’s left boundary offset, in pixels.
- bt
The glyph’s top boundary offset, in pixels.
- tx
The horizontal/x offset into the atlas texture, in pixels.
- class urclib.ui_qt.visualizer.textrenderer.StringEntry(txt='', anchor=(0.0, 0.0, 0.0), color=(0.0, 0.0, 0.0, 1.0), h_justify='center', v_justify='center', tabspacing=4)
Bases:
objectContainer for storing a string and some rendering information.
- Parameters:
txt – The string to store; note that tabs will be converted to spaces.
anchor – The point which “anchors” the string in Worldspace coordinates. The value should be a container with 3 float values, corresponding to (x,y,z).
color – The color to use for rendering the text; defaults to opaque black. The value should be a container with 3 float values bounded to the range [0,1], corresponding to (red,green,blue,alpha).
h_justify – String representing the horizontal justification relative to the anchor point. Valid values are: * ‘center’: The string centers horizontally on the anchor point. This is the default value. * ‘left’: The string positions itself so the anchor is to the left. * ‘right’: The string positions itself so the anchor is to the right.
v_justify – String representing the vertical justification relative to the anchor point. Valid values are: * ‘center’: The string centers vertically on the anchor point. This is the default value. * ‘top’: The string positions itself so the anchor is on top. * ‘bottom’: The string positions itself so the anchor is below the bottom.
tabspacing – The number of spaces to substitute for tab characters. The default is 4.
- txt
The string to be rendered, with tab substitution applied.
- anchor
The (x,y,z) anchor point in worldspace.
- color
The color to apply to the string as (red,green,blue,alpha).
- h_justify
The string’s horizontal justification.
- v_justify
The string’s vertical justification.
- property validCount
The total number of characters in the string, minus the ‘ ‘ and ‘ ‘ control characters.
- Type:
int
- __len__()
- class urclib.ui_qt.visualizer.textrenderer.TxtRenderer(fontFile, fontSize=64, **kwargs)
Bases:
objectManages rendering text glyphs in freetype, and copying the results to OpenGL containers suitable for rendering
- Parameters:
fontFile – Path to the font file to load. This can be any supported by freetype, as listed [here](https://freetype.org/freetype2/docs/index.html)
fontSize – The point size for the rendered font; defaults to 64.
- Keyword Arguments:
charset – A string (or other iterable container of chars) to include in the atlas. By default, all ASCII characters from 32 through 127 are included, which includes english alphanumerics, and most punctuation. Use a custom set if you need chars outside of this range, or if you are using just a few chars and want to keep memory requirements down. 127 (delete) is always included as a default None char.
- property fontPtSize
The point size of the rendered font.
- Type:
int
- property fontFilePath
The path to the font definition file.
- Type:
str
- property atlasWidth
The width of the atlas texture, in pixels.
- Type:
int
- property atlasHeight
The height of the atlas texture, in pixels.
- Type:
int
- MAX_WIDTH = 512
- static PrepTextBuffer(vao, buff)
Prepare an OpenGL VAO and VBO for use with text rendering. It’s possible that we may want to organize strings into different VAOs and/or VBOs, so keep this as an external behavior.
- Parameters:
vao – The index of the VAO to modify.
buff – The index of the array VBO which will be updated.
- initGL(activeTex)
Initialize components that require an OpenGL context.
- Parameters:
activeTex – The texture slot to use for manipulation (such as GL_TEXTURE0).
- loadStrings(vao, buff, strs, sx=1, sy=1)
- Create renderable versions of a collection of strings. Each character will be billboarded to a quad (two
triangles) with its texture coordinates pinning the correct glyph to be rendered.
- Parameters:
vao – The VAO which will be used to render the supplied strings.
buff – The array VBO which will be used to store the vertices and their attributes.
strs – An iterable container of StringEntry objects which contain a string and rendering information.
sx – An x-scaling factor to apply; defaults to 1.
sy – A y-scaling factor to apply; defaults to 1.
- Returns:
The total number of vertices created and uploaded to the VBO. This value should be suitable for rendering with the GL_TRIANGLES mode.
- Return type:
int
- renderSize(testStr, sx=1, sy=1)
Estimate the dimension of the bounding box of a string, in pixels.
- Parameters:
testStr – The String to test.
sx – The x-scaling factor; defaults to 1.
sy – The y-scaling factor; defaults to 1.
- Returns:
A pair of ints corresponding to the width and height of the strings bounding box, in pixels.
- Return type:
tuple
- cleanupGL()
Cleanup any OpenGL resources.