Esempio n. 1
0
def bezier_arc_from_end_points(x1, y1, rx, ry, phi, fA, fS, x2, y2):
    if phi:
        # Our box bezier arcs can't handle rotations directly
        # move to a well known point, eliminate phi and transform the other point
        mx = mmult(rotate(-phi), translate(-x1, -y1))
        tx2, ty2 = transformPoint(mx, (x2, y2))
        # Convert to box form in unrotated coords
        cx, cy, rx, ry, start_ang, extent = end_point_to_center_parameters(
            0, 0, tx2, ty2, fA, fS, rx, ry
        )
        bp = bezier_arc_from_centre(cx, cy, rx, ry, start_ang, extent)
        # Re-rotate by the desired angle and add back the translation
        mx = mmult(translate(x1, y1), rotate(phi))
        res = []
        for x1, y1, x2, y2, x3, y3, x4, y4 in bp:
            res.append(
                transformPoint(mx, (x1, y1)) + transformPoint(mx, (x2, y2)) +
                transformPoint(mx, (x3, y3)) + transformPoint(mx, (x4, y4))
            )
        return res
    else:
        cx, cy, rx, ry, start_ang, extent = end_point_to_center_parameters(
            x1, y1, x2, y2, fA, fS, rx, ry
        )
        return bezier_arc_from_centre(cx, cy, rx, ry, start_ang, extent)
Esempio n. 2
0
def bezier_arc_from_end_points(x1, y1, rx, ry, phi, fA, fS, x2, y2):
    if phi:
        # Our box bezier arcs can't handle rotations directly
        # move to a well known point, eliminate phi and transform the other point
        mx = mmult(rotate(-phi), translate(-x1, -y1))
        tx2, ty2 = transformPoint(mx, (x2, y2))
        # Convert to box form in unrotated coords
        cx, cy, rx, ry, start_ang, extent = end_point_to_center_parameters(
            0, 0, tx2, ty2, fA, fS, rx, ry
        )
        bp = bezier_arc_from_centre(cx, cy, rx, ry, start_ang, extent)
        # Re-rotate by the desired angle and add back the translation
        mx = mmult(translate(x1, y1), rotate(phi))
        res = []
        for x1, y1, x2, y2, x3, y3, x4, y4 in bp:
            res.append(
                transformPoint(mx, (x1, y1)) + transformPoint(mx, (x2, y2)) +
                transformPoint(mx, (x3, y3)) + transformPoint(mx, (x4, y4))
            )
        return res
    else:
        cx, cy, rx, ry, start_ang, extent = end_point_to_center_parameters(
            x1, y1, x2, y2, fA, fS, rx, ry
        )
        return bezier_arc_from_centre(cx, cy, rx, ry, start_ang, extent)
Esempio n. 3
0
def bezier_arc_from_end_points(x1, y1, rx, ry, phi, fA, fS, x2, y2):
    if (x1 == x2 and y1 == y2):
        # From https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes:
        # If the endpoints (x1, y1) and (x2, y2) are identical, then this is
        # equivalent to omitting the elliptical arc segment entirely.
        return []
    if phi:
        # Our box bezier arcs can't handle rotations directly
        # move to a well known point, eliminate phi and transform the other point
        mx = mmult(rotate(-phi), translate(-x1, -y1))
        tx2, ty2 = transformPoint(mx, (x2, y2))
        # Convert to box form in unrotated coords
        cx, cy, rx, ry, start_ang, extent = end_point_to_center_parameters(
            0, 0, tx2, ty2, fA, fS, rx, ry)
        bp = bezier_arc_from_centre(cx, cy, rx, ry, start_ang, extent)
        # Re-rotate by the desired angle and add back the translation
        mx = mmult(translate(x1, y1), rotate(phi))
        res = []
        for x1, y1, x2, y2, x3, y3, x4, y4 in bp:
            res.append(
                transformPoint(mx, (x1, y1)) + transformPoint(mx, (x2, y2)) +
                transformPoint(mx, (x3, y3)) + transformPoint(mx, (x4, y4)))
        return res
    else:
        cx, cy, rx, ry, start_ang, extent = end_point_to_center_parameters(
            x1, y1, x2, y2, fA, fS, rx, ry)
        return bezier_arc_from_centre(cx, cy, rx, ry, start_ang, extent)
def computeTransformMatrix(transformList):
    """ compute the transform matrix that is the concatenation of all transforms in the 
        specifed transformList
    """
    transformMatrix = shapes.nullTransform()
    for transform in transformList:
        if not 'transform' in transform:
            raise InvalidTransform()
        if transform['transform'] is 'translate':
            transformMatrix = shapes.mmult(
                transformMatrix,
                shapes.translate(transform["tx"], transform["ty"]))
        elif transform['transform'] is 'rotate':
            transformMatrix = shapes.mmult(
                transformMatrix,
                shapes.translate(transform['cx'], transform['cy']))
            transformMatrix = shapes.mmult(transformMatrix,
                                           shapes.rotate(transform["theta"]))
            transformMatrix = shapes.mmult(
                transformMatrix,
                shapes.translate(-1.0 * transform['cx'],
                                 -1.0 * transform['cy']))
        elif transform['transform'] is 'scale':
            transformMatrix = shapes.mmult(
                transformMatrix, shapes.scale(transform['sx'],
                                              transform['sy']))
        else:
            raise InvalidTransform(transform['transform'])
    return transformMatrix
