You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When rendering text that gets truncated the text is offset vertically compared to when text is not truncated. The following code sample produces the screen shot below. The text on the left is offset a few pixels up. The difference becomes even more prominent if you change minimumLineHeight.
letlabel1=NantesLabel()
label1.text ="Some long text that should be truncated"
label1.layer.borderColor =UIColor.red.cgColor
label1.layer.borderWidth =1letlabel2=NantesLabel()
label2.text ="Some other long text"
label2.setContentCompressionResistancePriority(.required, for:.horizontal)
label2.layer.borderColor =UIColor.red.cgColor
label2.layer.borderWidth =1
I investigated this a bit and found that in the drawAttributedString method the call to CTFrameGetLines for the truncated label returns one CTLine. This line then has multiple CTRuns. The non truncated label gets one CTLine with one CTRun.
CTLineGetTypographicBounds is then called to get the descent of the line and this is the value that differs for the two lines and what seems to caused the differently rendered text. I tried to instead get the first CTRun of the line and call CTRunGetTypographicBounds to get the descent. This results in a descent that is equal for both labels but this is a bit beyond my knowledge of CoreText to say if this is a fix or not.
Expected behavior
Truncated text should be rendered at the same yOffset as non truncated text.
Screenshots
Smartphone (please complete the following information):
Device: [iPhone 11 and iPhone8 simulator]
OS: iOS12, iOS14
The text was updated successfully, but these errors were encountered:
Describe the bug
When rendering text that gets truncated the text is offset vertically compared to when text is not truncated. The following code sample produces the screen shot below. The text on the left is offset a few pixels up. The difference becomes even more prominent if you change
minimumLineHeight
.I investigated this a bit and found that in the
drawAttributedString
method the call toCTFrameGetLines
for the truncated label returns oneCTLine
. This line then has multipleCTRun
s. The non truncated label gets oneCTLine
with oneCTRun
.CTLineGetTypographicBounds
is then called to get thedescent
of the line and this is the value that differs for the two lines and what seems to caused the differently rendered text. I tried to instead get the firstCTRun
of the line and callCTRunGetTypographicBounds
to get thedescent
. This results in adescent
that is equal for both labels but this is a bit beyond my knowledge of CoreText to say if this is a fix or not.Expected behavior
Truncated text should be rendered at the same yOffset as non truncated text.
Screenshots
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: