Ejemplo n.º 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)

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

    textBoxStyle = doc.addStyle('textbox', dict(fill=(0, 0, 0, 0.7),
                                                padding=40))
    pStyle = doc.addStyle('p', dict(textFill=0))
    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.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 = newFS('Headline\n', style=h1Style)
    for n in range(10):
        s += newFS(
            '(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,
        maxW=W - 2 * PagePadding,
        minW=100,
        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=0,
        strokeWidth=0.5,
        fill=0.9,
        stroke=None,
    )
    print e1.style

    e2 = 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,
        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.
Ejemplo n.º 2
0
def makeDocument():
    u"""Make a new document."""
    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)

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

    padding = 12

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

    BODY_FONT = 'BitcountMonoDouble-RegularCircle'

    fs = doc.context.newString('TYPETR',
                               w=W - padding * 2,
                               style=dict(font=BODY_FONT,
                                          fontSize=56,
                                          leading=0,
                                          textFill=0))
    fs += doc.context.newString("""
Petr van Blokland
Designer|Lecturer|Developer

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

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

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

    return doc  # Answer the doc for further doing.
Ejemplo n.º 3
0
page['Column'].setText(context.newText(specimenText2))
page['PageNumber'].setText(68)
bs = page['Column'].getOverflow()

page = doc[4]
page.applyTemplate(tmp)
newTextBox('',
           parent=page,
           conditions=[Fit2Width(), Bottom2Bottom()],
           name='FootNotes',
           h=48)
page['Column'].setText(bs)
page['PageNumber'].setText(69)

# Views define the way documents are exported.
# Add space for cropmarks and registrations marks
view = doc.getView()
view.padding = 0
view.showPageNameInfo = True
view.showPagePadding = False  # No need, as we are drawing the grid
view.showPageCropMarks = True
view.showPageRegistrationMarks = True
view.showPageFrame = True
view.showGrid = False

view.style['viewGridStroke'] = (0, 0, 1)
view.style['viewGridStrokeWidth'] = 0.5

doc.solve()

doc.export(EXPORT_PATH)
Ejemplo n.º 4
0
def makeDocument():
    """Make a new document."""

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

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

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

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

    return doc  # Answer the doc for further doing.