added glyph_ids, enhancements in bounding box

This commit is contained in:
Mario Voigt 2021-10-16 00:50:17 +02:00
parent 2cdd7466d0
commit e423e1e7ea
8 changed files with 217 additions and 2 deletions

View File

@ -1,6 +1,6 @@
# MightyScape for Inkscape 1.0+
In short: A maintained extension collection for Inkscape 1.0+, working on Windows and Linux. There are **220 extension folders** with **386 .inx files** inside. We also take part at https://inkscape.org/gallery/=extension/ (with single extension uploads).
In short: A maintained extension collection for Inkscape 1.0+, working on Windows and Linux. There are **221 extension folders** with **388 .inx files** inside. We also take part at https://inkscape.org/gallery/=extension/ (with single extension uploads).
# About MightyScape

View File

@ -3,8 +3,9 @@
<name>Bounding Box</name>
<id>fablabchemnitz.de.bounding_box</id>
<label>Draws bounding boxes around selected objects, useful for debugging. Author: Pawel Mosakowski. Modded by Mario Voigt.</label>
<param min="-10000.0" max="10000.0" name="offset" type="float" gui-text="Offset from object (all directions)">0.0</param>
<param name="offset" min="-10000.000" max="10000.000" precision="3" type="float" gui-text="Offset from object (all directions)">0.000</param>
<param name="box" type="bool" gui-text="Draw boxes">true</param>
<param name="corner_radius" type="float" min="0.000" precision="3" max="10000.000" gui-text="Corner radius" gui-description="Only applies for box type">0.000</param>
<param name="circle" type="bool" gui-text="Draw circles">false</param>
<param name="split" type="bool" gui-text="Handle selection as group">true</param>
<effect>

View File

