Exemple #1
0
    def __init__(self, date=None, **kwargs):
        if date is None:
            date = now()
        self.date = date
        self.calendarMonth = date.calendarMonth

        Element.__init__(self, **kwargs)
def makeHeader(page, font):
    page.padding = PADDING
    #newImage('gallery/Fog35KeyMap.png', parent=page, z=100, conditions=[Fit2WidthSides(), Top2TopSide()])
    header = newRect(h=inch(1),
                     padding=pt(8),
                     mb=inch(0.6),
                     parent=page,
                     fill=0.4,
                     conditions=[Fit2Width(), Top2Top()])
    title = context.newString('Key map', style=titleStyle)
    newTextBox(title,
               w=page.pw / 3,
               fill=0.5,
               parent=header,
               pt=12,
               mr=8,
               borderTop=dict(stroke=whiteColor, strokeWidth=SHADOW),
               borderLeft=dict(stroke=whiteColor, strokeWidth=SHADOW),
               borderRight=dict(stroke=blackColor, strokeWidth=SHADOW),
               borderBottom=dict(stroke=blackColor, strokeWidth=SHADOW),
               conditions=[Left2Left(), Fit2Height()])
    t = 'Size: %s  Font: %s\nNotice: © %s\nPrinted by PageBot on %s' % \
        (pt(SQSIZE), font.path.split('/')[-1], font.info.copyright, now())
    fontInfo = context.newString(t, style=fontInfoStyle)
    newTextBox(
        fontInfo,
        fill=1,
        parent=header,
        margin=0,
        padding=pt(4),
        borderTop=dict(stroke=blackColor, strokeWidth=SHADOW),
        borderLeft=dict(stroke=blackColor, strokeWidth=SHADOW),
        conditions=[Right2Right(),
                    Float2Left(),
                    Fit2Right(),
                    Fit2Height()])
Exemple #3
0
def makeHeader(page, font):
    page.padding = PADDING
    header = newRect(h=inch(1),
                     padding=pt(8),
                     mb=inch(0.6),
                     parent=page,
                     fill=0.4,
                     conditions=[Fit2Width(), Top2Top()])
    title = context.newString('Key map', style=titleStyle)
    mr = pt(8)
    newTextBox(
        title,
        w=page.pw * 0.35,
        fill=0.5,
        parent=header,
        pt=pt(12),  # Padding top
        mr=mr,  # Margin right of the "Key map" text box element   
        borderTop=dict(stroke=whiteColor, strokeWidth=SHADOW),
        borderLeft=dict(stroke=whiteColor, strokeWidth=SHADOW),
        borderRight=dict(stroke=blackColor, strokeWidth=SHADOW),
        borderBottom=dict(stroke=blackColor, strokeWidth=SHADOW),
        conditions=[Left2Left(), Fit2Height()])
    t = 'Size: %s  Font: %s\nNotice: © %s\nPrinted by PageBot on %s' % \
        (pt(SQSIZE), font.path.split('/')[-1], font.info.copyright, now().datetime)
    fontInfo = context.newString(t, style=fontInfoStyle)
    newTextBox(fontInfo,
               fill=1,
               parent=header,
               margin=0,
               w=page.pw * 0.65 - 3 * mr,
               padding=pt(4),
               borderTop=dict(stroke=blackColor, strokeWidth=SHADOW),
               borderLeft=dict(stroke=blackColor, strokeWidth=SHADOW),
               conditions=[Right2Right(),
                           Top2Top(), Fit2Height()])
    page.solve()
    e.solve()

    txt = blurb.getBlurb('name')
    bs = context.newString(txt + ': ', style=topHeadBoldStyle)
    txt = blurb.getBlurb('design_article_title').capitalize()
    if not txt.endswith('.'):
        txt += '.'
    bs += context.newString('“' + txt + '”', style=topHeadStyle)
    txt = ' P:%d' % choice(range(80))
    bs += context.newString(txt, style=topHeadBoldStyle)
    paddingTop = inch(1)
    #tw, th = context.textSize(bs, w=CW3)
    e.select('TopHeadQuote').bs = bs

    # Date box
    date = now()
    dateString = '%s %s %s %s' % (date.fullDayName.upper(), date.day,
                                  date.fullMonthName.upper(), date.year)
    urlString = '\n%s.com' % (TITLE.replace(' ', ''))
    bs = context.newString(dateString, style=dateStyle)  #, w=CW1)
    bs += context.newString(urlString, style=urlStyle)
    e.select('TopHeadDate').bs = bs

urlStyle

if SHOW_TITLE:
    # Title of the newspaper. Calculate the size from the give usable page.pw width.
    bs = context.newString(TITLE, style=titleStyle, w=page.pw)
    tw, th = bs.size  # Get the (width, height) if the created string.
    #print('Calculated fitting title size: ', bs.fittingFontSize)
    titleBox = newTextBox(bs,
Exemple #5
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)
Exemple #6
0
    def exportMap(self,
                  cols=None,
                  maxSpread=None,
                  path=None,
                  showGrid=False,
                  showPadding=False):
        """Export the magazine map into a PDF document at path.
        """
        if cols is None:
            cols = 2  # Number of columns per spread
        sw = self.cw * cols + self.gw * (cols - 1)
        sh = self.h / self.w * sw / 2 + self.gh

        if maxSpread is None:
            maxSpread = 8

        date = now()
        if path is None:
            path = '_export/%d-%02d-%02d-%02d %s.pdf' % (
                date.year, date.month, date.day, date.hour,
                self.name.replace(' ', '_'))

        doc = self.newDocument()

        font = self.style.get('font') or findFont('Roboto Regular')
        headStyle = dict(font=font, fontSize=pt(24))
        labelStyle = dict(font=font, fontSize=pt(7))

        # Set to True if padding and grid to be shown. The magazine map has the same layout
        # as the main magazine pages, which allows the map export to be used as full page
        # illustration in the magazine. :)
        view = doc.view
        view.showPadding = showPadding
        view.showGrid = showGrid
        view.showBaselineGrid = False

        page = None  # Force first page to initialize.
        pn = 0  # Pagenumber: TODO--> Translate to real pagenumber, this is only page index.
        headerH = pt(80)  # Height of the header box.

        spreads = self.spreads  # Run property that accumulates all spreads width Page instances.
        for index in range(0, len(spreads),
                           maxSpread):  # Take chunks of spreads for each page.
            pageSpreads = spreads[index:index + maxSpread]
            if pageSpreads:  # If there still are spreads in the chunk, process them on a new page.
                if page is None:
                    page = doc[1]  # Start at first (autoPage) of the document.
                else:
                    page = page.next  # Otherwise automatic create a new page in the document.
                page.padding = self.padding  # Set the padding of this page from self.
                # Create a new header text box for each page.
                # TODO: This could contain more info from self, number of pager, etc.
                bs = self.context.newString('Map %s' % self.name,
                                            style=headStyle)
                newTextBox(bs,
                           x=page.pl,
                           y=page.pb + page.ph - headerH,
                           w=page.pw,
                           h=headerH,
                           parent=page)

                # Set coordinate of the first spread thumbnail to be positioned.
                x = page.pl
                y = page.pb + page.ph - sh - headerH

                for pageSpread in pageSpreads:  # Process all spreads in the chunk of this page.
                    ps = PageSpread(pageSpread,
                                    pn,
                                    x=x,
                                    y=y,
                                    w=sw,
                                    h=sh,
                                    parent=page,
                                    style=labelStyle)
                    pn += 2
                    x += sw + page.gw  # Position of next spread thumbnail
                    if x >= page.pw:  # If all columns used, then continue on the next row.
                        x = page.pl
                        y -= ps.h

        # TODO: Why is export so slow?
        doc.export(path)