Insert text into a given rectangle. Args: rect -- the textbox to fill buffer -- text to be inserted fontname -- a Base-14 font, font name or '/name' fontfile -- name of a font file fontsize -- font size lineheight -- ov
(
self,
rect: rect_like,
buffer: typing.Union[str, list],
fontname: OptStr = "helv",
fontfile: OptStr = None,
fontsize: float = 11,
lineheight: OptFloat = None,
set_simple: bool = 0,
encoding: int = 0,
color: OptSeq = None,
fill: OptSeq = None,
expandtabs: int = 1,
border_width: float = 0.05,
align: int = 0,
render_mode: int = 0,
rotate: int = 0,
morph: OptSeq = None,
stroke_opacity: float = 1,
fill_opacity: float = 1,
oc: int = 0,
)
| 3617 | # Shape.insert_textbox |
| 3618 | # ========================================================================= |
| 3619 | def insert_textbox( |
| 3620 | self, |
| 3621 | rect: rect_like, |
| 3622 | buffer: typing.Union[str, list], |
| 3623 | fontname: OptStr = "helv", |
| 3624 | fontfile: OptStr = None, |
| 3625 | fontsize: float = 11, |
| 3626 | lineheight: OptFloat = None, |
| 3627 | set_simple: bool = 0, |
| 3628 | encoding: int = 0, |
| 3629 | color: OptSeq = None, |
| 3630 | fill: OptSeq = None, |
| 3631 | expandtabs: int = 1, |
| 3632 | border_width: float = 0.05, |
| 3633 | align: int = 0, |
| 3634 | render_mode: int = 0, |
| 3635 | rotate: int = 0, |
| 3636 | morph: OptSeq = None, |
| 3637 | stroke_opacity: float = 1, |
| 3638 | fill_opacity: float = 1, |
| 3639 | oc: int = 0, |
| 3640 | ) -> float: |
| 3641 | """Insert text into a given rectangle. |
| 3642 | |
| 3643 | Args: |
| 3644 | rect -- the textbox to fill |
| 3645 | buffer -- text to be inserted |
| 3646 | fontname -- a Base-14 font, font name or '/name' |
| 3647 | fontfile -- name of a font file |
| 3648 | fontsize -- font size |
| 3649 | lineheight -- overwrite the font property |
| 3650 | color -- RGB stroke color triple |
| 3651 | fill -- RGB fill color triple |
| 3652 | render_mode -- text rendering control |
| 3653 | border_width -- thickness of glyph borders as percentage of fontsize |
| 3654 | expandtabs -- handles tabulators with string function |
| 3655 | align -- left, center, right, justified |
| 3656 | rotate -- 0, 90, 180, or 270 degrees |
| 3657 | morph -- morph box with a matrix and a fixpoint |
| 3658 | Returns: |
| 3659 | unused or deficit rectangle area (float) |
| 3660 | """ |
| 3661 | rect = Rect(rect) |
| 3662 | if rect.is_empty or rect.is_infinite: |
| 3663 | raise ValueError("text box must be finite and not empty") |
| 3664 | |
| 3665 | color_str = ColorCode(color, "c") |
| 3666 | fill_str = ColorCode(fill, "f") |
| 3667 | if fill is None and render_mode == 0: # ensure fill color for 0 Tr |
| 3668 | fill = color |
| 3669 | fill_str = ColorCode(color, "f") |
| 3670 | |
| 3671 | optcont = self.page._get_optional_content(oc) |
| 3672 | if optcont != None: |
| 3673 | bdc = "/OC /%s BDC\n" % optcont |
| 3674 | emc = "EMC\n" |
| 3675 | else: |
| 3676 | bdc = emc = "" |
no test coverage detected