From fff3763b330b25757fc3ba6ba38733db79477f90 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Fri, 18 Oct 2024 13:23:34 +0100 Subject: [PATCH 1/3] src/__init__.py tests/test_font.py: use new mupdf.fz_enumerate_font_cmap2(). fz_enumerate_font_cmap2() behaves slightly differently from PyMuPDF classic's JM_valid_chars(), in that it can return separate (ucs, gid) pairs with the same . So tests/test_font.py:test_3933()'s expectations have been changed slightly. --- src/__init__.py | 16 +++++++--------- tests/test_font.py | 8 +++----- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index a9afff7e6..66c94d82c 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -6489,16 +6489,14 @@ def valid_codepoints(self): ''' Returns sorted list of valid unicodes of a fz_font. ''' - if 1 or mupdf_version_tuple < (1, 25): - # Not available. + if mupdf_version_tuple < (1, 25): + # mupdf.fz_enumerate_font_cmap2() not available. return [] - # This code should be used when MuPDF has been updated to provide - # fz_ft_font_reverse_cmap(). - gid_to_ucs = mupdf.fz_ft_font_reverse_cmap(self.this) - ucs_unique = set(gid_to_ucs) - ucs_unique_sorted = sorted(ucs_unique) - assert ucs_unique_sorted[0] == 0 - return ucs_unique_sorted[1:] + ucs_gids = mupdf.fz_enumerate_font_cmap2(self.this) + ucss = [i.ucs for i in ucs_gids] + ucss_unique = set(ucss) + ucss_unique_sorted = sorted(ucss_unique) + return ucss_unique_sorted class Graftmap: diff --git a/tests/test_font.py b/tests/test_font.py index b48e05144..dee8f9ee7 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -165,12 +165,12 @@ def test_3933(): print(f'{len(page.get_fonts())=}') expected = { - 'BCDEEE+Calibri': 36, + 'BCDEEE+Calibri': 39, 'BCDFEE+SwissReSan-Regu': 53, 'BCDGEE+SwissReSan-Ital': 20, 'BCDHEE+SwissReSan-Bold': 20, 'BCDIEE+SwissReSan-Regu': 53, - 'BCDJEE+Calibri': 36, + 'BCDJEE+Calibri': 39, } for xref, _, _, name, _, _ in page.get_fonts(): @@ -180,9 +180,7 @@ def test_3933(): font = pymupdf.Font(fontname=name, fontbuffer=content) supported_symbols = font.valid_codepoints() print(f'Font {name}: {len(supported_symbols)=}.', flush=1) - if 1 or pymupdf.mupdf_version_tuple < (1, 25): + if pymupdf.mupdf_version_tuple < (1, 25): assert len(supported_symbols) == 0 else: - # We have a fix but as of 2024-10-17 it is not yet on MuPDF - # master. assert len(supported_symbols) == expected.get(name) From fdfbfb2653b1e928f3d349dba54de0f580766672 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Sun, 20 Oct 2024 18:06:29 +0100 Subject: [PATCH 2/3] tests/test_general.py:test_use_python_logging(): avoid spurious test failure. This test doesn't work when checking `fitz` alias. --- tests/test_general.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_general.py b/tests/test_general.py index 2ee844560..b766fb04d 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1141,6 +1141,12 @@ def test_use_python_logging(): if os.environ.get('PYMUPDF_USE_EXTRA') == '0': log_prefix = f'.+Using non-default setting from PYMUPDF_USE_EXTRA: \'0\'' + if os.path.basename(__file__).startswith(f'test_fitz_'): + # Do nothing, because command `pymupdf` outputs diagnostics containing + # `pymupdf` which are not renamed to `fitz`, which breaks our checking. + print(f'Not testing with fitz alias.') + return + def check( code, regexes_stdout, From 4b8690489ce78db4956602b27a03316918cc1819 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Sun, 20 Oct 2024 18:07:21 +0100 Subject: [PATCH 3/3] setup.py: fix incorrect assert of PYMUPDF_SETUP_PY_LIMITED_API. --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f1341cc0c..7b81a68c2 100755 --- a/setup.py +++ b/setup.py @@ -236,8 +236,8 @@ def log( text): g_pymupdfb_sdist_marker = 'pymupdfb_sdist' PYMUPDF_SETUP_PY_LIMITED_API = os.environ.get('PYMUPDF_SETUP_PY_LIMITED_API') -assert PYMUPDF_SETUP_PY_LIMITED_API in (None, '0', '1'), \ - f'Should be "0", "1" or undefined: {PYMUPDF_SETUP_PY_LIMITED_API=}.' +assert PYMUPDF_SETUP_PY_LIMITED_API in (None, '', '0', '1'), \ + f'Should be "", "0", "1" or undefined: {PYMUPDF_SETUP_PY_LIMITED_API=}.' g_py_limited_api = (PYMUPDF_SETUP_PY_LIMITED_API != '0') PYMUPDF_SETUP_URL_WHEEL = os.environ.get('PYMUPDF_SETUP_URL_WHEEL')