load specific font in memory
This commit is contained in:
parent
40e97aaf9e
commit
cd1af39985
2 changed files with 26 additions and 3 deletions
20
__init__.py
20
__init__.py
|
@ -347,6 +347,10 @@ class ABC3D_PT_FontList(bpy.types.Panel):
|
||||||
scale_y = 0.5
|
scale_y = 0.5
|
||||||
row = subbox.row(); row.scale_y = scale_y
|
row = subbox.row(); row.scale_y = scale_y
|
||||||
row.label(text=text)
|
row.label(text=text)
|
||||||
|
row = layout.row()
|
||||||
|
oper = row.operator(f"{__name__}.load_font", text='Load all glyphs in memory')
|
||||||
|
oper.font_name = font_name
|
||||||
|
oper.face_name = face_name
|
||||||
|
|
||||||
|
|
||||||
class ABC3D_PT_TextPlacement(bpy.types.Panel):
|
class ABC3D_PT_TextPlacement(bpy.types.Panel):
|
||||||
|
@ -710,6 +714,21 @@ class ABC3D_OT_LoadInstalledFonts(bpy.types.Operator):
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class ABC3D_OT_LoadFont(bpy.types.Operator):
|
||||||
|
"""Load all glyphs from a specific font in memory.\nThis can take a while and slow down Blender."""
|
||||||
|
bl_idname = f"{__name__}.load_font"
|
||||||
|
bl_label = "Loading Font."
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
font_name: bpy.props.StringProperty()
|
||||||
|
face_name: bpy.props.StringProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
filepaths = Font.fonts[self.font_name].faces[self.face_name].filepaths
|
||||||
|
for f in filepaths:
|
||||||
|
butils.load_font_from_filepath(f)
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
class ABC3D_OT_AddDefaultMetrics(bpy.types.Operator):
|
class ABC3D_OT_AddDefaultMetrics(bpy.types.Operator):
|
||||||
"""Add default metrics to selected objects"""
|
"""Add default metrics to selected objects"""
|
||||||
bl_idname = f"{__name__}.add_default_metrics"
|
bl_idname = f"{__name__}.add_default_metrics"
|
||||||
|
@ -1353,6 +1372,7 @@ classes = (
|
||||||
ABC3D_PT_FontCreation,
|
ABC3D_PT_FontCreation,
|
||||||
ABC3D_PT_TextPropertiesPanel,
|
ABC3D_PT_TextPropertiesPanel,
|
||||||
ABC3D_OT_LoadInstalledFonts,
|
ABC3D_OT_LoadInstalledFonts,
|
||||||
|
ABC3D_OT_LoadFont,
|
||||||
ABC3D_OT_AddDefaultMetrics,
|
ABC3D_OT_AddDefaultMetrics,
|
||||||
ABC3D_OT_RemoveMetrics,
|
ABC3D_OT_RemoveMetrics,
|
||||||
ABC3D_OT_AlignMetricsToActiveObject,
|
ABC3D_OT_AlignMetricsToActiveObject,
|
||||||
|
|
|
@ -695,9 +695,14 @@ def set_text_on_curve(text_properties, recursive=True):
|
||||||
is_command = False
|
is_command = False
|
||||||
previous_spline_index = -1
|
previous_spline_index = -1
|
||||||
for i, c in enumerate(text_properties.text):
|
for i, c in enumerate(text_properties.text):
|
||||||
|
face = Font.fonts[text_properties.font_name].faces[text_properties.face_name]
|
||||||
|
scalor = face.unit_factor * text_properties.font_size
|
||||||
if c == '\\':
|
if c == '\\':
|
||||||
is_command = True
|
is_command = True
|
||||||
continue
|
continue
|
||||||
|
if c == ' ':
|
||||||
|
advance = advance + scalor
|
||||||
|
continue
|
||||||
is_newline = False
|
is_newline = False
|
||||||
if is_command:
|
if is_command:
|
||||||
if c == 'n':
|
if c == 'n':
|
||||||
|
@ -767,8 +772,6 @@ def set_text_on_curve(text_properties, recursive=True):
|
||||||
ob.rotation_quaternion = q
|
ob.rotation_quaternion = q
|
||||||
# ob.rotation_quaternion = (mom.matrix_world @ q.to_matrix().to_4x4()).to_quaternion()
|
# ob.rotation_quaternion = (mom.matrix_world @ q.to_matrix().to_4x4()).to_quaternion()
|
||||||
|
|
||||||
face = Font.fonts[text_properties.font_name].faces[text_properties.face_name]
|
|
||||||
scalor = face.unit_factor * text_properties.font_size
|
|
||||||
|
|
||||||
glyph_advance = get_glyph_advance(glyph) * scalor + text_properties.letter_spacing
|
glyph_advance = get_glyph_advance(glyph) * scalor + text_properties.letter_spacing
|
||||||
|
|
||||||
|
@ -776,7 +779,7 @@ def set_text_on_curve(text_properties, recursive=True):
|
||||||
# otherwise letters will be closer together the curvier the bezier is
|
# otherwise letters will be closer together the curvier the bezier is
|
||||||
# this could be done more efficiently, but whatever
|
# this could be done more efficiently, but whatever
|
||||||
curve_compensation = 0
|
curve_compensation = 0
|
||||||
if distribution_type == 'CALCULATE' and not is_newline:
|
if distribution_type == 'CALCULATE' and (not is_newline or spline_index == 0): # TODO: fix newline hack
|
||||||
if text_properties.compensate_curvature and glyph_advance > 0:
|
if text_properties.compensate_curvature and glyph_advance > 0:
|
||||||
previous_location, psi = calc_point_on_bezier_curve(mom, advance, False, True)
|
previous_location, psi = calc_point_on_bezier_curve(mom, advance, False, True)
|
||||||
new_location, si = calc_point_on_bezier_curve(mom, advance + glyph_advance, False, True)
|
new_location, si = calc_point_on_bezier_curve(mom, advance + glyph_advance, False, True)
|
||||||
|
|
Loading…
Reference in a new issue