Exemplo n.º 1
0
 def buildPages(self, doc):
     # Build the pages, showing axes, samples, etc.
     # Using the first page as cover (to be filled...)
     page = doc[1]
     glyphName = 'A'        
     scatter = VariableCircle(decovar, point=(50, 100), w=500, h=500, s=glyphName)
     page.append(scatter)
Exemplo n.º 2
0
    def buildPages(self, doc, varFont):
        # Build the pages, showing axes, samples, etc.
        # Using the first page as cover (to be filled...)
        page = doc[0]
        page.applyTemplate(self.makeTemplate(doc.getRootStyle()))
        glyphName = 'A'

        newLine(parent=page, conditions=CONDITIONS, stroke=0, strokeWidth=0.25)
        newTextBox('', parent=page, conditions=CONDITIONS, eId=self.titleBoxId)
        newTextBox('',
                   parent=page,
                   conditions=CONDITIONS,
                   eId=self.specimenBoxId)
        newLine(parent=page, conditions=CONDITIONS, stroke=0, strokeWidth=0.25)
        newRect(fill=(1, 0, 0),
                w=300,
                h=400,
                conditions=CONDITIONS,
                parent=page)

        view = doc.getView()
        view.showElementOrigin = True
        view.showElementDimensions = False
        vce = VariableCircle(varFont,
                             conditions=CONDITIONS,
                             parent=page,
                             s=glyphName)
        newLine(parent=page, conditions=CONDITIONS, stroke=0, strokeWidth=0.25)

        score = page.solve()
        if score.fails:
            print score.fails
        print vce.x, vce.y, vce.w, vce.h
Exemplo n.º 3
0
def makeDocument(fontPath):
    u"""Make a new document."""

    f = Font(fontPath) # Get PageBot Font instance of Variable font.
   
    W = H = PageSize

    # Create a new document, default to the defined page size. 
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=1)
    
    view = doc.getView()
    view.padding = 0 # Aboid showing of crop marks, etc.
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPagePadding = True
    view.showElementOrigin = False
    view.showElementDimensions = False
    
    # Get list of pages with equal y, then equal x.    
    #page = doc[0][0] # Get the single page from te document.
    page = doc.getPage(0) # Get page on pageNumber, first in row (this is only one now).
    page.name = 'Page 1'
    page.padding = PagePadding
    
    fs = doc.context.newString(f.info.familyName + ' ' + f.info.styleName, 
                               style=dict(font=f.name,
                                          fontSize=18,
                                          textFill=0))
    _, th = textSize(fs)
    title = newTextBox(fs, conditions=[Top2Top(), Fit2Width()],
        parent=page, h=th*1.2)
    
    circle = VariableCircle(f, s=GLYPH_NAME, name='VariableCircleSpeciment',
        parent=page, padding=4, x=100, fontSize=64,
        maxW=W-2*PagePadding, minW=100, showAxisName=True,     
        # Conditions make the element move to top-left of the page.
        # And the condition that there should be no overflow, otherwise the text box
        # will try to solve it.     
        conditions=[Float2Top(), Fit2Bottom(), Center2Center()],
        # Position of the origin of the element. Just to show where it is.
        # Has no effect on the position conditions. 
        yAlign=BOTTOM, xAlign=LEFT, fill=CIRCLE_ELEMENT_FILL, borders=0,
    )
        
    score = doc.solve() # Try to solve all pages.
    if score.fails:
        print score.fails

    # To avoid circular dependent conditions, we correct the position of the title
    # on left to that the position of the circle has become.
    title.pl = circle.x - page.pl
    
    return doc # Answer the doc for further doing.
