Places the babelstring instance inside rectangle `r`. The rectangle can be any 2D or 3D points tuple. Currently the z-axis is ignored. The FlatContext version of the BabelString should contain Flat.text. TODO: make clipPath work. TODO: make align work. TODO:
(self, s, r=None, clipPath=None, align=None)
| 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 |
| 641 | can be any 2D or 3D points tuple. Currently the z-axis is ignored. The |
| 642 | FlatContext version of the BabelString should contain Flat.text. |
| 643 | |
| 644 | TODO: make clipPath work. |
| 645 | TODO: make align work. |
| 646 | TODO: wrap placedText so we can derive length of text without overflow and |
| 647 | print the result. |
| 648 | TODO: use PageBot hyphenation. |
| 649 | |
| 650 | See also drawBot.contexts.baseContext textbox() |
| 651 | |
| 652 | >>> from pagebot.toolbox.units import pt |
| 653 | >>> from pagebot import getContext |
| 654 | >>> from pagebot.contributions.filibuster.blurb import Blurb |
| 655 | >>> from pagebot.fonttoolbox.objects.font import findFont |
| 656 | >>> from pagebot.style import makeStyle |
| 657 | >>> w = 400 |
| 658 | >>> h = 300 |
| 659 | >>> context = getContext('Flat') |
| 660 | >>> context.newPage(w, h) |
| 661 | >>> txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean hendrerit auctor dolor eu interdum. ' |
| 662 | >>> font = findFont('Roboto-Regular') |
| 663 | >>> style = dict(font=font, fontSize=pt(20)) |
| 664 | >>> style = makeStyle(style=style) |
| 665 | >>> bs = context.newString(txt * 7, style=style) |
| 666 | >>> bs |
| 667 | $Lorem ipsu...$ |
| 668 | >>> r = (10, 262, 200, 300) |
| 669 | >>> #of = context.textBox(bs, r) # Calculate overflow in the box |
| 670 | >>> #of |
| 671 | 'dolor eu interdum. ' |
| 672 | """ |
| 673 | if isinstance(s, str): |
| 674 | s = self.newString(s) |
| 675 | assert isinstance(s, BabelString) |
| 676 | assert self.page is not None, 'FlatString.text: self.page is not set.' |
| 677 | assert r is not None |
| 678 | xpt, ypt, wpt, hpt = pt(r) |
| 679 | ypt = self.height - ypt |
| 680 | self._place(s, xpt, ypt, wpt, hpt) |
| 681 | |
| 682 | def textOverflow(self, s, box, align=LEFT): |
| 683 | """Answers the the box overflow as a new FlatString in the current |