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


Python Group.scale方法代码示例

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


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

示例1: draw

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import scale [as 别名]
    def draw(self):
        fillColor = self.fillColor
        strokeColor = self.strokeColor
        g = Group()
        bg = self.background
        bd = self.border
        bdw = self.borderWidth
        shadow = self.shadow
        x, y = self.x, self.y
        if bg:
            if shadow is not None and 0<=shadow<1:
                shadow = Color(bg.red*shadow,bg.green*shadow,bg.blue*shadow)
            self._paintLogo(g,dy=-2.5, dx=2,fillColor=shadow)
        self._paintLogo(g,fillColor=fillColor,strokeColor=strokeColor)
        g.skew(kx=self.skewX, ky=self.skewY)
        g.shift(self._dx,self._dy)
        G = Group()
        G.add(g)
        _w, _h = 130, 86
        w, h = self.width, self.height
        if bg or (bd and bdw):
            G.insert(0,Rect(0,0,_w,_h,fillColor=bg,strokeColor=bd,strokeWidth=bdw))
        if w!=_w or h!=_h: G.scale(w/float(_w),h/float(_h))

        angle = self.angle
        if self.angle:
            w, h = w/2., h/2.
            G.shift(-w,-h)
            G.rotate(angle)
            G.shift(w,h)
        G.shift(x,y)
        return G
开发者ID:broodjeaap,项目名称:project-78-hr-2011-groep1,代码行数:34,代码来源:corp.py

示例2: ttf_ocr

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import scale [as 别名]
def ttf_ocr(font, key=None):
    gs = font.getGlyphSet()
    keys = [key for key in gs.keys() if key.startswith("uni")] if key is None else [key]
    c = []
    for i, key in enumerate(keys):
        if key not in gs:
            logger.info("No this key: %s" % key)
            c.append("")
            continue
        pen = ReportLabPen(gs, Path(fillColor=colors.black, strokeWidth=0.01))
        g = gs[key]
        g.draw(pen)
        w, h = 50, 50
        g = Group(pen.path)
        g.translate(10, 10)
        g.scale(0.02, 0.02)
        d = Drawing(w, h)
        d.add(g)
        renderPM.drawToFile(d, png_file.name, fmt="PNG")
        result = os.popen("tesseract %s stdout -l chi_sim -psm 5" % png_file.name).read().strip().decode("utf-8",
                                                                                                         "ignore")
        if len(result) != 1:
            result = os.popen("tesseract %s stdout -l chi_sim -psm 8" % png_file.name).read().strip().decode("utf-8",
                                                                                                             "ignore")
        logger.info("key: %s, result: %s" % (key, result))
        c.append(result)
    if key is not None:
        return c[0]
    return c
开发者ID:a625687551,项目名称:Spyder,代码行数:31,代码来源:autogg.py

示例3: convertText

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import scale [as 别名]
    def convertText(self, node):
        attrConv = self.attrConverter
        x, y = map(node.getAttribute, ('x', 'y'))
        x, y = map(attrConv.convertLength, (x, y))
        xml_space = node.getAttribute("{%s}space" % XML_NS)
        if xml_space:
            preserve_space = xml_space == 'preserve'
        else:
            preserve_space = self.preserve_space

        gr = Group()

        frag_lengths = []

        dx0, dy0 = 0, 0
        x1, y1 = 0, 0
        ff = attrConv.findAttr(node, "font-family") or "Helvetica"
        ff = attrConv.convertFontFamily(ff)
        fs = attrConv.findAttr(node, "font-size") or "12"
        fs = attrConv.convertLength(fs)
        for c in itertools.chain([node], node.getchildren()):
            has_x = False
            dx, dy = 0, 0
            baseLineShift = 0
            if node_name(c) == 'text':
                text = self.clean_text(c.text, preserve_space)
                if not text:
                    continue
            elif node_name(c) == 'tspan':
                text = self.clean_text(c.text, preserve_space)
                if not text:
                    continue
                x1, y1, dx, dy = [c.attrib.get(name, '') for name in ("x", "y", "dx", "dy")]
                has_x = x1 != ''
                x1, y1, dx, dy = map(attrConv.convertLength, (x1, y1, dx, dy))
                dx0 = dx0 + dx
                dy0 = dy0 + dy
                baseLineShift = c.attrib.get("baseline-shift", '0')
                if baseLineShift in ("sub", "super", "baseline"):
                    baseLineShift = {"sub":-fs/2, "super":fs/2, "baseline":0}[baseLineShift]
                else:
                    baseLineShift = attrConv.convertLength(baseLineShift, fs)
            else:
                continue

            frag_lengths.append(stringWidth(text, ff, fs))
            new_x = x1 if has_x else sum(frag_lengths[:-1])
            shape = String(x + new_x, y - y1 - dy0 + baseLineShift, text)
            self.applyStyleOnShape(shape, node)
            if node_name(c) == 'tspan':
                self.applyStyleOnShape(shape, c)

            gr.add(shape)

        gr.scale(1, -1)
        gr.translate(0, -2*y)

        return gr
开发者ID:pacoqueen,项目名称:ginn,代码行数:60,代码来源:svglib.py

