Places the Babelstring instance at position p. The position can be any 2D or 3D points tuple. Currently the z-axis is ignored. The FlatContext version of the BabelString should contain Flat.text. >>> from pagebot.toolbox.units import pt >>> context = FlatContext()
(self, s, p)
| 604 | return r*256, g*256, b*256 |
| 605 | |
| 606 | def text(self, s, p): |
| 607 | """Places the Babelstring instance at position p. The position can be |
| 608 | any 2D or 3D points tuple. Currently the z-axis is ignored. The |
| 609 | FlatContext version of the BabelString should contain Flat.text. |
| 610 | |
| 611 | >>> from pagebot.toolbox.units import pt |
| 612 | >>> context = FlatContext() |
| 613 | >>> style1 = dict(font='PageBot-Regular', fontSize=pt(100), textFill=(1, 0, 0)) |
| 614 | >>> style2 = dict(font='PageBot-Bold', fontSize=pt(50), textFill=(0, 1, 0.5)) |
| 615 | >>> s = context.newString('ABCD', style=style1) |
| 616 | >>> s.add('EFGH', style=style2) |
| 617 | >>> s, s.__class__.__name__ |
| 618 | ($ABCDEFGH$, 'BabelString') |
| 619 | |
| 620 | >>> context.newPage(1000, 1000) |
| 621 | >>> context.fill(None) |
| 622 | >>> context.stroke(0, 0.5) |
| 623 | >>> context.rect(10, 500, 20, 20) |
| 624 | >>> context.text(s, (10, 500)) |
| 625 | >>> context.saveDrawing('_export/Flat-Text.pdf') |
| 626 | """ |
| 627 | if isinstance(s, str): |
| 628 | bs = self.newString(s) |
| 629 | else: |
| 630 | bs = s |
| 631 | assert isinstance(bs, BabelString) |
| 632 | assert self.page is not None, 'FlatContext.text: self.page is not set.' |
| 633 | x, y = p |
| 634 | x, y = self.getTransformed(x, y) |
| 635 | y -= bs.topLineDescender |
| 636 | xpt, ypt = pt(x, y) # Make sure to convert to points |
| 637 | self._place(bs, xpt, ypt) |
| 638 | |
| 639 | def textBox(self, s, r=None, clipPath=None, align=None): |
| 640 | """Places the babelstring instance inside rectangle `r`. The rectangle |
no test coverage detected