Draws the BabelString at position p. >>> from pagebot.contexts import getContext >>> from pagebot.toolbox.units import pt, em >>> from pagebot.document import Document >>> from pagebot.elements import * >>> context = getContext() >>> style = dict(font
(self, bs, p)
| 876 | # Text. |
| 877 | |
| 878 | def drawString(self, bs, p): |
| 879 | """Draws the BabelString at position p. |
| 880 | |
| 881 | >>> from pagebot.contexts import getContext |
| 882 | >>> from pagebot.toolbox.units import pt, em |
| 883 | >>> from pagebot.document import Document |
| 884 | >>> from pagebot.elements import * |
| 885 | >>> context = getContext() |
| 886 | >>> style = dict(font='PageBot-Regular', fontSize=pt(100), leading=em(1)) |
| 887 | >>> bs = BabelString('Hkpx'+chr(10)+'Hkpx', style, context=context) |
| 888 | >>> context.drawString(bs, pt(100, 100)) |
| 889 | """ |
| 890 | |
| 891 | if not isinstance(bs, BabelString): |
| 892 | try: |
| 893 | bs = self.asBabelString(bs) |
| 894 | except TypeError as e: |
| 895 | print('TypeError: %s is not a string compatible type, %s' % (type(bs), e)) |
| 896 | return |
| 897 | |
| 898 | if bs._w is None and bs._h is None: |
| 899 | x, y = p |
| 900 | p = (pt(x), pt(y)) |
| 901 | self.text(bs, p) |
| 902 | else: |
| 903 | x, y = p |
| 904 | x = pt(x) |
| 905 | y = pt(y) |
| 906 | # x, y = point2D(upt(p)) |
| 907 | box = (x, y, bs.w or DEFAULT_WIDTH, bs.h or 1000) |
| 908 | self.textBox(bs, box) |
| 909 | |
| 910 | def drawText(self, bs, box): |
| 911 | """Draws the text block, in case a width or height is defined.""" |
no test coverage detected