Python reportlab.lib.colors.CMYKColor() Examples
The following are 15
code examples of reportlab.lib.colors.CMYKColor().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
reportlab.lib.colors
, or try the search function
.
Example #1
Source File: para.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: para.py From stdm with GNU General Public License v2.0 | 6 votes |
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)
Example #3
Source File: gen.py From cwg with GNU General Public License v3.0 | 6 votes |
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));
Example #4
Source File: letters.py From coursys with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: textobject.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: textobject.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #7
Source File: canvas.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: pdfdoc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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
Example #9
Source File: test_basic.py From svglib with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #10
Source File: textobject.py From stdm with GNU General Public License v2.0 | 5 votes |
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)
Example #11
Source File: textobject.py From stdm with GNU General Public License v2.0 | 5 votes |
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)
Example #12
Source File: canvas.py From stdm with GNU General Public License v2.0 | 5 votes |
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)
Example #13
Source File: pdfdoc.py From stdm with GNU General Public License v2.0 | 5 votes |
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
Example #14
Source File: fontcrunch.py From fontcrunch with Apache License 2.0 | 5 votes |
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()
Example #15
Source File: pdfgen.py From uniconvertor with GNU Affero General Public License v3.0 | 5 votes |
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