load installed fonts, fix some minor loading issues
This commit is contained in:
parent
8ce5e6c816
commit
0bf80e01b2
3 changed files with 69 additions and 20 deletions
20
butils.py
20
butils.py
|
@ -419,7 +419,7 @@ def load_font_from_filepath(filepath):
|
|||
glyph_id = o["glyph"]
|
||||
font_name = o["font_name"]
|
||||
face_name = o["face_name"]
|
||||
ShowMessageBox("Loading Font", "INFO", f"adding glyph {glyph_id} for {font_name} {face_name}")
|
||||
# ShowMessageBox("Loading Font", "INFO", f"adding glyph {glyph_id} for {font_name} {face_name}")
|
||||
print(f"adding glyph {glyph_id} for {font_name} {face_name}")
|
||||
glyph_obj = move_in_fontcollection(
|
||||
o,
|
||||
|
@ -486,15 +486,13 @@ def getPreferences(context):
|
|||
def clear_available_fonts():
|
||||
bpy.context.scene.abc3d_data.available_fonts.clear()
|
||||
|
||||
def load_available_fonts():
|
||||
|
||||
def load_installed_fonts():
|
||||
preferences = getPreferences(bpy.context)
|
||||
print(f"assets folder: {preferences.assets_dir}")
|
||||
font_dir = f"{preferences.assets_dir}/fonts"
|
||||
for file in os.listdir(font_dir):
|
||||
if file.endswith(".glb") or file.endswith(".gltf"):
|
||||
font_path = os.path.join(font_dir, file)
|
||||
ShowMessageBox("Loading Font", "INFO", f"loading font from {font_path}")
|
||||
# ShowMessageBox("Loading Font", "INFO", f"loading font from {font_path}")
|
||||
print(f"loading font from {font_path}")
|
||||
for f in bpy.context.scene.abc3d_data.available_fonts.values():
|
||||
print(f"available font: {f.font_name} {f.face_name}")
|
||||
|
@ -555,7 +553,7 @@ def is_mesh(o):
|
|||
return type(o.data) == bpy.types.Mesh
|
||||
|
||||
def is_metrics_object(o):
|
||||
return (re.match("[\w]*_metrics$", o.name) != None or re.match("[\w]*_metrics.[\d]{3}$", o.name) != None) and is_mesh(o)
|
||||
return (re.match(".*_metrics$", o.name) != None or re.match(".*_metrics.[\d]{3}$", o.name) != None) and is_mesh(o)
|
||||
|
||||
def is_glyph(o):
|
||||
try:
|
||||
|
@ -757,6 +755,15 @@ def add_metrics_obj_from_bound_box(glyph, bound_box=None):
|
|||
obj["face_name"] = glyph["face_name"]
|
||||
obj["glyph"] = glyph["glyph"]
|
||||
obj["type"] = "metrics"
|
||||
|
||||
# remove already existing metrics
|
||||
remove_metrics = []
|
||||
for c in glyph.children:
|
||||
if is_metrics_object(c):
|
||||
remove_metrics.append(c)
|
||||
if len(remove_metrics) > 0:
|
||||
completely_delete_objects(remove_metrics)
|
||||
|
||||
col = glyph.users_collection[0]
|
||||
col.objects.link(obj)
|
||||
# bpy.context.view_layer.objects.active = obj
|
||||
|
@ -784,6 +791,7 @@ def add_metrics_obj_from_bound_box(glyph, bound_box=None):
|
|||
|
||||
def add_faces_to_metrics(obj):
|
||||
mesh = bpy.data.meshes.new(f"{obj.name}") # add the new mesh
|
||||
print(f"add_faces_to_metrics for {obj.name}")
|
||||
bound_box = bound_box_as_array(obj.bound_box)
|
||||
verts = [bound_box[0],
|
||||
bound_box[1],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue