Пример #1
0
def makeBodyPages(doc, bodyText):
    """Create a number of new pages in the document, as long as there is overflow. 
    If no new page size is given, it will take over the size of the document.
    """
    bs = BabelString(bodyText,
                     font=fontName,
                     fontSize=bodyFontSize,
                     lineHeight=bodyFontSize * leading)
    while True:
        page = doc.newPage()
        # Add text element with page number
        pn = BabelString(str(page.pn),
                         align=CENTER,
                         font=fontName,
                         fontSize=bodyFontSize)
        page.addElement(Text(pn, page.w / 2, padding / 2))
        e = TextBox(bs,
                    x=padding,
                    y=padding,
                    w=page.w - 2 * padding,
                    h=page.h - 2 * padding,
                    fill=1)
        page.addElement(e)
        bs = e.getOverflow(bs, doc=doc)
        if not bs.fs:
            break
Пример #2
0
def oneColumnPage(doc, theme=None, page=None, pageNumbers=None, **kwargs):
    """
    >>> from pagebotnano_010.document import Document
    >>> from pagebotnano_010.themes import BackToTheCity
    >>> theme = BackToTheCity()
    >>> doc = Document()
    >>> page = oneColumnPage(doc, theme, pageNumbers=NONE)
    >>> page.compose(doc)
    >>> page.find(MAIN)
    <TextBox name=mainText w=535 h=782>
    >>> page = doc.newPage(template=oneColumnPage)
    """
    page = _initialize(doc, page)
    # Add text element with the main text column of this page
    e = TextBox('', name=MAIN, x=page.pl, y=page.pb, w=page.pw, h=page.ph)
    page.addElement(e)

    if pageNumbers is None:
        pageNumbers = [LEFT, RIGHT]
    if LEFT in pageNumbers and page.pn % 2 == 0:  # Even page number?:
        bs = BabelString(str(page.pn), style)
        e = Text(bs, name=PN_LEFT, x=page.pl, y=page.pb / 2)
        page.addElement(e)
    if CENTER in pageNumbers:
        e = Text('', name=PN_CENTER, x=page.pl + page.pw, y=page.pb / 2)
        page.addElement(e)
    if RIGHT in pageNumbers:
        e = Text('', name=PN_RIGHT, x=page.pl + page.pw, y=page.pb / 2)
        page.addElement(e)
    return page
Пример #3
0
    def page(self, doc):
        """
        >>> from pagebotnano_010.document import Document
        >>> templates = OneColumnTemplates()
        >>> templates
        <OneColumnTemplates>
        >>> doc = Document(templates=templates)
        >>> page = templates.cover(doc) # The "page" template always must be there.
        >>> page.compose(doc)
        """
        page = self._initialize(doc, True)
        # Add text element with the main text column of this page
        e = TextBox('', name=MAIN, x=page.pl, y=page.pb, w=page.pw, h=page.ph)
        page.addElement(e)

        leftPageNumberStyle = doc.theme.getStyle('leftPageNumber')
        centerPageNumberStyle = doc.theme.getStyle('centerPageNumber')
        rightPageNumberStyle = doc.theme.getStyle('rightPageNumber')

        if leftPageNumberStyle is not None and page.pn % 2 == 0:  # Even page number?:
            bs = BabelString(str(page.pn), style)
            e = Text(bs, name=PN_LEFT, x=page.pl, y=page.pb / 2)
            page.addElement(e)
        if centerPageNumberStyle is not None:
            e = Text('', name=PN_CENTER, x=page.pl + page.pw, y=page.pb / 2)
            page.addElement(e)
        if rightPageNumberStyle is not None and page.pn % 2 != 0:  # Odd page number?:
            e = Text('', name=PN_RIGHT, x=page.pl + page.pw, y=page.pb / 2)
            page.addElement(e)
        return page
Пример #4
0
 def chapter(self, doc):
     """If this template is called, a new chapter starts.
     Create a new page, select is as doc.page, create a new text box and make select it
     as case.flow.
     """
     page = self._initialize(doc, True)
     e = TextBox('', name=MAIN, x=page.pl, y=page.pb, w=page.pw, h=page.ph)
     page.addElement(e)
     return page
