diff options
| author | Sebastian Wüst <sebi@timewaster.de> | 2013-10-12 19:39:52 +0000 |
|---|---|---|
| committer | Sebastian Wüst <sebi@timewaster.de> | 2013-10-12 19:39:52 +0000 |
| commit | 2bae41d2e7cac21f3b62f19bdc8a9e162ef3db48 (patch) | |
| tree | 677b6762ca3d3e47831aa880656ea5e033784e8e | |
| parent | small stuff (diff) | |
| download | inkscape-2bae41d2e7cac21f3b62f19bdc8a9e162ef3db48.tar.gz inkscape-2bae41d2e7cac21f3b62f19bdc8a9e162ef3db48.zip | |
finished new offset correction
(bzr r12417.1.18)
| -rw-r--r-- | share/extensions/hpgl_decoder.py | 40 | ||||
| -rw-r--r-- | share/extensions/hpgl_encoder.py | 37 |
2 files changed, 41 insertions, 36 deletions
diff --git a/share/extensions/hpgl_decoder.py b/share/extensions/hpgl_decoder.py index 3b8a86f6b..6843cca2a 100644 --- a/share/extensions/hpgl_decoder.py +++ b/share/extensions/hpgl_decoder.py @@ -2,7 +2,7 @@ # coding=utf-8
'''
Copyright (C) 2013 Sebastian Wüst, sebi@timewaster.de, http://www.timewasters-place.com/
-This importer supports the HP-GL commands only (More should not be necessary).
+This importer supports HP-GL commands only.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -55,7 +55,16 @@ class hpglDecoder: for i, command in enumerate(hpglData):
if command.strip() != '':
# TODO:2013-07-13:Sebastian Wüst:Implement all the HP-GL commands. (Or pass it as PLT to UniConverter when unknown commands are found?)
- if command[:2] == 'PU': # if Pen Up command
+ if command[:2] == 'IN': # if Initialize command, ignore
+ pass
+ elif command[:2] == 'SP': # if Select Pen command
+ actualLayer = command[2:]
+ self.createLayer(actualLayer)
+ elif command[:2] == 'AA': # if arc command
+ # a150,150 0 1,0 150,-150
+ path += ' A %f,%f,%d,%d,%d,%f,%f' % (150, 150, 0, 0, 0, 150, 150)
+ oldCoordinates = self.getParameters(command[2:])
+ elif command[:2] == 'PU': # if Pen Up command
if ' L ' in path:
self.addPathToLayer(path, actualLayer)
if self.options.showMovements and i != len(hpglData) - 1:
@@ -63,14 +72,10 @@ class hpglDecoder: path += ' L %f,%f' % self.getParameters(command[2:])
self.addPathToLayer(path, 0)
path = 'M %f,%f' % self.getParameters(command[2:])
+ oldCoordinates = self.getParameters(command[2:])
elif command[:2] == 'PD': # if Pen Down command
path += ' L %f,%f' % self.getParameters(command[2:])
oldCoordinates = self.getParameters(command[2:])
- elif command[:2] == 'IN': # if Initialize command, ignore
- pass
- elif command[:2] == 'SP': # if Select Pen command
- actualLayer = command[2:]
- self.createLayer(actualLayer)
else:
self.warnings.append('UNKNOWN_COMMANDS')
if ' L ' in path:
@@ -92,19 +97,14 @@ class hpglDecoder: return []
# remove command delimiter
parameterString = parameterString.replace(';', '').strip()
- # correct parameter delimiter
- parameterString = parameterString.replace(' ', ',')
- parameterString = parameterString.replace('+', ',')
- parameterString = parameterString.replace('-', ',-')
- while ',,' in parameterString:
- parameterString = parameterString.replace(',,', ',')
# split parameter
- parameterString = parameterString.split(',')
- return self.correctAbsoluteCoordinates(parameterString[0], parameterString[1])
-
- def correctAbsoluteCoordinates(self, x, y):
- x = float(x) / self.scaleX; # convert to pixels coordinate system
- y = self.options.docHeight - float(y) / self.scaleY; # convert to pixels coordinate system, flip vertically for inkscape coordinate system
- return (x, y)
+ parameter = parameterString.split(',')
+ # convert to svg coordinate system
+ parameter[0] = float(parameter[0]) / self.scaleX; # convert to pixels coordinate system
+ parameter[1] = self.options.docHeight - float(parameter[1]) / self.scaleY; # convert to pixels coordinate system, flip vertically for inkscape coordinate system
+ if len(parameter) == 2:
+ return (parameter[0], parameter[1])
+ elif len(parameter) == 3:
+ return (parameter[0], parameter[1], parameter[2])
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
\ No newline at end of file diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py index d08b297ae..d90493a11 100644 --- a/share/extensions/hpgl_encoder.py +++ b/share/extensions/hpgl_encoder.py @@ -205,11 +205,6 @@ class hpglEncoder: if self.vData[1][1] == -1.0:
self.storeData(self.vData[2][0], self.vData[2][1], self.vData[2][2])
else:
- # check if tool offset correction is needed (if the angle is big enough)
- if self.vData[2][0] == 'PD' and self.vData[3][0] == 'PD':
- if self.getAlpha(self.vData[1][1], self.vData[1][2], self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2]) > 3:
- self.storeData(self.vData[2][0], self.vData[2][1], self.vData[2][2])
- return
# perform tool offset correction (It's a *tad* complicated, if you want to understand it draw the data as lines on paper)
if self.vData[2][0] == 'PD': # If the 3rd entry in the cache is a pen down command make the line longer by the tool offset
pointThree = self.changeLength(self.vData[1][1], self.vData[1][2], self.vData[2][1], self.vData[2][2], self.options.toolOffset)
@@ -227,18 +222,17 @@ class hpglEncoder: if self.getLength(self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2]) >= self.options.toolOffset:
pointFour = self.changeLength(self.vData[3][1], self.vData[3][2], self.vData[2][1], self.vData[2][2], -self.options.toolOffset)
else:
- pointFour = self.changeLength(self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2], (self.options.toolOffset - self.getLength(self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2])))
- alpha1 = math.atan2(pointThree[1] - self.vData[2][2], pointThree[0] - self.vData[2][1])
- alpha2 = math.atan2(pointFour[1] - self.vData[2][2], pointFour[0] - self.vData[2][1])
- # TODO:2013-07-13:Sebastian Wüst:Fix that sucker! (number of points in the circle has to be calculated)
- step = 10
- #inkex.errormsg(str(alpha1) + ' | ' + str(alpha2))
- for alpha in range(int(step), 101, int(step)):
- alpha = alpha1 + alpha * (alpha2 - alpha1) / 100
- self.storeData('PD', self.vData[2][1] + math.cos(alpha) * self.options.toolOffset, self.vData[2][2] + math.sin(alpha) * self.options.toolOffset)
+ pointFour = self.changeLength(self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2],
+ (self.options.toolOffset - self.getLength(self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2])))
+ alpha = self.angleDiff(math.atan2(pointThree[1] - self.vData[2][2], pointThree[0] - self.vData[2][1]) * 57.295779,
+ math.atan2(pointFour[1] - self.vData[2][2], pointFour[0] - self.vData[2][1]) * 57.295779)
+ if alpha > 15.0:
+ self.storeData('AA', self.vData[2][1], self.vData[2][2], alpha - 10)
+ if alpha < -15.0:
+ self.storeData('AA', self.vData[2][1], self.vData[2][2], alpha + 10)
self.storeData('PD', pointFour[0], pointFour[1])
- def storeData(self, command, x, y):
+ def storeData(self, command, x, y, z="False"):
# store point
if self.dryRun:
if self.divergenceX == 'False' or x < self.divergenceX: self.divergenceX = x
@@ -249,6 +243,17 @@ class hpglEncoder: if not self.options.center:
if x < 0: x = 0 # only positive values are allowed (usually)
if y < 0: y = 0
- self.hpgl += '%s%d,%d;' % (command, x, y)
+ if z == "False":
+ self.hpgl += '%s%d,%d;' % (command, x, y)
+ else:
+ self.hpgl += '%s%d,%d,%d;' % (command, x, y, z)
+
+ def angleDiff(self, a1, a2):
+ diff = a2 - a1
+ if diff > 180:
+ diff -= 360
+ elif diff < -180:
+ diff += 360
+ return diff
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
\ No newline at end of file |
