Skip to content

Commit

Permalink
added use <font.ttf/otf> support (SolidCode#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-dh committed May 31, 2021
1 parent 2842edf commit ef29831
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions solid/core/scad_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from types import SimpleNamespace
from pathlib import Path
import inspect

from .utils import resolve_scad_filename, escape_openscad_identifier
Expand All @@ -8,6 +9,7 @@
# = IMPORTING OPENSCAD CODE =
# ===========================
module_cache_by_resolved_filename = {}
registered_fonts = []

def check_module_cache(resolved_scad, use_not_include):
global module_cache_by_resolved_filename
Expand Down Expand Up @@ -96,6 +98,14 @@ def get_callers_namespace_dict(depth=2):
return frame.f_globals

def use(filename):
#is this a font to register?
p_file = Path(filename)
if p_file.suffix == ".ttf" or p_file.suffix == ".otf":
global registered_fonts
registered_fonts += [p_file]
return

#otherwise load the scad file
load_scad_file_or_dir_into_dict(filename, get_callers_namespace_dict(), True)

def include(filename):
Expand Down
5 changes: 4 additions & 1 deletion solid/core/scad_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .utils import indent
from .object_base import ObjectBase, OpenSCADObject
from .scad_import import module_cache_by_resolved_filename
from .scad_import import module_cache_by_resolved_filename, registered_fonts
from ..config import config

# =========================================
Expand Down Expand Up @@ -77,6 +77,9 @@ def get_include_string():
else:
strings.append(f"include <{k}>")

for f in registered_fonts:
strings.append(f"use <{f}>")

s = "\n".join(strings)
s += "\n\n" if s else ''

Expand Down

0 comments on commit ef29831

Please sign in to comment.