Exemple #1
0
def useBabelStrings():
    
    for contextId, context in (
            ('DrawBot', DrawBotContext()),
            ('Flat', FlatContext())):
        W, H = pt(1000, 300)
        M = pt(100)
        

        EXPORT_PATH = '_export/UseBabelStrings-%s.pdf' % contextId
        # Create a page and set y on top margin.
        context.newPage(W, H)
        y = H - M
        cs = context.newString('Context: %s' % contextId, style={'textFill': color(0, 0, 1), 'fontSize': 36})
        context.text(cs, (100, y))
        y -= 20

        # Create formatted string, with default settings of font, fontSize and textFill color
        bs = context.newString('This is a formatted BabelString')
        print(bs.__class__.__name__)
        context.text(bs, (100, y))

        # FIXME: solve for Flat.
        # Add string with formatting style dict
        bs += context.newString('\nAdd an other string with color/size format',
            style=dict(textFill=color(1, 0, 0), fontSize=20, leading=em(1.4)))
        print(bs)

        y -= 50

        context.text(bs, (100, y))
        context.saveImage(EXPORT_PATH)
Exemple #2
0
#     Supporting DrawBot, www.drawbot.com
#     Supporting Flat, xxyxyz.org/flat
# -----------------------------------------------------------------------------
#
#     ThemeColorMatrix.py
#
# Import the Theme classes from PageBot.
from pagebot.themes import ThemeClasses
from pagebot.themes.basetheme import BaseTheme
from pagebot.constants import CENTER # Import some constants that we need.
from pagebot.toolbox.units import upt, pt
from pagebot.fonttoolbox.objects.font import findFont
from pagebotcocoa.contexts.drawbot.drawbotcontext import DrawBotContext
from pagebot.toolbox.color import color, blackColor

context = DrawBotContext()

# Make a new Theme, altering the some slots in the BaseTheme
class FantasyTheme(BaseTheme):
    NAME = 'Fantasy Red'
    BASE_COLORS = dict(
        base2=color(1, 0, 0.2), # Filling 2 base colors as source for range.
        dark3=color(1, 0, 0.5), # Overwriting single slot in the matrix.
        logo=color(spot=300)
    )
# Make another Theme, based on DesignDesign.Space identity colors.
DDS_LOGO = color(spot=165)
class DDSTheme(BaseTheme):
    NAME = 'DesignDesign.Space'
    BASE_COLORS = dict(
        #base1=color('#8080A0'),
Exemple #3
0
from pagebot.elements import *
from pagebot.conditions import *
from pagebot.typesetter import Typesetter
from pagebot.composer import Composer
from pagebot.toolbox.color import color, blackColor
from pagebot.constants import A4
from pagebot.toolbox.units import pt, em

W, H = A4
PADDING = pt(40)  # Simple page padding
G = pt(12)

# Path to the MarkDown source file
MARKDOWN_PATH = 'EmbeddedPython.md'

pdfContext = DrawBotContext()
htmlContext = HtmlContext()

styles = dict(
    h1=dict(textFill=color('red'),
            fontSize=pt(24),
            leading=em(1.4),
            firstTagIndent=pt(0),
            firstLineIndent=0,
            paragraphBottomSpacing=pt(12)),
    h2=dict(textFill=color(0.3),
            fontSize=pt(18),
            leading=em(1.4),
            firstTagIndent=pt(0),
            firstLineIndent=0,
            paragraphTopSpacing=pt(12),
Exemple #4
0
            """
            ox, oy, _ = origin
            c = self.context
            style = self.style.copy()
            
            # Now make instance and draw over regular and add to new copy of the style
            style = self.style.copy()
            instance = self.f.getInstance(self.style['location'])
            style['font'] = instance.path
            #print(self.frameIndex, style['font'])
            #style['fontSize'] = self.h/3
            bs = c.newString(self.sampleText, style=style, w=self.pw)
            tw, th = bs.size
            c.text(bs, (self.w/2 - tw/2, self.h/2-th/2))
     
c = DrawBotContext()
W, H = 2040, 1020 # Type Network banners

# Claire: for now, add your Fit-Variable_1.ttf to your /Library/Fonts and it can be found.
#Gimlet_Italics-VF.ttf
#Gimlet_Romans-VF.ttf

def makeBanner(font):
    # Fit axes to select from: here we are showing the optical size.
    # Define tag list for axes to be part of the animation as sequence
    sequenceAxes = ['wdth']
    sequenceLength = 3 # Seconds per sequence
    sequences = len(sequenceAxes) # Amount of sequences, one per axis
    duration = sequenceLength * len(sequenceAxes) # Total duration of the animation in seconds
    framesPerSecond = 10
    frameCnt = duration * framesPerSecond # Total number of frames

def appendS(fs1, fs2, w, baselineGrid):
    """Append fs2 to fs2, while keeping baseline grid locked.
    Assumed is that the top fs1 textBox is already on the baseline grid."""
    h = 1000
    box = 0, 0, w, h
    # Get the status of of the target string. We need to know the position of the last line.
    baselines = context.textBoxBaseLines(fs2, box)
    if baselines:
        print(1000 - baselines[0][1], 1000 - baselines[-1][1])
    return fs1


testContexts = (
    (DrawBotContext(), '_export/testFlatString.pdf'),
    # TODO: Get this to work with Flat
    #(FlatContext(), '_export/testDrawBotString.pdf'),
)
for context, path in testContexts:

    context.newPage(1000, 1000)

    leading = 24
    for n in range(0, 1000, leading):
        context.stroke(1, 0, 0)
        context.fill(None)
        context.line((0, n), (1000, n))

    fs1 = context.newString('')
    fs2 = context.newString('aaa vvv bbbbbb\nss' * 5,
Exemple #6
0
def makeDocument():
    """Re-generate the original Type3-PeopleInType chapter as PDF output."""

    context = DrawBotContext()

    # 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='Type Magazine #3',
                   autoPages=endPage - startPage + 1,
                   baselineGrid=BASELINE,
                   baselineStart=BASELINE_START,
                   style=styles,
                   templates=getTemplates(),
                   startPage=startPage,
                   originTop=False,
                   context=context)

    # 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 = True
    view.showPadding = True
    view.showNameInfo = True
    view.showMetaInfo = False
    view.showTextOverflowMarker = True
    view.showOrigin = False  # Show origin marker
    view.showElementOrigin = False  # Don't show the origin of other elements.

    view.showGrid = [GRID_COL, GRID_ROW]
    view.showBaselines = True

    view.showSpreadPages = True
    view.showSpreadMiddleAsGap = False

    # PageBot article
    _, backgroundHeight = context.imageSize(BACKGROUND_PDF)
    backgroundIndex = 0
    for pn in range(startPage, endPage + 1):
        page = doc[pn]
        setPageStyle(page, backgroundIndex)
        backgroundIndex += 1

    if 1:
        page = doc[startPage + 2]
        print(page)
        t = Typesetter(context, styles=styles, imageAsElement=True)
        galley = t.typesetFile(CONTENT_PATH, e=page)
        composer = Composer(doc)
        targets = dict(composer=composer,
                       doc=doc,
                       page=page,
                       style=doc.styles,
                       box=page.select('people'),
                       newTextBox=newTextBox)

        composer.compose(galley, targets=targets, page=page)

    date = now()
    if EXPORT_PDF:  # Export as PDF
        exportPath = EXPORT_PATH_PDF % (date.year, date.month, date.day,
                                        date.hour, startPage, endPage)
        doc.export(exportPath)
    if EXPORT_PNG:  # Export as PNG without cropmarks for mapping purpose
        doc.view.padding = 0
        exportPath = EXPORT_PATH_PNG % (startPage, endPage)
        doc.export(exportPath)
#
#     Supporting DrawBot, www.drawbot.com
#     Supporting Flat, xxyxyz.org/flat
# -----------------------------------------------------------------------------
#
#     08-HeadlineAlignment.py
#
from pagebotcocoa.contexts.drawbot.drawbotcontext import DrawBotContext
from pagebot.fonttoolbox.objects.font import findFont
from pagebot.toolbox.units import em, p, pt
from pagebot.constants import *
from pagebot.elements import *
from pagebot.conditions import *
from pagebot.document import Document

context = DrawBotContext()

W, H = pt(1500, 1000)  # Document size
PADDING = pt(100)  # Page padding on all sides
G = p(2)  # 2 Pica gutter
PW = W - 2 * PADDING  # Usable padded page width
PH = H - 2 * PADDING  # Usable padded page height
CW = (PW - G) / 3  # Column width
CH = PH
# Hard coded grid for 3 columns, will be automatic in later examples.
GRIDX = ((CW, G), (CW, G), (CW, G))
GRIDY = ((CH, 0), )  # No division in vertical grid.
BASELINE = G

NUM_PAGES = 1
#     Supporting DrawBot, www.drawbot.com
#     Supporting Flat, xxyxyz.org/flat
# -----------------------------------------------------------------------------
#
#     08-HeadlineAlignment.py
#
from pagebotcocoa.contexts.drawbot.drawbotcontext import DrawBotContext
from pagebot.fonttoolbox.objects.font import findFont
from pagebot.toolbox.units import em, p, pt
from pagebot.constants import *
from pagebot.elements import *
from pagebot.conditions import *
from pagebot.document import Document
from pagebot.toolbox.color import color

context = DrawBotContext()

W, H = pt(800, 500)  # Document size
PADDING = pt(120, 20)  # Page padding on all sides

NUM_PAGES = 1

# Get the font object, from te Roboto file that is included in PageBot resources for testing.
f = findFont('PageBot-Regular')

# Create a new document with 1 page. Set overall size and padding.
# TODO: View grid drawing, etc. does not work properly for originTop=True
doc = Document(w=W,
               h=H,
               padding=PADDING,
               context=context,
Exemple #9
0
#     Licensed under MIT conditions
#
#     Supporting DrawBot, www.drawbot.com
# -----------------------------------------------------------------------------
#
#     TextFlowWithContext.py
#
#     Calculate the overflowing text and add it to another column.
#
#     This example shows the most basic version, using only DrawBot functions.
#     The overflow text takes the same parameters for the Formatted String as the
#     original text had.
#
from pagebotcocoa.contexts.drawbot.drawbotcontext import DrawBotContext

context = DrawBotContext()

W = H = 500
PADDING = 30
CW = (W - 3 * PADDING) / 2
CH = H - 2 * PADDING

context.newPage(W, H)

style = dict(font='Verdana',
             textFill=(1, 0, 0),
             fontSize=14,
             leading=16,
             firstLineIndent=20)
bs = context.newString('AAA ' * 300, style=style)