Incorrect layout using kCTRubyAlignmentCenter when ruby text is wider than base text (iOS 10.0+)

Originator:clindsay
Number:rdar://29918938 Date Originated:01/08/2017
Status:Resolved Resolved:
Product:iOS SDK Product Version:10.0
Classification: Reproducible:Always
 
Area:
Something not on this list

Summary:
Using the CTRubyAnnotationCreate function available in CoreText, starting in iOS 10.0 the layout of text using the kCTRubyAlignmentCenter value for CTRubyAlignment is incorrect. 

When the ruby text is wider than the base text, it incorrectly aligns the ruby text to the *end* of the base text, instead of the center. When the ruby text is less wide than the base text, it correctly aligns the ruby text to the center of the base text.

The intended behavior is for the ruby to be aligned to the center of the base text in both situations, and this was the behavior in iOS 9. This is made clear in the documentation for that parameter, which states:

"The ruby text is centered within the width of the base text. If the ruby text is wider than the base text the base text is centered in the width of the ruby text."

See the attached screenshots for examples. It shows the behavior for every combination of CTRubyAlignment and CTRubyOverhang. It turns out that CTRubyOverhang did not affect the results, but it's included to confirm that it doesn't have an effect.

The incorrect line is in iOS 10 Wide Ruby.png, the row marked "center". Notice that the ruby is not centered above the base text. The same exact app running on iOS 9 (see screenshot iOS 9 Wide Ruby.png) displays the ruby correctly centered above the base text. Also note that when the base text is larger than the ruby text, it is properly centered even in iOS 10 (see iOS 10 Wide Base.png)

Steps to Reproduce:
1. Create a CTRubyAnnotationRef, passing kCTRubyAlignmentCenter as the alignment, and ruby text that is longer than the base text it will be applied to.
2. Create a CFAttributedStringRef using this ruby annotation as the kCTRubyAnnotationAttributeName attribute for the short base text.
3. Create a CTLineRef using this CFAttributedStringRef.
4. Draw the CTLineRef using CTLineDraw.

Expected Results:
The text is drawn with the ruby text centered above the base text.

Actual Results:
The text is drawn with the ruby text aligned to the end of the base text.

Version:
iOS 10.0 to 10.2

Notes:
Sample project illustrating the issue is attached. Run on iOS 9 and iOS 10 to see the difference in behavior.

Configuration:
Tested on iOS simulator and iPhone SE

Attachments:
'RubyAlignmentBug.zip', 'iOS 10 Wide Base.png', 'iOS 9 Wide Base.png', 'iOS 10 Wide Ruby.png' and 'iOS 9 Wide Ruby.png' were successfully uploaded.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!