fix different meta glitches
This commit is contained in:
@@ -2,31 +2,40 @@
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Ids To Text</name>
|
||||
<id>fablabchemnitz.de.ids_to_text</id>
|
||||
<param name="path_attribute" appearance="combo" gui-text="Path attribute to show:" type="optiongroup">
|
||||
<option value="id">Id</option>
|
||||
<option value="label">Label</option>
|
||||
<option value="fill">Fill color</option>
|
||||
<option value="stroke">Stroke color</option>
|
||||
<option value="width">Width</option>
|
||||
<option value="height">Height</option>
|
||||
</param>
|
||||
<param name="fontsize" type="int" min="1" max="1000" gui-text="Font size (px):">10</param>
|
||||
<param name="color" type="color" appearance="colorbutton" gui-text="Color (in hex)">255</param>
|
||||
<param name="font" type="string" gui-text="Font">Roboto</param>
|
||||
<param name="fontweight" appearance="combo" gui-text="Font Weight" type="optiongroup">
|
||||
<param name="color" type="color" appearance="colorbutton" gui-text="Text color:">255</param>
|
||||
<param name="font" type="string" gui-text="Font:">Roboto</param>
|
||||
<param name="fontweight" appearance="combo" gui-text="Font weight:" type="optiongroup">
|
||||
<option value="light">Light</option>
|
||||
<option value="normal">Normal</option>
|
||||
<option value="italic">Italic</option>
|
||||
<option value="medium">Medium</option>
|
||||
<option value="bold">Bold</option>
|
||||
</param>
|
||||
<param name="replaced" type="string" gui-text="Text to replace:"/>
|
||||
<param name="replacewith" type="string" gui-text="Replace with:"/>
|
||||
<param name="replaced" type="string" gui-text="Text to replace:" />
|
||||
<param name="replacewith" type="string" gui-text="Replace with:" />
|
||||
<param name="matchre" type="string" gui-text="Match regular expression:" />
|
||||
<param name="angle" type="float" min="-360" max="360" gui-text="Angle (°):">0</param>
|
||||
<param name="capitals" type="bool" gui-text="Capitalize all text">false</param>
|
||||
<param name="group" type="bool" gui-text="Group paths with the generated text elements">false</param>
|
||||
<label appearance="header">Help</label>
|
||||
<label>A simple Inkscape extension that lets you extract the ids from all selected paths and show them as elements inside the paths.
|
||||
Useful for when you want to have all paths' ids shown on the SVG document as text nodes.
|
||||
<label>Lets you extract the ids (or other attributes) from all selected paths and show them as text elements inside the paths.
|
||||
Examples and more info:</label>
|
||||
<label appearance="url">https://github.com/whiplashoo/ids_to_text_inkscape</label>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Various"/>
|
||||
</submenu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Various"/>
|
||||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
|
||||
@@ -16,36 +16,87 @@ class IdsToText(inkex.EffectExtension):
|
||||
pars.add_argument('--replacewith', default = '', help = 'Replace with this text')
|
||||
pars.add_argument('--angle', type = float, dest = 'angle', default = 0, help = 'Rotation angle')
|
||||
pars.add_argument('--capitals', type = inkex.Boolean, default = False, help = 'Capitalize')
|
||||
pars.add_argument('--path_attribute', default='id', help='Path attribute to show')
|
||||
pars.add_argument('--matchre', default='', help='Match regular expression')
|
||||
pars.add_argument('--group', type=inkex.Boolean, default=False, help='Group paths with generated text elements')
|
||||
|
||||
def extract_path_attribute(self, attr, node):
|
||||
ret = ''
|
||||
if attr == 'id':
|
||||
ret = node.get(attr)
|
||||
elif attr == 'label':
|
||||
value = node.get(attr)
|
||||
ret = str(value) if value else (node.get("inkscape:label") or "")
|
||||
elif attr == 'width':
|
||||
ret = format(node.bounding_box().width, '.2f')
|
||||
elif attr == 'height':
|
||||
ret = format(node.bounding_box().height, '.2f')
|
||||
elif attr == 'fill' or attr == 'stroke':
|
||||
if 'style' in node.attrib:
|
||||
style = node.attrib.get('style')
|
||||
style = dict(inkex.styles.Style.parse_str(style))
|
||||
if attr in style:
|
||||
ret = style.get(attr)
|
||||
elif attr in node.attrib:
|
||||
ret = node.attrib.get(attr)
|
||||
return ret
|
||||
|
||||
def effect(self):
|
||||
if len(self.svg.selected) == 0:
|
||||
if len(self.svg.selection.filter(inkex.PathElement)) == 0:
|
||||
inkex.errormsg("Please select some paths first.")
|
||||
exit()
|
||||
|
||||
for id, node in self.svg.selected.items():
|
||||
id = node.get('id')
|
||||
self.group = node.getparent().add(TextElement())
|
||||
csp = node.path.transform(node.composed_transform()).to_superpath()
|
||||
path_attribute = self.options.path_attribute
|
||||
is_text_attribute = path_attribute in ['id', 'label']
|
||||
for id, node in self.svg.selection.filter(inkex.PathElement).items():
|
||||
to_show = self.extract_path_attribute(path_attribute, node)
|
||||
|
||||
node.path.transform(node.composed_transform()).to_superpath()
|
||||
bbox = node.bounding_box()
|
||||
tx, ty = bbox.center
|
||||
anchor = 'middle'
|
||||
|
||||
node = self.group
|
||||
new = node.add(Tspan())
|
||||
new.set('sodipodi:role', 'line')
|
||||
s = {'text-align': 'center', 'vertical-align': 'bottom',
|
||||
'text-anchor': 'middle', 'font-size': str(self.options.fontsize) + 'px',
|
||||
'font-weight': self.options.fontweight, 'font-style': 'normal', 'font-family': self.options.font, 'fill': str(self.options.color)}
|
||||
new.set('style', str(inkex.Style(s)))
|
||||
new.set('dy', '0')
|
||||
if self.options.group:
|
||||
group_element = node.getparent().add(inkex.Group())
|
||||
group_element.add(node)
|
||||
group_element.set('id', node.get('id') + "_group")
|
||||
text_element = group_element.add(inkex.TextElement())
|
||||
else:
|
||||
text_element = node.getparent().add(inkex.TextElement())
|
||||
|
||||
if self.options.capitals:
|
||||
id = id.upper()
|
||||
tspan_element = text_element.add(inkex.Tspan())
|
||||
tspan_element.set('sodipodi:role', 'line')
|
||||
styles = {'text-align': 'center',
|
||||
'vertical-align': 'bottom',
|
||||
'text-anchor': 'middle',
|
||||
'font-size': str(self.options.fontsize) + 'px',
|
||||
'font-weight': self.options.fontweight,
|
||||
'font-style': 'normal',
|
||||
'font-family': self.options.font,
|
||||
'fill': str(self.options.color)
|
||||
}
|
||||
tspan_element.set('style', str(inkex.Style(styles)))
|
||||
tspan_element.set('dy', '0')
|
||||
|
||||
new.text = id.replace(self.options.replaced, self.options.replacewith)
|
||||
node.set('x', str(tx))
|
||||
node.set('y', str(ty))
|
||||
node.set('transform', 'rotate(%s, %s, %s)' % (-int(self.options.angle), tx, ty))
|
||||
if is_text_attribute:
|
||||
if self.options.capitals:
|
||||
to_show = to_show.upper()
|
||||
|
||||
if self.options.matchre != '':
|
||||
matches = re.findall(self.options.matchre, to_show)
|
||||
if len(matches) > 0:
|
||||
to_show = matches[0]
|
||||
|
||||
if self.options.replaced != '':
|
||||
to_show = to_show.replace(
|
||||
self.options.replaced, self.options.replacewith)
|
||||
|
||||
tspan_element.text = to_show
|
||||
tspan_element.set('id', node.get('id') + "_tspan")
|
||||
text_element.set('id', node.get('id') + "_text")
|
||||
text_element.set('x', str(tx))
|
||||
text_element.set('y', str(ty))
|
||||
text_element.set('transform', 'rotate(%s, %s, %s)' %
|
||||
(-int(self.options.angle), tx, ty))
|
||||
|
||||
if __name__ == '__main__':
|
||||
IdsToText().run()
|
||||
20
extensions/fablabchemnitz/ids_to_text/meta.json
Normal file
20
extensions/fablabchemnitz/ids_to_text/meta.json
Normal file
@@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"name": "Ids To Text",
|
||||
"id": "fablabchemnitz.de.ids_to_text",
|
||||
"path": "ids_to_text",
|
||||
"original_name": "Ids To Text",
|
||||
"original_id": "org.inkscape.render.ids_to_text",
|
||||
"license": "GNU GPL v3",
|
||||
"license_url": "https://github.com/whiplashoo/ids_to_text_inkscape/blob/master/LICENSE",
|
||||
"comment": "",
|
||||
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/ids_to_text",
|
||||
"fork_url": "https://github.com/whiplashoo/ids_to_text_inkscape",
|
||||
"documentation_url": "https://stadtfabrikanten.org/display/IFM/Ids+To+Text",
|
||||
"inkscape_gallery_url": null,
|
||||
"main_authors": [
|
||||
"github.com/whiplashoo",
|
||||
"github.com/vmario89"
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user