Exemplo n.º 1
0
    def build_drawBot(self, view, b, origin=ORIGIN, drawElements=True):
        u"""Default drawing method just drawing the frame. 
        Probably will be redefined by inheriting element classes."""

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        self.drawFrame(view, p)  # Draw optional frame or borders.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        self._drawSpreadSheet(view, b, p)

        if drawElements:
            # If there are child elements, draw them over the pixel image.
            self.buildChildElements(view, b, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, b, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(
            self, origin)  # Depends on flag 'view.showElementInfo'
Exemplo n.º 2
0
    def draw(self, origin, view):

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        save()
        sh = 1.0 * self.h / self.ih
        transform((1, 0, 0, 1, px, py))
        scale(sh)
        if self.pathFilter is not None:
            self.pathFilter(self, self.glyph.path)
        if self.css('fill') != NO_COLOR or self.css('stroke') != NO_COLOR:
            setFillColor(self.css('fill'))
            print(self.css('strokeWidth') or 1), sh
            setStrokeColor(self.css('stroke', NO_COLOR),
                           (self.css('strokeWidth') or 20))
            fill(0)
            stroke(1, 0, 0)
            strokeWidth(20)
            drawPath(self.glyph.path)
        restore()

        # If there are child elements, draw them over the polygon.
        self._drawElements(p, view)

        # Draw optional bounding box.
        #self.drawFrame(origin, view)

        self._restoreScale()
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
Exemplo n.º 3
0
 def draw(self, origin, view):
     u"""Draw all elements this page."""
     p = pointOffset(self.oPoint, origin) # Ignoe z-axis for now.
     # If there are child elements, draw them over the text.
     self._drawElements(p, view)
     # Draw addition page info, such as crop-mark, registration crosses, etc. if parameters are set.
     view.drawPageMetaInfo(self, origin)
Exemplo n.º 4
0
    def draw(self, origin, view):
        u"""Like "rolled pasteboard" galleys can draw themselves, if the Composer decides to keep
        them in tact, instead of select, pick & choose elements, until the are all
        part of a page. In that case the w/h must have been set by the Composer to fit the
        containing page."""
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)    
        px, py, _ = self._applyAlignment(p) # Ignore z-axis for now.

        if self.drawBefore is not None: # Call if defined
            self.drawBefore(self, p, view)

        setFillColor(self.OLD_PAPER_COLOR) # Color of old paper: #F8ECC2
        gw, gh = self.getSize()
        rect(px, py, gw, gh)
        gy = 0
        for element in self.elements:
            # @@@ Find space and do more composition
            element.draw((px, py + gy), view)
            gy += element.h

        if self.drawAfter is not None: # Call if defined
            self.drawAfter(self, p, view)

        self._restoreScale()
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 5
0
    def build_html(self, view, origin=None, drawElements=True):

        context = self.context # Get current context and builder.
        b = context.b # This is a bit more efficient than self.b once we got context
 
        self.build_css(view)
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)    
        px, py, _ = p = self._applyAlignment(p) # Ignore z-axis for now.

        context.setFillColor(None)
        context.setStrokeColor(self.css('stroke', NO_COLOR), self.css('strokeWidth'))
        #b.line((px + sIndent, py), (px + w, py))

        if self.drawBefore is not None: # Call if defined
            self.drawBefore(self, view, p)

        if drawElements:
            self.buildChildElements(view, p)

        if self.drawAfter is not None: # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 6
0
    def build(self, view, origin):
        u"""Build the Ruler in the current context

        >>> from pagebot.contexts.drawbotcontext import DrawBotContext
        >>> from pagebot.document import Document
        >>> c = DrawBotContext()
        >>> w, h = 300, 400
        >>> doc = Document(w=w, h=h, autoPages=1, padding=30, originTop=False, context=c)
        >>> page = doc[1]
        >>> e = Ruler(parent=page, x=0, y=20, w=page.w, h=3)
        >>> e.build(doc.getView(), (0, 0))
        >>> e.xy
        (0, 20)
        >>> e.size
        (300, 3, 1)
        >>> view = doc.getView()
        >>> e.build(view, (0, 0))

        >>> from pagebot.contexts.flatcontext import FlatContext 
        >>> from pagebot.document import Document
        >>> c = FlatContext()
        >>> doc = Document(w=w, h=h, autoPages=1, padding=30, originTop=False, context=c)
        >>> page = doc[1]
        >>> e = Ruler(parent=page, x=0, y=20, w=page.w, h=3)
        >>> # Allow the context to create a new document and page canvas. Normally view does it.
        >>> c.newPage(w, h) 
        >>> e.build(doc.getView(), (0, 0))
        >>> e.xy
        (0, 20)
        >>> e.size
        (300, 3, 1)
        """
        context = self.context  # Get current context and builder.

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = self._applyAlignment(p)  # Ignore z-axis for now.
        sIndent = self.css('indent')
        sTailIndent = self.css('tailIndent')
        w = self.w - sIndent - sTailIndent

        # Let the view draw frame info for debugging, in case view.showElementFrame == True
        view.drawElementFrame(self, p)

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        context.setFillColor(None)
        context.setStrokeColor(self.css('stroke', NO_COLOR),
                               self.css('strokeWidth'))
        context.line((px + sIndent, py), (px + w, py))

        # If there are child elements, recursively draw them over the pixel image.
        self.buildChildElements(view, origin)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 7
0
    def build(self, view, origin, drawElements=True):
        u"""Draw the circle info-graphic, showing most info about the variable font as can be interpreted from the file."""
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = self._applyAlignment(p)  # Ignore z-axis for now.

        # Let the view draw frame info for debugging, in case view.showElementFrame == True
        view.drawElementFrame(self, p)

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        # Draw actual circle
        self._drawFontCircle(px, py)

        if drawElements:
            for e in self.elements:
                e.build_flat(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
Exemplo n.º 8
0
    def draw(self, origin, view):
        u"""Draw the image in the calculated scale. Since we need to use the image
        by scale transform, all other measure (position, lineWidth) are scaled
        back to their original proportions.
        If stroke is defined, then use that to draw a frame around the image.
        Note that the (sx, sy) is already scaled to fit the padding position and size."""
        p = pointOffset(self.oPoint, origin)   
        p = self._applyScale(p)    
        px, py, _ = self._applyAlignment(p) # Ignore z-axis for now.

        if self.path is None or not os.path.exists(self.path) or not self.iw or not self.ih:
            # TODO: Also show error, in case the image does not exist, to differ from empty box.
            print 'Cannot display pixelMap', self
            #self._drawMissingElementRect(page, px, py, self.w, self.h)
        else:
            save()
            sx = self.w / self.iw
            sy = self.h / self.ih
            scale(sx, sy)
            
            # If there is a clipRect defined, create the bezier path
            if self.clipRect is not None:
                clipRect = BezierPath()
                clX, clY, clW, clH = self.clipRect
                sclX = clX/sx
                sclY = clY/sx
                sclW = clW/sx
                sclH = clH/sy
                # move to a point
                clipRect.moveTo((sclX, sclY))
                # line to a point
                clipRect.lineTo((sclX, sclY+sclH))
                clipRect.lineTo((sclX+sclW, sclY+sclH))
                clipRect.lineTo((sclX+sclW, sclY))
                # close the path
                clipRect.closePath()
                # set the path as a clipping path
                clipPath(clipRect)
                # the image will be clipped inside the path
                #fill(1, 0, 0, 0.5)
                #drawPath(clipRect)
            elif self.clipPath is not None:
                #Otherwise if there is a clipPath, then use it.
                clipPath(self.clipPath)

            if self.imo is not None:
                with self.imo:
                    image(self.path, (0, 0), pageNumber=0, alpha=self._getAlpha())
                image(self.imo, (px/sx, py/sy), pageNumber=0, alpha=self._getAlpha())
            else:
                # Store page element Id in this image, in case we want to make an image index later.
                image(self.path, (px/sx, py/sy), pageNumber=0, alpha=self._getAlpha())
            # TODO: Draw optional (transparant) forground color?
            restore()

        # If there are child elements, draw them over the pixel image.
        self._drawElements(origin, view)

        self._restoreScale()
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 9
0
    def build_drawBot(self, view, origin, drawElement=True):

        context = self.context # Get current context and builder.

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)    
        px, py, _ = self._applyAlignment(p) # Ignore z-axis for now.
        sIndent = self.css('indent')
        sTailIndent = self.css('tailIndent')
        w = self.w - sIndent - sTailIndent
 
        if self.drawBefore is not None: # Call if defined
            self.drawBefore(view, p)

        context.setFillColor(None)
        context.setStrokeColor(self.css('stroke', NO_COLOR), self.css('strokeWidth'))
        context.line((px + sIndent, py), (px + w, py))

        if drawElements:
            # If there are child elements, recursively draw them over the pixel image.
            self.buildChildElements(view, origin)

        if self.drawAfter is not None: # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 10
