Example #1
0
def testContext(context, path):
    doc = Document(w=W, h=H, context=context)
    page = doc[1]
    #print('Current page: %s' % page)
    nextPage = page.next
    #print('Next page: %s' % nextPage)
    #print(type(page))
    #print('Units: %s' % context.units)
    #print('# Testing document in %s' % context)
    conditions = [Right2Right(), Float2Top(), Float2Left()]

    for n in range(10):
        newLine(x=100, y=n * 100, parent=page, stroke=0)

    for n in range(10):
        newRect(w=40,
                h=42,
                mr=4,
                mt=4,
                parent=nextPage,
                fill=color(random() * 0.5 + 0.5, 0, 0.5),
                conditions=conditions)
    score = nextPage.solve()
    #print(score)
    doc.build()  # Export?
Example #2
0
def makeDocument():
    # Creates the publication/document that holds the pages.
    doc = Document(w=W, h=H, originTop=False, autoPages=1)

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

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

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

    # Recursively solve the conditions in all pages.
    # If there are failing conditions, then the status
    # is returned in the Score instance.
    score = doc.solve()
    doc.build()
Example #3
0
def showPaths():
    context = getContext()
    doc = Document(w=W, h=H, originTop=False, autoPages=1, context=context)
    page = doc[1]

    c = (Fit2Right(), Left2Left(), Float2Top())
    f = findFont('PageBot-Regular')

    # FIXME: text disappears with padding.
    #t = newText('bla', font='Helvetica', parent=page, conditions=c, fontSize=200, padding=1)

    # FIXME: causes scaling unit error.
    #path = newPageBotPath(context=context)
    #path.text('ABCD', style=dict(font=f, fontSize=30, fill=(0, 1, 0)))
    #newPaths(path, parent=page, fill=(0, 1, 1), conditions=c, stroke=None)

    rootPath = getRootPath()
    s = dict(fontSize=24, font=f)
    msg = 'Root path is %s' % rootPath
    bs = page.newString(msg, style=s)
    makeText(bs, page, c)
    resourcesPath = getResourcesPath()
    msg = 'Resources path is %s' % resourcesPath
    bs = page.newString(msg, style=s)
    makeText(bs, page, c)
    print(glob.glob('%s/*' % resourcesPath))
    defaultFontPath = getDefaultFontPath()
    msg = 'Default font path is %s' % defaultFontPath
    bs = page.newString(msg, style=s)
    makeText(bs, page, c)
    page.solve()
    doc.build()
Example #4
0
def test(context):
    print("creating doc")
    doc = Document(w=W, h=H, context=context)
    doc.name = 'TextBoxes-%s' % doc.context.name
    print('# Testing text boxes in %s' % doc)

    page = doc[1]
    #s = getString(page)
    blurb = Blurb()
    txt = blurb.getBlurb('stylewars_bluray')

    i = len(txt.split('. ')[0]) + 1

    style = {'font': bungeeRegular, 'fontSize': 24, 'leading': 1.5}
    s = page.newString(txt[0:i], style=style)

    style = {'font': bungeeOutline, 'fontSize': 24, 'leading': 1.5}
    s += page.newString(txt[i:], style=style)

    w = W / 2 - 2 * M
    h = 460  #H - 2*M
    x = M
    y = H - M - h

    sc = color(0.3, 0.2, 0.1, 0.5)
    tb = newTextBox(s, x=x, y=y, w=w, h=h, parent=page, stroke=sc)
    y0 = H - M
    drawBaselines(x, y0, w, tb.baselines, s, page)

    # Get the rest of the text.
    txt = tb.getOverflow()
    style = {'font': pageBotBold, 'fontSize': 24, 'leading': 1.5}
    s = page.newString(txt, style=style)

    w = W / 2 - 2 * M
    h = 240  #H - 2*M
    x = M
    y = M

    tb = newTextBox(s, x=x, y=y, w=w, h=h, parent=page, stroke=sc)
    y0 = M + h
    drawBaselines(x, y0, w, tb.baselines, s, page)

    # Get the rest of the text.
    txt = tb.getOverflow()
    style = {'font': robotoRegular, 'fontSize': 24, 'leading': 1.5}
    s = page.newString(txt, style=style)

    h = 500
    x = W / 2
    y = M
    w = W / 2 - M
    tb = newTextBox(s, x=x, y=y, w=w, h=h, parent=page, stroke=sc)
    y0 = M + h
    drawBaselines(x, y0, w, tb.baselines, s, page)

    print('Starting doc build')
    doc.build()
Example #5
0
def showFilePaths():
    # Get the context that this script runs in, e.g. DrawBotApp.
    context = getContext('Flat')

    # Make a Document instance for this size and context, intializing one page.
    doc = Document(w=W, h=H, originTop=False, autoPages=1, context=context)

    # Get the page.
    page = doc[1]

    # Make a set of conditions for the element positions of this page.
    c = (Left2Left(), Fit2Right(), Float2Top())

    # Find the demo font, as supplied with the PageBot library installation.
    # This is a subset of TYPETR Upgrade Regular.
    f = findFont('PageBot-Regular')

    rootPath = getRootPath()  # Location of this PageBot library
    style = dict(fontSize=14, font=f)
    msg = 'Root path is %s' % rootPath
    bs = page.newString(msg, style=style)
    makeText(bs, page, f, c)

    resourcesPath = getResourcesPath()
    msg = 'Resources path is %s' % resourcesPath
    bs = page.newString(msg, style=style)
    makeText(bs, page, f, c)
    #print(glob.glob('%s/*' % resourcesPath))

    defaultFontPath = getDefaultFontPath()
    msg = 'Default font path is %s' % defaultFontPath
    msg = '\n\t'.join(msg.split('/'))
    bs = page.newString(msg, style=style)
    c = (Right2Right(), Float2Top())
    e = makeText(bs, page, f, c)
    e.w = page.pw / 2 - 2 * GUTTER
    e.mr = 0

    msg = 'PageBot font path is %s' % f.path
    msg = '\n\t'.join(msg.split('/'))
    bs = page.newString(msg, style=style)
    c = (Left2Left(), Float2Top())
    e = makeText(bs, page, f, c)
    e.w = page.pw / 2 - 2 * GUTTER

    # Let the page solve all of its child element layout conditions.
    page.solve()
    doc.build()
Example #6
0
def makeDocument():
    # Creates the publication/document that holds the pages.
    doc = Document(w=W, h=H, originTop=False, autoPages=1)
    print(doc.view)
    print(doc.pages)

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

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

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

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

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

    from pagebot import getContext
    context = getContext()

    for r in rects:
        x = r.getFloatLeftSide() + doc.view.pr
        y = r.getFloatTopSide() + doc.view.pt
        context.fill((0, 1, 0))
        context.circle(x, y, 2)
Example #7
0
def showAll():
    context = getContext()
    doc = Document(w=W, h=H, originTop=False, autoPages=1, context=context)
    page = doc[1]
    print(page.view.margin)
    c1 = (Fit2Right(), Left2Left(), Float2Top())
    c2 = (Left2Left(), Top2Top())
    c3 = (Float2Left(), Top2Top())

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

    for pbFont in sorted(pbFonts.keys()):
        if 'Bungee' in pbFont or 'PageBot' in pbFont:
            i += 1
            g = newGroup(parent=page, conditions=c1, padding=7)
            newText('%s\n' % pbFont, parent=g, conditions=c2, fontSize=16)
            f = findFont(pbFont)
            path = PageBotPath(context=context)
            path.text(' ABCDEF0123456789', style=dict(font=f, fontSize=pt(42)))
            path = path.removeOverlap()
            newPaths(path, parent=g, conditions=c3, margin=20, fill=0)
        if i > 10:
            break

    page.solve()
    doc.build()
Example #8
0
def test():
    doc = Document(w=W, h=H)
    print(doc.pages)
    print(len(doc))
    page = doc[1]
    print('# Testing text boxes in %s' % doc)
    # Create a new BabelString with the DrawBot FormttedString inside.
    style=dict(font=roboto, fontSize=40, textFill=(1, 0, 0))
    bs = page.newString('This is a string', style=style)

    # Adding or appending strings are added to the internal formatted string.
    # Adding plain strings take over the existing style.
    bs += ' and more,'
    
    # Reusing the same style different text fill color.
    style['textFill'] = 0.1, 0.5, 0.9
    bs += page.newString(' more and', style=style)

    # Different color and weight.
    style['textFill'] = 0.5, 0, 1
    style['font'] = robotoBold
    bs += page.newString(' even more!', style=style)
    tb = newTextBox(bs, x=M, y=H-M, w=W-2*M, h=2*M, parent=page, stroke=color(0.3, 0.2, 0.1, 0.5), style=dict(hyphenation=True, language='en', leading=200))

    style = dict(font=bungee, fontSize=pt(bungeeSize))
    bs = page.newString(txt, style=style)

    tb = newTextBox(bs, x=M, y=H-5*M, w=W/2, h=300, parent=page, stroke=color(0.3, 0.2, 0.1, 0.5), style=dict(hyphenation=True, language='en', leading=200))
 
    for baseline in tb.baselines:
        s = dict(stroke=color(1, 0, 0))
        newLine(x=M, y=H-5*M-baseline, w=W/2, h=0, style=s, stroke=color(0.5), strokeWidth=0.5, parent=page)
    #doc.view.drawBaselines()
    #doc.export('_export/Strings.pdf')
    print(doc.pages)
    print(len(doc))
    doc.build()
Example #9
0
def testContext(context, path):
    doc = Document(w=W, h=H, context=context, autoPages=1)
    page = doc[1]

    #print('Units: %s' % context.units)
    #context.newDocument(W, H)
    print('# Testing strings in %s' % context)
    #context.newPage(W, H)
    # Create a new BabelString with the DrawBot FormttedString inside.
    style = dict(font=roboto, fontSize=40, textFill=(1, 0, 0))
    bs = context.newString('This is a string', style=style)
    # It prints its contents.
    #print(' - Is a BabelString: %s' % isinstance(bs, BabelString))
    #print(' - Is a DrawBotString: %s' % isinstance(bs, DrawBotString))
    #print(' - Is a FlatString: %s' % isinstance(bs, FlatString))
    #print(' - Is an InDesignString: %s' % isinstance(bs, FlatString))
    #print(bs)

    # Adding or appending strings are added to the internal formatted string.
    # Adding plain strings take over the existing style.
    bs += ' and more,'
    #print(bs)

    # Reusing the same style different text fill color.
    style['textFill'] = 0.1, 0.5, 0.9
    bs += context.newString(' more and', style=style)

    # Different color and weight.
    style['textFill'] = 0.5, 0, 1
    style['font'] = robotoBold
    bs += context.newString(' even more!', style=style)
    context.text(bs, (M, H - 2 * M))
    #tb = newTextBox(bs, context=context, x=M, y=H-M, w=W/2, h=300, parent=page, stroke=color(0.3, 0.2, 0.1, 0.5), style=dict(hyphenation=True, language='en', leading=200))

    style = dict(font=bungee, fontSize=pt(bungeeSize))
    bs = context.newString(txt, style=style)

    # Usage in DrawBot by addressing the embedded FS for drawing.
    #context.text(bs, (M, H- 4*M))
    capHeight = bungee.info.capHeight
    upem = bungee.info.unitsPerEm
    h = capHeight / upem * bungeeSize
    context.stroke((0, 1, 0))
    context.strokeWidth(0.1)
    context.rect(x=M, y=H - 4 * M, w=pt(400), h=h)
    #context.saveImage(path)

    #print(doc.view.context == context)
    #bs.style['baselineShift'] = 20
    #print(bs.style)
    #context.baselineShift(20)

    style = dict(font=bungee, fontSize=pt(bungeeSize), baselineShift=6)
    bs = context.newString(txt, style=style)

    tb = newTextBox(bs,
                    context=context,
                    x=M,
                    y=H - 10 * M,
                    w=W / 2,
                    h=300,
                    parent=page,
                    stroke=color(0.3, 0.2, 0.1, 0.5),
                    style=dict(hyphenation=True, language='en', leading=200))

    #for line in tb.textLines:
    #    print(line.string)
    #rs = getRootStyle()
    #print(rs.keys())

    context.stroke((1, 0, 0))
    context.fill(None)

    for baseline in tb.baselines:
        s = dict(stroke=color(1, 0, 0))
        newLine(x=M,
                y=H - 10 * M - baseline,
                w=W / 2,
                h=0,
                style=s,
                stroke=color(0.5),
                strokeWidth=0.5,
                parent=page)

    #doc.view.drawBaselines()
    #print(doc.pages[1][0].elements)
    doc.build()
    drawLines(page)
Example #10
0
for i in range(1, int(W / SQ) + 1):
    GRIDX.append((pt(SQ)))

for i in range(1, int(H / SQ) + 1):
    GRIDY.append((pt(SQ)))

for contextName in ['DrawBot', 'Flat']:
    context = getContext(contextName)
    doc = Document(w=W, h=H, padding=30, context=context, originTop=False)
    doc.name = 'Grid-%s' % contextName
    page = doc[1]
    page.padding = (SQ, SQ, SQ, SQ)
    doc.gridX = GRIDX
    doc.gridY = GRIDY
    print(' * %s' % doc.name)
    doc.view.showGrid = True
    doc.view.showOrigin = True
    doc.view.showDimensions = True
    doc.view.showNameInfo = True
    doc.view.showColorBars = True
    #doc.view.showFrame = True
    #doc.view.showPadding = True
    #doc.view.showMargin = True
    #doc.view.showRegistrationMarks = True
    #style = getRootStyle()
    #print(doc.view.padding)
    #print(doc.view.margin)
    #print(page.view.padding)
    doc.solve()
    doc.build()