示例#1
0
 def buildFamilySpecimenPage(self, page, family):
     box = page[self.specimenBoxId][0]
     fontSize = 500
     while not box.getOverflow():
         sportsHeadline = ' '.join(
             blurb.getBlurb('news_headline').split(' ')[:choice(
                 (2, 2, 3, 3, 4))]) + '\n'
         styleKey = choice(('Regular', 'Bold', 'Italic', 'BoldItalic'))
         fs = self.context.newString(
             sportsHeadline,
             self,
             style=dict(font=family[styleKey].installedName,
                        fontSize=fontSize))
         fsWidth = fs.size()[0]
         fittingFontSize = fontSize * box.w / fsWidth
         # Make new formatted string with fitting font size.
         fs = self.context.newString(
             sportsHeadline,
             self,
             style=dict(font=family[styleKey].installedName,
                        leading=0,
                        fontSize=fittingFontSize,
                        textColor=0))
         box.append(fs)
         print '###', page, family, sportsHeadline
示例#2
0
import pagebot
from pagebot import newFS
from pagebot.fonttoolbox.objects.family import getFamilyFontPaths
from pagebot.contributions.filibuster.blurb import blurb
from pagebot.toolbox.transformer import path2ScriptId

if __name__ == '__main__':

    scriptGlobals = pagebot.getGlobals(path2ScriptId(__file__))

    #for k in sorted(getFamilyFontPaths('Bitpath')):
    #    print k

    if not hasattr(scriptGlobals, 'initialized'):
        scriptGlobals.initialized = True
        scriptGlobals.s1 = blurb.getBlurb('article_content', noTags=True)
        scriptGlobals.s2 = blurb.getBlurb('article_content', noTags=True)
        scriptGlobals.s3 = blurb.getBlurb('article_content', noTags=True)
        scriptGlobals.s4 = blurb.getBlurb('article_content', noTags=True)
        scriptGlobals.s5 = blurb.getBlurb('article_content', noTags=True)

    F = 50
    R = 10
    x = y = 20

    rLeading = 0.6

    for angle in range(0, 360, 10):
        newPage(1000, 1000)
        dx = sin(angle / 360 * 2 * pi) * R
        dy = cos(angle / 360 * 2 * pi) * R
示例#3
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
示例#4
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.
示例#5
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
示例#6
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
示例#7
0
import pagebot
from pagebot import newFS, findMarkers, textBoxBaseLines
from pagebot.style import getRootStyle, LEFT, NO_COLOR
from pagebot.document import Document
from pagebot.elements import Page, Template, Galley
from pagebot.composer import Composer
from pagebot.typesetter import Typesetter
from pagebot.style import A4
from pagebot.toolbox.transformer import path2ScriptId
from pagebot.fonttoolbox.objects.family import getFamilyFontPaths
from pagebot.contributions.filibuster.blurb import blurb

scriptGlobals = pagebot.getGlobals(path2ScriptId(__file__))
if not hasattr(scriptGlobals, 'initialized'):
    scriptGlobals.initialized = True
    scriptGlobals.head = blurb.getBlurb('sports_headline', noTags=True) + '\n'
    scriptGlobals.subhead = blurb.getBlurb('aerospace_headline',
                                           noTags=True) + '\n'
    scriptGlobals.body = blurb.getBlurb('article_content', noTags=True) + '\n'

DEBUG = False

SHOW_GRID = True
SHOW_GRID_COLUMNS = True
SHOW_BASELINE_GRID = DEBUG
SHOW_FLOW_CONNECTIONS = DEBUG

if SHOW_GRID:
    BOX_COLOR = (0.8, 0.8, 0.8, 0.4)
else:
    BOX_COLOR = None
示例#8
0
#     This script the PDF document with Bitcount refernce information.
#
import pagebot
from pagebot.contexts import defaultContext as context
from pagebot.fonttoolbox.objects.family import getFamilyFontPaths
from pagebot.contributions.filibuster.blurb import blurb

if __name__ == '__main__':

    #for k in getFamilyFontPaths('Bitpath'):
    #    print k

    F = 50
    x = y = 20

    s = blurb.getBlurb('article_content', noTags=True)
    fs = context.newString(s,
                           style=dict(
                               font='BitpathGridDouble-RegularLineSquare',
                               fontSize=F,
                               textFill=(1, 0, 0),
                               rLeading=0.5))
    textBox(fs, (x, y, 1000, 900))

    s = blurb.getBlurb('article_content', noTags=True)
    fs = context.newString(s,
                           style=dict(
                               font='BitpathGridDouble-RegularLineSquare',
                               fontSize=F,
                               textFill=(0, 1, 0),
                               rLeading=0.5))