0
    def buld(self, view, origin, drawElements=True):

        context = self.context # Get current context and builder.
        b = context.b # This is a bit more efficient than self.b once we got context
       
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)    
        px, py, _ = p = self._applyAlignment(p) # Ignore z-axis for now.

        if self.drawBefore is not None: # Call if defined
            self.drawBefore(self, view, p)

        context.setFillColor(self.css('fill'))
        context.setStrokeColor(self.css('stroke', NO_COLOR), self.css('strokeWidth'))
        b.newPath()
        for index, (ppx, ppy) in enumerate(self.points):
            if index == 0:
                b.moveTo((px + ppx, py + ppy))
            else:
                b.lineTo((px + ppx, py + ppy))
        b.drawPath()

        if drawElements:
            # If there are child elements, recursively draw them over the pixel image.
            self.buildElements(view, p)

        if self.drawAfter is not None: # Call if defined
            self.drawAfter(self, view, p)

        # Draw optional bouning box.
        self.drawFrame(origin, view)
 
        self._restoreScale()
        view.drawElementMetaInfo(self, origin) # Depends on css flag 'showElementInfo'
Exemplo n.º 11
0
    def build(self, view, origin, drawElements=True):
        u"""Default drawing method just drawing the frame.
        Probably will be redefined by inheriting element classes."""
        c = self.context
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        p = self._applyAlignment(p)  # Ignore z-axis for now.

        self.buildFrame(view,
                        p)  # Draw optional background fill, frame or borders.

        # Let the view draw frame info for debugging, in case view.showElementFrame == True
        view.drawElementFrame(self, p)

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        # Draw that actual content of the element by stacked specimen rectangles.
        self.drawStacked(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(
            self, origin)  # Depends on flag 'view.showElementInfo'
Exemplo n.º 12
0
    def draw(self, view, origin):

        c = self.context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = self._applyAlignment(p)  # Ignore z-axis for now.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        fillColor = self.style.get('fill')
        #fillColor = (0, 0, 0)
        #if fillColor is not None:
        #    c = self.doc.context
        #    c.setFillColor(fillColor)
        #    c.setStrokeColor(None)
        #else:
        #    fillColor = (0, 0, 0)
        glyphPathScale = self.fontSize / self.font.info.unitsPerEm
        drawGlyphPath(c, self.font.ttFont, self.glyphNames[0], px, py,
                      self.location, glyphPathScale, fillColor)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)
Exemplo n.º 13
0
    def build(self, view, origin, drawElements=True):

        c = self.context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = self._applyAlignment(p)  # Ignore z-axis for now.

        # Let the view draw frame info for debugging, in case view.showElementFrame == True
        view.drawElementFrame(self, p)

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        fillColor = self.style.get('fill')
        #fillColor = (0, 0, 0)
        #if fillColor is not None:
        #    c = self.doc.context
        #    c.setFillColor(fillColor)
        #    c.setStrokeColor(None)
        #else:
        #    fillColor = (0, 0, 0)
        glyphPathScale = self.fontSize / self.font.info.unitsPerEm
        context.drawGlyphPath(c, self.font.ttFont, self.glyphNames[0], px, py,
                              self.location, glyphPathScale, fillColor)

        if drawElements:
            # If there are child elements, recursively draw them over the pixel image.
            self.buildChildElements(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)
Exemplo n.º 14
0
    def build_drawBot(self, view, origin=ORIGIN, drawElements=True):

        context = self.context  # Get current context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        context.save()
        sh = 1.0 * self.h / self.ih
        context.transform((1, 0, 0, 1, px, py))
        context.scale(sh)
        # If there is a path filter defined, then call that the draw and ignore regular drawing.
        if self.pathFilter is not None:
            self.pathFilter(self, self.glyph.path, view)
        elif self.css('fill') != NO_COLOR or self.css('stroke') != NO_COLOR:
            # Not path filter defined, draw by regular stroke/fill.
            context.setFillColor(self.css('fill'))
            context.setStrokeColor(self.css('stroke', NO_COLOR),
                                   (self.css('strokeWidth') or 20))
            context.strokeWidth(20)
            context.drawPath(self.glyph.path)
        context.restore()

        if drawElements:
            for e in self.elements:
                e.build_flat(view, p)

        # Draw optional bounding box.
        #self.drawFrame(origin, view)

        self._restoreScale(view)
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
Exemplo n.º 15
0
    def draw(self, view, origin):
        c = self.doc.context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = self._applyAlignment(p)  # Ignore z-axis for now.

        fillColor = self.style.get('fill')
        if fillColor is not None:
            c.fill(fillColor)

        c.stroke((0.8, 0.8, 0.8), 0.5)
        c.rect(px, py, self.w, self.h)
        if len(self.dimensions) == 1:
            raise ValueError('Not supporting 1 axis now')
        if len(self.dimensions) > 2:
            raise ValueError('Not supporting >2 axis now')

        axisNames = sorted(self.dimensions.keys())
        axisX = axisNames[0]
        sizeX = self.dimensions[axisX]
        axisY = axisNames[1]
        sizeY = self.dimensions[axisY]
        stepX = self.w / (sizeX + 1)
        stepY = self.h / (sizeY + 1)
        """Add more parametric layout behavior here."""
        RANGE = 1000
        for indexX in range(sizeX + 1):
            for indexY in range(sizeY + 1):
                ox = 30
                oy = 25
                ppx = ox + px + indexX * stepX
                ppy = oy + py + indexY * stepY
                self.location[axisX] = indexX * RANGE / sizeX
                self.location[axisY] = indexY * RANGE / sizeY
                glyphPathScale = self.fontSize / self.font.info.unitsPerEm

                c.drawGlyphPath(c,
                                self.font.ttFont,
                                self.glyphNames[0],
                                ppx,
                                ppy,
                                self.location,
                                s=glyphPathScale,
                                fillColor=(0, 0, 0))

                bs = c.newString('%s %d\n%s %d' %
                                 (axisX, indexX * RANGE / sizeX, axisY,
                                  indexY * RANGE / sizeY),
                                 fontSize=6,
                                 fill=0)
                w, h = bs.size()

                c.text(bs, ppx - stepX / 4, ppy - 16)
                # Bit of hack, we need the width of the glyph here.

        bs = c.newString('Other axes: %s' % self.location, fontSize=6, fill=0)
        w, h = bs.size()
        c.text(bs, px, py - 16)
Exemplo n.º 16
0
 def build(self, view, origin=ORIGIN, drawElements=True):
     u"""Draw all elements of this page in DrawBot."""
     p = pointOffset(self.oPoint, origin) # Ignoe z-axis for now.
     # If there are child elements, draw them over the text.
     if drawElements:
         self.buildChildElements(view, p) # Build child elements, depending in context build implementations.
     # Draw addition page info, such as crop-mark, registration crosses, etc. if parameters are set.
     view.drawPageMetaInfo(self, origin)
