示例#1
0
    def initialize(self, padding=None, gutter=None, columns=None, **kwargs):
        u"""Initialize the generic book templates. """
        blurb = Blurb()

        # TODO: Solve for left/right templates.
        if padding is None:
            padding = self.PADDING
        if gutter is None:
            gutter = self.GUTTER
        if columns is None:
            columns = self.COLUMNS

        fillColor1 = (0.2, 0.2, 0.9, 0.6)  # Temp fill of markers.
        fillColor2 = (0.9, 0.2, 0.9, 0.6)  # Temp fill of markers.
        fillColor3 = (0.9, 0.2, 0.3, 0.6)  # Temp fill of markers.
        fillColor4 = (0.9, 0.9, 0.3, 0.6)  # Temp fill of markers.
        fillColor1 = fillColor2 = fillColor3 = fillColor4 = None

        w, h = self.w, self.h
        cw = (w - 2 * padding - gutter * (columns - 1)) / columns
        cwg = cw + gutter
        lineW = 4

        # Max amount of words return by the blurb generator.
        maxHeadline = 6
        maxHeadlineShort = 4
        maxAnkeiler = 30

        fontPaths = getFontPaths()
        #for fontName, path in getFontPaths().items():
        #    if 'Escrow' in fontName:
        #        print(fontName, path)
        #newspaperTitleFont = fontPaths['Escrow-Black']
        #newspaperTitleFont = 'Proforma Book'
        newspaperTitleFont = 'Upgrade Semibold'
        h1Font = 'Upgrade Medium'
        bodyFont = 'Upgrade Book'

        titleStyle = dict(font=newspaperTitleFont,
                          fontSize=140,
                          w=(columns - 2) * cw,
                          textFill=0)
        h1Style = dict(font=h1Font, fontSize=90, leading=90, textFill=0)
        h2Style = dict(font=h1Font, fontSize=60, leading=60, textFill=0)
        bodyStyle = dict(font=bodyFont,
                         fontSize=14,
                         hyphenation=True,
                         leading=18,
                         textFill=0,
                         firstParagraphIndent=2 * gutter,
                         firstLineIndent=gutter)
        h1IntroStyle = dict(font=bodyFont,
                            fontSize=45,
                            hyphenation=True,
                            leading=52,
                            textFill=0)
        h2IntroStyle = dict(font=bodyFont,
                            fontSize=30,
                            hyphenation=True,
                            leading=36,
                            textFill=0)

        titleLine = dict(strokeWidth=1, stroke=0)

        # grid-template-columns, grid-template-rows, grid-auto-rows, grid-column-gap, grid-row-gap,
        gridX = []
        for n in range(columns):
            gridX.append([cw, gutter])
        gridX[-1][-1] = 0
        gridY = [(None, 0)]  # Default is full height of columns

        # Template 'Front'

        t = Template(w=w,
                     h=h,
                     name='Front',
                     padding=padding,
                     gridX=gridX,
                     gridY=gridY)

        # Newspaper name with border lines on top and bottom
        #self.title = 'NORTHAMPTON GLOBE'
        bs = self.view.newString(self.title.upper(), style=titleStyle)
        _, nameHeight = bs.size()
        title = Title(parent=t,
                      mb=2 * gutter,
                      h=nameHeight,
                      conditions=[Top2Top(), Fit2Width()])
        tb = newTextBox(bs,
                        parent=title,
                        h=nameHeight,
                        xTextAlign=CENTER,
                        pt=gutter,
                        borderTop=titleLine,
                        borderBottom=titleLine,
                        conditions=[Fit2Width()])

        # Place article 3 columns

        cc = 3  # Column width of this article.
        article = Article(parent=t,
                          h=h / 3,
                          w=cc * cwg - gutter,
                          mr=gutter,
                          mb=gutter,
                          fill=fillColor1,
                          conditions=[Left2Left(), Float2Top()])

        s = None  #'Happy birthday, Jill'
        headLine = self.getHeadline(s,
                                    h2Style,
                                    cnt=maxHeadline,
                                    w=cc * cwg - gutter)
        newTextBox(headLine,
                   parent=article,
                   w=cc * cwg - gutter,
                   fill=fillColor2,
                   conditions=[Left2Left(), Float2Top()])

        intro = self.getAnkeiler(cnt=maxAnkeiler)
        bs = self.view.newString(intro, style=h2IntroStyle)
        newTextBox(bs,
                   parent=article,
                   w=cc * cwg - gutter,
                   mt=gutter,
                   mb=gutter,
                   fill=fillColor3,
                   conditions=[Left2Left(), Float2Top()])

        for n in range(cc):
            dummyArticle = blurb.getBlurb('article', newLines=True)
            bs = self.view.newString(dummyArticle, style=bodyStyle)
            newTextBox(bs,
                       parent=article,
                       w=cw,
                       mr=gutter,
                       h=10,
                       fill=fillColor4,
                       conditions=[
                           Right2Right(),
                           Float2Top(),
                           Float2Left(),
                           Fit2Bottom()
                       ])

        cc = 3  # Column width of this article.
        article = Article(parent=t,
                          h=h / 4,
                          w=cc * cwg - gutter,
                          mr=gutter,
                          mb=gutter,
                          pt=gutter,
                          borderTop=titleLine,
                          conditions=[Left2Left(), Float2Top()])

        s = None  #'Explore Northampton in spring'
        headLine = self.getHeadline(s,
                                    h2Style,
                                    cnt=maxHeadline,
                                    w=cc * cwg - 2 * gutter)
        newTextBox(headLine,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg,
                   conditions=[Left2Left(), Float2Top()])

        intro = blurb.getBlurb('article_ankeiler', cnt=maxAnkeiler)
        bs = self.view.newString(intro, style=h2IntroStyle)
        newTextBox(bs,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg,
                   mt=gutter,
                   mb=gutter,
                   conditions=[Left2Left(), Float2Top()])

        for n in range(cc):
            dummyArticle = blurb.getBlurb('article', newLines=True)
            bs = self.view.newString(dummyArticle, style=bodyStyle)
            newTextBox(bs,
                       parent=article,
                       w=cw,
                       mr=gutter,
                       conditions=[
                           Left2RightSide(),
                           Float2Top(),
                           Float2Left(),
                           Fit2Bottom()
                       ])

        cc = 3  # Column width of this article.
        article = Article(parent=t,
                          h=h / 4,
                          w=cc * cwg - gutter,
                          mr=gutter,
                          mb=gutter,
                          pt=gutter,
                          borderTop=titleLine,
                          borderBottom=titleLine,
                          conditions=[Left2Left(),
                                      Float2Top(),
                                      Fit2Bottom()])

        s = None  #'Mothersday for Sara & Jill'
        headLine = self.getHeadline(s,
                                    h2Style,
                                    cnt=maxHeadline,
                                    w=cc * cwg - 2 * gutter)
        newTextBox(headLine,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg,
                   conditions=[Left2Left(), Float2Top()])

        intro = self.getAnkeiler(cnt=maxAnkeiler)
        bs = self.view.newString(intro, style=h2IntroStyle)
        newTextBox(bs,
                   parent=article,
                   w=cc * cwg,
                   mt=gutter,
                   mb=gutter,
                   conditions=[Left2Left(), Float2Top()])

        for n in range(cc):
            dummyArticle = blurb.getBlurb('article', newLines=True)
            bs = self.view.newString(dummyArticle, style=bodyStyle)
            newTextBox(bs,
                       parent=article,
                       pr=gutter,
                       w=cw,
                       mr=gutter,
                       conditions=[
                           Left2RightSide(),
                           Float2Top(),
                           Float2Left(),
                           Fit2Bottom()
                       ])

        # Place article 4 columns with photo
        cc = 4
        article = Article(
            parent=t,
            w=cc * cwg,
            h=h / 2,
            pr=gutter,
            conditions=[Right2RightSide(),
                        Float2Top(),
                        Float2Left()])

        newRect(h=cc * cw * 2 / 3,
                mb=gutter,
                parent=article,
                fill=0.8,
                stroke=0,
                strokeWidth=0.5,
                conditions=[Left2Left(), Top2Top(),
                            Fit2Width()])

        s = None  #'Petr & Claudia visiting soon'
        headLine = self.getHeadline(s, h1Style, cnt=5, w=cc * cwg - 2 * gutter)
        newTextBox(headLine,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg,
                   pb=gutter,
                   conditions=[Left2Left(),
                               Float2Top(),
                               Fit2Width()])

        for n in range(cc):
            if n == 3:
                newRect(mb=gutter,
                        parent=article,
                        w=cw,
                        fill=0.8,
                        stroke=0,
                        strokeWidth=0.5,
                        conditions=[
                            Right2RightSide(),
                            Float2Top(),
                            Float2Left(),
                            Fit2Bottom()
                        ])
            else:
                dummyArticle = blurb.getBlurb('article', newLines=True)
                bs = self.view.newString(dummyArticle, style=bodyStyle)
                newTextBox(bs,
                           parent=article,
                           pr=gutter,
                           w=cw,
                           mr=gutter,
                           h=10,
                           conditions=[
                               Right2Right(),
                               Float2Top(),
                               Float2Left(),
                               Fit2Bottom()
                           ])

        cc = 2  # Column width of this article.
        article = Article(parent=t,
                          w=cc * cwg,
                          borderTop=titleLine,
                          mb=gutter,
                          borderBottom=titleLine,
                          conditions=[
                              Right2Right(),
                              Float2Top(),
                              Float2Left(),
                              Fit2Bottom()
                          ])

        s = None  #'AirB&B stock up 450%'
        headLine = self.getHeadline(s,
                                    h2Style,
                                    cnt=maxHeadlineShort,
                                    w=cc * cwg - gutter)
        newTextBox(headLine,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg,
                   pt=gutter,
                   conditions=[Left2Left(), Float2Top()])

        intro = self.getAnkeiler(cnt=maxAnkeiler)
        bs = self.view.newString(intro, style=h2IntroStyle)
        newTextBox(bs,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg,
                   mt=gutter,
                   mb=gutter,
                   conditions=[Left2Left(), Float2Top()])

        for n in range(cc):
            dummyArticle = blurb.getBlurb('article', newLines=True)
            bs = self.view.newString(dummyArticle, style=bodyStyle)
            newTextBox(bs,
                       parent=article,
                       pr=gutter,
                       w=cwg,
                       conditions=[
                           Left2RightSide(),
                           Float2Top(),
                           Float2Left(),
                           Fit2Bottom()
                       ])

        cc = 2  # Column width of this article.
        article = Article(parent=t,
                          w=cc * cwg,
                          borderTop=titleLine,
                          mb=gutter,
                          borderBottom=titleLine,
                          conditions=[
                              Right2RightSide(),
                              Float2Top(),
                              Float2Left(),
                              Fit2Bottom()
                          ])

        s = None  #u'Tay & Lan’s best moms'
        headLine = self.getHeadline(s,
                                    h2Style,
                                    cnt=maxHeadlineShort,
                                    w=cc * cwg - gutter)
        newTextBox(headLine,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg,
                   pt=gutter,
                   conditions=[Left2Left(), Float2Top()])

        intro = self.getAnkeiler(cnt=maxAnkeiler)
        bs = self.view.newString(intro, style=h2IntroStyle)
        newTextBox(bs,
                   parent=article,
                   pr=gutter,
                   w=cc * cwg - gutter,
                   mr=gutter,
                   mt=gutter,
                   mb=gutter,
                   conditions=[Left2Left(), Float2Top()])

        newRect(
            mb=gutter,
            parent=article,
            h=200,
            maxH=
            MAX_HEIGHT,  # TODO: Why need to set this, as r.maxH is 100 here.
            fill=0.8,
            stroke=0,
            strokeWidth=0.5,
            conditions=[Left2Left(), Float2Top(),
                        Fit2Width()])

        for n in range(cc):
            dummyArticle = blurb.getBlurb('article', newLines=True)
            bs = self.view.newString(dummyArticle, style=bodyStyle)
            newTextBox(bs,
                       parent=article,
                       pr=gutter,
                       w=cwg,
                       conditions=[
                           Left2RightSide(),
                           Float2Top(),
                           Float2Left(),
                           Fit2Bottom()
                       ])

        self.addTemplate(t.name, t)

        # Template 'MainPage'

        t = Template(w=w,
                     h=h,
                     name='MainPage',
                     padding=padding,
                     gridX=gridX,
                     gridY=gridY)
        for n in range(columns):
            if n == 0:
                cc = 3
                headLine = self.getHeadline(None, h2Style, cnt=maxHeadline)
                newTextBox(headLine,
                           parent=t,
                           pr=gutter,
                           w=cc * cwg,
                           conditions=[Left2Left(), Float2Top()])
                intro = self.getAnkeiler(cnt=maxAnkeiler)
                bs = self.view.newString(intro, style=h2IntroStyle)
                newTextBox(bs,
                           parent=t,
                           pr=gutter,
                           w=cc * cwg,
                           mt=gutter,
                           mb=gutter,
                           conditions=[Left2Left(), Float2Top()])

            dummyArticle = blurb.getBlurb('article', newLines=True)
            bs = self.view.newString(dummyArticle, style=bodyStyle)
            newTextBox(bs,
                       parent=t,
                       pr=gutter,
                       w=cw + gutter,
                       z=0,
                       conditions=[
                           Right2RightSide(),
                           Float2Top(),
                           Fit2Bottom(),
                           Float2Left()
                       ])
        self.addTemplate(t.name, t)
示例#2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------
#     Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens & Font Bureau
#     www.pagebot.io
#
#     P A G E B O T
#
#     Licensed under MIT conditions
#     Example written by Frederik Berlaen
#
#     Supporting usage of DrawBot, www.drawbot.com
# -----------------------------------------------------------------------------
#
#     testFiliBusterArticle.py
#
from pagebot.contributions.filibuster.blurb import Blurb

NO_TAGS = True # Flag to show/hide HTML tags in output

blurb = Blurb()

print(blurb.getBlurb('news_headline', noTags=NO_TAGS)+'\n')
print(blurb.getBlurb('article_ankeiler', noTags=NO_TAGS)+'\n')
print(blurb.getBlurb('article_summary', noTags=NO_TAGS)+'\n')
print(blurb.getBlurb('article', noTags=NO_TAGS)+'\n')
示例#3
0
red = rgb(255, 0, 0)
black = rgb(0, 0, 0)
bungee = findFont('Bungee-Regular')
bungeeFlat = font.open(bungee.path)

blurb = Blurb()
types = blurb.getBlurbTypes()

txts = []

for i in range(5):
    i = random.randint(0, len(types))
    t = types[i]
    print(t)
    txts.append(blurb.getBlurb(t, noTags=True))

txt = '. '.join(txts)
#print(txt)
headline = strike(bungeeFlat).color(red).size(20, 24)
body = strike(bungeeFlat).color(black).size(10, 12)

