Example #1
0
def showAll():
    """Shows all fonts that are shipped with PageBot."""
    context = getContext()
    doc = Document(w=W, h=H, originTop=False, autoPages=1, context=context)
    page = doc[1]
    page.padding = P
    
    c1 = (Left2Left(), Fit2Right(), Float2Top()) # Group condition
    c2 = (Left2Left(), Float2Top()) # Title condition    
    c3 = (Right2Right(), Float2Top()) # Speciment condition

    families = getFamilyPaths()
    fam = findFamily('Roboto')
    print(fam)
    fam = getFamily('Bungee')
    print(fam)

    fam = getFamily('BungeeOutline')
    print(fam)

    fam = getFamily('Roboto')

    #verboseFam(fam)
    fam = getFamily('RobotoCondensed')
    verboseFam(fam)

    fam = getFamily('PageBot')
    print(fam)

    for s in fam.getStyles():
        print(' - %s' % s)

    #print(families)
    print('Number of families found: %d' % len(families))
    fontPaths = getFontPaths()
    print('Number of fonts found: %d' % len(fontPaths))
    tfp = getTestFontsPath()
    pbFonts = getPageBotFontPaths()
    print('Number of fonts shipped with PageBot: %d' % len(pbFonts))
    #print(sorted(pbFonts.keys()))
    font = findFont('Roboto-Black')
    print('The Font object from the pagebot.fonttoolbox.objects module: %s' % font)
    print('It has %d glyphs.' % len(font))
    i = 0

    for pbFont in sorted(pbFonts.keys()):
        if 'Bungee' in pbFont or 'PageBot' in pbFont: # Filter some of the PageBot fonts.
            f = findFont(pbFont)
            if f is not None:
                i += 1
                g = newGroup(parent=page, conditions=c1, padding=7, borderTop=1, strokeWidth=0)
                newText('%s\n' % pbFont, parent=g, conditions=c2, fontSize=16, strokeWidth=0)
                newText('ABCDEabcde012345', parent=g, conditions=c3, font=f, fontSize=pt(44), strokeWidth=0)
        if i > 10:
            page = page.next
            page.padding = P
            i = 0
                
    doc.solve()
    doc.export('_export/Fonts.pdf')
Example #2
0
def makeDocument():
    
    doc = Document(w=W, h=H, originTop=False)
    view = doc.getView()
    view.padding = INCH/2
    view.showPageNameInfo = True
    view.showPageCropMarks = True
    view.showPagePadding = True
    view.showPageFrame = True
    view.showPageRegistrationMarks = True
    view.showGrid = False
    view.showGridColumns = True
    view.showElementOrigin = True
    view.showElementInfo = False

    page = doc[0]
    page.padding = INCH
    
    #rr = newRect(parent=page, x=100, y=200, w=50, h=50, fill=(1, 0, 0))
    cc = [Left2Left(), Float2Top()]
    rr = newRect(parent=page, h=300, conditions=cc, fill=(1, 0, 0))

    print page.elements

    conditions = [Left2LeftSide(), Top2TopSide(), Fit2Width()]
    conditions = [Left2Left(), Float2Top()]
    
    pr = newRect(parent=page, conditions=conditions, w=page.pw*2/3, fill=(1, 0, 1))
    doc.solve()
    
    #rr.left = pr.right
    #rr.top = pr.bottom
    
    return doc
Example #3
0
def makeAnimation(font, w, h, c, magnifySizeFactor):
    # Amstelvar axes to select from: here we are showing the optical size.
    # Define tag list for axes to be part of the animation as sequence
    sequenceAxes = ['opsz']
    sequenceLength = 3  # Seconds per sequence
    sequences = len(sequenceAxes)  # Amount of sequences, one per axis
    duration = sequenceLength * len(
        sequenceAxes)  # Total duration of the animation in seconds
    framesPerSecond = 10
    frameCnt = duration * framesPerSecond  # Total number of frames
    axisFrames = sequenceLength * framesPerSecond  # Number of frames per axis sequence.

    # Create a new doc, with the right amount of frames/pages.
    doc = Document(w=W,
                   h=H,
                   originTop=False,
                   frameDuration=1.0 / framesPerSecond,
                   autoPages=frameCnt,
                   context=c)
    # Sample text to show in the animation
    sample = 'Optical size'  #font.info.familyName #'Decovar'

    frameIndex = 1  # Same as page index in the document
    for axisTag in sequenceAxes:

        minValue, defaultValue, maxValue = font.axes[axisTag]
        for axisFrameIndex in range(axisFrames):
            page = doc[frameIndex]  # Get the current frame-page
            page.w = W

            phisin = sin(
                radians(axisFrameIndex / axisFrames * 360 +
                        3 / 4 * 360)) * 0.5 + 0.5
            fontSize = phisin * (maxValue - minValue) + minValue

            # Variable Font location for this frame sample
            variableLocation = {axisTag: fontSize}
            # Overall style for the frame
            style = dict(leading=em(1.4),
                         fontSize=fontSize * fontSizeFactor,
                         xTextAlign=RIGHT,
                         textFill=color(1),
                         stroke=None,
                         fill=blackColor,
                         variableLocation=variableLocation)

            af = AnimatedBannerFrame(sample,
                                     font,
                                     frameCnt,
                                     frameIndex,
                                     parent=page,
                                     style=style,
                                     w=page.w,
                                     h=page.h,
                                     context=c)
            af.magnifySizeFactor = magnifySizeFactor
            frameIndex += 1  # Prepare for the next frame

    doc.solve()
    doc.export('images/%s_OpticalSize.gif' % font.info.familyName)
def makeDocument():
    if mode == 'Anim':
        template = makeAnimation(0,0,0,0)
    elif mode == 'Iter':
        template = makeIteration(0,0,0,0,0,0,0,0)
    elif mode == 'Words':
        template = makeWords(0,0,0,0,0,0,0,0)
        
    pages = []
    
    for i in range(frames):
        pages.append(i+1)
    
    doc = Document(title='V-F AnimIterator', w=W, h=H, originTop=False, autoPages=frames, defaultTemplate=template)

    for i in pages:
        def easeInOutQuad(n):
            if n< 0.5:
                return 2 * n**2
            else:
                n=n * 2 -1
            return -0.5 * (n*(n-2) - 1)

        def Method(start, end):
            ee = easeInOutQuad(i/frames)
            result = start+(((end-start) * ee))
            return result
        
        sWGTH = Method(WG[0],WG[1])
        eWGTH = Method(WG[2],WG[3])
        sWDTH = Method(WD[0],WD[1])
        eWDTH = Method(WD[2],WD[3])
        sSLNT = Method(SL[0],SL[1])
        eSLNT = Method(SL[2],SL[3])
        sCNTR = Method(CT[0],CT[1])
        eCNTR = Method(CT[2],CT[3])
    

    
        pageid = i + 1
        # print(pageid, sWGTH,eWGTH,sWGTH,eWDTH)
        page = doc.getPage(i)
        if mode == 'Anim':
            page.applyTemplate(makeAnimation(sWGTH,sWDTH,sSLNT,sCNTR))
        elif mode == 'Iter':
            page.applyTemplate(makeIteration(sWGTH,eWGTH,sWDTH,eWDTH, sSLNT, eSLNT, sCNTR, eCNTR))
        elif mode == 'Words':
            page.applyTemplate(makeWords(sWGTH,eWGTH,sWDTH,eWDTH, sSLNT, eSLNT, sCNTR, eCNTR))
        else:
            print ('Incorrect mode')
    doc.solve()
    return doc # Answer the doc for further doing.
Example #5
0
def makeSite(viewId):
    doc = Document(viewId=viewId, autoPages=1)
    view = doc.view
    view.resourcePaths = ['js']
    view.jsUrls = (URL_JQUERY, URL_MEDIA, 'js/d3.js')
    # SiteView will automatically generate css/style.scss.css from assumed css/style.scss
    view.cssUrls = None#('css/normalize.css', 'css/style.scss.css')

    # Make the single page and elements of the site as empty containers
    makePage(doc)        
    
    doc.solve() # Solve all layout and float conditions for pages and elements.

    return doc
Example #6
0
def makeDocument():
    # Creates the publication/document that holds the pages.
    doc = Document(w=W, h=H, originTop=False, autoPages=1)

    # Gets page by pageNumber, first in row (at this point there is only one in
    # this row).
    page = doc[1]
    page.padding = PADDING
    page.showPadding = True

    conditions = [Right2Right(), Float2Top(), Float2Left()]
    # TODO: Solve this bug, does not mirror.
    conditions = (Left2Left(), Float2Top(), Float2Right())
    numberOfSquares = 88
    ratio = 1 / numberOfSquares

    for n in range(numberOfSquares):
        newRect(w=RW,
                h=RH,
                parent=page,
                fill=color(1 - n * ratio, 0, 0.5),
                conditions=conditions,
                margin=0)

    # Recursively solve the conditions in all page child elements..
    # If there are failing conditions, then the status
    # is returned in the Score instance.
    score = doc.solve()
    # Export to various export formats
    for exportPath in EXPORT_PATHS:
        doc.export(exportPath)
Example #7
0
def makeDocument():
    # Creates the publication/document that holds the pages.
    doc = Document(w=W, h=H, originTop=False, autoPages=1)

    # Gets page by pageNumber, first in row (at this point there is only one in
    # this row).
    page = doc[1]
    page.padding = 28
    page.showPadding = True

    conditions = [Right2Right(), Float2Top(),
                  Float2Left()]  #, Float2Top()]#, Float2Left()]
    # TODO: Solve this bug, does not mirror.
    #conditions = [Left2Left(), Float2Top(), Float2Right()]
    numberOfSquares = 88
    ratio = 1 / numberOfSquares

    for n in range(numberOfSquares):
        newRect(w=40,
                h=40,
                parent=page,
                fill=color(1 - n * ratio, 0, 0.5),
                conditions=conditions,
                margin=0)

    # Recursively solve the conditions in all pages.
    # If there are failing conditions, then the status
    # is returned in the Score instance.
    score = doc.solve()
    doc.build()
Example #8
0
def makeDocument():
    u"""Create the main document in the defined size with a couple of automatic empty pages."""
    doc = Document(w=W,
                   h=H,
                   title='Variable Font Sample Page',
                   originTop=False,
                   startPage=1,
                   autoPages=10,
                   context=context)
    # Get default view from the document and set the viewing parameters.
    view = doc.view
    view.padding = INCH / 2  # To show cropmarks and such, make >=20*MM or INCH.
    view.showPageCropMarks = True  # Won't show if there is not padding in the view.
    view.showPageFrame = False  # No frame in case PAPER_COLOR exists to be shown.
    view.showPageRegistrationMarks = True
    view.showPageNameInfo = True
    view.showTextOverflowMarker = False  # Don't show marker in case Filibuster blurb is too long.

    # Build the pages for all fonts that include one of these patterns.
    fontNames = findInstalledFonts(fontNamePatterns=FONT_NAME_PATTERNS,
                                   context=context)
    buildSpecimenPages(doc, fontNames)

    # Solve remaining layout and size conditions.

    score = doc.solve()
    if score.fails:
        print 'Conditiond failed', score.fails

    return doc
Example #9
0
def makeDocument():
    u"""Make a new document."""

    W = H = PageSize

    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)

    view = doc.getView()
    view.padding = 0 # Aboid showing of crop marks, etc.
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPagePadding = True
    view.showElementOrigin = True
    view.showElementDimensions = False

    # Get list of pages with equal y, then equal x.
    #page = doc[0][0] # Get the single page from te document.
    page0 = doc.getPage(0) # Get page on pageNumber,
                           # first in row (this is only one now).
    page0.name = 'Page 1'
    page0.padding = PagePadding

    s = ''
    for n in range(10):
        s += ('(Line %d) Volume of text defines the box height.'
              ' Volume of text defines the box height.\n') % (n+1)
        h1 = None

    newTextBox(s,
               name='CSSTextBox1',
               parent=page0, padding=4, x=100, font='Verdana', h=h1,
               maxW=W-2*PagePadding,
               minW=100, mb=20, mr=10, # Conditions make the
                                       # element move to
                                       # top-left of the page.
               # And the condition that there should be no overflow,
               # otherwise the text box will try to solve it.
               conditions=[Left2Left(), Fit2Width(), Float2Top()],
               # Position of the origin of the element.
               # Just to show where it is.
               # Has no effect on the position conditions.
               yAlign=BOTTOM, xAlign=LEFT,
               leading=5, fontSize=9, textFill=0,
               strokeWidth=0.5, fill=0.9, stroke=None)
    newTextBox('', # Empty box, will get the
                   # overflow from e1, if there is any.
               name='CSSTextBox2', # Flow reference by element.name
               parent=page0, padding=4, x=100, h=200,
               maxW=W-2*PagePadding, minW=100,
               conditions=[Left2Left(), Fit2Width(), Float2Top()],
               yAlign=TOP, fill=1, stroke=None)

    score = doc.solve() # Try to solve all pages.
    if score.fails:
        print score.fails

    return doc # Answer the doc for further doing.
Example #10
0
def makeDocument():
    u"""Make a new document."""
    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)

    view = doc.getView()
    view.padding = ViewPadding  # Aboid showing of crop marks, etc.
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPagePadding = True
    view.showElementOrigin = True
    view.showElementDimensions = False
    view.showTextOverflowMarker = False

    padding = 12

    # Get list of pages with equal y, then equal x.
    #page = doc[0][0] # Get the single page from te document.
    page = doc.getPage(
        0)  # Get page on pageNumber, first in row (this is only one now).
    page.name = 'Page 1'
    page.padding = padding

    BODY_FONT = 'BitcountMonoDouble-RegularCircle'

    fs = newFS('TYPETR',
               w=W - padding * 2,
               style=dict(font=BODY_FONT, fontSize=56, leading=0, textFill=0))
    fs += newFS("""\nPetr van Blokland
Designer|Lecturer|Developer

Rietveld 56 | 2611 LM Delft 
The Netherlands
Email [email protected]
typetr.typenetwork.com
Twitter @petrvanblokland
Mobile +31 6 2421 9502""",
                style=dict(font=BODY_FONT, fontSize=9, leading=0, textFill=0))

    e1 = newTextBox(
        fs,
        name='ElasticTextBox1',
        parent=page,
        font=BODY_FONT,
        pt=6,
        # And the condition that there should be no overflow, otherwise the text box
        # will try to solve it.
        conditions=[Left2Left(), Fit2Width(),
                    Float2TopSide()],
        # Position of the origin of the element. Just to show where it is.
        # Has no effect on the position conditions.
    )

    score = doc.solve()  # Try to solve all pages.
    if score.fails:
        print score.fails

    return doc  # Answer the doc for further doing.
Example #11
0
def main():
    #print _drawBotDrawingTool._tempInstalledFonts
    template = Template(w=W, h=H, padding=PADDING)

    doc = Document(title="sample", w=W, h=H, autoPages=1, originTop=False,
        pageTemplate=template, startPage=1)
    view = doc.getView()
    view.padding = 40

    page1 = doc[0]

    for ypos, ytch in enumerate(range(200, 800+1, 200)):
        for xpos, xtch in enumerate(range(200, 800+1, 200)):
            f = getVariableFont(FONT_PATH, location=dict(xtch=xtch, ytch=ytch))
            newText("我H", point=(70*xpos, 750-40*ypos), parent=page1, name="", font=f.installedName, fontSize=40)
    doc.solve()
    doc.export(EXPORT_PATH)
def makeDocument(families):
    u"""Create the main document in the defined size with a couple of automatic empty pages."""
    # Calculate the amount of pages to create
    numPages = 1  # Add one page for the original page scan.
    for family in families:
        numPages += len(family)  # Length of the family is the amount of fonts.
    numPages = min(numPages, MAX_PAGES - 1)

    doc = Document(w=W,
                   h=H,
                   title='Variable Font Sample Page',
                   originTop=False,
                   autoPages=numPages,
                   context=context,
                   gridX=GRID_X,
                   gridY=GRID_Y)

    pn = 1
    page = doc[pn]
    page.ch = 0  # No vertical grid
    page.padding = PADDING
    page.gridX = GRID_X
    newImage(ATF_PATH, x=0, y=0, w=W, parent=page)

    # Get default view from the document and set the viewing parameters.
    view = doc.view
    view.padding = inch(
        0.5)  # For showing cropmarks and such, make > mm(20) or inch(1).
    view.showPageCropMarks = True  # Won't show if there is not padding in the view.
    view.showPageFrame = SHOW_FRAMES  # No frame in case PAPER_COLOR exists to be shown.
    view.showPagePadding = SHOW_FRAMES  # No frame in case PAPER_COLOR exists to be shown.
    view.showPageRegistrationMarks = True
    view.showGrid = SHOW_GRID  # Show GRID_X lines
    view.showPageNameInfo = True  # Show file name and date of the document
    view.showTextOverflowMarker = False  # Don't show marker in case Filibuster blurb is too long.

    # Build the pages for all fonts that include one of these patterns.
    pn += 1
    for family in families[:1]:
        pn = buildSpecimenPages(doc, family, pn)
        if pn > MAX_PAGES:
            break

    doc.solve()

    return doc
def makeDocument(fontPath):
    u"""Make a new document."""

    f = Font(fontPath) # Get PageBot Font instance of Variable font.
   
    W = H = PageSize

    # Create a new document, default to the defined page size. 
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=1)
    
    view = doc.getView()
    view.padding = 0 # Aboid showing of crop marks, etc.
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPagePadding = True
    view.showElementOrigin = False
    view.showElementDimensions = False
    
    # Get list of pages with equal y, then equal x.    
    #page = doc[0][0] # Get the single page from te document.
    page = doc.getPage(0) # Get page on pageNumber, first in row (this is only one now).
    page.name = 'Page 1'
    page.padding = PagePadding
    
    fs = doc.context.newString(f.info.familyName + ' ' + f.info.styleName, 
                               style=dict(font=f.name,
                                          fontSize=18,
                                          textFill=0))
    _, th = textSize(fs)
    title = newTextBox(fs, conditions=[Top2Top(), Fit2Width()],
        parent=page, h=th*1.2)
    
    circle = VariableCircle(f, s=GLYPH_NAME, name='VariableCircleSpeciment',
        parent=page, padding=4, x=100, fontSize=64,
        maxW=W-2*PagePadding, minW=100, showAxisName=True,     
        # Conditions make the element move to top-left of the page.
        # And the condition that there should be no overflow, otherwise the text box
        # will try to solve it.     
        conditions=[Float2Top(), Fit2Bottom(), Center2Center()],
        # Position of the origin of the element. Just to show where it is.
        # Has no effect on the position conditions. 
        yAlign=BOTTOM, xAlign=LEFT, fill=CIRCLE_ELEMENT_FILL, borders=0,
    )
        
    score = doc.solve() # Try to solve all pages.
    if score.fails:
        print score.fails

    # To avoid circular dependent conditions, we correct the position of the title
    # on left to that the position of the circle has become.
    title.pl = circle.x - page.pl
    
    return doc # Answer the doc for further doing.
Example #14
0
def makeDocument(families):
    u"""Create the main document in the defined size with a couple of automatic empty pages."""
    # Calculate the amount of pages to create
    numPages = len(families) + 1  # One family per spread.

    doc = Document(w=W,
                   h=H,
                   title='Variable Font Sample Page',
                   originTop=False,
                   startPage=0,
                   autoPages=numPages,
                   context=context,
                   gridX=GRID_X,
                   gridY=GRID_Y)

    # Get default view from the document and set the viewing parameters.
    view = doc.view
    view.padding = inch(
        0.5)  # For showing cropmarks and such, make >=20*MM or INCH.
    view.showPageCropMarks = True  # Won't show if there is not padding in the view.
    view.showPageFrame = SHOW_FRAMES  # No frame in case PAPER_COLOR exists to be shown.
    view.showPagePadding = SHOW_FRAMES  # No frame in case PAPER_COLOR exists to be shown.
    view.showPageRegistrationMarks = True
    view.showGrid = SHOW_GRID  # Show GRID_X lines
    view.showPageNameInfo = True  # Show file name and date of the document
    view.showTextOverflowMarker = False  # Don't show marker in case Filibuster blurb is too long.

    # Build the pages for all fonts that include one of these patterns.
    for family in families:
        page = doc[1]
        page.ch = pt(0)  # No vertical grid
        page.padding = PADDING
        page.gridX = GRID_X
        newImage(FB_PATH_L, x=0, y=0, w=W / 2, parent=page)
        newImage(FB_PATH_R, x=W / 2, y=0, w=W / 2, parent=page)

        buildSpecimenPages(page, family)

    doc.solve()

    return doc
Example #15
0
def makeBanner(font):
    # Fit axes to select from: here we are showing the optical size.
    # Define tag list for axes to be part of the animation as sequence
    sequenceAxes = ['wdth']
    sequenceLength = 3 # Seconds per sequence
    sequences = len(sequenceAxes) # Amount of sequences, one per axis
    duration = sequenceLength * len(sequenceAxes) # Total duration of the animation in seconds
    framesPerSecond = 10
    frameCnt = duration * framesPerSecond # Total number of frames
    axisFrames = sequenceLength * framesPerSecond # Number of frames per axis sequence.

    # Create a new doc, with the right amount of frames/pages.
    doc = Document(w=W, h=H, originTop=False, frameDuration=1.0/framesPerSecond, 
        autoPages=frameCnt, context=c)
    # Sample text to show in the animation
    sample = 'Fitting' 

    frameIndex = 1 # Same as page index in the document
    for axisTag in sequenceAxes:

        minValue, defaultValue, maxValue = font.axes[axisTag]
        for axisFrameIndex in range(axisFrames):
            page = doc[frameIndex] # Get the current frame-page
            page.w = W

            axisRange = maxValue - minValue
            phisin = sin(radians(axisFrameIndex/axisFrames * 360+3/4*360))*0.5+0.5
        
            # Variable Font location for this frame sample
            location = {axisTag: phisin*axisRange+minValue}
            # Overall style for the frame
            style = dict(leading=em(1.4), fontSize=H-40, xTextAlign=RIGHT, textFill=whiteColor, 
                fill=blackColor, location=location)
        
            af = AnimatedBannerFrame(sample, font, frameCnt, frameIndex, parent=page, style=style, 
                w=page.pw, h=page.ph, context=c)
            frameIndex += 1 # Prepare for the next frame

    doc.solve()
    doc.export('_export/%s_%s.gif' % (font.info.familyName, sample))
Example #16
0
def makeDocument():
    """Make a new document."""

    W = H = PageSize

    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)

    view = doc.getView()
    view.padding = 40  # Aboid showing of crop marks, etc.
    view.showCropMarks = True
    view.showRegistrationMarks = True
    view.showFrame = False
    view.showPadding = False  # Table already has background color
    view.showOrigin = False
    view.showDimensions = False

    # Get list of pages with equal y, then equal x.
    #page = doc[1][0] # Get the single page from te document.
    page0 = doc.getPage(
        1)  # Get page on pageNumber, first in row (this is only one now).
    page0.name = 'Page 1'
    page0.padding = PagePadding

    t = newTable(cols=6,
                 rows=62,
                 borders=0.5,
                 parent=page0,
                 fill=color(0.85),
                 conditions=[Fit(), Overflow2Next()],
                 nextElement='nextTable',
                 nextPageName='Page 2')

    page1 = doc.getPage(1)
    page1.name = 'Page 2'
    page1.padding = PagePadding

    t = newTable(cols=0,
                 rows=0,
                 borders=0.5,
                 parent=page1,
                 name='nextTable',
                 fill=color(0.85),
                 conditions=[Fit()])

    score = doc.solve()  # Try to solve all pages.
    if score.fails:
        print(score.fails)

    #print(t.w, t.h, t.elements, t.borders)

    return doc  # Answer the doc for further doing.
Example #17
0
def makeDocument():
    # Creates the publication/document that holds the pages.
    doc = Document(w=W, h=H, originTop=False, autoPages=1)
    print(doc.view)
    print(doc.pages)

    doc.view.padding = 100  # Don't show cropmarks in this example.
    #doc.margin =
    doc.view.showPadding = True

    # Gets page by pageNumber, first in row (at this point there is only one in
    # this row).
    page = doc[1]
    page.padding = 1
    page.showPadding = True

    conditions = [Right2Right(), Float2Top(), Float2Left()]
    #conditions = [Right2Right(), Float2Top()]
    #conditions = [Left2Left()]
    #conditions = [Right2Right()]
    numberOfSquares = 8
    ratio = 1 / numberOfSquares
    rects = []

    for n in range(numberOfSquares):
        r = newRect(w=40,
                    h=42,
                    mr=4,
                    mt=4,
                    parent=page,
                    fill=color(1 - n * ratio, 0, 0.5),
                    conditions=conditions,
                    margin=0)
        rects.append(r)

    score = doc.solve()
    doc.build()

    from pagebot import getContext
    context = getContext()

    for r in rects:
        x = r.getFloatLeftSide() + doc.view.pr
        y = r.getFloatTopSide() + doc.view.pt
        context.fill((0, 1, 0))
        context.circle(x, y, 2)
def makeDocument():
    """Make a new document, using the rs as root style."""

    #W = H = 120 # Get the standard a4 width and height in points.
    W, H = PageSize

    # Create overall template, and set it in the document as default template for new pages.
    template = makeTemplate(W, H)

    doc = Document(title='Color Squares',
                   w=W,
                   h=H,
                   originTop=False,
                   autoPages=3,
                   defaultTemplate=template)

    view = doc.getView()
    view.padding = 0  # Don't show cropmarks in this example.

    # Get list of pages with equal y, then equal x.
    #page = [1][0] # Get the single page from the document.
    page0 = doc.getPage(
        1
    )  # Get page by pageNumber, first in row (there is only one now in this row).

    # Overwrite the default template by another template (in this case with different color).
    # Note that this way it is possible to mix different page sizes in one document.
    # The elements are copied from the template page, so not reference to the
    # original elenents remains in the page after thhe apply.
    # Note that also the apply will remove all previous element from the page,
    # so the order is important: first apply a new template, then add elements
    # to a specific page.
    page1 = doc.getPage(1)
    page1.applyTemplate(makeTemplate(W, H, True))

    # Recursively solve the conditions in all pages.
    # If there are failing conditions, then the status is returned in the Score instance.
    score = doc.solve()
    if score.fails:
        print(score.fails)

    return doc  # Answer the doc for further doing.
def makeDocument(font):
    u"""Create the main document in the defined size with a couple of automatic empty pages."""

    # Build 4 pages, two for the original scan, the two for the generated version.
    doc = Document(w=W,
                   h=H,
                   title='Variable Font Sample Page',
                   originTop=False,
                   context=context,
                   gridX=GRID_X,
                   fontSize=24)

    # Get default view from the document and set the viewing parameters.
    view = doc.view
    view.padding = 0  # For showing cropmarks and such, make > mm(20) or inch(1).
    view.showCropMarks = True  # Won't show if there is not padding in the view.
    view.showFrame = SHOW_FRAMES  # No frame in case PAPER_COLOR exists to be shown.
    view.showPadding = SHOW_FRAMES  # No frame in case PAPER_COLOR exists to be shown.
    view.showRegistrationMarks = True
    view.showOrigin = True  # Show position of xAlign and yAlign
    view.showBaselines = set([BASE_LINE, BASE_INDEX_LEFT])
    view.showGrid = DEFAULT_GRID  # Show GRID_X lines
    view.showInfo = True  # Show file name and date of the document
    view.showTextOverflowMarker = False  # Don't show marker in case Filibuster blurb is too long.

    page = doc[1]
    # During development, draw the template scan as background
    # Set z-azis != 0, to make floating elements not get stuck at the background
    page.padding = {True: PADDING_LEFT, False: PADDING_RIGHT}[page.isLeft]
    page.bleed = pt(6)
    if SHOW_TEMPLATE:
        newImage(BERTHOLD_PATH, index=1, parent=page, conditions=[Fit2Sides()])
    else:
        newRect(parent=page,
                fill=PAPER_COLOR,
                yAlign=BOTTOM,
                conditions=[Fit2Bleed()])
    makePage1(page, sampleFont)

    print(doc.solve())

    return doc
Example #20
0
def makeDocument():
    # Creates the publication/document that holds the pages.
    doc = Document(w=W, h=H, originTop=False, autoPages=1)
    doc.view.padding = 0  # Don't show cropmarks in this example.
    doc.view.showPadding = True

    # Gets page by pageNumber, first in row (at this point there is only one in
    # this row).
    page = doc[1]
    page.padding = 30

    conditions = [Right2Right(), Float2Top(), Float2Left()]
    # TODO: Solve this bug, does not mirror.
    #conditions = [Left2Left(), Float2Top(), Float2Right()]

    for n in range(32):
        newRect(w=40,
                h=42,
                mr=4,
                mt=4,
                parent=page,
                fill=color(random() * 0.5 + 0.5, 0, 0.5),
                conditions=conditions)

    # Recursively solve the conditions in all pages.
    # If there are failing conditions, then the status
    # is returned in the Score instance.
    score = doc.solve()
    if score.fails:
        print(score.fails)

    doc.export(EXPORT_PATH_SVG)
    doc.export(EXPORT_PATH_JPG)
    doc.export(EXPORT_PATH_PNG)
    doc.export(EXPORT_PATH_PDF)

    print('Done making document %s' % doc)
Example #21
0
def makeDocument():
    u"""Make a new document."""

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

    page = doc[0]  # Get the single page from te document.

    # Hard coded padding, just for simple demo, instead of filling padding an
    # columns in the root style.
    page.padding = SQ

    # Position square in the 4 corners of the page area.
    # Notice that their alignment (left) does not matter for the conditions.
    cornerConditions = [(Float2Right(), Float2Top()),
                        (Float2Right(), Float2Bottom()),
                        (Float2Left(), Float2Bottom()),
                        (Float2Left(), Float2Top())]
    z = 1
    for condition in cornerConditions:
        newRect(z=z, w=SQ, h=SQ, parent=page, conditions=condition, fill=0.7)
        z += 1
    # Make new container for adding elements inside with alignment.
    #cnt = newRect(z=z, w=W-2*SQ, h=H-2*SQ, fill=(0.8, 0.8, 0.8, 0.4),
    #              parent=page, margin=SQ, yAlign=BOTTOM,
    #              xAlign=CENTER, stroke=None,
    #              conditions=(Center2Center(), Middle2Middle()))
    z += 1
    newRect(z=z,
            w=SQ,
            h=SQ,
            stroke=None,
            parent=page,
            xAlign=CENTER,
            conditions=(Center2Center(), Middle2Middle()),
            fill=(1, 0, 0))
    z += 1

    # Side conditions

    conditions = [(Center2Center(), Float2Top()),
                  (Center2Center(), Float2Bottom()),
                  (Float2Left(), Middle2Middle()),
                  (Float2Right(), Middle2Middle())]
    for condition in conditions:
        newRect(z=z,
                w=SQ,
                h=SQ,
                stroke=None,
                parent=page,
                xAlign=CENTER,
                conditions=condition,
                fill=(1, 1, 0))
        z += z

    sideConditions = [(Center2Center(), Float2TopSide()),
                      (Center2Center(), Float2BottomSide()),
                      (Float2LeftSide(), Middle2Middle()),
                      (Float2RightSide(), Middle2Middle())]
    for condition in sideConditions:
        newRect(z=z,
                w=SQ,
                h=SQ,
                stroke=None,
                parent=page,
                xAlign=CENTER,
                conditions=condition,
                fill=(0.5, 1, 0))
        z += 1

    cornerConditions = [(Float2LeftSide(), Float2TopSide()),
                        (Float2RightSide(), Float2TopSide()),
                        (Float2LeftSide(), Float2BottomSide()),
                        (Float2RightSide(), Float2BottomSide())]
    for condition in cornerConditions:
        newRect(z=z,
                w=SQ,
                h=SQ,
                stroke=None,
                parent=page,
                xAlign=CENTER,
                conditions=condition,
                fill=(0, 0, 1))
        z += 1

    # Solve the layout placement conditions on the pages of doc by moving the
    # elements that are not on the right positions (which is all of them,
    # because we did not add point attributes when creating them.
    score = doc.solve()  # Solves all document. page.solve() only solves page.
    if score.fails:
        print('Failed to solve %d conditions:' % len(score.fails))
    for condition, e in score.fails:
        print(e.bottom2BottomSide())
        print(condition, e, e.bottom,
              Bottom2BottomSide().test(e), e.isBottomOnBottomSide(), e.bottom)

    view = doc.getView()
    view.w, view.h = W, H
    view.padding = 40  # Don't show cropmarks and such.
    view.showElementOrigin = ShowOrigins  # Show origin alignment
    # markers on each element.
    view.showElementDimensions = ShowDimensions
    view.showPageFrame = True
    view.showPagePadding = True
    view.showPageCropMarks = True
    view.showElementInfo = ShowElementInfo  # Show baxes with element info

    return doc  # Answer the doc for further doing.
Example #22
0
context = getContext()
print(context)

W = H = 1000  # Document size
PADDING = 100  # Page padding on all sides. Select value and cmd-drag to change interactive.

font = findFont('PageBot-Bold')
#print(font)

style = dict(font=font, fontSize=24, leading=em(1.4), textFill=0.3)
# Make long text to force box overflow
t = context.newString(text, style=style)
# Create a new document with 1 page. Set overall size and padding.
doc = Document(w=W, h=H, padding=PADDING, context=context, originTop=False)
# Get the default page view of the document and set viewing parameters
view = doc.view
# Show the usable space (=page.padding) of the page, which the same as the box after fitting
view.showPadding = True
view.showOrigin = True
view.showTextOverflowMarker = True
# Get the first (and only automatic created) page of the document
page = doc[1]
# Make text box as child element of the page and set its layout conditions
# to fit the padding of the page.
# Text overflows the edge of the text box, but currently we cannot see that.
tb = newTextBox(t, parent=page, yAlign=TOP, showFrame=True, conditions=[Fit()])
# Solve the page/element conditions
doc.solve()
# Export the document to this PDF file.
doc.export('_export/SingleColumn.pdf')
Example #23
0
def makeDocument():
    """Make a new document."""

    W = H = PageSize

    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)

    view = doc.getView()
    print(view.viewId, doc.views)
    view.padding = 30  # Avoid showing of crop marks, etc. when value = 0
    view.showCropMarks = True
    view.showRegistrationMarks = True
    view.showFrame = True
    view.showPadding = True
    view.showOrigin = True
    view.showDimensions = False
    view.showElementInfo = False

    # Get list of pages with equal y, then equal x.
    #page = doc[1][0] # Get the single page from te document.
    page0 = doc.getPage(
        1)  # Get page on pageNumber, first in row (this is only one now).
    page0.name = 'Page 1'
    page0.padding = PagePadding

    s = ''
    for n in range(10):
        s += '(Line %d) Volume of text defines the box height. Volume of text defines the box height. \n' % (
            n + 1)
    if DoTextFlow:
        h1 = 120  # Fox on a given height, to show the text flowing to the e2 element.
    else:
        h1 = None

    e1 = newTextBox(
        s,
        name='ElasticTextBox1',
        nextElement='ElasticTextBox2',  # Overflow goes here.
        parent=page0,
        padding=4,
        x=100,
        w=BoxWidth,
        font='Verdana',
        h=h1,
        mb=20,
        mr=10,  # Conditions make the element move to top-left of the page.
        # And the condition that there should be no overflow, otherwise the text box
        # will try to solve it.
        conditions=[Left2Left(), Float2Top(),
                    Overflow2Next()],
        # Position of the origin of the element. Just to show where it is.
        # Has no effect on the position conditions.
        yAlign=BOTTOM,
        xAlign=LEFT,
        leading=em(1.4),
        fontSize=pt(9),
        textFill=blackColor,
        fill=0.9,  # Renders to color
        stroke=noColor,
        strokeWidth=pt(0.5))
    e2 = newTextBox(
        '',  # Empty box, will get the overflow from e1, if there is any.
        name='ElasticTextBox2',  # Flow reference by element.name
        nextElementName='ElasticTextBox3',
        nextPageName='Page 2',
        parent=page0,
        padding=4,
        x=100,
        w=BoxWidth,
        h=200,
        conditions=[Right2Right(),
                    Float2Top(),
                    Fit2Bottom(),
                    Overflow2Next()],
        yAlign=TOP,
        fill=whiteColor,
        stroke=noColor,
    )
    # Get next page, to show flow running over page breaks.
    page1 = doc[1]
    page1.name = 'Page 2'
    page1.padding = PagePadding

    e3 = newTextBox(
        '',  # Empty box, will get the overflow from e2, if there is any.
        name='ElasticTextBox3',  # Flow reference by element.name
        parent=page1,
        padding=4,
        w=BoxWidth,
        conditions=[Right2Right(), Float2Top(),
                    Fit2Bottom()],
        yAlign=TOP,
        fill=whiteColor,
        stroke=noColor)

    score = doc.solve()  # Try to solve all pages.
    if score.fails:
        print(score.fails)

    return doc  # Answer the doc for further doing.
               name='main12',
               h=1200,
               w=CW1,
               parent=main1,
               fill=0.95,
               conditions=(Right2Right(), Float2Top()))
'''
if 1:
    # Main article as group of 3 text boxes
    main2 = newRect(parent=page, w=CW4, mt=G, fill=0.8, conditions=(Left2Left(), Float2Top()))

    bs = context.newString('Headline main 2', style=headline1Style)
    tw, th = bs.size
    newTextBox(bs, name='head2', parent=main2, conditions=(Left2Left(), Fit2Width(), Float2Top()))

    bs = context.newString('Aaaa ' * 120, style=mainStyle)
    newTextBox(bs, name='main21', h=400, w=CW2, parent=main2, fill=0.8, mt=3*G,
        conditions=(Left2Left(), Float2Top()))
    bs = context.newString('Aaaa ' * 120, style=mainStyle)
    newTextBox(bs, name='main22', h=400, w=CW2, parent=main2, fill=0.8, mt=3*G, 
        conditions=(Right2Right(), Float2Top()))

'''
doc.solve()  # Drill down to solve all elements conditions.

# =============================================================================
#    Export to PDF or other file formats
# .............................................................................

doc.export('_export/TheVariableGlobe.pdf')
Example #25
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 = 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 = (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 = c.newString('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 = c.newString(labelFont.info.familyName.upper(), style=dict(font=boldName, textFill=paperColor, 
        fontSize=fontNameSize, tracking=0, rTracking=0.3))
    tw, th = fs.textSize()
    # 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 = c.newString(foundryName.upper(), style=dict(font=boldName, textFill=0, 
        fontSize=fontNameSize, tracking=0, rTracking=0.3))
    tw, th = fs.textSize()
    # 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 = c.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(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 = c.newString(caps, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, 
        leading=glyphSetLeading, tracking=0, rTracking=glyphTracking))
    fs += c.newString(lc, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, 
        leading=glyphSetLeading, tracking=0, rTracking=glyphTracking))

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

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

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

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

    fs += c.newString(punctuations, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, 
        leading=glyphSetLeading, tracking=0, rTracking=glyphTracking))
    if bookName != bookItalicName:
        fs += c.newString(punctuations + '\n', style=dict(font=bookItalicName, textFill=0, 
            fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking))
    else:
        fs += '\n'
        
    if bookName != boldName:
        fs += c.newString(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 = c.newString(labelFont.info.familyName.upper(), style=dict(font=boldName, textFill=paperColor, 
        fontSize=fontNameSize, tracking=0, rTracking=0.3))
    tw, th = fs.textSize()
    # 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 = c.newString(foundryName.upper(), style=dict(font=boldName, textFill=0, fontSize=fontNameSize, tracking=0, rTracking=0.3))
    tw, th = fs.textSize()
    # 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 = c.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(fs, parent=page, x=leftPadding, w=50*MM, h=30*MM)
    tbSpec6.top = tbFoundry.bottom - 8*MM

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

    fs = c.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(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 = c.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(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 = c.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(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 = c.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(fs, parent=page, x=page.pl, w=page.w - page.pl - page.pr)
    tbCaptionTotal.top = tbSpec8.bottom - MM
    
    # Page number
    fs = c.newString(`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 = c.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(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 = c.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(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 = c.newString(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 = c.newString(labelFont.info.styleName.upper(), style=dict(font=boldName, textFill=paperColor, 
        fontSize=fontNameSize, tracking=0, rTracking=0.3))
    tw, th = fs.textSize()
    # 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 = c.newString(`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 = c.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(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 = c.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(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 = c.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(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 = c.newString('10.5pt', style=dict(font=boldName, textFill=paperColor, 
        fontSize=fontNameSize, tracking=0, rTracking=0.3))
    tw, th = fs.textSize()
    # 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 = c.newString(`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 = c.newString(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 = c.newString(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 = c.newString(labelFont.info.styleName.upper(), style=dict(font=boldName, textFill=paperColor, 
        fontSize=fontNameSize, tracking=0, rTracking=0.3))
    tw, th = fs.textSize()
    # 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 = c.newString(`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.
Example #26
0
# Get page by pageNumber, first in row (there is only one now in this row).
page = doc[0]
page.padding = 30

conditions = [Right2Right(), Float2Top(), Float2Left()]
# TODO: Solve this bug, does not mirror.
#conditions = [Left2Left(), Float2Top(), Float2Right()]

for n in range(32):
    newRect(w=40,
            h=42,
            mr=4,
            mt=4,
            parent=page,
            fill=(random() * 0.5 + 0.5, 0, 0.5),
            conditions=conditions)

# Recursively solve the conditions in all pages.
# If there are failing conditions, then the status
# is returned in the Score instance.
score = doc.solve()
if score.fails:
    print(score.fails)

doc.export(EXPORT_PATH_SVG)
doc.export(EXPORT_PATH_JPG)
doc.export(EXPORT_PATH_PNG)
doc.export(EXPORT_PATH_PDF)

print('Done')
Example #27
0
from pagebot.constants import HalfLetter
from pagebot.toolbox.color import blackColor, color

W, H = HalfLetter

class VariableFontPlay(Element):
    """This element will show a summery of VF functions. 
    Including but not limited to showing file size as an 
    animation in relation to several axes, such as width 
    and weight."""

from pagebot.document import Document 
document = Document(w=W, h=H, originTop=False)
view = document.view 
view.padding = 30
view.showCropMarks = True
view.showRegistrationMarks = True
view.showPadding = True
view.showFrame = True
view.showNameInfo = True
view.showPageMetaInfo = True
page = document[1]
page.padding = 30
vfp = VariableFontPlay(fill=blackColor, parent=page, padding=20, conditions=[Top2Top(), Left2Left(), Fit()])
for n in range(4):
    newRect(parent=vfp, w=30, h=40, margin=10, fill=color(1,0,0), stroke=0,  conditions=[Right2Right(), Bottom2Bottom(), Float2Left(), Float2Top()])
document.solve()


document.export("_export/VariableFontPlay.png")
Example #28
0
def makeDocument():
    """Make a new document."""

    W = H = PageSize

    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)

    rs = doc.getRootStyle()
    rs['fill'] = (1, 1, 0)  # Yellow background for debugging
    rs['font'] = 'Verdana'
    rs['fontSize'] = 14
    rs['textFill'] = 1

    #textBoxStyle = doc.addStyle('textbox', dict(fill=color(0, 0, 0, 0.7),
    #                                            padding=40))
    pStyle = doc.addStyle('p', dict(textFill=blackColor))
    h1Style = doc.addStyle('h1', dict(fontSize=24, textFill=(0, 0, 1)))
    #h2Style = doc.addStyle('h2', dict(fontSize=18, textFill=(0, 1, 0)))

    view = doc.getView()
    view.padding = 0  # Aboid showing of crop marks, etc.
    view.showCropMarks = True
    view.showRegistrationMarks = True
    view.showFrame = True
    view.showPadding = True
    view.showOrigin = True
    view.showDimensions = False

    # Get list of pages with equal y, then equal x.
    #page = doc[1][0] # Get the single page from the document.
    page0 = doc.getPage(1)  # Get page on pageNumber,
    # first in row (this is only one now).
    page0.name = 'Page 1'
    page0.padding = PagePadding

    s = doc.context.newString('Headline\n', style=h1Style)
    for n in range(10):
        s += doc.context.newString(('(Line %d) Volume of text defines'
                                    ' the box height.'
                                    ' Volume of text defines'
                                    ' the box height. \n') % (n + 1),
                                   style=pStyle)
        h1 = None

    e1 = newTextBox(
        s,
        name='CSSTextBox1',
        parent=page0,
        padding=4,
        x=100,
        font='Verdana',
        h=h1,
        mb=20,
        mr=10,  # Conditions make the element
        # move to top-left of the page.
        gridX=((fr(3), px(8)), (fr(2), px(8))),
        # And the condition that there should be no overflow,
        # otherwise the text box will try to solve it.
        conditions=[Left2Left(), Fit2Width(),
                    Float2Top()],
        # Position of the origin of the element.
        # Just to show where it is.
        # Has no effect on the position conditions.
        yAlign=BOTTOM,
        xAlign=LEFT,
        leading=5,
        fontSize=9,
        textFill=blackColor,
        strokeWidth=pt(0.5),
        fill=color(0.9),
        stroke=noColor)
    print(e1.style)

    newTextBox(
        s,  # Empty box, will get the overflow
        # from e1, if there is any.
        name='CSSTextBox2',  # Flow reference by element.name
        parent=page0,
        padding=4,
        x=100,
        h=200,
        conditions=[Left2Left(), Fit2Width(),
                    Float2Top()],
        yAlign=TOP,
        fill=whiteColor,
        stroke=noColor)

    score = doc.solve()  # Try to solve all pages.
    if score.fails:
        print(score.fails)

    return doc  # Answer the doc for further doing.
Example #29
0
M = pt(8)  # Margin between the images

EXPORT_PATH = '_export/CacheScaledImage.pdf'

if __name__ == '__main__':

    # Define the path where to find the example image.
    path = getResourcesPath() + "/images/cookbot1.jpg"
    # Use the standard DrawBot function to get the width/height of the image from the file.
    doc = Document(
        w=W, h=1.35 * H, originTop=False,
        context=context)  # New simple document with default padding.

    page = doc[1]  # Get first (and only) automatic page.
    factor = 1  # Incremental scale division factor of the image width.

    for n in range(12):  # Stop before they become invisible small
        # Create a range of scaled imaged that try to fit by floating conditions.
        newImage(path,
                 w=page.pw / factor,
                 mr=M,
                 mb=M,
                 parent=page,
                 conditions=(Right2Right(), Float2Top(), Float2Left()),
                 scaleImage=False)
        factor *= 1.6

    doc.solve()  # Solve the fitting of the scaled images on the page.

    doc.export(EXPORT_PATH)
Example #30
0
def makeDocument():
    u"""Make a new document."""

    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)
    c = doc.context

    view = doc.getView()
    view.padding = 30 # Aboid showing of crop marks, etc.
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPagePadding = True
    view.showElementOrigin = True
    view.showElementDimensions = False
    view.showElementInfo = False

    # Get list of pages with equal y, then equal x.
    #page = doc[1][0] # Get the single page from te document.
    page0 = doc.getPage(1) # Get page on pageNumber, first in row (this is only one now).
    page0.name = 'Page 1'
    page0.padding = PagePadding

    s = c.newString('', style=dict(font='Verdana', fontSize=10, textFill=0))
    for n in range(10):
        s += c.newString(('(Line %d) '
                          'Volume of text defines the box height.') % (n+1),
                         style=dict(fontSize=10+n*2, textFill=0))
        s += c.newString('Volume', style=dict(textFill=(1, 0, 0),
                                              font='Verdana',
                                              fontSize=10+n*2))
        s += c.newString(' of text defines the box height. \n',
                         style=dict(textFill=0,
                                    font='Verdana',
                                    fontSize=10+n*2))
    e1 = newTextBox(s, parent=page0, padding=4, x=100,
                    w=BoxWidth, font='Verdana', h=None,
                    maxW=W-2*PagePadding, minW=100, mb=20, mr=10,
                    #Conditions make the element move to top-left of the page.
                    # And the condition that there should be no overflow,
                    # otherwise the text box will try to solve it.
                    conditions=[Left2Left(),
                                Float2Top(),
                                Overflow2Next()],
                    #Position of the origin of the element. Just to show
                    # where it is. Has no effect on the position conditions.
                    yAlign=BOTTOM, xAlign=LEFT,
                    leading=5, fontSize=9, textFill=0,
                    strokeWidth=0.5, fill=0.9, stroke=None)
    """
    for line in e1.textLines:
        print(line, line.x, line.y)
    for foundPattern in e1.findPattern('Line 5'):
        print(foundPattern.x, foundPattern.y, foundPattern.line, foundPattern.line.runs)
    """
    font = getFontByName(e1.textLines[0].runs[1].displayName)
    char = 'hyphen'
    g = font[char]
    print(g.pointContexts[0].p.x)
    c.save()
    c.scale(0.3)
    path = font[char].path
    c.fill(1, 0, 0)
    c.drawPath(path)
    ga = GlyphAnalyzer(font, char)
    for x, vertical in ga.verticals.items():
        c.stroke(0)
        c.strokeWidth(1)
        c.fill(None)
        c.line((x, 0), (x, 3000))
    print(ga.horizontals    )
    for y, horizontal in ga.horizontals.items():
        c.stroke(0)
        c.strokeWidth(1)
        c.fill(None)
        c.line((0, y), (2000, y))
    c.restore()
    """
    for contour in ga.glyph.pointContexts:
        path = BezierPath()
        for index, pc in contour.items():
            p = pc[3]
            if index == 0:
                path.moveTo((p.x/2, p.y/2))
            else:
                path.lineTo((p.x/2, p.y/2))
        path.closePath()
        c.fill(0)
        c.drawPath(path)
            #c.oval(p.x/2, p.y/2, 4, 4)
            #print(index, pc   )
    """
    score = doc.solve() # Try to solve all pages.
    if score.fails:
        print(score.fails)

    return doc # Answer the doc for further doing.