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

Function _get_font_properties

src/utils.py:790–824  ·  view source on GitHub ↗
(doc: pymupdf.Document, xref: int)

Source from the content-addressed store, hash-verified

788
789
790def _get_font_properties(doc: pymupdf.Document, xref: int) -> tuple:
791 fontname, ext, stype, buffer = doc.extract_font(xref)
792 asc = 0.8
793 dsc = -0.2
794 if ext == "":
795 return fontname, ext, stype, asc, dsc
796
797 if buffer:
798 try:
799 font = pymupdf.Font(fontbuffer=buffer)
800 asc = font.ascender
801 dsc = font.descender
802 bbox = font.bbox
803 if asc - dsc < 1:
804 if bbox.y0 < dsc:
805 dsc = bbox.y0
806 asc = 1 - dsc
807 except Exception:
808 pymupdf.exception_info()
809 asc *= 1.2
810 dsc *= 1.2
811 return fontname, ext, stype, asc, dsc
812 if ext != "n/a":
813 try:
814 font = pymupdf.Font(fontname)
815 asc = font.ascender
816 dsc = font.descender
817 except Exception:
818 pymupdf.exception_info()
819 asc *= 1.2
820 dsc *= 1.2
821 else:
822 asc *= 1.2
823 dsc *= 1.2
824 return fontname, ext, stype, asc, dsc
825
826
827def _show_fz_text( text):

Callers

nothing calls this directly

Calls 1

extract_fontMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…