redStroke = shape().stroke(red).width(0.5)
blackFill = shape().nostroke().fill(black)
blackStroke = shape().stroke(black).width(0.2)

d = document(w, h, 'pt')
print(id(d))
d.meta('hello')
p = d.addpage()
p.place(redStroke.circle(50, 50, 20))
示例#4
0
# TODO: move to basics when finished.

H, W = A3
W = pt(W)
H = pt(H)
M = 36

roboto = findFont('Roboto-Regular')
robotoBold = findFont('Roboto-Bold')

bungee = findFont('Bungee-HairlineRegular')
bungeeSize = 48

blurb = Blurb()
txt = blurb.getBlurb('news_headline', noTags=True)

testContexts = (
    (getContext('DrawBot'), '_export/testDrawBotString.pdf'),
    (getContext('Flat'), '_export/testFlatString.pdf'),
)


def drawLines(page):
    page.context.fill(noColor)
    page.context.stroke((0.2, 0.7, 0.5, 0.3))
    page.context.strokeWidth(1)
    page.context.line((M, 0), (M, H))

    # Number of lines.
示例#5
0
class Stacked(BaseFontShow):
    """Showing the specified (variable) font as full page with a matrix
    of all glyphs in the font.

    Usage of standard style parameters
    fill        Fill color for the background of the element
    stroke      Draw frame around the element
    textFill    Color of the text. Default is black.
    padding     Use in case of background color or frame. Default is 0

    """
    def __init__(self, f, words=None, labelFontSize=None, **kwargs):
        """
        >>> from pagebot.fonttoolbox.objects.font import findFont
        >>> from pagebot.document import Document
        >>> from pagebot.constants import Letter
        >>> from pagebot import getContext
        >>> from pagebot.conditions import *
        >>> from pagebot.toolbox.units import em
        >>> c = getContext()
        >>> w, h = Letter
        >>> doc = Document(w=w, h=h, padding=80, autoPages=2, context=c)
        >>> conditions = [Fit()]
        >>> page = doc[1]
        >>> font1 = findFont('AmstelvarAlpha-VF')
        >>> style = dict(gh=16, fill=0.95, leading=em(1.4))
        >>> gs = Stacked(font1, parent=page, conditions=conditions, padding=40, style=style, context=c)
        >>> page = doc[2]
        >>> font2 = findFont('RobotoDelta-VF')
        >>> #font2 = findFont('Upgrade-Regular')
        >>> #font2 = findFont('Escrow-Bold')
        >>> style = dict(stroke=0, strokeWidth=0.25, gh=8, leading=em(1.4))
        >>> gs = Stacked(font2, parent=page, conditions=conditions, style=style, padding=40, context=c)
        >>> score = doc.solve()
        >>> # FIXME
        >>> #doc.export('_export/%sStacked.pdf' % font1.info.familyName)
        """
        BaseFontShow.__init__(self, **kwargs)
        self.f = f  # Font instance
        self.words = words or {
        }  # Optional dictionary for headline words. Keys is frame index number.
        self.usedText = set()  # Avoid double use of headline words.
        # Add semi-random generated content, styles of fitting.
        self.blurb = Blurb(
        )  # Random content creator, in case there is no content supplied.
        self.lineTag = 'design_headline'  # Default label where to find random word choices.
        self.headlineTag = 'design_headline'  # Default label where to find (or create) random headline text.
        self.textTag = 'da_text'  # Default label where to find (or create) random body text.

    def build(self, view, origin=ORIGIN, **kwargs):
        """Default drawing method just drawing the frame.
        Probably will be redefined by inheriting element classes."""
        c = self.context
        p = pointOffset(self.origin, origin)
        p = self._applyScale(view, p)
        p = self._applyAlignment(p)  # Ignore z-axis for now.
        self.buildFrame(view,
                        p)  # Draw optional background fill, frame or borders.

        # Let the view draw frame info for debugging, in case view.showFrame == True
        view.drawElementFrame(self, p)

        # Draw that actual content of the element by stacked specimen rectangles.
        self.drawStacked(view, p, **kwargs)
        self._restoreScale(view)
        view.drawElementInfo(self,
                             origin)  # Depends on flag 'view.showElementInfo'

    def getText(self, tag, cnt=None, charCnt=None):
        """If the tag type of text is in self.words, then take a random choice from there.
        Otherwise use the tag to create a blurb with the specified length."""
        if tag in self.words:
            text = choice(self.words[tag])
            if text in self.usedText:  # Already used, try once more.
                text = choice(self.words[tag])
        else:
            text = self.blurb.getBlurb(tag, cnt=cnt, charCnt=charCnt)
        self.usedText.add(text)
        return text

    def drawStacked(self, view, origin, **kwargs):
        """Draw the content of the element, responding to size, styles, font and content."""

        c = self.context

        # Start on top left, with respect to optional padding value.
        x = self.pl
        y = self.h - self.pt
        # Top headline. (x,y) is top-left of the box, passed on for the position of the next box.
        s = self.getText(self.lineTag, charCnt=10).upper()
        x, y = self.buildStackedLine(s,
                                     origin,
                                     x,
                                     y,
                                     self.pw,
                                     wght=0.7,
                                     wdth=-0.4)

        # Second headline
        s = self.getText(self.lineTag, 4, 18)
        x, y = self.buildStackedLine(s, origin, x, y, self.pw, wght=-0.7)

        # Some large headline thing
        s = self.getText(self.lineTag, 5, 24)
        x, y = self.buildStackedLine(s,
                                     origin,
                                     x,
                                     y,
                                     self.pw,
                                     wght=0.3,
                                     wdth=-0.4)

        # Body text 16/24
        s = self.getText(self.textTag, 20)
        x, y = self.buildText(None, s, origin, x, y, self.pw, None, 16,
                              JUSTIFIED)

        # Body text 12/18
        s = self.getText(self.textTag, 30)
        x, y = self.buildText(None, s, origin, x, y, self.pw, None, 12,
                              JUSTIFIED)

        # Body text 10/15
        s1 = self.getText(self.headlineTag)
        s2 = self.getText(self.textTag, cnt=20)
        x, y = self.buildText(s1,
                              s2,
                              origin,
                              x,
                              y,
                              self.pw,
                              None,
                              10,
                              JUSTIFIED,
                              Bwght=0.7,
                              Bwdth=-0.1)

        # Body text 9/13.5
        # Don't update to the new y, next colomn needs to be on the right, starting at the same y.
        s1 = self.getText(self.headlineTag)
        s2 = self.getText(self.textTag) + ' ' + self.getText(self.textTag)
        x, _ = self.buildText(s1,
                              s2,
                              origin,
                              x,
                              y, (self.pw - self.gw) / 2,
                              y - self.pb,
                              9,
                              LEFT,
                              labelSize=7,
                              Bwght=0.6,
                              Bwdth=-0.1)

        # Body text 8/12
        s1 = self.getText(self.headlineTag)
        s2 = self.getText(self.textTag) + ' ' + self.getText(self.textTag)
        x, y = self.buildText(s1,
                              s2,
                              origin,
                              x + (self.pw + self.gw) / 2,
                              y, (self.pw - self.gw) / 2,
                              y - self.pb,
                              8,
                              LEFT,
                              labelSize=7,
                              Bwght=0.6,
                              Bwdth=-0.1)
