summaryrefslogtreecommitdiff
path: root/gerbonara/newstroke.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-04-18 12:26:03 +0200
committerjaseg <git@jaseg.de>2023-04-19 00:51:27 +0200
commit2c6c9a5cbc6d389a17c0cc15173c6e626fd5d5c6 (patch)
treedd588a4beff48425d5723f767a25e51d28e4500f /gerbonara/newstroke.py
parent263033c9bdecf8c82027f6475c863d818f499914 (diff)
downloadgerbonara-2c6c9a5cbc6d389a17c0cc15173c6e626fd5d5c6.tar.gz
gerbonara-2c6c9a5cbc6d389a17c0cc15173c6e626fd5d5c6.tar.bz2
gerbonara-2c6c9a5cbc6d389a17c0cc15173c6e626fd5d5c6.zip
Basic KiCad footprint rendering works
Diffstat (limited to 'gerbonara/newstroke.py')
-rw-r--r--gerbonara/newstroke.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/gerbonara/newstroke.py b/gerbonara/newstroke.py
index f9c4038..b48476a 100644
--- a/gerbonara/newstroke.py
+++ b/gerbonara/newstroke.py
@@ -4,6 +4,7 @@ from pathlib import Path
import unicodedata
import re
import ast
+from functools import lru_cache
from importlib.resources import files
from . import data
@@ -21,7 +22,12 @@ class Newstroke:
def __init__(self, newstroke_cpp=None):
if newstroke_cpp is None:
newstroke_cpp = files(data).joinpath('newstroke_font.cpp').read_bytes()
- self.glyphs = dict(self.load(newstroke_cpp))
+ self.glyphs = dict(self.load_font(newstroke_cpp))
+
+ @classmethod
+ @lru_cache
+ def load(kls):
+ return kls()
def render(self, text, size=1.0, space_width=DEFAULT_SPACE_WIDTH, char_gap=DEFAULT_CHAR_GAP):
text = unicodedata.normalize('NFC', text)
@@ -47,7 +53,7 @@ class Newstroke:
return [(x*sx+dx, y*sy+dy) for x, y in stroke]
- def load(self, newstroke_cpp):
+ def load_font(self, newstroke_cpp):
e = []
for char, (width, strokes) in self.load_glyphs(newstroke_cpp):
yield char, (width, strokes)