Even I don’t have time to check it, I’m sure that the problem is that the size of the label is calculated from the advances. Promotion is the amount of movement from one character’s base point to the next. Usually for an italic font, the advance may be less than the boundaries. Therefore, adding advances will shorten the end of the layout.
those. Baskerville-Italic H :
(lldb) p bounds[0].size (CGSize) $6 = (width=33.53515625, height=26.484375) (lldb) p advances[0] (CGSize) $7 = (width=30, height=0)
Therefore, I believe that you need to add the difference between the prefix and the bounding box of the last character, if the text is perfect layout (no compression, etc.).
To get both values, you need to call some CT functions:
Typed in Safari.
Addition: you have the same problem on the left side: the transition to upper case L is 0 (the first character), but the bounding box has a negative x. Therefore, the left side is cut off. Add a place there too .. (Which is much simpler).
source share