@ -9,6 +9,7 @@ class BoundingBox(inkex.EffectExtension):
def add_arguments(self, pars):
pars.add_argument('--offset', type=float, default=0.0, help='Offset from object (all directions)')
pars.add_argument('--box', type=inkex.Boolean, default=0.0, help='Draw boxes')
pars.add_argument('--corner_radius', type=float, default=0.0, help='Corner radius')
pars.add_argument('--circle', type=inkex.Boolean, default=0.0, help='Draw circles')
pars.add_argument('--split', type = inkex.Boolean, default = True, help = 'Handle selection as group')
@ -20,6 +21,8 @@ class BoundingBox(inkex.EffectExtension):
'y' : str(bbox.top - self.options.offset),
'width' : str(bbox.width + 2 * self.options.offset),
'height': str(bbox.height + 2 * self.options.offset),
'ry' : str(self.options.corner_radius),
'rx' : str(self.options.corner_radius)
}
etree.SubElement(self.svg.get_current_layer(), inkex.addNS('rect','svg'), attribs)

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Glyph IDs - Get</name>
<id>fablabchemnitz.de.glyph_ids.get_glyph_ids</id>
<param type="notebook" name="tab">
<page name="getGlyphIDs" gui-text="Glyph IDs - Get">
<label>Get all glyph ids (all path ids in layer with id = glyph) and combine to a string.</label>
<label>This string will be saved into a text element in a new layer 'glyphIds'.</label>
<label>Use this string when setting the ids (Glyph IDs - set) before generating your new font as the ids might get lost during path operations</label>
</page>
<page name="help" gui-text="Information">
<label xml:space="preserve">
For more information:
https://gitlab.com/EllenWasbo/inkscape-extension-getsetGlyphIDs
and
http://cutlings.wasbo.net/inkscape-extension-automate-glyph-ids/</label>
</page>
</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Text" />
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">get_glyph_ids.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,66 @@
#!/usr/bin/env python3
#
# Copyright (C) 2020 Ellen Wasboe, ellen@wasbo.net
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Get path ids of all selected paths should be of all paths in "Glyphs" layer
Put all ids into a continueous string (no separation character) and paste as text element in layer Ids at position x 0 y 0.
Paths are sorted by left bounding box.
Intention:
to quickly retrieve all path-ids of the glyph-paths when using the Custom Stroke Font extension to edit a existing svg font https://github.com/Shriinivas/inkscapestrokefont
this string of ids can then be used to set ids using setIds.py as ids might be lost in different path operations. https://gitlab.com/EllenWasbo/inkscape-extension-setIds
"""
import inkex
from inkex import Group, TextElement
class getGlyphIDs(inkex.EffectExtension):
def add_arguments(self, pars):
pars.add_argument("--tab", default="getGlyphIDs")
def effect(self):
if self.svg.getElementById('glyph') == None:
raise inkex.AbortExtension("Could not find layer Glyphs (id=glyphs)")
else:
txtElem=TextElement()
if self.svg.getElementById('glyphIds') == None:
txtLayer=self.svg.add(Group.new('glyphIds'))#, is_layer=True))
txtLayer.set('id','glyphIds')
txtLayer.set('inkscape:groupmode','layer')
txtLayer.style={'display':'inline'}
else:
txtLayer=self.svg.getElementById('glyphIds')
if self.svg.getElementById('txtGlyphIds') == None:
txt=txtLayer.add(txtElem)
txt.style={'font-size': '20px','letter-spacing': '2px','fill': '#000000','fill-opacity': 1,'stroke': 'none'}
txt.set('id','txtGlyphIds')
else:
txt=self.svg.getElementById('txtGlyphIds')
idArr=''
for elem in self.svg.getElementById('glyph'):
idArr=idArr+elem.get('id')
txt.text = idArr
if __name__ == '__main__':
getGlyphIDs().run()

View File

@ -0,0 +1,20 @@
[
{
"name": "Glyph IDs - <various>",
"id": "fablabchemnitz.de.glyph_ids.<various>",
"path": "Glyph IDs - <various>",
"original_name": "<various>",
"original_id": "EllenWasbo.cutlings.",
"license": "GNU GPL v2",
"license_url": "https://gitlab.com/EllenWasbo/inkscape-extension-getsetGlyphIDs/-/blob/master/getGlyphIDs.py",
"comment": "",
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/glyph_ids",
"fork_url": "https://gitlab.com/EllenWasbo/inkscape-extension-getsetGlyphID",
"documentation_url": "https://stadtfabrikanten.org/display/IFM/Glyph+IDs",
"inkscape_gallery_url": null,
"main_authors": [
"gitlab.com/EllenWasbo",
"github.com/vmario89"
]
}
]

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Glyph IDs - Set</name>
<id>fablabchemnitz.de.glyph_ids.set_glyph_ids</id>
<param type="notebook" name="tab">
<page name="setGlyphIDs" gui-text="Glyph IDs - set">
<label>Id for each selected path will be set to one single character within the given string below.</label>
<label>The path ids are set ordered from left to right (bounding box).</label>
<param name="characters" type="string" gui-text="Characters:">abc</param>
</page>
<page name="help" gui-text="Information">
<label xml:space="preserve">
For more information:
https://gitlab.com/EllenWasbo/inkscape-extension-getsetGlyphIDs
and
http://cutlings.wasbo.net/inkscape-automate-set-glyph-ids/</label>
</page>
</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Text" />
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">set_glyph_ids.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,65 @@
#!/usr/bin/env python3
#
# Copyright (C) 2020 Ellen Wasboe, ellen@wasbo.net
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Set ids of selected paths to a character in the specified string.
Paths a sorted by left bounding box. Id for the path to the left is set to the first character in the string.
Intention: to quickly set the correct id of the glyph-paths when using the Custom Stroke Font extension https://github.com/Shriinivas/inkscapestrokefont
"""
import inkex, re
class setGlyphIDs(inkex.EffectExtension):
"""Set ids of selected paths to a character in the specified string. """
def add_arguments(self, pars):
pars.add_argument("--tab", default="setGlyphIDs")
pars.add_argument("--characters", default="")
def effect(self):
if not self.svg.selected:
raise inkex.AbortExtension("Please select the glyph paths.")
else:
if self.options.characters == "":
raise inkex.AbortExtension("No characters specified.")
else:
chars=self.options.characters
listChar=list(chars)
leftVal=[]
i = 0
for id, elem in self.svg.selection.id_dict().items():
leftVal.append(elem.bounding_box().left)
elem.set('id','reset'+str(i))#reset all ids to prevent duplicate id problems
i+=1
leftVal.sort(key=float)
i = 0
for id, elem in self.svg.selection.id_dict().items():
thisLeft=elem.bounding_box().left
charNo=leftVal.index(thisLeft)
if i < len(listChar):
elem.set('id',listChar[charNo])
i+=1
else:
break
if __name__ == '__main__':
setGlyphIDs().run()