summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2024-10-21 17:01:58 +0200
committerGitHub <noreply@github.com>2024-10-21 17:01:58 +0200
commitc6fecfb0bc91d94f56da43e242b6e59b41058094 (patch)
tree7d33e5a67d97461089ffb6f0dbfeb1fefa95cbd0 /lib/extensions
parentdbfdb3e8d4fe3787927e8ab536473f9db6264e2b (diff)
Add color sort option for multicolor fonts (#3242)
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/__init__.py2
-rw-r--r--lib/extensions/lettering_generate_json.py12
-rw-r--r--lib/extensions/lettering_set_color_sort_index.py28
3 files changed, 39 insertions, 3 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index 8bf0b021..d5cfc8f8 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -37,6 +37,7 @@ from .lettering_font_sample import LetteringFontSample
from .lettering_force_lock_stitches import LetteringForceLockStitches
from .lettering_generate_json import LetteringGenerateJson
from .lettering_remove_kerning import LetteringRemoveKerning
+from .lettering_set_color_sort_index import LetteringSetColorSortIndex
from .lettering_update_json_glyphlist import LetteringUpdateJsonGlyphlist
from .letters_to_font import LettersToFont
from .object_commands import ObjectCommands
@@ -105,6 +106,7 @@ __all__ = extensions = [About,
LetteringForceLockStitches,
LetteringGenerateJson,
LetteringRemoveKerning,
+ LetteringSetColorSortIndex,
LetteringUpdateJsonGlyphlist,
LettersToFont,
ObjectCommands,
diff --git a/lib/extensions/lettering_generate_json.py b/lib/extensions/lettering_generate_json.py
index 5ff64c41..e6f997c7 100644
--- a/lib/extensions/lettering_generate_json.py
+++ b/lib/extensions/lettering_generate_json.py
@@ -5,9 +5,8 @@
import json
import os
-import sys
-from inkex import Boolean
+from inkex import Boolean, errormsg
from ..i18n import _
from ..lettering.categories import FONT_CATEGORIES
@@ -27,6 +26,8 @@ class LetteringGenerateJson(InkstitchExtension):
self.arg_parser.add_argument("-d", "--font-description", type=str, default="Description", dest="font_description")
self.arg_parser.add_argument("-s", "--auto-satin", type=Boolean, default="true", dest="auto_satin")
self.arg_parser.add_argument("-r", "--reversible", type=Boolean, default="true", dest="reversible")
+ self.arg_parser.add_argument("-o", "--combine-at-sort-indices", type=str, default="", dest="combine_at_sort_indices")
+ self.arg_parser.add_argument("-t", "--sortable", type=Boolean, default="false", dest="sortable")
self.arg_parser.add_argument("-u", "--letter-case", type=str, default="", dest="letter_case")
self.arg_parser.add_argument("-g", "--default-glyph", type=str, default="", dest="default_glyph")
self.arg_parser.add_argument("-z", "--size", type=float, default=15, dest="size")
@@ -45,7 +46,7 @@ class LetteringGenerateJson(InkstitchExtension):
# file paths
path = self.options.path
if not os.path.isfile(path):
- print(_("Please specify a font file."), file=sys.stderr)
+ errormsg(_("Please specify a font file."))
return
output_path = os.path.join(os.path.dirname(path), 'font.json')
@@ -77,6 +78,9 @@ class LetteringGenerateJson(InkstitchExtension):
if getattr(self.options, category.id):
keywords.append(category.id)
+ combine_at_sort_indices = self.options.combine_at_sort_indices.split(',')
+ combine_at_sort_indices = set([index.strip() for index in combine_at_sort_indices if index.strip()])
+
# collect data
data = {'name': self.options.font_name,
'description': self.options.font_description,
@@ -84,6 +88,8 @@ class LetteringGenerateJson(InkstitchExtension):
'leading': leading,
'auto_satin': self.options.auto_satin,
'reversible': self.options.reversible,
+ 'sortable': self.options.sortable,
+ 'combine_at_sort_indices': list(combine_at_sort_indices),
'letter_case': self.options.letter_case,
'default_glyph': self.options.default_glyph,
'size': self.options.size,
diff --git a/lib/extensions/lettering_set_color_sort_index.py b/lib/extensions/lettering_set_color_sort_index.py
new file mode 100644
index 00000000..3fb33094
--- /dev/null
+++ b/lib/extensions/lettering_set_color_sort_index.py
@@ -0,0 +1,28 @@
+# Authors: see git history
+#
+# Copyright (c) 2024 Authors
+# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
+from .base import InkstitchExtension
+
+
+class LetteringSetColorSortIndex(InkstitchExtension):
+ '''
+ This extension sets a color sort index to selected elements.
+ It enables font authors to define the order of elements in multicolor fonts when color sorted.
+ '''
+ def __init__(self, *args, **kwargs):
+ InkstitchExtension.__init__(self, *args, **kwargs)
+ self.arg_parser.add_argument("--notebook")
+ self.arg_parser.add_argument("-i", "--color-sort-index", type=int, default=0, dest="color_sort_index")
+
+ def effect(self):
+ selection = self.svg.selection
+ self.set_index(selection)
+
+ def set_index(self, element_list):
+ for element in element_list:
+ if element.TAG == "path":
+ element.set('inkstitch:color_sort_index', self.options.color_sort_index)
+ elif element.TAG == "g":
+ self.set_index(element.getchildren())