Exemplo n.º 4
0
def makeDocument(fontPath):
    u"""Create Document instance with a single page. Fill the page with elements
    and perform a conditional layout run, until all conditions are solved."""

    f = Font(fontPath) # Get PageBot Font instance of Variable font.
    fHeader = getVariableFont(f, dict(wght=0.5))
    fHeaderCondensed = getVariableFont(f, dict(wght=0.5, wdth=0.4))
    
    doc = Document(w=PageWidth, h=PageHeight, originTop=False, autoPages=1)
    # Get default view from the document and set the viewing parameters.
    view = doc.getView()
    view.style['fill'] = 1
    view.padding = 0 # To show cropmarks and such, make >40 or so.
    view.showPageCropMarks = True # Won't show if there is not padding in the view.
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPagePadding = True
    view.showPageNameInfo = True
    view.showElementOrigin = False
    view.showElementDimensions = False #ShowDimensions
    view.showElementInfo = False
       
    page = doc[0] # Get the single frint page from the document.
    
    # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style.
    page.margin = 0
    page.padding = pagePadding
    
    pageAreaW = PageWidth-pl-pr
    pageAreaH = PageHeight-pt-pb
    
    # Resources
    blockFill = None #(1, 1, 0) # Use color to debug page area
    gradient = Gradient(locations=[1,0], colors=((0, 0, 0), (0.8, 0.8, 0.8)))
    shadow = Shadow(offset=(6, -6), blur=10, color=(0.2, 0.2, 0.2, 0.5))
    bookBorders = dict(stroke=(1, 1, 1, 0.5),strokeWidth=0.1,line=OUTLINE)
    bookPadding = (25, 30, 40, 30)
    
    # Styles
    titleStyle =dict(font=fHeader.installedName, fontSize=26, rLeading=1.4, xTextAlign=CENTER, textFill=1)
    authorStyle = dict(font='Georgia-Italic', textFill=1, fontSize=18, xTextAlign=CENTER)
    headStyle = dict(font=fHeader.installedName, textFill=0, fontSize=14, rLeading=1.4, 
        xTextAlign=LEFT, paragraphTopSpacing=30, paragraphBottomSpacing=0)
    bodyStyle = dict(font='Verdana', textFill=0, fontSize=12, rLeading=1.4, 
        xTextAlign=LEFT, paragraphTopSpacing=10, hyphenation=True)
    italicBodyStyle = copy.copy(bodyStyle)
    italicBodyStyle['font'] = 'Verdana-Italic'
    italicBodyStyle['paragraphTopSpacing'] = 0

    fs = newFS(f.info.familyName + ' ' + f.info.styleName, style=titleStyle)
    _, th = textSize(fs)
    title = newTextBox(fs, conditions=[Top2Top(), Fit2Width()],
        parent=page, h=th*1.2)

    # Make new container for adding elements inside with alignment.
    newRect(z=10, w=pageAreaW, h=pageAreaH, fill=blockFill, 
        parent=page, margin=0, padding=0, yAlign=MIDDLE, maxW=pageAreaW, 
        maxH=pageAreaH, xAlign=CENTER,  
        conditions=(Center2Center(), Middle2Middle()))
    
    t1 = newTextBox('Inside the Amstelvar', z=0, font=fHeader.installedName, 
        fontSize=40, w=pageAreaW/2, 
        parent=page, conditions=(Left2Left(), Top2Top()))
        
    w = pageAreaW*0.75 # Used as element width and relative font size. 
    padding = PageHeight/24
    
    fs = newFS('Variable Fonts ', style=dict(font=fHeader.installedName, 
        textFill=0, fontSize=90))
    fs += newFS('Explained', style=dict(font=fHeaderCondensed.installedName,
        textFill=0, fontSize=90))
    t2 = newTextBox(fs, z=0, w=PageWidth*0.75, parent=page, 
        conditions=(Left2Left(), Fit2Width(), Float2Top()))
  
    circle = VariableCircle(f, s=GLYPH_NAME, name='VariableCircleSpeciment',
        parent=page, padding=4, x=100, fontSize=150,
        maxW=PageWidth-2*PADDING, minW=100, showAxisName=True,     
        # Conditions make the element move to top-left of the page.
        # And the condition that there should be no overflow, otherwise the text box
        # will try to solve it.     
        #conditions=[Right2Right(), Float2Top()],
        conditions=[Left2Left(), Fit2Width(), Bottom2Bottom()],
        # Position of the origin of the element. Just to show where it is.
        # Has no effect on the position conditions. 
        yAlign=BOTTOM, xAlign=LEFT, fill=CIRCLE_ELEMENT_FILL, borders=1,
    )
      
    score = page.solve()
    if score.fails:
        print 'Condition fails', score.fails 
    
    return doc # Answer the doc for further doing.
Exemplo n.º 5
0
def makeDocument(fontPath):
    u"""Make a new document."""

    f = Font(fontPath)  # Get PageBot Font instance of Variable font.

    W = H = PageSize

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

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

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

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

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

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

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

        circle = VariableCircle(
            f,
            s=GLYPH_NAME,
            name='VariableCircleSpeciment',
            parent=page,
            padding=4,  #t=frame,
            maxW=W - 2 * PagePadding,
            minW=100,
            # Location frame, float means 50% of defined axis range
            #location=dict(wght=v),
            #location=dict(wdth=wdthValue),
            location=location,
            # Fontsize of the neutral glyph. All measures in the info-graphic
            # are derived relative from this one.
            fontSize=64,
            # Show axis names with the axis max circle markers
            showAxisNames=True,
            # Show 3D effect of needles enteting sphere, instead of circle.
            draw3D=True,
            # Conditions make the element move to top-left of the page.
            # And the condition that there should be no overflow, otherwise the text box
            # will try to solve it.
            conditions=[Float2Top(),
                        Fit2Bottom(),
                        Center2Center()],
            # Position of the origin of the element. Just to show where it is.
            # Has no effect on the position conditions.
            yAlign=BOTTOM,
            xAlign=LEFT,
            fill=CIRCLE_ELEMENT_FILL,
            borders=0,
        )

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

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

        # To avoid circular dependent conditions, we correct the position of the title
        # on left to that the position of the circle has become. This is tricky,
        # because as a result the title may go to 2 lines and then the size of the
        # circle should be adjusted again.
        title.pl = circle.x - page.pl
        created.pl = circle.x - page.pl

    return doc  # Answer the doc for further doing.