scistag.imagestag.font.Font

class Font(source, size, framework, index=0)[source]

Bases: object

SDK independent font handle

Initializer :type source: str | bytes | BytesIO :param source: The font source. Either a file path, a bytes like object

or a stream

Parameters
  • size (int) – The font’s size

  • framework (ImsFramework) – The framework to be used

  • index – The font face index

Methods

get_covered_area

Returns the area in which this text will modify pixels, relative to pos 0,0.

get_handle

Returns the low level font handle :rtype: FreeTypeFont :return: The font handle

get_text_size

Returns the text size in pixels

get_y_offset

Returns the relative y starting offset for given vertical alignment type.

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

framework

The framework being used to render the font

size

The font size in pixels as passed in the constructor when creating the font.

ascend

The maximum size of a character above the baseline (in pixels)

descend

The maximum size of a character below the baseline (in pixels)

row_height

The real size of the font in pixels, assuming characters with large ascends such as German umlauts and descending characters.

_y_start_offsets

Dictionary for converting a vertical alignment to a relative y starting offset

get_covered_area(text, h_align=HTextAlignment.LEFT, v_align=VTextAlignment.TOP)[source]

Returns the area in which this text will modify pixels, relative to pos 0,0.

The bounding box defines the area of the printed text which is covered with pixels where the smallest y can be zero and the biggest y2 can be ascend + descend.

Parameters
  • text (str) – The text to be verified

  • h_align (Union[HTextAlignment, Literal[‘l’, ‘c’, ‘r’, ‘left’, ‘center’, ‘right’]]) – The horizontal text alignment

  • v_align (Union[VTextAlignment, Literal[‘t’, ‘c’, ‘rc’, ‘b’, ‘bl’, ‘top’, ‘center’, ‘realCenter’, ‘bottom’, ‘baseLine’]]) – The vertical text alignment

Return type

Bounding2D

Returns

The bbox (x,y,x2,y2)

get_handle()[source]

Returns the low level font handle :rtype: FreeTypeFont :return: The font handle

get_text_size(text, out_lines=None, out_widths=None)[source]

Returns the text size in pixels

Parameters
  • text (str) – The text of which the size shall be determined

  • out_lines (list[str] | None) – If provided it receives the single lines of the text

  • out_widths (list[int] | None) – If provided it receives the widths of the single lines.

Return type

Size2D

Returns

The size in pixels

get_y_offset(vert_alignment)[source]

Returns the relative y starting offset for given vertical alignment type.

Param

vert_alignment: The vertical alignment

Returns

The y shifting relative to a top-left starting point in pixels.

_y_start_offsets

Dictionary for converting a vertical alignment to a relative y starting offset

ascend

The maximum size of a character above the baseline (in pixels)

descend

The maximum size of a character below the baseline (in pixels)

framework

The framework being used to render the font

row_height

The real size of the font in pixels, assuming characters with large ascends such as German umlauts and descending characters. This is the height a text printed with this font will cover at max.

size

The font size in pixels as passed in the constructor when creating the font. Usually this defines (coarsely) the height of the font above the baseline.