Exemplo n.º 17
0
    def build(self, view, origin, drawElements=True):
        u"""Draw the text on position (x, y). Draw background rectangle and/or frame if
        fill and/or stroke are defined."""
        context = view.context # Get current context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p) # Ignore z-axis for now.

        # TODO: Add marker if there is overflow text in the textbox.

        self.buildFrame(view, p) # Draw optional background, frame or borders.

        # Let the view draw frame info for debugging, in case view.showElementFrame == True
        view.drawElementFrame(self, p) 

        if self.drawBefore is not None: # Call if defined
            self.drawBefore(self, view, p)

        # Draw the text with horizontal and vertical alignment
        tw, th = self.bs.textSize()
        xOffset = yOffset = 0
        if self.css('yTextAlign') == MIDDLE:
            yOffset = (self.h - self.pb - self.pt - th)/2
        elif self.css('yTextAlign') == BOTTOM:
            yOffset = self.h - self.pb - self.pt - th
        if self.css('xTextAlign') == CENTER:
            xOffset = (self.w - self.pl - self.pr - tw)/2
        elif self.css('xTextAlign') == RIGHT:
            xOffset = self.w - self.pl - self.pr - tw

        textShadow = self.textShadow
        if textShadow:
            context.saveGraphicState()
            context.setShadow(textShadow)

        context.textBox(self.bs, (px + self.pl + xOffset, py + self.pb-yOffset,
            self.w-self.pl-self.pr, self.h-self.pb-self.pt))

        if textShadow:
            context.restoreGraphicState()

        if drawElements:
            # If there are child elements, recursively draw them over the pixel image.
            self.buildChildElements(view, p)

        # Draw markers on TextLine and TextRun positions.
        self._drawBaselines_drawBot(view, px, py)

        if view.showTextOverflowMarker and self.isOverflow():
            self._drawOverflowMarker_drawBot(view, px, py)

        if self.drawAfter is not None: # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(self, origin) # Depends on css flag 'showElementInfo'
