# Class pyglet.font.base.Font

Abstract font class able to produce glyphs.

To construct a font, use pyglet.font.load, which will instantiate the platform-specific font class.

Internally, this class is used by the platform classes to manage the set of textures into which glyphs are written.

## Nested Classes

| glyph_renderer_class Abstract class for creating glyph images.
| texture_class A texture within which glyphs can be drawn.

## Methods

| __init__(self)
| add_font_data(cls, data) Add font data to the font loader.
bool | have_font(cls, name) Determine if a font with the given name is installed.
Glyph | create_glyph(self, image) Create a glyph using the given image.
list of Glyph | get_glyphs(self, text) Create and return a list of Glyphs for text.
list of Glyph | get_glyphs_for_width(self, text, width) Return a list of glyphs for text that fit within the given width.

## Instance Variables

int | ascent = `0` Maximum ascent above the baseline, in pixels.
int | descent = `0` Maximum descent below the baseline, in pixels.

## Class Variables

| texture_width = `256`
| texture_height = `256`
| texture_internalformat = `6406`

## Method Details

### add_font_data

Class Method add_font_data(cls, data)

Add font data to the font loader.

This is a class method and affects all fonts loaded. Data must be some byte string of data, for example, the contents of a TrueType font file. Subclasses can override this method to add the font data into the font registry.

There is no way to instantiate a font given the data directly, you must use pyglet.font.load specifying the font name.

### have_font

Class Method have_font(cls, name)
Determine if a font with the given name is installed.

Parameters:
  name : str
    Name of a font to search for
Returns: bool

### create_glyph

create_glyph(self, image)

Create a glyph using the given image.

This is used internally by Font subclasses to add glyph data to the font. Glyphs are packed within large textures maintained by Font. This method inserts the image into a font texture and returns a glyph reference; it is up to the subclass to add metadata to the glyph.

Applications should not use this method directly.

Parameters:
  image : pyglet.image.AbstractImage
    The image to write to the font texture.
Returns: Glyph

### get_glyphs

get_glyphs(self, text)

Create and return a list of Glyphs for text.

If any characters do not have a known glyph representation in this font, a substitution will be made.

Parameters:
  text : str or unicode
    Text to render.
Returns: list of Glyph

### get_glyphs_for_width

get_glyphs_for_width(self, text, width)

Return a list of glyphs for text that fit within the given width.

If the entire text is larger than 'width', as much as possible will be used while breaking after a space or zero-width space character. If a newline is encountered in text, only text up to that newline will be used. If no break opportunities (newlines or spaces) occur within `width`, the text up to the first break opportunity will be used (this will exceed `width`). If there are no break opportunities, the entire text will be used.

You can assume that each character of the text is represented by exactly one glyph; so the amount of text "used up" can be determined by examining the length of the returned glyph list.

Parameters:
  text : str or unicode
    Text to render.
  width : int
    Maximum width of returned glyphs.
Returns: list of Glyph

See Also: GlyphString

## Instance Variable Details

### descent

Maximum descent below the baseline, in pixels. Usually negative.

Type:
  int
Value:

      0