Skip to content

Commit e21f733

Browse files
docs/ src/__init__.py: improve docs for insert_textbox() methods.
src/__init__.py: In Page.insert_textbox() and Shape.insert_textbox(), sort args to simplify comparison. docs/shape.rst::insert_textbox(): Use sorted multiple lines for args to simplify comparison. docs/page.rst:insert_textbox(): Use sorted multiple lines for args to simplify comparison. Describe <overlay> explicitly because not in Shape.insert_textbox(). Fixed args to match the code: * Removed <charwidths>. * Removed <idx>. * Added <lineheight>. * Added <set_simple>.
1 parent 2f362bd commit e21f733

3 files changed

Lines changed: 80 additions & 32 deletions

File tree

docs/page.rst

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,34 @@ In a nutshell, this is what you can do with PyMuPDF:
783783
pair: fill_opacity; insert_textbox
784784
pair: oc; insert_textbox
785785

786-
.. method:: insert_textbox(rect, buffer, *, fontsize=11, fontname="helv", fontfile=None, idx=0, color=None, fill=None, render_mode=0, miter_limit=1, border_width=1, encoding=TEXT_ENCODING_LATIN, expandtabs=8, align=TEXT_ALIGN_LEFT, charwidths=None, rotate=0, morph=None, stroke_opacity=1, fill_opacity=1, oc=0, overlay=True)
787-
788-
PDF only: Insert text into the specified :data:`rect_like` *rect*. See :meth:`Shape.insert_textbox`.
786+
.. method:: insert_textbox(rect, buffer, \
787+
*, \
788+
align=TEXT_ALIGN_LEFT, \
789+
border_width=1, \
790+
color=None, \
791+
encoding=TEXT_ENCODING_LATIN, \
792+
expandtabs=8, \
793+
fill=None, \
794+
fill_opacity=1, \
795+
fontfile=None, \
796+
fontname="helv", \
797+
fontsize=11, \
798+
lineheight=None, \
799+
miter_limit=1, \
800+
morph=None, \
801+
oc=0, \
802+
overlay=True, \
803+
render_mode=0, \
804+
rotate=0, \
805+
set_simple=False, \
806+
stroke_opacity=1, \
807+
)
808+
809+
PDF only: Insert text into the specified :data:`rect_like` *rect*.
810+
811+
:arg overlay: see :meth:`Shape.commit`.
812+
813+
For other args, see `Shape.insert_textbox`.
789814

790815
|history_begin|
791816

docs/shape.rst

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,30 @@ Several draw methods can be executed in a row and each one of them will contribu
333333
pair: rotate; insert_textbox
334334
pair: oc; insert_textbox
335335

336-
.. method:: insert_textbox(rect, buffer, *, fontsize=11, fontname="helv", fontfile=None, set_simple=False, encoding=TEXT_ENCODING_LATIN, color=None, fill=None, render_mode=0, miter_limit=1, border_width=1, expandtabs=8, align=TEXT_ALIGN_LEFT, rotate=0, lineheight=None, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)
337-
336+
.. method:: insert_textbox( \
337+
rect, \
338+
buffer, \
339+
*, \
340+
align=TEXT_ALIGN_LEFT, \
341+
border_width=1, \
342+
color=None, \
343+
encoding=TEXT_ENCODING_LATIN, \
344+
expandtabs=8, \
345+
fill=None, \
346+
fill_opacity=1, \
347+
fontfile=None, \
348+
fontname="helv", \
349+
fontsize=11, \
350+
lineheight=None, \
351+
miter_limit=1, \
352+
morph=None, \
353+
oc=0, \
354+
render_mode=0, \
355+
rotate=0, \
356+
set_simple=False, \
357+
stroke_opacity=1, \
358+
)
359+
338360
PDF only: Insert text into the specified rectangle. The text will be split into lines and words and then filled into the available space, starting from one of the four rectangle corners, which depends on `rotate`. Line feeds and multiple space will be respected.
339361

340362
:arg rect_like rect: the area to use. It must be finite and not empty.
@@ -343,17 +365,18 @@ Several draw methods can be executed in a row and each one of them will contribu
343365

344366
:arg int align: align each text line. Default is 0 (left). Centered, right and justified are the other supported options, see :ref:`TextAlign`. Please note that the effect of parameter value *TEXT_ALIGN_JUSTIFY* is only achievable with "simple" (single-byte) fonts (including the :ref:`Base-14-Fonts`).
345367

346-
:arg float lineheight: a factor to override the line height calculated from font properties. If not `None`, a line height of `fontsize * lineheight` will be used.
347-
348368
:arg int expandtabs: controls handling of tab characters ``\t`` using the `string.expandtabs()` method **per each line**.
349369

350-
:arg float stroke_opacity: *(new in v1.18.1)* set transparency for stroke colors. Negative values and values > 1 will be ignored. Default is 1 (intransparent).
351370
:arg float fill_opacity: *(new in v1.18.1)* set transparency for fill colors. Default is 1 (intransparent). Use this value to control transparency of the text color. Stroke opacity **only** affects the border line of characters.
352371

