Exemplo n.º 1
0
    def compose(self, doc, page, parent=None):
        """Compose the cell as background color, with recipes text block on top.

        """
        label = self._getLabel()
        bs = BabelString(label, self.style)
        tw, th = bs.textSize

        if self.layout == SPOTSAMPLE:
            # Mark abbreviated color recipes by parenthesis.
            # They are not an exact match, but closest known value for this color.

            # Used padding-bottom (self.pb) also as gutter between color rectangle and labels
            e = Rect(x=0, y=th+self.pb, w=self.w, h=self.h-th-self.pb, fill=self.c)
            self.addElement(e)

            e = Text(bs, x=self.w/2, y=th-self.style.get('lineHeight', 0) + self.pb, w=self.w, h=self.h)
            self.addElement(e)

        else: # Default layout is OVERLAY
            e = Rect(x=0, y=0, w=self.w, h=self.h, fill=self.c)
            self.addElement(e)

            e = Text(bs, x=self.w/2, y=th-self.style.get('lineHeight', 0) + self.pb, w=self.w, h=self.h)
            self.addElement(e)
Exemplo n.º 2
0
    def coverPage(cls, theme, doc, page=None, parent=None, **kwargs):
        page = cls._initialize(theme, doc, page, parent)
        # 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=page.pl, y=page.pb, w=page.pw)
        page.addElement(e)
Exemplo n.º 3
0
    def compose(self, doc, parent=None):
        """Compose the cell as background color, with recipes text block on top.

        """
        label = self._getLabel()

        if self.layout == SPOTSAMPLE:
            # Mark approximated color recipes by parenthesis.
            # They are not an exact match, but closest known value for this color.

            bs = BabelString(label, self.style)
            tw, th = bs.textSize

            # Used padding-bottom (self.pb) also as gutter between color rectangle and labels
            e = Rect(x=self.pl, y=th+self.pb, w=self.pw, h=self.h-th-self.pb, fill=self.c)
            self.addElement(e)

            e = Text(bs, x=self.w/2, y=th-self.style.get('fontSize') + self.pb, w=self.w, h=self.h)
            self.addElement(e)

        else: # Default layout is OVERLAY. 
            # Check the text color to be enough contrast with the background.
            # Otherwise flip between black and white.
            style = copy(self.style) # Copy as we are going to alter it
            if self.c.gray < 0.33: # Dark color?
                labelText = color(1) # White label text
            else:
                labelText = color(0) # Black label text
            style['fill'] = labelText
            bs = BabelString(label, style)
            tw, th = bs.textSize

            e = Rect(x=self.pl, y=self.pb, w=self.pw, h=self.ph, fill=self.c)
            self.addElement(e)

            e = Text(bs, x=self.w/2, y=th-self.style.get('fontSize')*2/3 + self.pb, w=self.w, h=self.h)
            self.addElement(e)
Exemplo n.º 4
0
    def compose(self, doc, page, parent=None):
        """Compose the cell as background color, with recipes text block on top.

        """
        e = Rect(x=0, y=0, w=self.w, h=self.h, fill=self.c)
        self.addElement(e)

        # Mark approximated color recipes by parenthesis.
        # They are not an exact match, but closest known value for this color.
        Cmyk, cMyk, cmYk, cmyK = self.c.cmyk 
        s = '#%s\n(%s)\n(cmyk %d %d %d %d)\n(Spot %s)\n(RAL %s)' % \
            (self.c.hex, self.c.name.capitalize(), Cmyk*100, cMyk*100, cmYk*100, cmyK*100, 
                self.c.spot, self.c.ral)
        if self.themePosition is not None:
            s += '\nColor[%d][%d]' % (base, shade)
        bs = BabelString(s, self.style)
        tw, th = bs.textSize
        e = Text(bs, x=self.w/2, y=th-self.style.get('lineHeight', 0)/2, w=self.w, h=self.h)
        self.addElement(e)
Exemplo n.º 5
0
    def frenchTitle(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
Exemplo n.º 6
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
Exemplo n.º 7
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

        titleStyle = dict(
            font='Georgia-Bold',
            lineHeight=titleSize * 1.1,
            fontSize=titleSize,
            align=CENTER,
            fill=1,  # White title on dark cover background
            language=EN,
            hyphenation=False,
        )
        subTitleStyle = 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 = self.doc.newPage()

        # Fill the cover page with a random dark color
        e = Rect(0, 0, page.w, page.h,
                 fill=self.coverColor)  # Dark cover color
        page.addElement(e)

        # Add title and author, centered on top-half of the cover.
        titleBs = BabelString(self.title + '\n', titleStyle)
        authorBs = BabelString(self.author, subTitleStyle)
        bs = titleBs + authorBs
        e = TextBox(bs,
                    x=pad / 2,
                    y=page.h / 2,
                    w=page.w - pad,
                    h=page.h / 2 - pad)
        page.addElement(e)

        if self.coverImagePath is not None:  # Only if not defined.
            e = Image(self.coverImagePath, x=pad, y=pad, w=page.w - 2 * pad)
            page.addElement(e)

        # Make “French” “Voordehandse” page.
        page = self.doc.newPage()  # No page number here.
        page.applyTemplate()
        # CENTER text alignment overwrites the value in headStyle.
        # fontSize overwrites the value in headStyle
        bs = BabelString(self.title + '\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 = self.doc.newPage(template=TitlePage())  # No page number here.
        page.compose(self.doc, page)
        bs = BabelString(self.title + '\n', headStyle, align=CENTER)
        bs.append(BabelString(self.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