MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_font1

Function test_font1

tests/test_font.py:13–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12
13def test_font1():
14 text = "PyMuPDF"
15 font = pymupdf.Font("helv")
16 assert font.name == "Helvetica"
17 tl = font.text_length(text, fontsize=20)
18 cl = font.char_lengths(text, fontsize=20)
19 assert len(text) == len(cl)
20 assert abs(sum(cl) - tl) < pymupdf.EPSILON
21 for i in range(len(cl)):
22 assert cl[i] == font.glyph_advance(ord(text[i])) * 20
23 font2 = pymupdf.Font(fontbuffer=font.buffer)
24 codepoints1 = font.valid_codepoints()
25 codepoints2 = font2.valid_codepoints()
26 print('')
27 print(f'{len(codepoints1)=}')
28 print(f'{len(codepoints2)=}')
29 if 0:
30 for i, (ucs1, ucs2) in enumerate(zip(codepoints1, codepoints2)):
31 print(f' {i}: {ucs1=} {ucs2=} {"" if ucs2==ucs2 else "*"}')
32 assert font2.valid_codepoints() == font.valid_codepoints()
33
34 # Also check we can get font's bbox.
35 bbox1 = font.bbox
36 print(f'{bbox1=}')
37 bbox2 = font.this.fz_font_bbox()
38 assert bbox2 == bbox1
39
40
41def test_font2():

Callers

nothing calls this directly

Calls 4

text_lengthMethod · 0.95
char_lengthsMethod · 0.95
glyph_advanceMethod · 0.95
valid_codepointsMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…