diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-05-15 21:10:21 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-05-15 21:10:21 +0000 |
| commit | 91967d2ba3e1f30b1e6430196d01718994081f18 (patch) | |
| tree | 451930016657d607a069b16a55775f637accfa00 | |
| parent | Check code quality with clang-format-diff on merge requests (diff) | |
| download | inkscape-91967d2ba3e1f30b1e6430196d01718994081f18.tar.gz inkscape-91967d2ba3e1f30b1e6430196d01718994081f18.zip | |
Fis maren improvements to embed/import
| -rw-r--r-- | share/extensions/extractimage.inx | 1 | ||||
| -rwxr-xr-x | share/extensions/extractimage.py | 88 | ||||
| -rw-r--r-- | src/extension/internal/svg.cpp | 8 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 4 |
4 files changed, 62 insertions, 39 deletions
diff --git a/share/extensions/extractimage.inx b/share/extensions/extractimage.inx index 984dc9aef..9d1984168 100644 --- a/share/extensions/extractimage.inx +++ b/share/extensions/extractimage.inx @@ -4,6 +4,7 @@ <id>org.ekips.filter.extractimage</id> <dependency type="executable" location="extensions">extractimage.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> + <param name="selectedonly" type="boolean" _gui-text="Extract only selected images">True</param> <param name="filepath" type="string" _gui-text="Path to save image:">none</param> <_param name="desc" type="description" xml:space="preserve">* Don't type the file extension, it is appended automatically. * A relative path (or a filename without path) is relative to the user's home directory.</_param> diff --git a/share/extensions/extractimage.py b/share/extensions/extractimage.py index b30a326a7..fe70de433 100755 --- a/share/extensions/extractimage.py +++ b/share/extensions/extractimage.py @@ -21,17 +21,43 @@ import base64 import os # local library import inkex -import imghdr class MyEffect(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) self.OptionParser.add_option("--desc") + self.OptionParser.add_option("-s", "--selectedonly", + action="store", type="inkbool", + dest="selectedonly", default=True, + help="extract only selected images") self.OptionParser.add_option("--filepath", action="store", type="string", dest="filepath", default=None, help="") + def effect(self): + # if slectedonly is enabled and there is a selection only extractselected + # images. otherwise extract all images + if (self.options.selectedonly): + self.extractSelected(self.document, self.selected) + else: + self.extractAll(self.document) + + def extractSelected(self, document, selected): + self.document=document + self.selected=selected + if (self.options.ids): + for id, node in selected.iteritems(): + if node.tag == inkex.addNS('image','svg'): + self.extractImage(node) + + def extractAll(self, document): + self.document=document #not that nice... oh well + path = '//svg:image' + for node in self.document.getroot().xpath(path, namespaces=inkex.NSS): + self.extractImage(node) + + def extractImage(self, node): mimesubext={ 'png' : '.png', 'svg+xml' : '.svg', @@ -45,38 +71,34 @@ class MyEffect(inkex.Effect): # exbed the first embedded image path = self.options.filepath if (path != ''): - if (self.options.ids): - for id, node in self.selected.iteritems(): - if node.tag == inkex.addNS('image','svg'): - xlink = node.get(inkex.addNS('href','xlink')) - if (xlink[:4]=='data'): - comma = xlink.find(',') - if comma>0: - #get extension - fileext='' - semicolon = xlink.find(';') - if semicolon>0: - for sub in mimesubext.keys(): - if sub in xlink[5:semicolon].lower(): - fileext=mimesubext[sub] - path=path+fileext; - if (not os.path.isabs(path)): - if os.name == 'nt': - path = os.path.join(os.environ['USERPROFILE'],path) - else: - path = os.path.join(os.path.expanduser("~"),path) - break - #save - data = base64.decodestring(xlink[comma:]) - open(path,'wb').write(data) - if fileext == '.png' and imghdr.what(path) != 'png': - os.rename(path, path.replace(".png",".svg")) - path.replace(".png",".svg"); - inkex.errormsg(_('Image extracted to: %s') % path) - node.set(inkex.addNS('href','xlink'),os.path.realpath(path)) #absolute for making in-mem cycles work - else: - inkex.errormsg(_('Unable to find image data.')) - break + if node.tag == inkex.addNS('image','svg'): + xlink = node.get(inkex.addNS('href','xlink')) + if (xlink[:4]=='data'): + comma = xlink.find(',') + if comma>0: + #get extension + fileext='' + semicolon = xlink.find(';') + if semicolon>0: + for sub in mimesubext.keys(): + if sub in xlink[5:semicolon].lower(): + fileext=mimesubext[sub] + pathwext=path+fileext + if os.path.isfile(pathwext): + pathwext=path + "_" + node.get("id") +fileext + if (not os.path.isabs(pathwext)): + if os.name == 'nt': + pathwext = os.path.join(os.environ['USERPROFILE'],pathwext) + else: + pathwext = os.path.join(os.path.expanduser("~"),pathwext) + inkex.errormsg(_('Image extracted to: %s') % pathwext) + break + #save + data = base64.decodestring(xlink[comma:]) + open(pathwext,'wb').write(data) + node.set(inkex.addNS('href','xlink'),os.path.realpath(pathwext)) #absolute for making in-mem cycles work + else: + inkex.errormsg(_('Unable to find image data.')) if __name__ == '__main__': e = MyEffect() diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index 41fca734f..c4e12c174 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -137,10 +137,10 @@ Svg::init(void) "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("SVG Input") "</name>\n" "<id>" SP_MODULE_KEY_INPUT_SVG "</id>\n" - "<param name='link_svg' type='optiongroup' appearance='full' _gui-text='" N_("SVG Image Import Type:") "' _gui-description='" N_("Include SVG image as editable object(s) in the current file, Embed the SVG file in a image tag (not editable in this document) or Link the SVG file in a image tag (not editable in this document).") "' >\n" - "<_option value='include' >" N_("Include") "</_option>\n" - "<_option value='embed' >" N_("Embed") "</_option>\n" - "<_option value='link' >" N_("Link") "</_option>\n" + "<param name='link_svg' type='optiongroup' appearance='full' _gui-text='" N_("SVG Image Import Type:") "' >\n" + "<_option value='include' >" N_("Include SVG image as editable object(s) in the current file") "</_option>\n" + "<_option value='embed' >" N_("Embed the SVG file in a image tag (not editable in this document)") "</_option>\n" + "<_option value='link' >" N_("Link the SVG file in a image tag (not editable in this document).") "</_option>\n" "</param>\n" "<param name='scale' appearance='minimal' type='optiongroup' _gui-text='" N_("Image Rendering Mode:") "' _gui-description='" N_("When an image is upscaled, apply smoothing or keep blocky (pixelated). (Will not work in all browsers.)") "' >\n" "<_option value='auto' >" N_("None (auto)") "</_option>\n" diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 6b55da0da..ecf6204de 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -1559,14 +1559,14 @@ void InkscapePreferences::initPageBitmaps() Glib::ustring labels[] = {_("Embed"), _("Link")}; Glib::ustring values[] = {"embed", "link"}; _bitmap_link.init("/dialogs/import/link", labels, values, G_N_ELEMENTS(values), "link"); - _page_bitmaps.add_line( false, _("Bitmap link:"), _bitmap_link, "", "", false); + _page_bitmaps.add_line( false, _("Bitmap import/open mode:"), _bitmap_link, "", "", false); } { Glib::ustring labels[] = {_("Include"), _("Embed"), _("Link")}; Glib::ustring values[] = {"include", "embed", "link"}; _svg_link.init("/dialogs/import/link_svg", labels, values, G_N_ELEMENTS(values), "include"); - _page_bitmaps.add_line( false, _("SVG link:"), _svg_link, "", "", false); + _page_bitmaps.add_line( false, _("SVG import mode:"), _svg_link, "", "", false); } { |
