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


Python colors.Color方法代码示例

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


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

示例1: test_0

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def test_0(self):
        "Test color attribute conversion."

        mapping = (
            ("red", colors.red),
            ("#ff0000", colors.red),
            ("#ff000055", colors.Color(1, 0, 0, 1/3.0)),
            ("#f00", colors.red),
            ("#f00f", colors.red),
            ("rgb(100%,50%,10%)", colors.Color(1, 1.0/255 * 128, 1.0/255 * 26, 1)),
            ("rgb(255, 0, 0)", colors.red),
            ("rgba(255, 255, 128, .5)", colors.Color(1, 1, 1.0/255 * 128, .5)),
            ("fuchsia", colors.Color(1, 0, 1, 1)),
            ("slategrey", colors.HexColor(0x708090)),
            ("transparent", colors.Color(0, 0, 0, 0)),
            ("whatever", None),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertColor, mapping)
        assert len(failed) == 0 
开发者ID:deeplook,项目名称:svglib,代码行数:22,代码来源:test_basic.py

示例2: highlightAnnotation

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def highlightAnnotation(self, contents, Rect, QuadPoints=None, Color=[0.83, 0.89, 0.95], addtopage=1,
                            name=None, relative=0, **kw):
        """
        Allows adding of a highlighted annotation.

        Rect: Mouseover area to show contents of annotation
        QuadPoints: List of four x/y points [TOP-LEFT, TOP-RIGHT, BOTTOM-LEFT, BOTTOM-RIGHT]
          These points outline the areas to highlight.
          You can have multiple groups of four to allow multiple highlighted areas.
          Is in the format [x1, y1, x2, y2, x3, y3, x4, y4, x1, y1, x2, y2, x3, y3, x4, y4] etc
          QuadPoints defaults to be area inside of passed in Rect
        Color: The color of the highlighting.
        """
        Rect = self._absRect(Rect, relative)
        if not QuadPoints:
            QuadPoints = pdfdoc.rect_to_quad(Rect)
        self._addAnnotation(pdfdoc.HighlightAnnotation(Rect, contents, QuadPoints, Color, **kw), name, addtopage) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:canvas.py

示例3: readColor

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def readColor(text):
    """Read color names or tuples, RGB or CMYK, and return a Color object."""
    if not text:
        return None
    from reportlab.lib import colors
    from string import letters
    if text[0] in letters:
        return colors.__dict__[text]
    tup = lengthSequence(text)

    msg = "Color tuple must have 3 (or 4) elements for RGB (or CMYC)."
    assert 3 <= len(tup) <= 4, msg
    msg = "Color tuple must have all elements <= 1.0."
    for i in range(len(tup)):
        assert tup[i] <= 1.0, msg

    if len(tup) == 3:
        colClass = colors.Color
    elif len(tup) == 4:
        colClass = colors.CMYKColor
    return colClass(*tup) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:para.py

示例4: drawBoundary

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def drawBoundary(self,canv):
        "draw the frame boundary as a rectangle (primarily for debugging)."
        from reportlab.lib.colors import Color, toColor
        sb = self.showBoundary
        ss = isinstance(sb,(str,tuple,list)) or isinstance(sb,Color)
        w = -1
        if ss:
            c = toColor(sb,self)
            ss = c is not self
        elif isinstance(sb,ShowBoundaryValue) and sb:
            c = toColor(sb.color,self)
            w = sb.width
            ss = c is not self
        if ss:
            canv.saveState()
            canv.setStrokeColor(c)
            if w>=0:
                canv.setLineWidth(w)
        canv.rect(
                self._x1,
                self._y1,
                self._x2 - self._x1,
                self._y2 - self._y1
                )
        if ss: canv.restoreState() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:frames.py

