예제 #1
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.
예제 #2
0
def makePage1(page, font):
    # Title as 2-letter abbreviation of the family name, as in Berthold original
    style = dict(font=font, fontSize=pt(24))
    bs = context.newString(font.info.familyName[:2].capitalize(), style=style)
    newTextBox(bs,
               parent=page,
               conditions=[Left2Left(), Top2SideTop()],
               yAlign=BOTTOM)
    """
def makePage(page, data, xAlign, yAlign):
    for ix, col in enumerate(data):
        for iy, row in enumerate(col):
            name = 'Hkpx%d%d' % (ix, iy)
            c = [Shrink2TextBounds()] + list(row)
            bgColor = color(ix / 3, 0, iy / 3, 0.8)
            newTextBox(getText(name),
                       conditions=c,
                       xAlign=xAlign,
                       yAlign=yAlign,
                       parent=page,
                       fill=bgColor,
                       showOrigin=True)
    page.solve()
예제 #4
0
def makePage2(page, font):
    border = dict(stroke=blackColor, strokeWidth=pt(0.5))
    r = newRect(parent=page, conditions=[Fit()])

    fullName = '%s %s' % (font.info.familyName, font.info.styleName)
    style = dict(font=font, fontSize=pt(24), xTextAlign=CENTER)
    bs = context.newString(fullName.upper(), style=style)
    newTextBox(bs,
               parent=r,
               borderTop=border,
               borderBottom=border,
               margin=0,
               padding=0,
               conditions=[Left2Left(), Top2Top(),
                           Fit2Width()])
예제 #5
0
def makeDocument():
    u"""Create new document with (w,h) and fixed amount of pages.
    Make number of pages with default document size.
    Initially make all pages default with template."""

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

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

    view = doc.view
    view.w = view.h = W, H
    view.padding = 40
    view.showPageFrame = True
    view.showPageCropMarks = True
    view.showElementOrigin = True # Show the alignment position
                                  # of elements as plus-mark.

    title = 'Book Cover' # Using plain string, style values
                         # from text box element.
    fontSize = 40
    newTextBox(title, # Text inside the text box
               name='Other element', # Optinal (unique) name of element.
                                     # Otherwise e.eId is used.
               x=100, y=100, # Position from left-bottom of page side
                             # (not page padding)
               parent=page,
               w=400, h=200, # Size of the element.
                             # Since x = 100 and W = 500, this "manually" fits.
               padding=5, # Padding inside text box for all 4 sides equal.
               fill=(0.4, 0.6, 1), # Rectangle fill color
               stroke=(1, 0, 0), # Rectangle stroke color
               strokeWidth=10,
               # Below style values that apply to the content
               font='Verdana',
               fontSize=fontSize,
               leading=0, rLeading=1, # Absolute and relative leading.
               xAlign=LEFT, yAlign=BOTTOM, # Set origin of element to left-bottom
               textFill=(0, 0, 1)) # Color of the text.
    # Return the generated document to the caller.
    return doc
예제 #6
0
def setPageStyle(page, index):

    if SHOW_BACKGROUND:
        bgi = newImage(BACKGROUND_PDF, z=-10, parent=page,
                       index=index // 2)  #, conditions=[Fit()])
        bgi.size = inch(W * 2, H)
        if page.isRight:
            bgi.x -= W

    # Page numbers
    dy1 = BASELINE + pt(4)
    dy2 = BASELINE
    if page.isLeft:
        bs = context.newString('FALL 2018', style=styles['typeTitleRight'])
        newTextBox(bs,
                   w=CW,
                   h=page.pb - dy1,
                   parent=page,
                   conditions=[Bottom2SideBottom(),
                               Right2Right()],
                   bleed=0)
        bs = context.newString(page.pn[0], style=styles['pnLeft'])
        newTextBox(bs,
                   w=CW,
                   h=page.pb - dy2,
                   parent=page,
                   conditions=[Bottom2SideBottom(),
                               Left2Left()],
                   bleed=0)
    else:
        bs = context.newString('TYPE No. 3', style=styles['typeTitleLeft'])
        newTextBox(bs,
                   w=CW,
                   h=page.pb - dy1,
                   parent=page,
                   conditions=[Bottom2SideBottom(),
                               Left2Left()],
                   bleed=0)
        bs = context.newString(page.pn[0], style=styles['pnRight'])
        newTextBox(bs,
                   w=CW,
                   h=page.pb - dy2,
                   parent=page,
                   conditions=[Bottom2SideBottom(),
                               Right2Right()],
                   bleed=0)

    page.solve()
예제 #7
0
def setPageStyle(page, index):
    if page.isLeft:
        page.bleed = BLEED_LEFT
        page.padding = '3p1.5', LM, '4p1.5', RM
    else:
        page.bleed = BLEED_RIGHT
        page.padding = '3p1.5', RM, '4p1.5', LM
    page.gridX = (CW, GUTTER), (CW, GUTTER), (CW, GUTTER), (CW, 0)
    page.gridY = (CH, GUTTER), (CH, GUTTER), (CH, GUTTER), (CH, GUTTER), (CH, GUTTER), (CH, GUTTER), (CH, GUTTER), (CH, 0)

    #newTextBox(parent=page, name=BOX_NAME, fill=0.9, nextElementName=BOX_NAME, bleed=0,
    #    conditions=[Fit()])

    if SHOW_TEMPLATE:
        bgi = newImage(TEMPLATE_PDF, z=-10, parent=page, index=index//2)#, conditions=[Fit()])
        bgi.size = inch(W*2, H)
        if page.isRight:
            bgi.x -= W

    # Page numbers
    dy1 = BASELINE+pt(4)
    dy2 = BASELINE
    if page.isLeft:
        bs = context.newString('FALL 2018', style=styles['typeTitleRight'])
        newTextBox(bs, w=CW, h=page.pb-dy1, parent=page, conditions=[Bottom2SideBottom(), Right2Right()],
            bleed=0)
        bs = context.newString(page.pn[0], style=styles['pnLeft'])
        newTextBox(bs, w=CW, h=page.pb-dy2, parent=page, conditions=[Bottom2SideBottom(), Left2Left()],
            bleed=0)
    else:
        bs = context.newString('TYPE No. 3', style=styles['typeTitleLeft'])
        newTextBox(bs, w=CW, h=page.pb-dy1, parent=page, conditions=[Bottom2SideBottom(), Left2Left()],
            bleed=0)
        bs = context.newString(page.pn[0], style=styles['pnRight'])
        newTextBox(bs, w=CW, h=page.pb-dy2, parent=page, conditions=[Bottom2SideBottom(), Right2Right()],
            bleed=0)

    path = '../../../Art_TYPE-3/Firsts_images_TYPE-3/1. page-number-printed-1470.pdf'
    if page.pn[0] == startPage:
        pass
    elif page.pn[0] == startPage+1:
        pass
    else:
        pass

    page.solve()
예제 #8
0
def makeDocument():
    """Demo random book cover generator."""

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

    page = doc[1]  # Get the first/single page of the document.
    page.name = 'Cover'

    # Get the current view of the document. This allows setting of
    # parameters how the document is represented on output.
    view = doc.view
    view.w, view.h = W, H
    # Set view options. Full list is in elements/views/baseviews.py
    view.padding = 40  # Showing cropmarks and registration marks
    # need >= 20 padding of the view.
    view.showRegistrationMarks = True
    view.showCropMarks = True
    view.showFrame = False
    view.showPadding = False
    view.showNameInfo = True
    view.showTextOverflowMarker = False

    context = view.context

    C1 = Color(r=0.2 + random() * 0.8,
               g=random() * 0.2,
               b=0.4 + random() * 0.2)

    # Make background element, filling the page color and bleed.
    colorRect1 = newRect(z=-10,
                         name='Page area',
                         parent=page,
                         pt=40,
                         conditions=[
                             Top2TopSide(),
                             Left2LeftSide(),
                             Fit2RightSide(),
                             Fit2BottomSide()
                         ],
                         fill=C1)
    colorRect1.bleed = BLEED
    colorRect1.solve()  # Solve element position, before we can make
    # other elements depend on position and size.

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

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

    # Make random blurb name and titles
    title = blurb.getBlurb('book_phylosophy_title')
    subTitle = blurb.getBlurb('book_pseudoscientific').capitalize()
    if random() < 0.2:  # 1/5 chance to add editions text
        subTitle += '\nEdition ' + blurb.getBlurb('edition')
    authorName = blurb.getBlurb('name', noTags=True)
    if random() < 0.33:  # 1/3 chance for a second author name
        authorName += '\n' + blurb.getBlurb('name')

    # Add some title (same width, different height) at the "wrongOrigin" position.
    # They will be repositioned by solving the colorConditions.
    titleS = context.newString('')
    for word in title.split(' '):
        titleS += context.newString(' ' + word,
                                    style=dict(font=fontRegular.path,
                                               fontSize=50,
                                               w=page.pw,
                                               leading=em(1.2),
                                               xTextAlign=CENTER,
                                               textFill=whiteColor))
    #title += context.newString(subTitle + '\n\n', style=dict(font=fontRegular.path, fontSize=32, xTextAlign=CENTER, textFill=(1, 1, 1,0.5)))
    #title += context.newString(authorName, style=dict(font=fontItalic.path, fontSize=24, tracking=em(0.025), xTextAlign=CENTER, textFill=(1, 0.5, 1,0.7)))
    newTextBox(titleS,
               parent=colorRect2,
               name='Title',
               conditions=[Fit2Width(),
                           Center2Center(),
                           Top2Top()],
               xAlign=CENTER,
               yAlign=TOP)

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

    # Evaluate again, result should now be >= 0
    return doc
예제 #9
0
    # Make image box as child element of the page and set its layout conditions.
    im = Image(imagePath,
               h=IH,
               w=IH,
               fill=(1, 0, 0, 0.5),
               parent=page,
               conditions=[Right2Right(),
                           Float2Top(),
                           Float2Left()],
               mr=G,
               mb=G)
    style1 = dict(fontSize=14, textFill=0, xTextAlign=CENTER)
    bs = context.newString('1', style=style1)
    newTextBox(bs,
               parent=im,
               w=IH,
               fill=noColor,
               conditions=(Center2Center(), Middle2Middle()))

if 1:
    # Make image box as child element of the page and set its layout conditions.
    im = Image(imagePath,
               h=IH,
               w=IH,
               fill=(1, 1, 0, 0.5),
               parent=page,
               conditions=[Right2Right(),
                           Float2Top(),
                           Float2Left()],
               mr=G,
               mb=G)
def makeBanner(bd):
    u"""Demo random book cover generator."""
    w, h = bd['w'], bd['h']
    imagePaths = bd['imagePaths']
    labelSize = bd['labelSize']
    title1 = bd['title1']
    title2 = bd['title2']
    titleSize = bd['titleSize']

    context = getContext()
    context.newDrawing()
    # 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,
                   title=title1,
                   autoPages=FRAMES,
                   context=context,
                   originTop=False)  # One page, just the cover.

    A = (1, 1, 1, 0.5)
    B = (1, 0, 1, 0.8)
    C = (1, 1, 1, 0.8)
    COLORS = (
        (B, B, B),
        (A, B, B),
        (B, A, B),
        (B, B, A),
        (A, B, B),
        (B, B, A),
        (B, A, B),
    )
    for pn in range(1, FRAMES + 1):
        page = doc[pn]  # Get the first/single page of the document.

        page.frameDuration = 1.5

        imagePath, imageConditions = imagePaths[pn - 1]
        # Background image of the slide
        newImage(PATH + imagePath, conditions=imageConditions, parent=page)

        ww75 = w * 0.75
        newRect(fill=(0.05, 0.05, 0.4, 0.8),
                w=ww75,
                conditions=(Fit2HeightSides(), Right2RightSide()),
                parent=page)

        ww25 = w * 0.25
        #bs = context.newString('Type@Cooper\nTypographics', style=dict(font=fontRegular.path, fontSize=w/28, xTextAlign=CENTER, textFill=1, rLeading=1.05))
        #tw, th = bs.textSize()
        #newTextBox(bs, parent=page, h=th+P/2, w=ww25, padding=(P/4,P/3,0,P/3), fill=(1,0,0,0.8), conditions=(Left2LeftSide(), Top2TopSide()))

        bs = context.newString('Typographics',
                               style=dict(font=fontRegular.path,
                                          fontSize=w / 24,
                                          xTextAlign=CENTER,
                                          textFill=1,
                                          rLeading=1.05))
        tw, th = bs.textSize()
        newTextBox(bs,
                   parent=page,
                   h=th + P / 2,
                   w=ww25,
                   padding=(P / 4, P / 3, 0, P / 3),
                   fill=(1, 0, 0, 0.8),
                   conditions=(Left2LeftSide(), Top2TopSide()))

        bs = context.newString(title1 + '\n',
                               style=dict(font=fontMedium.path,
                                          textFill=C,
                                          fontSize=w / 11,
                                          rTracking=0.015,
                                          rLeading=1.4))
        bs += context.newString(title2 + '\n',
                                style=dict(font=fontBook.path,
                                           textFill=C,
                                           fontSize=w / 12,
                                           rLeading=1))
        bs += context.newString('SKETCHING',
                                style=dict(font=fontRegular.path,
                                           textFill=COLORS[pn - 1][0],
                                           fontSize=w / 15,
                                           rTracking=0.648,
                                           rLeading=1.5))
        bs += context.newString('\nCODING',
                                style=dict(font=fontRegular.path,
                                           textFill=COLORS[pn - 1][1],
                                           fontSize=w / 16,
                                           rTracking=0.185,
                                           rLeading=1.05))
        bs += context.newString(' & ',
                                style=dict(font=fontRegular.path,
                                           textFill=A,
                                           fontSize=w / 16,
                                           rTracking=0.185,
                                           rLeading=1.05))
        bs += context.newString('MAKING\n',
                                style=dict(font=fontRegular.path,
                                           textFill=COLORS[pn - 1][2],
                                           fontSize=w / 16,
                                           rTracking=0.185,
                                           rLeading=1.05))
        bs += context.newString('Petr van Blokland April 11-13',
                                style=dict(font=fontRegular.path,
                                           textFill=C,
                                           fontSize=w / 17.5,
                                           rTracking=0.032,
                                           rLeading=1.6))
        newTextBox(bs,
                   parent=page,
                   x=ww25,
                   y=0,
                   padding=(0, 0, 0, w / 30),
                   w=ww75 + w / 100,
                   conditions=[Fit2HeightSides()])

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

    # Evaluate again, result should now be >= 0
    return doc
예제 #11
0
def makeDocument(docStyle):
    u"""Demo Bitpath Reference composer."""
    mainId = 'mainId'

    features = dict(
        kern=True,
        liga=Ligatures,
        zero=Slashed_Zero,
        frac=Fraction,
        smcp=Smallcaps,
        c2sc=Caps_As_Smallcaps,
        ss08=Italic_Shapes,
        ss07=Condensed,
        ss01=Extended_Ascenders,
        ss02=Extended_Capitals,
        ss03=Extended_Descenders,
        ss04=Contrast_Pixel,
        ss09=Alternative_g,
        onum=LC_Figures,
    )
    if HeadlineTracking:
        headlineTracking = 0.1
    else:
        headlineTracking = 0

    if BodyTracking:
        bodyTracking = 0.1
    else:
        bodyTracking = 0

    if Single:
        singleDouble = 'Single'
    else:
        singleDouble = 'Double'

    if Monospaced:
        spacing = 'Mono'
    else:
        spacing = 'Prop'

    if Italic:
        italic = 'Italic'
    else:
        italic = ''

    spacing = 'Grid'
    singleDouble = 'Double'

    BOOK = '%s%s%s-BlackLineRound%s' % (familyName, spacing, singleDouble,
                                        italic)
    MEDIUM = '%s%s%s-RegularLineRound%s' % (familyName, spacing, singleDouble,
                                            italic)
    BOOK_ITALIC = '%s%s%s-RegularLineRound%s' % (familyName, spacing,
                                                 singleDouble, italic)
    BOLD = '%s%s%s-RegularLineRound%s' % (familyName, spacing, singleDouble,
                                          italic)
    SEMIBOLD = '%s%s%s-RegularLineRound%s' % (familyName, spacing,
                                              singleDouble, italic)

    # 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 template2
    doc = Document(style=docStyle, w=W, h=H, autoPages=1)

    page = doc[0]
    # Index by element id, answers ([e1, ...], (x, y)) tuple. There can be multiple elements
    # with the same Id, and there can be multiple elements on the same position).
    #page[mainId]
    context = doc.context

    bs = context.newString(blurb.getBlurb('sports_headline', noTags=True) +
                           '\n',
                           style=dict(font=BOOK,
                                      fontSize=32,
                                      rTracking=headlineTracking,
                                      openTypeFeatures=features))
    bs += context.newString(blurb.getBlurb('aerospace_headline', noTags=True) +
                            '\n',
                            style=dict(font=BOOK,
                                       fontSize=24,
                                       rTracking=headlineTracking,
                                       openTypeFeatures=features))
    bs += context.newString(blurb.getBlurb('article_content', noTags=True) +
                            '\n',
                            style=dict(font=BOOK,
                                       fontSize=18,
                                       rTracking=bodyTracking,
                                       openTypeFeatures=features))

    newTextBox(bs, x=M, y=H - M, w=W - 2 * M, h=H, parent=page)

    return doc
예제 #12
0
def makeDocument():
    """Make a new document."""

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

    view = doc.view
    view.padding = pt(40)  # Show cropmarks and such.
    view.showCropMarks = True  # Add crop marks
    view.showRegistrationMarks = True  # Add registration marks
    view.showNameInfo = True  # Add file name
    view.showMargin = True
    view.showFrame = True
    #view.showOrigin = True
    #view.showColorBars = True # Gives error
    view.showDimensions = False
    view.showElementInfo = ShowElementInfo

    page = doc[1]  # 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.margin = 0
    page.padding = SQ

    pageArea = PageSize - 2 * SQ
    print(PageSize, pageArea, SQ)

    # Make new container for adding elements inside with alignment.
    newRect(z=10,
            w=pageArea,
            h=pageArea,
            fill=color(0.8, 0.8, 0.8, 0.4),
            parent=page,
            margin=0,
            padding=0,
            yAlign=MIDDLE,
            xAlign=CENTER,
            stroke=noColor,
            conditions=(Center2Center(), Middle2Middle()))

    fontSize = RedHeight / 3
    fs = doc.context.newString('Headline in red box.',
                               style=dict(textFill=whiteColor,
                                          fontSize=fontSize,
                                          leading=fontSize,
                                          font='LucidaGrande'))
    newTextBox(fs,
               z=0,
               w=RedWidth,
               h=RedHeight,
               name='RedRect',
               parent=page,
               fill=color(1, 0.1, 0.1),
               yAlign=TOP,
               padding=4,
               conditions=(Center2Center(), Top2Top()))

    if not hasattr(scriptGlobals, 'blurbText'):
        scriptGlobals.blurbText = blurb.getBlurb('article_summary',
                                                 noTags=True)
    fs = doc.context.newString('Headline of formatted text.\n',
                               style=dict(font='LucidaGrande-Bold',
                                          fontSize=12,
                                          leading=14,
                                          textFill=blackColor))
    fs += doc.context.newString(scriptGlobals.blurbText,
                                style=dict(font='LucidaGrande',
                                           fontSize=10,
                                           leading=12,
                                           textFill=blackColor))
    newTextBox(fs,
               z=0,
               w=YellowWidth,
               h=YellowHeight,
               parent=page,
               padding=4,
               fill=0.7,
               conditions=(Left2Left(), Float2Top()))

    path = getResourcesPath() + 'cookbot10.jpg'

    newImage(path,
             z=0,
             w=BlueWidth,
             parent=page,
             fill=0.7,
             padding=8,
             conditions=(Right2Right(), Float2Top()))

    newRect(z=0,
            w=BlueWidth,
            h=20,
            parent=page,
            fill=0.2,
            conditions=(Fit2Width(), Float2Top()))

    score = page.solve()
    if score.fails:
        print('Condition fails', score.fails)

    return doc  # Answer the doc for further doing.
예제 #13
0
def addDescription(page, context, description):
    style = {'font': regularFont.path, 'fontSize': 12, 'leading': 14}
    bs = context.newString(description, style=style)
    newTextBox(bs, parent=page, w=W/2, conditions=[Right2RightSide(),
        Top2Top()])
예제 #14
0
def makeDocument():
    u"""Demo random book cover generator."""

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

    page = doc[1]  # Get the first/single page of the document.
    page.name = 'Cover'

    # Get the current view of the document. This allows setting of
    # parameters how the document is represented on output.
    view = doc.view
    view.w, view.h = W, H
    # Set view options. Full list is in elements/views/baseviews.py
    view.padding = 40  # Showing cropmarks and registration marks
    # need >= 20 padding of the view.
    view.showPageRegistrationMarks = True
    view.showPageCropMarks = True
    view.showPageFrame = True
    view.showPagePadding = False
    view.showPageNameInfo = True
    view.showTextOverflowMarker = False

    context = view.context

    C1 = Color(r=random() * 0.2, g=random() * 0.2, b=random() * 0.9)

    # Make background element, filling the page color and bleed.
    colorRect1 = newRect(z=-10,
                         name='Page area',
                         parent=page,
                         conditions=[
                             Top2TopSide(),
                             Left2LeftSide(),
                             Fit2RightSide(),
                             Fit2BottomSide()
                         ],
                         fill=C1)
    colorRect1.bleed = BLEED
    colorRect1.solve()  # Solve element position, before we can make
    # other elements depend on position and size.

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

    # Make random blurb name and titles
    title = blurb.getBlurb('book_phylosophy_title')
    subTitle = blurb.getBlurb('book_pseudoscientific').capitalize()
    if random() < 0.2:  # 1/5 chance to add editions text
        subTitle += '\nEdition ' + blurb.getBlurb('edition')
    authorName = blurb.getBlurb('name', noTags=True)
    if random() < 0.33:  # 1/3 chance for a second author name
        authorName += '\n' + blurb.getBlurb('name')

    page.pt = 100  # Now the rectangles positioned automatic, alter the paddings
    page.pl = page.pr = 80
    page.pb = 20
    # Add some title (same width, different height) at the "wrongOrigin" position.
    # They will be repositioned by solving the colorConditions.
    title = context.newString(title + '\n\n',
                              style=dict(font=fontBold.path,
                                         fontSize=40,
                                         rLeading=1.2,
                                         xTextAlign=CENTER,
                                         textFill=1))
    title += context.newString(subTitle + '\n\n',
                               style=dict(font=fontRegular.path,
                                          fontSize=32,
                                          xTextAlign=CENTER,
                                          textFill=(1, 1, 1, 0.5)))
    title += context.newString(authorName,
                               style=dict(font=fontItalic.path,
                                          fontSize=24,
                                          rTracking=0.025,
                                          xTextAlign=CENTER,
                                          textFill=(1, 0.5, 1, 0.7)))
    newTextBox(title,
               parent=page,
               name='Other element',
               conditions=[Fit2Width(),
                           Center2Center(),
                           Top2Top()],
               xAlign=CENTER,
               yAlign=TOP)

    typoIllustration = context.newString('&',
                                         style=dict(font=ampersandFont.path,
                                                    fontSize=300,
                                                    xTextAlign=CENTER,
                                                    textFill=(1, 0.5, 1, 0.7)))
    newTextBox(typoIllustration,
               parent=page,
               conditions=[Fit2Width(),
                           Center2Center(),
                           Bottom2Bottom()],
               xAlign=CENTER,
               yAlign=TOP)

    # Evaluate again, result should now be >= 0
    score = page.evaluate()
    if score.fails:  # There is new "failing" elements. Solve their layout.
        page.solve()

    return doc
예제 #15
0
# Rotate the whole by selecting the value and then cmd-drag to alter the value
# The elements rotate independently. Note that the image is rotating in the
# reversed direction, so it stays upright in the clipping rectangle.
a = degrees(100)

im.angle = a
im.fill = (0, 0, 0.7 + random() * 0.3)
imd = im.imageData
imd.x = 366
imd.y = 150
imd.w = 300
imd.h = 400
imd.rx = 50
imd.ry = 60
imd.angle = -a

bs = context.newString('Rotating images', style=dict(fontSize=32, textFill=1))
tb = newTextBox(bs,
                w=400,
                parent=im,
                conditions=(Center2Center(), Middle2Middle()),
                angle=-a,
                fill=noColor)
# Solve the page/element conditions
doc.solve()

im.rx = im.w / 2
im.ry = im.h / 2
# Export the document to this PDF file.
doc.export('_export/ImageClipping.pdf')
예제 #16
0
    def initialize(self, padding=None, gutter=None, columns=None, **kwargs):
        u"""Initialize the generic book templates. """
        blurb = Blurb()

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

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

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

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

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

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

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

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

        # Template 'Front'

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

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

        # Place article 3 columns

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.addTemplate(t.name, t)

        # Template 'MainPage'

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

            dummyArticle = blurb.getBlurb('article', newLines=True)
            bs = self.view.newString(dummyArticle, style=bodyStyle)
            newTextBox(bs,
                       parent=t,
                       pr=gutter,
                       w=cw + gutter,
                       z=0,
                       conditions=[
                           Right2RightSide(),
                           Float2Top(),
                           Fit2Bottom(),
                           Float2Left()
                       ])
        self.addTemplate(t.name, t)
예제 #17
0
def getTemplates():
    titleLeft = Template(bleed=BLEED_LEFT,
                         padding=PADDING_LEFT,
                         gridX=GRID_X,
                         gridY=GRID_Y)
    titleRight = Template(bleed=BLEED_RIGHT,
                          padding=PADDING_RIGHT,
                          gridX=GRID_X,
                          gridY=GRID_Y)
    left = Template(bleed=BLEED_LEFT,
                    padding=PADDING_LEFT,
                    gridX=GRID_X,
                    gridY=GRID_Y)
    right = Template(bleed=BLEED_LEFT,
                     padding=PADDING_LEFT,
                     gridX=GRID_X,
                     gridY=GRID_Y)

    borders = dict(stroke=blackColor,
                   strokeWidth=SWIDTH,
                   line=INLINE,
                   dash=None)
    path = '../../../Art_TYPE-3/Type-People_TYPE-3/Selects_Type-People/Frida-Medrano_02_177797.tif'

    newImage(path=path,
             parent=titleLeft,
             name='images',
             conditions=(Left2Col(1), Top2Top()))
    newTextBox(name='title',
               h=300,
               parent=titleLeft,
               conditions=[Top2Top(), Left2Left(),
                           Fit2Width()],
               bleed=0)
    newTextBox(name='people',
               h=300,
               parent=titleLeft,
               conditions=[Bottom2Bottom(),
                           Left2Left(),
                           Fit2Width()],
               bleed=0)

    newImage(path=path,
             parent=titleRight,
             name='images',
             conditions=(Left2Col(1), Top2Top()))

    for template in (left, right):
        im = newImage(path=path,
                      parent=template,
                      name='image',
                      bleed=0,
                      conditions=[Left2Left(),
                                  Fit2Width(),
                                  Top2Top()],
                      borders=borders)
        newTextBox(name='people',
                   h=300,
                   parent=template,
                   conditions=[Bottom2Bottom(),
                               Left2Left(),
                               Fit2Width()],
                   bleed=0)

    return dict(
        titleLeft=titleLeft,
        titleRight=titleRight,
        left=left,
        right=right,
    )
예제 #18
0
def buildSpecimenPages(page, family):
    page.padding = PADDING
    page.gridX = GRID_X
    pageTitle = family.name
    # Add filling rectangle for background color of the old paper book.
    # Set z-azis != 0, to make floating elements not get stuck at the background
    newRect(z=-10, w=W, h=H, parent=page, fill=PAPER_COLOR)
    # During development, draw the template scan as background
    # Set z-azis != 0, to make floating elements not get stuck at the background
    if SHOW_TEMPLATE:
        newImage(FB_PATH_L, x=0, y=0, z=-10, w=W / 2, parent=page)
        newImage(FB_PATH_R, x=W / 2, y=0, z=-10, w=W / 2, parent=page)

    # Left and right family name the current font.
    titleBs = context.newString(pageTitle,
                                style=dict(font=labelFont.path,
                                           fontSize=16,
                                           xTextAlign=LEFT,
                                           textFill=0))
    titleBox = newTextBox(titleBs,
                          parent=page,
                          h=3 * U,
                          w=C3,
                          conditions=[Top2Top(), Left2Left()],
                          fill=DEBUG_COLOR0)

    titleBs = context.newString(pageTitle,
                                style=dict(font=labelFont.path,
                                           fontSize=16,
                                           xTextAlign=RIGHT,
                                           textFill=0))
    titleBox = newTextBox(titleBs,
                          parent=page,
                          h=3 * U,
                          w=C3,
                          conditions=[Top2Top(), Right2Right()],
                          fill=DEBUG_COLOR0)

    lineL = newLine(parent=page,
                    w=C3,
                    h=1,
                    mb=U,
                    strokeWidth=1,
                    stroke=0,
                    conditions=(Float2Top(), Left2Left()))
    lineR = newLine(parent=page,
                    w=C3,
                    h=1,
                    mb=U,
                    strokeWidth=1,
                    stroke=0,
                    conditions=(Float2Top(), Right2Right()))

    descriptionFont = family.findRegularFont()
    description = ''
    if descriptionFont.info.description:
        description += descriptionFont.info.description + ' '
    if descriptionFont.info.trademark:
        description += descriptionFont.info.trademark
    if description:
        description = context.newString(description, style=descriptionStyle)
        _, descriptionH = context.textSize(description, w=C3)
    else:
        descriptionH = 0

    # Get the weightClass-->fonts dictionary, sorted by weight.
    weightClasses = family.getWeights()

    # Text samples on the right
    y = 300  #lineR.bottom
    for weightClass, fonts in sorted(weightClasses.items()):
        for font in fonts:
            if font.isItalic():
                continue
            sample = context.newString(blurb.getBlurb('article'),
                                       style=dict(font=font.path,
                                                  fontSize=9,
                                                  leading=em(1.1)))
            h = H / len(family) + L
            newTextBox(sample,
                       parent=page,
                       w=C3,
                       h=h,
                       conditions=(Right2Right(), Float2Top()),
                       fill=DEBUG_COLOR1)
            y -= h
            if y <= PB + descriptionH:
                break

    if description:
        newTextBox(description,
                   parent=page,
                   w=C3,
                   h=descriptionH,
                   conditions=(Right2Right(), Bottom2Bottom()),
                   fill=DEBUG_COLOR1)

    weightNames = getWeightNames(family)

    charSetString = context.newString(weightNames + '\n\n', style=fontSetStyle)
    charSetString += context.newString(GLYPH_SET, style=charSetStyle)
    _, charSetStringH = context.textSize(charSetString, w=C3)

    newTextBox(charSetString,
               parent=page,
               w=C3,
               h=charSetStringH,
               conditions=(Left2Left(), Bottom2Bottom()))

    page.solve()  # So far with conditional placement.

    # It's easier for this example to position the elements by y-coordinate now, because there
    # is mismatch between the position of the pixel image of the lines and the content of text
    # boxes. Although it is possible to build by floating elements or by on single text, which
    # will show in another proof-revival example.

    y = lineL.bottom - U  # Position at where this went to by solving the layout conditions.
    # Stacked lines on the left, by separate elements, so we can squeeze them by pixel image size.
    for n in range(100):  # That's enough
        headline = blurb.getBlurb('_headline',
                                  cnt=choice(
                                      (2, 3, 4, 4, 4, 4, 4, 5, 6, 7, 8)))
        if random() <= 0.2:
            headline = headline.upper()
        stackLine = context.newString(headline,
                                      style=dict(font=choice(
                                          context.installedFonts()),
                                                 leading=em(-0.2),
                                                 paragraphTopSpacing=0,
                                                 paragraphBottomSpacing=0),
                                      w=C3,
                                      pixelFit=False)
        _, by, bw, bh = stackLine.bounds()
        tw, th = context.textSize(charSetString)
        if y - bh < PB + th:  # Reserve space for glyph set
            break  # Filled the page.
        newTextBox(stackLine,
                   parent=page,
                   x=PL,
                   y=y - bh - by - U,
                   w=C3,
                   h=th + 2,
                   fill=DEBUG_COLOR1)
        y -= bh + by + U
        page = page.nextc
예제 #19
0
def testFlatContext():
    context = getContext('Flat')

    # PageBot implementation, to be used for strings and styles.
    pagebotFont = findFont(FONTNAME)
    pagebotFill = color((180.0 / 255, 0, 125.0 / 255))
    pagebotStroke = color(100.0 / 255, 180.0 / 255, 0)

    # Native flat implementation of fonts and colors.
    flatFont = font.open(pagebotFont.path)
    flatFill = rgb(180, 0, 125)
    flatStroke = rgb(100, 180, 0)

    # Stroke width is the same.
    strokeWidth = 1

    ''' Creates a document. '''

    # Creating a Flat document.
    flatDoc = document(WIDTH, HEIGHT, 'pt')
    flatPage = flatDoc.addpage()

    # Pagebot equivalent.
    context.newDrawing(WIDTH, HEIGHT)
    pbPage = context.newPage()
    print(pbPage)

    ''' Draws a figure. '''

    # Flat.
    #figure = shape().fill(flatFill).stroke(flatStroke).width(strokeWidth)
    #r = figure.rectangle(50, 50, 20, 20)
    #p.place(r)

    # Pagebot.
    #context.fill(pagebotFill)
    #context.stroke(pagebotStroke)
    #context.strokeWidth(strokeWidth)
    #context.rect(50, 50, 20, 20)

    #print(p.items[0].item.style.width)
    #print(context.pages[0].items[0].item.style.width)

    #s = context.pages[0].items[0]

    #print(s.item.style.fill)
    #print(s.item.style.stroke)
    #print(s.item.style.join)
    #print(s.item.style.limit)

    ''' Draws text. '''

    msg = 'Hello world!'

    # Flat.

    header = strike(flatFont).color(flatStroke).size(FONTSIZE, LEADING, units='pt')
    t = header.text(msg)
    placedText = flatPage.place(t).frame(100, 100, 380, 80)

    # Pagebot.
    style = dict(font=pagebotFont, fontSize=FONTSIZE, textFill=pagebotStroke,
            leading=LEADING)
    bs = context.newString(msg, style=style)
    context.text('bla', (50, 100)) # TODO: also for native flat.
    context.text(bs, (100, 100))


    #print(headline.style.size)
    #print(headline.style.leading)
    #print(headline.style.color.r)
    #print(headline.style.color.g)

    # Now for conditions and elements.
    c = (Left2Left(), Fit2Right(), Float2Top())
    style = dict(fontSize=14, font=pagebotFont)
    msg = 'Testing textBox'
    print(msg)
    bs = context.newString(msg, style=style)
    print(type(bs))

    newTextBox(bs, font=pagebotFont, parent=pbPage, conditions=c, fill=0.9,
            margin=4)
    #print(p.items)

    ''' Exports file. '''

    im = flatPage.image(kind='rgb')


    # TODO:
    #imagePath = getResourcesPath() + '/images/peppertom_lowres_398x530.png'
    #size = context.imageSize(imagePath)
    #print(size)

    if not os.path.exists('_export'):
        os.mkdir('_export')

    #print('Exporting native')
    flatDoc.pdf('_export/native-flat.pdf')
    #im.png('_export/native-flat.png')
    #im.jpeg('_export/native-flat.jpg')
    #p.svg('_export/native-flat.svg')
    #print(context.doc)

    context.saveDrawing('_export/pagebot-flat.pdf')
def buildSpecimenPages(doc, family, pn):
    for font in family.getFonts():
        page = doc[pn]
        page.padding = PADDING
        page.gridX = GRID_X
        pageTitle = path2FontName(font.path)
        # Add filling rectangle for background color of the old paper book.
        # Set z-azis != 0, to make floating elements not get stuck at the background
        newRect(z=-10, w=W, h=H, parent=page, fill=PAPER_COLOR)
        # During development, draw the template scan as background
        # Set z-azis != 0, to make floating elements not get stuck at the background
        if SHOW_TEMPLATE:
            newImage(ATF_PATH, x=0, y=0, z=-10, w=W, parent=page)
        
        # Centered title: family name and style name of the current font.
        titleBs = context.newString(pageTitle, 
                                    style=dict(font=font.path, xTextAlign=CENTER, textFill=0))
        titleBox = newTextBox(titleBs, parent=page, h=2*L,  
                   conditions=[Top2Top(), Fit2Width()],
                   fill=DEBUG_COLOR0)
        titleBox.solve()
        
        largeSampleBox = newTextBox('', parent=page, w=C1+G/2, 
                   conditions=[Float2Top(), Left2Left(), Fit2Bottom()],
                   fill=DEBUG_COLOR1)
        largeSampleBox.solve()

        # In order to fit different words in the fixed space, they will vary in size.
        # But as the variation in sizes is larger than the variation in size, we'll calculate the strings
        # first for the various word lengths and then sort them by size.
        largeSampleSizes = {}
        for n in (4, 5, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10):
            word = getCapitalizedWord(n)
            if word is None:
                continue
            if len(largeSampleSizes) > 10:
                break
            sample = context.newString(word+'\n', style=dict(font=font.path, rLeading=1), w=C1, pixelFit=False)
            sampleFontSize = int(round(sample.fontSize))
            if not sampleFontSize in largeSampleSizes:
                largeSampleSizes[sampleFontSize] = sample                
        print sorted(largeSampleSizes.keys())
           
        largeSample = context.newString('')
        for sampleFontSize, sample in sorted(largeSampleSizes.items(), reverse=True):
            label = context.newString('%d Points\n' % round(sampleFontSize), style=labelStyle)
            #if largeSample.h + sample.h > largeSampleBox.h:
            #    break
            largeSample += label + sample  
            
        largeSampleBox.setText(largeSample)        
        for fontSize, numChars in ((12, 8), (10, 13), (8, 16)):        
            smallSamples = context.newString(getCapWord(numChars), style=dict(font=font.path), w=C2)
            label = context.newString('%d Points\n' % round(smallSamples.fontSize), style=labelStyle)
            shortWordsSample = context.newString(getShortWordText(), 
                        style=dict(font=font.path, fontSize=smallSamples.fontSize, rLeading=1))
            newTextBox(label + smallSamples + ' ' + shortWordsSample, parent=page, w=C2+G/2, h=80, ml=G/2, mb=L,
                       conditions=[Right2Right(), Float2Top(), Float2Left()],
                       fill=DEBUG_COLOR1)
                       
            label = context.newString('%d Points\n' % fontSize, style=labelStyle)
            smallSamples = context.newString(blurb.getBlurb('article', noTags=True), 
                                             style=dict(font=font.path, fontSize=fontSize))
            newTextBox(label + smallSamples, parent=page, w=C2-2, h=80, mb=L, ml=G/2,
                       conditions=[Right2Right(), Float2Top()], 
                       fill=DEBUG_COLOR1)

        glyphSetFrame = newRect(parent=page, mb=L, ml=G/2, padding=L,
                                borders=dict(line=INLINE, stroke=0, strokeWidth=0.5), 
                                conditions=[Right2Right(), Float2Top(), Float2Left(), 
                                            Fit2Right(), Fit2Bottom()], 
                                fill=DEBUG_COLOR2)
        
        glyphSet = context.newString('Subset of characters in Complete Font\n', 
            style=dict(font=font.path, fontSize=8, xTextAlign=CENTER,
            rParagraphTopSpacing=0.25,
            rParagraphBottomSpacing=0.5))
        glyphSet += context.newString(GLYPH_SET, 
            style=dict(font=font.path, fontSize=23, xTextAlign=CENTER, leading=32))
        newTextBox(glyphSet, parent=glyphSetFrame, padding=(1.5*L, L, L, L),
                             borders=dict(line=INLINE, stroke=0, strokeWidth=0.25), 
                             conditions=[Left2Left(), Fit2Right(), Top2Top(), 
                             Fit2Bottom() ], 
                             fill=DEBUG_COLOR3)
        
        pn += 1
    return pn
예제 #21
0
def makeDocument():
    u"""Make a new document."""

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

    view = doc.getView()
    view.padding = 10 # Don't show cropmarks and such.
    view.showPageCropMarks = True
    view.showElementOrigin = ShowOrigin
    view.showElementDimensions = False
    view.showElementInfo = ShowElementInfo

    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.margin = 0
    page.padding = SQ

    pageArea = PageSize-2*SQ
    print PageSize, pageArea, SQ

    # Make new container for adding elements inside with alignment.
    newRect(z=10, w=pageArea, h=pageArea, fill=(0.8, 0.8, 0.8, 0.4),
            parent=page, margin=0, padding=0, yAlign=MIDDLE,
            maxW=pageArea, maxH=pageArea,
            xAlign=CENTER, stroke=None, conditions=(Center2Center(),
                                                    Middle2Middle()))

    fontSize = RedHeight/3
    fs = doc.context.newString('Headline in red box.',
                               style=dict(textFill=1,
                                          fontSize=fontSize,
                                          maxW=pageArea,
                                          maxH=pageArea,
                                          leading=fontSize,
                                          font='LucidaGrande'))
    newTextBox(fs, z=0, w=RedWidth, h=RedHeight, name='RedRect',
               parent=page, fill=(1, 0.1, 0.1),
               yAlign=TOP, maxW=pageArea, maxH=pageArea,
               padding=4, conditions=(Center2Center(),
                                      Top2Top()))

    if not hasattr(scriptGlobals, 'blurbText'):
        scriptGlobals.blurbText = blurb.getBlurb('article_summary',
                                                 noTags=True)
    fs = doc.context.newString('Headline of formatted text.\n',
                               style=dict(font='LucidaGrande-Bold',
                                          fontSize=12,
                                          leading=14,
                                          textFill=0))
    fs += doc.context.newString(scriptGlobals.blurbText,
                                style=dict(font='LucidaGrande',
                                           fontSize=10,
                                           leading=12,
                                           textFill=0))
    newTextBox(fs, z=0, w=YellowWidth, h=YellowHeight, parent=page,
               padding=4, fill=0.7,
               maxW=pageArea, maxH=pageArea, conditions=(Left2Left(),
                                                         Float2Top()))
    
    newImage('images/cookbot10.jpg', z=0, w=BlueWidth,
             parent=page, fill=0.7, padding=8,
             maxW=pageArea, maxH=pageArea, conditions=(Right2Right(),
                                                       Float2Top()))

    newRect(z=0, w=BlueWidth, h=20,
            parent=page, fill=0.2, conditions=(Fit2Width(),
                                               Float2Top()))

    score = page.solve()
    if score.fails:
        print('Condition fails', score.fails)

    return doc # Answer the doc for further doing.
예제 #22
0
                                     align='left',
                                     fontSize=500))
w, _ = fittingWord.size
fittingSize = W/w*500
fittingWord = context.newString('ABC\n',
                          style=dict(font='BitcountMonoDouble-RegularCircle',
                                     align='left',
                                     fontSize=fittingSize,
                                     lineHeight=fittingSize))
fs += fittingWord

doc = Document(w=W+G*2, h=H + G*2, autoPages=1)
view = doc.view

page = doc[1]
myTextBox = newTextBox(fs, x=G, y=G, w=W, h=H, parent=page)
#myTextBox._drawBaselines(showIndex=True, showY=True, showLeading=True)

"""
FIX
for pattern in myTextBox.findPattern('Find'):
    #print(pattern)
    px = pattern.x
    py = pattern.y
    print(pattern)
    print(px, py[1])
    context.stroke(1, 0, 0)
    context.fill(None)
    context.oval(px-10, py[1]-10, 20, 20)

