pdfcolor.py 879 Bytes
Newer Older
1 2
import collections
from .psparser import LIT
3

4
import six #Python 2+3 compatibility
5 6 7 8 9 10 11

##  PDFColorSpace
##
LITERAL_DEVICE_GRAY = LIT('DeviceGray')
LITERAL_DEVICE_RGB = LIT('DeviceRGB')
LITERAL_DEVICE_CMYK = LIT('DeviceCMYK')

12

13 14 15 16 17 18 19 20 21 22 23
class PDFColorSpace(object):

    def __init__(self, name, ncomponents):
        self.name = name
        self.ncomponents = ncomponents
        return

    def __repr__(self):
        return '<PDFColorSpace: %s, ncomponents=%d>' % (self.name, self.ncomponents)


24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
if six.PY2:
    PREDEFINED_COLORSPACE = {}
else:
    PREDEFINED_COLORSPACE = collections.OrderedDict()

for (name, n) in [
    ('DeviceGray', 1),  # default value first
    ('CalRGB', 3),
    ('CalGray', 1),
    ('Lab', 3),
    ('DeviceRGB', 3),
    ('DeviceCMYK', 4),
    ('Separation', 1),
    ('Indexed', 1),
    ('Pattern', 1),
]:
    PREDEFINED_COLORSPACE[name]=PDFColorSpace(name, n)