示例4: _borderDraw

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import scale [as 别名]
 def _borderDraw(self,f):
     s = self.size  # abbreviate as we will use this a lot
     g = Group()
     g.add(f)
     x, y, sW = self.x+self.dx, self.y+self.dy, self.strokeWidth/2.
     g.insert(0,Rect(-sW, -sW, width=getattr(self,'_width',2*s)+3*sW, height=getattr(self,'_height',s)+2*sW,
             fillColor = None, strokeColor = self.strokeColor, strokeWidth=sW*2))
     g.shift(x,y)
     g.scale(s/_size, s/_size)
     return g
开发者ID:ShaulBarkan,项目名称:PRION,代码行数:12,代码来源:flags.py

示例5: draw

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import scale [as 别名]
    def draw(self):
        fillColor = self.fillColor
        strokeColor = self.strokeColor
        g = Group()
        bg = self.background
        bd = self.border
        bdw = self.borderWidth
        shadow = self.shadow
        x, y = self.x, self.y
        if bg:
            if shadow is not None and 0 <= shadow < 1:
                shadow = Color(bg.red * shadow, bg.green * shadow, bg.blue * shadow)
            self._paintLogo(g, dy=-2.5, dx=2, fillColor=shadow)
        self._paintLogo(
            g,
            fillColor=fillColor,
            strokeColor=strokeColor,
            _ocolors=getattr(self, "_ocolors", None),
            _pagecolors=getattr(self, "_pagecolors", None),
        )
        g.skew(kx=self.skewX, ky=self.skewY)
        g.shift(self._dx, self._dy)
        G = Group()
        G.add(g)
        _w, _h = 130, 86
        w, h = self.width, self.height
        if bg or (bd and bdw):
            G.insert(0, Rect(0, 0, _w, _h, fillColor=bg, strokeColor=bd, strokeWidth=bdw))
        if w != _w or h != _h:
            G.scale(w / float(_w), h / float(_h))

        angle = self.angle
        if self.angle:
            w, h = w / 2.0, h / 2.0
            G.shift(-w, -h)
            G.rotate(angle)
            G.shift(w, h)
        xFlip = getattr(self, "xFlip", 0) and -1 or 0
        yFlip = getattr(self, "yFlip", 0) and -1 or 0
        if xFlip or yFlip:
            sx = xFlip or 1
            sy = yFlip or 1
            G.shift(sx * x + w * xFlip, sy * y + yFlip * h)
            G = Group(G, transform=(sx, 0, 0, sy, 0, 0))
        else:
            G.shift(x, y)
        return G
开发者ID:FatihZor,项目名称:infernal-twin,代码行数:49,代码来源:corp.py

示例6: render

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import scale [as 别名]
    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

            return self.drawing

        elif node.tag in (self.SVG_G, self.SVG_A):
            self.level += 1

            # set this levels style
            style = self.styles[self.level - 1].copy()
            style = self.nodeStyle(node, style)
            self.styles[self.level] = style

            group = Group()

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

            parent.add(group)

            transforms = node.get('transform')
            if transforms:
                for op in parseTransform.iterparse(transforms):
                    self.applyTransformOnGroup(group, op)

            self.level -= 1

        elif node.tag == self.SVG_USE:
            self.level += 1

            # set this levels style
            style = self.styles[self.level - 1].copy()
            style = self.nodeStyle(node, style)
            self.styles[self.level] = style

            group = Group()

            # link id
            link_id = node.get(self.LINK).lstrip('#')

            # find linked node in defs or symbol section
            target = None
#.........这里部分代码省略.........
开发者ID:eseifert,项目名称:svg2rlg,代码行数:103,代码来源:svg2rlg.py

示例7: TTFont

# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import scale [as 别名]
	from fontTools.ttLib import TTFont
	from reportlab.lib import colors

	path = sys.argv[1]
	glyphName = sys.argv[2]
	if (len(sys.argv) > 3):
		imageFile = sys.argv[3]
	else:
		imageFile = "%s.png" % glyphName

	font = TTFont(path)  # it would work just as well with fontTools.t1Lib.T1Font
	gs = font.getGlyphSet()
	pen = ReportLabPen(gs, Path(fillColor=colors.red, strokeWidth=5))
	g = gs[glyphName]
	g.draw(pen)

	w, h = g.width, 1000
	from reportlab.graphics import renderPM
	from reportlab.graphics.shapes import Group, Drawing, scale

	# Everything is wrapped in a group to allow transformations.
	g = Group(pen.path)
	g.translate(0, 200)
	g.scale(0.3, 0.3)

	d = Drawing(w, h)
	d.add(g)

	renderPM.drawToFile(d, imageFile, fmt="PNG")
开发者ID:AlexShiLucky,项目名称:fonttools,代码行数:31,代码来源:reportLabPen.py

示例8: frozenset

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

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

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

    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 == 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

            return self.drawing

        elif node.tag in (self.SVG_G, self.SVG_A, self.SVG_SYMBOL):
            self.level += 1

            # set this levels style
            style = self.styles[self.level - 1].copy()
            style = self.nodeStyle(node, style)
#.........这里部分代码省略.........
开发者ID:alvingonzales,项目名称:z3c.rml,代码行数:103,代码来源:svg2rlg.py


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