Пример #5
0
    def colophon(self, doc):
        """Compose the template page with the position of the ColophonPage.
        Empty page, with only the title of the book centere on the page width.

        >>> from pagebotnano_010.document import Document
        >>> templates = OneColumnTemplates()
        >>> doc = Document()
        >>> page = templates.colophon(doc) # Creating a new page
        >>> page.compose(doc)
        """
        page = self._initialize(doc, True)
        e = TextBox('', name=MAIN, x=page.pl, y=page.pb, w=page.pw, h=page.ph)
        page.addElement(e)
        return page
Пример #6
0
def colophonPage(doc, theme=None, page=None, **kwargs):
    """Compose the template page with the position of the ColophonPage.
    Empty page, with only the title of the book centere on the page width.

    >>> from pagebotnano_010.document import Document
    >>> from pagebotnano_010.themes import BackToTheCity
    >>> theme = BackToTheCity()
    >>> doc = Document()
    >>> page = colophonPage(doc, theme) # Creating a new page
    >>> page.compose(doc, page)
    >>> page.find(MAIN)
    <TextBox name=mainText w=535 h=782>
    """
    page = _initialize(doc, page)
    e = TextBox('', name=MAIN, x=page.pl, y=page.pb, w=page.pw, h=page.ph)
    page.addElement(e)
    return page
Пример #7
0
def coverPage(doc, theme=None, page=None, **kwargs):
    page = _initialize(doc, page)
    # Fill the cover page with a theme background color
    e = Rect(0, 0, page.w, page.h, fill=theme.getColor(1,
                                                       4))  # Dark cover color
    page.addElement(e)

    # Add title and author, centered on top-half of the cover.
    e = TextBox('',
                name='Title',
                x=page.pl / 2,
                y=page.h / 2,
                w=page.pw,
                h=page.ph / 2)
    page.addElement(e)

    e = Image(x=pad, y=pad, w=page.w - 2 * pad)
    page.addElement(e)
Пример #8
0
    def title(self, doc):
        page = self._initialize(doc, True)
        # Fill the cover page with a theme background color
        e = Rect(0, 0, page.w, page.h,
                 fill=doc.theme.getColor(1, 4))  # Dark cover color
        page.addElement(e)

        # Add title and author, centered on top-half of the cover.
        e = TextBox('',
                    name='Title',
                    x=page.pl / 2,
                    y=page.h / 2,
                    w=page.pw,
                    h=page.ph / 2)
        page.addElement(e)

        e = Image(x=page.pl, y=page.pb, w=page.pw)
        page.addElement(e)
        return page
Пример #9
0
    def frenchTitle(self, doc):
        """In Dutch it is called the "Franse pagina", which comes from
        "Voordehandse pagina" (the first page in the book)
        """
        page = self._initialize(doc, True)
        # Fill the cover page with a theme background color
        e = Rect(0, 0, page.w, page.h, fill=color(0.8))  # Dark cover color
        page.addElement(e)

        # Add title and author, centered on top-half of the cover.
        e = TextBox('',
                    name='Title',
                    x=page.pl / 2,
                    y=page.h / 2,
                    w=page.pw,
                    h=page.ph / 2)
        page.addElement(e)

        e = Image(x=page.pl, y=page.pb, w=page.pw)
        page.addElement(e)
        return page
Пример #10
0
    def getTextBox(self, e=None):
        """Answer the last TextBox element if it exists. 
        Otherwise create it first.

        >>> ts = Typesetter()
        >>> e = ts.getTextBox()
        >>> e
        <TextBox name=TextBox w=100 h=None>
        >>> e1 = ts.getTextBox() # Gets the existing last TextBox
        >>> e is e1
        True
        >>> e2 = TextBox('', x=0, y=0, w=DEFAULT_WIDTH)
        >>> ts.galley.addElement(e2)
        <TextBox name=TextBox w=100 h=None>
        >>> e2 is ts.getTextBox() # Now finding the new one as last
        True
        """
        if e is None:
            e = self.galley
        if not e.elements or not isinstance(e.elements[-1], TextBox):
            e.addElement(TextBox('', x=0, y=0, w=e.w or DEFAULT_WIDTH))
        return e.elements[-1]
Пример #11
0
    def cover(self, doc):
        page = self._initialize(doc, True)
        # Fill the cover page with a theme background color
        e = Rect(0, 0, page.w, page.h,
                 fill=doc.theme.getColor(1, 4))  # Dark cover color
        page.addElement(e)

        # Add title and author, centered on top-half of the cover.
        try:
            title = doc.cd.elements[0].bs
        except (IndexError, AttributeError):
            title = BabelString('Untitled')
        e = TextBox(title,
                    name='Title',
                    x=page.pl / 2,
                    y=page.h / 2,
                    w=page.pw,
                    h=page.ph / 2)
        page.addElement(e)

        e = Image(x=page.pl, y=page.pb, w=page.pw)
        page.addElement(e)
        return page
