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

Method _get_char_widths

src/__init__.py:3828–3856  ·  view source on GitHub ↗
(self, xref: int, bfname: str, ext: str, ordering: int, limit: int, idx: int = 0)

Source from the content-addressed store, hash-verified

3826 del self._page_refs[pid]
3827
3828 def _get_char_widths(self, xref: int, bfname: str, ext: str, ordering: int, limit: int, idx: int = 0):
3829 pdf = _as_pdf_document(self)
3830 mylimit = limit
3831 if mylimit < 256:
3832 mylimit = 256
3833 if ordering >= 0:
3834 data, size, index = mupdf.fz_lookup_cjk_font(ordering)
3835 font = mupdf.fz_new_font_from_memory(None, data, size, index, 0)
3836 else:
3837 data, size = mupdf.fz_lookup_base14_font(bfname)
3838 if data:
3839 font = mupdf.fz_new_font_from_memory(bfname, data, size, 0, 0)
3840 else:
3841 buf = JM_get_fontbuffer(pdf, xref)
3842 if not buf.m_internal:
3843 raise Exception(f"font at xref {xref:d} is not supported")
3844
3845 font = mupdf.fz_new_font_from_buffer(None, buf, idx, 0)
3846 wlist = []
3847 for i in range(mylimit):
3848 glyph = mupdf.fz_encode_character(font, i)
3849 adv = mupdf.fz_advance_glyph(font, glyph, 0)
3850 if ordering >= 0:
3851 glyph = i
3852 if glyph > 0:
3853 wlist.append( (glyph, adv))
3854 else:
3855 wlist.append( (glyph, 0.0))
3856 return wlist
3857
3858 def _get_page_labels(self):
3859 pdf = _as_pdf_document(self)

Callers 2

get_char_widthsMethod · 0.80
get_char_widthsFunction · 0.80

Calls 3

_as_pdf_documentFunction · 0.85
JM_get_fontbufferFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected