def process_fill(self, chunk): cdr_version=self.cdr_version fill_data=self.fill_data fild_pal_type = ('Transparent', 'Solid', 'Gradient') colorIndex='%02X'%ord(chunk.data[0]) + '%02X'%ord(chunk.data[1]) + '%02X'%ord(chunk.data[2]) + '%02X'%ord(chunk.data[3]) pal = ord(chunk.data[4]) if cdr_version >= 13: pal = ord(chunk.data[0xc]) if pal < 3: fild_type = fild_pal_type[pal] else: fild_type = 'Unknown (%X)'%pal clr_offset = 0x8 if cdr_version >= 13: clr_offset = 0x1b if clr_offset < chunk.rawsize: clrmode = ord(chunk.data[clr_offset]) if fild_type == 'Solid': offset = 0x10 if cdr_version >= 13: offset =0x23 if clrmode == 9: #Grayscale fill_data[colorIndex]=CreateCMYKColor(0, 0, 0, 1.0 - ord(chunk.data[offset]) /255.0) elif clrmode == 5: #RGB fill_data[colorIndex]=CreateRGBColor(ord(chunk.data[offset+2]) / 255.0, ord(chunk.data[offset+1])/ 255.0, ord(chunk.data[offset]) / 255.0) elif clrmode == 4: #CMY fill_data[colorIndex]=CreateCMYKColor(ord(chunk.data[offset])/255.0, ord(chunk.data[offset+1])/255.0, ord(chunk.data[offset+2])/255.0, 0.0) elif clrmode == 3:#CMYK255 fill_data[colorIndex]=CreateCMYKColor(ord(chunk.data[offset])/255.0, ord(chunk.data[offset+1])/255.0, ord(chunk.data[offset+2])/255.0, ord(chunk.data[offset+3])/255.0) elif clrmode == 2: #CMYK fill_data[colorIndex]=CreateCMYKColor(ord(chunk.data[offset])/100.0, ord(chunk.data[offset+1])/100.0, ord(chunk.data[offset+2])/100.0, ord(chunk.data[offset+3])/100.0) elif clrmode == 1: fill_data[colorIndex]=CreateCMYKColor(ord(chunk.data[offset])/255.0, ord(chunk.data[offset+1])/255.0, ord(chunk.data[offset+2])/255.0, ord(chunk.data[offset+3])/255.0) elif clrmode == 0x11: fill_data[colorIndex]=CreateCMYKColor(ord(chunk.data[offset])/255.0, ord(chunk.data[offset+1])/255.0, ord(chunk.data[offset+2])/255.0, ord(chunk.data[offset+3])/255.0) elif clrmode == 0x14: #Registration Color fill_data[colorIndex]=CreateCMYKColor(1,1,1,1) else: fill_data[colorIndex]=CreateCMYKColor(0, 0, 0, .20) if fild_type == 'Transparent': fill_data[colorIndex]=None if fild_type == 'Gradient': fill_data[colorIndex]=CreateCMYKColor(0, 0, 0, .3)
def csscolor(str): #set default color black color = StandardColors.black parts = str parts = parts.replace(',', ' ') parts = parts.replace('(', ' ') parts = parts.replace(')', ' ') parts = parts.split() i = 0 while i < len(parts): part = parts[i] if part[0] == '#' and len(part) == 7: r = atoi(part[1:3], 16) / 255.0 g = atoi(part[3:5], 16) / 255.0 b = atoi(part[5:7], 16) / 255.0 color = CreateRGBColor(r, g, b) i += 1 elif part[0] == '#' and len(part) == 4: # According to the CSS rules a single HEX digit is to be # treated as a repetition of the digit, so that for a digit # d the value is (16 * d + d) / 255.0 which is equal to d / 15.0 r = atoi(part[1], 16) / 15.0 g = atoi(part[2], 16) / 15.0 b = atoi(part[3], 16) / 15.0 color = CreateRGBColor(r, g, b) i += 1 elif namedcolors.has_key(part): color = namedcolors[part] i += 1 elif part == 'rgb': if parts[i+1][-1] == '%': r = atof(parts[i+1][:-1]) / 100.0 else: r = atof(parts[i+1]) / 255.0 if parts[i+2][-1] == '%': g = atof(parts[i+2][:-1]) / 100.0 else: g = atof(parts[i+2]) / 255.0 if parts[i+3][-1] == '%': b = atof(parts[i+3][:-1]) / 100.0 else: b = atof(parts[i+3]) / 255.0 color = CreateRGBColor(r, g, b) i += 4 elif part == 'icc-color': #icc = parts[i+1] c = atof(parts[i+2]) m = atof(parts[i+3]) y = atof(parts[i+4]) k = atof(parts[i+5]) color = CreateCMYKColor(c, m, y, k) i += 6 elif part == 'device-gray': gray = 1.0 - atof(parts[i+1]) color = CreateCMYKColor(0, 0, 0, gray) i += 2 elif part == 'device-cmyk': c = atof(parts[i+1]) m = atof(parts[i+2]) y = atof(parts[i+3]) k = atof(parts[i+4]) color = CreateCMYKColor(c, m, y, k) i += 5 else: i += 1 return color
def process_outline(self, chunk, usual): cdr_version = self.cdr_version outl = Outline() outl.outlineIndex = '%02X' % ord(chunk.data[0]) + '%02X' % ord( chunk.data[1]) + '%02X' % ord(chunk.data[2]) + '%02X' % ord( chunk.data[3]) ls_offset = 0x4 lc_offset = 0x6 ct_offset = 0x8 lw_offset = 0xc offset = 0x1c dash_offset = 0x68 if cdr_version >= 13: ls_offset = 0x18 lc_offset = 0x1a ct_offset = 0x1c lw_offset = 0x1e offset = 0x28 dash_offset = 0x74 outl.spec = ord(chunk.data[ls_offset]) outl.caps = ord(chunk.data[lc_offset]) outl.corner = ord(chunk.data[ct_offset]) [line_width] = struct.unpack('<L', chunk.data[lw_offset:lw_offset + 4]) outl.width = line_width * self.scale ## dashes [dashnum] = struct.unpack('<h', chunk.data[dash_offset:dash_offset + 2]) if dashnum > 0: outl.dashes = range(dashnum) for i in outl.dashes: [dash] = struct.unpack( '<h', chunk.data[dash_offset + 2 + i * 2:dash_offset + 4 + i * 2]) outl.dashes[i] = dash clrmode = ord(chunk.data[offset + 0x30]) if clrmode == 9: outl.color = CreateCMYKColor( 0, 0, 0, 1.0 - ord(chunk.data[offset + 0x38]) / 255.0) elif clrmode == 5: outl.color = CreateRGBColor( ord(chunk.data[offset + 0x3a]) / 255.0, ord(chunk.data[offset + 0x39]) / 255.0, ord(chunk.data[offset + 0x38]) / 255.0) elif clrmode == 4: outl.color = CreateCMYKColor( ord(chunk.data[offset + 0x38]) / 255.0, ord(chunk.data[offset + 0x39]) / 255.0, ord(chunk.data[offset + 0x3a]) / 255.0, 0.0) elif clrmode == 2: outl.color = CreateCMYKColor( ord(chunk.data[offset + 0x38]) / 100.0, ord(chunk.data[offset + 0x39]) / 100.0, ord(chunk.data[offset + 0x3a]) / 100.0, ord(chunk.data[offset + 0x3b]) / 100.0) elif clrmode == 3 or clrmode == 0x11: outl.color = CreateCMYKColor( ord(chunk.data[offset + 0x38]) / 255.0, ord(chunk.data[offset + 0x39]) / 255.0, ord(chunk.data[offset + 0x3a]) / 255.0, ord(chunk.data[offset + 0x3b]) / 255.0) elif clrmode == 17: outl.color = CreateCMYKColor( ord(chunk.data[offset + 0x38]) / 255.0, ord(chunk.data[offset + 0x39]) / 255.0, ord(chunk.data[offset + 0x3a]) / 255.0, ord(chunk.data[offset + 0x3b]) / 255.0) elif clrmode == 20: outl.color = CreateCMYKColor(1.0, 1.0, 1.0, 1.0) else: outl.color = CreateCMYKColor(0, 0, 0, 1) self.outl_data[outl.outlineIndex] = outl if not usual: self.default_outl_data = outl
def set_fill_cmyk(self, c, m, y, k): self.fill_color = CreateCMYKColor(c, m, y, k)
def set_line_cmyk(self, c, m, y, k): self.line_color = CreateCMYKColor(c, m, y, k)
def cmyk_custom_color(c, m, y, k, t): # t = tint t = 1.0 - t return CreateCMYKColor(t * c, t * m, t * y, t * k)