Пример #12
0
    def compose(self):
        """This is the core of a publication, composing the specific
        content of the document. The compose method gets called
        before building and exporting the self.doc document.
        """
        fontSize = 11
        headSize = fontSize*1.5
        titleSize = 36
        subTitleSize = titleSize * 0.5
        pad = 48

        self.theme.styles['h1'] = dict(font='Georgia-Bold', 
            lineHeight=titleSize*1.1, 
            fontSize=titleSize,
            align=CENTER,
            fill=1, # White title on dark cover background
            language=EN, hyphenation=False,
        )
        self.theme.styles['h2'] = dict(font='Georgia-Italic',
            paragraphTopSpacing=subTitleSize/2,
            lineHeight=subTitleSize*1.2, 
            fontSize=subTitleSize,
            align=CENTER,
            fill=1, # White title on dark cover background
            language=EN, hyphenation=False,
        )
        headStyle = dict(font='Georgia', 
            lineHeight=headSize*1.3, 
            fontSize=headSize,
            fill=0, # Black text
            language=EN, hyphenation=False,
        )
        subHeadStyle = dict(font='Georgia-Italic', 
            lineHeight=headSize*0.8*1.4, 
            fontSize=headSize*0.8,
            fill=0, # Black text
            language=EN, hyphenation=False,
        )
        bodyStyle = dict(font='Georgia', 
            lineHeight=fontSize*1.4, 
            fontSize=fontSize,
            fill=0, # Black text
            language=EN, hyphenation=True,
        )
        pageNumberLeftStyle = dict(
            font='Georgia', 
            fontSize=9,
            fill=0, # Black text
            align=LEFT, 
        )
        pageNumberRightStyle = copy(pageNumberLeftStyle)
        pageNumberRightStyle['align'] = RIGHT


        # Make the cover page.
        page = coverPage(self.theme, self.doc)

        # Make “French” “Voordehandse” page.
        page = self.doc.newPage() # No page number here.

        # CENTER text alignment overwrites the value in headStyle.
        # fontSize overwrites the value in headStyle
        bs = BabelString('AAAA'+'\n', headStyle, fontSize=fontSize, align=CENTER)
        e = Text(bs, x=page.w/2, y=page.h*4/5)
        page.addElement(e)

        # Make Title page.
        page = titlePage(self.theme, self.doc)
        page.compose(self.doc, page)
        bs = BabelString('VVVVV'+'\n', headStyle, align=CENTER)
        bs.append(BabelString('AUTHOR', subHeadStyle, align=CENTER))
        page.find(MAIN).bs = bs

        # For all the elements that are collected in the galley, assume that
        # the TextBoxes are chapters, creating a new page for them.
        # If the TextBox does not fit on the page, keep adding new pages 
        # until all of the BabelString overfill is processed.

        for ge in self.galley.elements:

            if isinstance(ge, TextBox):

                bs = ge.bs # Get the BabelString from the galley box.

                for n in range(self.MAX_PAGES):
                    page = self.doc.newPage()

                    # Add text element with page number
                    self.addPageNumber(page, pad, pageNumberLeftStyle, pageNumberRightStyle)

                    # Add text element with the main text column of this page
                    e = TextBox(bs, x=pad, y=pad, w=page.w-2*pad, h=page.h-2*pad)
                    page.addElement(e)

                    # If there is overflow on this page, continue looping creating
                    # as many pages as needed to fill all the text in self.content.
                    # Otherwise break the loop, as we are done placing content.
                    bs = e.getOverflow(bs, doc=self.doc)
                    # Test on this “incomplete” BabelString, as it only has a cached FS
                    if not bs.fs:
                        break

            elif isinstance(ge, Image): # Images not supported yet
                page = self.doc.newPage()

                self.addPageNumber(page, pad, pageNumberLeftStyle, pageNumberRightStyle)
                page.addElement(ge)
                ge.w = page.w - pad
                iw, ih = ge.getSize(self.doc)
                ge.x = pad/2
                ge.y = page.h - pad - ih