当前位置: 首页>>代码示例>>Python>>正文


Python Group.getBounds方法代码示例

本文整理汇总了Python中reportlab.graphics.shapes.Group.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Python Group.getBounds方法的具体用法?Python Group.getBounds怎么用?Python Group.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.graphics.shapes.Group的用法示例。


在下文中一共展示了Group.getBounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getCaptcha

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import getBounds [as 别名]
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')
开发者ID:AndyKovv,项目名称:hostel,代码行数:36,代码来源:captcha.py

示例2: frozenset

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import getBounds [as 别名]
class Renderer:
    LINK = '{http://www.w3.org/1999/xlink}href'

    SVG_NS = '{http://www.w3.org/2000/svg}'
    SVG_ROOT        = SVG_NS + 'svg'
    SVG_A           = SVG_NS + 'a'
    SVG_G           = SVG_NS + 'g'
    SVG_TITLE       = SVG_NS + 'title'
    SVG_DESC        = SVG_NS + 'desc'
    SVG_DEFS        = SVG_NS + 'defs'
    SVG_SYMBOL      = SVG_NS + 'symbol'
    SVG_USE         = SVG_NS + 'use'
    SVG_RECT        = SVG_NS + 'rect'
    SVG_CIRCLE      = SVG_NS + 'circle'
    SVG_ELLIPSE     = SVG_NS + 'ellipse'
    SVG_LINE        = SVG_NS + 'line'
    SVG_POLYLINE    = SVG_NS + 'polyline'
    SVG_POLYGON     = SVG_NS + 'polygon'
    SVG_PATH        = SVG_NS + 'path'
    SVG_TEXT        = SVG_NS + 'text'
    SVG_TSPAN       = SVG_NS + 'tspan'
    SVG_IMAGE       = SVG_NS + 'image'

    SVG_NODES = frozenset((
        SVG_ROOT, SVG_A, SVG_G, SVG_TITLE, SVG_DESC, SVG_DEFS, SVG_SYMBOL,
        SVG_USE, SVG_RECT, SVG_CIRCLE, SVG_ELLIPSE, SVG_LINE, SVG_POLYLINE,
        SVG_POLYGON, SVG_PATH, SVG_TEXT, SVG_TSPAN, SVG_IMAGE
    ))

    SKIP_NODES = frozenset((SVG_TITLE, SVG_DESC, SVG_DEFS, SVG_SYMBOL))
    PATH_NODES = frozenset((SVG_RECT, SVG_CIRCLE, SVG_ELLIPSE, SVG_LINE,
                            SVG_POLYLINE, SVG_POLYGON, SVG_PATH, SVG_TEXT))

    def __init__(self, filename):
        self.filename = filename
        self.level = 0
        self.styles = {}
        self.mainGroup = Group()
        self.drawing = None
        self.root = None

    def render(self, node, parent=None):
        if parent is None:
            parent = self.mainGroup

        # ignore if display = none
        display = node.get('display')
        if display == "none":
            return

        if node.tag == self.SVG_ROOT:
            self.level += 1

            if not self.drawing is None:
                raise SVGError('drawing already created!')

            self.root = node

            # default styles
            style = {
                'color':'none',
                'fill':'none',
                'stroke':'none',
                'font-family':'Helvetica',
                'font-size':'12'
            }

            self.styles[self.level] = style

            # iterate children
            for child in node:
                self.render(child, self.mainGroup)

            # create drawing
            width = node.get('width', '100%')
            height = node.get('height', '100%')

            if node.get("viewBox"):
                try:
                    minx, miny, width, height = node.get("viewBox").split()
                except ValueError:
                    raise SVGError("viewBox values not valid")

            if width.endswith('%') and height.endswith('%'):
                # handle relative size
                wscale = parseLength(width) / 100.
                hscale = parseLength(height) / 100.

                xL,yL,xH,yH =  self.mainGroup.getBounds()
                self.drawing = Drawing(xH*wscale + xL, yH*hscale + yL)

            else:
                self.drawing = Drawing(parseLength(width), parseLength(height))

            height = self.drawing.height
            self.mainGroup.scale(1, -1)
            self.mainGroup.translate(0, -height)
            self.drawing.add(self.mainGroup)

            self.level -= 1
#.........这里部分代码省略.........
开发者ID:eseifert,项目名称:svg2rlg,代码行数:103,代码来源:svg2rlg.py


注:本文中的reportlab.graphics.shapes.Group.getBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。