MCPcopy Create free account
hub / github.com/PageBot/PageBot / Text

Class Text

Lib/pagebot/elements/text.py:38–931  ·  view source on GitHub ↗

PageBot stores text based on the internal BabelString format. TODO: reimplement various top baseline alignments. TODO: placed upside down compared to other elements, reverse. >>> from pagebot.contexts import getContext >>> from pagebot.document import Document >>> context = get

Source from the content-addressed store, hash-verified

36from pagebot.toolbox.color import noColor
37
38class Text(Element, TextConditions, TextAlignments):
39 """PageBot stores text based on the internal BabelString format.
40
41 TODO: reimplement various top baseline alignments.
42 TODO: placed upside down compared to other elements, reverse.
43
44 >>> from pagebot.contexts import getContext
45 >>> from pagebot.document import Document
46 >>> context = getContext()
47 >>> doc = Document(w=300, h=400, context=context)
48 >>> page = doc[1]
49 >>> t = Text('ABCD', parent=page)
50 >>> t
51 <Text $ABCD$ w=100pt h=400pt>
52 """
53 isText = True
54
55 # Absolute minimum width of a text box. Avoid endless elastic height.
56 TEXT_MIN_WIDTH = 24
57
58 def __init__(self, bs=None, w=None, h=None, size=None, style=None,
59 padding=None, xTextAlign=None, xAlign=None, yAlign=None,
60 margin=None, top=None, bottom=None, **kwargs):
61
62 # Placeholder, ignoring self.w and self.h until defined.
63 self._bs = None
64
65 # Adjust the attributes in **kwargs, so their keys are part of the
66 # rootstyle, in order to do automatic conversion with makeStyle()
67 Element.__init__(self, **kwargs)
68 assert self.context
69 """Creates a Text element, holding storage of `self.bs`.
70 BabelString instance."""
71
72 # Combines rootStyle, optional self.style and **kwargs attributes. Note
73 # that the final style is stored in the BabelString instance self.bs.
74 # self.style is used as template, in the content is defined as plain
75 # string.
76 if style is not None:
77 #self.style = makeStyle(style, **kwargs)
78 self.style = makeStyle(style)
79
80 # Set as property, to make sure there's always a generic BabelString
81 # instance or None. Needs to be done before element initialisation,
82 # because some attributes (Text.xTextAlign) may need the string style
83 # as reference.
84 self.bs = bs # BabelString source for this Text element.
85
86 # TODO: shouldn't BabelString be required?
87 #assert self.bs
88
89 # These need the self.bs to be defined.
90 if xTextAlign is not None:
91 self.xTextAlign = xTextAlign
92
93 if xAlign is not None:
94 self.xAlign = xAlign
95 if yAlign is not None:

Callers 2

newTextFunction · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected