ged2doc.textbox¶
Module defining TexBox
class and related methods.
Classes
|
Class representing an SVG box with a text inside. |
-
class
ged2doc.textbox.
TextBox
(x0=0, y0=0, width=0, maxwidth=0, height=0, text='', font_size='10pt', padding='4pt', line_spacing='1.5pt', href=None)[source]¶ Bases:
object
Class representing an SVG box with a text inside.
This class takes care of the text wrapping and optional resizing of the box in vertical direction to fit all text.
- Parameters
- x0
Size
, optional Lowest X coordinate of corner (def: 0)
- y0
Size
, optional Lowest Y coordinate of corner (def: 0)
- width
Size
, optional Width of a box (def: 0)
- maxwidth
Size
, optional Maximum width of a box (def: 0)
- height
Size
, optional Height of a box (def: 0)
- text
str
, optional Text contained in a box (def: ‘’)
- font_size
Size
, optional Font size (def: 10pt)
- rect_style
str
, optional SVG style for rectangle
- text_style
str
SVG style for text
- line_spacing
Size
, optional Space between lines (def: 1.5pt)
- padding
Size
, optional Box padding space (def: 4pt)
- x0
- Attributes
- font_size
- height
- href
- lines
- midx
- midy
- text
- width
- x0
- x1
- y0
- y1
Methods
Iterate over lines and their positions.
move
(x0, y0)Sets new coordinates fo x0 and y0
reflow
()Split the text inside the box so that it fits into box width, then recalculate box height so that all text fits inside the box.
-
property
x0
¶
-
property
x1
¶
-
property
y0
¶
-
property
y1
¶
-
property
midx
¶
-
property
midy
¶
-
property
width
¶
-
property
height
¶
-
property
text
¶
-
property
href
¶
-
property
font_size
¶
-
property
lines
¶
-
lines_pos
()[source]¶ Iterate over lines and their positions.
For each line of test iterator returns a tuple of two items:
text for that line
position as a tuple of two
Size
instances, for horizontal position it returns the center of the box (same asmidx
), and for vertical position it returns the baseline position of that line
- Yields
- line
str
Text for a line.
- pos
tuple
[Size
] Text position.
- line
-
reflow
()[source]¶ Split the text inside the box so that it fits into box width, then recalculate box height so that all text fits inside the box.
-
move
(x0, y0)[source]¶ Sets new coordinates fo x0 and y0
- Parameters
- x0, y0
int
orSize
New box coordinates.
- x0, y0
-
_splitText
(text)[source]¶ Tries to split a line of text into a number of lines which fit into box width. It honors embedded newlines, line will always be split at those first.
- Parameters
- text
str
Text to split into lines.
- text
- Returns
- lines
list
[str
]
- lines