# Bitcount measures, pixels are 1/10 of Em
예제 #23
0
                                style=dict(
                                    font='BitcountMonoDouble-RegularCircle',
                                    align='left',
                                    fontSize=500))
w, _ = context.textSize(fittingWord)
fittingSize = W / w * 500
fittingWord = context.newString('ABC\n',
                                style=dict(
                                    font='BitcountMonoDouble-RegularCircle',
                                    align='left',
                                    fontSize=fittingSize,
                                    lineHeight=fittingSize))
fs += fittingWord

context.newPage(W + G * 2, H + G * 2)
myTextBox = newTextBox(fs, x=G, y=G, w=W, h=H)
myTextBox.draw()
myTextBox._drawFrame()
myTextBox._drawBaselines(showIndex=True, showY=True, showLeading=True)

for pattern in myTextBox.findPattern('Find'):
    #print(pattern)
    px = pattern.x
    py = pattern.y
    print(pattern)
    print(px, py[1])
    context.stroke(1, 0, 0)
    context.fill(None)
    context.oval(px - 10, py[1] - 10, 20, 20)

# Bitcount measures, pixels are 1/10 of Em
예제 #24
0
doc = Document(w=W, h=H, originTop=False)
t = doc.context.newString('TEXT',
                          style=dict(font=font,
                                     fontSize=36,
                                     textFill=whiteColor,
                                     xTextAlign=CENTER))
