Exemplo n.º 1
0
def addImage(page, context, src):
    newImage(src,
        parent=page, 
        w=(W-COL_GUTTER)/2, 
        h=(H-IMG_GUTTER)/2,
        conditions=[Left2LeftSide(), Float2TopSide()], 
        mt=IMG_GUTTER, 
        scaleImage=False,
    )
def makeDocument(families):
    u"""Create the main document in the defined size with a couple of automatic empty pages."""
    # Calculate the amount of pages to create
    numPages = 1  # Add one page for the original page scan.
    for family in families:
        numPages += len(family)  # Length of the family is the amount of fonts.
    numPages = min(numPages, MAX_PAGES - 1)

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

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

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

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

    doc.solve()

    return doc
Exemplo n.º 3
0
def makeDocument(font):
    u"""Create the main document in the defined size with a couple of automatic empty pages."""

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

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

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

    print(doc.solve())

    return doc
Exemplo n.º 4
0
def makeDocument(families):
    u"""Create the main document in the defined size with a couple of automatic empty pages."""
    # Calculate the amount of pages to create
    numPages = len(families) + 1  # One family per spread.

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

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

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

        buildSpecimenPages(page, family)

    doc.solve()

    return doc
Exemplo n.º 5
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()
Exemplo n.º 6
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()
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
Exemplo n.º 8
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.
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
Exemplo n.º 10
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
Exemplo n.º 11
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,
    )
Exemplo n.º 12
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
Exemplo n.º 13
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.