MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _gen_multi_font_text

Function _gen_multi_font_text

lib/matplotlib/testing/__init__.py:274–314  ·  view source on GitHub ↗

Generate text intended for use with multiple fonts to exercise font fallbacks. Returns ------- fonts : list of str The names of the fonts used to render the test string, sorted by intended priority. This should be set as the font family for the Figure or Text artist

()

Source from the content-addressed store, hash-verified

272
273
274def _gen_multi_font_text():
275 """
276 Generate text intended for use with multiple fonts to exercise font fallbacks.
277
278 Returns
279 -------
280 fonts : list of str
281 The names of the fonts used to render the test string, sorted by intended
282 priority. This should be set as the font family for the Figure or Text artist.
283 text : str
284 The test string.
285 """
286 # These fonts are serif and sans-serif, and would not normally be combined, but that
287 # should make it easier to see which glyph is from which font.
288 fonts = ['cmr10', 'DejaVu Sans']
289 # cmr10 does not contain accented characters, so they should fall back to DejaVu
290 # Sans. However, some accented capital A versions *are* in cmr10 with non-standard
291 # glyph shapes, so don't test those (otherwise this Latin1 supplement group would
292 # start at 0xA0.)
293 start = 0xC5
294 latin1_supplement = [chr(x) for x in range(start, 0xFF+1)]
295 latin_extended_A = [chr(x) for x in range(0x100, 0x17F+1)]
296 latin_extended_B = [chr(x) for x in range(0x180, 0x24F+1)]
297 non_basic_multilingual_plane = [chr(x) for x in range(0x1F600, 0x1F610)]
298 count = itertools.count(start - 0xA0)
299 non_basic_characters = '\n'.join(
300 ''.join(line)
301 for _, line in itertools.groupby( # Replace with itertools.batched for Py3.12+.
302 [*latin1_supplement, *latin_extended_A, *latin_extended_B,
303 *non_basic_multilingual_plane],
304 key=lambda x: next(count) // 32) # 32 characters per line.
305 )
306 test_str = f"""There are basic characters
307{string.ascii_uppercase} {string.ascii_lowercase}
308{string.digits} {string.punctuation}
309and accented characters
310{non_basic_characters}
311in between!"""
312 # The resulting string contains 491 unique characters. Some file formats use 8-bit
313 # tables, which the large number of characters exercises twice over.
314 return fonts, test_str

Callers 8

test_multi_font_aspathFunction · 0.90
test_multi_font_astextFunction · 0.90
test_multi_font_type3Function · 0.90
test_multi_font_type42Function · 0.90
test_fallback_smokeFunction · 0.90
test__layoutFunction · 0.90
test_multi_font_type3Function · 0.90
test_multi_font_type42Function · 0.90

Calls 2

countMethod · 0.80
joinMethod · 0.80

Tested by 8

test_multi_font_aspathFunction · 0.72
test_multi_font_astextFunction · 0.72
test_multi_font_type3Function · 0.72
test_multi_font_type42Function · 0.72
test_fallback_smokeFunction · 0.72
test__layoutFunction · 0.72
test_multi_font_type3Function · 0.72
test_multi_font_type42Function · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…