revamp installing fonts
This commit is contained in:
parent
5e881ad864
commit
28e664cd6c
3 changed files with 53 additions and 10 deletions
55
__init__.py
55
__init__.py
|
@ -314,7 +314,7 @@ class ABC3D_PT_LoadFontPanel(bpy.types.Panel):
|
|||
|
||||
layout.label(text="Install FontFile:")
|
||||
layout.row().prop(abc3d, "font_path")
|
||||
layout.row().operator(f"{__name__}.loadfont", text='Install and load Font')
|
||||
layout.row().operator(f"{__name__}.install_font", text='Install')
|
||||
|
||||
|
||||
class ABC3D_PT_FontList(bpy.types.Panel):
|
||||
|
@ -579,13 +579,39 @@ class ABC3D_PT_TextPropertiesPanel(bpy.types.Panel):
|
|||
layout.column().prop(props, "translation")
|
||||
layout.column().prop(props, "orientation")
|
||||
|
||||
class ABC3D_OT_LoadFont(bpy.types.Operator):
|
||||
"""Load Fontfile from path above.
|
||||
class ABC3D_OT_InstallFont(bpy.types.Operator):
|
||||
"""Install or load Fontfile from path above.
|
||||
(Format must be *.glb or *.gltf)"""
|
||||
bl_idname = f"{__name__}.loadfont"
|
||||
bl_idname = f"{__name__}.install_font"
|
||||
bl_label = "Load Font"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
install_in_assets: bpy.props.BoolProperty(
|
||||
name="install in assets",
|
||||
description="install the font in the assets directory of the addon",
|
||||
)
|
||||
|
||||
load_into_memory: bpy.props.BoolProperty(name="load font data into memory",
|
||||
description="if false, it will load font data on demand",
|
||||
default=False)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.row().prop(self, "install_in_assets")
|
||||
if not self.install_in_assets and not self.load_into_memory:
|
||||
layout.label(text="If the fontfile is not installed,")
|
||||
layout.label(text="and the font is not loaded in memory completely,")
|
||||
layout.label(text="the fontfile should not be moved.")
|
||||
layout.row().prop(self, "load_into_memory")
|
||||
if self.load_into_memory:
|
||||
layout.label(text="Loading font files can take a long time")
|
||||
layout.label(text="and use a lot of RAM.")
|
||||
layout.label(text="We recommend not doing this and let us")
|
||||
layout.label(text="load the font data on demand.")
|
||||
|
||||
def invoke(self, context, event):
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def execute(self, context):
|
||||
scene = bpy.context.scene
|
||||
|
||||
|
@ -593,10 +619,27 @@ class ABC3D_OT_LoadFont(bpy.types.Operator):
|
|||
butils.ShowMessageBox(
|
||||
title=f"{__name__} Warning",
|
||||
icon="ERROR",
|
||||
message=f"We believe the font path ({scene[__name__].font_path}) does not exist.",
|
||||
message=f"We believe the font path ({scene.abc3d.font_path}) does not exist.",
|
||||
)
|
||||
return {'CANCELLED'}
|
||||
|
||||
if self.install_in_assets:
|
||||
preferences = getPreferences(context)
|
||||
filename = os.path.basename(scene.abc3d.font_path)
|
||||
target = os.path.join(preferences.assets_dir, "fonts", filename)
|
||||
print(f"installing {scene.abc3d.font_path} -> {target}")
|
||||
import shutil
|
||||
shutil.copyfile(scene.abc3d.font_path, target)
|
||||
# def register_load(target, load=False):
|
||||
# print(f"registering installed fonts")
|
||||
# bpy.app.timers.register(lambda: register_load(target, self.load_into_memory), first_interval=5)
|
||||
butils.register_font_from_filepath(target)
|
||||
if self.load_into_memory:
|
||||
butils.load_font_from_filepath(target)
|
||||
butils.update_available_fonts()
|
||||
else:
|
||||
butils.register_font_from_filepath(scene.abc3d.font_path)
|
||||
if self.load_into_memory:
|
||||
butils.load_font_from_filepath(scene.abc3d.font_path)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
@ -1219,7 +1262,7 @@ classes = (
|
|||
ABC3D_OT_AlignMetrics,
|
||||
ABC3D_OT_TemporaryHelper,
|
||||
ABC3D_OT_PlaceText,
|
||||
ABC3D_OT_LoadFont,
|
||||
ABC3D_OT_InstallFont,
|
||||
ABC3D_OT_ToggleABC3DCollection,
|
||||
ABC3D_OT_SaveFontToFile,
|
||||
ABC3D_OT_CreateFontFromObjects,
|
||||
|
|
|
@ -25,7 +25,7 @@ def get_font_faces_in_file(filepath):
|
|||
for node in gltf_importer.data.nodes:
|
||||
if type(node.extras) != type(None) \
|
||||
and "glyph" in node.extras \
|
||||
and not ("type" in node.extras and node.extras["type"] is "metrics"):
|
||||
and not ("type" in node.extras and node.extras["type"] == "metrics"):
|
||||
out.append(node.extras)
|
||||
return out
|
||||
|
||||
|
|
|
@ -509,7 +509,7 @@ def clear_available_fonts():
|
|||
|
||||
def load_installed_fonts():
|
||||
preferences = getPreferences(bpy.context)
|
||||
font_dir = f"{preferences.assets_dir}/fonts"
|
||||
font_dir = os.path.join(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)
|
||||
|
@ -522,7 +522,7 @@ def load_installed_fonts():
|
|||
|
||||
def register_installed_fonts():
|
||||
preferences = getPreferences(bpy.context)
|
||||
font_dir = f"{preferences.assets_dir}/fonts"
|
||||
font_dir = os.path.join(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)
|
||||
|
|
Loading…
Reference in a new issue