It seems as though something is different in the way text is drawn in ContextSentenceModelItem and AttributedModeltem text measurement. Starting with iOS 16, UITextView changed its behavior for text layout. Reverting that change (to TextKit 1 layout) causes the Japanese text to draw the same for edge cases, but then the drawing in ContextSentenceModelItem is different.
To make it draw the same, grab the attributed string from the NSTextView and draw that instead. (The difference between the two attributed strings seems to be the font, interestingly enough, unless there is another attribute that I did not notice - I just checked via a simple print(), which may have skipped something).
So, said another way: The drawing in ContextSentenceModelItem draws different than the actual text layout in AttributedModeltem. In 生まれる, the first context sentence draws as 1 line in ContextSentenceModelItem, but 2 lines in AttributedModeltem via the actual UITextView (and for whatever reason the text height measurement is also only doing 1 line for the Japanese, making us 1 line short). We can make the UITextView draw the same way by forcing it to use TextKit 1 layout, but then the blurred text in ContextSentenceModelItem is not right, so we draw that text using the same attributed string as the UITextView, and things appear happy, even though I'm not exactly happy with this fix. But, I'd rather have something working than not working, even if it's ugly, since I'm not sure how to go about fixing this in the best way.
This is not the greatest fix in the world, I think, but it works on iOS 17 (SE 3 Simulator) and iOS 18 (SE 3 Simulator), and that is something at least!
All these test cases were broken before and are working now.
Before:
Note the wrong placement of the English blur (as it is expecting 2 lines for the Japanese text, but the Japanese text only takes 1 line when drawn this way). But then, when you tap it, the UITextView is drawing with 2 lines for the Japanese. The English always needs 2 lines, but the text measuring only assumes 3 lines total instead of 4.
Closes #718 Closes #755
It seems as though something is different in the way text is drawn in
ContextSentenceModelItem
andAttributedModeltem
text measurement. Starting with iOS 16,UITextView
changed its behavior for text layout. Reverting that change (to TextKit 1 layout) causes the Japanese text to draw the same for edge cases, but then the drawing inContextSentenceModelItem
is different.To make it draw the same, grab the attributed string from the NSTextView and draw that instead. (The difference between the two attributed strings seems to be the font, interestingly enough, unless there is another attribute that I did not notice - I just checked via a simple print(), which may have skipped something).
So, said another way: The drawing in
ContextSentenceModelItem
draws different than the actual text layout inAttributedModeltem
. In 生まれる, the first context sentence draws as 1 line inContextSentenceModelItem
, but 2 lines inAttributedModeltem
via the actualUITextView
(and for whatever reason the text height measurement is also only doing 1 line for the Japanese, making us 1 line short). We can make theUITextView
draw the same way by forcing it to use TextKit 1 layout, but then the blurred text inContextSentenceModelItem
is not right, so we draw that text using the same attributed string as theUITextView
, and things appear happy, even though I'm not exactly happy with this fix. But, I'd rather have something working than not working, even if it's ugly, since I'm not sure how to go about fixing this in the best way.This is not the greatest fix in the world, I think, but it works on iOS 17 (SE 3 Simulator) and iOS 18 (SE 3 Simulator), and that is something at least!
Test cases: 分 一台 二台 生まれ 生まれる 写る 足りない 交通 仮に 命 芸者 絵文字
All these test cases were broken before and are working now.
Before:
Note the wrong placement of the English blur (as it is expecting 2 lines for the Japanese text, but the Japanese text only takes 1 line when drawn this way). But then, when you tap it, the
UITextView
is drawing with 2 lines for the Japanese. The English always needs 2 lines, but the text measuring only assumes 3 lines total instead of 4.After: