diff options
| author | Alvin Penner <penner@vaxxine.com> | 2013-06-11 20:45:58 +0000 |
|---|---|---|
| committer | apenner <penner@vaxxine.com> | 2013-06-11 20:45:58 +0000 |
| commit | d2f98829fb2bc1e667ce1823d43e5b9bf50a2a29 (patch) | |
| tree | 4f2dfbbef0ade15385904fe95b725a2eb6d61df5 | |
| parent | Fix new bug with No-Marker having no icon, use Stock GTK::Remove icon for No-... (diff) | |
| download | inkscape-d2f98829fb2bc1e667ce1823d43e5b9bf50a2a29.tar.gz inkscape-d2f98829fb2bc1e667ce1823d43e5b9bf50a2a29.zip | |
extensions. hpgl input. new import routine by TimeWaster
Fixed bugs:
- https://launchpad.net/bugs/1159641
(bzr r12365)
| -rw-r--r-- | share/extensions/Makefile.am | 2 | ||||
| -rw-r--r-- | share/extensions/hpgl_input.inx | 19 | ||||
| -rw-r--r-- | share/extensions/hpgl_input.py | 113 |
3 files changed, 134 insertions, 0 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index ee6bd0ea3..5a600be79 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -74,6 +74,7 @@ extensions = \ guides_creator.py \ guillotine.py \ handles.py \ + hpgl_input.py \ hpgl_output.py \ ill2svg.pl \ ink2canvas.py \ @@ -262,6 +263,7 @@ modules = \ guides_creator.inx \ guillotine.inx \ handles.inx \ + hpgl_input.inx \ hpgl_output.inx \ ink2canvas.inx \ inkscape_follow_link.inx \ diff --git a/share/extensions/hpgl_input.inx b/share/extensions/hpgl_input.inx new file mode 100644 index 000000000..0d8cad158 --- /dev/null +++ b/share/extensions/hpgl_input.inx @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>HPGL Input</_name> + <id>org.inkscape.input.hpgl</id> + <dependency type="executable" location="extensions">hpgl_input.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <param name="resolutionX" type="float" min="1.0" max="4096.0" precision="1" _gui-text="Resolution X (dpi)" _gui-description="The amount of steps in one inch on the X axis (Default: 1016.0)">1016.0</param> + <param name="resolutionY" type="float" min="1.0" max="4096.0" precision="1" _gui-text="Resolution Y (dpi)" _gui-description="The amount of steps in one inch on the Y axis (Default: 1016.0)">1016.0</param> + <param name="showMovements" type="boolean" _gui-text="Show Movements between paths" _gui-description="Show movements between paths in a different color (Default: Un-checked)">false</param> + <input> + <extension>.hpgl</extension> + <mimetype>image/hpgl</mimetype> + <_filetypename>HP Graphics Language file (*.hpgl)</_filetypename> + <_filetypetooltip>Import HP Graphics Language file</_filetypetooltip> + </input> + <script> + <command reldir="extensions" interpreter="python">hpgl_input.py</command> + </script> +</inkscape-extension> diff --git a/share/extensions/hpgl_input.py b/share/extensions/hpgl_input.py new file mode 100644 index 000000000..d20b344f5 --- /dev/null +++ b/share/extensions/hpgl_input.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# coding=utf-8 +''' +hpgl_input.py - input a HP Graphics Language file + +Copyright (C) 2013 Sebastian Wüst, sebi@timewaster.de, http://www.timewasters-place.com/ + +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 +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 library +from StringIO import StringIO +# local library +import inkex + +inkex.localize() + +# parse options +parser = inkex.optparse.OptionParser(usage="usage: %prog [options] HPGLfile", option_class=inkex.InkOption) +parser.add_option("-a", "--resolutionX", + action="store", type="float", + dest="resolutionX", default=1016.0, + help="Resolution X (dpi)") +parser.add_option("-b", "--resolutionY", + action="store", type="float", + dest="resolutionY", default=1016.0, + help="Resolution Y (dpi)") +parser.add_option("-c", "--showMovements", + action="store", type="inkbool", + dest="showMovements", default="FALSE", + help="Show Movements between paths") +(options, args) = parser.parse_args(inkex.sys.argv[1:]) + +# global vars +scaleX = options.resolutionX / 90.0 # dots/inch to dots/pixels +scaleY = options.resolutionY / 90.0 # dots/inch to dots/pixels +documentWidth = 210.0 * 3.5433070866 # 210mm to pixels +documentHeight = 297.0 * 3.5433070866 # 297mm to pixels +hasUnknownCommands = False + +def getData(file): + # read file (read only one line, there should not be more than one line) + stream = open(file, 'r') + data = stream.readline().strip() + data = data.split(';') + if len(data) < 2: + inkex.errormsg(_("No HPGL data found.")) + return False + if data[-1].strip() == '': + data.pop() + return data + +def getCoordinates(coord): + # process coordinates + (x, y) = coord.split(',') + x = float(x) / scaleX; # convert to pixels coordinate system + y = documentHeight - float(y) / scaleY; # convert to pixels coordinate system + return (x, y) + +# prepare document +doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="%s" height="%s"></svg>' % (documentWidth, documentHeight))) +layerDrawing = inkex.etree.SubElement(doc.getroot(), 'g', {inkex.addNS('groupmode','inkscape'):'layer', inkex.addNS('label','inkscape'):'Drawing'}) +if options.showMovements: + layerMovements = inkex.etree.SubElement(doc.getroot(), 'g', {inkex.addNS('groupmode','inkscape'):'layer', inkex.addNS('label','inkscape'):'Movements'}) + +# load data +data = getData(args[0]) +if data != False: + # parse paths + oldCoordinates = (0.0, documentHeight) + path = '' + for i, command in enumerate(data): + if command.strip() != '': + if command[:2] == 'PU': # if Pen Up command + if " L" in path: + inkex.etree.SubElement(layerDrawing, 'path', {'d':path, 'style':'stroke:#000000; stroke-width:0.2; fill:none;'}) + if options.showMovements and i != len(data) - 1: + path = 'M %f,%f' % oldCoordinates + path += ' L %f,%f' % getCoordinates(command[2:]) + inkex.etree.SubElement(layerMovements, 'path', {'d':path, 'style':'stroke:#ff0000; stroke-width:0.2; fill:none;'}) + path = 'M %f,%f' % getCoordinates(command[2:]) + elif command[:2] == 'PD': # if Pen Down command + path += ' L %f,%f' % getCoordinates(command[2:]) + oldCoordinates = getCoordinates(command[2:]) + elif command[:2] == 'IN': # if Initialize command + pass + elif command[:2] == 'SP': # if Select Pen command + pass + else: + hasUnknownCommands = True + if " L" in path: + inkex.etree.SubElement(layerDrawing, 'path', {'d':path, 'style':'stroke:#000000; stroke-width:0.2; fill:none;'}) + +# deliver document to inkscape +doc.write(inkex.sys.stdout) + +# issue warning if unknown commands where found +if hasUnknownCommands: + inkex.errormsg(_("The HPGL data contained unknown (unsupported) commands, there is a possibility that the drawing is missing some content.")) + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 |