PADDING = t.size[0]

page = doc[1]  # Get the single page from te document.
page.padding = PADDING

page.showPadding = True

newTextBox(t,
           parent=page,
           fill=color('red'),
           conditions=[Right2Left(), Top2Bottom()])
newTextBox(t,
           parent=page,
           fill=color('green'),
           conditions=[Center2Center(), Bottom2Top()])
newTextBox(t,
           parent=page,
           fill=color('blue'),
           conditions=[Left2Right(), Bottom2Top()])
newTextBox(t,
           parent=page,
           fill=color('orange'),
           conditions=[Right2Left(), Middle2Middle()])
newTextBox(t,
           parent=page,
예제 #25
0
view.showPadding = True  # Show the padding of the page. The size is then (page.pw, page.ph)
view.showOrigin = False  # No origin showing

page = doc[1]  # Get the first (and only) page of the document

# Define the style dictionary fir the main text.
style = dict(name='body', font='Verdana', fontSize=pt(12), leading=em(1.4))
conditions = [Fit()
              ]  # Fitting conditions for the text box on (page.pw, page.ph)

# Create a new text box and set the view-parameres, so they angue for today.
tb = newTextBox(
    text * 5,
    parent=page,
    stroke=0.5,
    strokeWidth=0.5,
    style=style,
    conditions=conditions,
    baselineColor=color(1, 0, 0),  # Show baselines and indices in red.
    showBaselines=[BASE_LINE_BG,
                   BASE_INDEX_RIGHT])  # Define type of baseline view.

# Make the text box fit to the page padding, solving position and size.
doc.solve()

# Adjust vertical position of the fitting textbox, so that textLines[4]
# locks on page baseline.
lineIndex = 4
#print(tb.x, tb.y)
tb.y += tb.baselineOffset(lineIndex)
#print(tb.y)
# Add lines to indicate to position where the text box and grid match up.
예제 #26
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.
예제 #27
0
def addTitle(page, context, title):
    style = {'font': boldFont.path, 'fontSize': HEADSIZE}
    bs = context.newString(title, style=style)
    newTextBox(bs, parent=page, w=W/2, conditions=[Right2RightSide(),
        Top2Top()])
예제 #28
0
def makeBanner(bd):
    w, h = bd['w'], bd['h']
    imagePaths = bd['imagePaths']
    labelSize = bd['labelSize']
    title1 = bd['title1']
    title2 = bd['title2']
    title3 = bd['title3']
    sideImage = bd['sideImage']
    titleSize = bd['titleSize']
    L1 = bd['l1']
    L2 = bd['l2']
    padding = bd['padding']
    type = bd['type']

    context = getContext()
    context.newDrawing()
    # 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,
                   title=title1,
                   autoPages=FRAMES,
                   context=context,
                   originTop=False)  # One page, just the cover.

    for pn in range(1, FRAMES + 1):
        page = doc[pn]  # Get the first/single page of the document.

        page.frameDuration = 0.75

        imagePath, imageConditions = imagePaths[0]
        # Background image of the slide
        im = newImage(PATH + imagePath,
                      y=h / FRAMES * (pn - 1),
                      conditions=imageConditions,
                      parent=page)
        newImage(PATH + imagePath,
                 y=h / FRAMES * (pn - 1) - 2 * im.h,
                 conditions=imageConditions,
                 parent=page)
        newImage(PATH + imagePath,
                 y=h / FRAMES * (pn - 1) - im.h,
                 conditions=imageConditions,
                 parent=page)
        newImage(PATH + imagePath,
                 y=h / FRAMES * (pn - 1) + im.h,
                 conditions=imageConditions,
                 parent=page)
        newImage(PATH + imagePath,
                 y=h / FRAMES * (pn - 1) + 2 * im.h,
                 conditions=imageConditions,
                 parent=page)

        ww75 = w * 0.75
        ww25 = w * 0.25
        bs = context.newString('Type@Cooper\nTypographics',
                               style=dict(font=fontRegular.path,
                                          fontSize=w / 30,
                                          xTextAlign=CENTER,
                                          textFill=1,
                                          rLeading=1.05,
                                          rTracking=0.02))
        tw, th = bs.textSize()
        newRect(fill=(0.15, 0.17, 0.15, 0.7),
                w=ww75,
                conditions=(Fit2HeightSides(), Right2RightSide()),
                parent=page)
        newTextBox(bs,
                   parent=page,
                   h=th + P,
                   w=ww25,
                   padding=(P / 2, P, 0, P),
                   fill=(1, 0, 0),
                   conditions=(Left2LeftSide(), Top2TopSide()))

        # Show design measures
        m = padding * 2
        m2 = m / 2
        m4 = m / 4
        designProcess = newGroup(x=0,
                                 y=0,
                                 fill=(0.3, 0.32, 0.3, 0.7),
                                 w=ww25,
                                 h=h - th - P,
                                 padding=padding,
                                 parent=page)
        design = newImage(PATH + sideImage,
                          y=padding,
                          h=h - th - P - 2 * padding,
                          fill=None,
                          conditions=[Center2Center()],
                          parent=designProcess)
        designProcess.solve()

        if pn > 1:  # Horizontal frame
            newLine(x=design.x - m4,
                    y=design.y,
                    w=design.w + m2,
                    h=0,
                    fill=None,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
            newLine(x=design.x - m4,
                    y=design.y + design.h,
                    w=design.w + m2,
                    h=0,
                    fill=None,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn > 2:  # Vertical frame
            newLine(x=design.x,
                    y=design.y - m4,
                    w=0,
                    h=design.h + m2,
                    fill=None,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
            newLine(x=design.x + design.w,
                    y=design.y - m4,
                    w=0,
                    h=design.h + m2,
                    fill=None,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn == 4:  # Diagonal
            newLine(x=design.x,
                    y=design.y,
                    w=design.w,
                    h=design.h,
                    fill=None,
                    stroke=(1, 0, 0),
                    strokeWidth=L2,
                    parent=designProcess)
            newLine(x=design.x + design.w,
                    y=design.y,
                    w=-design.w,
                    h=design.h,
                    fill=None,
                    stroke=(1, 0, 0),
                    strokeWidth=L2,
                    parent=designProcess)
        if pn > 5:  # V-lines
            newLine(x=design.x + design.w / 2,
                    y=design.y - m4,
                    w=0,
                    h=design.h + m2,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn > 6:  # V-lines
            newLine(x=design.x + design.w * 0.35,
                    y=design.y - m4,
                    w=0,
                    h=design.h + m2,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn > 7:  # V-lines
            newLine(x=design.x + design.w * 0.92,
                    y=design.y - m4,
                    w=0,
                    h=design.h + m2,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn == 9:  # H-lines 1/2
            newLine(x=design.x - m2,
                    y=design.y + design.h * 0.5,
                    w=design.w + 2 * m2,
                    h=0,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn > 9:  # H=lines
            newLine(x=design.x - m2,
                    y=design.y + design.h * 0.53,
                    w=design.w + 2 * m2,
                    h=0,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
            newLine(x=design.x - m2,
                    y=design.y + design.h * 0.59,
                    w=design.w + 2 * m2,
                    h=0,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn > 10:  # H=lines
            newLine(x=design.x - m2,
                    y=design.y + design.h * 0.24,
                    w=design.w + 2 * m2,
                    h=0,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn > 11:  # H=lines
            newLine(x=design.x - m2,
                    y=design.y + design.h * 0.655,
                    w=design.w + 2 * m2,
                    h=0,
                    stroke=1,
                    strokeWidth=L1,
                    parent=designProcess)
        if pn > 12:  # Diagonal
            newLine(x=design.x,
                    y=design.y,
                    w=design.w,
                    h=design.h * 0.53,
                    fill=None,
                    stroke=(1, 0, 0),
                    strokeWidth=L2,
                    parent=designProcess)
            newLine(x=design.x + design.w,
                    y=design.y,
                    w=-design.w,
                    h=design.h * 0.53,
                    fill=None,
                    stroke=(1, 0, 0),
                    strokeWidth=L2,
                    parent=designProcess)
        if pn > 13:  # Diagonal
            newLine(x=design.x,
                    y=design.y + design.h * 0.59,
                    w=design.w,
                    h=design.h - design.h * 0.59,
                    fill=None,
                    stroke=(1, 0, 0),
                    strokeWidth=L2,
                    parent=designProcess)
            newLine(x=design.x + design.w,
                    y=design.y + +design.h * 0.59,
                    w=-design.w,
                    h=design.h - design.h * 0.59,
                    fill=None,
                    stroke=(1, 0, 0),
                    strokeWidth=L2,
                    parent=designProcess)

        C0 = 1
        C1 = C2 = (0, 1, 0.1, 0.95)
        if pn > 10:
            C2 = C0

        if type == 'Small':
            bs = context.newString(title1 + '\n',
                                   style=dict(font=fontMedium.path,
                                              textFill=C0,
                                              fontSize=w / 20,
                                              rTracking=0.015,
                                              rLeading=1.25))
            bs += context.newString(title2 + '\n',
                                    style=dict(font=fontBook.path,
                                               textFill=C1,
                                               fontSize=w / 20,
                                               rLeading=1.2,
                                               rTracking=0.03))
            if title3 is not None:
                bs += context.newString(title3 + '\n',
                                        style=dict(font=fontRegular.path,
                                                   textFill=1,
                                                   fontSize=w / 30,
                                                   rLeading=1.2,
                                                   rTracking=0.03))
            bs += context.newString(
                'By DrawBot + PageBot + Petr van Blokland, June 17th',
                style=dict(font=fontRegular.path,
                           textFill=C2,
                           fontSize=w / 33,
                           rTracking=0.030,
                           rLeading=1.8))
            newTextBox(bs,
                       parent=page,
                       x=ww25,
                       y=0,
                       padding=(w / 30, 0, 0, w / 30),
                       w=ww75 + w / 100,
                       conditions=[Fit2HeightSides()])
        else:
            bs = context.newString(title1 + '\n',
                                   style=dict(font=fontMedium.path,
                                              textFill=C0,
                                              fontSize=w / 20,
                                              rTracking=0.015,
                                              rLeading=1.25))
            bs += context.newString(title2 + '\n',
                                    style=dict(font=fontBook.path,
                                               textFill=C1,
                                               fontSize=w / 20,
                                               rLeading=1.2,
                                               rTracking=0.03))
            if title3 is not None:
                bs += context.newString(title3 + '\n',
                                        style=dict(font=fontRegular.path,
                                                   textFill=1,
                                                   fontSize=w / 27,
                                                   rLeading=1.2,
                                                   rTracking=0.03))
            bs += context.newString(
                'By DrawBot + PageBot + Petr van Blokland, June 17th',
                style=dict(font=fontRegular.path,
                           textFill=C2,
                           fontSize=w / 33,
                           rTracking=0.030,
                           rLeading=1.8))
            newTextBox(bs,
                       parent=page,
                       x=ww25,
                       y=0,
                       padding=(w / 30, 0, 0, w / 30),
                       w=ww75 + w / 100,
                       conditions=[Fit2HeightSides()])

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

    # Evaluate again, result should now be >= 0
    return doc
예제 #29
0
# In multipage documents this also can be done in the document, so pages inherit.
page.padding = PAD, PAD, 2 * PAD, PAD
# Create rectangles. Default position and size is (0, 0, 100, 100). The conditions define the layout.
newRect(fill=color(1, 0, 0),
        parent=page,
        h=pt(62),
        conditions=(Left2Left(), Float2Top(), Fit2Right()))
newRect(fill=color(1, 0, 1),
        parent=page,
        conditions=(Left2LeftSide(), Float2Top()))
newRect(fill=color(spot=300),
        parent=page,
        conditions=(Right2Right(), Float2Top(), Float2Left(), Fit2Right()))

# Add a floating text box.
newTextBox('BB',
           parent=page,
           x=100,
           y=150,
           w=300,
           h=400,
           fill=color(spot=400),
           fontSize=p(8),
           font='Verdana',
           textFill=color(spot=120))

# Solve the conditions of the layout in defined order.
doc.solve()
# Export to PDF.
doc.export('_export/SimpleDocument.pdf')
BASELINE_GRID = pt(48)

font = findFont('PageBot-Regular')

doc = Document(w=W, h=H, originTop=False,
    baselineGrid=BASELINE_GRID)
view = doc.view
view.showPadding = True # Show padding and margin on page

page = doc[1] # Get the single page from te document.
page.margin = page.bleed = MARGIN
page.padding = PADDING
page.showBaselineGrid = True

# Condition alignment takes the element margin into account.
style = dict(font=font, fontSize=100, textFill=(1, 0, 0))
bs = doc.context.newString('Hkpx', style=style)
newTextBox(bs, parent=page, fill=color(0.7, 0.7, 0.7, 0.3), 
    w=300, h=300, showMargin=True, showPadding=True, 
    margin=MARGIN, padding=PADDING, showBaselineGrid=True,
    conditions=[Right2Right(), Top2Top(), BaselineDown2Grid()])

page.solve()

# Export in _export folder that does not commit in Git. 
# Force to export PDF.
EXPORT_PATH = '_export/TextBoxBaselinePaddingMargin.pdf'
doc.export(EXPORT_PATH)