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

Method insert_text

src_classic/utils.py:3435–3614  ·  view source on GitHub ↗
(
        self,
        point: point_like,
        buffer: typing.Union[str, list],
        fontsize: float = 11,
        lineheight: OptFloat = None,
        fontname: str = "helv",
        fontfile: OptStr = None,
        set_simple: bool = 0,
        encoding: int = 0,
        color: OptSeq = None,
        fill: OptSeq = None,
        render_mode: int = 0,
        border_width: float = 0.05,
        rotate: int = 0,
        morph: OptSeq = None,
        stroke_opacity: float = 1,
        fill_opacity: float = 1,
        oc: int = 0,
    )

Source from the content-addressed store, hash-verified

3433 # Shape.insert_text
3434 # ==============================================================================
3435 def insert_text(
3436 self,
3437 point: point_like,
3438 buffer: typing.Union[str, list],
3439 fontsize: float = 11,
3440 lineheight: OptFloat = None,
3441 fontname: str = "helv",
3442 fontfile: OptStr = None,
3443 set_simple: bool = 0,
3444 encoding: int = 0,
3445 color: OptSeq = None,
3446 fill: OptSeq = None,
3447 render_mode: int = 0,
3448 border_width: float = 0.05,
3449 rotate: int = 0,
3450 morph: OptSeq = None,
3451 stroke_opacity: float = 1,
3452 fill_opacity: float = 1,
3453 oc: int = 0,
3454 ) -> int:
3455 # ensure 'text' is a list of strings, worth dealing with
3456 if not bool(buffer):
3457 return 0
3458
3459 if type(buffer) not in (list, tuple):
3460 text = buffer.splitlines()
3461 else:
3462 text = buffer
3463
3464 if not len(text) > 0:
3465 return 0
3466
3467 point = Point(point)
3468 try:
3469 maxcode = max([ord(c) for c in " ".join(text)])
3470 except:
3471 return 0
3472
3473 # ensure valid 'fontname'
3474 fname = fontname
3475 if fname.startswith("/"):
3476 fname = fname[1:]
3477
3478 xref = self.page.insert_font(
3479 fontname=fname, fontfile=fontfile, encoding=encoding, set_simple=set_simple
3480 )
3481 fontinfo = CheckFontInfo(self.doc, xref)
3482
3483 fontdict = fontinfo[1]
3484 ordering = fontdict["ordering"]
3485 simple = fontdict["simple"]
3486 bfname = fontdict["name"]
3487 ascender = fontdict["ascender"]
3488 descender = fontdict["descender"]
3489 if lineheight:
3490 lheight = fontsize * lineheight
3491 elif ascender - descender <= 1:
3492 lheight = fontsize * 1.2

Callers 2

insert_textFunction · 0.45
insert_pageFunction · 0.45

Calls 12

PointClass · 0.85
CheckFontInfoFunction · 0.85
getTJstrFunction · 0.85
ColorCodeFunction · 0.85
CheckMorphFunction · 0.85
MatrixClass · 0.85
JM_TUPLEFunction · 0.85
insert_fontMethod · 0.80
get_char_widthsMethod · 0.80
_get_optional_contentMethod · 0.80
_set_opacityMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected