Exemplo n.º 1
0
 def update(self):
     rifx = self.config.rifx
     self.chunk = self.data['identifier'] + 4 * '\x00'
     sz = len(self.data['records'])
     self.chunk += '\x01\x00\x18\x00'
     self.chunk += utils.py_int2word(sz, rifx)
     for rec_id, offset in self.data['records']:
         self.chunk += utils.py_int2word(rec_id, rifx)
         self.chunk += utils.py_int2dword(offset, rifx)
     CmxRiffElement.update(self)
Exemplo n.º 2
0
 def update(self):
     rifx = self.config.rifx
     self.chunk = self.data['identifier'] + 4 * '\x00'
     sz = len(self.data['layers'])
     self.chunk += utils.py_int2word(sz, rifx)
     self.chunk += utils.py_int2word(self.data['page'], rifx)
     for offset, name in self.data['layers']:
         self.chunk += utils.py_int2dword(offset, rifx)
         self.chunk += utils.py_int2word(len(name), rifx)
         self.chunk += name + 4 * '\xff'
     CmxRiffElement.update(self)
Exemplo n.º 3
0
 def update(self):
     rifx = self.config.rifx
     self.chunk = self.data['identifier'] + 4 * '\x00'
     rec_sz = self.data['rec_sz']
     rec_sig = 4 * {2: 'H', 4: 'I', 8: 'Q'}.get(rec_sz / 4)
     sig = '>' + rec_sig if rifx else '<' + rec_sig
     self.chunk += utils.py_int2word(len(self.data['records']), rifx)
     if not self.config.v1:
         self.chunk += utils.py_int2word(rec_sz, rifx)
     for rec in self.data['records']:
         self.chunk += struct.pack(sig, *rec)
     CmxRiffElement.update(self)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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))
Exemplo n.º 8
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))
Exemplo n.º 9
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)
Exemplo n.º 10
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')
Exemplo n.º 11
0
 def update(self):
     size = self.get_chunk_size()
     sz = utils.py_int2word(size, self.config.rifx)
     self.chunk = sz + self._get_code_str() + self.chunk[4:]
Exemplo n.º 12
0
 def _get_code_str(self):
     return utils.py_int2word(self.data['code'], self.config.rifx)
Exemplo n.º 13
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')
Exemplo n.º 14
0
 def update(self):
     if self.is_padding():
         self.chunk += '\x00'
     size = len(self.chunk)
     sz = utils.py_int2word(size, self.config.rifx)
     self.chunk = sz + self._get_code_str() + self.chunk[4:]