Skip to content

Commit

Permalink
Fix use of pymupdf.TOOLS.set_subset_fontnames() and pymupdf.TOOLS.uns…
Browse files Browse the repository at this point in the history
…et_quad_corrections().

We need to propagate changes to the `extra` submodule.

Checked with new test tests/test_font.py:test_3677().

This addresses #3677.
  • Loading branch information
julian-smith-artifex-com committed Jul 12, 2024
1 parent c725d3f commit 3a259dc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21605,6 +21605,8 @@ def set_subset_fontnames(on=None):
'''
if on is not None:
_globals.subset_fontnames = bool(on)
if g_use_extra:
extra.set_subset_fontnames(_globals.subset_fontnames)
return _globals.subset_fontnames

@staticmethod
Expand Down Expand Up @@ -21653,6 +21655,8 @@ def unset_quad_corrections(on=None):
'''
if on is not None:
_globals.skip_quad_corrections = bool(on)
if g_use_extra:
extra.set_skip_quad_corrections(_globals.skip_quad_corrections)
return _globals.skip_quad_corrections

# fixme: also defined at top-level.
Expand Down
14 changes: 13 additions & 1 deletion src/extra.i
Original file line number Diff line number Diff line change
Expand Up @@ -1566,11 +1566,20 @@ enum
TEXT_FONT_BOLD = 16,
};

/* todo: implement fns to set these and sync with __init__.py. */
int g_skip_quad_corrections = 0;
int g_subset_fontnames = 0;
int g_small_glyph_heights = 0;

void set_skip_quad_corrections(int on)
{
g_skip_quad_corrections = on;
}

void set_subset_fontnames(int on)
{
g_subset_fontnames = on;
}

void set_small_glyph_heights(int on)
{
g_small_glyph_heights = on;
Expand Down Expand Up @@ -4045,7 +4054,10 @@ fz_rect JM_char_bbox(const mupdf::FzStextLine& line, const mupdf::FzStextChar& c
static fz_quad JM_char_quad( fz_stext_line *line, fz_stext_char *ch);
void JM_print_stext_page_as_text(mupdf::FzBuffer& res, mupdf::FzStextPage& page);

void set_skip_quad_corrections(int on);
void set_subset_fontnames(int on);
void set_small_glyph_heights(int on);

mupdf::FzRect JM_cropbox(mupdf::PdfObj& page_obj);
PyObject* get_cdrawings(mupdf::FzPage& page, PyObject *extended=NULL, PyObject *callback=NULL, PyObject *method=NULL);

Expand Down
Binary file added tests/resources/test_3677.pdf
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,26 @@ def test_mupdf_subset_fonts2():
pages = [i*2 for i in range(n//2)]
print(f'{pages=}.')
pymupdf.mupdf.pdf_subset_fonts2(pymupdf._as_pdf_document(doc), pages)


def test_3677():
pymupdf.TOOLS.set_subset_fontnames(True)
path = os.path.abspath(f'{__file__}/../../tests/resources/test_3677.pdf')
font_names_expected = [
'BCDEEE+Aptos',
'BCDFEE+Aptos',
'BCDGEE+Calibri-Light',
'BCDHEE+Calibri-Light',
]
font_names = list()
with pymupdf.open(path) as document:
for page in document:
for block in page.get_text('dict')['blocks']:
if block['type'] == 0:
if 'lines' in block.keys():
for line in block['lines']:
for span in line['spans']:
font_name=span['font']
print(font_name)
font_names.append(font_name)
assert font_names == font_names_expected, f'{font_names=}'

0 comments on commit 3a259dc

Please sign in to comment.