author | rptlab |
Tue, 30 Apr 2013 14:28:14 +0100 | |
branch | py33 |
changeset 3723 | 99aa837b6703 |
parent 3721 | 0c93dd8ff567 |
child 3781 | df8b57380768 |
permissions | -rw-r--r-- |
3617 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2012 |
494 | 2 |
#see license.txt for license details |
2332 | 3 |
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/lib/colors.py |
4 |
__version__=''' $Id$ ''' |
|
3029 | 5 |
__doc__='''Defines standard colour-handling classes and colour names. |
37 | 6 |
|
3029 | 7 |
We define standard classes to hold colours in two models: RGB and CMYK. |
8 |
These can be constructed from several popular formats. We also include |
|
9 |
||
10 |
- pre-built colour objects for the HTML standard colours |
|
11 |
||
12 |
- pre-built colours used in ReportLab's branding |
|
13 |
||
14 |
- various conversion and construction functions |
|
3496
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
15 |
|
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
16 |
These tests are here because doctest cannot find them otherwise. |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
17 |
>>> toColor('rgb(128,0,0)')==toColor('rgb(50%,0%,0%)') |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
18 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
19 |
>>> toColor('rgb(50%,0%,0%)')!=Color(0.5,0,0,1) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
20 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
21 |
>>> toColor('hsl(0,100%,50%)')==toColor('rgb(255,0,0)') |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
22 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
23 |
>>> toColor('hsl(-120,100%,50%)')==toColor('rgb(0,0,255)') |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
24 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
25 |
>>> toColor('hsl(120,100%,50%)')==toColor('rgb(0,255,0)') |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
26 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
27 |
>>> toColor('rgba( 255,0,0,0.5)')==Color(1,0,0,0.5) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
28 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
29 |
>>> toColor('cmyk(1,0,0,0 )')==CMYKColor(1,0,0,0) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
30 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
31 |
>>> toColor('pcmyk( 100 , 0 , 0 , 0 )')==PCMYKColor(100,0,0,0) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
32 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
33 |
>>> toColor('cmyka(1,0,0,0,0.5)')==CMYKColor(1,0,0,0,alpha=0.5) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
34 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
35 |
>>> toColor('pcmyka(100,0,0,0,0.5)')==PCMYKColor(100,0,0,0,alpha=0.5) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
36 |
True |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
37 |
>>> toColor('pcmyka(100,0,0,0)') |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
38 |
Traceback (most recent call last): |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
39 |
.... |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
40 |
ValueError: css color 'pcmyka(100,0,0,0)' has wrong number of components |
3029 | 41 |
''' |
3496
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
42 |
import math, re |
1061
11c13c203d02
Made import from utils absolute to avoid bombing Andy's yaml stuff
rgbecker
parents:
1041
diff
changeset
|
43 |
from reportlab.lib.utils import fp_str |
3721 | 44 |
import collections |
37 | 45 |
|
46 |
class Color: |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
47 |
"""This class is used to represent color. Components red, green, blue |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
48 |
are in the range 0 (dark) to 1 (full intensity).""" |
37 | 49 |
|
3279 | 50 |
def __init__(self, red=0, green=0, blue=0, alpha=1): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
51 |
"Initialize with red, green, blue in range [0-1]." |
3279 | 52 |
self.red = red |
53 |
self.green = green |
|
54 |
self.blue = blue |
|
55 |
self.alpha = alpha |
|
563 | 56 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
57 |
def __repr__(self): |
3279 | 58 |
return "Color(%s)" % fp_str(*(self.red, self.green, self.blue,self.alpha)).replace(' ',',') |
563 | 59 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
60 |
def __hash__(self): |
3279 | 61 |
return hash((self.red, self.green, self.blue, self.alpha)) |
37 | 62 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
63 |
def __cmp__(self,other): |
3300
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
64 |
'''simple comparison by component; cmyk != color ever |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
65 |
>>> cmp(Color(0,0,0),None) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
66 |
-1 |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
67 |
>>> cmp(Color(0,0,0),black) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
68 |
0 |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
69 |
>>> cmp(Color(0,0,0),CMYKColor(0,0,0,1)),Color(0,0,0).rgba()==CMYKColor(0,0,0,1).rgba() |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
70 |
(-1, True) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
71 |
''' |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
72 |
if isinstance(other,CMYKColor) or not isinstance(other,Color): return -1 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
73 |
try: |
3300
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
74 |
return cmp((self.red, self.green, self.blue, self.alpha), |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
75 |
(other.red, other.green, other.blue, other.alpha)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
76 |
except: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
77 |
return -1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
78 |
return 0 |
66 | 79 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
80 |
def rgb(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
81 |
"Returns a three-tuple of components" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
82 |
return (self.red, self.green, self.blue) |
1663 | 83 |
|
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
84 |
def rgba(self): |
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
85 |
"Returns a four-tuple of components" |
3279 | 86 |
return (self.red, self.green, self.blue, self.alpha) |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
87 |
|
2001 | 88 |
def bitmap_rgb(self): |
3721 | 89 |
return tuple([int(x*255)&255 for x in self.rgb()]) |
2001 | 90 |
|
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
91 |
def bitmap_rgba(self): |
3721 | 92 |
return tuple([int(x*255)&255 for x in self.rgba()]) |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
93 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
94 |
def hexval(self): |
2001 | 95 |
return '0x%02x%02x%02x' % self.bitmap_rgb() |
1683 | 96 |
|
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
97 |
def hexvala(self): |
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
98 |
return '0x%02x%02x%02x%02x' % self.bitmap_rgba() |
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
99 |
|
3473
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
100 |
def int_rgb(self): |
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
101 |
v = self.bitmap_rgb() |
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
102 |
return v[0]<<16|v[1]<<8|v[2] |
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
103 |
|
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
104 |
def int_rgba(self): |
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
105 |
v = self.bitmap_rgba() |
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
106 |
return int((v[0]<<24|v[1]<<16|v[2]<<8|v[3])&0xffffff) |
c56be984bc24
colros.py: add methods int_rgb & int_rgba to Color
rgbecker
parents:
3446
diff
changeset
|
107 |
|
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
108 |
_cKwds='red green blue alpha'.split() |
3225
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
109 |
def cKwds(self): |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
110 |
for k in self._cKwds: |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
111 |
yield k,getattr(self,k) |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
112 |
cKwds=property(cKwds) |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
113 |
|
3155 | 114 |
def clone(self,**kwds): |
115 |
'''copy then change values in kwds''' |
|
3225
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
116 |
D = dict([kv for kv in self.cKwds]) |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
117 |
D.update(kwds) |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
118 |
return self.__class__(**D) |
3155 | 119 |
|
3446 | 120 |
def _lookupName(self,D={}): |
121 |
if not D: |
|
3721 | 122 |
for n,v in getAllNamedColors().items(): |
3446 | 123 |
if not isinstance(v,CMYKColor): |
124 |
t = v.red,v.green,v.blue |
|
125 |
if t in D: |
|
126 |
n = n+'/'+D[t] |
|
127 |
D[t] = n |
|
128 |
t = self.red,self.green,self.blue |
|
129 |
return t in D and D[t] or None |
|
130 |
||
3633 | 131 |
@property |
132 |
def normalizedAlpha(self): |
|
133 |
return self.alpha |
|
134 |
||
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
135 |
|
695 | 136 |
class CMYKColor(Color): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
137 |
"""This represents colors using the CMYK (cyan, magenta, yellow, black) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
138 |
model commonly used in professional printing. This is implemented |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
139 |
as a derived class so that renderers which only know about RGB "see it" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
140 |
as an RGB color through its 'red','green' and 'blue' attributes, according |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
141 |
to an approximate function. |
695 | 142 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
143 |
The RGB approximation is worked out when the object in constructed, so |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
144 |
the color attributes should not be changed afterwards. |
695 | 145 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
146 |
Extra attributes may be attached to the class to support specific ink models, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
147 |
and renderers may look for these.""" |
695 | 148 |
|
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
149 |
_scale = 1.0 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
150 |
def __init__(self, cyan=0, magenta=0, yellow=0, black=0, |
3279 | 151 |
spotName=None, density=1, knockout=None, alpha=1): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
152 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
153 |
Initialize with four colors in range [0-1]. the optional |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
154 |
spotName, density & knockout may be of use to specific renderers. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
155 |
spotName is intended for use as an identifier to the renderer not client programs. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
156 |
density is used to modify the overall amount of ink. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
157 |
knockout is a renderer dependent option that determines whether the applied colour |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
158 |
knocksout (removes) existing colour; None means use the global default. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
159 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
160 |
self.cyan = cyan |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
161 |
self.magenta = magenta |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
162 |
self.yellow = yellow |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
163 |
self.black = black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
164 |
self.spotName = spotName |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
165 |
self.density = max(min(density,1),0) # force into right range |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
166 |
self.knockout = knockout |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
167 |
self.alpha = alpha |
695 | 168 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
169 |
# now work out the RGB approximation. override |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
170 |
self.red, self.green, self.blue = cmyk2rgb( (cyan, magenta, yellow, black) ) |
695 | 171 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
172 |
if density<1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
173 |
#density adjustment of rgb approximants, effectively mix with white |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
174 |
r, g, b = self.red, self.green, self.blue |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
175 |
r = density*(r-1)+1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
176 |
g = density*(g-1)+1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
177 |
b = density*(b-1)+1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
178 |
self.red, self.green, self.blue = (r,g,b) |
1041 | 179 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
180 |
def __repr__(self): |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
181 |
return "%s(%s%s%s%s%s)" % (self.__class__.__name__, |
3198
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
182 |
fp_str(self.cyan, self.magenta, self.yellow, self.black).replace(' ',','), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
183 |
(self.spotName and (',spotName='+repr(self.spotName)) or ''), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
184 |
(self.density!=1 and (',density='+fp_str(self.density)) or ''), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
185 |
(self.knockout is not None and (',knockout=%d' % self.knockout) or ''), |
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
186 |
(self.alpha is not None and (',alpha=%s' % self.alpha) or ''), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
187 |
) |
695 | 188 |
|
3377 | 189 |
def fader(self, n, reverse=False): |
190 |
'''return n colors based on density fade |
|
191 |
*NB* note this dosen't reach density zero''' |
|
192 |
scale = self._scale |
|
193 |
dd = scale/float(n) |
|
3721 | 194 |
L = [self.clone(density=scale - i*dd) for i in range(n)] |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
195 |
if reverse: L.reverse() |
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
196 |
return L |
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
197 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
198 |
def __hash__(self): |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
199 |
return hash( (self.cyan, self.magenta, self.yellow, self.black, self.density, self.spotName, self.alpha) ) |
695 | 200 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
201 |
def __cmp__(self,other): |
3300
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
202 |
"""obvious way to compare colours |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
203 |
Comparing across the two color models is of limited use. |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
204 |
>>> cmp(CMYKColor(0,0,0,1),None) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
205 |
-1 |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
206 |
>>> cmp(CMYKColor(0,0,0,1),_CMYK_black) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
207 |
0 |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
208 |
>>> cmp(PCMYKColor(0,0,0,100),_CMYK_black) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
209 |
0 |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
210 |
>>> cmp(CMYKColor(0,0,0,1),Color(0,0,1)),Color(0,0,0).rgba()==CMYKColor(0,0,0,1).rgba() |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
211 |
(-1, True) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
212 |
""" |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
213 |
if not isinstance(other, CMYKColor): return -1 |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
214 |
try: |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
215 |
return cmp( |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
216 |
(self.cyan, self.magenta, self.yellow, self.black, self.density, self.alpha, self.spotName), |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
217 |
(other.cyan, other.magenta, other.yellow, other.black, other.density, other.alpha, other.spotName)) |
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
218 |
except: # or just return 'not equal' if not a color |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
219 |
return -1 |
3300
9906989730e9
colors.py: improve comparison funcs so they actually work
rgbecker
parents:
3297
diff
changeset
|
220 |
return 0 |
696 | 221 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
222 |
def cmyk(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
223 |
"Returns a tuple of four color components - syntactic sugar" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
224 |
return (self.cyan, self.magenta, self.yellow, self.black) |
695 | 225 |
|
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
226 |
def cmyka(self): |
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
227 |
"Returns a tuple of five color components - syntactic sugar" |
3279 | 228 |
return (self.cyan, self.magenta, self.yellow, self.black, self.alpha) |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
229 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
230 |
def _density_str(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
231 |
return fp_str(self.density) |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
232 |
_cKwds='cyan magenta yellow black density alpha spotName knockout'.split() |
3225
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
233 |
|
3446 | 234 |
def _lookupName(self,D={}): |
235 |
if not D: |
|
3721 | 236 |
for n,v in getAllNamedColors().items(): |
3446 | 237 |
if isinstance(v,CMYKColor): |
238 |
t = v.cyan,v.magenta,v.yellow,v.black |
|
239 |
if t in D: |
|
240 |
n = n+'/'+D[t] |
|
241 |
D[t] = n |
|
242 |
t = self.cyan,self.magenta,self.yellow,self.black |
|
243 |
return t in D and D[t] or None |
|
244 |
||
3633 | 245 |
@property |
246 |
def normalizedAlpha(self): |
|
247 |
return self.alpha*self._scale |
|
248 |
||
1041 | 249 |
class PCMYKColor(CMYKColor): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
250 |
'''100 based CMYKColor with density and a spotName; just like Rimas uses''' |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
251 |
_scale = 100. |
3292 | 252 |
def __init__(self,cyan,magenta,yellow,black,density=100,spotName=None,knockout=None,alpha=100): |
253 |
CMYKColor.__init__(self,cyan/100.,magenta/100.,yellow/100.,black/100.,spotName,density/100.,knockout=knockout,alpha=alpha/100.) |
|
1041 | 254 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
255 |
def __repr__(self): |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
256 |
return "%s(%s%s%s%s%s)" % (self.__class__.__name__, |
3198
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
257 |
fp_str(self.cyan*100, self.magenta*100, self.yellow*100, self.black*100).replace(' ',','), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
258 |
(self.spotName and (',spotName='+repr(self.spotName)) or ''), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
259 |
(self.density!=1 and (',density='+fp_str(self.density*100)) or ''), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
260 |
(self.knockout is not None and (',knockout=%d' % self.knockout) or ''), |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
261 |
(self.alpha is not None and (',alpha=%s' % (fp_str(self.alpha*100))) or ''), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
262 |
) |
1041 | 263 |
|
3225
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
264 |
def cKwds(self): |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
265 |
K=self._cKwds |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
266 |
S=K[:6] |
3225
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
267 |
for k in self._cKwds: |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
268 |
v=getattr(self,k) |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
269 |
if k in S: v*=100 |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
270 |
yield k,v |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
271 |
cKwds=property(cKwds) |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
272 |
|
3198
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
273 |
class CMYKColorSep(CMYKColor): |
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
274 |
'''special case color for making separating pdfs''' |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
275 |
_scale = 1. |
3198
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
276 |
def __init__(self, cyan=0, magenta=0, yellow=0, black=0, |
3279 | 277 |
spotName=None, density=1,alpha=1): |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
278 |
CMYKColor.__init__(self,cyan,magenta,yellow,black,spotName,density,knockout=None,alpha=alpha) |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
279 |
_cKwds='cyan magenta yellow black density alpha spotName'.split() |
3225
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
280 |
|
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
281 |
class PCMYKColorSep(PCMYKColor,CMYKColorSep): |
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
282 |
'''special case color for making separating pdfs''' |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
283 |
_scale = 100. |
3225
b034291925d9
colors.py: attempt to fix up the cloning of various color instances
rgbecker
parents:
3198
diff
changeset
|
284 |
def __init__(self, cyan=0, magenta=0, yellow=0, black=0, |
3292 | 285 |
spotName=None, density=100, alpha=100): |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
286 |
PCMYKColor.__init__(self,cyan,magenta,yellow,black,density,spotName,knockout=None,alpha=alpha) |
3375
baeae60700c7
colors.py: add CMYK color fading method & fix bug in scaling
rgbecker
parents:
3333
diff
changeset
|
287 |
_cKwds='cyan magenta yellow black density alpha spotName'.split() |
3198
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
288 |
|
3326 | 289 |
def cmyk2rgb(cmyk,density=1): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
290 |
"Convert from a CMYK color tuple to an RGB color tuple" |
3326 | 291 |
c,m,y,k = cmyk |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
292 |
# From the Adobe Postscript Ref. Manual 2nd ed. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
293 |
r = 1.0 - min(1.0, c + k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
294 |
g = 1.0 - min(1.0, m + k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
295 |
b = 1.0 - min(1.0, y + k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
296 |
return (r,g,b) |
51 | 297 |
|
430 | 298 |
def rgb2cmyk(r,g,b): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
299 |
'''one way to get cmyk from rgb''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
300 |
c = 1 - r |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
301 |
m = 1 - g |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
302 |
y = 1 - b |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
303 |
k = min(c,m,y) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
304 |
c = min(1,max(0,c-k)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
305 |
m = min(1,max(0,m-k)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
306 |
y = min(1,max(0,y-k)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
307 |
k = min(1,max(0,k)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
308 |
return (c,m,y,k) |
430 | 309 |
|
641 | 310 |
def color2bw(colorRGB): |
311 |
"Transform an RGB color to a black and white equivalent." |
|
312 |
||
313 |
col = colorRGB |
|
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
314 |
r, g, b, a = col.red, col.green, col.blue, col.alpha |
641 | 315 |
n = (r + g + b) / 3.0 |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
316 |
bwColorRGB = Color(n, n, n, a) |
641 | 317 |
return bwColorRGB |
318 |
||
3643 | 319 |
def HexColor(val, htmlOnly=False, hasAlpha=False): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
320 |
"""This function converts a hex string, or an actual integer number, |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
321 |
into the corresponding color. E.g., in "#AABBCC" or 0xAABBCC, |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
322 |
AA is the red, BB is the green, and CC is the blue (00-FF). |
37 | 323 |
|
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
324 |
An alpha value can also be given in the form #AABBCCDD or 0xAABBCCDD where |
3643 | 325 |
DD is the alpha value if hasAlpha is True. |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
326 |
|
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
327 |
For completeness I assume that #aabbcc or 0xaabbcc are hex numbers |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
328 |
otherwise a pure integer is converted as decimal rgb. If htmlOnly is true, |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
329 |
only the #aabbcc form is allowed. |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
330 |
|
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
331 |
>>> HexColor('#ffffff') |
3295 | 332 |
Color(1,1,1,1) |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
333 |
>>> HexColor('#FFFFFF') |
3295 | 334 |
Color(1,1,1,1) |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
335 |
>>> HexColor('0xffffff') |
3295 | 336 |
Color(1,1,1,1) |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
337 |
>>> HexColor('16777215') |
3295 | 338 |
Color(1,1,1,1) |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
339 |
|
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
340 |
An '0x' or '#' prefix is required for hex (as opposed to decimal): |
65
fb9c613d4c13
Allow 0x in HexColor, added stringToColor, fixed caching in getAllNamedColors
rgbecker
parents:
51
diff
changeset
|
341 |
|
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
342 |
>>> HexColor('ffffff') |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
343 |
Traceback (most recent call last): |
3295 | 344 |
ValueError: invalid literal for int() with base 10: 'ffffff' |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
345 |
|
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
346 |
>>> HexColor('#FFFFFF', htmlOnly=True) |
3295 | 347 |
Color(1,1,1,1) |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
348 |
>>> HexColor('0xffffff', htmlOnly=True) |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
349 |
Traceback (most recent call last): |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
350 |
ValueError: not a hex string |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
351 |
>>> HexColor('16777215', htmlOnly=True) |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
352 |
Traceback (most recent call last): |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
353 |
ValueError: not a hex string |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
354 |
|
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
355 |
""" #" for emacs |
37 | 356 |
|
3721 | 357 |
if isinstance(val,str): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
358 |
b = 10 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
359 |
if val[:1] == '#': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
360 |
val = val[1:] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
361 |
b = 16 |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
362 |
if len(val) == 8: |
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
363 |
alpha = True |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
364 |
else: |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
365 |
if htmlOnly: |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
366 |
raise ValueError('not a hex string') |
3198
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
367 |
if val[:2].lower() == '0x': |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
368 |
b = 16 |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
369 |
val = val[2:] |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
370 |
if len(val) == 8: |
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
371 |
alpha = True |
3198
683ca9eb6b18
reportlab: added in support for Overprint/Opacity & Separated colours (Opacity inspired by Simon King)
rgbecker
parents:
3176
diff
changeset
|
372 |
val = int(val,b) |
3643 | 373 |
if hasAlpha: |
374 |
return Color(((val>>24)&0xFF)/255.0,((val>>16)&0xFF)/255.0,((val>>8)&0xFF)/255.0,(val&0xFF)/255.0) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
375 |
return Color(((val>>16)&0xFF)/255.0,((val>>8)&0xFF)/255.0,(val&0xFF)/255.0) |
37 | 376 |
|
1154
c6314e34823b
Added method to color for interpolating colors - changed shadedRect in
johnprecedo
parents:
1120
diff
changeset
|
377 |
def linearlyInterpolatedColor(c0, c1, x0, x1, x): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
378 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
379 |
Linearly interpolates colors. Can handle RGB, CMYK and PCMYK |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
380 |
colors - give ValueError if colours aren't the same. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
381 |
Doesn't currently handle 'Spot Color Interpolation'. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
382 |
""" |
1154
c6314e34823b
Added method to color for interpolating colors - changed shadedRect in
johnprecedo
parents:
1120
diff
changeset
|
383 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
384 |
if c0.__class__ != c1.__class__: |
3410 | 385 |
raise ValueError("Color classes must be the same for interpolation!\nGot %r and %r'"%(c0,c1)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
386 |
if x1<x0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
387 |
x0,x1,c0,c1 = x1,x0,c1,c0 # normalized so x1>x0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
388 |
if x<x0-1e-8 or x>x1+1e-8: # fudge factor for numerical problems |
3721 | 389 |
raise ValueError("Can't interpolate: x=%f is not between %f and %f!" % (x,x0,x1)) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
390 |
if x<=x0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
391 |
return c0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
392 |
elif x>=x1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
393 |
return c1 |
1154
c6314e34823b
Added method to color for interpolating colors - changed shadedRect in
johnprecedo
parents:
1120
diff
changeset
|
394 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
395 |
cname = c0.__class__.__name__ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
396 |
dx = float(x1-x0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
397 |
x = x-x0 |
1154
c6314e34823b
Added method to color for interpolating colors - changed shadedRect in
johnprecedo
parents:
1120
diff
changeset
|
398 |
|
2047 | 399 |
if cname == 'Color': # RGB |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
400 |
r = c0.red+x*(c1.red - c0.red)/dx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
401 |
g = c0.green+x*(c1.green- c0.green)/dx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
402 |
b = c0.blue+x*(c1.blue - c0.blue)/dx |
3279 | 403 |
a = c0.alpha+x*(c1.alpha - c0.alpha)/dx |
404 |
return Color(r,g,b,alpha=a) |
|
2047 | 405 |
elif cname == 'CMYKColor': |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
406 |
if cmykDistance(c0,c1)<1e-8: |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
407 |
#colors same do density and preserve spotName if any |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
408 |
assert c0.spotName == c1.spotName, "Identical cmyk, but different spotName" |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
409 |
c = c0.cyan |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
410 |
m = c0.magenta |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
411 |
y = c0.yellow |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
412 |
k = c0.black |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
413 |
d = c0.density+x*(c1.density - c0.density)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
414 |
a = c0.alpha+x*(c1.alpha - c0.alpha)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
415 |
return CMYKColor(c,m,y,k, density=d, spotName=c0.spotName, alpha=a) |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
416 |
elif cmykDistance(c0,_CMYK_white)<1e-8: |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
417 |
#special c0 is white |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
418 |
c = c1.cyan |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
419 |
m = c1.magenta |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
420 |
y = c1.yellow |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
421 |
k = c1.black |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
422 |
d = x*c1.density/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
423 |
a = x*c1.alpha/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
424 |
return CMYKColor(c,m,y,k, density=d, spotName=c1.spotName, alpha=a) |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
425 |
elif cmykDistance(c1,_CMYK_white)<1e-8: |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
426 |
#special c1 is white |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
427 |
c = c0.cyan |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
428 |
m = c0.magenta |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
429 |
y = c0.yellow |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
430 |
k = c0.black |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
431 |
d = x*c0.density/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
432 |
d = c0.density*(1-x/dx) |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
433 |
a = c0.alpha*(1-x/dx) |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
434 |
return PCMYKColor(c,m,y,k, density=d, spotName=c0.spotName, alpha=a) |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
435 |
else: |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
436 |
c = c0.cyan+x*(c1.cyan - c0.cyan)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
437 |
m = c0.magenta+x*(c1.magenta - c0.magenta)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
438 |
y = c0.yellow+x*(c1.yellow - c0.yellow)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
439 |
k = c0.black+x*(c1.black - c0.black)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
440 |
d = c0.density+x*(c1.density - c0.density)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
441 |
a = c0.alpha+x*(c1.alpha - c0.alpha)/dx |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
442 |
return CMYKColor(c,m,y,k, density=d, alpha=a) |
2047 | 443 |
elif cname == 'PCMYKColor': |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
444 |
if cmykDistance(c0,c1)<1e-8: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
445 |
#colors same do density and preserve spotName if any |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
446 |
assert c0.spotName == c1.spotName, "Identical cmyk, but different spotName" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
447 |
c = c0.cyan |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
448 |
m = c0.magenta |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
449 |
y = c0.yellow |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
450 |
k = c0.black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
451 |
d = c0.density+x*(c1.density - c0.density)/dx |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
452 |
a = c0.alpha+x*(c1.alpha - c0.alpha)/dx |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
453 |
return PCMYKColor(c*100,m*100,y*100,k*100, density=d*100, |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
454 |
spotName=c0.spotName, alpha=100*a) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
455 |
elif cmykDistance(c0,_CMYK_white)<1e-8: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
456 |
#special c0 is white |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
457 |
c = c1.cyan |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
458 |
m = c1.magenta |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
459 |
y = c1.yellow |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
460 |
k = c1.black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
461 |
d = x*c1.density/dx |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
462 |
a = x*c1.alpha/dx |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
463 |
return PCMYKColor(c*100,m*100,y*100,k*100, density=d*100, |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
464 |
spotName=c1.spotName, alpha=a*100) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
465 |
elif cmykDistance(c1,_CMYK_white)<1e-8: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
466 |
#special c1 is white |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
467 |
c = c0.cyan |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
468 |
m = c0.magenta |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
469 |
y = c0.yellow |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
470 |
k = c0.black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
471 |
d = x*c0.density/dx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
472 |
d = c0.density*(1-x/dx) |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
473 |
a = c0.alpha*(1-x/dx) |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
474 |
return PCMYKColor(c*100,m*100,y*100,k*100, density=d*100, |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
475 |
spotName=c0.spotName, alpha=a*100) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
476 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
477 |
c = c0.cyan+x*(c1.cyan - c0.cyan)/dx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
478 |
m = c0.magenta+x*(c1.magenta - c0.magenta)/dx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
479 |
y = c0.yellow+x*(c1.yellow - c0.yellow)/dx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
480 |
k = c0.black+x*(c1.black - c0.black)/dx |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
481 |
d = c0.density+x*(c1.density - c0.density)/dx |
3284 | 482 |
a = c0.alpha+x*(c1.alpha - c0.alpha)/dx |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
483 |
return PCMYKColor(c*100,m*100,y*100,k*100, density=d*100, alpha=a*100) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
484 |
else: |
3721 | 485 |
raise ValueError("Can't interpolate: Unknown color class %s!" % cname) |
1154
c6314e34823b
Added method to color for interpolating colors - changed shadedRect in
johnprecedo
parents:
1120
diff
changeset
|
486 |
|
3254
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
487 |
def obj_R_G_B(c): |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
488 |
'''attempt to convert an object to (red,green,blue)''' |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
489 |
if isinstance(c,Color): |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
490 |
return c.red,c.green,c.blue |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
491 |
elif isinstance(c,(tuple,list)): |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
492 |
if len(c)==3: |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
493 |
return tuple(c) |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
494 |
elif len(c)==4: |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
495 |
return toColor(c).rgb() |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
496 |
else: |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
497 |
raise ValueError('obj_R_G_B(%r) bad argument' % (c)) |
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
498 |
|
37 | 499 |
# special case -- indicates no drawing should be done |
696 | 500 |
# this is a hangover from PIDDLE - suggest we ditch it since it is not used anywhere |
3277
8fe70e71c2db
reportlab: add alpha property to colours, patch contributed by Keven D Smith <Kevin.Smith@sixquickrun.com>
rgbecker
parents:
3254
diff
changeset
|
501 |
transparent = Color(0,0,0,alpha=0) |
563 | 502 |
|
1308 | 503 |
_CMYK_white=CMYKColor(0,0,0,0) |
1659 | 504 |
_PCMYK_white=PCMYKColor(0,0,0,0) |
505 |
_CMYK_black=CMYKColor(0,0,0,1) |
|
506 |
_PCMYK_black=PCMYKColor(0,0,0,100) |
|
1307 | 507 |
|
1683 | 508 |
# Special colors |
2154 | 509 |
ReportLabBlueOLD = HexColor(0x4e5688) |
510 |
ReportLabBlue = HexColor(0x00337f) |
|
511 |
ReportLabBluePCMYK = PCMYKColor(100,65,0,30,spotName='Pantone 288U') |
|
1429 | 512 |
ReportLabLightBlue = HexColor(0xb7b9d3) |
1844 | 513 |
ReportLabFidBlue=HexColor(0x3366cc) |
514 |
ReportLabFidRed=HexColor(0xcc0033) |
|
1991 | 515 |
ReportLabGreen = HexColor(0x336600) |
516 |
ReportLabLightGreen = HexColor(0x339933) |
|
894 | 517 |
|
37 | 518 |
# color constants -- mostly from HTML standard |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
519 |
aliceblue = HexColor(0xF0F8FF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
520 |
antiquewhite = HexColor(0xFAEBD7) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
521 |
aqua = HexColor(0x00FFFF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
522 |
aquamarine = HexColor(0x7FFFD4) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
523 |
azure = HexColor(0xF0FFFF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
524 |
beige = HexColor(0xF5F5DC) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
525 |
bisque = HexColor(0xFFE4C4) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
526 |
black = HexColor(0x000000) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
527 |
blanchedalmond = HexColor(0xFFEBCD) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
528 |
blue = HexColor(0x0000FF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
529 |
blueviolet = HexColor(0x8A2BE2) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
530 |
brown = HexColor(0xA52A2A) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
531 |
burlywood = HexColor(0xDEB887) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
532 |
cadetblue = HexColor(0x5F9EA0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
533 |
chartreuse = HexColor(0x7FFF00) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
534 |
chocolate = HexColor(0xD2691E) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
535 |
coral = HexColor(0xFF7F50) |
1727 | 536 |
cornflowerblue = cornflower = HexColor(0x6495ED) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
537 |
cornsilk = HexColor(0xFFF8DC) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
538 |
crimson = HexColor(0xDC143C) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
539 |
cyan = HexColor(0x00FFFF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
540 |
darkblue = HexColor(0x00008B) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
541 |
darkcyan = HexColor(0x008B8B) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
542 |
darkgoldenrod = HexColor(0xB8860B) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
543 |
darkgray = HexColor(0xA9A9A9) |
3097
9c90e1e4baaa
colors.py: normalize spelling of grey/gray colours, suggested by Paul Barass
rgbecker
parents:
3029
diff
changeset
|
544 |
darkgrey = darkgray |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
545 |
darkgreen = HexColor(0x006400) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
546 |
darkkhaki = HexColor(0xBDB76B) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
547 |
darkmagenta = HexColor(0x8B008B) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
548 |
darkolivegreen = HexColor(0x556B2F) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
549 |
darkorange = HexColor(0xFF8C00) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
550 |
darkorchid = HexColor(0x9932CC) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
551 |
darkred = HexColor(0x8B0000) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
552 |
darksalmon = HexColor(0xE9967A) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
553 |
darkseagreen = HexColor(0x8FBC8B) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
554 |
darkslateblue = HexColor(0x483D8B) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
555 |
darkslategray = HexColor(0x2F4F4F) |
3097
9c90e1e4baaa
colors.py: normalize spelling of grey/gray colours, suggested by Paul Barass
rgbecker
parents:
3029
diff
changeset
|
556 |
darkslategrey = darkslategray |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
557 |
darkturquoise = HexColor(0x00CED1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
558 |
darkviolet = HexColor(0x9400D3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
559 |
deeppink = HexColor(0xFF1493) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
560 |
deepskyblue = HexColor(0x00BFFF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
561 |
dimgray = HexColor(0x696969) |
3097
9c90e1e4baaa
colors.py: normalize spelling of grey/gray colours, suggested by Paul Barass
rgbecker
parents:
3029
diff
changeset
|
562 |
dimgrey = dimgray |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
563 |
dodgerblue = HexColor(0x1E90FF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
564 |
firebrick = HexColor(0xB22222) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
565 |
floralwhite = HexColor(0xFFFAF0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
566 |
forestgreen = HexColor(0x228B22) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
567 |
fuchsia = HexColor(0xFF00FF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
568 |
gainsboro = HexColor(0xDCDCDC) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
569 |
ghostwhite = HexColor(0xF8F8FF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
570 |
gold = HexColor(0xFFD700) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
571 |
goldenrod = HexColor(0xDAA520) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
572 |
gray = HexColor(0x808080) |
37 | 573 |
grey = gray |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
574 |
green = HexColor(0x008000) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
575 |
greenyellow = HexColor(0xADFF2F) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
576 |
honeydew = HexColor(0xF0FFF0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
577 |
hotpink = HexColor(0xFF69B4) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
578 |
indianred = HexColor(0xCD5C5C) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
579 |
indigo = HexColor(0x4B0082) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
580 |
ivory = HexColor(0xFFFFF0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
581 |
khaki = HexColor(0xF0E68C) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
582 |
lavender = HexColor(0xE6E6FA) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
583 |
lavenderblush = HexColor(0xFFF0F5) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
584 |
lawngreen = HexColor(0x7CFC00) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
585 |
lemonchiffon = HexColor(0xFFFACD) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
586 |
lightblue = HexColor(0xADD8E6) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
587 |
lightcoral = HexColor(0xF08080) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
588 |
lightcyan = HexColor(0xE0FFFF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
589 |
lightgoldenrodyellow = HexColor(0xFAFAD2) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
590 |
lightgreen = HexColor(0x90EE90) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
591 |
lightgrey = HexColor(0xD3D3D3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
592 |
lightpink = HexColor(0xFFB6C1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
593 |
lightsalmon = HexColor(0xFFA07A) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
594 |
lightseagreen = HexColor(0x20B2AA) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
595 |
lightskyblue = HexColor(0x87CEFA) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
596 |
lightslategray = HexColor(0x778899) |
3097
9c90e1e4baaa
colors.py: normalize spelling of grey/gray colours, suggested by Paul Barass
rgbecker
parents:
3029
diff
changeset
|
597 |
lightslategrey = lightslategray |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
598 |
lightsteelblue = HexColor(0xB0C4DE) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
599 |
lightyellow = HexColor(0xFFFFE0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
600 |
lime = HexColor(0x00FF00) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
601 |
limegreen = HexColor(0x32CD32) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
602 |
linen = HexColor(0xFAF0E6) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
603 |
magenta = HexColor(0xFF00FF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
604 |
maroon = HexColor(0x800000) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
605 |
mediumaquamarine = HexColor(0x66CDAA) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
606 |
mediumblue = HexColor(0x0000CD) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
607 |
mediumorchid = HexColor(0xBA55D3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
608 |
mediumpurple = HexColor(0x9370DB) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
609 |
mediumseagreen = HexColor(0x3CB371) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
610 |
mediumslateblue = HexColor(0x7B68EE) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
611 |
mediumspringgreen = HexColor(0x00FA9A) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
612 |
mediumturquoise = HexColor(0x48D1CC) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
613 |
mediumvioletred = HexColor(0xC71585) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
614 |
midnightblue = HexColor(0x191970) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
615 |
mintcream = HexColor(0xF5FFFA) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
616 |
mistyrose = HexColor(0xFFE4E1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
617 |
moccasin = HexColor(0xFFE4B5) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
618 |
navajowhite = HexColor(0xFFDEAD) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
619 |
navy = HexColor(0x000080) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
620 |
oldlace = HexColor(0xFDF5E6) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
621 |
olive = HexColor(0x808000) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
622 |
olivedrab = HexColor(0x6B8E23) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
623 |
orange = HexColor(0xFFA500) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
624 |
orangered = HexColor(0xFF4500) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
625 |
orchid = HexColor(0xDA70D6) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
626 |
palegoldenrod = HexColor(0xEEE8AA) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
627 |
palegreen = HexColor(0x98FB98) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
628 |
paleturquoise = HexColor(0xAFEEEE) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
629 |
palevioletred = HexColor(0xDB7093) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
630 |
papayawhip = HexColor(0xFFEFD5) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
631 |
peachpuff = HexColor(0xFFDAB9) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
632 |
peru = HexColor(0xCD853F) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
633 |
pink = HexColor(0xFFC0CB) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
634 |
plum = HexColor(0xDDA0DD) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
635 |
powderblue = HexColor(0xB0E0E6) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
636 |
purple = HexColor(0x800080) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
637 |
red = HexColor(0xFF0000) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
638 |
rosybrown = HexColor(0xBC8F8F) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
639 |
royalblue = HexColor(0x4169E1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
640 |
saddlebrown = HexColor(0x8B4513) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
641 |
salmon = HexColor(0xFA8072) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
642 |
sandybrown = HexColor(0xF4A460) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
643 |
seagreen = HexColor(0x2E8B57) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
644 |
seashell = HexColor(0xFFF5EE) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
645 |
sienna = HexColor(0xA0522D) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
646 |
silver = HexColor(0xC0C0C0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
647 |
skyblue = HexColor(0x87CEEB) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
648 |
slateblue = HexColor(0x6A5ACD) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
649 |
slategray = HexColor(0x708090) |
3097
9c90e1e4baaa
colors.py: normalize spelling of grey/gray colours, suggested by Paul Barass
rgbecker
parents:
3029
diff
changeset
|
650 |
slategrey = slategray |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
651 |
snow = HexColor(0xFFFAFA) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
652 |
springgreen = HexColor(0x00FF7F) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
653 |
steelblue = HexColor(0x4682B4) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
654 |
tan = HexColor(0xD2B48C) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
655 |
teal = HexColor(0x008080) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
656 |
thistle = HexColor(0xD8BFD8) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
657 |
tomato = HexColor(0xFF6347) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
658 |
turquoise = HexColor(0x40E0D0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
659 |
violet = HexColor(0xEE82EE) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
660 |
wheat = HexColor(0xF5DEB3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
661 |
white = HexColor(0xFFFFFF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
662 |
whitesmoke = HexColor(0xF5F5F5) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
663 |
yellow = HexColor(0xFFFF00) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
664 |
yellowgreen = HexColor(0x9ACD32) |
1654 | 665 |
fidblue=HexColor(0x3366cc) |
2490 | 666 |
fidred=HexColor(0xcc0033) |
2402
da8c6a14c84f
minor changes for pdf canvas compatibility and tests
rgbecker
parents:
2392
diff
changeset
|
667 |
fidlightblue=HexColor("#d6e0f5") |
37 | 668 |
|
66 | 669 |
ColorType=type(black) |
37 | 670 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
671 |
################################################################ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
672 |
# |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
673 |
# Helper functions for dealing with colors. These tell you |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
674 |
# which are predefined, so you can print color charts; |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
675 |
# and can give the nearest match to an arbitrary color object |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
676 |
# |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
677 |
################################################################# |
563 | 678 |
|
37 | 679 |
def colorDistance(col1, col2): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
680 |
"""Returns a number between 0 and root(3) stating how similar |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
681 |
two colours are - distance in r,g,b, space. Only used to find |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
682 |
names for things.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
683 |
return math.sqrt( |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
684 |
(col1.red - col2.red)**2 + |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
685 |
(col1.green - col2.green)**2 + |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
686 |
(col1.blue - col2.blue)**2 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
687 |
) |
37 | 688 |
|
1306 | 689 |
def cmykDistance(col1, col2): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
690 |
"""Returns a number between 0 and root(4) stating how similar |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
691 |
two colours are - distance in r,g,b, space. Only used to find |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
692 |
names for things.""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
693 |
return math.sqrt( |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
694 |
(col1.cyan - col2.cyan)**2 + |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
695 |
(col1.magenta - col2.magenta)**2 + |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
696 |
(col1.yellow - col2.yellow)**2 + |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
697 |
(col1.black - col2.black)**2 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
698 |
) |
1306 | 699 |
|
67 | 700 |
_namedColors = None |
37 | 701 |
|
702 |
def getAllNamedColors(): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
703 |
#returns a dictionary of all the named ones in the module |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
704 |
# uses a singleton for efficiency |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
705 |
global _namedColors |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
706 |
if _namedColors is not None: return _namedColors |
3721 | 707 |
from . import colors |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
708 |
_namedColors = {} |
3723
99aa837b6703
second stage of port to Python 3.3; working hello world
rptlab
parents:
3721
diff
changeset
|
709 |
for name, value in colors.__dict__.items(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
710 |
if isinstance(value, Color): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
711 |
_namedColors[name] = value |
65
fb9c613d4c13
Allow 0x in HexColor, added stringToColor, fixed caching in getAllNamedColors
rgbecker
parents:
51
diff
changeset
|
712 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
713 |
return _namedColors |
37 | 714 |
|
461 | 715 |
def describe(aColor,mode=0): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
716 |
'''finds nearest colour match to aColor. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
717 |
mode=0 print a string desription |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
718 |
mode=1 return a string description |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
719 |
mode=2 return (distance, colorName) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
720 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
721 |
namedColors = getAllNamedColors() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
722 |
closest = (10, None, None) #big number, name, color |
3723
99aa837b6703
second stage of port to Python 3.3; working hello world
rptlab
parents:
3721
diff
changeset
|
723 |
for name, color in namedColors.items(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
724 |
distance = colorDistance(aColor, color) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
725 |
if distance < closest[0]: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
726 |
closest = (distance, name, color) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
727 |
if mode<=1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
728 |
s = 'best match is %s, distance %0.4f' % (closest[1], closest[0]) |
3721 | 729 |
if mode==0: print(s) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
730 |
else: return s |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
731 |
elif mode==2: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
732 |
return (closest[1], closest[0]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
733 |
else: |
3721 | 734 |
raise ValueError("Illegal value for mode "+str(mode)) |
65
fb9c613d4c13
Allow 0x in HexColor, added stringToColor, fixed caching in getAllNamedColors
rgbecker
parents:
51
diff
changeset
|
735 |
|
3296 | 736 |
def hue2rgb(m1, m2, h): |
737 |
if h<0: h += 1 |
|
738 |
if h>1: h -= 1 |
|
739 |
if h*6<1: return m1+(m2-m1)*h*6 |
|
740 |
if h*2<1: return m2 |
|
741 |
if h*3<2: return m1+(m2-m1)*(4-6*h) |
|
742 |
return m1 |
|
743 |
||
744 |
def hsl2rgb(h, s, l): |
|
745 |
if l<=0.5: |
|
746 |
m2 = l*(s+1) |
|
747 |
else: |
|
748 |
m2 = l+s-l*s |
|
749 |
m1 = l*2-m2 |
|
750 |
return hue2rgb(m1, m2, h+1./3),hue2rgb(m1, m2, h),hue2rgb(m1, m2, h-1./3) |
|
751 |
||
3496
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
752 |
import re |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
753 |
_re_css = re.compile(r'^\s*(pcmyk|cmyk|rgb|hsl)(a|)\s*\(\s*([^)]*)\)\s*$') |
3296 | 754 |
class cssParse: |
755 |
def pcVal(self,v): |
|
756 |
v = v.strip() |
|
757 |
try: |
|
758 |
c=eval(v[:-1]) |
|
759 |
if not isinstance(c,(float,int)): raise ValueError |
|
760 |
c=min(100,max(0,c))/100. |
|
761 |
except: |
|
762 |
raise ValueError('bad percentage argument value %r in css color %r' % (v,self.s)) |
|
763 |
return c |
|
764 |
||
3297
22145ebf1cf4
colors.py: fix rgbVal and use rgbPcVal for colors (ie discrete mapped colours)
rgbecker
parents:
3296
diff
changeset
|
765 |
def rgbPcVal(self,v): |
22145ebf1cf4
colors.py: fix rgbVal and use rgbPcVal for colors (ie discrete mapped colours)
rgbecker
parents:
3296
diff
changeset
|
766 |
return int(self.pcVal(v)*255+0.5)/255. |
22145ebf1cf4
colors.py: fix rgbVal and use rgbPcVal for colors (ie discrete mapped colours)
rgbecker
parents:
3296
diff
changeset
|
767 |
|
3296 | 768 |
def rgbVal(self,v): |
769 |
v = v.strip() |
|
770 |
try: |
|
771 |
c=eval(v[:]) |
|
772 |
if not isinstance(c,int): raise ValueError |
|
3297
22145ebf1cf4
colors.py: fix rgbVal and use rgbPcVal for colors (ie discrete mapped colours)
rgbecker
parents:
3296
diff
changeset
|
773 |
return int(min(255,max(0,c)))/255. |
3296 | 774 |
except: |
775 |
raise ValueError('bad argument value %r in css color %r' % (v,self.s)) |
|
776 |
||
777 |
def hueVal(self,v): |
|
778 |
v = v.strip() |
|
779 |
try: |
|
780 |
c=eval(v[:]) |
|
781 |
if not isinstance(c,(int,float)): raise ValueError |
|
782 |
return ((c%360+360)%360)/360. |
|
783 |
except: |
|
784 |
raise ValueError('bad hue argument value %r in css color %r' % (v,self.s)) |
|
785 |
||
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
786 |
def alphaVal(self,v,c=1,n='alpha'): |
3296 | 787 |
try: |
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
788 |
a = eval(v.strip()) |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
789 |
if not isinstance(a,(int,float)): raise ValueError |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
790 |
return min(c,max(0,a)) |
3296 | 791 |
except: |
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
792 |
raise ValueError('bad %s argument value %r in css color %r' % (n,v,self.s)) |
3296 | 793 |
|
3496
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
794 |
_n_c = dict(pcmyk=(4,100,True,False),cmyk=(4,1,True,False),hsl=(3,1,False,True),rgb=(3,1,False,False)) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
795 |
|
3296 | 796 |
def __call__(self,s): |
3496
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
797 |
n = _re_css.match(s) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
798 |
if not n: return |
3296 | 799 |
self.s = s |
3496
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
800 |
b,c,cmyk,hsl = self._n_c[n.group(1)] |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
801 |
ha = n.group(2) |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
802 |
n = n.group(3).split(',') #strip parens and split on comma |
97191b541cc7
colors.py: fix up cssParse so we can have colors named cmyk_black
rgbecker
parents:
3473
diff
changeset
|
803 |
if len(n)!=(b+(ha and 1 or 0)): |
3296 | 804 |
raise ValueError('css color %r has wrong number of components' % s) |
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
805 |
if ha: |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
806 |
n,a = n[:b],self.alphaVal(n[b],c) |
3296 | 807 |
else: |
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
808 |
a = c |
3296 | 809 |
|
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
810 |
if cmyk: |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
811 |
C = self.alphaVal(n[0],c,'cyan') |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
812 |
M = self.alphaVal(n[1],c,'magenta') |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
813 |
Y = self.alphaVal(n[2],c,'yellow') |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
814 |
K = self.alphaVal(n[3],c,'black') |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
815 |
return (c>1 and PCMYKColor or CMYKColor)(C,M,Y,K,alpha=a) |
3296 | 816 |
else: |
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
817 |
if hsl: |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
818 |
R,G,B= hsl2rgb(self.hueVal(n[0]),self.pcVal(n[1]),self.pcVal(n[2])) |
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
819 |
else: |
3721 | 820 |
R,G,B = list(map('%' in n[0] and self.rgbPcVal or self.rgbVal,n)) |
3296 | 821 |
|
3333
5f8d60b7e5de
colors.py: add (p)cmyk(a) handling to cssParse/toColor
rgbecker
parents:
3326
diff
changeset
|
822 |
return Color(R,G,B,a) |
3296 | 823 |
|
824 |
cssParse=cssParse() |
|
825 |
||
3441
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
826 |
class toColor: |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
827 |
|
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
828 |
def __init__(self): |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
829 |
self.extraColorsNS = {} #used for overriding/adding to existing color names |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
830 |
#make case insensitive if that's your wish |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
831 |
|
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
832 |
def setExtraColorsNameSpace(self,NS): |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
833 |
self.extraColorsNS = NS |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
834 |
|
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
835 |
def __call__(self,arg,default=None): |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
836 |
'''try to map an arbitrary arg to a color instance |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
837 |
''' |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
838 |
if isinstance(arg,Color): return arg |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
839 |
if isinstance(arg,(tuple,list)): |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
840 |
assert 3<=len(arg)<=4, 'Can only convert 3 and 4 sequences to color' |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
841 |
assert 0<=min(arg) and max(arg)<=1 |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
842 |
return len(arg)==3 and Color(arg[0],arg[1],arg[2]) or CMYKColor(arg[0],arg[1],arg[2],arg[3]) |
3721 | 843 |
elif isinstance(arg,str): |
3441
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
844 |
C = cssParse(arg) |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
845 |
if C: return C |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
846 |
if arg in self.extraColorsNS: return self.extraColorsNS[arg] |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
847 |
C = getAllNamedColors() |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
848 |
s = arg.lower() |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
849 |
if s in C: return C[s] |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
850 |
try: |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
851 |
return toColor(eval(arg)) |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
852 |
except: |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
853 |
pass |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
854 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
855 |
try: |
3441
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
856 |
return HexColor(arg) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
857 |
except: |
3441
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
858 |
if default is None: |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
859 |
raise ValueError('Invalid color value %r' % arg) |
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
860 |
return default |
65
fb9c613d4c13
Allow 0x in HexColor, added stringToColor, fixed caching in getAllNamedColors
rgbecker
parents:
51
diff
changeset
|
861 |
|
3441
574d72e1ea74
colors.py: allow specified pre-namespacse for toColor
rgbecker
parents:
3411
diff
changeset
|
862 |
toColor = toColor() |
1654 | 863 |
|
2392 | 864 |
def toColorOrNone(arg,default=None): |
865 |
'''as above but allows None as a legal value''' |
|
866 |
if arg is None: |
|
867 |
return None |
|
868 |
else: |
|
869 |
return toColor(arg, default) |
|
870 |
||
1654 | 871 |
def setColors(**kw): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
872 |
UNDEF = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
873 |
progress = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
874 |
assigned = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
875 |
while kw and progress: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
876 |
progress = 0 |
3723
99aa837b6703
second stage of port to Python 3.3; working hello world
rptlab
parents:
3721
diff
changeset
|
877 |
for k, v in kw.items(): |
3176
c15bdeba0afc
colors.py: allow unicode arguments in toColor and elsewhere
rgbecker
parents:
3155
diff
changeset
|
878 |
if isinstance(v,(tuple,list)): |
3721 | 879 |
c = list(map(lambda x,UNDEF=UNDEF: toColor(x,UNDEF),v)) |
3176
c15bdeba0afc
colors.py: allow unicode arguments in toColor and elsewhere
rgbecker
parents:
3155
diff
changeset
|
880 |
if isinstance(v,tuple): c = tuple(c) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
881 |
ok = UNDEF not in c |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
882 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
883 |
c = toColor(v,UNDEF) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
884 |
ok = c is not UNDEF |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
885 |
if ok: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
886 |
assigned[k] = c |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
887 |
del kw[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
888 |
progress = 1 |
1654 | 889 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
890 |
if kw: raise ValueError("Can't convert\n%s" % str(kw)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
891 |
getAllNamedColors() |
3723
99aa837b6703
second stage of port to Python 3.3; working hello world
rptlab
parents:
3721
diff
changeset
|
892 |
for k, c in assigned.items(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
893 |
globals()[k] = c |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
894 |
if isinstance(c,Color): _namedColors[k] = c |
1659 | 895 |
|
896 |
def Whiter(c,f): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
897 |
'''given a color combine with white as c*f w*(1-f) 0<=f<=1''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
898 |
c = toColor(c) |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
899 |
if isinstance(c,CMYKColorSep): |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
900 |
c = c.clone() |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
901 |
if isinstance(c,PCMYKColorSep): |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
902 |
c.__class__ = PCMYKColor |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
903 |
else: |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
904 |
c.__class__ = CMYKColor |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
905 |
if isinstance(c,PCMYKColor): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
906 |
w = _PCMYK_white |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
907 |
elif isinstance(c,CMYKColor): w = _CMYK_white |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
908 |
else: w = white |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
909 |
return linearlyInterpolatedColor(w, c, 0, 1, f) |
1659 | 910 |
|
911 |
def Blacker(c,f): |
|
2136 | 912 |
'''given a color combine with black as c*f+b*(1-f) 0<=f<=1''' |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
913 |
c = toColor(c) |
3411
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
914 |
if isinstance(c,CMYKColorSep): |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
915 |
c = c.clone() |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
916 |
if isinstance(c,PCMYKColorSep): |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
917 |
c.__class__ = PCMYKColor |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
918 |
else: |
dc9b7ac34b8f
colors.py: attempt to fix linear interpolation for CMYKColorSep class
rgbecker
parents:
3410
diff
changeset
|
919 |
c.__class__ = CMYKColor |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
920 |
if isinstance(c,PCMYKColor): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
921 |
b = _PCMYK_black |
2032 | 922 |
elif isinstance(c,CMYKColor): b = _CMYK_black |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1663
diff
changeset
|
923 |
else: b = black |
1723 | 924 |
return linearlyInterpolatedColor(b, c, 0, 1, f) |
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
925 |
|
3237 | 926 |
def fade(aSpotColor, percentages): |
927 |
"""Waters down spot colors and returns a list of new ones |
|
928 |
||
929 |
e.g fade(myColor, [100,80,60,40,20]) returns a list of five colors |
|
930 |
""" |
|
931 |
out = [] |
|
932 |
for percent in percentages: |
|
933 |
frac = percent * 0.01 #assume they give us numbers from 0 to 100 |
|
934 |
newCyan = frac * aSpotColor.cyan |
|
935 |
newMagenta = frac * aSpotColor.magenta |
|
936 |
newYellow = frac * aSpotColor.yellow |
|
937 |
newBlack = frac * aSpotColor.black |
|
938 |
newDensity = frac * aSpotColor.density |
|
3254
dd9042134279
canvas.py, textobject.py: merge _*ColorRGB/CMYK attributes into ColorObj
rgbecker
parents:
3237
diff
changeset
|
939 |
newSpot = CMYKColor( newCyan, newMagenta, newYellow, newBlack, |
3237 | 940 |
spotName = aSpotColor.spotName, |
941 |
density = newDensity) |
|
942 |
out.append(newSpot) |
|
943 |
return out |
|
944 |
||
3446 | 945 |
def _enforceError(kind,c,tc): |
946 |
if isinstance(tc,Color): |
|
947 |
xtra = tc._lookupName() |
|
948 |
xtra = xtra and '(%s)'%xtra or '' |
|
949 |
else: |
|
950 |
xtra = '' |
|
951 |
raise ValueError('Non %s color %r%s' % (kind,c,xtra)) |
|
952 |
||
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
953 |
def _enforceSEP(c): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
954 |
'''pure separating colors only, this makes black a problem''' |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
955 |
tc = toColor(c) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
956 |
if not isinstance(tc,CMYKColorSep): |
3446 | 957 |
_enforceError('separating',c,tc) |
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
958 |
return tc |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
959 |
|
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
960 |
def _enforceSEP_BLACK(c): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
961 |
'''separating + blacks only''' |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
962 |
tc = toColor(c) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
963 |
if not isinstance(tc,CMYKColorSep): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
964 |
if isinstance(tc,Color) and tc.red==tc.blue==tc.green: #ahahahah it's a grey |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
965 |
tc = _CMYK_black.clone(density=1-tc.red) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
966 |
elif not (isinstance(tc,CMYKColor) and tc.cyan==tc.magenta==tc.yellow==0): #ie some shade of grey |
3446 | 967 |
_enforceError('separating or black',c,tc) |
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
968 |
return tc |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
969 |
|
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
970 |
def _enforceSEP_CMYK(c): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
971 |
'''separating or cmyk only''' |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
972 |
tc = toColor(c) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
973 |
if not isinstance(tc,CMYKColorSep): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
974 |
if isinstance(tc,Color) and tc.red==tc.blue==tc.green: #ahahahah it's a grey |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
975 |
tc = _CMYK_black.clone(density=1-tc.red) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
976 |
elif not isinstance(tc,CMYKColor): |
3446 | 977 |
_enforceError('separating or CMYK',c,tc) |
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
978 |
return tc |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
979 |
|
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
980 |
def _enforceCMYK(c): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
981 |
'''cmyk outputs only (rgb greys converted)''' |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
982 |
tc = toColor(c) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
983 |
if not isinstance(tc,CMYKColor): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
984 |
if isinstance(tc,Color) and tc.red==tc.blue==tc.green: #ahahahah it's a grey |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
985 |
tc = _CMYK_black.clone(black=1-tc.red,alpha=tc.alpha) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
986 |
else: |
3446 | 987 |
_enforceError('CMYK',c,tc) |
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
988 |
elif isinstance(tc,CMYKColorSep): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
989 |
tc = tc.clone() |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
990 |
tc.__class__ = CMYKColor |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
991 |
return tc |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
992 |
|
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
993 |
def _enforceRGB(c): |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
994 |
tc = toColor(c) |
3446 | 995 |
if isinstance(tc,CMYKColor): |
996 |
if tc.cyan==tc.magenta==tc.yellow==0: #ahahahah it's grey |
|
997 |
v = 1-tc.black*tc.density |
|
998 |
tc = Color(v,v,v,alpha=tc.alpha) |
|
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
999 |
else: |
3446 | 1000 |
_enforceError('RGB',c,tc) |
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1001 |
return tc |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1002 |
|
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1003 |
def _chooseEnforceColorSpace(enforceColorSpace): |
3721 | 1004 |
if enforceColorSpace is not None and not isinstance(enforceColorSpace, collections.Callable): |
1005 |
if isinstance(enforceColorSpace,str): enforceColorSpace=enforceColorSpace.upper() |
|
3444
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1006 |
if enforceColorSpace=='CMYK': |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1007 |
enforceColorSpace = _enforceCMYK |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1008 |
elif enforceColorSpace=='RGB': |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1009 |
enforceColorSpace = _enforceRGB |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1010 |
elif enforceColorSpace=='SEP': |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1011 |
enforceColorSpace = _enforceSEP |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1012 |
elif enforceColorSpace=='SEP_BLACK': |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1013 |
enforceColorSpace = _enforceSEP_BLACK |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1014 |
elif enforceColorSpace=='SEP_CMYK': |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1015 |
enforceColorSpace = _enforceSEP_CMYK |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1016 |
else: |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1017 |
raise ValueError('Invalid value for Canvas argument enforceColorSpace=%r' % enforceColorSpace) |
bea839deb0c1
reportlab: initial checkin for colorspace handling
rgbecker
parents:
3441
diff
changeset
|
1018 |
return enforceColorSpace |
3237 | 1019 |
|
2719
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
1020 |
if __name__ == "__main__": |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
1021 |
import doctest |
2fe0642f3951
Add some tests for, and an extra argument to, HexColor
jjlee
parents:
2490
diff
changeset
|
1022 |
doctest.testmod() |