toyplot.font module

Font management and font metrics.

class toyplot.font.Font[source]

Bases: object

Abstract interface for objects that return information about a specific combination of typeface and size.

property ascent

Font ascent (maximum height above the baseline).

Returns

ascent – ascent of the font in CSS pixels.

Return type

number

property descent

Font descent (maximum height below the baseline).

Returns

descent – descent of the font in CSS pixels.

Return type

number

width(string)[source]

Return the width of a string if rendered using the font.

Parameters

string (str, required) – 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

Abstract interface for objects that manage 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: 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.

property ascent

Font ascent (maximum height above the baseline).

Returns

ascent – ascent of the font in CSS pixels.

Return type

number

property descent

Font descent (maximum height below the baseline).

Returns

descent – descent of the font in CSS pixels.

Return type

number

width(string)[source]

Return the width of a string if rendered using the font.

Parameters
  • string (str, required) –

  • measured. (The text to be) –

Returns

width – Width of the string in CSS pixels, if rendered using the given font and font size.

Return type

number

class toyplot.font.ReportlabLibrary[source]

Bases: Library

Use Reportlab to provide information about standard PDF 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.ReportlabFont