def makeDocument():
    u"""Demo page composer."""

    # 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, autoPages=1)

    # Get default view
    view = doc.getView()
    view.padding = 0
    view.showElementOrigin = True
    view.showPageCropMarks = True
    view.showPageRegistrationMarks = True
    view.showPageFrame = True
    view.showPageNameInfo = True

    w = 300

    colorCondition1 = [  # Placement condition(s) for the color rectangle elements.
        Right2Right(),
        #Center2Right(),
        #Right2Right(),
        Top2Top(),
    ]
    colorCondition2 = [  # Placement condition(s) for the color rectangle elements.
        Right2Right(),
        #Top2Bottom(),
        Float2Left(),
        Float2Top(),
    ]
    colorCondition3 = [  # Placement condition(s) for the color rectangle elements.
        Right2Right(),
        #Top2Bottom(),
        Float2Left(),
        Float2Top(),
        Fit2Bottom(),
        #Bottom2Bottom(),
    ]
    textCondition = [  # Placement condition(s) for the text element..
        Float2Left(),
        Float2Top(),
    ]
    page = doc.getPage(0)  # Get the first/single page of the document.

    # Other z-layer, makes this element be ignored on floating checks.
    e0 = newRect(z=-10,
                 name='Page area',
                 parent=page,
                 conditions=[Fit()],
                 fill=0.9)

    # Add some color elements (same width, different height) at the “wrongOrigin” position.
    # They will be repositioned by solving the colorConditions.
    e1 = newRect(parent=page,
                 name='Other element',
                 w=Element1_W,
                 h=Element1_H,
                 conditions=colorCondition1,
                 fill=(1, 0.5, 0.5),
                 xAlign=RIGHT,
                 yAlign=TOP)
    e2 = newRect(parent=page,
                 w=Element2_W,
                 h=Element2_H,
                 name='Floating element 2',
                 conditions=colorCondition2,
                 fill=(1, 1, 0),
                 xAlign=LEFT,
                 yAlign=TOP)
    e3 = newRect(parent=page,
                 w=Element3_W,
                 h=Element3_H,
                 name='Floating element 3',
                 conditions=colorCondition2,
                 fill=(1, 0, 1),
                 xAlign=LEFT,
                 yAlign=TOP)
    # Make text box at wrong origin. Apply same width a the color rect, which may
    # be too wide from typographic point ogf view. The MaxWidthByFontSize will set the
    # self.w to the maximum width for this pointSize.
    if not hasattr(scriptGlobals, 'blurbText'):
        scriptGlobals.blurbText = doc.context.newString(
            blurb.getBlurb('article_summary', noTags=True),
            page,
            style=dict(font='Georgia', fontSize=12, leading=16, textColor=0))
    eTextBox = newTextBox(scriptGlobals.blurbText,
                          parent=page,
                          w=Text_W,
                          conditions=textCondition,
                          xAlign=CENTER,
                          yAlign=MIDDLE,
                          stroke=None,
                          fill=None)

    e4 = newRect(parent=page,
                 w=Element4_W,
                 h=Element4_H,
                 name='Floating element 4',
                 conditions=colorCondition3,
                 fill=(0, 1, 1),
                 xAlign=RIGHT,
                 yAlign=TOP,
                 minH=50,
                 maxH=150)
    e5 = newRect(parent=page,
                 w=Element5_W,
                 h=Element5_H,
                 name='Floating element 5',
                 conditions=[Float2RightTopSides()],
                 fill=(0, 1, 0),
                 xAlign=LEFT,
                 yAlign=TOP)

    score = page.evaluate()
    #print 'Page value on evaluation:', score
    #print score.fails
    # Try to solve the problems if evaluation < 0
    if score.result < 0:
        print 'Solving', score
        page.solve()
    #print score.fails
    # Evaluate again, result should now be >= 0
    score = page.evaluate()
    print 'Page value after solving the problems:', score
    for fail in score.fails:
        print fail

    return doc
示例#10
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.
示例#11
0
def makeDocument(rs):
    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)

    # Template 1
    template1 = Template(rs)  # Create template of main size. Front page only.
    # Show baseline grid if rs.showBaselineGrid is True
    template1.baselineGrid(rs)
    # Create linked text boxes. Note the "nextPage" to keep on the same page or to next.
    template1.cTextBox(FS, 1, 0, 6, 6, rs, eId=mainId)

    # 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(rs, autoPages=1, template=template1)

    page = doc[1]
    # 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]
    e = page.getElement(mainId)

    fs = doc.context.newString(Sample_Text + ' V.T.TeY.Yjy\n',
                               style=dict(font=BOLD,
                                          fontSize=32,
                                          rTracking=headlineTracking,
                                          openTypeFeatures=features))
    e.append(fs)
    fs = doc.context.newString(blurb.getBlurb('sports_headline', noTags=True) +
                               '\n',
                               style=dict(font=BOOK,
                                          fontSize=32,
                                          rTracking=headlineTracking,
                                          openTypeFeatures=features))
    e.append(fs)
    fs = doc.context.newString(
        blurb.getBlurb('aerospace_headline', noTags=True) + '\n',
        style=dict(font=BOOK,
                   fontSize=16,
                   rTracking=headlineTracking,
                   openTypeFeatures=features))
    e.append(fs)
    fs = doc.context.newString(blurb.getBlurb('article_content', noTags=True) +
                               '\n',
                               style=dict(font=BOOK,
                                          fontSize=12,
                                          rTracking=bodyTracking,
                                          openTypeFeatures=features))
    e.append(fs)

    return doc