0
|
1 |
#!/usr/bin/env python
|
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
|
|
4 |
##############################################################################
|
|
5 |
# miffile.py - Symbian OS multi-image format (MIF) utilities
|
|
6 |
# Copyright 2006, 2007 Jussi Ylänen
|
|
7 |
#
|
|
8 |
# This file is part of Ensymble developer utilities for Symbian OS(TM).
|
|
9 |
#
|
|
10 |
# Ensymble is free software; you can redistribute it and/or modify
|
|
11 |
# it under the terms of the GNU General Public License as published by
|
|
12 |
# the Free Software Foundation; either version 2 of the License, or
|
|
13 |
# (at your option) any later version.
|
|
14 |
#
|
|
15 |
# Ensymble is distributed in the hope that it will be useful,
|
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
# GNU General Public License for more details.
|
|
19 |
#
|
|
20 |
# You should have received a copy of the GNU General Public License
|
|
21 |
# along with Ensymble; if not, write to the Free Software
|
|
22 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
23 |
##############################################################################
|
|
24 |
|
|
25 |
import struct
|
|
26 |
|
|
27 |
|
|
28 |
##############################################################################
|
|
29 |
# MIFWriter class for grouping SVG-T items into MIF files
|
|
30 |
##############################################################################
|
|
31 |
|
|
32 |
class MIFWriter(object):
|
|
33 |
'''A MIF file generator
|
|
34 |
|
|
35 |
Limitations:
|
|
36 |
|
|
37 |
- MBM file linkage is not supported.
|
|
38 |
- Flags and other unknown fields are filled with guessed values.'''
|
|
39 |
|
|
40 |
def __init__(self):
|
|
41 |
self.fileinfo = []
|
|
42 |
self.filedata = []
|
|
43 |
|
|
44 |
def addfile(self, contents, animate = False):
|
|
45 |
self.filedata.append(contents)
|
|
46 |
self.fileinfo.append((animate and 1) or 0)
|
|
47 |
|
|
48 |
def tostring(self):
|
|
49 |
# Generate header.
|
|
50 |
strdata = ["B##4", struct.pack("<LLL", 2, 16, len(self.filedata) * 2)]
|
|
51 |
|
|
52 |
# Generate indexes.
|
|
53 |
offset = 16 + 16 * len(self.filedata)
|
|
54 |
for n in xrange(len(self.filedata)):
|
|
55 |
clen = len(self.filedata[n]) + 32 # Including header length
|
|
56 |
strdata.append(struct.pack("<LLLL", offset, clen, offset, clen))
|
|
57 |
offset += clen
|
|
58 |
|
|
59 |
# Generate contents.
|
|
60 |
for n in xrange(len(self.filedata)):
|
|
61 |
clen = len(self.filedata[n]) # Not including header length
|
|
62 |
strdata.append("C##4")
|
|
63 |
strdata.append(struct.pack("<LLLLLLL", 1, 32, clen,
|
|
64 |
1, 0, self.fileinfo[n], 0))
|
|
65 |
strdata.append(self.filedata[n])
|
|
66 |
|
|
67 |
# TODO: Ineffiecient. Improve.
|
|
68 |
return "".join(strdata)
|