MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / get_fontnames

Method get_fontnames

src/__init__.py:7627–7653  ·  view source on GitHub ↗

Return a list of fontnames for an item of page.get_fonts(). There may be multiple names e.g. for Type0 fonts.

(doc, item)

Source from the content-addressed store, hash-verified

7625 return name
7626
7627 def get_fontnames(doc, item):
7628 """Return a list of fontnames for an item of page.get_fonts().
7629
7630 There may be multiple names e.g. for Type0 fonts.
7631 """
7632 fontname = item[3]
7633 names = [fontname]
7634 fontname = doc.xref_get_key(item[0], "BaseFont")[1][1:]
7635 fontname = norm_name(fontname)
7636 if fontname not in names:
7637 names.append(fontname)
7638 descendents = doc.xref_get_key(item[0], "DescendantFonts")
7639 if descendents[0] != "array":
7640 return names
7641 descendents = descendents[1][1:-1]
7642 if descendents.endswith(" 0 R"):
7643 xref = int(descendents[:-4])
7644 descendents = doc.xref_object(xref, compressed=True)
7645 p1 = descendents.find("/BaseFont")
7646 if p1 >= 0:
7647 p2 = descendents.find("/", p1 + 1)
7648 p1 = min(descendents.find("/", p2 + 1), descendents.find(">>", p2 + 1))
7649 fontname = descendents[p2 + 1 : p1]
7650 fontname = norm_name(fontname)
7651 if fontname not in names:
7652 names.append(fontname)
7653 return names
7654
7655 for i in range(doc.page_count):
7656 for f in doc.get_page_fonts(i, full=True):

Callers

nothing calls this directly

Calls 5

norm_nameFunction · 0.85
xref_get_keyMethod · 0.80
xref_objectMethod · 0.80
findMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected