Example #1
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 #2
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 #3
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 #4
0
def makeDocument():
    u"""Make a new document."""

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

    # Hard coded SQUARE and GUTTE, just for simple demo, instead of filling padding an columns in the root style.
    # Page size decides on the amount squares that is visible.
    # Page padding is centered then.
    sqx = int(W/(SQUARE + GUTTER)) # Whole amount of squares that fit on the page.
    sqy = int(H/(SQUARE + GUTTER))
    # Calculate centered paddings for the amount of fitting squares.
    # Set values in the rootStyle, so we can compare with column calculated square position and sizes.
    #rs['colH'] = rs['colW'] = SQUARE  # Make default colW and colH square.

    #padX = (W - sqx*(SQUARE + GUTTER) + GUTTER)/2
    my = (H - sqy*(SQUARE + GUTTER) + GUTTER)/2

    doc = Document(w=W, h=H, originTop=False, title='Color Squares', autoPages=1)
    
    view = doc.getView()
    view.padding = 0 # Aboid showing of crop marks, etc.
    view.showElementOrigin = True
    
    # 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 = 'This is a demo page for floating child elements'
    page.padding = PagePadding
    
    page.gutter3D = GUTTER # Set all 3 gutters to same value

    im = newImage('images/cookbot10.jpg', (50, 50, 10), padding=0, parent=page, w=200, h=300,
        conditions=(Top2Top(), Fit2Width(), SolveBlock(), Shrink2BlockBottom()), 
        yAlign=BOTTOM, fill=(0, 1, 0, 0.3), stroke=(1, 0, 0)
    )
    # Give parent on creation, to have the css chain working.
    
    # Caption falls through the yr2 (with differnt z) and lands on yr1 by Float2BottomSide()    
    fs = doc.context.newString('Captions float below the image',
                               style=dict(font='Verdana',
                                          fontSize=20,
                                          textFill=1))
    cap = newTextBox(fs, name='Caption', parent=im, z=0,
        conditions=[ Fit2Width(), Float2Top()], 
        padding=4, font='Verdana', 
        yAlign=TOP, fontSize=9, textFill=1, strokeWidth=0.5, 
        fill=(0, 0, 1, 0.3), stroke=(0, 0, 1),
    )
    score = page.solve()
    if score.fails:
        print score.fails

    print im.h
    for e in im.elements:
        print e.h

    return doc # Answer the doc for further doing.
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(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.
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 #8
0
def makeDocument():
    """Make a new document."""

    W = H = PageSize

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

    view = doc.getView()
    view.padding = pt(0) # Aboid showing of crop marks, etc.
    view.showOrigin = False
    view.showTextOverflowMarker = False

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

    # Show margin of page, can also be done by
    # view.showPadding = True
    newRect(fill=color(0.9), parent=page, margin=0,
            conditions=(Left2Left(), Fit2Right(), Bottom2Bottom(), Fit2Height()))

    redContainer = newRect(fill=color(1, 0, 0), pb=pt(10), w=RedSize, h=RedSize, padding=pt(10),
                           conditions=(Left2Left(), Bottom2Bottom()), parent=page)

    # Yellow square
    yellowSquare = newRect(fill=color(1, 1, 0), z=pt(8), w=YellowSize,
                           h=YellowSize, parent=redContainer, xAlign=CENTER, yAlign=TOP,
                           conditions=(Center2Center(), Bottom2Bottom()))

    # Blue square in different z=layer. No interaction with Floating on other z-layers.
    blueSquare = newRect(fill=color(0, 1, 1), z=10, w=50, h=50,
                         parent=redContainer, xAlign=CENTER,
                         conditions=(Top2Top(), Center2Center()))

    # Centered string
    fs = doc.context.newString('Float on top of yellow',
                               style=dict(font='Verdana',
                                          fontSize=7,
                                          xTextAlign=CENTER,
                                          textFill=blackColor))
    # Text falls through the yr2 (with differnt z) and lands on yellowSquare by Float2SideBottom()
    newTextBox(fs, name='Caption', parent=redContainer, z=8,
               fill=color(0, 1, 0), strokeWidth=0.5, stroke=color(1, 1, 0),
               conditions=[Fit2Width(), Float2SideBottom()], padding=3)
    score = page.solve()
    if score.fails:
        print(score.fails)

    return doc # Answer the doc for further doing.
Example #9
0
def makeDocument():
    u"""Make a new document."""

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

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

    view = doc.getView()
    view.padding = 40  # Aboid showing of crop marks, etc.
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = 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.
    page = doc.getPage(
        0)  # Get page on pageNumber, first in row (this is only one now).
    page.name = 'This is a demo page for floating child elements'

    PATH = u"/Library/Fonts/Georgia.ttf"
    f = Font(PATH, install=False)
    #pathFilter = None
    glyphName = 'e'  #'cid05405.1'

    e1 = GlyphPath(f[glyphName],
                   stroke=None,
                   h=600,
                   fill=None,
                   pathFilter=pathFilter,
                   parent=page,
                   font='Verdana',
                   conditions=[Left2Left(), Float2Top()])

    score = page.solve()
    if score.fails:
        print score.fails
    e1.y += 100
    #e2.y += 100

    return doc  # Answer the doc for further doing.
Example #10
0
def makeDocument():
    u"""Make a new document."""

    #W = H = 120 # Get the standard a4 width and height in points.
    #W = PageSize
    #H = PageSize
    W, H = A4
    # Hard coded SQUARE and GUTTE, just for simple demo, instead of filling padding an columns in the root style.
    # Page size decides on the amount squares that is visible.
    # Page padding is centered then.
    sqx = int(
        W / (SQUARE + GUTTER))  # Whole amount of squares that fit on the page.
    sqy = int(H / (SQUARE + GUTTER))
    # Calculate centered paddings for the amount of fitting squares.
    # Set values in the rootStyle, so we can compare with column calculated square position and sizes.
    #rs['colH'] = rs['colW'] = SQUARE  # Make default colW and colH square.

    #padX = (W - sqx*(SQUARE + GUTTER) + GUTTER)/2
    my = (H - sqy * (SQUARE + GUTTER) + GUTTER) / 2

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

    view = doc.view  # Get the current view of the document.
    view.padding = 40  # Aboid showing of crop marks, etc.
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = 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.
    page = doc.getPage(
        0)  # Get page on pageNumber, first in row (this is only one now).
    page.name = 'This is a demo page for floating child elements'
    page.padding = PagePadding

    page.gutter3D = GUTTER  # Set all 3 gutters to same value

    if BoxWidths < 200:
        tColor = (1, 0, 0)
    else:
        tColor = (0, 0, 1)

    s = ''
    for n in range(10):
        s += '(%d) Volume of text defines the box height.\n' % (n + 1)
    if DoTextFlow:
        h1 = 100
    else:
        h1 = None
    e1 = newTextBox(
        s,
        name='ElasticTextBox1',
        parent=page,
        padding=4,
        x=100,
        w=BoxWidth,
        font='Verdana',
        h=h1,
        maxW=W - 2 * PagePadding,
        conditions=[Left2Left(), Float2Top()],
        yAlign=BOTTOM,
        xAlign=LEFT,
        leading=5,
        fontSize=9,
        textFill=tColor,
        strokeWidth=0.5,
        fill=0.9,
        stroke=None,
    )
    e2 = newTextBox(
        s,
        name='ElasticTextBox2',
        parent=page,
        padding=4,
        x=100,
        w=BoxWidth,
        font='Verdana',
        maxW=W - 2 * PagePadding,
        conditions=[Right2Right(), Float2Top()],
        yAlign=TOP,
        leading=5,
        fontSize=9,
        textFill=0.9,
        strokeWidth=0.5,
        fill=tColor,
        stroke=None,
    )

    score = page.solve()
    if score.fails:
        print score.fails

    return doc  # Answer the doc for further doing.
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.view
    c = view.context
    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

    bs = c.newString('')
    for n in range(10):
        bs += c.newString('(Line %d) ' % (n + 1),
                          style=dict(font='Verdana-Bold',
                                     fontSize=9,
                                     leading=10,
                                     textFill=0))
        bs += c.newString(
            'Volume of text defines the box height. Volume of text defines the box height. \n',
            style=dict(font='Verdana', fontSize=9, leading=10, textFill=0))

    if DoTextFlow:
        h1 = 120  # Fox on a given height, to show the text flowing to the e2 element.
    else:
        h1 = None

    e1 = newTextBox(
        bs,
        name='ElasticTextBox1',
        nextElement='ElasticTextBox2',  # Overflow goes here.
        parent=page0,
        padding=4,
        x=100,
        w=BoxWidth,
        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(), 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,
        strokeWidth=0.5,
        fill=0.9,
        stroke=None,
    )
    e2 = newTextBox(
        '',  # Empty box, will get the overflow from e1, if there is any.
        name='ElasticTextBox2',  # Flow reference by element.name 
        nextElement='ElasticTextBox3',
        nextPage='Page 2',
        parent=page0,
        padding=4,
        x=100,
        w=BoxWidth,
        h=200,
        maxW=W - 2 * PagePadding,
        minW=100,
        conditions=[Right2Right(),
                    Float2Top(),
                    Fit2Bottom(),
                    Overflow2Next()],
        yAlign=TOP,
        fill=1,
        stroke=None,
    )
    # 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,
        maxW=W - 2 * PagePadding,
        minW=100,
        conditions=[Right2Right(), Float2Top(),
                    Fit2Bottom()],
        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 #12
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.
Example #13
0
def makeDocument(rs):
    u"""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

    # Hard coded SQUARE and GUTTE, just for simple demo, instead of filling padding an columns in the root style.
    # Page size decides on the amount squares that is visible.
    # Page padding is centered then.
    sqx = int(W/(SQUARE + GUTTER)) # Whole amount of squares that fit on the page.
    sqy = int(H/(SQUARE + GUTTER))
    # Calculate centered paddings for the amount of fitting squares.
    # Set values in the rootStyle, so we can compare with column calculated square position and sizes.
    rs['ch'] = rs['cw'] = SQUARE  # Make default column width and column height square.

    padX = (W - sqx*(SQUARE + GUTTER) + GUTTER)/2
    my = (H - sqy*(SQUARE + GUTTER) + GUTTER)/2


    doc = Document(w=W, h=H, rootStyle=rs, originTop=False, title='Color Squares', autoPages=1)
    
    view = doc.getView()
    
    view.showElementOrigin = ElementOrigin
    view.showPageCropMarks = CropMarks
    view.showPageRegistrationMarks = RegistrationMarks
    view.showPageFrame = PageFrame
    view.showPageNameInfo = PageNameInfo
    view.padding = ViewPadding # Space around the view to accommodate cropmarks and registration marks.

    # 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 = 'This demo page'
    
    page.w = W
    page.h = H
 
    page.padding3D = padX # Set all 3 paddings to same value
    page.gutter3D = GUTTER # Set all 3 gutters to same value

    for ix in range(sqx): # Run through the range of (0, 1, ...) number of horizontal squares
        for iy in range(sqy): # Same with vertical squares  
            # Place squares in random colors
            color1 = (0.1, random(), 0.6)
            color2 = (0.1, random(), 0.6)
            # Create Rect object and place it in the page on column/row index posiition
            e = newColRect(ix, iy, 1, 1, parent=page, fill=color1, stroke=None) 
            # Create Rect object and place it in the page on the same column/row index position.
            newColOval(ix, iy, 1, 1, parent=page, fill=color2, stroke=None)    
            # Now drawing with point coordinates needs to align with the column positions. 
            # Test by drawing a rectangle on the same position.        
            # No need to draw the origin marker of each element. That is done by the style flag
            # showElementOrigin = True
            p = padX + ix * (SQUARE + GUTTER), my + iy * (SQUARE + GUTTER) # Make 2-dimensional point tuple.
            newRect(p, w=SQUARE, h=SQUARE, parent=page, fill=None, stroke=0, strokeWidth=0.5)
            # Show coordinate and column/row index value. Don't show origin of the text box, by resetting
            # its style flag showElementOrigin=False 
            newText('%d, %d Column: %d, %d' % (p[0], p[1], 
                x2cx(p[0], e), # Calculate back to column index for checking.
                y2cy(p[1], e)), 
                (p[0], p[1] + e.css('colH') + e.gh/4), # Position of the coordinate with a bit of offset.
                parent=page, textFill=0, fontSize=4, leading=0, 
                fill=None, stroke=None)

    # Note that in this stage nothing is drawn yet in DrawBot. Potentionally all element can still be moved around
    # added or deleted or moved to other pages.  
    return doc # Answer the doc for further doing.
Example #14
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 #15
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.
Example #16
0
def makeDocument():
    u"""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

    # Hard coded SQUARE and GUTTE, just for simple demo, instead of filling padding an columns in the root style.
    # Page size decides on the amount squares that is visible.
    # Page padding is centered then.
    sqx = int(
        W / (SQUARE + GUTTER))  # Whole amount of squares that fit on the page.
    sqy = int(H / (SQUARE + GUTTER))
    # Calculate centered paddings for the amount of fitting squares.
    # Set values in the rootStyle, so we can compare with column calculated square position and sizes.
    #rs['colH'] = rs['colW'] = SQUARE  # Make default colW and colH square.

    padX = (W - sqx * (SQUARE + GUTTER) + GUTTER) / 2
    my = (H - sqy * (SQUARE + GUTTER) + GUTTER) / 2

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

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

    # 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 = 'This demo page'

    page.w = W
    page.h = H

    page.padding3D = padX  # Set all 3 paddings to same value
    page.gutter3D = GUTTER  # Set all 3 gutters to same value

    #newRect((0, 0), w=square, h=square, parent=page, fill=(1, 0, 0), stroke=None)

    for ix in range(
            sqx
    ):  # Run through the range of (0, 1, ...) number of horizontal squares
        for iy in range(sqy):  # Same with vertical squares
            # Place squares in random colors
            color1 = (random() * 0.5 + 0.5, 0.1, 0.6)
            color2 = (random() * 0.5 + 0.5, 0.1, 0.6)
            # Calculate the position for each square as combination
            # of paddings and (ix, iy)
            p = padX + ix * (SQUARE + GUTTER), my + iy * (
                SQUARE + GUTTER)  # Make 2-dimensional point tuple.
            # Create Rect object and place it in the page on position p
            # Initialize the borders dicts on lineWidth == 0
            e = newRect(p,
                        w=SQUARE,
                        h=SQUARE,
                        parent=page,
                        fill=color1,
                        stroke=None,
                        borders=1)  # border=1 also works, identical.
            lineType = {-1: ONLINE, 0: INLINE, 1: ONLINE, 2: OUTLINE}[LineType]
            e.borderLeft['strokeWidth'] = (ix + 1) * 4
            e.borderLeft['line'] = lineType
            e.borderLeft['stroke'] = (0, 0, 0, 0.5)
            e.borderLeft['dash'] = (DashWhite, DashBlack)

            e.borderBottom['strokeWidth'] = (ix + 1) * 4
            e.borderBottom['line'] = lineType
            e.borderBottom['stroke'] = (0, 1, 0)
            e.borderBottom['dash'] = (DashWhite, DashBlack)

            e.borderTop['strokeWidth'] = (iy + 1) * 4
            e.borderTop['line'] = lineType
            e.borderTop['stroke'] = (1, 1, 0, 0.5)

            e.borderRight['strokeWidth'] = (iy + 1) * 4
            e.borderRight['line'] = lineType
            e.borderRight['stroke'] = (0, 0, 1, 0.5)

            # Create Rect object and place it in the page on position p
    return doc  # Answer the doc for further doing.
Example #17
0
glyphName = 'e'  #'cid05405.1'

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

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

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

e1 = GlyphPath(font[glyphName],
               stroke=noColor,
               fill=noColor,
               pathFilter=pathFilter,
               parent=page,
               font='Verdana',
               conditions=[Left2Left(), Top2Top()])

#score = page.solve()

doc.export(EXPORT_PATH)
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=FRAMES)

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

    for frame in range(FRAMES):
        # Get list of pages with equal y, then equal x.
        #page = doc[0][0] # Get the single page from te document.
        page = doc.getPage(
            frame
        )  # Get page on pageNumber, first in row (this is only one now).
        page.padding = PagePadding

        #wghtValue = 0.5*sin(math.radians(360.0*frame/FRAMES)) + 0.5
        #wdthValue = 0.5*cos(math.radians(360.0*frame/FRAMES)) + 0.5

        fs = doc.context.newString(f.info.familyName + ' ' + f.info.styleName,
                                   style=dict(font=f.installedName,
                                              fontSize=18,
                                              textFill=0))
        _, th = textSize(fs)
        title = newTextBox(fs,
                           conditions=[Top2Top(), Fit2Width()],
                           parent=page,
                           h=th * 1.2)

        for (minF, maxF), axisNames in LOCATIONS:
            fIndex = frame - minF
            if fIndex >= 0 and fIndex < 20:
                # = axisNames
                break

        location = {}
        v = 0.5 * cos(math.radians(360.0 * fIndex /
                                   (FRAMES / len(LOCATIONS)))) + 0.5
        if 'wdth' in axisNames and 'wght' in axisNames:
            location['wdth'] = v
            location['wght'] = v
        elif 'wdth' in axisNames:
            location['wdth'] = v
            location['wght'] = 1
        elif 'wght' in axisNames:
            location['wdth'] = 1
            location['wght'] = v
        #print frame, axisNames, location

        circle = VariableCircle(
            f,
            s=GLYPH_NAME,
            name='VariableCircleSpeciment',
            parent=page,
            padding=4,  #t=frame,
            maxW=W - 2 * PagePadding,
            minW=100,
            # Location frame, float means 50% of defined axis range
            #location=dict(wght=v),
            #location=dict(wdth=wdthValue),
            location=location,
            # Fontsize of the neutral glyph. All measures in the info-graphic
            # are derived relative from this one.
            fontSize=64,
            # Show axis names with the axis max circle markers
            showAxisNames=True,
            # Show 3D effect of needles enteting sphere, instead of circle.
            draw3D=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,
        )

        fs = doc.context.newString('Axiswheel created by PageBot',
                                   style=dict(font=f.installedName,
                                              fontSize=7,
                                              textFill=0))
        _, th = textSize(fs)
        created = newTextBox(fs,
                             conditions=[Top2Bottom(),
                                         Fit2Width()],
                             parent=page,
                             h=th * 1.2)

        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. This is tricky,
        # because as a result the title may go to 2 lines and then the size of the
        # circle should be adjusted again.
        title.pl = circle.x - page.pl
        created.pl = circle.x - page.pl

    return doc  # Answer the doc for further doing.
def makeDocument():
    u"""Demo page composer."""

    # 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(w=W, h=H, autoPages=1)

    # Get default view
    view = doc.getView()
    view.padding = 0
    view.showElementOrigin = True
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPageNameInfo = True

    w = 300

    colorCondition1 = [  # Placement condition(s) for the color rectangle elements.
        Right2Right(),
        #Center2Right(),
        #Right2Right(),
        Top2Top(),
    ]
    colorCondition2 = [  # Placement condition(s) for the color rectangle elements.
        Right2Right(),
        #Top2Bottom(),
        Float2Left(),
        Float2Top(),
    ]
    colorCondition3 = [  # Placement condition(s) for the color rectangle elements.
        Right2Right(),
        #Top2Bottom(),
        Float2Left(),
        Float2Top(),
        Fit2Bottom(),
        #Bottom2Bottom(),
    ]
    textCondition = [  # Placement condition(s) for the text element..
        Float2Left(),
        Float2Top(),
    ]
    page = doc.getPage(0)  # Get the first/single page of the document.

    # Other z-layer, makes this element be ignored on floating checks.
    e0 = newRect(z=-10,
                 name='Page area',
                 parent=page,
                 conditions=[Fit()],
                 fill=0.9)

    # Add some color elements (same width, different height) at the “wrongOrigin” position.
    # They will be repositioned by solving the colorConditions.
    e1 = newRect(parent=page,
                 name='Other element',
                 w=Element1_W,
                 h=Element1_H,
                 conditions=colorCondition1,
                 fill=(1, 0.5, 0.5),
                 xAlign=RIGHT,
                 yAlign=TOP)
    e2 = newRect(parent=page,
                 w=Element2_W,
                 h=Element2_H,
                 name='Floating element 2',
                 conditions=colorCondition2,
                 fill=(1, 1, 0),
                 xAlign=LEFT,
                 yAlign=TOP)
    e3 = newRect(parent=page,
                 w=Element3_W,
                 h=Element3_H,
                 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(scriptGlobals, 'blurbText'):
        scriptGlobals.blurbText = doc.context.newString(
            blurb.getBlurb('article_summary', noTags=True),
            page,
            style=dict(font='Georgia', fontSize=12, leading=16, textColor=0))
    eTextBox = newTextBox(scriptGlobals.blurbText,
                          parent=page,
                          w=Text_W,
                          conditions=textCondition,
                          xAlign=CENTER,
                          yAlign=MIDDLE,
                          stroke=None,
                          fill=None)

    e4 = newRect(parent=page,
                 w=Element4_W,
                 h=Element4_H,
                 name='Floating element 4',
                 conditions=colorCondition3,
                 fill=(0, 1, 1),
                 xAlign=RIGHT,
                 yAlign=TOP,
                 minH=50,
                 maxH=150)
    e5 = newRect(parent=page,
                 w=Element5_W,
                 h=Element5_H,
                 name='Floating element 5',
                 conditions=[Float2RightTopSides()],
                 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.result < 0:
        print 'Solving', score
        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