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

Method textBox

Lib/pagebot/contexts/basecontext/bezierpath.py:593–648  ·  view source on GitHub ↗

Draws a txt with a font and fontSize in a box in the bezier path. If a font path is given the font will be installed and used directly. Style is normal optional PageBot style dictionary. Optionally an alignment can be set. Possible align values are: LEFT, CENTER, RIGHT.

(self, bs, x=None, y=None, w=None, h=None, clipPath=None, style=None)

Source from the content-addressed store, hash-verified

591 self.bp.text(bs, offset=p, font=font, fontSize=fontSize, align=align)
592
593 def textBox(self, bs, x=None, y=None, w=None, h=None, clipPath=None, style=None):
594 """Draws a txt with a font and fontSize in a box in the bezier path. If
595 a font path is given the font will be installed and used directly.
596 Style is normal optional PageBot style dictionary. Optionally an
597 alignment can be set. Possible align values are: LEFT, CENTER, RIGHT.
598 The default alignment is left. Optionally hyphenation can be provided.
599 Optionally txt can be a context-based BabelString. Optionally box can
600 be a DrawBotPath.
601
602 >>> from pagebot.toolbox.units import p, pt
603 >>> from pagebot import getContext
604 >>> context = getContext('Flat')
605 >>> path = BezierPath(context=context)
606 >>> path.textBox('ABC', x=10, y=10, w=400, h=400, style=dict(font=DEFAULT_FALLBACK_FONT_PATH, fontSize=pt(100)))
607 """
608 if hasattr(bs, 's'):
609 s = bs.s
610 tx, ty, tw, th = bs.bounds
611 else:
612 s = str(bs)
613 tx, ty, tw, th = 0, 0, 100, 100
614
615 if clipPath is None:
616 if x is None or x < 0:
617 x = 0
618 if y is None or y < 0:
619 y = 0
620 if w is None:
621 w = tw - tx
622 # TODO re-render the line to see if width wraps.
623 #if hasattr(bs, 's'):
624 # h = bs.getSize(w=w)[1]
625 #else:
626 # h = 100
627 if h is None:
628 h = th - ty
629
630 clipPathOrBox = x, y, w, h
631 else: # Otherwise take size from the string
632 if isinstance(clipPath, BezierPath):
633 clipPathOrBox = clipPath.bp # It can be another clippath
634 else: # Otherwise, assume it alread is a DrawBot.BezierPath or None
635 clipPathOrBox = clipPath
636
637 if style is None:
638 style = {}
639
640 font = style.get('font', DEFAULT_FALLBACK_FONT_PATH)
641
642 if hasattr(font, 'path'): # In case it is a Font instance, extract the path.
643 font = font.path
644
645 fontSize = upt(style.get('fontSize', DEFAULT_FONT_SIZE))
646 align = style.get('align')
647 hyphenation = style.get('hyphenation', False)
648 self.bp.textBox(s, clipPathOrBox, font=font, fontSize=fontSize, align=align, hyphenation=hyphenation)
649
650 def traceImage(self, imagePath, threshold=0.2, blur=None, invert=False,

Callers 2

drawStringMethod · 0.45
drawTextMethod · 0.45

Calls 2

uptFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected