GlyphString Class

Inheritance diagram of GlyphString

class GlyphString(text, glyphs, x=0, y=0)

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.


__init__(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.

  • 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.


draw([from_index, to_index]) Draw a region of the glyph string.
get_break_index(from_index, width) Find a breakpoint within the text for a given width.
get_subwidth(from_index, to_index) Return the width of a slice of this string.


GlyphString.draw(from_index=0, to_index=None)

Draw a region of the glyph string.

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

from import *
  • from_index (int) – Start index of text to render.
  • to_index (int) – End index (exclusive) of text to render.
GlyphString.get_break_index(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.

  • from_index (int) – Index of text to begin at, or 0 for the beginning of the string.
  • width (float) – Maximum width to use.
Return type:



the index of text which will be used as the breakpoint, or from_index if there is no valid breakpoint.

GlyphString.get_subwidth(from_index, to_index)

Return the width of a slice of this string.

  • from_index (int) – The start index of the string to measure.
  • to_index (int) – The end index (exclusive) of the string to measure.
Return type:


Table Of Contents

Previous topic

TruetypeInfo Class

Next topic

Text Class