def fit():
    varFont = findFont('RobotoDelta-VF')
    print(varFont.axes)
    condensedFont = getVarFontInstance(varFont, dict(wdth=75, YTUC=528))
    wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528))
    boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1))

    W, H = 500, 500
    PADDING = 56
    COL = 40
    
    doc = Document(w=W, h=H, originTop=False)
    view = doc.view
    context = view.context

    page = doc[1] # Get page on pageNumber, first in row (this is only one now).
    page.padding = PADDING

    s = 'a'

    fontSize = 32

    for ix in range(10):
        for iy in range(10):

            instance = getVarFontInstance(varFont, dict(wdth=75, YTUC=528))
                
            style = dict(font=instance, fontSize=fontSize, leading=fontSize)
            bs = context.newString(s, style=style)
            tw, th = bs.size
            newText(bs, x=page.pl+ix*COL, y=page.pb+iy*COL, w=COL, h=COL, parent=page)

    doc.export(EXPORT_PATH)
Exemple #2
0
def makeDocument():
    u"""Create new document with (w,h) and fixed amount of pages.
    Make number of pages with default document size.
    Initially make all pages default with template."""

    smallWords = []
    for word in words():  # Get all English hyphenating words.
        if len(word) in (4, 5, 6):
            smallWords.append(word)

    title = 'Position Text Box Example'  # Using plain string, style values

    doc = Document(originTop=False,
                   title=title,
                   w=W,
                   h=H,
                   autoPages=1,
                   context=defaultContext)

    page = doc[0]  # Get the first/single page of the document.
    page.size = W, H

    view = doc.view
    view.w = view.h = W, H
    view.padding = 40
    view.showPageFrame = True
    view.showPageCropMarks = True
    view.showElementOrigin = True  # Show the alignment position
    # of elements as plus-mark.
    fontSize = 18
    cellHeight = int(fontSize * 4)
    for cx in range(0, W - 2 * M, C):
        for cy in range(0, H - 2 * M, cellHeight):
            newText(
                choice(smallWords),  # Random small word
                x=cx,
                y=cy,  # Position from left-bottom of page side
                # (not page padding)
                parent=page,
                w=C - G,
                h=cellHeight,  # Size of the element.
                padding=5,  # Padding inside text box for all 4 sides equal.
                fill=(0.4, 0.6, 1),  # Rectangle fill color
                stroke=(1, 0, 0),  # Rectangle stroke color
                strokeWidth=10,
                # Below style values that apply to the content
                font='Verdana',
                fontSize=fontSize,
                leading=0,
                rLeading=1,  # Absolute and relative leading.
                xAlign=LEFT,
                yAlign=BOTTOM,  # Set origin of element to left-bottom
                textFill=(0, 0, 1))  # Color of the text.
    # Return the generated document to the caller.
    return doc
Exemple #3
0
def buildSpecimenPages(doc, fontNames):
    for index, fontName in enumerate(sorted(fontNames)):
        font = getFontByName(fontName)
        page = doc[index]
        pageTitle = font.info.familyName + ' ' + font.info.styleName
        # Add filling rectangle for background color of the old paper book.
        newRect(z=-1,
                parent=page,
                conditions=[Bleed2Sides()],
                fill=PAPER_COLOR)
        # Centered title: family name and style name of the current font.
        titleBs = context.newString(pageTitle,
                                    style=dict(font=fontName,
                                               fontSize=24,
                                               textFill=0))
        newText(titleBs, x=50, y=100, parent=page, w=400)
Exemple #4
0
def makeDocument(rootStyle):
    u"""Demo random book cover generator."""

    # Create new document with (w,h) and fixed amount of pages.
    # Make number of pages with default document size.
    # Initially make all pages default with template
    doc = Document(rootStyle, w=W, h=H,
                   autoPages=1)  # One page, just the cover.

    page = doc[0]  # Get the first/single page of the document.

    from random import random
    C1 = (random() * 0.2, random() * 0.2, random() * 0.9)

    # Make background element, filling the page color and bleed.
    colorRect1 = newRect(z=-10,
                         name='Page area',
                         parent=page,
                         conditions=[
                             Top2TopSide(),
                             Left2LeftSide(),
                             Fit2RightSide(),
                             Fit2BottomSide()
                         ],
                         fill=C1)

    colorRect1.solve()  # Solve element position, before we can make
    # other elements depend on position and size.

    #colorRect2:
    M = 64
    newRect(
        z=-10,
        name='Frame 2',
        conditions=[Center2Center(), Middle2Middle()],
        fill=darker(C1, 0.5),  # Default parameter:
        # 50% between background color and white
        stroke=None,
        w=colorRect1.w - M,
        h=colorRect1.h - M,
        xAlign=CENTER,
        yAlign=CENTER)

    # Add some title (same width, different height) at the "wrongOrigin" position.
    # They will be repositioned by solving the colorConditions.
    newText('Book Cover',
            style=rootStyle,
            parent=page,
            name='Other element',
            font='Georgia',
            fontSize=40,
            fill=(0.3, 0.3, 0.5),
            textFill=(1, 0, 0),
            conditions=[Top2Middle(), Top2Top()],
            xAlign=CENTER)  #yAlign=TOP)
    """
    page.rect(point=wrongOrigin, style=rootStyle, w=W2, h=H2,
              name='Floating element 2',
              conditions=colorCondition2, fill=(1, 1, 0),
              xAlign=LEFT, yAlign=TOP)
    page.rect(point=wrongOrigin, style=rootStyle, w=W3, h=H3,
              name='Floating element 3',
              conditions=colorCondition2, fill=(1, 0, 1),
              xAlign=LEFT, yAlign=TOP)

    # Make text box at wrong origin. Apply same width a the color rect,
    # which may be too wide from typographic point ogf view.
    # The MaxWidthByFontSize will set the self.w to the maximum
    # width for this pointSize.
    if not hasattr(pbglobals, 'blurbText'):
        the_blurb = blurb.getBlurb('article_summary', noTags=True)
        pbglobals.blurbText = doc.context.newString(the_blurb, page,
                                                    style=dict(font='Georgia',
                                                               fontSize=12,
                                                               rLeading=0.2,
                                                               textColor=0))
    page.textBox(pbglobals.blurbText, point=wrongOrigin,
                 style=rootStyle, w=WT,
                 conditions=textCondition,
                 xAlign=CENTER, yAlign=CENTER)

    page.rect(point=wrongOrigin, style=rootStyle, w=W4, h=H4,
              name='Floating element 4',
              conditions=colorCondition2, fill=(0, 1, 1),
              xAlign=LEFT, yAlign=TOP)

    page.rect(point=wrongOrigin, style=rootStyle, w=W5, h=H5,
              name='Floating element 5',
              conditions=[FloatRightTopSides()], fill=(0, 1, 0),
              xAlign=LEFT, yAlign=TOP)
    """
    score = page.evaluate()
    #print 'Page value on evaluation:', score
    #print score.fails
    # Try to solve the problems if evaluation < 0
    if score.fails:
        print('Solving', score.fails)
        page.solve()
    #print score.fails
    # Evaluate again, result should now be >= 0
    score = page.evaluate()
    print('Page value after solving the problems:', score)
    for fail in score.fails:
        print(fail)

    return doc
Exemple #5
0
#wdthMin, wdthDef, wdthMax = (-1, 0, 1)

print('wght %s %s %s' % (wghtMin, wghtDef, wghtMax))
print('wdth %s %s %s' % (wdthMin, wdthDef, wdthMax))


NORMAL = getVarFontInstance(f, dict(wght=wghtDef, wdth=wdthDef), styleName='Normal', normalize=False)
LIGHT = getVarFontInstance(f, dict(wght=wghtMin, wdth=wdthDef), styleName='Light', normalize=False)
BOLD = getVarFontInstance(f, dict(wght=wghtMax, wdth=wdthDef), styleName='Bold', normalize=False)
COND = getVarFontInstance(f, dict(wght=wghtDef, wdth=wdthMin), styleName='Cond', normalize=False)
WIDE = getVarFontInstance(f, dict(wght=wghtDef, wdth=wdthMax), styleName='Wide', normalize=False)

W, H = A4
doc = Document(w=W, h=H, autoPages=1)
page = doc[1]

bs = context.newString('Q', style=dict(fontSize=250, font=NORMAL.path, textFill=blackColor))
newText(bs, x=350, y=400, parent=page)
bs = context.newString('Q', style=dict(fontSize=250, font=LIGHT.path, textFill=blackColor))
newText(bs, x=50, y=400, parent=page)
bs = context.newString('Q', style=dict(fontSize=250, font=BOLD.path, textFill=blackColor))
newText(bs, x=650, y=400, parent=page)
bs = context.newString('Q', style=dict(fontSize=250, font=COND.path, textFill=blackColor))
newText(bs, x=350, y=700, parent=page)
bs = context.newString('Q', style=dict(fontSize=250, font=WIDE.path, textFill=blackColor))
newText(bs, x=350, y=100, parent=page)

doc.export('_export/TestVariableTTFont.pdf')

