ged2doc.textbox

Module defining TexBox class and related methods.

Classes

TextBox([x0, y0, width, maxwidth, height, …])

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
x0Size, optional

Lowest X coordinate of corner (def: 0)

y0Size, optional

Lowest Y coordinate of corner (def: 0)

widthSize, optional

Width of a box (def: 0)

maxwidthSize, optional

Maximum width of a box (def: 0)

heightSize, optional

Height of a box (def: 0)

textstr, optional

Text contained in a box (def: ‘’)

font_sizeSize, optional

Font size (def: 10pt)

rect_stylestr, optional

SVG style for rectangle

text_stylestr

SVG style for text

line_spacingSize, optional

Space between lines (def: 1.5pt)

paddingSize, optional

Box padding space (def: 4pt)

Attributes
font_size
height
href
lines
midx
midy
text
width
x0
x1
y0
y1

Methods

lines_pos()

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 as midx), and for vertical position it returns the baseline position of that line

Yields
linestr

Text for a line.

postuple [ Size ]

Text position.

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, y0int or Size

New box coordinates.

_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
textstr

Text to split into lines.

Returns
lineslist [ str ]
_splitText1(text, width)[source]

Tries to split a line of text into a number of lines which fit into box width.

_textWidth(text)[source]

Calculates approximate width of the string of text.