Fonts and Typefaces (rinoh.font)

Classes for fonts and typefaces.

class rinoh.font.Font(filename, weight='medium', slant='upright', width='normal')

A collection of glyphs in a particular style

This is a base class for classes that parse different font formats. See rinoh.font.type1 and rinoh.font.opentype.

Parameters
  • filename (str) – filename of the font file to load

  • weight (FontWeight) – weight of the font

  • slant (FontSlant) – slant of the font

  • width (FontWidth) – width of the font

encoding

If no encoding is set for the Font, glyphs are addressed by glyph ID (and thus support more than 256 glyphs).

get_glyph(char, variant)

Return the glyph for a particular character

If the glyph of requested font variant is not present in the font, the normal variant is returned instead. If that is not present either, an exception is raised.

Parameters
  • char (str of length 1) – the character for which to find the glyph

  • variant (FontVariant) – the variant of the glyph to return

Returns

GlyphMetrics – the requested glyph

Raises

MissingGlyphException – when the requested glyph is not present in the font

get_ligature(glyph, successor_glyph)

Return the ligature to replace the given glyphs

If no ligature is defined in the font for the given glyphs, return None.

Parameters
  • glyph (GlyphMetrics) – the first of the glyphs to combine

  • successor_glyph (GlyphMetrics) – the second of the glyphs to combine

Returns

GlyphMetrics or None – the ligature to replace the given glyphs

get_kerning(a, b)

Look up the kerning for two glyphs

Parameters
  • a (GlyphMetrics) – the first of the glyphs

  • b (GlyphMetrics) – the second of the glyphs

Returns

float – the kerning value in font units

class rinoh.font.Typeface(name, *fonts)

A set of fonts that share common design features

The fonts collected in a typeface differ in weight, width and/or slant.

Parameters

*fonts (Font) – the fonts that make up this typeface

fonts()

Generator yielding all fonts of this typeface

Yields

Font – the next font in this typeface

get_font(weight='medium', slant='upright', width='normal')

Return the font matching or closest to the given style

If a font with the given weight, slant and width is available, return it. Otherwise, return the font that is closest in style.

Parameters
Returns

Font – the requested font

class rinoh.font.style.FontWeight

Accepts: hairline, thin, ultra-light, extra-light, light, book, regular, medium, demi-bold, bold, extra-bold, heavy, black, extra-black, ultra-black

class rinoh.font.style.FontSlant

Accepts: upright, oblique, italic

class rinoh.font.style.FontWidth

Accepts: normal, condensed, extended

class rinoh.font.style.FontVariant

Accepts: normal, small capital, oldstyle figures

class rinoh.font.style.TextPosition

Accepts: normal, superscript, subscript