>>> s = App.ActiveDocument.ShapeString
>>> ss = s.Shape
>>> bearingX = ss.BoundBox.XMax - ss.BoundBox.XLength
I would have indeed expected that the bounding box would have the width of advance from your image, which includes some white space before the character - it is called bearing here - and some white space after the character - not named in your image.
Instead it seems that the bound box is just width wide.
My trick to center a ShapeString is to use an intermediate compound and some expressions.
As you use PartDesign, a ShapeBinder is needed.
I attached your file modified that way. You can change anything (cube width/length/height, shapestring text) and it will keep the text centered on the top face.
chrisb wrote: ↑Wed Aug 05, 2020 5:47 am
I would have indeed expected that the bounding box would have the width of advance from your image, which includes some white space before the character - it is called bearing here - and soome white space after the character - not named in your image.
Instead it seems that the bound box is just width wide.
This is standard FreeCAD behaviour. The bound box only includes the actual shape. The distance from the reference point/origin is never included.
Advance is used to determine the position of subsequent characters.
easy with string feature of lattice2 wb:
select the face, then attach a datumpoint
call the string feature, then select datumpoint as link.
and choose middle for alignment.
wandererfan wrote: ↑Wed Aug 05, 2020 1:18 am
You need to also allow for "bearingX" (the empty space in the "em square" before the actual shape):
glyphMetrics.png
EDIT: this calculation is rubbish. Don't know what I was thinking. WF
Vincent B wrote: ↑Wed Aug 05, 2020 7:00 pm
easy with string feature of lattice2 wb:
select the face, then attach a datumpoint
call the string feature, then select datumpoint as link.
and choose middle for alignment.
Thanks for this. It took me some fiddling to get this right, but now that I understand it, it is an easy solution.