From 70ffb2b72fc97c269e25509f17b72893276bce1d Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Mon, 19 Apr 2021 22:07:01 +0200 Subject: [PATCH] fixes in filter layer, added guide support for migrategroups --- .settings/org.eclipse.core.resources.prefs | 2 + extensions/fablabchemnitz/cleanup_styles.py | 4 +- .../contourscanner/contour_scanner.py | 8 +-- extensions/fablabchemnitz/filter_layer.py | 16 +++-- extensions/fablabchemnitz/migrategroups.inx | 7 ++- extensions/fablabchemnitz/migrategroups.py | 61 ++++++++++--------- 6 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 .settings/org.eclipse.core.resources.prefs diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..e1acb01e --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//extensions/fablabchemnitz/create_links.py=utf-8 diff --git a/extensions/fablabchemnitz/cleanup_styles.py b/extensions/fablabchemnitz/cleanup_styles.py index 5ce29d0a..5e5911b2 100644 --- a/extensions/fablabchemnitz/cleanup_styles.py +++ b/extensions/fablabchemnitz/cleanup_styles.py @@ -55,8 +55,8 @@ class Cleanup(inkex.EffectExtension): if len(self.svg.selected) == 0: self.getAttribs(self.document.getroot()) else: - for id, node in self.svg.selected.items(): - self.getAttribs(node) + for element in self.svg.selected.values(): + self.getAttribs(element) #finally remove the styles from collected groups (if enabled) if self.options.remove_group_styles is True: for group in self.groups: diff --git a/extensions/fablabchemnitz/contourscanner/contour_scanner.py b/extensions/fablabchemnitz/contourscanner/contour_scanner.py index c90024e7..8ab0bb41 100644 --- a/extensions/fablabchemnitz/contourscanner/contour_scanner.py +++ b/extensions/fablabchemnitz/contourscanner/contour_scanner.py @@ -289,16 +289,16 @@ class ContourScanner(inkex.EffectExtension): self.scanContours(self.document.getroot()) else: newContourSet = [] - for id, item in self.svg.selected.items(): - self.breakContours(item) + for element in self.svg.selected.items(): + self.breakContours(element) for newContours in self.replacedNodes: self.scanContours(newContours) else: if len(self.svg.selected) == 0: self.scanContours(self.document.getroot()) else: - for id, item in self.svg.selected.items(): - self.scanContours(item) + for element in self.svg.selected.values(): + self.scanContours(element) if __name__ == '__main__': ContourScanner().run() \ No newline at end of file diff --git a/extensions/fablabchemnitz/filter_layer.py b/extensions/fablabchemnitz/filter_layer.py index 373cb8af..a04dd813 100644 --- a/extensions/fablabchemnitz/filter_layer.py +++ b/extensions/fablabchemnitz/filter_layer.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 ''' -This extension adds or removes filters to current layer +This extension adds filters to current layer or removes filters from current layer Copyright (C) 2012 Jabiertxo Arraiza, jabier.arraiza@marker.es @@ -37,15 +37,11 @@ class FilterAndLiveEffectsLayer(inkex.EffectExtension): pars.add_argument('--type', default = 'Add', help = 'Add or remove filters to current layer') def selectTop(self): - selected = [] selectedSorted = None if self.svg.selected is not None: - for id, node in self.svg.selected.items(): - selected.append(id) - for node in self.document.getroot().iter(): - idNode = node.get("id") - if idNode in selected: - selectedSorted = node + for element in self.document.getroot().iter(): + if element.get("id") in self.svg.selection: + selectedSorted = element return selectedSorted def effect(self): @@ -56,7 +52,8 @@ class FilterAndLiveEffectsLayer(inkex.EffectExtension): idLayer = namedview[0].get('{http://www.inkscape.org/namespaces/inkscape}current-layer'); xpathStr = '//svg:g[@id="'+idLayer+'"]' layer = svg.xpath(xpathStr, namespaces=inkex.NSS) - if typeOperation == "Add": + + if typeOperation == "Add": #Add action element = self.selectTop() if element is not None: if element.get('style'): @@ -74,6 +71,7 @@ class FilterAndLiveEffectsLayer(inkex.EffectExtension): layer[0].set('style',filter) else: inkex.utils.debug("Nothing selected") + else: #Remove action if layer[0].get('style'): matchObj = re.search( r'filter:url\(#.*?[^\)]\)', layer[0].get('style'), re.M|re.I) diff --git a/extensions/fablabchemnitz/migrategroups.inx b/extensions/fablabchemnitz/migrategroups.inx index aa9a28fc..3a735d28 100644 --- a/extensions/fablabchemnitz/migrategroups.inx +++ b/extensions/fablabchemnitz/migrategroups.inx @@ -45,12 +45,13 @@ true true true + true true true + + + true - - - true true true diff --git a/extensions/fablabchemnitz/migrategroups.py b/extensions/fablabchemnitz/migrategroups.py index 6caee6f6..ca53b7db 100644 --- a/extensions/fablabchemnitz/migrategroups.py +++ b/extensions/fablabchemnitz/migrategroups.py @@ -39,6 +39,7 @@ class MigrateGroups(inkex.EffectExtension): pars.add_argument("--defs", type=inkex.Boolean, default=True) pars.add_argument("--ellipse", type=inkex.Boolean, default=True) pars.add_argument("--image", type=inkex.Boolean, default=True) + pars.add_argument("--guide", type=inkex.Boolean, default=True) pars.add_argument("--line", type=inkex.Boolean, default=True) pars.add_argument("--path", type=inkex.Boolean, default=True) pars.add_argument("--polyline", type=inkex.Boolean, default=True) @@ -69,35 +70,37 @@ class MigrateGroups(inkex.EffectExtension): namespace = [] #a list of selected types we are going to process for filtering (dropping items) #namespace.append("{http://www.w3.org/2000/svg}sodipodi") if self.options.sodipodi else "" #do not do this. it will crash InkScape #namespace.append("{http://www.w3.org/2000/svg}svg") if self.options.svg else "" #we handle svg:svg the same type like svg:g - namespace.append("{http://www.w3.org/2000/svg}circle") if self.options.circle else "" - namespace.append("{http://www.w3.org/2000/svg}clipPath") if self.options.clipPath else "" - namespace.append("{http://www.w3.org/2000/svg}defs") if self.options.defs else "" - namespace.append("{http://www.w3.org/2000/svg}ellipse") if self.options.ellipse else "" - namespace.append("{http://www.w3.org/2000/svg}image") if self.options.image else "" - namespace.append("{http://www.w3.org/2000/svg}line") if self.options.line else "" - namespace.append("{http://www.w3.org/2000/svg}polygon") if self.options.polygon else "" - namespace.append("{http://www.w3.org/2000/svg}path") if self.options.path else "" - namespace.append("{http://www.w3.org/2000/svg}polyline") if self.options.polyline else "" - namespace.append("{http://www.w3.org/2000/svg}rect") if self.options.rect else "" - namespace.append("{http://www.w3.org/2000/svg}text") if self.options.text else "" - namespace.append("{http://www.w3.org/2000/svg}tspan") if self.options.tspan else "" - namespace.append("{http://www.w3.org/2000/svg}linearGradient") if self.options.linearGradient else "" - namespace.append("{http://www.w3.org/2000/svg}radialGradient") if self.options.radialGradient else "" - namespace.append("{http://www.w3.org/2000/svg}meshGradient") if self.options.meshGradient else "" - namespace.append("{http://www.w3.org/2000/svg}meshRow") if self.options.meshRow else "" - namespace.append("{http://www.w3.org/2000/svg}meshPatch") if self.options.meshPatch else "" - namespace.append("{http://www.w3.org/2000/svg}script") if self.options.script else "" - namespace.append("{http://www.w3.org/2000/svg}symbol") if self.options.symbol else "" - namespace.append("{http://www.w3.org/2000/svg}mask") if self.options.mask else "" - namespace.append("{http://www.w3.org/2000/svg}metadata") if self.options.metadata else "" - namespace.append("{http://www.w3.org/2000/svg}stop") if self.options.stop else "" - namespace.append("{http://www.w3.org/2000/svg}switch") if self.options.switch else "" - namespace.append("{http://www.w3.org/2000/svg}use") if self.options.use else "" - namespace.append("{http://www.w3.org/2000/svg}flowRoot") if self.options.flowRoot else "" - namespace.append("{http://www.w3.org/2000/svg}flowRegion") if self.options.flowRegion else "" - namespace.append("{http://www.w3.org/2000/svg}flowPara") if self.options.flowPara else "" - namespace.append("{http://www.w3.org/2000/svg}marker") if self.options.marker else "" - namespace.append("{http://www.w3.org/2000/svg}pattern") if self.options.pattern else "" + namespace.append("{http://www.w3.org/2000/svg}circle") if self.options.circle else "" + namespace.append("{http://www.w3.org/2000/svg}clipPath") if self.options.clipPath else "" + namespace.append("{http://www.w3.org/2000/svg}defs") if self.options.defs else "" + namespace.append("{http://www.w3.org/2000/svg}ellipse") if self.options.ellipse else "" + namespace.append("{http://www.w3.org/2000/svg}image") if self.options.image else "" + namespace.append("{http://www.w3.org/2000/svg}line") if self.options.line else "" + namespace.append("{http://www.w3.org/2000/svg}polygon") if self.options.polygon else "" + namespace.append("{http://www.w3.org/2000/svg}path") if self.options.path else "" + namespace.append("{http://www.w3.org/2000/svg}polyline") if self.options.polyline else "" + namespace.append("{http://www.w3.org/2000/svg}rect") if self.options.rect else "" + namespace.append("{http://www.w3.org/2000/svg}text") if self.options.text else "" + namespace.append("{http://www.w3.org/2000/svg}tspan") if self.options.tspan else "" + namespace.append("{http://www.w3.org/2000/svg}linearGradient") if self.options.linearGradient else "" + namespace.append("{http://www.w3.org/2000/svg}radialGradient") if self.options.radialGradient else "" + namespace.append("{http://www.w3.org/2000/svg}meshGradient") if self.options.meshGradient else "" + namespace.append("{http://www.w3.org/2000/svg}meshRow") if self.options.meshRow else "" + namespace.append("{http://www.w3.org/2000/svg}meshPatch") if self.options.meshPatch else "" + namespace.append("{http://www.w3.org/2000/svg}script") if self.options.script else "" + namespace.append("{http://www.w3.org/2000/svg}symbol") if self.options.symbol else "" + namespace.append("{http://www.w3.org/2000/svg}mask") if self.options.mask else "" + namespace.append("{http://www.w3.org/2000/svg}metadata") if self.options.metadata else "" + namespace.append("{http://www.w3.org/2000/svg}stop") if self.options.stop else "" + namespace.append("{http://www.w3.org/2000/svg}switch") if self.options.switch else "" + namespace.append("{http://www.w3.org/2000/svg}use") if self.options.use else "" + namespace.append("{http://www.w3.org/2000/svg}flowRoot") if self.options.flowRoot else "" + namespace.append("{http://www.w3.org/2000/svg}flowRegion") if self.options.flowRegion else "" + namespace.append("{http://www.w3.org/2000/svg}flowPara") if self.options.flowPara else "" + namespace.append("{http://www.w3.org/2000/svg}marker") if self.options.marker else "" + namespace.append("{http://www.w3.org/2000/svg}pattern") if self.options.pattern else "" + namespace.append("{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}guide") if self.options.guide else "" + #self.msg(namespace) #in case the user made a manual selection instead of whole document parsing, we need to collect all required elements first