dm2svg.py revision f745ff2339d2fc3e5d17164c3571e46b9196242a
'''
dm2svg.py - import a DHW file from ACECAD DigiMemo
Copyright (C) 2009 Kevin Lindsey, https://github.com/thelonious/DM2SVG
Copyright (C) 2011 Nikita Kitaev, https://github.com/nikitakit/DM2SVG
Copyright (C) 2011 Chris Morgan, https://gist.github.com/1471691
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
import struct
def process_file(filename):
try:
except IOError as e:
return
with f:
height = emit_header(f)
layer = 'layer1'
timestamp = 0
while True:
if tag == '':
break
if tag == '\x90':
# Emit the current element and close the last layer
emit_element('</g>')
# Start a new layer
timestamp = 0
elif tag == '\x88':
# Read the timestamp next
else:
# Emit the current svg element
coords = []
# Pen down
while True:
break
# Pen up
else:
# Emit the footer to finish it off
print '\n</svg>\n'
def read_point(f, ymax):
return x, ymax - y
def emit_header(f):
print '''
<svg viewBox="0 0 %(width)s %(height)s" fill="none" stroke="black" stroke-width="10" stroke-linecap="round" stroke-linejoin="round"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:dm="http://github.com/nikitakit/DM2SVG">
<metadata>
<dm:page
id="%(id)s"
version="%(version)s"
width="%(width)s"
height="%(height)s"
page_type="%(page_type)s">
</dm:page>
</metadata>
<rect width="%(width)s" height="%(height)s" fill="aliceblue"/>
''' % locals()
return height
def emit_element(message):
if message:
print '%s\n' % message
if __name__ == '__main__':
import sys
else:
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99