[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 =
This commit is contained in:
Gauthier Brière
2024-11-16 18:02:02 +01:00
committed by GitHub
parent 8f9718ebc6
commit f08cf60155

View File

@@ -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)