Exemplo n.º 1
0
def useUnits():
    # 2mm, 2
    for v in mm(2), px(5), pt(5), em(12, base=10), perc(12.5, base=400), col(
            1 / 4, base=mm(200), g=mm(4)):
        # Showing the unit as instance and as rendered value
        print(
            'As unit:',
            v,
            'As raw value:',
            v.rv,
            'As pt:',
            v.pt,
        )
Exemplo n.º 2
0
def useUnits():
    """
    >>> mm(2), mm(2).rv # Showing the unit as instance and as rendered value
    (2mm, 2)
    >>> px(5), px(5).rv
    (5px, 5)
    >>> px(5), pt(5).rv
    (5px, 5)
    >>> fr(8, base=400), fr(8, base=400).rv # Fractional units, used in CSS-grid.
    (8fr, 50)
    >>> em(12, base=10), em(12, base=10).rv
    (12em, 120)
    >>> perc(12.5, base=400), perc(12.5, base=400).rv
    (12.5%, 50)
    >>> u = col(1/4, base=mm(200), g=mm(4))
    >>> u, u.rv
    (0.25col, 47mm)
    """
    print(mm(2))
    # Real value:
    print(mm(2).rv)
    print(px(5))
    print(px(5).rv)
# =============================================================================
#    Measures
# .............................................................................
#W, H = Broadsheet # Split paper size in document width and height
W, H = pt(819, 1176)  # Dutch Volksrant tabloid size.

U = pt(10)
G = pt(11)
PL = pt(35)  # Page padding left
PR = pt(28)
PT = 4 * U  # Page padding top
PB = pt(48)  # Page badding bottom
PADDING_LEFT = PT, PR, PB, PL
PADDING_RIGHT = PT, PL, PB, PR
BASELINE = mm(3.45)  # Overall baseline grid, talem from background baseline

# Grid definitions
CC = 5  # Column count
CW = (W - PL - PR + G) / CC - G  # Column width (without gutter)
CW1 = CW
CW2 = 2 * CW + G
CW3 = 3 * CW + 2 * G
CW4 = 4 * CW + 3 * G
CW5 = 5 * CW + 4 * G

RC = 7  # Row count
RH = BASELINE * RC  # Row height (without gutter) depending on row count and page height

