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

Method _insertFont

src/__init__.py:10160–10179  ·  view source on GitHub ↗
(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering)

Source from the content-addressed store, hash-verified

10158 return img_xref, None
10159
10160 def _insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering):
10161 page = self._pdf_page()
10162 pdf = page.doc()
10163
10164 value = JM_insert_font(pdf, bfname, fontfile,fontbuffer, set_simple, idx, wmode, serif, encoding, ordering)
10165 # get the objects /Resources, /Resources/Font
10166 resources = mupdf.pdf_dict_get_inheritable(page.obj(), PDF_NAME('Resources'))
10167 if not resources.pdf_is_dict():
10168 resources = mupdf.pdf_dict_put_dict(page.obj(), PDF_NAME("Resources"), 5)
10169 fonts = mupdf.pdf_dict_get(resources, PDF_NAME('Font'))
10170 if not fonts.m_internal: # page has no fonts yet
10171 fonts = mupdf.pdf_new_dict(pdf, 5)
10172 mupdf.pdf_dict_putl(page.obj(), fonts, PDF_NAME('Resources'), PDF_NAME('Font'))
10173 # store font in resources and fonts objects will contain named reference to font
10174 _, xref = JM_INT_ITEM(value, 0)
10175 if not xref:
10176 raise RuntimeError( "cannot insert font")
10177 font_obj = mupdf.pdf_new_indirect(pdf, xref, 0)
10178 mupdf.pdf_dict_puts(fonts, fontname, font_obj)
10179 return value
10180
10181 def _load_annot(self, name, xref):
10182 page = self._pdf_page()

Callers 1

insert_fontMethod · 0.95

Calls 4

_pdf_pageMethod · 0.95
JM_insert_fontFunction · 0.85
PDF_NAMEFunction · 0.85
JM_INT_ITEMFunction · 0.85

Tested by

no test coverage detected