def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx self.cache_fields += [ (8, 2, 'Number of layer records'), ] self.cache_fields += [ (10, 2, 'Page index\n'), ] pos = 12 for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): self.cache_fields += [ (pos, 4, 'Layer offset'), ] pos += 4 self.cache_fields += [ (pos, 2, 'Layer name size'), ] sz = utils.word2py_int(self.chunk[pos:pos + 2], rifx) pos += 2 self.cache_fields += [ (pos, sz, 'Layer name'), ] pos += sz self.cache_fields += [ (pos, 4, 'Ref.list address\n'), ] pos += 4
def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx if self.config.v1: self.cache_fields += [ (8, 2, 'Record count\n'), ] pos, rec_sz = 10, 4 else: self.cache_fields += [ (8, 2, 'Record count'), ] self.cache_fields += [ (10, 2, 'Record size\n'), ] pos = 12 rec_sz = utils.word2py_int(self.chunk[10:12], rifx) / 4 for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): self.cache_fields += [ (pos, rec_sz, 'Page offset'), ] pos += rec_sz self.cache_fields += [ (pos, rec_sz, 'Layer Table offset'), ] pos += rec_sz self.cache_fields += [ (pos, rec_sz, 'Thumbnail offset'), ] pos += rec_sz self.cache_fields += [ (pos, rec_sz, 'RefList offset\n'), ] pos += rec_sz
def update_from_chunk(self): rifx = self.config.rifx records = self.data['records'] = [] pos = 14 for _i in range(utils.word2py_int(self.chunk[12:14], rifx)): rec_id = utils.word2py_int(self.chunk[pos:pos + 2], rifx) pos += 2 offset = utils.dword2py_int(self.chunk[pos:pos + 4], rifx) pos += 4 records.append((rec_id, offset))
def update(self): self.stroke_id = str(self.chunk[8:12].encode('hex')) self.cache_fields.append((8, 4, 'outline id')) data = self.chunk[8:] ls_offset = 4 lc_offset = 6 ct_offset = 8 lw_offset = 12 offset = 28 dash_offset = 104 if self.version == CDR13: ls_offset = 24 lc_offset = 26 ct_offset = 28 lw_offset = 30 offset = 40 dash_offset = 116 self.stroke_spec = ord(data[ls_offset]) self.cache_fields.append((ls_offset + 8, 1, 'outline specification')) self.stroke_caps = ord(data[lc_offset]) self.cache_fields.append((lc_offset + 8, 1, 'outline caps')) self.stroke_join = ord(data[ct_offset]) self.cache_fields.append((ct_offset + 8, 1, 'outline corners')) self.stroke_width = parse_size_value(data[lw_offset:lw_offset + 4]) self.cache_fields.append((lw_offset + 8, 1, 'outline width')) dashnum = word2py_int(data[dash_offset:dash_offset + 2]) self.cache_fields.append( (dash_offset + 8, 2, 'number of dash records')) if dashnum > 0: self.stroke_dashes = range(dashnum) for i in self.stroke_dashes: dash = word2py_int(data[dash_offset + 2 + i * 2:dash_offset + 4 + i * 2]) self.stroke_dashes[i] = dash self.cache_fields.append( (dash_offset + 10, 2 * dashnum, 'dash records')) offset += 0x30 self.color_space_type = ord(data[offset]) self.cache_fields.append((offset + 8, 1, 'color space type')) offset += 16 self.stroke_color = parse_cdr_color(self.color_space_type, self.chunk[offset:offset + 4]) if self.stroke_color: self.cache_fields.append((offset, 4, 'color value'))
def update_from_chunk(self): rifx = self.config.rifx layers = self.data['layers'] = [] pos = 12 self.data['page'] = utils.word2py_int(self.chunk[10:12], rifx) for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): offset = utils.dword2py_int(self.chunk[pos:pos + 4], rifx) pos += 4 sz = utils.word2py_int(self.chunk[pos:pos + 2], rifx) pos += 2 name = self.chunk[pos:pos + sz] pos += sz + 4 layers.append((offset, name))
def update(self): self.stroke_id = str(self.chunk[8:12].encode('hex')) self.cache_fields.append((8, 4, 'outline id')) data = self.chunk[8:] ls_offset = 4 lc_offset = 6 ct_offset = 8 lw_offset = 12 offset = 28 dash_offset = 104 if self.version == CDR13: ls_offset = 24 lc_offset = 26 ct_offset = 28 lw_offset = 30 offset = 40 dash_offset = 116 self.stroke_spec = ord(data[ls_offset]) self.cache_fields.append((ls_offset + 8, 1, 'outline specification')) self.stroke_caps = ord(data[lc_offset]) self.cache_fields.append((lc_offset + 8, 1, 'outline caps')) self.stroke_join = ord(data[ct_offset]) self.cache_fields.append((ct_offset + 8, 1, 'outline corners')) self.stroke_width = parse_size_value(data[lw_offset:lw_offset + 4]) self.cache_fields.append((lw_offset + 8, 1, 'outline width')) dashnum = word2py_int(data[dash_offset:dash_offset + 2]) self.cache_fields.append((dash_offset + 8, 2, 'number of dash records')) if dashnum > 0: self.stroke_dashes = range(dashnum) for i in self.stroke_dashes: dash = word2py_int(data[dash_offset + 2 + i * 2:dash_offset + 4 + i * 2]) self.stroke_dashes[i] = dash self.cache_fields.append((dash_offset + 10, 2 * dashnum, 'dash records')) offset += 0x30 self.color_space_type = ord(data[offset]) self.cache_fields.append((offset + 8, 1, 'color space type')) offset += 16 self.stroke_color = parse_cdr_color(self.color_space_type, self.chunk[offset:offset + 4]) if self.stroke_color: self.cache_fields.append((offset, 4, 'color value'))
def update_from_chunk(self): rifx = self.config.rifx records = self.data['records'] = [] if self.config.v1: pos, rec_sz, rec_sig = 10, 16, 'IIII' self.data['rec_sz'] = rec_sz else: pos = 12 rec_sz = utils.word2py_int(self.chunk[10:12], rifx) rec_sig = 4 * {2: 'H', 4: 'I', 8: 'Q'}.get(rec_sz / 4) self.data['rec_sz'] = rec_sz sig = '>' + rec_sig if rifx else '<' + rec_sig for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): records.append(struct.unpack(sig, self.chunk[pos:pos + rec_sz])) pos += rec_sz
def update_from_chunk(self): chunk = self.chunk[8:] pos = 0 rifx = self.config.rifx parents = [self] while pos < len(chunk): size = utils.word2py_int(chunk[pos:pos + 2], rifx) instr_id = chunk[pos + 2:pos + 4] instr_id = abs(utils.signed_word2py_int(instr_id, rifx)) instr = chunk[pos:pos + size] offset = self.offset + 8 + pos obj = cmx_instr.make_instruction(self.config, instr, offset) name = cmx_const.INSTR_CODES.get(instr_id, '') if name.startswith('Begin'): parents[-1].add(obj) parents.append(obj) elif name.startswith('End'): parents[-1].add(obj) parents = parents[:-1] elif instr_id == cmx_const.JUMP_ABSOLUTE: parents[-1].add(obj) sz = obj.get('jump') - offset - 8 obj.chunk += chunk[pos + 8:pos + 8 + sz] size += sz else: parents[-1].add(obj) pos += size self.chunk = self.chunk[:8]
def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx self.cache_fields += [ (8, 2, 'Number of colors\n'), ] pos = 10 for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): model = utils.byte2py_int(self.chunk[pos]) model_name = cmx_const.COLOR_MODEL_MAP.get(model, 'Unknown') self.cache_fields += [ (pos, 1, '%s color model' % model_name), ] palette = utils.byte2py_int(self.chunk[pos + 1]) pals = cmx_const.COLOR_PALETTES pal_name = pals[palette] if palette < len(pals) else 'Unknown' self.cache_fields += [ (pos + 1, 1, '%s palette' % pal_name), ] if model >= len(cmx_const.COLOR_BYTES): break clr_sz = cmx_const.COLOR_BYTES[model] self.cache_fields += [ (pos + 2, clr_sz, 'Color values\n'), ] pos += clr_sz + 2
def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx self.cache_fields += [ (8, 2, 'Number of dash records'), ] pos = 10 for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): self.cache_fields += [ (pos, 2, 'Number of dash elements'), ] num = utils.word2py_int(self.chunk[pos:pos + 2], rifx) self.cache_fields += [ (pos + 2, 2 * num, 'Dash elements'), ] pos += 2 + 2 * num
def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx self.cache_fields += [ (8, 2, 'Number of pen records'), ] pos = 10 for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): self.cache_fields += [ (pos, 10, 'Pen record'), ] pos += 10 if utils.word2py_int(self.chunk[pos - 2:pos], rifx) != 1: self.cache_fields += [ (pos, 48, 'Pen matrix'), ]
def update_from_chunk(self): rifx = self.config.rifx arrows = self.data['arrows'] = [] pos = 10 sig = '>hh' if rifx else '<hh' for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): arrows.append(struct.unpack(sig, self.chunk[pos:pos + 4])) pos += 4
def update_from_chunk(self): rifx = self.config.rifx records = self.data['records'] = [] if self.config.v1: pos, rec_sz, rec_sig = 12, 4, 'I' self.data['rec_sz'] = rec_sz self.data['table_id'] = utils.word2py_int(self.chunk[10:12], rifx) else: pos = 14 rec_sz = utils.word2py_int(self.chunk[10:12], rifx) rec_sig = {2: 'H', 4: 'I', 8: 'Q'}.get(rec_sz) self.data['rec_sz'] = rec_sz self.data['table_id'] = utils.word2py_int(self.chunk[12:14], rifx) sig = '>' + rec_sig if rifx else '<' + rec_sig for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): records.append(struct.unpack(sig, self.chunk[pos:pos + rec_sz])[0]) pos += rec_sz
def parse_hls(data): """ Parses HLS color bytes and returns fill style list. """ h = word2py_int(data[0:2]) / 360.0 l = ord(data[2]) / 255.0 s = ord(data[3]) / 255.0 r, g, b = hls_to_rgb(h, l, s) return [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
def parse_hsb(data): """ Parses HSB/HSV color bytes and returns fill style list. """ h = word2py_int(data[0:2]) / 360.0 s = ord(data[2]) / 255.0 v = ord(data[3]) / 255.0 r, g, b = hsv_to_rgb(h, s, v) return [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
def update_from_chunk(self): rifx = self.config.rifx rlists = self.data['rlists'] = [] pos = 10 # Association, Type, ObjectID sig = '>hhh' if rifx else '<hhh' for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): rlists.append(struct.unpack(sig, self.chunk[pos:pos + 6])) pos += 6
def parse_hsb(data): """ Parses HSB/HSV color bytes and returns fill style list. """ h = word2py_int(data[0:2]) / 360.0 s = data[2] / 255.0 v = data[3] / 255.0 r, g, b = hsv_to_rgb(h, s, v) return [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
def parse_hls(data): """ Parses HLS color bytes and returns fill style list. """ h = word2py_int(data[0:2]) / 360.0 l = data[2] / 255.0 s = data[3] / 255.0 r, g, b = hls_to_rgb(h, l, s) return [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx self.cache_fields += [ (8, 2, 'Number of records'), ] pos = 10 for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): self.cache_fields += [ (pos, 13, 'Screen record'), ] pos += 13
def update_for_sword(self): CmxInstruction.update_for_sword(self) name_sz = utils.word2py_int(self.chunk[16:18], self.config.rifx) tail_sz = len(self.chunk) - 18 - name_sz self.cache_fields += [ (4, 2, 'Page number'), (6, 2, 'Layer number'), (8, 4, 'Layer flags'), (12, 4, 'Tally'), (16, 2, 'Layer name size'), (18, name_sz, 'Layer name'), (18 + name_sz, tail_sz, 'Layer tail'), ]
def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx self.cache_fields += [ (8, 2, 'MasterID'), ] self.cache_fields += [ (10, 2, 'Size'), ] self.cache_fields += [ (12, 2, 'Record count\n'), ] pos = 14 for _i in range(utils.word2py_int(self.chunk[12:14], rifx)): rec_id = utils.word2py_int(self.chunk[pos:pos + 2], rifx) rec_name = cmx_const.SECTIONS.get(rec_id, 'UNKNOWN') self.cache_fields += [ (pos, 2, rec_name), ] pos += 2 self.cache_fields += [ (pos, 4, 'Section address\n'), ] pos += 4
def update_for_sword(self): CmxRiffElement.update_for_sword(self) rifx = self.config.rifx self.cache_fields += [ (8, 2, 'Record count'), ] if self.config.v1: pos, rec_sz = 12, 4 else: self.cache_fields += [ (10, 2, 'Record size'), ] pos = 14 rec_sz = utils.word2py_int(self.chunk[10:12], rifx) section = utils.word2py_int(self.chunk[pos - 2:pos], rifx) section = cmx_const.SECTIONS.get(section, 'UNKNOWN') self.cache_fields += [ (pos - 2, 2, 'Index Table ID\n' + 7 * ' ' + '(%s)\n' % section), ] for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): self.cache_fields += [ (pos, rec_sz, 'Offset'), ] pos += rec_sz
def update_from_chunk(self): rifx = self.config.rifx colors = self.data['colors'] = [] pos = 10 for _i in range(utils.word2py_int(self.chunk[8:10], rifx)): model = utils.byte2py_int(self.chunk[pos]) palette = utils.byte2py_int(self.chunk[pos + 1]) if model < len(cmx_const.COLOR_BYTES): clr_sz = cmx_const.COLOR_BYTES[model] else: LOG.error('Invalide or unknown color model %s', model) break vals = tuple( utils.byte2py_int(val) for val in self.chunk[pos + 2:pos + 2 + clr_sz]) colors.append((model, palette, vals)) pos += clr_sz + 2
def update_from_chunk(self): chunk = self.chunk[8:] pos = 0 rifx = self.config.rifx parents = [self] while pos < len(chunk): size = utils.word2py_int(chunk[pos:pos + 2], rifx) instr_id = utils.signed_word2py_int(chunk[pos + 2:pos + 4], rifx) instr = chunk[pos:pos + size] obj = cmx_instr.make_instruction(self.config, instr) name = cmx_const.INSTR_CODES.get(instr_id, '') if name.startswith('Begin'): parents[-1].add(obj) parents.append(obj) elif name.startswith('End'): parents = parents[:-1] parents[-1].add(obj) else: parents[-1].add(obj) pos += size self.chunk = self.chunk[:8]
def update(self): data = self.chunk[8:] self.font_id = str(data[0:2].encode('hex')) self.cache_fields.append((8, 2, 'font id')) self.encoding = word2py_int(data[2:4]) self.cache_fields.append((10, 2, 'font encoding')) self.font_flags = str(data[4:18].encode('hex')) self.cache_fields.append((12, 14, 'font flags')) try: #Gets font name data = data[18:52] zero = '00'.decode('hex') if not self.version in [CDR6, CDR7, CDR8, CDR9]: self.font_name = (data.rstrip(zero) + zero).decode('utf-16') else: self.font_name = data.rstrip(zero).decode(self.config.system_encoding) self.cache_fields.append((26, len(data), 'font name')) except: self.font_name = ''
def update_for_sword(self): rifx = self.config.rifx CmxInstruction.update_for_sword(self) flags = utils.byte2py_int(self.chunk[4]) self.cache_fields += [ (4, 1, 'Style flags'), ] pos = 5 if flags & cmx_const.INSTR_FILL_FLAG: fill = utils.word2py_int(self.chunk[pos:pos + 2], rifx) f = cmx_const.FILL_TYPE_MAP.get(fill, 'UNKNOWN') self.cache_fields += [ (pos, 2, 'Fill type: %s' % f), ] pos += 2 if fill == cmx_const.INSTR_FILL_EMPTY: pass elif fill == cmx_const.INSTR_FILL_UNIFORM: self.cache_fields += [ (pos, 2, 'Color ref.'), ] pos += 2 self.cache_fields += [ (pos, 2, 'Screen ref.'), ] pos += 2 elif fill == cmx_const.INSTR_FILL_FOUNTAIN: f = utils.word2py_int(self.chunk[pos:pos + 2], rifx) f = cmx_const.FILL_FOUNTAINS.get(f, 'unknown') self.cache_fields += [ (pos, 2, 'Fountain type: %s' % f), ] pos += 2 self.cache_fields += [ (pos, 2, 'Screen ref.'), ] pos += 2 self.cache_fields += [ (pos, 2, 'Padding'), ] pos += 2 self.cache_fields += [ (pos, 4, 'Angle'), ] pos += 4 self.cache_fields += [ (pos, 4, 'Offset (x,y) int16'), ] pos += 4 self.cache_fields += [ (pos, 2, 'Steps'), ] pos += 2 self.cache_fields += [ (pos, 2, 'Mode'), ] pos += 2 color_count = utils.word2py_int(self.chunk[pos:pos + 2], rifx) self.cache_fields += [ (pos, 2, 'Color count (%d)' % color_count), ] pos += 2 for _i in range(color_count): self.cache_fields += [ (pos, 2, 'Color ref.'), ] pos += 2 self.cache_fields += [ (pos, 2, 'Position'), ] pos += 2 else: pos, sz, txt = self.cache_fields[-1] txt += '\n UNSUPPORTED FILL TYPE!' self.cache_fields[-1] = (pos, sz, txt) return if flags & cmx_const.INSTR_STROKE_FLAG: self.cache_fields += [ (pos, 2, 'Outline ref.'), ] pos += 2 if flags >= cmx_const.INSTR_LENS_FLAG: pos, sz, txt = self.cache_fields[-1] sp = '\n ' txt += '%sUNSUPPORTED LENS, CANVAS %sOR CONTAINER!' % (sp, sp) self.cache_fields[-1] = (pos, sz, txt) return count = utils.word2py_int(self.chunk[pos:pos + 2], rifx) self.cache_fields += [ (pos, 2, 'Point count (%d)' % count), ] pos += 2 self.cache_fields += [ (pos, 4 * count, 'Points [(x,y),] int16'), ] pos += 4 * count self.cache_fields += [ (pos, count, 'Nodes [byte,]'), ] pos += count self.cache_fields += [ (pos, 8, 'Curve bbox'), ] pos += 8
def __init__(self, chunk): self.cache_fields = [] self.chunk = chunk self.func = utils.word2py_int(self.chunk[4:6]) if self.func in wmfconst.WMF_RECORD_NAMES: self.resolve_name = wmfconst.WMF_RECORD_NAMES[self.func]
def readword(self): return utils.word2py_int(self.fileptr.read(2))
def update_from_chunk(self): rifx = self.config.rifx self.data['tail'] = '' flags = self.data['style_flags'] = utils.byte2py_int(self.chunk[4]) pos = 5 if flags & cmx_const.INSTR_FILL_FLAG: fill = utils.word2py_int(self.chunk[pos:pos + 2], rifx) self.data['fill_type'] = fill pos += 2 # FILL if fill == cmx_const.INSTR_FILL_EMPTY: pass elif fill == cmx_const.INSTR_FILL_UNIFORM: # (color, screen) sig = '>hh' if rifx else '<hh' self.data['fill'] = struct.unpack(sig, self.chunk[pos:pos + 4]) pos += 4 elif fill == cmx_const.INSTR_FILL_FOUNTAIN: # (type, screen, padding, angle, x, y, steps, mode, clr_count) sig = '>hhhihhhh' if rifx else '<hhhihhhh' self.data['fill'] = struct.unpack(sig, self.chunk[pos:pos + 18]) pos += 18 # steps: [(color, pos)] sig = '>hh' if rifx else '<hh' steps = self.data['steps'] = [] for _ in range(self.data['fill'][-1]): steps.append(struct.unpack(sig, self.chunk[pos:pos + 4])) pos += 4 else: self.data['tail'] = self.chunk[pos:] return # OUTLINE if flags & cmx_const.INSTR_STROKE_FLAG: self.data['outline'] = utils.word2py_int(self.chunk[pos:pos + 2], rifx) pos += 2 if flags >= cmx_const.INSTR_LENS_FLAG: self.data['tail'] = self.chunk[pos:] return # POINTS & NODES # points: [(x,y),...] count = utils.word2py_int(self.chunk[pos:pos + 2], rifx) pos += 2 points = self.data['points'] = [] sig = '>hh' if rifx else '<hh' for _ in range(count): points.append(struct.unpack(sig, self.chunk[pos:pos + 4])) pos += 4 # nodes: (node,...) sig = count * 'B' self.data['nodes'] = struct.unpack(sig, self.chunk[pos:pos + count]) pos += count # BBOX sig = '>hhhh' if rifx else '<hhhh' self.data['bbox'] = struct.unpack(sig, self.chunk[pos:pos + 8]) pos += 8 if pos < len(self.chunk): self.data['tail'] = self.chunk[pos:]