示例#6
0
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    from pagebot.contributions.filibuster.blurb import Blurb

    # Show the list of all possible entries.
    SHOW_ALL_TYPES = False

    # see if we can generate all of them
    blurb = Blurb()

    # General aricle new headline
    print(blurb.getBlurb('name_german_male'))
    print(blurb.getBlurb('name_japanese'))

    # General book title and author name
    print(blurb.getBlurb('book_title'))

    # Scientific book title
    print(blurb.getBlurb('book_pseudoscientific'))

    # Philosphy book title
    print(blurb.getBlurb('book_phylosophy_title'))

    # Neutral airport new headline
    print(blurb.getBlurb('air_news_neutral'))

    # General aricle new headline
    print(blurb.getBlurb('_headline'))
示例#7
0
W = 652
LINE = 29.2
PADDING = 6
f = Color(1, 0, 0)
wbox = 300
hbox = 400

blurb = Blurb()
context = getContext('Flat')
context.newDrawing()
context.newPage(W, H)
x = 0
y = 0
context.text('(%s, %s)' % (x, y), (x, y))

b = blurb.getBlurb('stylewars_documentary')[:200]
font = findFont('Bungee-Regular')
style = dict(font=font, fontSize=pt(18), textFill=color(0.5, 1, 0))
bs = context.newString(b, style=style)
lines = bs.getTextLines(w=wbox, h=hbox)

print(lines)

