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

Method overflow2Next

Lib/pagebot/elements/text.py:646–728  ·  view source on GitHub ↗

Try to fix if there is overflow. If there is overflow outside the page, then find the page.next with it's target element to continue, until all text fits or the element has not nextElement defined. Answers the page and result, as the page may have been altered. Overflow is

(self, processed=None)

Source from the content-addressed store, hash-verified

644 return self.nextElement is None and self.getOverflow()
645
646 def overflow2Next(self, processed=None):
647 """Try to fix if there is overflow. If there is overflow outside the
648 page, then find the page.next with it's target element to continue,
649 until all text fits or the element has not nextElement defined. Answers
650 the page and result, as the page may have been altered. Overflow is
651 solved by element condition Overflow2Next().
652
653 >>> from pagebot.document import Document
654 >>> from pagebot import getContext
655 >>> context = getContext()
656 >>> doc = Document(w=1000, h=1000, context=context)
657 >>> page1 = doc[1]
658 >>> page1
659 <Page #1 default (1000pt, 1000pt)>
660 >>> bs = BabelString('AAA ' * 1000, style=dict(font='Roboto', fontSize=pt(20), leading=pt(12)), context=context)
661 >>> # Fix h to lock elastic height. Overflow is now defined.
662 >>> t1 = Text(bs, name="T1", w=100, h=200, nextElement='T2', parent=page1)
663 >>> #t1.isOverflow()
664 # Overflow shows here
665 >>> t1.bs.getStyleAtIndex(0)['font']
666 'Roboto'
667 >>> t1.bs.getStyleAtIndex(0)['fontSize']
668 20pt
669 >>> t2 = Text(name="T2", w=100, h=200, nextElement='T1', nextPage=page1.next, parent=page1)
670 >>> #len(str(t2.bs))
671 #4000
672 >>> #len(t1.isOverflow())
673 #3744 # FIXME: Flat yields larger overflow
674 """
675 result = True
676 overflow = self.getOverflow()
677 page = self.getElementPage()
678 nextElement = None
679 if processed is None:
680 # Keep track of what we did, to avoid circular references.
681 processed = set()
682
683 # If there is text overflow and there is a next element?
684 if overflow and self.nextElement:
685
686 if self.nextPage: # Try to use element on another page?
687 # Try on several types in which the next page can be defined.
688 # Force to next page, relative to current.
689 if page is not None and self.nextPage == 'next':
690 page = page.next
691 elif isinstance(self.nextPage, Element):
692 page = self.nextPage
693 elif page is not None and isinstance(self.nextPage, (int, float)):
694 # Offset to next page.
695 page = page.parent.pageNumber(page) + self.nextPage
696 else:
697 # Try by name.
698 page = self.doc.getPage(self.nextPage)
699 if page is not None:
700 nextElement = page.getElementByName(self.nextElement)
701
702 # Find element on this page.
703 nextElement = page.getElementByName(self.nextElement)

Callers 2

solveMethod · 0.45
solveMethod · 0.45

Calls 6

getOverflowMethod · 0.95
getPageMethod · 0.80
getElementByNameMethod · 0.80
addMethod · 0.80
getElementPageMethod · 0.45
deepFindMethod · 0.45

Tested by

no test coverage detected