()
| 11 | |
| 12 | |
| 13 | def 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 | |
| 41 | def test_font2(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…