2021-03-12 04:17:19 +00:00
|
|
|
# Authors: see git history
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Authors
|
|
|
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
|
|
|
|
2021-03-04 17:40:53 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from inkex import NSS
|
|
|
|
from lxml import etree
|
|
|
|
|
|
|
|
from .base import InkstitchExtension
|
|
|
|
|
|
|
|
|
|
|
|
class LetteringRemoveKerning(InkstitchExtension):
|
|
|
|
'''
|
|
|
|
This extension helps font creators to generate the json file for the lettering tool
|
|
|
|
'''
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
InkstitchExtension.__init__(self, *args, **kwargs)
|
2024-05-22 19:49:35 +00:00
|
|
|
self.arg_parser.add_argument("--notebook")
|
2021-03-04 17:40:53 +00:00
|
|
|
self.arg_parser.add_argument("-p", "--font-files", type=str, default="", dest="paths")
|
|
|
|
|
|
|
|
def effect(self):
|
|
|
|
# file paths
|
|
|
|
paths = self.options.paths.split("|")
|
|
|
|
for path in paths:
|
|
|
|
if not os.path.isfile(path):
|
|
|
|
continue
|
|
|
|
with open(path, 'r+', encoding="utf-8") as fontfile:
|
|
|
|
svg = etree.parse(fontfile)
|
|
|
|
xpath = ".//svg:font[1]"
|
2021-03-22 16:06:48 +00:00
|
|
|
kerning = svg.xpath(xpath, namespaces=NSS)
|
|
|
|
if kerning:
|
|
|
|
kerning = kerning[0]
|
|
|
|
kerning.getparent().remove(kerning)
|
|
|
|
fontfile.seek(0)
|
|
|
|
fontfile.write(etree.tostring(svg).decode('utf-8'))
|
|
|
|
fontfile.truncate()
|