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

Method __init__

src/__init__.py:8184–8233  ·  view source on GitHub ↗
(
            self,
            fontname=None,
            fontfile=None,
            fontbuffer=None,
            script=0,
            language=None,
            ordering=-1,
            is_bold=0,
            is_italic=0,
            is_serif=0,
            embed=1,
            )

Source from the content-addressed store, hash-verified

8182 return None
8183
8184 def __init__(
8185 self,
8186 fontname=None,
8187 fontfile=None,
8188 fontbuffer=None,
8189 script=0,
8190 language=None,
8191 ordering=-1,
8192 is_bold=0,
8193 is_italic=0,
8194 is_serif=0,
8195 embed=1,
8196 ):
8197
8198 if fontbuffer:
8199 if hasattr(fontbuffer, "getvalue"):
8200 fontbuffer = fontbuffer.getvalue()
8201 elif isinstance(fontbuffer, bytearray):
8202 fontbuffer = bytes(fontbuffer)
8203 if not isinstance(fontbuffer, bytes):
8204 raise ValueError("bad type: 'fontbuffer'")
8205
8206 if isinstance(fontname, str):
8207 fname_lower = fontname.lower()
8208 if "/" in fname_lower or "\\" in fname_lower or "." in fname_lower:
8209 message("Warning: did you mean a fontfile?")
8210
8211 if fname_lower in ("cjk", "china-t", "china-ts"):
8212 ordering = 0
8213
8214 elif fname_lower.startswith("china-s"):
8215 ordering = 1
8216 elif fname_lower.startswith("korea"):
8217 ordering = 3
8218 elif fname_lower.startswith("japan"):
8219 ordering = 2
8220 elif fname_lower in fitz_fontdescriptors.keys():
8221 import pymupdf_fonts # optional fonts
8222 fontbuffer = pymupdf_fonts.myfont(fname_lower) # make a copy
8223 fontname = None # ensure using fontbuffer only
8224 del pymupdf_fonts # remove package again
8225
8226 elif ordering < 0:
8227 fontname = Base14_fontdict.get(fontname, fontname)
8228
8229 lang = mupdf.fz_text_language_from_string(language)
8230 font = JM_get_font(fontname, fontfile,
8231 fontbuffer, script, lang, ordering,
8232 is_bold, is_italic, is_serif, embed)
8233 self.this = font
8234
8235 def __repr__(self):
8236 return f"Font('{self.name}')"

Callers

nothing calls this directly

Calls 3

JM_get_fontFunction · 0.85
messageFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected