diff --git a/__init__.py b/__init__.py index 94533ab..112e507 100644 --- a/__init__.py +++ b/__init__.py @@ -347,6 +347,10 @@ class ABC3D_PT_FontList(bpy.types.Panel): scale_y = 0.5 row = subbox.row(); row.scale_y = scale_y 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): @@ -710,6 +714,21 @@ class ABC3D_OT_LoadInstalledFonts(bpy.types.Operator): 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): """Add default metrics to selected objects""" bl_idname = f"{__name__}.add_default_metrics" @@ -1353,6 +1372,7 @@ classes = ( ABC3D_PT_FontCreation, ABC3D_PT_TextPropertiesPanel, ABC3D_OT_LoadInstalledFonts, + ABC3D_OT_LoadFont, ABC3D_OT_AddDefaultMetrics, ABC3D_OT_RemoveMetrics, ABC3D_OT_AlignMetricsToActiveObject, diff --git a/butils.py b/butils.py index 74ec19b..9e22e7f 100644 --- a/butils.py +++ b/butils.py @@ -695,9 +695,14 @@ def set_text_on_curve(text_properties, recursive=True): is_command = False previous_spline_index = -1 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 == '\\': is_command = True continue + if c == ' ': + advance = advance + scalor + continue is_newline = False if is_command: if c == 'n': @@ -767,8 +772,6 @@ def set_text_on_curve(text_properties, recursive=True): ob.rotation_quaternion = q # 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 @@ -776,7 +779,7 @@ def set_text_on_curve(text_properties, recursive=True): # otherwise letters will be closer together the curvier the bezier is # this could be done more efficiently, but whatever 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: 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)