pyhanko.pdf_utils.font.basic module

class pyhanko.pdf_utils.font.basic.SimpleFontEngineFactory(name: str, avg_width: float, meta: Optional[SimpleFontMeta] = None)

Bases: FontEngineFactory

create_font_engine(writer: BasePdfFileWriter, obj_stream=None)
static default_factory()

A FontEngineFactory instance representing the Courier standard font.

class pyhanko.pdf_utils.font.basic.SimpleFontEngine(writer: BasePdfFileWriter, name: str, avg_width: float, meta: Optional[SimpleFontMeta] = None)

Bases: FontEngine

Simplistic font engine that effectively only works with PDF standard fonts, and does not care about font metrics. Best used with monospaced fonts such as Courier.

property uses_complex_positioning

If True, this font engine expects the line matrix to always be equal to the text matrix when exiting and entering shape(). In other words, the current text position is where 0 0 Td would move to.

If False, this method does not use any text positioning operators, and therefore uses the PDF standard’s ‘natural’ positioning rules for text showing operators.

The default is True unless overridden.

shape(txt) ShapeResult

Render a string to a format suitable for inclusion in a content stream and measure its total cursor advancement vector in em units.


txt – String to shape.


A shaping result.


Convert a FontEngine to a PDF object suitable for embedding inside a resource dictionary.


If the PDF object is an indirect reference, the caller must not attempt to dereference it. In other words, implementations can use preallocated references to delay subsetting until the last possible moment (this is even encouraged, see prepare_write()).


A PDF dictionary.

class pyhanko.pdf_utils.font.basic.SimpleFontMeta(first_char: int, last_char: int, widths: List[int], descriptor: pyhanko.pdf_utils.generic.DictionaryObject)

Bases: object

first_char: int
last_char: int
widths: List[int]
descriptor: DictionaryObject
pyhanko.pdf_utils.font.basic.get_courier(pdf_writer: BasePdfFileWriter)

Quick-and-dirty way to obtain a Courier font resource.


pdf_writer – A PDF writer.


A resource dictionary representing the standard Courier font (or one of its metric equivalents).