pyhanko.pdf_utils.font.api module

class pyhanko.pdf_utils.font.api.ShapeResult(graphics_ops: bytes, x_advance: float, y_advance: float)

Bases: object

Result of shaping a Unicode string.

graphics_ops: bytes

PDF graphics operators to render the glyphs.

x_advance: float

Total horizontal advance in em units.

y_advance: float

Total vertical advance in em units.

class pyhanko.pdf_utils.font.api.FontEngine(writer: pyhanko.pdf_utils.writer.BasePdfFileWriter, base_postscript_name: str, embedded_subset: bool, obj_stream=None)

Bases: object

General interface for text shaping and font metrics.

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: str) pyhanko.pdf_utils.font.api.ShapeResult

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

Parameters

txt – String to shape.

Returns

A shaping result.

as_resource() pyhanko.pdf_utils.generic.PdfObject

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

Note

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()).

Returns

A PDF dictionary.

prepare_write()

Called by the writer that manages this font resource before the PDF content is written to a stream.

Subsetting operations and the like should be carried out as part of this method.

class pyhanko.pdf_utils.font.api.FontSubsetCollection(base_postscript_name: str, subsets: Dict[Union[str, NoneType], ForwardRef('FontEngine')] = <factory>)

Bases: object

base_postscript_name: str

Base postscript name of the font.

subsets: Dict[Optional[str], pyhanko.pdf_utils.font.api.FontEngine]

Dictionary mapping prefixes to subsets. None represents the full font.

add_subset() str
class pyhanko.pdf_utils.font.api.FontEngineFactory

Bases: object

create_font_engine(writer: pyhanko.pdf_utils.writer.BasePdfFileWriter, obj_stream=None) pyhanko.pdf_utils.font.api.FontEngine