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

Method get_char_widths

src/__init__.py:4742–4841  ·  view source on GitHub ↗

Get list of glyph information of a font. Notes: Must be provided by its XREF number. If we already dealt with the font, it will be recorded in doc.FontInfos. Otherwise we insert an entry there. Finally we return the glyphs for the font. This i

(
            doc: 'Document',
            xref: int,
            limit: int = 256,
            idx: int = 0,
            fontdict: OptDict = None,
            )

Source from the content-addressed store, hash-verified

4740 self._reset_page_refs()
4741
4742 def get_char_widths(
4743 doc: 'Document',
4744 xref: int,
4745 limit: int = 256,
4746 idx: int = 0,
4747 fontdict: OptDict = None,
4748 ) -> list:
4749 """Get list of glyph information of a font.
4750
4751 Notes:
4752 Must be provided by its XREF number. If we already dealt with the
4753 font, it will be recorded in doc.FontInfos. Otherwise we insert an
4754 entry there.
4755 Finally we return the glyphs for the font. This is a list of
4756 (glyph, width) where glyph is an integer controlling the char
4757 appearance, and width is a float controlling the char's spacing:
4758 width * fontsize is the actual space.
4759 For 'simple' fonts, glyph == ord(char) will usually be true.
4760 Exceptions are 'Symbol' and 'ZapfDingbats'. We are providing data for these directly here.
4761 """
4762 fontinfo = CheckFontInfo(doc, xref)
4763 if fontinfo is None: # not recorded yet: create it
4764 if fontdict is None:
4765 name, ext, stype, asc, dsc = utils._get_font_properties(doc, xref)
4766 fontdict = {
4767 "name": name,
4768 "type": stype,
4769 "ext": ext,
4770 "ascender": asc,
4771 "descender": dsc,
4772 }
4773 else:
4774 name = fontdict["name"]
4775 ext = fontdict["ext"]
4776 stype = fontdict["type"]
4777 ordering = fontdict["ordering"]
4778 simple = fontdict["simple"]
4779
4780 if ext == "":
4781 raise ValueError("xref is not a font")
4782
4783 # check for 'simple' fonts
4784 if stype in ("Type1", "MMType1", "TrueType"):
4785 simple = True
4786 else:
4787 simple = False
4788
4789 # check for CJK fonts
4790 if name in ("Fangti", "Ming"):
4791 ordering = 0
4792 elif name in ("Heiti", "Song"):
4793 ordering = 1
4794 elif name in ("Gothic", "Mincho"):
4795 ordering = 2
4796 elif name in ("Dotum", "Batang"):
4797 ordering = 3
4798 else:
4799 ordering = -1

Callers 5

insert_fontMethod · 0.80
insert_textMethod · 0.80
insert_textboxMethod · 0.80
insert_textMethod · 0.80
insert_textboxMethod · 0.80

Calls 4

CheckFontInfoFunction · 0.85
UpdateFontInfoFunction · 0.85
_get_char_widthsMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected