From f08cf60155a0155d2aaa283091dd8ce32c0f2e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gauthier=20Bri=C3=A8re?= Date: Sat, 16 Nov 2024 18:02:02 +0100 Subject: [PATCH] [Draft] add font path relative (#17819) * Permit a font file path relative to the FreeCAD file * Use obj.Document instead of App.ActiveDocument * use filename = instead of directory = --- src/Mod/Draft/draftobjects/shapestring.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Mod/Draft/draftobjects/shapestring.py b/src/Mod/Draft/draftobjects/shapestring.py index 05c5a564e7..6dca3f6e24 100644 --- a/src/Mod/Draft/draftobjects/shapestring.py +++ b/src/Mod/Draft/draftobjects/shapestring.py @@ -27,6 +27,7 @@ ## \addtogroup draftobjects # @{ +import os import math from PySide.QtCore import QT_TRANSLATE_NOOP @@ -129,6 +130,12 @@ class ShapeString(DraftObject): if obj.String and obj.FontFile: plm = obj.Placement + if obj.FontFile[0] == ".": + # FontFile path relative to the FreeCAD file directory. + font_file = os.path.join(os.path.dirname(obj.Document.FileName), obj.FontFile) + else: + font_file = obj.FontFile + fill = obj.MakeFace if fill is True: # Test a simple letter to know if we have a sticky font or not. @@ -136,7 +143,7 @@ class ShapeString(DraftObject): # The 0.03 total area minimum is based on tests with: # 1CamBam_Stick_0.ttf and 1CamBam_Stick_0C.ttf. # See the make_faces function for more information. - char = Part.makeWireString("L", obj.FontFile, 1, 0)[0] + char = Part.makeWireString("L", font_file, 1, 0)[0] shapes = self.make_faces(char) # char is list of wires if not shapes: fill = False @@ -146,7 +153,7 @@ class ShapeString(DraftObject): Part.Compound(shapes).BoundBox.DiagonalLength, rel_tol=1e-7) - chars = Part.makeWireString(obj.String, obj.FontFile, obj.Size, obj.Tracking) + chars = Part.makeWireString(obj.String, font_file, obj.Size, obj.Tracking) shapes = [] for char in chars: @@ -164,7 +171,7 @@ class ShapeString(DraftObject): ss_shape = Part.Compound([ss_shape]) else: ss_shape = Part.Compound(shapes) - cap_char = Part.makeWireString("M", obj.FontFile, obj.Size, obj.Tracking)[0] + cap_char = Part.makeWireString("M", font_file, obj.Size, obj.Tracking)[0] cap_height = Part.Compound(cap_char).BoundBox.YMax if obj.ScaleToSize: ss_shape.scale(obj.Size / cap_height)