Exemplo n.º 18
0
    def build(self, view, origin=ORIGIN, drawElements=True):
        u"""Draw a line on the current context canvas.

        >>> from pagebot.contexts.drawbotcontext import DrawBotContext
        >>> from pagebot.document import Document
        >>> c = DrawBotContext()
        >>> w, h = 300, 400
        >>> doc = Document(w=w, h=h, autoPages=1, padding=30, originTop=False, context=c)
        >>> page = doc[0]
        >>> e = Line(parent=page, x=0, y=20, w=page.w, h=3)
        >>> e.build(doc.getView(), (0, 0))
        >>> e.xy
        (0, 20)
        >>> e.size
        (300, 3, 1)
        >>> view = doc.getView()
        >>> e.build(view, (0, 0))

        >>> from pagebot.contexts.flatcontext import FlatContext 
        >>> from pagebot.document import Document
        >>> c = FlatContext()
        >>> doc = Document(w=w, h=h, autoPages=1, padding=30, originTop=False, context=c)
        >>> page = doc[0]
        >>> e = Line(parent=page, x=0, y=20, w=page.w, h=3)
        >>> # Allow the context to create a new document and page canvas. Normally view does it.
        >>> c.newPage(w, h) 
        >>> e.build(doc.getView(), (0, 0))
        >>> e.xy
        (0, 20)
        >>> e.size
        (300, 3, 1)
        """
        context = self.context  # Get current context and builder.

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        context.setStrokeColor(self.css('stroke', NO_COLOR),
                               self.css('strokeWidth'))
        context.newPath()
        context.moveTo((px, py))
        context.lineTo((px + self.w, py + self.h))
        context.drawPath()

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        if drawElements:
            # If there are child elements, recursively draw them over the pixel image.
            self.buildChildElements(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 19
0
    def build(self, view, origin=ORIGIN, drawElements=True):
        u"""Draw the oval in the current context canvas.

        >>> from pagebot.contexts.drawbotcontext import DrawBotContext
        >>> from pagebot.document import Document
        >>> c = DrawBotContext()
        >>> w, h = 300, 400
        >>> doc = Document(w=w, h=h, autoPages=1, padding=30, originTop=False, context=c)
        >>> page = doc[0]
        >>> e = Oval(parent=page, x=0, y=20, w=page.w, h=3)
        >>> e.build(doc.getView(), (0, 0))
        >>> e.xy
        (0, 20)
        >>> e.size
        (300, 3, 1)
        >>> view = doc.getView()
        >>> e.build(view, (0, 0))

        >>> from pagebot.contexts.flatcontext import FlatContext 
        >>> from pagebot.document import Document
        >>> c = FlatContext()
        >>> doc = Document(w=w, h=h, autoPages=1, padding=30, originTop=False, context=c)
        >>> page = doc[0]
        >>> e = Oval(parent=page, x=0, y=20, w=page.w, h=3)
        >>> # Allow the context to create a new document and page canvas. Normally view does it.
        >>> c.newPage(w, h) 
        >>> e.build(doc.getView(), (0, 0))
        >>> e.xy
        (0, 20)
        >>> e.size
        (300, 3, 1)
        """
        context = self.context  # Get current context and builder.

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        self.buildFrame(view, p)  # Draw optional frame or borders.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        context.fill(self.css('fill', NO_COLOR))
        context.stroke(self.css('stroke', NO_COLOR), self.css('strokeWidth'))
        context.oval(px, py, self.w, self.h)

        if drawElements:
            self.buildChildElements(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 20
0
    def draw(self, view, origin):
        c = self.doc.context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = self._applyAlignment(p)  # Ignore z-axis for now.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        fillColor = self.style.get('fill')
        if fillColor is not None:
            c.fill(fillColor)
        c.stroke(None)

        stepX = self.w / (self.sizeX + 1)
        stepY = self.h / (self.sizeY + 1)
        """Add more parametric layout behavior here."""
        for indexX in range(self.sizeX + 1):
            for indexY in range(self.sizeY + 1):
                ox = 30
                oy = 25
                ppx = ox + px + indexX * stepX
                ppy = oy + py + indexY * stepY
                if self.locations is not None:
                    location = choice(self.locations)
                else:
                    location = self.getRandomLocation()
                glyphPathScale = self.fontSize / self.font.info.unitsPerEm
                fillColor = self.style.get('textFill') or (0, 0, 0)
                c.drawGlyphPath(self.font.ttFont,
                                self.glyphNames[0],
                                px,
                                py,
                                location,
                                s=glyphPathScale,
                                fillColor=fillColor)
                if self.recipeAxes:
                    recipe = self.location2Recipe(location)
                    bs = c.newString(recipe, fontSize=4, fill=0)
                    w, h = bs.size()
                    c.text(
                        bs, ppx - stepX / 4, ppy - 24
                    )  # Bit of hack, we need the width of the glyph here.
                    if len(self.recipeAxes) > 3:
                        recipe = self.location2Recipe(location, 3, 6)
                        bs = c.newString(recipe, fontSize=4, fill=0)
                        w, h = bs.size()
                        c.text(bs, point=(
                            ppx - stepX / 4 + 30, ppy - 24
                        ))  # Bit of hack, we need the width of the glyph here.

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)
Exemplo n.º 21
0
    def draw(self, origin, view):
        u"""Draw the text on position (x, y). Draw background rectangle and/or frame if
        fill and/or stroke are defined."""
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        # TODO: Add marker if there is overflow text in the textbox.

        self.drawFrame(p, view)  # Draw optional frame or borders.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, p, view)

        # Draw the text with horizontal and vertical alignment
        tw, th = textSize(self.fs)
        xOffset = yOffset = 0
        if self.css('yTextAlign') == MIDDLE:
            yOffset = (self.h - self.pb - self.pt - th) / 2
        elif self.css('yTextAlign') == BOTTOM:
            yOffset = self.h - self.pb - self.pt - th
        if self.css('xTextAlign') == CENTER:
            xOffset = (self.w - self.pl - self.pr - tw) / 2
        elif self.css('xTextAlign') == RIGHT:
            xOffset = self.w - self.pl - self.pr - tw

        textShadow = self.textShadow
        if textShadow:
            save()
            setShadow(textShadow)

        textBox(self.fs,
                (px + self.pl + xOffset, py + self.pb - yOffset,
                 self.w - self.pl - self.pr, self.h - self.pb - self.pt))

        if textShadow:
            restore()

        # If there are any child elements, draw them over the text.
        self._drawElements(p, view)

        # Draw markers on TextLine and TextRun positions.
        self._drawBaselines(px, py, view)

        if view.showTextOverflowMarker and self.isOverflow():
            self._drawOverflowMarker(px, py, view)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, p, view)

        self._restoreScale()
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
Exemplo n.º 22
0
    def build_html(self, view, origin=None, drawElements=True):

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(view, p)

        if drawElements:
            self.buildElements(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(view, p)
Exemplo n.º 23
0
    def draw(self, origin, view):
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        setStrokeColor(self.css('stroke', NO_COLOR), self.css('strokeWidth'))
        newPath()
        moveTo((px, py))
        lineTo((px + self.w, py + self.h))
        drawPath()

        # If there are child elements, draw them over the line.
        self._drawElements(p, view)

        self._restoreScale()
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 24
0
    def build_html(self, view, origin=None, drawElements=True):

        self.build_css(view)
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        if drawElements:
            self.buildChildElements(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
Exemplo n.º 25
0
    def build_html(self, view, origin=None):
        u"""Build the Ruler in the current context

        >>> from pagebot.contexts import HtmlContext
        >>> from pagebot.document import Document
        >>> c = HtmlContext()
        >>> doc = Document(w=300, h=400, autoPages=1, padding=30, originTop=False, context=c)
        >>> page = doc[0]
        >>> e = Ruler(parent=page, x=0, y=20, w=page.w, h=3)
        >>> e.build(doc.getView(), (0, 0))
        >>> e.xy
        (0, 20)
        >>> e.size
        (300, 3, 1)
        >>> view = doc.getView()
        >>> e.build_html(view, (0, 0))
        """

        context = self.context  # Get current context and builder.
        b = context.b  # This is a bit more efficient than self.b once we got context

        self.build_css(view)
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        context.setFillColor(None)
        context.setStrokeColor(self.css('stroke', NO_COLOR),
                               self.css('strokeWidth'))
        #b.line((px + sIndent, py), (px + w, py))

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        b.hr(class_=self.class_)

        self.buildChildElements(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
Exemplo n.º 26
0
    def build(self, view, origin=ORIGIN, drawElements=True):
        u"""Like "rolled pasteboard" galleys can draw themselves, if the Composer decides to keep
        them in tact, instead of select, pick & choose elements, until the are all
        part of a page. In that case the w/h must have been set by the Composer to fit the
        containing page."""

        context = self.context  # Get current context and builder.
        b = context.b  # This is a bit more efficient than self.b once we got context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = self._applyAlignment(p)  # Ignore z-axis for now.

        # Let the view draw frame info for debugging, in case view.showElementFrame == True
        view.drawElementFrame(self, p)

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        context.setFillColor(
            self.OLD_PAPER_COLOR)  # Color of old paper: #F8ECC2
        gw, gh = self.getSize()
        b.rect(px, py, gw, gh)
        if drawElements:
            hook = 'build_' + self.context.b.PB_ID
            # Don't call self.buildElements, as we want to track the vertical positions
            gy = 0
            for e in self.elements:
                if not e.show:
                    continue
                # @@@ Find space and do more composition
                if hasattr(e, hook):
                    getattr(e, hook)(view, (px, py + gy))
                else:  # No implementation for this context, call default building method for this element.
                    e.build(view, (px, py + gy))
                gy += e.h

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(self, origin)
Exemplo n.º 27
0
    def build(self, view, origin=ORIGIN, drawElements=True):

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        self.drawFrame(view, p)  # Draw optional frame or borders.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        if drawElements:
            self.buildChildElements(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
Exemplo n.º 28
0
    def draw(self, origin, view):
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        self.drawFrame(p, view)  # Draw optional frame or borders.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, p, view)

        # If there are child elements, draw them over the text.
        # TODO: Needs updated x/y value
        self._drawElements(p, view)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, p, view)

        self._restoreScale()
        view.drawElementMetaInfo(
            self, origin)  # Depends on css flag 'showElementInfo'
Exemplo n.º 29
0
    def build(self, view, origin, drawElements=True):
        u"""Default drawing method just drawing the frame.
        Probably will be redefined by inheriting element classes."""
        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        self.buildFrame(view, p)  # Draw optional frame or borders.

        # Let the view draw frame info for debugging, in case view.showElementFrame == True
        view.drawElementFrame(self, p)

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, view, p)

        self.drawMatrix(view, p)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, view, p)

        self._restoreScale(view)
        view.drawElementMetaInfo(
            self, origin)  # Depends on flag 'view.showElementInfo'
Exemplo n.º 30
0
    def draw(self, origin, view):

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(p)
        px, py, _ = p = self._applyAlignment(p)  # Ignore z-axis for now.

        self.drawFrame(p, view)  # Draw optional frame or borders.

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, p, view)

        setFillColor(self.css('fill', NO_COLOR))
        setStrokeColor(self.css('stroke', NO_COLOR), self.css('strokeWidth'))
        oval(px, py, self.w, self.h)

        # If there are child elements, draw them over the text.
        self._drawElements(p, view)

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, p, view)

        self._restoreScale()
        view.drawElementMetaInfo(self, origin)