本文整理汇总了Python中reportlab.lib.colors.CMYKColor方法的典型用法代码示例。如果您正苦于以下问题:Python colors.CMYKColor方法的具体用法?Python colors.CMYKColor怎么用?Python colors.CMYKColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.lib.colors
的用法示例。
在下文中一共展示了colors.CMYKColor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readColor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [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)
示例2: draw_guide
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def draw_guide(canvas, x, y, guide):
canvas.setDash(1, 2);
canvas.setStrokeColor(CMYKColor(0, 0, 0, 0.2));
if guide == Guide.STAR or guide == Guide.CROSS_STAR:
x1 = x;
y1 = y;
x2 = x1 + SQUARE_SIZE;
y2 = y - SQUARE_SIZE;
canvas.line(x1, y1, x2, y2);
canvas.line(x2, y1, x1, y2);
if guide == Guide.CROSS or guide == Guide.CROSS_STAR:
x1 = x;
y1 = y - SQUARE_SIZE/2;
x2 = x1 + SQUARE_SIZE;
y2 = y1;
canvas.line(x1, y1, x2, y2);
x1 = x + SQUARE_SIZE/2;
y1 = y;
x2 = x1;
y2 = y1 - SQUARE_SIZE;
canvas.line(x1, y1, x2, y2);
canvas.setDash();
canvas.setStrokeColor(CMYKColor(0, 0, 0, 1));
示例3: _media_setup
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def _media_setup(self):
"Get all of the media needed for the letterhead"
# fonts and logo
ttfFile = os.path.join(media_path, 'BemboMTPro-Regular.ttf')
pdfmetrics.registerFont(TTFont("BemboMTPro", ttfFile))
ttfFile = os.path.join(media_path, 'BemboMTPro-Bold.ttf')
pdfmetrics.registerFont(TTFont("BemboMTPro-Bold", ttfFile))
ttfFile = os.path.join(media_path, 'DINPro-Regular.ttf')
pdfmetrics.registerFont(TTFont("DINPro", ttfFile))
ttfFile = os.path.join(media_path, 'DINPro-Bold.ttf')
pdfmetrics.registerFont(TTFont("DINPro-Bold", ttfFile))
# graphic standards colours
self.sfu_red = CMYKColor(0, 1, 0.79, 0.2)
self.sfu_grey = CMYKColor(0, 0, 0.15, 0.82)
self.sfu_blue = CMYKColor(1, 0.68, 0, 0.12)
# translate digits to old-style numerals (in their Bembo character positions)
self.digit_trans = {}
for d in range(10):
self.digit_trans[48+d] = chr(0xF643 + d)
self.sc_trans_bembo = {}
# translate letters to smallcaps characters (in their [strange] Bembo character positions)
for d in range(26):
if d<3: # A-C
offset = d
elif d<4: # D
offset = d+2
elif d<21: # E-U
offset = d+3
else: # V-Z
offset = d+4
self.sc_trans_bembo[65+d] = chr(0xE004 + offset)
self.sc_trans_bembo[97+d] = chr(0xE004 + offset)
示例4: setFillColor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [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)
示例5: setStrokeColor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def setStrokeColor(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._strokeColorObj = 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._strokeColorObj = aColor
self._code.append('%s RG' % fp_str(rgb) )
elif isinstance(aColor,(tuple,list)):
l = len(aColor)
if l==3:
self._strokeColorObj = aColor
self._code.append('%s RG' % fp_str(aColor) )
elif l==4:
self._strokeColorObj = aColor
self._code.append('%s K' % fp_str(aColor))
else:
raise ValueError('Unknown color %r' % aColor)
elif isStr(aColor):
self.setStrokeColor(toColor(aColor))
else:
raise ValueError('Unknown color %r' % aColor)
if alpha is not None:
self.setStrokeAlpha(alpha)
elif getattr(aColor, 'alpha', None) is not None:
self.setStrokeAlpha(aColor.alpha)
示例6: _normalizeColor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [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)
示例7: __init__
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def __init__(self, cmyk):
from reportlab.lib.colors import CMYKColor
if not isinstance(cmyk,CMYKColor):
raise ValueError('%s needs a CMYKColor argument' % self.__class__.__name__)
elif not cmyk.spotName:
raise ValueError('%s needs a CMYKColor argument with a spotName' % self.__class__.__name__)
self.cmyk = cmyk
示例8: force_cmyk
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def force_cmyk(rgb):
c, m, y, k = colors.rgb2cmyk(rgb.red, rgb.green, rgb.blue)
return colors.CMYKColor(c, m, y, k, alpha=rgb.alpha)
示例9: setFillColor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [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 isinstance(aColor,basestring):
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)
示例10: setStrokeColor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def setStrokeColor(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._strokeColorObj = 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._strokeColorObj = aColor
self._code.append('%s RG' % fp_str(rgb) )
elif isinstance(aColor,(tuple,list)):
l = len(aColor)
if l==3:
self._strokeColorObj = 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 isinstance(aColor,basestring):
self.setStrokeColor(toColor(aColor))
else:
raise ValueError('Unknown color %r' % aColor)
if alpha is not None:
self.setStrokeAlpha(alpha)
elif getattr(aColor, 'alpha', None) is not None:
self.setStrokeAlpha(aColor.alpha)
示例11: _normalizeColor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [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, basestring):
return _normalizeColor(toColor(aColor))
raise ValueError("Unknown color %r" % aColor)
示例12: plot_glyph
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def plot_glyph(font, name, canvas, orig):
if canvas is None:
return
from reportlab.lib.colors import CMYKColor
gs = font.getGlyphSet()
glyph = gs[name]
pen = PDFPen(gs, canvas.beginPath())
glyph.draw(pen)
if orig:
color = CMYKColor(0, 1, 1, 0, alpha=.5)
else:
color = CMYKColor(0, 0, 0, 1, alpha=.5)
x0 = 100
y0 = 100
scale = 0.25
canvas.saveState()
canvas.setFillColor(color)
canvas.translate(x0, y0)
canvas.scale(scale, scale)
canvas.drawPath(pen.path, stroke=False, fill=True)
canvas.restoreState()
if not orig:
canvas.showPage()
示例13: get_pdfcolor
# 需要导入模块: from reportlab.lib import colors [as 别名]
# 或者: from reportlab.lib.colors import CMYKColor [as 别名]
def get_pdfcolor(self, color):
alpha = color[2]
if self.use_spot and color[0] == uc2const.COLOR_SPOT:
c, m, y, k = self.cms.get_cmyk_color(color)[1]
spotname = color[3]
if spotname == uc2const.COLOR_REG:
spotname = 'All'
pdfcolor = CMYKColorSep(c, m, y, k, spotName=spotname, alpha=alpha)
elif self.colorspace == uc2const.COLOR_CMYK:
c, m, y, k = self.cms.get_cmyk_color(color)[1]
pdfcolor = CMYKColor(c, m, y, k, alpha=alpha)
elif self.colorspace == uc2const.COLOR_RGB:
r, g, b = self.cms.get_rgb_color(color)[1]
return Color(r, g, b, alpha)
elif self.colorspace == uc2const.COLOR_GRAY:
gray = self.cms.get_grayscale_color(color)
k = 1.0 - gray[1][0]
c = m = y = 0.0
pdfcolor = CMYKColor(c, m, y, k, alpha=alpha)
else:
if color[0] == uc2const.COLOR_RGB:
r, g, b = color[1]
return Color(r, g, b, alpha)
elif color[0] == uc2const.COLOR_GRAY:
k = 1.0 - color[1][0]
c = m = y = 0.0
pdfcolor = CMYKColor(c, m, y, k, alpha=alpha)
else:
c, m, y, k = self.cms.get_cmyk_color(color)[1]
pdfcolor = CMYKColor(c, m, y, k, alpha=alpha)
self.set_rgb_values(color, pdfcolor)
return pdfcolor