gridX = []  # Create the column grid
for colIndex in range(CC):
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 = findTheFont(
        (None, 'Book', 'Regular'))  # Find these styles in order.
    _, mediumName = findTheFont(('Medium', 'Book', 'Regular'))
    mediumName = mediumName or bookName  # In case medium weight does not exist.
    _, boldName = findTheFont(('Bold', 'Medium'))

    print('Found fonts', bookName, mediumName, boldName)

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

    # Get the fonts, so we can dig in the information.
    bookFont = findTheFont(bookName)
    mediumFont = findTheFont(mediumName)
    boldFont = findTheFont(boldName)
    bookItalicFont = findTheFont(bookItalicName)
    mediumItalicFont = findTheFont(mediumItalicName)
    boldItalicFont = findTheFont(boldItalicName)

    # Some parameters from the original book
    paperColor = color(
        rgb='#F4EbC9')  # Approximation of paper color of original specimen.
    redColor = color(rgb='#AC1E2B')  # Red color used in the original specimen

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

    blurb = Blurb()  # Blurb text 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 = doc.view
    c = view.context
    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 = mm(3, 3, 3, 3)
    fontNameSize = pt(16)
    aboutSize = pt(10)
    glyphSetSize = pt(11)
    glyphSetLeading = mm(5)
    captionSize = pt(7)
    pageNumberSize = pt(12)
    glyphTracking = em(0.2)  # Tracking of glyphset samples
    rt = em(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.
    page = doc[1]
    # 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()],
             h=H,
             w=W)
    page.solve()

    # -----------------------------------------------------------------------------------
    # Empty left page.
    page = page.next
    # 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.
    page = page.next
    # 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)

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

    # -----------------------------------------------------------------------------------
    # Empty left page.
    page = page.next
    # 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.
    page = page.next  # 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)

    bs = c.newString(labelFont.info.familyName.upper(),
                     style=dict(font=boldName,
                                textFill=paperColor,
                                fontSize=fontNameSize,
                                tracking=0,
                                rTracking=0.3))
    tw, th = bs.size
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(bs,
                        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.

    bs = context.newString(foundryName.upper(),
                           style=dict(font=boldName,
                                      textFill=0,
                                      fontSize=fontNameSize,
                                      tracking=0,
                                      rTracking=0.3))
    tw, th = bs.size
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbFoundry = newTextBox(bs,
                           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)
    bs = context.newString(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(bs,
                         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.

    page = page.next
    # 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',.;:?![]()-–—“”‘’'

    bs = context.newString(caps,
                           style=dict(font=bookName,
                                      textFill=0,
                                      fontSize=glyphSetSize,
                                      leading=glyphSetLeading,
                                      tracking=0,
                                      rTracking=glyphTracking))
    bs += context.newString(lc,
                            style=dict(font=bookName,
                                       textFill=0,
                                       fontSize=glyphSetSize,
                                       leading=glyphSetLeading,
                                       tracking=0,
                                       rTracking=glyphTracking))

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

    bs += context.newString(figures,
                            style=dict(font=bookName,
                                       textFill=0,
                                       fontSize=glyphSetSize,
                                       leading=glyphSetLeading,
                                       tracking=0,
                                       rTracking=glyphTracking))
    if bookName != bookItalicName:
        bs += context.newString(figures,
                                style=dict(font=bookItalicName,
                                           textFill=0,
                                           fontSize=glyphSetSize,
                                           leading=glyphSetLeading,
                                           tracking=0,
                                           rTracking=glyphTracking))

    bs += context.newString(capAccents,
                            style=dict(font=bookName,
                                       textFill=0,
                                       fontSize=glyphSetSize,
                                       leading=glyphSetLeading,
                                       tracking=0,
                                       rTracking=glyphTracking))
    bs += context.newString(lcAccents,
                            style=dict(font=bookName,
                                       textFill=0,
                                       fontSize=glyphSetSize,
                                       leading=glyphSetLeading,
                                       tracking=0,
                                       rTracking=glyphTracking))

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

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

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

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

    bs = context.newString(labelFont.info.familyName.upper(),
                           style=dict(font=boldName,
                                      textFill=paperColor,
                                      fontSize=fontNameSize,
                                      tracking=0,
                                      rTracking=0.3))
    tw, th = bs.size
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(bs,
                        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.

    bs = context.newString(foundryName.upper(),
                           style=dict(font=boldName,
                                      textFill=0,
                                      fontSize=fontNameSize,
                                      tracking=0,
                                      rTracking=0.3))
    tw, th = bs.size
    # TODO: Something wrong with left padding or right padding. Should be symmetric.
    tbFoundry = newTextBox(bs,
                           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)
    bs = context.newString(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(bs, parent=page, x=leftPadding, w=50 * MM, h=30 * MM)
    tbSpec6.top = tbFoundry.bottom - 8 * MM

    bs = context.newString('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(bs,
                            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)
    bs = context.newString(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(bs, parent=page, x=leftPadding, w=50 * MM, h=35 * MM)
    tbSpec7.top = tbSpec6.bottom - 5 * MM

    bs = context.newString('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(bs,
                            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)
    bs = context.newString(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(bs, 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

    bs = context.newString('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(bs,
                            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
    bs = context.newString(
        '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(bs,
                                parent=page,
                                x=page.pl,
                                w=page.w - page.pl - page.pr)
    tbCaptionTotal.top = tbSpec8.bottom - MM

    # Page number
    bs = context.newString(str(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(bs, parent=page, x=leftPadding, w=10 * MM)
    tbPageNumber.bottom = 20 * MM

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

    page = page.next
    # 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)
    bs = context.newString(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(bs,
                         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)
    bs = context.newString(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(bs,
                         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)
    bs = context.newString(specText,
                           style=dict(font=bookName,
                                      textFill=0,
                                      fontSize=8.5,
                                      tracking=0,
                                      rTracking=rt,
                                      leading=10,
                                      hyphenation='en'))
    x = tbText1.left
    tbText3 = newTextBox(bs,
                         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
    bs = context.newString(labelFont.info.styleName.upper(),
                           style=dict(font=boldName,
                                      textFill=paperColor,
                                      fontSize=fontNameSize,
                                      tracking=0,
                                      rTracking=0.3))
    tw, th = bs.size
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(bs,
                        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
    bs = context.newString(str(pn),
                           style=dict(font=bookName,
                                      fontSize=pageNumberSize,
                                      textFill=redColor,
                                      xTextAlign=RIGHT,
                                      rTracking=rt,
                                      leading=8))
    tbPageNumber = newTextBox(bs,
                              parent=page,
                              x=page.w - rightPadding - 10 * MM,
                              w=10 * MM)
    tbPageNumber.bottom = 20 * MM

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

    page = page.next
    # 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)
    bs = context.newString(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(bs,
                         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)
    bs = context.newString(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(bs,
               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)
    bs = context.newString(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(bs,
               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
    bs = c.newString('10.5pt',
                     style=dict(font=boldName,
                                textFill=paperColor,
                                fontSize=fontNameSize,
                                tracking=0,
                                rTracking=0.3))
    tw, th = bs.size
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(bs,
                        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.
    bs = c.newString(str(pn),
                     style=dict(font=bookName,
                                fontSize=pageNumberSize,
                                textFill=redColor,
                                xTextAlign=LEFT,
                                rTracking=rt,
                                leading=8))
    tbPageNumber = newTextBox(bs, parent=page, x=leftPadding, w=10 * MM)
    tbPageNumber.bottom = 20 * MM

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

    page = page.next
    # 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)
    bs = c.newString(specText,
                     style=dict(font=bookName,
                                textFill=0,
                                fontSize=12.5,
                                tracking=0,
                                rTracking=rt,
                                leading=12,
                                hyphenation='en'))
    newTextBox(bs,
               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)
    bs = c.newString(specText,
                     style=dict(font=bookName,
                                textFill=0,
                                fontSize=12.5,
                                tracking=0,
                                rTracking=rt,
                                leading=13,
                                hyphenation='en'))
    newTextBox(bs,
               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
    bs = c.newString(labelFont.info.styleName.upper(),
                     style=dict(font=boldName,
                                textFill=paperColor,
                                fontSize=fontNameSize,
                                tracking=0,
                                rTracking=0.3))
    tw, th = bs.size
    # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured.
    tbName = newTextBox(bs,
                        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
    bs = c.newString(str(pn),
                     style=dict(font=bookName,
                                fontSize=pageNumberSize,
                                textFill=redColor,
                                xTextAlign=RIGHT,
                                rTracking=rt,
                                leading=8))
    tbPageNumber = newTextBox(bs,
                              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.
from pagebot.contributions.filibuster.blurb import Blurb
from pagebot.fonttoolbox.objects.font import findFont

from pagebot.style import CENTER, TOP, BOTTOM, MIDDLE, INLINE, ONLINE, OUTLINE, RIGHT, LEFT
# Document is the main instance holding all information about the document together (pages, views, etc.)
from pagebot.document import Document
# Import all element classes that can be placed on a page.
from pagebot.elements import *
# Import all layout condition classes
from pagebot.conditions import *
# Import colors and units
from pagebot.toolbox.color import color, noColor
from pagebot.toolbox.units import mm, pt, em
# Generic function to create new FormattedString, extended version of DrawBot FormattedString() call.

W, H, = PageWidth, PageHeight = mm(180), mm(
    247)  # Original size of Letterproef (type specimen)
PADDING = PageWidth / 18  # Padding based on size (= in book layout called margin) of the page.
PT = mm(22)
PB = mm(36)
PL = PR = mm(
    16
)  # Although the various types of specimen page have their own margin, this it the overall page padding.
pagePadding = (PT, PR, PB, PL)
G = pt(12)  # Gutter
#SYSTEM_FAMILY_NAMES = ('Verdana',)
#SYSTEM_FAMILY_NAMES = ('Georgia',)
#FONT_NAME_PATTERNS = ('Bungee', 'Amstel', 'Deco') # TODO, make this work if fonts don't exist.
#SYSTEM_FAMILY_NAMES = ('Proforma', 'Productus')
#MY_FAMILY_NAMES = ('Proforma', 'Productus')
FONT_NAME_PATTERNS = ('Proforma')
Exemplo n.º 6
0
from pagebot.contexts.platform import getContext

from pagebot.fonttoolbox.objects.font import findFont
from pagebot.document import Document
from pagebot.elements import *  # Import all types of page-child elements for convenience
from pagebot.toolbox.color import color
from pagebot.toolbox.units import em, p, pt, mm, inch
from pagebot.style import CENTER
from pagebot.toolbox.color import blueColor, darkGrayColor, redColor, Color, noColor, color
from pagebot.conditions import *  # Import all conditions for convenience.
from pagebot.constants import GRID_COL, GRID_ROW, GRID_SQR

#context = FlatContext()
context = getContext()
W, H = pt(inch(9)), pt(inch(12))  # Document size
PADDING = pt(mm(13))  # Page padding on all sides
G = mm(4)  # 2 Pica gutter
PW = W - 2 * PADDING  # Usable padded page width
PH = H - 2 * PADDING  # Usable padded page height
CW = (PW - (G * 2))  # Column width
CH = PH
# Hard coded grid, will be automatic in later examples.
GRIDX = ((CW, G), (CW, 0))
GRIDY = ((CH, 0), )

# Abstract Paragraph
text = """Roanne Adams launched RoAndCo in 2006 after being recognized as one of Print magazine’s “New Visual Artist (20 under 30).” In 2010, she was named one of the city’s most “outstanding up-and-coming design professionals” by T: The New York Times Style Magazine and she received an Art Director’s Club Young Guns 9 award in 2011. Roanne currently serves on the Board of Directors for AIGA’s New York Chapter. With her keen eye for style and a skill for visually embodying brands’ personalities, Roanne has earned the trust and respect of clients and collaborators alike.

Photography by James Chorous"""
font = findFont('Roboto')
style = dict(font=font,
Exemplo n.º 7
0
EXPORT_PATH = '_export/HandleDocWithPages.pdf'

doc = Document(w=W, h=H, originTop=False, autoPages=1)
print('One page in the document', doc.pages)

view = doc.getView()
view.showPadding = True
view.showDimensions = True
view.showOrigin = True

# Gets the first page from te document.
page = doc[1] 
page.name = 'First page'
page.padding = 20

conditions = (Center2Center(), Middle2Middle())
# Try other positions
#conditions= (Left2Left(), Top2SideTop())
#conditions= (Right2Right(), Top2SideTop())

# Position square in the center of the page area. Notice that their alignment
# (left) does not matter for the conditions. Measures can be any type of
# units. Their type is show in the measured output.

newTextBox(page.name, w=mm(86), h=pt(164), parent=page, pl=3, pt=3,
    showDimensions=True,
    conditions=conditions, fill=color(0.8))

page.solve()
doc.export(EXPORT_PATH)
def makeDocument():
    #Parameters of the docuemnt
    context = getContext()
    W, H = pt(1920, 1080)
    padheight = pt(70)
    padside = pt(466)
    PADDING = padheight, padside, padheight, padside
    G = mm(4)
    PW = W - 2 * padside
    PH = H - 2 * padheight
    CW = (PW - (G * 2)) / 3
    CH = PH
    GRIDX = ((CW, G), (CW, 0))
    GRIDY = ((CH, 0), )
    fontSizeH1 = 144
    points = ' / ' + str(fontSizeH1)

    # Function for the first column in the main page layout
    def firstColumnWaterfall(b, fontStyle):
        s = c.newString('', style=dict(font=f))
        s2 = c.newString('', style=dict(font=f))
        CW2 = (PW - (G * 2)) / 3  # Column width
        for n in range(4):
            fontSize = pt(12 + n * 1)
            leading = pt((12 + n * 1) + 3)
            if n < 3:
                leading2 = pt(((12 + n * 1) * n) + 90 + n * 4)
            else:
                leading2 = ((12 + n * 1) * n) + 86 + n
            s += c.newString(b + '\n',
                             style=dict(font=fontStyle,
                                        fontSize=fontSize,
                                        leading=leading))
            s2 += c.newString(str(fontSize) + '/' + str(leading) + '\n',
                              style=dict(font=fontStyle,
                                         fontSize=10,
                                         leading=leading2))
        newTextBox(s,
                   parent=page,
                   w=CW2,
                   h=pt(700),
                   font=f,
                   pt=pt(160),
                   nextElementName='e2',
                   conditions=[Left2Left(),
                               Top2Top(),
                               Overflow2Next()])
        newTextBox(s2,
                   parent=page,
                   w=CW2,
                   h=pt(700),
                   font=f,
                   pt=(pt(70)),
                   nextElementName='e2',
                   conditions=[Left2Left(),
                               Top2Top(),
                               Overflow2Next()])
        doc.solve()

    # Function for the second column in the main page layout
    def secondColumnWaterfall(b, fontStyle):
        s = c.newString('', style=dict(font=f))
        s2 = c.newString('', style=dict(font=f))
        CW2 = (PW - (G * 2)) / 3  # Column width
        for n in range(3):
            fontSize = pt(16 + n * 2)
            leading = pt((12 + n * 2) + 6)
            if n < 1:
                leading2 = (((12 + n * 2) + 6) * n * 2) + 90 + n * 10
            elif n < 2:
                leading2 = (((12 + n * 2) + 6) * n * 2) + 110 + n * 10
            else:
                leading2 = ((((12 + n * 2) + 6) * n * 2) + 76 + n * 10) + n * 6
            s += c.newString(b + '\n',
                             style=dict(font=fontStyle,
                                        fontSize=fontSize,
                                        leading=leading))
            s2 += c.newString(str(fontSize) + '/' + str(leading) + '\n',
                              style=dict(font=fontStyle,
                                         fontSize=10,
                                         leading=leading2))
        newTextBox(s,
                   parent=page,
                   w=CW2,
                   h=pt(700),
                   font=f,
                   pt=pt(160),
                   conditions=[Right2Right(), Top2Top()])
        newTextBox(s2,
                   parent=page,
                   w=CW2,
                   h=pt(700),
                   font=f,
                   pt=(pt(70)),
                   conditions=[Right2Right(), Top2Top()])
        doc.solve()

    # Function for the Waterfall layout
    def typeWaterfall(x, fontStyle, PageDescription, pageNumber):
        newTextBox(PageDescription,
                   style=subtitle,
                   w=PW,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Left2Left(), Top2Top()))
        newTextBox(pageNumber,
                   style=subtitle,
                   xTextAlign=RIGHT,
                   w=50,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Right2Right(), Top2Top()))
        st = c.newString('', style=dict(font=f))
        st2 = c.newString('', style=dict(font=f))
        for n in range(7):
            if n < 4:
                fontSize = 144 - n * 24
                leading = (144 - n * 24) + 24
                leading2 = (144 - n * 24) + 24
            else:
                fontSize = 108 - n * 12
                leading = None
                leading2 = (108 - n * 12) + 24
            st += c.newString(x + '\n',
                              style=dict(font=fontStyle,
                                         fontSize=fontSize,
                                         leading=leading))
            st2 += c.newString(str(fontSize) + 'pt' + '\n',
                               style=dict(font=fontStyle,
                                          fontSize=12,
                                          leading=leading2))
        newTextBox(
            st,
            parent=page,
            padding=pt(4),
            x=pt(60),
            y=pt(950),
            w=W,
            font=f,
            cconditions=[Left2Left(), Top2Top(),
                         Overflow2Next()],
            yAlign=TOP,
            xAlign=LEFT,
        )
        newTextBox(
            st2,
            parent=page,
            padding=pt(4),
            x=pt(60),
            y=pt(940),
            w=W,
            font=f,
            cconditions=[Left2Left(), Top2Top(),
                         Overflow2Next()],
            yAlign=TOP,
            xAlign=LEFT,
        )
        return doc
        doc.solve()

    # Function for the Waterfall layout
    def typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber):
        newTextBox(PageDescription,
                   style=subtitle,
                   w=PW,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Left2Left(), Top2Top()))
        newTextBox(pageNumber,
                   style=subtitle,
                   xTextAlign=RIGHT,
                   w=50,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Right2Right(), Top2Top()))
        st = c.newString('', style=dict(font=f))
        st2 = c.newString('', style=dict(font=f))
        for n in range(7):
            if n < 4:
                fontSize = 144 - n * 24
                leading = (144 - n * 24) + 24
                leading2 = (144 - n * 24) + 24
            else:
                fontSize = 108 - n * 12
                leading = None
                leading2 = (108 - n * 12) + 24
            st += c.newString(x + '\n',
                              style=dict(font=fontStyle,
                                         hyphenation=False,
                                         fontSize=fontSize,
                                         leading=leading))
            st2 += c.newString(str(fontSize) + 'pt' + '\n',
                               style=dict(font=fontStyle,
                                          fontSize=12,
                                          leading=leading2))
        newTextBox(
            st,
            parent=page,
            hyphenation=False,
            padding=pt(4),
            x=pt(60),
            y=pt(950),
            w=W - 50,
            font=f,
            cconditions=[Left2Left(), Top2Top(),
                         Overflow2Next()],
            yAlign=TOP,
            xAlign=LEFT,
        )
        newTextBox(
            st2,
            parent=page,
            padding=pt(4),
            x=pt(60),
            y=pt(780),
            w=W,
            font=f,
            cconditions=[Left2Left(), Top2Top(),
                         Overflow2Next()],
            yAlign=TOP,
            xAlign=LEFT,
        )
        return doc
        doc.solve()

    # Create a new document with 1 page. Set overall size and padding.
    doc = Document(w=W,
                   h=H,
                   padding=PADDING,
                   gridX=GRIDX,
                   gridY=GRIDY,
                   context=context)
    view = doc.view
    page = doc[1]

    subtitle = dict(font=f, fontSize=pt(18), leading=pt(28))
    pagePaddings = (50, 50, 50, 50)

    # Page1
    # Function to make the main page layout
    def mainPage(fontStyle1, fontStyle2, pageNumber, defaultfont):
        # New text box for the Title
        maintitle = context.newString("Amstelvar",
                                      style=dict(font=fontStyle1,
                                                 xTextAlign=CENTER,
                                                 fontSize=pt(96),
                                                 leading=pt(115)))
        newTextBox(maintitle,
                   w=PW,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   xTextAlign=CENTER,
                   conditions=(Center2Center(), Top2Top()))
        subtitle = dict(font=fontStyle2, fontSize=pt(18), leading=pt(28))
        subtitle2 = dict(font=defaultfont, fontSize=pt(18), leading=pt(28))
        newTextBox(pageNumber,
                   w=W - 100,
                   pt=-20,
                   h=PH + 100,
                   parent=page,
                   xAlign=RIGHT,
                   xTextAlign=RIGHT,
                   style=subtitle2,
                   conditions=(Center2Center(), Top2Top()))
        newTextBox("Series by David Berlow",
                   style=subtitle,
                   pt=pt(100),
                   w=PW,
                   h=PH,
                   parent=page,
                   columnAlignY=BOTTOM,
                   xTextAlign=CENTER,
                   conditions=(Center2Center(), Bottom2Bottom()))
        # 3 columns
        heightCol = pt(700)
        textString = "ABCDEFG HIJKLMN OPQRSTU VWXYZ&! abcdefghij klmnopqrs tuvwxyzĸ¢ 1234567890"
        centertext = context.newString(textString,
                                       style=dict(font=fontStyle1,
                                                  xTextAlign=CENTER,
                                                  fontSize=pt(60),
                                                  leading=pt(69)))
        CW2 = (PW - (G * 2))  # Column width
        style3 = dict(font=f,
                      fontSize=pt(60),
                      leading=pt(69),
                      hyphenation=None,
                      prefix=None,
                      postfix=None)
        newTextBox(centertext,
                   style=style3,
                   w=CW,
                   h=heightCol,
                   pt=pt(158),
                   xTextAlign=CENTER,
                   parent=page,
                   conditions=[Center2Center(), Top2Top()])
        text4 = "Betreed de wereld van de invloedrijke familie Plantin en Moretus. Christophe Plantin bracht zijn leven door in boeken. Samen met zijn vrouw en vijf dochters woonde hij in een imposant pand aan de Vrijdagmarkt. Plantin en Jan Moretus hebben een indrukwekkende drukkerij opgebouwd. Tegenwoordig is dit het enige museum ter wereld dat ..."
        style4 = dict(font=fontStyle2, fontSize=pt(28), leading=pt(34))
        newTextBox(text4,
                   style=style4,
                   xTextAlign=JUSTIFIED,
                   w=CW2 + 26,
                   h=pt(380),
                   parent=page,
                   pt=pt(174),
                   conditions=[Right2Right(), Bottom2Bottom()])
        style5 = dict(font=defaultfont, fontSize=pt(10))
        b = (
            "Hyni në botën e familjes me ndikim Plantin dhe Moretus. Christophe Plantin e kaloi jetën mes librave. Së bashku me gruan dhe pesë bijat e tij, ai jetonte në një pronë imponuese në Vrijdagmarkt. Plantin dhe Jan Moretus krijuan një biznes shtypës mbresëlënës. Sot, ky është muze i vetëm në botë që mbresëlënës do gruan ... \n "
        )
        c = (
            "Hyni në botën e familjes me ndikim Plantin dhe Moretus. Christophe Plantin e kaloi jetën mes librave. Së bashku me gruan dhe pesë bijat e tij, ai jetonte në një pronë imponuese në Vrijdagmarkt. Plantin dhe Jan Moretus krijuan një biznes shtypës mbresëlënës. Sot, ky është muze i vetëm në botë që mbresëlënës do ... \n "
        )
        newTextBox('60pt/72pt',
                   fontSize=pt(10),
                   parent=page,
                   w=CW - 60,
                   h=heightCol,
                   font=f,
                   pt=pt(146),
                   conditions=[Center2Center(), Top2Top()])
        newTextBox('28pt/34pt',
                   fontSize=pt(10),
                   parent=page,
                   w=CW2,
                   h=pt(380),
                   font=f,
                   pt=pt(160),
                   conditions=[Left2Left(), Bottom2Bottom()])
        firstColumnWaterfall(b, fontStyle2)
        secondColumnWaterfall(c, fontStyle2)
        doc.solve()

    # Parameters of the function
    fontStyle1 = H2OPTICAL.path
    fontStyle2 = f.path
    defaultfont = f.path
    pageNumber = '1'
    mainPage(fontStyle1, fontStyle2, pageNumber, defaultfont)

    # Page2
    # Function to make the one column layout
    page = page.next

    def oneColumnPage(fontStyle, textString, PageDescription, pageNumber):
        astring = context.newString(textString,
                                    style=dict(font=fontStyle,
                                               xTextAlign=CENTER,
                                               fontSize=fontSizeH1,
                                               leading=pt(163)))
        page.padding = pagePaddings
        padd = pt(100)
        PW2 = W - 2 * padd
        newTextBox(astring,
                   pt=pt(130),
                   w=PW2,
                   h=H,
                   hyphenation=False,
                   parent=page,
                   conditions=(Center2Center(), Middle2Middle()))
        newTextBox(PageDescription,
                   style=subtitle,
                   w=PW,
                   hyphenation=False,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Left2Left(), Top2Top()))
        newTextBox(pageNumber,
                   style=subtitle,
                   xTextAlign=RIGHT,
                   w=50,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Right2Right(), Top2Top()))
        #newTextBox('144pt', style=subtitle, xTextAlign=CENTER, w=200, h=50, parent=page, columnAlignY = TOP, conditions=(Center2Center(), Top2Top()))
        doc.solve()

    # Parameters of the function
    textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz"
    PageDescription = "Opsz-max camelcase roman" + points
    fontStyle = MAXOPTICAL.path
    pageNumber = '2'
    oneColumnPage(fontStyle, textString, PageDescription, pageNumber)

    # Page3
    page = page.next
    PageDescription = "Opsz-default camelcase roman" + points
    fontStyle = f.path
    pageNumber = '3'
    oneColumnPage(fontStyle, textString, PageDescription, pageNumber)

    #Page4
    page = page.next
    PageDescription = "Opsz-min camelcase roman" + points
    fontStyle = MINOPTICAL.path
    pageNumber = '4'
    oneColumnPage(fontStyle, textString, PageDescription, pageNumber)

    # Page 5
    #Function to make the 3 column layout
    page = page.next

    def threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString,
                        PageDescription, pageNumber):
        page.padding = pagePaddings
        CW3 = (W - 120) / 3  # Column width
        cstring = context.newString(textString,
                                    style=dict(font=fontStyle1,
                                               xTextAlign=CENTER,
                                               fontSize=fontSizeH1,
                                               leading=pt(163)))
        dstring = context.newString(textString,
                                    style=dict(font=fontStyle2,
                                               xTextAlign=CENTER,
                                               fontSize=fontSizeH1,
                                               leading=pt(163),
                                               hyphenation=None))
        spreads = dict(font=fontStyle3, fontSize=fontSizeH1, leading=pt(163))
        newTextBox(cstring,
                   w=(CW3 + 10),
                   parent=page,
                   conditions=[Left2Left(), Middle2Middle()])
        newTextBox(textString,
                   style=spreads,
                   w=CW3,
                   xTextAlign=CENTER,
                   parent=page,
                   conditions=[Center2Center(),
                               Middle2Middle()])
        newTextBox(dstring,
                   w=CW3,
                   parent=page,
                   conditions=[Right2Right(), Middle2Middle()])
        newTextBox(PageDescription,
                   style=subtitle,
                   w=PW,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Left2Left(), Top2Top()))
        newTextBox(pageNumber,
                   style=subtitle,
                   xTextAlign=RIGHT,
                   w=50,
                   h=PH,
                   parent=page,
                   columnAlignY=TOP,
                   conditions=(Right2Right(), Top2Top()))
        #newTextBox('144pt', style=subtitle, xTextAlign=CENTER, w=200, h=50, parent=page, columnAlignY = TOP, conditions=(Center2Center(), Top2Top()))

        doc.solve()

    # Parameters of the function
    textString = "ABCDE\nFGHIJK\nLMNOP\nQRSTU\nVWXYZ"
    PageDescription = "Opsz-min opsz-default opsz-max uppercase roman" + points
    fontStyle1 = MINOPTICAL.path
    fontStyle2 = MAXOPTICAL.path
    fontStyle3 = f.path
    pageNumber = '5'
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString,
                    PageDescription, pageNumber)

    # Page 6
    page = page.next
    textString = 'adhesion'
    PageDescription = "Opsz-min opsz-default opsz-max lowercase roman" + points
    fontStyle1 = MINOPTICAL.path
    fontStyle2 = MAXOPTICAL.path
    fontStyle3 = f.path
    pageNumber = '6'
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString,
                    PageDescription, pageNumber)

    # Page 7
    page = page.next
    page.padding = pagePaddings
    x = 'ADHESION'
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall uppercase roman'
    pageNumber = '7'
    typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber)

    # Page 8
    page = page.next
    page.padding = pagePaddings
    x = 'adhesion'
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall lowercase roman'
    pageNumber = '8'
    typeWaterfall(x, fontStyle, PageDescription, pageNumber)

    # Page 9
    page = page.next
    page.padding = pagePaddings
    x = '1234567890‘?“!(%)[#]{@}/&\$:;,._^*'
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall numerals and punctuation roman'
    pageNumber = '9'
    typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber)

    # Page 10
    page = page.next
    page.padding = pagePaddings
    x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽'
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall monetary'
    pageNumber = '10'
    typeWaterfall(x, fontStyle, PageDescription, pageNumber)

    # Page 1 Italic
    page = page.next
    fontStyle1 = H2OPTICALIT.path
    fontStyle2 = f2.path
    defaultfont = f.path
    pageNumber = '11'
    mainPage(fontStyle1, fontStyle2, pageNumber, defaultfont)

    # Page 2 Italic
    page = page.next
    textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz"
    PageDescription = "Opsz-max camelcase italic" + points
    fontStyle = MAXOPTICALIT.path
    pageNumber = '12'
    oneColumnPage(fontStyle, textString, PageDescription, pageNumber)

    # Page 3 Italic
    page = page.next
    PageDescription = "Opsz-default camelcase italic" + points
    fontStyle = f2.path
    pageNumber = '13'
    oneColumnPage(fontStyle, textString, PageDescription, pageNumber)

    # Page 4 Italic
    page = page.next
    PageDescription = "Opsz-min camelcase italic" + points
    fontStyle = MINOPTICALIT.path
    pageNumber = '14'
    oneColumnPage(fontStyle, textString, PageDescription, pageNumber)

    # Page 5 Italic
    page = page.next
    textString = "ABCDE\nFGHIJK\nLMNOP\nQRSTU\nVWXYZ"
    PageDescription = "Opsz-min opsz-default opsz-max uppercase italic" + points
    fontStyle1 = MINOPTICALIT.path
    fontStyle2 = MAXOPTICALIT.path
    fontStyle3 = f2.path
    pageNumber = '15'
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString,
                    PageDescription, pageNumber)

    # Page 6 Italic
    page = page.next
    textString = 'abcde\nfghijk\nlmnop\nqrstu\nvwxyz'
    PageDescription = "Opsz-min opsz-default opsz-max lowercase italic" + points
    fontStyle1 = MINOPTICALIT.path
    fontStyle2 = MAXOPTICALIT.path
    fontStyle3 = f2.path
    pageNumber = '16'
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString,
                    PageDescription, pageNumber)
    doc.solve()

    # Page 7 Italic
    page = page.next
    page.padding = pagePaddings
    x = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall uppercase italic'
    pageNumber = '17'
    typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber)
    doc.solve()

    # Page 8 Italic
    page = page.next
    page.padding = pagePaddings
    x = 'abcdefghijklmnopqrstuvwxyz'
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall lowercase italic'
    pageNumber = '18'
    typeWaterfall(x, fontStyle, PageDescription, pageNumber)
    doc.solve()

    # Page 9 Italic
    page = page.next
    page.padding = pagePaddings
    x = '1234567890‘?“!(%)[#]{@}/&\$:;,._^*'
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall numerals and punctuation roman'
    pageNumber = '19'
    typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber)
    doc.solve()

    # Page 10 Italic
    page = page.next
    page.padding = pagePaddings
    x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽'
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall monetary'
    pageNumber = '20'
    typeWaterfall(x, fontStyle, PageDescription, pageNumber)

    page.solve()
    return doc
Exemplo n.º 9
0
def makeDocument():
    #Parameters of the docuemnt
    context = getContext()
    W, H = pt(1920, 1080)
    padheight = pt(70)
    padside = pt(466)
    PADDING = padheight, padside, padheight, padside
    G = mm(4)
    PW = W - 2*padside 
    PH = H - 2*padheight
    CW = (PW - (G*2))/3 
    CH = PH
    GRIDX = ((CW, G), (CW, 0))
    GRIDY = ((CH, 0),)

    # Function for the first column in the main page layout
    def firstColumnWaterfall(b, fontStyle):
        s = c.newString('', style=dict(font=f))
        CW2 = (PW - (G*2))/3 # Column width
        for n in range(4):
                s += c.newString( b + '\n', style=dict(font=fontStyle, fontSize=pt(12+n*1), leading=pt((12+n*1)+3) ))
        newTextBox(s ,parent=page, w=CW2, h=pt(700),font=f, pt=pt(160), nextElementName='e2',conditions=[Left2Left(),Top2Top(), Overflow2Next()])
        doc.solve()
    
    # Function for the second column in the main page layout
    def secondColumnWaterfall(b, fontStyle):
        s = c.newString('', style=dict(font=f))
        CW2 = (PW - (G*2))/3 # Column width
        for n in range(3):
                s += c.newString( b + '\n', style=dict(font=fontStyle, fontSize=pt(16+n*2), leading=pt((12+n*2)+6) ))
        newTextBox(s ,parent=page, w=CW2, h=pt(700),font=f, pt=pt(160), conditions=[Right2Right(),Top2Top()])
        doc.solve()

    # Function for the Waterfall layout
    def typeWaterfall(x, fontStyle, PageDescription):
        newTextBox(PageDescription, style=subtitle, w=PW, h=PH, parent=page, columnAlignY = TOP, conditions=(Left2Left(), Top2Top()))
        st = c.newString('', style=dict(font=f))
        for n in range(7):
            if n < 4:
                fontSize=144-n*24
                leading=(144-n*24)+24
            else:
                fontSize=108-n*12
                leading=None
            st += c.newString( x + '\n', style=dict(font=fontStyle, fontSize=fontSize, leading=leading))
        newTextBox(st ,parent=page, padding=pt(4), x=pt(60), y= pt(950), w=W, font=f,
                    cconditions=[Left2Left(), Top2Top(),  Overflow2Next()],
                    yAlign=TOP, xAlign=LEFT,)
        return doc 
        doc.solve()

    # Create a new document with 1 page. Set overall size and padding.
    doc = Document(w=W, h=H, padding=PADDING, gridX=GRIDX, gridY=GRIDY, context=context)
    view = doc.view
    page = doc[1]

    subtitle = dict(font=f, fontSize=pt(24), leading=pt(28))
    pagePaddings = (50, 50, 50, 50)

    # Page1
    # Function to make the main page layout 
    def mainPage(fontStyle1, fontStyle2):
        # New text box for the Title
        maintitle = context.newString("Amstelvar", style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(96), leading=pt(115)))
        newTextBox(maintitle, w=PW, h=PH, parent=page, columnAlignY = TOP, xTextAlign=CENTER, conditions=(Center2Center(), Top2Top()))
        subtitle = dict(font=fontStyle2, fontSize=pt(24), leading=pt(28))
        newTextBox("Series by David Berlow", style=subtitle, pt = pt(100), w=PW, h=PH, parent=page, columnAlignY = BOTTOM, xTextAlign=CENTER, conditions=(Center2Center(), Bottom2Bottom()))
        # 3 columns
        heightCol = pt(700)
        textString = "ABCDEFG HIJKLMN OPQRSTU VWXYZ&! abcdefghij klmnopqrs tuvwxyzĸ¢ 1234567890"
        centertext = context.newString(textString, style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(60), leading=pt(69)))
        CW2 = (PW - (G*2)) # Column width
        style3 = dict(font=f, fontSize=pt(60), leading=pt(69), hyphenation=None, prefix= None, postfix=None)
        newTextBox(centertext, style=style3, w=CW, h=heightCol, pt = pt(148), xTextAlign=CENTER, parent=page, conditions=[Center2Center(), Top2Top()])
        text4 = "Betreed de wereld van de invloedrijke familie Plantin en Moretus. Christophe Plantin bracht zijn leven door in boeken. Samen met zijn vrouw en vijf dochters woonde hij in een imposant pand aan de Vrijdagmarkt. Plantin en Jan Moretus hebben een indrukwekkende drukkerij opgebouwd. Tegenwoordig is dit het enige museum ter wereld dat ..."
        style4 = dict(font=fontStyle2, fontSize=pt(29), leading=pt(35))
        newTextBox(text4, style=style4, xTextAlign=JUSTIFIED, w=CW2, parent=page, conditions=[Left2Left(), Bottom2Bottom()])
        b = ("Hyni në botën e familjes me ndikim Plantin dhe Moretus. Christophe Plantin e kaloi jetën mes librave. Së bashku me gruan dhe pesë bijat e tij, ai jetonte në një pronë imponuese në Vrijdagmarkt. Plantin dhe Jan Moretus krijuan një biznes shtypës mbresëlënës. Sot, ky është muze i vetëm në botë që do të ... \n ")
        firstColumnWaterfall(b, fontStyle2)
        secondColumnWaterfall(b, fontStyle2)
        doc.solve()

    # Parameters of the function
    fontStyle1 = H2OPTICAL.path
    fontStyle2 = f.path
    mainPage(fontStyle1, fontStyle2)

    # Page2
    # Function to make the one column layout
    page = page.next
    def oneColumnPage(fontStyle, textString, PageDescription):
        astring = context.newString(textString, style=dict(font=fontStyle, xTextAlign=CENTER, fontSize=pt(144), leading=pt(163)))
        page.padding = pagePaddings
        padd= pt(100)
        PW2 = W - 2*padd
        newTextBox(astring, pt= pt(130), w=PW2, h=H, hyphenation=False, parent=page, conditions=(Center2Center(), Middle2Middle()))
        newTextBox(PageDescription, style=subtitle, w=PW, hyphenation=False, h=PH, parent=page, columnAlignY = TOP, conditions=(Left2Left(), Top2Top()))
        doc.solve()
    
    # Parameters of the function
    textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz"
    PageDescription = "Opsz-max camelcase roman"
    fontStyle = MAXOPTICAL.path
    oneColumnPage(fontStyle, textString, PageDescription)

    # Page3
    page = page.next
    PageDescription = "Opsz-default camelcase roman"
    fontStyle = f.path
    oneColumnPage(fontStyle, textString, PageDescription)

    #Page4
    page = page.next
    PageDescription = "Opsz-min camelcase roman"
    fontStyle = MINOPTICAL.path
    oneColumnPage(fontStyle, textString, PageDescription)

    # Page 5
    #Function to make the 3 column layout
    page = page.next 
    def threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription):
        page.padding = pagePaddings
        CW3 = (W-120)/3 # Column width
        cstring = context.newString(textString, style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(144), leading=pt(163)))
        dstring = context.newString(textString, style=dict(font=fontStyle2, xTextAlign=CENTER, fontSize=pt(144), leading=pt(163), hyphenation=None))
        spreads= dict(font=fontStyle3, fontSize=pt(144), leading=pt(163))
        newTextBox(cstring, w=(CW3+10), parent=page, conditions=[Left2Left(), Middle2Middle()])
        newTextBox(textString, style=spreads, w=CW3, xTextAlign=CENTER, parent=page, conditions=[Center2Center(), Middle2Middle()])
        newTextBox(dstring, w=CW3, parent=page, conditions=[Right2Right(), Middle2Middle()])
        newTextBox(PageDescription, style=subtitle, w=PW, h=PH, parent=page, columnAlignY = TOP, conditions=(Left2Left(), Top2Top()))
        doc.solve()

    # Parameters of the function
    textString = "ABCDE\nFGHIJK\nLMNOP\nQRSTU\nVWXYZ"
    PageDescription = "Opsz-min opsz-default opsz-max uppercase roman"
    fontStyle1 = MINOPTICAL.path
    fontStyle2 = MAXOPTICAL.path
    fontStyle3 = f.path
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription)

    # Page 6
    page = page.next 
    textString = 'abcde\nfghijk\nlmnop\nqrstu\nvwxyz'
    PageDescription = "Opsz-min opsz-default opsz-max lowercase roman"
    fontStyle1 = MINOPTICAL.path
    fontStyle2 = MAXOPTICAL.path
    fontStyle3 = f.path
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription)

    # Page 7
    page = page.next
    page.padding = pagePaddings
    x = 'ABCDEFGHIJKLMNOPQRST'
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall uppercase roman'
    typeWaterfall(x, fontStyle, PageDescription)

    # Page 8
    page = page.next
    page.padding = pagePaddings
    x = 'abcdefghijklmnopqrstuvwxyz'
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall lowercase roman'
    typeWaterfall(x, fontStyle, PageDescription)

    # Page 9
    page = page.next
    page.padding = pagePaddings
    x = '123456789!@#$%^&*()_+{}|:”<>?/.,’;\]['
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall numerals and punctuation roman'
    typeWaterfall(x, fontStyle, PageDescription)
    
    # Page 10
    page = page.next
    page.padding = pagePaddings
    x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽'
    fontStyle = MAXOPTICAL.path
    PageDescription = 'Waterfall monetary'
    typeWaterfall(x, fontStyle, PageDescription)
    
    # Page 1 Italic
    page = page.next
    fontStyle1 = H2OPTICALIT.path
    fontStyle2 = f2.path
    mainPage(fontStyle1, fontStyle2)

    # Page 2 Italic
    page = page.next
    textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz"
    PageDescription = "Opsz-max camelcase italic"
    fontStyle = MAXOPTICALIT.path
    oneColumnPage(fontStyle, textString, PageDescription)

    # Page 3 Italic
    page = page.next
    PageDescription = "Opsz-default camelcase italic"
    fontStyle = f2.path
    oneColumnPage(fontStyle, textString, PageDescription)

    # Page 4 Italic
    page = page.next
    PageDescription = "Opsz-min camelcase italic"
    fontStyle = MINOPTICALIT.path
    oneColumnPage(fontStyle, textString, PageDescription)

    # Page 5 Italic
    page = page.next
    textString = "ABCDE\nfFGHIJK\nfLMNOP\nfQRSTU\nfVWXYZ"
    PageDescription = "Opsz-min opsz-default opsz-max uppercase italic"
    fontStyle1 = MINOPTICALIT.path
    fontStyle2 = MAXOPTICALIT.path
    fontStyle3 = f2.path
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription)

    # Page 6 Italic
    page = page.next 
    textString = 'abcde\nfghijk\nlmnop\nqrstu\nvwxyz'
    PageDescription = "Opsz-min opsz-default opsz-max lowercase italic"
    fontStyle1 = MINOPTICALIT.path
    fontStyle2 = MAXOPTICALIT.path
    fontStyle3 = f2.path
    threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription)
    doc.solve()

    # Page 7 Italic
    page = page.next
    page.padding = pagePaddings
    x = 'ABCDEFGHIJKLMNOPQRST'
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall uppercase italic'
    typeWaterfall(x, fontStyle, PageDescription)
    doc.solve()

    # Page 8 Italic
    page = page.next
    page.padding = pagePaddings
    x = 'abcdefghijklmnopqrstuvwxyz'
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall lowercase italic'
    typeWaterfall(x, fontStyle, PageDescription)
    doc.solve()

    # Page 9 Italic
    page = page.next
    page.padding = pagePaddings
    x = '123456789!@#$%^&*()_+{}|:”<>?/.,’;\]['
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall numerals and punctuation roman'
    typeWaterfall(x, fontStyle, PageDescription)
    doc.solve()

    # Page 10 Italic
    page = page.next
    page.padding = pagePaddings
    x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽'
    fontStyle = MAXOPTICALIT.path
    PageDescription = 'Waterfall monetary'
    typeWaterfall(x, fontStyle, PageDescription)
    
    page.solve()
    return doc
Exemplo n.º 10
0
context = getContext()
# Random text generator
blurb = Blurb()

# =============================================================================
#    Building switches
# .............................................................................

SHOW_TOPHEAD = True  # Headline on top of title
SHOW_TITLE = True  # Main title of the newspaper

# =============================================================================
#    Measures
# .............................................................................
#W, H = Broadsheet # Split paper size in document width and height
W, H = mm(819, 1176)  # Dutch Volskrant tabloid size.

U = pt(10)
G = 3 * U
PL = 8 * U  # Page padding left
PR = 10.5 * U
PT = 7 * U  # Page padding top
PB = 10 * U  # Page badding bottom
PADDING = PT, PR, PB, PL
BASELINE = mm(9.8)  # Overall baseline grid

# Grid definitions
CC = 5  # Column count
CW1 = CW = (W - PL - PR + G) / CC - G  # Column width (without gutter)
CW2 = 2 * CW + G
CW3 = 3 * CW + 2 * G