Class pyglet.font.GlyphString

An immutable string of glyphs that can be rendered quickly.

This class is ideal for quickly rendering single or multi-line strings of text that use the same font. To wrap text using a glyph string, call get_break_index to find the optimal breakpoint for each line, the repeatedly call draw for each breakpoint.

Deprecated: Use pyglet.text.layout classes.

Methods

  __init__(self, text, glyphs, x=0, y=0)
Create a glyph string.
int get_break_index(self, from_index, width)
Find a breakpoint within the text for a given width.
float get_subwidth(self, from_index, to_index)
Return the width of a slice of this string.
  draw(self, from_index=0, to_index=None)
Draw a region of the glyph string.

Method Details

__init__

(Constructor) __init__(self, text, glyphs, x=0, y=0)

Create a glyph string.

The text string is used to determine valid breakpoints; all glyphs must have already been determined using pyglet.font.base.Font.get_glyphs. The string will be positioned with the baseline of the left-most glyph at the given coordinates.

Parameters:
text : str or unicode
String to represent.
glyphs : list of pyglet.font.base.Glyph
Glyphs representing text.
x : float
X coordinate of the left-side bearing of the left-most glyph.
y : float
Y coordinate of the baseline.

get_break_index

get_break_index(self, from_index, width)

Find a breakpoint within the text for a given width.

Returns a valid breakpoint after from_index so that the text between from_index and the breakpoint fits within width pixels.

This method uses precomputed cumulative glyph widths to give quick answer, and so is much faster than pyglet.font.base.Font.get_glyphs_for_width.

Parameters:
from_index : int
Index of text to begin at, or 0 for the beginning of the string.
width : float
Maximum width to use.
Returns:
int: the index of text which will be used as the breakpoint, or from_index if there is no valid breakpoint.

get_subwidth

get_subwidth(self, from_index, to_index)
Return the width of a slice of this string.
Parameters:
from_index : int
The start index of the string to measure.
to_index : int
The end index (exclusive) of the string to measure.
Returns: float

draw

draw(self, from_index=0, to_index=None)

Draw a region of the glyph string.

Assumes texture state is enabled. To enable the texture state:

from pyglet.gl import *
glEnable(GL_TEXTURE_2D)
Parameters:
from_index : int
Start index of text to render.
to_index : int
End index (exclusive) of text to render.