context.fill(None)
context.stroke(f)
x = W / 2
y = H - hbox
context.text('(%s, %s)' % (x, y), (x, y))
context.textBox(bs, (W / 2, H - hbox, wbox, hbox))
context.rect(W / 2, H - hbox, wbox, hbox)
context.textBox(bs, (PADDING, H - hbox, wbox, hbox))
示例#8
0
def makeDocument():
    u"""Create Document instance with a single page. Fill the page with elements
    and perform a conditional layout run, until all conditions are solved."""

    foundryName, bookName = findFont(
        (None, 'Book', 'Regular'))  # Find these styles in order.
    _, mediumName = findFont(('Medium', 'Book', 'Regular'))
    mediumName = mediumName or bookName  # In case medium weight does not exist.
    _, boldName = findFont(('Bold', 'Medium'))

    bookItalicName = italicName(bookName)
    mediumItalicName = italicName(mediumName)
    boldItalicName = italicName(boldName)

    # Get the fonts, so we can dig in the information.
    bookFont = getFontByName(bookName, install=False)
    mediumFont = getFontByName(mediumName, install=False)
    boldFont = getFontByName(boldName, install=False)

    bookItalicFont = getFontByName(bookItalicName, install=False)
    mediumItalicFont = getFontByName(mediumItalicName, install=False)
    boldItalicFont = getFontByName(boldItalicName, install=False)

    # Some parameters from the original book
    paperColor = int2Color(
        0xF4EbC9)  # Approximation of paper color of original specimen.
    redColor = int2Color(0xAC1E2B)  # Red color used in the original specimen

    RedBoxY = 118 * MM  # Vertical position of the Red Box, on Bodoni chapter.
    columnX = 80 * MM  # Original 80MM, by we don't adjust, so optically a bit more.
    columnW = 60 * MM
    leftPadding = rightPadding = 52 * MM  # Exception page padding for columns

    blurb = Blurb()  # BLurb generator

    doc = Document(w=PageWidth,
                   h=PageHeight,
                   originTop=False,
                   startPage=1,
                   autoPages=10)
    # Get default view from the document and set the viewing parameters.
    view = SpreadView(parent=doc)
    view.style['fill'] = 1
    # TODO: There is a bug that makes view page size grow, if there are multiple pages and padding > 0
    # TODO: Add optional showing of mid-page line gradient, to suggest bended book pages.
    view.padding = 0  # 20*MM # To show cropmarks and such, make >=20*MM or INCH.
    view.showPageCropMarks = False  # Won't show if there is not padding in the view.
    view.showPageRegistrationMarks = False
    view.showPageFrame = True
    view.showPageNameInfo = False
    view.showElementOrigin = False
    view.showElementDimensions = False  #ShowDimensions
    view.showElementInfo = False
    view.showTextOverflowMarker = False  # Don't show marker in case Filibuster blurb is too long.

    labelFont = boldFont
    padding = (3 * MM, 3 * MM, 3 * MM, 3 * MM)
    fontNameSize = 16
    aboutSize = 10
    glyphSetSize = 11
    glyphSetLeading = 5 * MM
    captionSize = 7
    pageNumberSize = 12
    glyphTracking = 0.2  # Tracking of glyphset samples
    rt = 0.02  # Relative tracking
    capHeight = labelFont.info.capHeight / labelFont.info.unitsPerEm * fontNameSize

    border = dict(line=INLINE, dash=None, stroke=redColor, strokeWidth=1)

    # -----------------------------------------------------------------------------------
    # Cover from image scan.
    pn = 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding
    # Add image of cover scan.
    # TODO: Make other positions and scaling work on image element.
    newImage(path=COVER_IMAGE_PATH, parent=page, conditions=[Fit2Sides()])
    page.solve()

    # -----------------------------------------------------------------------------------
    # Empty left page.
    pn += 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding
    # Fill with paper color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor)

    # -----------------------------------------------------------------------------------
    # Full red page with white chapter title.
    pn += 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding
    # Fill full page with red color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=redColor)

    fs = newFS('BOEKLETTER',
               style=dict(font=boldName,
                          xTextAlign=RIGHT,
                          textFill=paperColor,
                          fontSize=24,
                          rTracking=0.1))  #, xTextAlign=RIGHT))
    newTextBox(fs,
               parent=page,
               y=page.h - 176 * MM,
               conditions=[Left2Left(), Fit2Right(),
                           Fit2Bottom()])
    page.solve()

    # -----------------------------------------------------------------------------------
    # Empty left page.
    pn += 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding
    # Fill with paper color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor)

    # -----------------------------------------------------------------------------------
    # Title page of family.
    pn += 1
    page = doc[pn]  # Get the single front page from the document.
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding

    # Fill with paper color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor)

    fs = newFS(labelFont.info.familyName.upper(),
               style=dict(font=boldName,
                          textFill=paperColor,
                          fontSize=fontNameSize,
                          tracking=0,
                          rTracking=0.3))
    tw, th = textSize(fs)
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(fs,
                        parent=page,
                        h=capHeight + 3 * padding[0],
                        w=tw + 2 * padding[1],
                        conditions=[Right2RightSide()],
                        fill=redColor,
                        padding=padding)
    tbName.top = page.h - RedBoxY
    tbName.solve()  # Make it go to right side of page.

    fs = newFS(foundryName.upper(),
               style=dict(font=boldName,
                          textFill=0,
                          fontSize=fontNameSize,
                          tracking=0,
                          rTracking=0.3))
    tw, th = textSize(fs)
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbFoundry = newTextBox(fs,
                           parent=page,
                           h=capHeight + 3 * padding[0],
                           w=tw + 2 * padding[1],
                           fill=None,
                           padding=padding,
                           borders=border)
    tbFoundry.top = page.h - RedBoxY
    tbFoundry.right = tbName.left

    # Make blurb text about design and typography.
    aboutText = blurb.getBlurb('article_summary', noTags=True)
    fs = newFS(aboutText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=aboutSize,
                          tracking=0,
                          rTracking=rt,
                          rLeading=1.3,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbAbout = newTextBox(fs,
                         parent=page,
                         x=columnX,
                         w=columnW,
                         conditions=[Fit2Bottom()])
    tbAbout.top = tbFoundry.bottom - 8 * MM

    # -----------------------------------------------------------------------------------
    # Page 2 of a family chapter. Glyph overview and 3 columns.

    pn += 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding

    # Fill with paper color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor)

    # Glyph set

    caps = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ\n'
    lc = caps.lower()
    figures = u'1234567890\n'
    capAccents = u'ÁÀÄÂÉÈËÊÇÍÌÏÎÓÒÖÔØÚÙÜÛÑ\n'
    lcAccents = capAccents.lower()
    punctuations = u',.;:?![]()-–—“”‘’'

    fs = newFS(caps,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=glyphSetSize,
                          leading=glyphSetLeading,
                          tracking=0,
                          rTracking=glyphTracking))
    fs += newFS(lc,
                style=dict(font=bookName,
                           textFill=0,
                           fontSize=glyphSetSize,
                           leading=glyphSetLeading,
                           tracking=0,
                           rTracking=glyphTracking))

    if bookName != bookItalicName:
        fs += newFS(caps,
                    style=dict(font=bookItalicName,
                               textFill=0,
                               fontSize=glyphSetSize,
                               leading=glyphSetLeading,
                               tracking=0,
                               rTracking=glyphTracking))
        fs += newFS(lc,
                    style=dict(font=bookItalicName,
                               textFill=0,
                               fontSize=glyphSetSize,
                               leading=glyphSetLeading,
                               tracking=0,
                               rTracking=glyphTracking))

    fs += newFS(figures,
                style=dict(font=bookName,
                           textFill=0,
                           fontSize=glyphSetSize,
                           leading=glyphSetLeading,
                           tracking=0,
                           rTracking=glyphTracking))
    if bookName != bookItalicName:
        fs += newFS(figures,
                    style=dict(font=bookItalicName,
                               textFill=0,
                               fontSize=glyphSetSize,
                               leading=glyphSetLeading,
                               tracking=0,
                               rTracking=glyphTracking))

    fs += newFS(capAccents,
                style=dict(font=bookName,
                           textFill=0,
                           fontSize=glyphSetSize,
                           leading=glyphSetLeading,
                           tracking=0,
                           rTracking=glyphTracking))
    fs += newFS(lcAccents,
                style=dict(font=bookName,
                           textFill=0,
                           fontSize=glyphSetSize,
                           leading=glyphSetLeading,
                           tracking=0,
                           rTracking=glyphTracking))

    if bookName != bookItalicName:
        fs += newFS(capAccents,
                    style=dict(font=bookItalicName,
                               textFill=0,
                               fontSize=glyphSetSize,
                               leading=glyphSetLeading,
                               tracking=0,
                               rTracking=glyphTracking))
        fs += newFS(lcAccents,
                    style=dict(font=bookItalicName,
                               textFill=0,
                               fontSize=glyphSetSize,
                               leading=glyphSetLeading,
                               tracking=0,
                               rTracking=glyphTracking))

    fs += newFS(punctuations,
                style=dict(font=bookName,
                           textFill=0,
                           fontSize=glyphSetSize,
                           leading=glyphSetLeading,
                           tracking=0,
                           rTracking=glyphTracking))
    if bookName != bookItalicName:
        fs += newFS(punctuations + '\n',
                    style=dict(font=bookItalicName,
                               textFill=0,
                               fontSize=glyphSetSize,
                               leading=glyphSetLeading,
                               tracking=0,
                               rTracking=glyphTracking))
    else:
        fs += '\n'

    if bookName != boldName:
        fs += newFS(caps + lc + figures + capAccents + lcAccents +
                    punctuations,
                    style=dict(font=boldName,
                               textFill=0,
                               fontSize=glyphSetSize,
                               leading=glyphSetLeading,
                               tracking=0,
                               rTracking=glyphTracking))

    tbGlyphSet = newTextBox(fs,
                            parent=page,
                            w=112 * MM,
                            x=leftPadding,
                            conditions=[Top2Top()])

    fs = newFS(labelFont.info.familyName.upper(),
               style=dict(font=boldName,
                          textFill=paperColor,
                          fontSize=fontNameSize,
                          tracking=0,
                          rTracking=0.3))
    tw, th = textSize(fs)
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(fs,
                        parent=page,
                        h=capHeight + 3 * padding[0],
                        w=tw + 2 * padding[1],
                        conditions=[Left2LeftSide()],
                        fill=redColor,
                        padding=padding)
    tbName.top = page.h - RedBoxY
    tbName.solve()  # Make it go to right side of page.

    fs = newFS(foundryName.upper(),
               style=dict(font=boldName,
                          textFill=0,
                          fontSize=fontNameSize,
                          tracking=0,
                          rTracking=0.3))
    tw, th = textSize(fs)
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbFoundry = newTextBox(fs,
                           parent=page,
                           h=capHeight + 3 * padding[0],
                           w=tw + 2 * padding[1],
                           fill=None,
                           padding=padding,
                           borders=border)
    tbFoundry.top = page.h - RedBoxY
    tbFoundry.left = tbName.right

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=6.5,
                          tracking=0,
                          rTracking=rt,
                          leading=6.5,
                          hyphenation='en'))
    # TODO: Last line of text blocks in original is bold.
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbSpec6 = newTextBox(fs, parent=page, x=leftPadding, w=50 * MM, h=30 * MM)
    tbSpec6.top = tbFoundry.bottom - 8 * MM

    fs = newFS('6 1/2 set\nop 6 pt gegoten (links)',
               style=dict(font=bookName,
                          fontSize=captionSize,
                          textFill=redColor,
                          xTextAlign=RIGHT,
                          rTracking=0.05,
                          leading=8,
                          openTypeFeatures=dict(frac=True)))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbCaption6 = newTextBox(fs,
                            parent=page,
                            x=page.pl,
                            w=leftPadding - page.pl - 3 * MM,
                            h=30 * MM)
    tbCaption6.top = tbSpec6.top

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=6.5,
                          tracking=0,
                          rTracking=rt,
                          leading=7,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbSpec7 = newTextBox(fs, parent=page, x=leftPadding, w=50 * MM, h=35 * MM)
    tbSpec7.top = tbSpec6.bottom - 5 * MM

    fs = newFS('op 7 pt gegoten (links)',
               style=dict(font=bookName,
                          fontSize=captionSize,
                          textFill=redColor,
                          xTextAlign=RIGHT,
                          rTracking=0.05,
                          leading=8))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbCaption7 = newTextBox(fs,
                            parent=page,
                            x=page.pl,
                            w=leftPadding - page.pl - 3 * MM,
                            h=30 * MM)
    tbCaption7.top = tbSpec7.top  # TODO: Align with first baseline, instead of box top.

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=6.5,
                          tracking=0,
                          rTracking=rt,
                          leading=8,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbSpec8 = newTextBox(fs, parent=page, h=tbSpec6.top - tbSpec7.bottom)
    tbSpec8.top = tbSpec6.top
    tbSpec8.left = tbSpec6.right + 5 * MM
    tbSpec8.w = page.w - page.pr - tbSpec8.left

    fs = newFS('op 8 pt gegoten (rechts)',
               style=dict(font=bookName,
                          fontSize=captionSize,
                          textFill=redColor,
                          xTextAlign=RIGHT,
                          rTracking=0.05,
                          leading=8))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbCaption8 = newTextBox(fs,
                            parent=page,
                            x=page.pl,
                            w=leftPadding - page.pl - 3 * MM)
    tbCaption8.bottom = tbSpec8.bottom  # TODO: Align with the position of the lowest base line.

    # TODO: Calculate the right amount
    fs = newFS(
        'Corps 6 – per 100 aug.: romein 417, cursief 444, vet 426 letters',
        style=dict(font=bookName,
                   fontSize=captionSize,
                   textFill=redColor,
                   xTextAlign=RIGHT,
                   rTracking=rt,
                   leading=8))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbCaptionTotal = newTextBox(fs,
                                parent=page,
                                x=page.pl,
                                w=page.w - page.pl - page.pr)
    tbCaptionTotal.top = tbSpec8.bottom - MM

    # Page number
    fs = newFS(
        ` pn `,
        style=dict(font=bookName,
                   fontSize=pageNumberSize,
                   textFill=redColor,
                   xTextAlign=LEFT,
                   rTracking=rt,
                   leading=8))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbPageNumber = newTextBox(fs, parent=page, x=leftPadding, w=10 * MM)
    tbPageNumber.bottom = 20 * MM

    # -----------------------------------------------------------------------------------
    # Page 3, 3 columns.

    pn += 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding

    # Fill with paper color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor)

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=8.5,
                          tracking=0,
                          rTracking=rt,
                          leading=8,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbText1 = newTextBox(fs,
                         parent=page,
                         h=110 * MM,
                         w=50 * MM,
                         conditions=[Top2Top(), Left2Left()])
    page.solve()

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=8.5,
                          tracking=0,
                          rTracking=rt,
                          leading=9,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    x = tbText1.right + 5 * MM
    tbText2 = newTextBox(fs,
                         parent=page,
                         x=x,
                         y=tbText1.y,
                         h=tbText1.h,
                         w=page.w - x - rightPadding)
    page.solve()

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=8.5,
                          tracking=0,
                          rTracking=rt,
                          leading=10,
                          hyphenation='en'))
    x = tbText1.left
    tbText3 = newTextBox(fs,
                         parent=page,
                         x=x,
                         h=64 * MM,
                         w=page.w - x - rightPadding,
                         mt=10 * MM,
                         conditions=[Float2TopLeft()])

    # TODO: Add red captions here.

    # Red label on the left
    fs = newFS(labelFont.info.styleName.upper(),
               style=dict(font=boldName,
                          textFill=paperColor,
                          fontSize=fontNameSize,
                          tracking=0,
                          rTracking=0.3))
    tw, th = textSize(fs)
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(fs,
                        parent=page,
                        h=capHeight + 3 * padding[0],
                        w=tw + 2 * padding[1],
                        conditions=[Right2RightSide()],
                        fill=redColor,
                        padding=padding)
    tbName.top = page.h - RedBoxY

    # Page number
    fs = newFS(
        ` pn `,
        style=dict(font=bookName,
                   fontSize=pageNumberSize,
                   textFill=redColor,
                   xTextAlign=RIGHT,
                   rTracking=rt,
                   leading=8))
    tbPageNumber = newTextBox(fs,
                              parent=page,
                              x=page.w - rightPadding - 10 * MM,
                              w=10 * MM)
    tbPageNumber.bottom = 20 * MM

    # -----------------------------------------------------------------------------------
    # Page 4, 3 columns.

    pn += 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding

    # Fill with paper color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor)
    x = leftPadding

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=10.5,
                          tracking=0,
                          rTracking=rt,
                          leading=10,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbText1 = newTextBox(fs,
                         parent=page,
                         x=x,
                         h=55 * MM,
                         w=page.w - x - page.pl,
                         conditions=[Top2Top()])
    page.solve()

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=10.5,
                          tracking=0,
                          rTracking=rt,
                          leading=11,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    newTextBox(fs,
               parent=page,
               mt=5 * MM,
               x=x,
               h=60 * MM,
               w=page.w - x - page.pl,
               conditions=[Float2Top()])
    page.solve()

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=10.5,
                          tracking=0,
                          rTracking=rt,
                          leading=12,
                          hyphenation='en'))
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    newTextBox(fs,
               parent=page,
               mt=5 * MM,
               x=x,
               h=65 * MM,
               w=page.w - x - page.pl,
               conditions=[Float2Top()])
    page.solve()

    # TODO: Add red captions here.

    # Red label on the right
    fs = newFS('10.5pt',
               style=dict(font=boldName,
                          textFill=paperColor,
                          fontSize=fontNameSize,
                          tracking=0,
                          rTracking=0.3))
    tw, th = textSize(fs)
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(fs,
                        parent=page,
                        h=capHeight + 3 * padding[0],
                        w=tw + 2 * padding[1],
                        conditions=[Left2LeftSide()],
                        fill=redColor,
                        padding=padding)
    tbName.top = page.h - RedBoxY

    # Page number, even on left side.
    fs = newFS(
        ` pn `,
        style=dict(font=bookName,
                   fontSize=pageNumberSize,
                   textFill=redColor,
                   xTextAlign=LEFT,
                   rTracking=rt,
                   leading=8))
    tbPageNumber = newTextBox(fs, parent=page, x=leftPadding, w=10 * MM)
    tbPageNumber.bottom = 20 * MM

    # -----------------------------------------------------------------------------------
    # Page 5, 2 columns.

    pn += 1
    page = doc[pn]
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding

    # Fill with paper color
    # TODO: Just background color could be part of page fill instead of extra element.
    newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor)

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=12.5,
                          tracking=0,
                          rTracking=rt,
                          leading=12,
                          hyphenation='en'))
    newTextBox(fs,
               parent=page,
               x=x,
               h=64 * MM,
               w=page.w - page.pl - rightPadding,
               mt=10 * MM,
               conditions=[Top2Top(), Left2Left()])

    # Make blurb text about design and typography.
    specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb(
        'article', noTags=True)
    fs = newFS(specText,
               style=dict(font=bookName,
                          textFill=0,
                          fontSize=12.5,
                          tracking=0,
                          rTracking=rt,
                          leading=13,
                          hyphenation='en'))
    newTextBox(fs,
               parent=page,
               x=x,
               h=64 * MM,
               w=page.w - page.pl - rightPadding,
               mt=10 * MM,
               conditions=[Float2TopLeft()])

    # TODO: Add red captions here.

    # Red label on the left
    fs = newFS(labelFont.info.styleName.upper(),
               style=dict(font=boldName,
                          textFill=paperColor,
                          fontSize=fontNameSize,
                          tracking=0,
                          rTracking=0.3))
    tw, th = textSize(fs)
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(fs,
                        parent=page,
                        h=capHeight + 3 * padding[0],
                        w=tw + 2 * padding[1],
                        conditions=[Right2RightSide()],
                        fill=redColor,
                        padding=padding)
    tbName.top = page.h - RedBoxY

    # Page number
    fs = newFS(
        ` pn `,
        style=dict(font=bookName,
                   fontSize=pageNumberSize,
                   textFill=redColor,
                   xTextAlign=RIGHT,
                   rTracking=rt,
                   leading=8))
    tbPageNumber = newTextBox(fs,
                              parent=page,
                              x=page.w - rightPadding - 10 * MM,
                              w=10 * MM)
    tbPageNumber.bottom = 20 * MM

    # Solve remaining layout and size conditions.

    score = doc.solve()
    if score.fails:
        print 'Condition fails', score.fails
    return doc  # Answer the doc for further doing.
