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

Function JM_insert_font

src/__init__.py:20348–20423  ·  view source on GitHub ↗

Insert a font in a PDF

(pdf, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering)

Source from the content-addressed store, hash-verified

20346
20347
20348def JM_insert_font(pdf, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering):
20349 '''
20350 Insert a font in a PDF
20351 '''
20352 font = None
20353 res = None
20354 data = None
20355 ixref = 0
20356 index = 0
20357 simple = 0
20358 value=None
20359 name=None
20360 subt=None
20361 exto = None
20362
20363 ENSURE_OPERATION(pdf)
20364 # check for CJK font
20365 if ordering > -1:
20366 data, size, index = mupdf.fz_lookup_cjk_font(ordering)
20367 if data:
20368 font = mupdf.fz_new_font_from_memory(None, data, size, index, 0)
20369 font_obj = mupdf.pdf_add_cjk_font(pdf, font, ordering, wmode, serif)
20370 exto = "n/a"
20371 simple = 0
20372 #goto weiter;
20373 else:
20374
20375 # check for PDF Base-14 font
20376 if bfname:
20377 data, size = mupdf.fz_lookup_base14_font(bfname)
20378 if data:
20379 font = mupdf.fz_new_font_from_memory(bfname, data, size, 0, 0)
20380 font_obj = mupdf.pdf_add_simple_font(pdf, font, encoding)
20381 exto = "n/a"
20382 simple = 1
20383 #goto weiter;
20384
20385 else:
20386 if fontfile:
20387 font = mupdf.fz_new_font_from_file(None, fontfile, idx, 0)
20388 else:
20389 res = JM_BufferFromBytes(fontbuffer)
20390 if not res.m_internal:
20391 RAISEPY(MSG_FILE_OR_BUFFER, PyExc_ValueError)
20392 font = mupdf.fz_new_font_from_buffer(None, res, idx, 0)
20393
20394 if not set_simple:
20395 font_obj = mupdf.pdf_add_cid_font(pdf, font)
20396 simple = 0
20397 else:
20398 font_obj = mupdf.pdf_add_simple_font(pdf, font, encoding)
20399 simple = 2
20400 #weiter: ;
20401 ixref = mupdf.pdf_to_num(font_obj)
20402 name = JM_EscapeStrFromStr( mupdf.pdf_to_name( mupdf.pdf_dict_get(font_obj, PDF_NAME('BaseFont'))))
20403
20404 subt = JM_UnicodeFromStr( mupdf.pdf_to_name( mupdf.pdf_dict_get( font_obj, PDF_NAME('Subtype'))))
20405

Callers 2

_insert_fontMethod · 0.85
_insertFontMethod · 0.85

Calls 7

ENSURE_OPERATIONFunction · 0.85
JM_BufferFromBytesFunction · 0.85
RAISEPYFunction · 0.85
JM_EscapeStrFromStrFunction · 0.85
PDF_NAMEFunction · 0.85
JM_UnicodeFromStrFunction · 0.85
JM_get_fontextensionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…