hpgl_decoder.py revision b584ec166ed0f23e1460e3ad88e8a2511ad85975
# coding=utf-8
'''
Copyright (C) 2013 Sebastian Wüst, sebi@timewaster.de
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
'''
# standard libraries
import math
# local library
import inkex
# TODO: Unittests
class hpglDecoder:
''' options:
"resolutionX":float
"resolutionY":float
"showMovements":bool
"docWidth":float
"docHeight":float
'''
# prepare document
self.doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="%s" height="%s"></svg>' %
actualLayer = 0
self.layers[0] = inkex.etree.SubElement(self.doc.getroot(), 'g', {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): self.textMovements})
# parse paths
raise Exception('NO_HPGL_DATA')
path = ''
# if Initialize, force or speed command, ignore
pass
# if Select Pen command
# if Pen Up command
if ' L ' in path:
# if Pen Down command
if i % 2 == 0:
else:
else:
if ' L ' in path:
try:
except KeyError:
{inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): self.textPenNumber + layerNumber})
lineColor = '000000'
if layerNumber == 0:
lineColor = 'ff0000'
inkex.etree.SubElement(self.layers[layerNumber], 'path', {'d': path, 'style': 'stroke:#' + lineColor + '; stroke-width:0.4; fill:none;'})
# process coordinates
return []
# remove command delimiter
# split parameter
# convert to svg coordinate system and return
return (float(parameter[0]) / self.scaleX, self.options.docHeight - (float(parameter[1]) / self.scaleY))
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99