示例5: draw

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def draw(self):
        sx = 0.5
        fillColor = self.fillColor
        strokeColor = self.strokeColor
        shadow = Color(fillColor.red*sx,fillColor.green*sx,fillColor.blue*sx)
        g = Group()
        g2= Group()
        g.add(Rect(fillColor=fillColor, strokeColor=fillColor, x=0, y=0, width=self._w, height=self._h))
        sx = (self._w-2)/self._sw()
        g2.scale(sx,1)
        self._addPage(g2,strokeWidth=3,dx=2,dy=-2.5,color=shadow)
        self._addPage(g2,strokeWidth=3,color=strokeColor)
        g2.scale(1/sx,1)
        g2.add(self._getText(x=1,y=0,color=shadow))
        g2.add(self._getText(x=0,y=1,color=strokeColor))
        g2.scale(sx,1)
        g2.skew(kx=10, ky=0)
        g2.shift(0,38)
        g.add(g2)
        g.scale(self.width/self._w,self.height/self._h)
        g.shift(self.x,self.y)
        return g 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:corp.py

示例6: test_use_node_properties

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def test_use_node_properties(self):
        """
        Properties on the use node apply to the referenced item.
        """
        drawing = svglib.svg2rlg(io.StringIO(textwrap.dedent(u'''\
            <?xml version="1.0"?>
            <svg version="1.1"
                 xmlns:xlink="http://www.w3.org/1999/xlink"
                 width="900" height="600">
                <path id="a" fill="#FF0000" d="M-15 37.57h60L-15 0v80h60l-60-60z"/>
                <use stroke="#003893" stroke-width="5" xlink:href="#a"/>
                <use stroke="#003893" stroke-width="2" xlink:href="#a"/>
            </svg>
        ''')))
        use_path1 = drawing.contents[0].contents[1].contents[0].contents[0]
        use_path2 = drawing.contents[0].contents[2].contents[0].contents[0]
        # Attribute from <path> node
        assert use_path1.fillColor == colors.Color(1, 0, 0, 1)
        # Attribute from <use> node
        assert use_path1.strokeWidth == 5
        assert use_path2.strokeWidth == 2 
开发者ID:deeplook,项目名称:svglib,代码行数:23,代码来源:test_basic.py

示例7: drawBoundary

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def drawBoundary(self,canv):
        "draw the frame boundary as a rectangle (primarily for debugging)."
        from reportlab.lib.colors import Color, CMYKColor, toColor
        sb = self.showBoundary
        ss = type(sb) in (type(''),type(()),type([])) or isinstance(sb,Color)
        w = -1
        if ss:
            c = toColor(sb,self)
            ss = c is not self
        elif isinstance(sb,ShowBoundaryValue) and sb:
            c = toColor(sb.color,self)
            w = sb.width
            ss = c is not self
        if ss:
            canv.saveState()
            canv.setStrokeColor(c)
            if w>=0:
                canv.setLineWidth(w)
        canv.rect(
                self._x1,
                self._y1,
                self._x2 - self._x1,
                self._y2 - self._y1
                )
        if ss: canv.restoreState() 
开发者ID:gltn,项目名称:stdm,代码行数:27,代码来源:frames.py

示例8: __init__

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def __init__(self):
        self.labelFontName = "Helvetica-Bold"
        self.labelFontSize = 10
        self.labelStrokeColor = black
        self.labelFillColor = white
        self.startColor = colors.Color(232/255.0,224/255.0,119/255.0)
        self.endColor = colors.Color(25/255.0,77/255.0,135/255.0)
        self.numberOfBoxes = 7
        self.trianglePosition = 7
        self.triangleHeight = 0.12*cm
        self.triangleWidth = 0.38*cm
        self.triangleFillColor = white
        self.triangleStrokeColor = black
        self.triangleStrokeWidth = 0.58
        self.boxHeight = 0.55*cm
        self.boxWidth = 0.73*cm
        self.boxSpacing = 0.075*cm
        self.boxOutlineColor = black
        self.boxOutlineWidth = 0.58
        self.leftPadding=5
        self.rightPadding=5
        self.topPadding=5
        self.bottomPadding=5
        self.background=None
        self.sourceLabelText = "Source: ReportLab"
        self.sourceLabelOffset = 0.2*cm
        self.sourceLabelFontName = "Helvetica-Oblique"
        self.sourceLabelFontSize = 6
        self.sourceLabelFillColor = black 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:31,代码来源:slidebox.py

示例9: drawOn

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def drawOn(self, canvas, x, y) :
        """Draws some blocks around the identifier's characters."""
        BaseLTOLabel.drawOn(self,
                            canvas,
                            x,
                            y)
        canvas.saveState()
        canvas.setLineWidth(self.LINEWIDTH)
        canvas.setStrokeColorRGB(0, 0, 0)
        canvas.translate(x, y)
        xblocks = (self.LABELWIDTH-(self.NBBLOCKS*self.BLOCKWIDTH))/2.0
        for i in range(self.NBBLOCKS) :
            (font, size) = self.LABELFONT
            newfont = self.LABELFONT
            if i == (self.NBBLOCKS - 1) :
                part = self.label[i:]
                (font, size) = newfont
                size /= 2.0
                newfont = (font, size)
            else :
                part = self.label[i]
            canvas.saveState()
            canvas.translate(xblocks+(i*self.BLOCKWIDTH), 0)
            if self.colored and part.isdigit() :
                canvas.setFillColorRGB(*getattr(colors,
                                                self.COLORSCHEME[int(part)],
                                                colors.Color(1, 1, 1)).rgb())
            else:
                canvas.setFillColorRGB(1, 1, 1)
            canvas.rect(0, 0, self.BLOCKWIDTH, self.BLOCKHEIGHT, fill=True)
            canvas.translate((self.BLOCKWIDTH+canvas.stringWidth(part, *newfont))/2.0,
                             (self.BLOCKHEIGHT/2.0))
            canvas.rotate(90.0)
            canvas.setFont(*newfont)
            canvas.setFillColorRGB(0, 0, 0)
            canvas.drawCentredString(0, 0, part)
            canvas.restoreState()
        canvas.restoreState() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:40,代码来源:lto.py

示例10: setFillColor

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def setFillColor(self, aColor, alpha=None):
        """Takes a color object, allowing colors to be referred to by name"""
        if self._enforceColorSpace:
            aColor = self._enforceColorSpace(aColor)
        if isinstance(aColor, CMYKColor):
            d = aColor.density
            c,m,y,k = (d*aColor.cyan, d*aColor.magenta, d*aColor.yellow, d*aColor.black)
            self._fillColorObj = aColor
            name = self._checkSeparation(aColor)
            if name:
                self._code.append('/%s cs %s scn' % (name,fp_str(d)))
            else:
                self._code.append('%s k' % fp_str(c, m, y, k))
        elif isinstance(aColor, Color):
            rgb = (aColor.red, aColor.green, aColor.blue)
            self._fillColorObj = aColor
            self._code.append('%s rg' % fp_str(rgb) )
        elif isinstance(aColor,(tuple,list)):
            l = len(aColor)
            if l==3:
                self._fillColorObj = aColor
                self._code.append('%s rg' % fp_str(aColor) )
            elif l==4:
                self._fillColorObj = aColor
                self._code.append('%s k' % fp_str(aColor))
            else:
                raise ValueError('Unknown color %r' % aColor)
        elif isStr(aColor):
            self.setFillColor(toColor(aColor))
        else:
            raise ValueError('Unknown color %r' % aColor)
        if alpha is not None:
            self.setFillAlpha(alpha)
        elif getattr(aColor, 'alpha', None) is not None:
            self.setFillAlpha(aColor.alpha) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:37,代码来源:textobject.py

示例11: _normalizeColor

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def _normalizeColor(aColor):
    if isinstance(aColor, CMYKColor):
        d = aColor.density
        return "DeviceCMYK", tuple(c*d for c in aColor.cmyk())
    elif isinstance(aColor, Color):
        return "DeviceRGB", aColor.rgb()
    elif isinstance(aColor, (tuple, list)):
        l = len(aColor)
        if l == 3:
            return "DeviceRGB", aColor
        elif l == 4:
            return "DeviceCMYK", aColor
    elif isinstance(aColor, str):
        return _normalizeColor(toColor(aColor))
    raise ValueError("Unknown color %r" % aColor) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:canvas.py