353-
:arg int rotate: requests text to be rotated in the rectangle. This value must be a multiple of 90 degrees. Default is 0 (no rotation). Effectively, the four values `0`, `90`, `180` and `270` (= `-90`) are processed, each causing the text to start in a different rectangle corner. Bottom-left is `90`, bottom-right is `180`, and `-90 / 270` is top-right. See the example how text is filled in a rectangle. This argument takes precedence over morphing. See the second example, which shows text first rotated left by `90` degrees and then the whole rectangle rotated clockwise around is lower left corner.
372+
:arg float lineheight: a factor to override the line height calculated from font properties. If not `None`, a line height of `fontsize * lineheight` will be used.
354373

355374
:arg int oc: *(new in v1.18.4)* the :data:`xref` number of an :data:`OCG` or :data:`OCMD` to make this text conditionally displayable.
356375

376+
:arg int rotate: requests text to be rotated in the rectangle. This value must be a multiple of 90 degrees. Default is 0 (no rotation). Effectively, the four values `0`, `90`, `180` and `270` (= `-90`) are processed, each causing the text to start in a different rectangle corner. Bottom-left is `90`, bottom-right is `180`, and `-90 / 270` is top-right. See the example how text is filled in a rectangle. This argument takes precedence over morphing. See the second example, which shows text first rotated left by `90` degrees and then the whole rectangle rotated clockwise around is lower left corner.
377+
378+
:arg float stroke_opacity: *(new in v1.18.1)* set transparency for stroke colors. Negative values and values > 1 will be ignored. Default is 1 (intransparent).
379+
357380
:rtype: float
358381
:returns:
359382
**If positive or zero**: successful execution. The value returned is the unused rectangle line space in pixels. This may safely be ignored -- or be used to optimize the rectangle, position subsequent items, etc.

src/__init__.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12620,25 +12620,25 @@ def insert_textbox(
1262012620
rect: rect_like,
1262112621
buffer: typing.Union[str, list],
1262212622
*,
12623-
fontname: str = "helv",
12624-
fontfile: OptStr = None,
12625-
set_simple: int = 0,
12623+
align: int = 0,
12624+
border_width: float = 0.05,
12625+
color: OptSeq = None,
1262612626
encoding: int = 0,
12627+
expandtabs: int = 1,
12628+
fill_opacity: float = 1,
12629+
fill: OptSeq = None,
12630+
fontfile: OptStr = None,
12631+
fontname: str = "helv",
1262712632
fontsize: float = 11,
1262812633
lineheight: OptFloat = None,
12629-
color: OptSeq = None,
12630-
fill: OptSeq = None,
12631-
expandtabs: int = 1,
12632-
align: int = 0,
12633-
rotate: int = 0,
12634-
render_mode: int = 0,
1263512634
miter_limit: float = 1,
12636-
border_width: float = 0.05,
1263712635
morph: OptSeq = None,
12636+
oc: int = 0,
1263812637
overlay: bool = True,
12638+
render_mode: int = 0,
12639+
rotate: int = 0,
12640+
set_simple: int = 0,
1263912641
stroke_opacity: float = 1,
12640-
fill_opacity: float = 1,
12641-
oc: int = 0,
1264212642
) -> float:
1264312643
"""Insert text into a given rectangle.
1264412644

@@ -15390,24 +15390,24 @@ def insert_textbox(
1539015390
rect: rect_like,
1539115391
buffer: typing.Union[str, list],
1539215392
*,
15393-
fontname: OptStr = "helv",
15393+
align: int = 0,
15394+
border_width: float = 0.05,
15395+
color: OptSeq = None,
15396+
encoding: int = 0,
15397+
expandtabs: int = 1,
15398+
fill_opacity: float = 1,
15399+
fill: OptSeq = None,
1539415400
fontfile: OptStr = None,
15401+
fontname: OptStr = "helv",
1539515402
fontsize: float = 11,
1539615403
lineheight: OptFloat = None,
15397-
set_simple: bool = 0,
15398-
encoding: int = 0,
15399-
color: OptSeq = None,
15400-
fill: OptSeq = None,
15401-
expandtabs: int = 1,
15402-
border_width: float = 0.05,
1540315404
miter_limit: float = 1,
15404-
align: int = 0,
15405+
morph: OptSeq = None,
15406+
oc: int = 0,
1540515407
render_mode: int = 0,
1540615408
rotate: int = 0,
15407-
morph: OptSeq = None,
15409+
set_simple: bool = 0,
1540815410
stroke_opacity: float = 1,
15409-
fill_opacity: float = 1,
15410-
oc: int = 0,
1541115411
) -> float:
1541215412
"""Insert text into a given rectangle.
1541315413

0 commit comments

Comments
 (0)