NSAttributedString misinterprets Unicode LINE SEPARATOR character (U+2028)

Originator:alexisgallagher
Number:rdar://22784299 Date Originated:2015-09-21
Status:Open Resolved:
Product: Product Version:iOS9
Classification:other bug Reproducible:always
 
Summary:
The Unicode standard (v5.0 onward), in section 5.8 "Newline Guidelines", subsection "Line Separator and Paragraph Separator", provides explicit guidance on how text rendering systems should differ in their handling of the characters LINE SEPARATOR (U+2029) and PARAGRAPH SEPARATOR (U+2028). (Link here: http://www.unicode.org/versions/Unicode8.0.0/ch05.pdf )

Cocoa ignores the guidance regarding LINE SEPARATOR, and treats it identically to PARAGRAPH SEPARATOR.

In particular, if you define an NSParagraphStyle with a paragraphSpacing, and you initialize an NSAttributedString that uses a LINE SEPARATOR character, then Cocoa will apply the paragraph spacing to the vertical separation produced by the LINE SEPARATOR, just as if it were a PARAGRAPH SEPARATOR.

This is noncompliant with Unicode's recommendation, and with the entire point of the LINE SEPARATOR character, which is for it to mark a line break that is not a paragraph break.

Steps to Reproduce:
1. Paste the enclosed swift file into a playground
2. Notice the values at the very bottom of the playground. The heights returned by the `intrinsicContentSize` of the two labels `twolineICSP2` and `twoParaICSP2` are equal, when they should be different. One uses LINE SEPARATOR, one uses PARAGRAPH SEPARATOR. The paragraphs style has been configured with explicit non-zero distinct values for `lineSpacing` and `paragraphSpacing`, so these two labels should not have the same heights.



Expected Results:
Expect to see that only `lineSpacing` is applied to the lines separated by LINE SEPARATOR, but `lineSpacing`

Actual Results:
 `lineSpacing` and `paragraphSpacing` are applied to the lines separated by LINE SEPARATOR, just like with PARAGRAPH SEPARATOR or LINE FEED.

Version:
iOS 9 at least.

attachment also at : https://gist.github.com/algal/17c73d28e562ccc07372

Comments

Further investigation shows ...

Further investigation shows:

  1. this bug affects UILabel, not UITextView.
  2. this bug affects NSAttributedString.boundingRectWithSize(_:options:context:) when .UsesDeviceMetrics is false.
By alexisgallagher at Sept. 25, 2015, 5:52 a.m. (reply...)

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!