Beispiel #1
0
	def update_for_save(self):
		for child in self.childs: child.update_for_save()
		self.chunk = '' + JCW_ID
		self.chunk += JCW_VER
		self.chunk += utils.py_int2word(len(self.childs))
		self.chunk += utils.py_int2byte(self.colorspace)
		self.chunk += utils.py_int2byte(self.namesize)
Beispiel #2
0
 def update_for_save(self):
     for child in self.childs:
         child.update_for_save()
     self.chunk = JCW_ID
     self.chunk += JCW_VER
     self.chunk += utils.py_int2word(len(self.childs))
     self.chunk += utils.py_int2byte(self.colorspace)
     self.chunk += utils.py_int2byte(self.namesize)
Beispiel #3
0
 def update(self):
     rifx = self.config.rifx
     self.chunk = self.data['identifier'] + 4 * '\x00'
     sz = len(self.data['colors'])
     self.chunk += utils.py_int2word(sz, rifx)
     for model, palette, vals in self.data['colors']:
         self.chunk += utils.py_int2byte(model)
         self.chunk += utils.py_int2byte(palette)
         for val in vals:
             self.chunk += utils.py_int2byte(val)
     CmxRiffElement.update(self)
Beispiel #4
0
 def update_for_save(self):
     for child in self.childs:
         child.update_for_save()
     self.chunk = ''
     self.chunk += cpl_const.CPL12
     self.chunk += cpl_const.CPL12_NHEADERS
     size = len(self.name) * 2
     pos = [30, 31 + size, 31 + size + 2]
     for i in range(3):
         self.chunk += utils.py_int2dword(i) + utils.py_int2dword(pos[i])
     self.chunk += utils.py_int2byte(len(self.name))
     self.chunk += self.name.encode('utf_16_le')
     self.chunk += cpl_const.CPL12_PALTYPE
     self.chunk += utils.py_int2word(len(self.childs))
Beispiel #5
0
	def update_for_save(self):
		for child in self.childs:
			child.update_for_save()
		self.chunk = ''
		self.chunk += cpl_const.CPL12
		self.chunk += cpl_const.CPL12_NHEADERS
		size = len(self.name) * 2
		pos = [30, 31 + size, 31 + size + 2]
		for i in range(3):
			self.chunk += utils.py_int2dword(i) + utils.py_int2dword(pos[i])
		self.chunk += utils.py_int2byte(len(self.name))
		self.chunk += self.name.encode('utf_16_le')
		self.chunk += cpl_const.CPL12_PALTYPE
		self.chunk += utils.py_int2word(len(self.childs))
    def update(self):
        rifx = self.config.rifx
        int2word = utils.py_int2word
        self.chunk = '\x00\x00' + int2word(self.data['code'], rifx)
        self.chunk += utils.py_int2byte(self.data['style_flags'])
        skip = False
        flags = self.data['style_flags']
        # FILL
        if flags & cmx_const.INSTR_FILL_FLAG:
            self.chunk += int2word(self.data['fill_type'], rifx)
            if self.data['fill_type'] == cmx_const.INSTR_FILL_EMPTY:
                pass
            elif self.data['fill_type'] == cmx_const.INSTR_FILL_UNIFORM:
                # (color, screen)
                sig = '>hh' if rifx else '<hh'
                self.chunk += struct.pack(sig, *self.data['fill'])
            elif self.data['fill_type'] == cmx_const.INSTR_FILL_FOUNTAIN:
                sig = '>hhhihhhh' if rifx else '<hhhihhhh'
                self.chunk += struct.pack(sig, *self.data['fill'])
                sig = '>hh' if rifx else '<hh'
                for item in self.data['steps']:
                    self.chunk += struct.pack(sig, *item)
            else:
                skip = True

        if not skip:
            # OUTLINE
            if flags & cmx_const.INSTR_STROKE_FLAG:
                self.chunk += int2word(self.data['outline'], rifx)

            if not flags >= cmx_const.INSTR_LENS_FLAG:
                # POINTS
                self.chunk += int2word(len(self.data['points']), rifx)
                for point in self.data['points']:
                    sig = '>hh' if rifx else '<hh'
                    self.chunk += struct.pack(sig, *point)
                # NODES
                self.chunk += struct.pack('B' * len(self.data['nodes']),
                                          *self.data['nodes'])
                # BBOX
                sig = '>hhhh' if rifx else '<hhhh'
                self.chunk += struct.pack(sig, *self.data['bbox'])

        self.chunk += self.data['tail']
        CmxInstruction.update(self)
Beispiel #7
0
def builder(element_id, **kwargs):
    elf = cgm_model.element_factory
    header = params = ''
    if element_id == cgm_const.BEGIN_METAFILE:
        txt = kwargs.get('txt', 'Computer Graphics Metafile')
        params = utils.py_int2byte(len(txt)) + txt
        header = utils.py_int2word(0x0020 + len(params), True)
    elif element_id == cgm_const.END_METAFILE:
        header = '\x00\x40'
    elif element_id == cgm_const.METAFILE_VERSION:
        version = kwargs.get('version', 1)
        params = utils.py_int2word(version, True)
        header = '\x10\x22'
    elif element_id == cgm_const.METAFILE_DESCRIPTION:
        txt = kwargs.get('description', 'Created by UniConvertor')
        params = utils.py_int2byte(len(txt)) + txt
        header = '\x10\x5f' + utils.py_int2word(len(params), True)
    elif element_id == cgm_const.METAFILE_ELEMENT_LIST:
        header = '\x11\x66'
        params = '\x00\x01\xff\xff\x00\x01'
    elif element_id == cgm_const.VDC_TYPE:
        header = '\x10\x62'
        params = '\x00\x00'
    elif element_id == cgm_const.INTEGER_PRECISION:
        header = '\x10\x82'
        params = '\x00\x10'
    elif element_id == cgm_const.REAL_PRECISION:
        header = '\x10\xa6'
        params = '\x00\x00\x00\x09\x00\x17'
    elif element_id == cgm_const.INDEX_PRECISION:
        header = '\x10\xc2'
        params = '\x00\x08'
    elif element_id == cgm_const.COLOUR_PRECISION:
        header = '\x10\xe2'
        params = '\x00\x08'
    elif element_id == cgm_const.COLOUR_INDEX_PRECISION:
        header = '\x11\x02'
        params = '\x00\x08'
    # Page elements
    elif element_id == cgm_const.BEGIN_PICTURE:
        page_number = kwargs.get('page_number', 1)
        txt = 'Page %d' % page_number
        params = utils.py_int2byte(len(txt)) + txt
        header = '\x00' + utils.py_int2byte(len(params) + 0x60)
    elif element_id == cgm_const.BEGIN_PICTURE_BODY:
        header = '\x00\x80'
    elif element_id == cgm_const.END_PICTURE:
        header = '\x00\xa0'
    elif element_id == cgm_const.SCALING_MODE:
        header = '\x20\x26'
        params = '\x00\x01' + '\x3c\xd0\x13\xa9'
    elif element_id == cgm_const.COLOUR_SELECTION_MODE:
        header = '\x20\x42'
        params = '\x00\x01'
    elif element_id == cgm_const.LINE_WIDTH_SPECIFICATION_MODE:
        header = '\x20\x62'
        params = '\x00\x01'
    elif element_id == cgm_const.EDGE_WIDTH_SPECIFICATION_MODE:
        header = '\x20\xa2'
        params = '\x00\x01'
    elif element_id == cgm_const.VDC_EXTENT:
        bbox = kwargs.get('bbox', (0.0, 0.0, 1.0, 1.0))
        header = '\x20\xc8'
        params = ''.join([cgm_unit(val) for val in bbox])
    # Polyline
    elif element_id == cgm_const.LINE_WIDTH:
        header = '\x50\x64'
        val = kwargs.get('width', 2.5)
        params = utils.py_float2float(val, True)
    elif element_id == cgm_const.LINE_TYPE:
        header = '\x50\x42'
        dashes = tuple(kwargs.get('dashes', []))
        index = 0
        if dashes:
            index = cgm_const.LINE_DASHTABLE.index(dashes) + 1 \
                if dashes in cgm_const.LINE_DASHTABLE else 2
        params = utils.py_int2word(index, True)
    elif element_id == cgm_const.LINE_COLOUR:
        header = '\x50\x83'
        color = kwargs.get('color', (0, 0, 0))
        params = ''.join([utils.py_int2byte(item) for item in color])
    elif element_id == cgm_const.POLYLINE:
        points = kwargs.get('points', [(0, 0), (1, 1)])
        params = ''.join([cgm_unit(x) + cgm_unit(y) for x, y in points])
        header = '\x40\x3f' + utils.py_int2word(len(params), True)
    # Polygon
    elif element_id == cgm_const.INTERIOR_STYLE:
        empty = kwargs.get('empty', False)
        header = '\x52\xc2'
        params = '\x00\x00' if empty else '\x00\x01'
    elif element_id == cgm_const.FILL_COLOUR:
        header = '\x52\xe3'
        color = kwargs.get('color', (0, 0, 0))
        params = ''.join([utils.py_int2byte(item) for item in color])
    elif element_id == cgm_const.EDGE_VISIBILITY:
        header = '\x53\xc2'
        visible = kwargs.get('visible', True)
        params = '\x00\x01' if visible else '\x00\x00'
    elif element_id == cgm_const.EDGE_COLOUR:
        header = '\x52\xa3'
        color = kwargs.get('color', (0, 0, 0))
        params = ''.join([utils.py_int2byte(item) for item in color])
    elif element_id == cgm_const.EDGE_WIDTH:
        header = '\x53\x84'
        val = kwargs.get('width', 2.5)
        params = utils.py_float2float(val, True)
    elif element_id == cgm_const.EDGE_TYPE:
        header = '\x53\x61'
        dashes = tuple(kwargs.get('dashes', []))
        index = 0
        if dashes:
            index = cgm_const.LINE_DASHTABLE.index(dashes) + 1 \
                if dashes in cgm_const.LINE_DASHTABLE else 2
        params = utils.py_int2word(index, True)
    elif element_id == cgm_const.POLYGON:
        points = kwargs.get('points')
        if points:
            params = ''.join([cgm_unit(x) + cgm_unit(y) for x, y in points])
            header = '\x40\xff' + utils.py_int2word(len(params), True)
    elif element_id == cgm_const.POLYGON_SET:
        polygons = kwargs.get('polygons')
        params = ''
        for points in polygons:
            if points:
                end = '\x00\x03'
                if not points[0] == points[-1]:
                    points += [points[0]]
                    end = '\x00\x02'
                params += '\x00\x01'.join(
                    [cgm_unit(x) + cgm_unit(y) for x, y in points]) + end
        header = '\x41\x1f' + utils.py_int2word(len(params), True)

    if header:
        return elf(header, params)
Beispiel #8
0
 def update_for_save(self):
     self.chunk = utils.py_int2word(self.colorspace)
     self.chunk += self.valbytes
     self.chunk += utils.py_int2byte(len(self.name))
     self.chunk += self.name.encode('utf_16_le')
Beispiel #9
0
	def update_for_save(self):
		self.chunk = utils.py_int2word(self.colorspace)
		self.chunk += self.valbytes
		self.chunk += utils.py_int2byte(len(self.name))
		self.chunk += self.name.encode('utf_16_le')