toyplot.font module

Font management and font metrics.

class toyplot.font.Font[source]

Bases: object

Base class for objects that can return information about a specific typeface.

ascent

Return the ascent for the given font.

Returns:ascent – ascent of the font in CSS pixels.
Return type:number
descent

Return the descent for the given font.

Returns:descent – descent of the font in CSS pixels.
Return type:number
width(string)[source]

Return the width of a string.

Parameters:string (str) – The text to be measured.
Returns:width – Width of the string in CSS pixels, if rendered using the given font and font size.
Return type:number
class toyplot.font.Library[source]

Bases: object

Base class for objects that can manage information about a collection of fonts.

font(style)[source]

Lookup a font using CSS style information and return a corresponding Font object.

Parameters:style (dict containing CSS style information)
Returns:font
Return type:instance of toyplot.font.Font
class toyplot.font.ReportlabFont(family, size)[source]

Bases: toyplot.font.Font

Use Reportlab to access the metrics for a font.

Parameters:
  • font_family (str) – PDF font family to use for measurement.
  • font_size (number) – Font size for the measurement. Defaults to CSS pixel units, and supports all toyplot Units.
ascent
descent
width(string)[source]
class toyplot.font.ReportlabLibrary[source]

Bases: toyplot.font.Library

Use Reportlab to provide information about standard PDF fonts.

font(style)[source]