示例#9
0
# Put them on z-position != 0, to avoid the condition floating hooking on them.
# E.g. Float2Top() layout conditions only look at elements with the same z-value.
opaque = 0.7
pageIndex = 1  # Select the page index from the PDF to use as background image.
# For copyright reasons the template PDF cannot be added to the Open Source repository
templatePath = '_local/2018-09-04_De_Volkskrant_-_04-09-2018.pdf'
#templatePath = '_local/2018-09-14_De_Volkskrant_-_14-09-2018.pdf'

newImage(templatePath, w=W, h=H, z=-10, index=pageIndex, parent=page)
newRect(fill=(1, 1, 1, opaque), w=W, h=H, z=-10, parent=page)

# =============================================================================
#    Top-left headline above newspaper title. Bold name with designer quote
# .............................................................................
if SHOW_TOPHEAD:
    txt = blurb.getBlurb('name')
    bs = context.newString(txt + ': ', style=topHeadBoldStyle)
    txt = blurb.getBlurb('design_article_title').capitalize()
    if not txt.endswith('.'):
        txt += '.'
    bs += context.newString('“' + txt + '”', style=topHeadStyle)
    txt = ' P:%d' % choice(range(80))
    bs += context.newString(txt, style=topHeadBoldStyle)
    paddingTop = inch(1)
    tw, th = context.textSize(bs, w=CW3)
    topHeadlineBox = newTextBox(bs,
                                parent=page,
                                h=RH,
                                pt=paddingTop,
                                conditions=(Left2Left(),
                                            Fit2ColSpan(colSpan=3),
示例#10
0
文件: test.py 项目: oakhope/PageBot
    definedIn, usedIn = index(name)
    usedMods = {}
    for a, b in usedIn:
        usedMods[a] = True

    f.write("\nDefined in module %s" % definedIn[0])
    if usedMods:
        k = usedMods.keys()
        list(k).sort()
        f.write("\nUsed in %s" % ", ".join(k))

    f.close()

    for i in range(maxTests):
        f = codecs.open(namePath, 'a', 'utf-8')
        result = w.getBlurb(name)
        try:
            f.write("\n\n" + result)
            success = True
        except:
            print("UnicodeDecodeError", definedIn[0], name)
        finally:
            f.close()

    if success:
        t.close()
        os.remove(nameTagPath)

print('generated %d files' % count)
print('done')
示例#11
0
from pagebot import getRootPath
from pagebot import getContext
from pagebot.fonttoolbox.variablefontbuilder import getVarFontInstance
from pagebot.constants import CENTER
from pagebot.toolbox.units import pt
from pagebot.toolbox.color import color, Color
from pagebot.contributions.filibuster.blurb import Blurb

# TODO: merge with Strings

NO_TAGS = True  # Flag to show/hide HTML tags in output

blurb = Blurb()

txt = blurb.getBlurb('news_headline', noTags=NO_TAGS) + '\n'
txt0 = txt[0:3]
txt1 = txt[3:6]
txt2 = txt[6:9]
txt3 = txt[9:12]

c = getContext()
W = H = 500


def testBabelStrings():
    c.newPage(pt(W), pt(H))
    style = dict(font='Helvetica', fontSize=pt(100), textFill=color(1, 1, 0))

    # Formattted string using append.
    print(' * Testing with append')
    bs = c.newString(txt0)  # NOTE: style isn't initiated, bug later on.
示例#12
0
from pagebot.contributions.filibuster.blurb import Blurb

NO_TAGS = True  # Flag to show/hide HTML tags in output

w = Blurb()

print w.getBlurb('article_ankeiler', noTags=NO_TAGS)
print
print w.getBlurb('article_summary', noTags=NO_TAGS)
print
print w.getBlurb('article', noTags=NO_TAGS)
示例#13
0
newRect(parent=page,
        z=10,
        x=10,
        y=10,
        fill=(1, 0, 1, 0.5),
        conditions=[
            Left2LeftSide(),
            Top2Bottom(),
            Fit2BottomSide(),
            Fit2WidthSides()
        ])

cId2 = 'colum2'
fontSize = 10

he = newTextBox(blurb.getBlurb('news_headline'),
                parent=page,
                x=20,
                y=220,
                w=page.pw,
                fill=0,
                fontSize=18,
                conditions=[Left2Left(), Top2Top()],
                mb=20)
ce1 = newTextBox(
    blurb.getBlurb('article', noTags=True),
    parent=page,
    x=20,
    y=20,
    w=page.pw / 2 - page.gw,
    mr=page.gw,
示例#14
0
f = findFont('Bungee-Regular')
bungee = font.open(f.path)
f = findFont('Bungee-OutlineRegular')
bungeeOutline = font.open(f.path)
f = findFont('PageBot-Book')
pageBotBook = font.open(f.path)

line = 12
blurb = Blurb()

h1Outline = strike(bungeeOutline).color(red).size(20, 24)
h1 = strike(bungee).color(black).size(20, 24)
intro = strike(bungee).color(black).size(10, 12)
body = strike(pageBotBook).color(black).size(16, 18)

title = blurb.getBlurb('stylewars_original')
txt = blurb.getBlurb('stylewars_documentary')

redStroke = shape().stroke(red).width(0.5)
blackFill = shape().nostroke().fill(black)
blackStroke = shape().stroke(black).width(0.2)
whiteFill = shape().nostroke().fill(white)

d = document(w, h, 'pt')
d.meta(documentName)
p = d.addpage()
padding = 10
w0 = w - 2 * padding
h0 = h - 2 * padding
x = padding
y = padding