示例12: _setCellStyle

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def _setCellStyle(cellStyles, i, j, op, values):
    #new = CellStyle('<%d, %d>' % (i,j), cellStyles[i][j])
    #cellStyles[i][j] = new
    ## modify in place!!!
    new = cellStyles[i][j]
    if op == 'FONT':
        n = len(values)
        new.fontname = values[0]
        if n>1:
            new.fontsize = values[1]
            if n>2:
                new.leading = values[2]
            else:
                new.leading = new.fontsize*1.2
    elif op in ('FONTNAME', 'FACE'):
        new.fontname = values[0]
    elif op in ('SIZE', 'FONTSIZE'):
        new.fontsize = values[0]
    elif op == 'LEADING':
        new.leading = values[0]
    elif op == 'TEXTCOLOR':
        new.color = colors.toColor(values[0], colors.Color(0,0,0))
    elif op in ('ALIGN', 'ALIGNMENT'):
        new.alignment = values[0]
    elif op == 'VALIGN':
        new.valign = values[0]
    elif op == 'LEFTPADDING':
        new.leftPadding = values[0]
    elif op == 'RIGHTPADDING':
        new.rightPadding = values[0]
    elif op == 'TOPPADDING':
        new.topPadding = values[0]
    elif op == 'BOTTOMPADDING':
        new.bottomPadding = values[0]
    elif op == 'HREF':
        new.href = values[0]
    elif op == 'DESTINATION':
        new.destination = values[0] 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:40,代码来源:tables.py

示例13: test

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def test():
    """This function produces a pdf with examples. """

    #white on blue
    rl = RL_CorpLogo()
    rl.width = 129
    rl.height = 86
    D = Drawing(rl.width,rl.height)
    D.add(rl)
    D.__dict__['verbose'] = 1
    D.save(fnRoot='corplogo_whiteonblue',formats=['pdf','eps','jpg','gif'])


    #blue on white
    rl = RL_CorpLogoReversed()
    rl.width = 129
    rl.height = 86
    D = Drawing(rl.width,rl.height)
    D.add(rl)
    D.__dict__['verbose'] = 1
    D.save(fnRoot='corplogo_blueonwhite',formats=['pdf','eps','jpg','gif'])

    #gray on white
    rl = RL_CorpLogoReversed()
    rl.fillColor = Color(0.2, 0.2, 0.2)
    rl.width = 129
    rl.height = 86
    D = Drawing(rl.width,rl.height)
    D.add(rl)
    D.__dict__['verbose'] = 1
    D.save(fnRoot='corplogo_grayonwhite',formats=['pdf','eps','jpg','gif'])


    rl = RL_BusinessCard()
    rl.x=25
    rl.y=25
    rl.border=1
    D = Drawing(rl.width+50,rl.height+50)
    D.add(rl)
    D.__dict__['verbose'] = 1
    D.save(fnRoot='RL_BusinessCard',formats=['pdf']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:43,代码来源:corp.py

示例14: test_1

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def test_1(self):
        "Test color attribute conversion to CMYK"

        mapping = (
            ("red", force_cmyk(colors.red)),
            ("#ff0000", force_cmyk(colors.red)),
            ("#f00", force_cmyk(colors.red)),
            ("rgb(100%,0%,0%)", force_cmyk(colors.red)),
            ("rgb(255, 0, 0)", force_cmyk(colors.red)),
            ("rgb(0,255, 0)", force_cmyk(colors.Color(0, 1, 0))),
            ("rgb(0, 0, 255)", force_cmyk(colors.Color(0, 0, 1))),
        )
        ac = svglib.Svg2RlgAttributeConverter(color_converter=force_cmyk)
        failed = _testit(ac.convertColor, mapping)
        assert len(failed) == 0 
开发者ID:deeplook,项目名称:svglib,代码行数:17,代码来源:test_basic.py

示例15: test_fillopacity

# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import Color [as 别名]
def test_fillopacity(self):
        """
        The fill-opacity property set the alpha of the color.
        """
        drawing = svglib.svg2rlg(io.StringIO(textwrap.dedent(u'''\
            <?xml version="1.0"?>
            <svg version="1.1"
                 xmlns="http://www.w3.org/2000/svg"
                 width="660" height="480">
                <polygon id="triangle" points="0,-29.14 -25.23, 14.57 25.23, 14.57"
                         stroke="#0038b8" stroke-width="5.5" fill-opacity="0"/>
            </svg>
        ''')))
        assert drawing.contents[0].contents[0].fillColor == colors.Color(0, 0, 0, 0) 
开发者ID:deeplook,项目名称:svglib,代码行数:16,代码来源:test_basic.py


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