Esempio n. 5
0
 def _render(self, name, intent, dataGetter, **kwds):
     from xml.sax.saxutils import escape
     spec = self.intentSpecs[intent]
     valueName = spec.valueName
     D = self._defaults.get(intent, {}).copy()
     escapeAction = D.get('escape')
     D.update(kwds)
     if self.uppercase and 'content' in D and isinstance(D['content'], str):
         D['content'] = self.upper(D['content'])
     if valueName not in kwds:
         data = dataGetter(name, intent)
         if self.uppercase and isinstance(data, str):
             data = self.upper(data)
         if escapeAction == 'escape':
             data = escape(data)
         D[valueName] = data
     if spec.preRenderFunc: spec.preRenderFunc(D)
     rml = []
     add = rml.append
     if 'rotation' in D:
         angle = D['rotation']
         add('<saveState/><rotate degrees="%s"/>' % angle)
         angle = float(angle)
         from reportlab.graphics.shapes import rotate, inverse, transformPoint
         D['x'], D['y'] = transformPoint(inverse(rotate(float(angle))),
                                         (float(D['x']), float(D['y'])))
     add(spec.rml(D))
     if 'rotation' in D: add('<restoreState/>')
     return ''.join(rml)  #+('<!--%s-->' % name)
Esempio n. 6
0
def getCaptcha(n=5,fontName='Courier',fontSize=14,text=None,fillColor=None):
    '''return n random chars in a string and in a byte string structured
    as a GIF image'''
    from reportlab.graphics.shapes import Drawing, Group, String, \
        rotate, skewX, skewY, mmult, translate, Rect
    if not text:
        from random import randint, uniform
        text=''.join([_allowed[randint(0,_mx)] for i in range(n)])
    else:
        uniform = lambda l,h: 0.5*(l+h)
        n = len(text)
    baseline = 0
    x = 0
    G0 = Group()
    for c in text:
        x += 1
        A = translate(x,uniform(baseline-5,baseline+5))
        A = mmult(A,rotate(uniform(-15,15)))
        A = mmult(A,skewX(uniform(-8,8)))
        A = mmult(A,skewY(uniform(-8,8)))
        G = Group(transform=A)
        G.add(String(0,0,c,fontname=fontName,fontSize=fontSize))
        G0.add(G)
        x0,y0,x1,y1 = G0.getBounds()
        x = 1+x1
    G0.transform=translate(2-x0,2-y0)
    W = 4+x1-x0
    H = 4+y1-y0
    D = Drawing(W,H)
    if fillColor:
        from reportlab.lib.colors import toColor
        D.add(Rect(0,0,W,H, fillColor = toColor(fillColor),strokeColor=None))
    D.add(G0)
    return text, D.asString('gif')
Esempio n. 7
0
 def _render(self,name,intent,dataGetter,**kwds):
     from xml.sax.saxutils import escape
     spec = self.intentSpecs[intent]
     valueName = spec.valueName
     D=self._defaults.get(intent,{}).copy()
     escapeAction=D.get('escape')
     D.update(kwds)
     if self.uppercase and 'content' in D and isinstance(D['content'],str):
         D['content'] = self.upper(D['content'])
     if valueName not in kwds:
         data = dataGetter(name, intent)
         if self.uppercase and isinstance(data,str):
             data = self.upper(data)
         if escapeAction == 'escape':
             data = escape(data)
         D[valueName] = data
     if spec.preRenderFunc: spec.preRenderFunc(D)
     rml = []
     add = rml.append
     if 'rotation' in D:
         angle = D['rotation']
         add('<saveState/><rotate degrees="%s"/>' % angle)
         angle = float(angle)
         from reportlab.graphics.shapes import rotate, inverse, transformPoint
         D['x'],D['y'] = transformPoint(inverse(rotate(float(angle))),(float(D['x']),float(D['y'])))
     add(spec.rml(D))
     if 'rotation' in D: add('<restoreState/>')
     return ''.join(rml)#+('<!--%s-->' % name)
Esempio n. 8
0
def y_axis_title(x_axis, y_axis, side):
    if side == "left":
        x = scale(y_axis["min"], y_axis)
        y = -(scale(x_axis["min"], x_axis)) + 20
        tf = rotate(90)
    else:
        x = -(scale(y_axis["max"], y_axis))
        y = scale(x_axis["max"], x_axis) + 20
        tf = rotate(270)
    return [
        String(x,
               y,
               y_axis["title"],
               transform=tf,
               fontSize=11,
               fontName="Helvetica")
    ]
Esempio n. 9
0
 def doTest0(c, vp, x, y, c0=0x0,c1=0xff0000, angle=0, c2=0xff00ff):
     c.ctm=(1,0,0,1,x,y)
     c.fillColor = c0
     doVPath(c,vp,128,128)
     c.ctm = shapes.mmult(c.ctm, shapes.rotate(180))
     c.fillColor = c1
     doVPath(c,vp,128,128)
     c.ctm=(1,0,0,1,x,y)
     c.pathBegin()
     c.ctm=(1,0,0,1,x+20,y)
     c.ctm = shapes.mmult(c.ctm, shapes.rotate(angle))
     c.moveTo(0,0)
     c.lineTo(20,0)
     c.strokeColor = c2
     c.pathStroke()
     c.ctm=(1,0,0,1,x+20,y-20)
     c.drawString(0,0,"Robin")
Esempio n. 10
0
 def doTest0(c, vp, x, y, c0=0x0,c1=0xff0000, angle=0, c2=0xff00ff):
     c.ctm=(1,0,0,1,x,y)
     c.fillColor = c0
     doVPath(c,vp,128,128)
     c.ctm = shapes.mmult(c.ctm, shapes.rotate(180))
     c.fillColor = c1
     doVPath(c,vp,128,128)
     c.ctm=(1,0,0,1,x,y)
     c.pathBegin()
     c.ctm=(1,0,0,1,x+20,y)
     c.ctm = shapes.mmult(c.ctm, shapes.rotate(angle))
     c.moveTo(0,0)
     c.lineTo(20,0)
     c.strokeColor = c2
     c.pathStroke()
     c.ctm=(1,0,0,1,x+20,y-20)
     c.drawString(0,0,"Robin")
def computeTransformMatrix(transformList):
    """ compute the transform matrix that is the concatenation of all transforms in the 
        specifed transformList
    """
    transformMatrix = shapes.nullTransform()
    for transform in transformList:
        if not 'transform' in transform:
            raise InvalidTransform()
        if transform['transform'] is 'translate':
            transformMatrix = shapes.mmult(transformMatrix, shapes.translate(transform["tx"], transform["ty"]))
        elif transform['transform'] is 'rotate':
            transformMatrix = shapes.mmult(transformMatrix, shapes.translate(transform['cx'], transform['cy']))
            transformMatrix = shapes.mmult(transformMatrix, shapes.rotate(transform["theta"]))
            transformMatrix = shapes.mmult(transformMatrix, shapes.translate(-1.0 * transform['cx'], -1.0 * transform['cy']))
        elif transform['transform'] is 'scale':
            transformMatrix = shapes.mmult(transformMatrix, shapes.scale(transform['sx'], transform['sy']))
        else:
            raise InvalidTransform(transform['transform'])
    return transformMatrix
Esempio n. 12
0
            doCTest(doCPath1, c, 0, 0)
            do_save(c, 1)

        if flagged(2):
            c = renderPM.PMCanvas(25, 25, bg=0xffffff)
            doCTest(doCPath2, c, 0, 0)
            do_save(c, 2, txt=1, pil=1)

        if flagged(3):
            c = renderPM.PMCanvas(256, 256, bg=0xffffff)
            c.fillColor = 0x000000
            c.setFont('Times-Roman', 18)
            text = "ABC"
            c.ctm = (1, 0, 0, ("invert" in sys.argv) and -1 or 1, 127.5, 127.5)
            c.drawString(0, 0, text)
            c.ctm = shapes.mmult(c.ctm, shapes.rotate(180))
            c.fillColor = 0xff0000
            c.drawString(0, 0, text)
            do_save(c, 3)

        if flagged(4):
            c = renderPM.PMCanvas(25, 25, bg=0xffffff)
            doCTest(doCPath4, c, 0, 0, c0=0x8000, c1=0xff0000)
            do_save(c, 4)

        if flagged(5):
            c = renderPM.PMCanvas(25, 25, bg=0xffffff)
            doCTest(doCPath5, c, 0, 0)
            do_save(c, 5)

        if flagged(6):
Esempio n. 13
0
            doCTest(doCPath1, c, 0, 0 )
            do_save(c,1)

        if flagged(2):
            c = renderPM.PMCanvas(25, 25, bg=0xffffff)
            doCTest(doCPath2, c, 0, 0 )
            do_save(c,2,txt=1,pil=1)

        if flagged(3):
            c = renderPM.PMCanvas(256, 256, bg=0xffffff)
            c.fillColor = 0x000000
            c.setFont('Times-Roman',18)
            text = "ABC"
            c.ctm=(1,0,0,("invert" in sys.argv) and -1 or 1, 127.5,127.5)
            c.drawString(0, 0, text)
            c.ctm = shapes.mmult(c.ctm, shapes.rotate(180))
            c.fillColor = 0xff0000
            c.drawString(0, 0, text)
            do_save(c,3)

        if flagged(4):
            c = renderPM.PMCanvas(25, 25, bg=0xffffff)
            doCTest(doCPath4, c, 0, 0, c0=0x8000, c1=0xff0000)
            do_save(c,4)

        if flagged(5):
            c = renderPM.PMCanvas(25, 25, bg=0xffffff)
            doCTest(doCPath5, c, 0, 0 )
            do_save(c,5)

        if flagged(6):