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

Method newString

Lib/pagebot/contexts/basecontext/basecontext.py:989–1010  ·  view source on GitHub ↗

Creates a new BabelString instance from `bs` (converted to plain unicode string), using style as typographic parameters or `e` as cascading style source. Ignore and just answer `bs` if it is already a BabelString instance and no style is forced. PageBot function. >>

(self, bs=None, style=None, w=None, h=None)

Source from the content-addressed store, hash-verified

987 # String.
988
989 def newString(self, bs=None, style=None, w=None, h=None):
990 """Creates a new BabelString instance from `bs` (converted to plain
991 unicode string), using style as typographic parameters or `e` as
992 cascading style source. Ignore and just answer `bs` if it is already a
993 BabelString instance and no style is forced. PageBot function.
994
995 >>> from pagebot.toolbox.units import pt
996 >>> from pagebot.contexts import getContext
997 >>> context = getContext()
998 >>> bs = context.newString('ABCD', dict(fontSize=pt(12)))
999 >>> bs, bs.__class__.__name__
1000 ($ABCD$, 'BabelString')
1001 """
1002 style = makeStyle(style=style)
1003 if not bs:
1004 bs = ''
1005 if not isinstance(bs, BabelString):
1006 # Otherwise convert bs into a BabelString, from whatever it is now.
1007 # Set the babelString.context as self.
1008 bs = BabelString(bs, style=style, w=w, h=h, context=self)
1009 assert isinstance(bs, BabelString)
1010 return bs
1011
1012 def newBulletString(self, bullet, style=None):
1013 return self.newString(bullet, style=style)

Callers 15

asBabelStringMethod · 0.95
newBulletStringMethod · 0.95
markerMethod · 0.95
node_brMethod · 0.80
node_ulMethod · 0.80
typesetStringMethod · 0.80
typesetNodeMethod · 0.80
fitVariableWidthFunction · 0.80
textMethod · 0.80
textBoxMethod · 0.80
newBulletStringMethod · 0.80
asBabelStringMethod · 0.80

Calls 2

makeStyleFunction · 0.90
BabelStringClass · 0.90

Tested by

no test coverage detected