Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fontsubset docs #3500

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5359,8 +5359,8 @@ def recover_char_quad(line_dir: tuple, span: dict, char: dict) -> pymupdf.Quad:
# -------------------------------------------------------------------
# Building font subsets using fontTools
# -------------------------------------------------------------------
def subset_fonts(doc: pymupdf.Document, verbose: bool = False, fallback: bool = False) -> None:
"""Build font subsets of a PDF. Requires package 'fontTools'.
def subset_fonts(doc: pymupdf.Document, verbose: bool = False, fallback: bool = False) -> OptInt:
"""Build font subsets in a PDF.

Eligible fonts are potentially replaced by smaller versions. Page text is
NOT rewritten and thus should retain properties like being hidden or
Expand All @@ -5369,6 +5369,17 @@ def subset_fonts(doc: pymupdf.Document, verbose: bool = False, fallback: bool =
This method by default uses MuPDF's own internal feature to create subset
fonts. As this is a new function, errors may still occur. In this case,
please fall back to using the previous version by using "fallback=True".
Fallback mode requires the external package 'fontTools'.

Args:
fallback: use the older deprecated implementation.
verbose: only used by fallback mode.

Returns:
The new MuPDF-based code returns None. The deprecated fallback
mode returns 0 if there are no fonts to subset. Otherwise, it
returns the decrease in fontsize (the difference in fontsize),
measured in bytes.
JorjMcKie marked this conversation as resolved.
Show resolved Hide resolved
"""
# Font binaries: - "buffer" -> (names, xrefs, (unicodes, glyphs))
# An embedded font is uniquely defined by its fontbuffer only. It may have
Expand Down
Loading