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') 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) 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,