print('Done')
Exemple #6
0
def fit():
    varFont = findFont('RobotoDelta-VF')
    print(varFont.axes)
    condensedFont = getVarFontInstance(varFont, dict(wdth=75, YTUC=528))
    wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528))
    boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1))

    W, H = 500, 400
    PADDING = 8

    doc = Document(w=W, h=H, originTop=False)
    view = doc.view
    context = view.context

    page = doc[1] # Get page on pageNumber, first in row (this is only one now).
    page.padding = PADDING

    s = 'Variable'

    labelStyle = dict(font=varFont.path, fontSize=8, textFill=(1, 0, 0),
        leading=8)

    conditions1 = [Left2Left(), Top2Top()]
    conditions2 = [Left2Left(), Float2Top()]
    
    fontSize = 80
    style = dict(font=varFont.path, fontSize=fontSize, leading=fontSize)
    bs = context.newString(s, style=style)
    tw, th = bs.size
    newText(bs, w=W-2*PADDING, h=th*1.2, parent=page,
        conditions=conditions1)
    labelS = context.newString('Original var-font %0.2fpt' % (bs.fontSize), style=labelStyle)
    newText(labelS, parent=page,
        conditions=conditions2)

    style = dict(font=condensedFont.path, fontSize=fontSize, leading=fontSize)
    bs = context.newString(s, style=style)
    tw, th = bs.size
    newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2)
    labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle)
    newText(labelS, parent=page, conditions=conditions2)

    style = dict(font=wideFont.path, fontSize=fontSize, leading=fontSize)
    bs = context.newString(s, style=style)
    tw, th = bs.size
    newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2)
    labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle)
    newText(labelS, parent=page, conditions=conditions2)

    style = dict(font=boldFont.path, fontSize=fontSize, leading=fontSize)
    bs = context.newString(s, style=style)
    tw, th = bs.size
    newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, 
        conditions=conditions2)
    labelS = context.newString('Bold %0.2fpt %s' % (bs.fontSize, boldFont.info.location), style=labelStyle)
    newText(labelS, parent=page, conditions=conditions2)
    
    page.solve()
    doc.export(EXPORT_PATH)
Exemple #7
0
PADDING = 20

doc = Document(w=W, h=H, originTop=False)
view = doc.view
context = view.context

page = doc[1] # Get page on pageNumber, first in row (this is only one now).
page.padding = PADDING

s = 'ABCDEF'

labelStyle = dict(font=varFont.path, fontSize=8, textFill=(1, 0, 0))

style = dict(font=varFont.path, fontSize=10)
bs = context.newString(s, style=style, w=W-2*PADDING)
newText(bs, (20, 180, W-2*PADDING, H), parent=page)
labelS = context.newString('Original var-font %0.2fpt' % (bs.fontSize), style=labelStyle)
newText(labelS, (20, 220), parent=page)

style = dict(font=wideFont.path, fontSize=10)
bs = context.newString(s, style=style, w=W-2*PADDING)
newText(bs, (20, 100, W-2*PADDING, H), parent=page)
labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle)
newText(labelS, (20, 130), parent=page)

style = dict(font=boldFont.path, fontSize=10)
bs = context.newString(s, style=style, w=W-2*PADDING)
newText(bs, (20, -30, W-2*PADDING, H), parent=page)
labelS = context.newString('Bold %0.2fpt %s' % (bs.fontSize, boldFont.info.location), style=labelStyle)
newText(labelS, (20, 10), parent=page)
Exemple #8
0
# -----------------------------------------------------------------------------
#
#     P A G E B O T
#
#     Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens
#     www.pagebot.io
#     Licensed under MIT conditions
#
# -----------------------------------------------------------------------------
#

from pagebot.document import Document
from pagebot.elements import newText
from pagebot.toolbox.units import pt
from pagebot.fonttoolbox.objects.font import findFont

# Find the Roboto font that exist in PageBot resources.
f = findFont('Roboto-Bold')
# Create document with default 1 page.
doc = Document(w=pt(800), h=pt(190), originTop=False) 
# First page in the list is uneven (right side)
page = doc[1] 
# Create a new rectangle element with (x, y) conditions
newText('Hello World', x=30, y=0, 
    font=f, fontSize=140, textFill=0.2, parent=page)
# Export the document page as png, so it shows as web image.
doc.export('_export/HelloWorld.png') 
Exemple #9
0
def fit():
    varFont = findFont('RobotoDelta-VF')
    print(varFont.axes)
    wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528))
    boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1))

    W, H = 500, 350
    PADDING = 20

    doc = Document(w=W, h=H, originTop=False)
    view = doc.view
    context = view.context

    page = doc[
        1]  # Get page on pageNumber, first in row (this is only one now).
    page.padding = PADDING

    s = 'ABCDEF'

    labelStyle = dict(font=varFont.path, fontSize=8, textFill=(1, 0, 0))

    style = dict(font=varFont.path, fontSize=10)
    bs = context.newString(s, style=style, w=W - 2 * PADDING)
    newText(bs, x=20, y=180, w=W - 2 * PADDING, h=H, parent=page)
    labelS = context.newString('Original var-font %0.2fpt' % (bs.fontSize),
                               style=labelStyle)
    newText(labelS, x=20, y=220, parent=page)

    style = dict(font=wideFont.path, fontSize=10)
    bs = context.newString(s, style=style, w=W - 2 * PADDING)
    newText(bs, x=20, y=100, w=W - 2 * PADDING, h=H, parent=page)
    labelS = context.newString('Wide %0.2fpt %s' %
                               (bs.fontSize, wideFont.info.location),
                               style=labelStyle)
    newText(labelS, x=20, y=130, parent=page)

    style = dict(font=boldFont.path, fontSize=10)
    bs = context.newString(s, style=style, w=W - 2 * PADDING)
    newText(bs, x=20, y=-30, w=W - 2 * PADDING, h=H, parent=page)
    labelS = context.newString('Bold %0.2fpt %s' %
                               (bs.fontSize, boldFont.info.location),
                               style=labelStyle)
    newText(labelS, x=20, y=10, parent=page)

    doc.export(EXPORT_PATH)