A white NSBackgroundColor is forced when decoding RTF NSData
| Originator: | george | ||
| Number: | rdar://29043092 | Date Originated: | 01-Nov-2016 |
| Status: | Open | Resolved: | |
| Product: | macOS | Product Version: | 10.12.1 |
| Classification: | Serious | Reproducible: | Always |
Summary:
Say you have a line of text in an NSTextView. You apply NSBackgroundColor of light red for a word within that text. Using RTFFromRange save it as NSData then load it back in. The attributes of the decoded RTF suddenly have a new white background color attribute added to words right after that highlighted word. Previous versions of OS X did not impose a background color and this messes up our rendering.
Steps to Reproduce:
1. On 10.12.1 download and launch Curio 10.3.2 (www.zengobi.com/downloads/Curio10.zip).
2. Choose File > New Blank Project.
3. Use the inspector to give the background a light gray coloring.
4. Double-click in the idea space area to create a new text figure and type "this is red and the rest isn't."
5. Double-click the word red to select it.
6. In the inspector bar give that word a light red background color.
7. Click elsewhere in the idea space to stop editing and notice that all is rendered fine.
8. Close the project and reopen it.
9. Notice the text after the word "red" now has a white background color imposed on it.
Expected Results:
The words following the highlighted word should not have a forced white background color. Indeed trying this same test in El Capitan or earlier OS X releases works just fine.
Actual Results:
Any text after subtext colored with NSBackgroundColor is given a NSBackgroundColor of white (specifically NSBackgroundColor = "NSCustomColorSpace Generic Gray Gamma 2.2 Profile colorspace 1 1";)
This is a serious bug for our app because we have a lot of students that highlight words in their text notes. Some of them have colored backgrounds and the forced-white ruins the look of their notes.
Debug Notes:
I also tried to force the RTF document to be transparent with documentAttributes of @{NSBackgroundColorDocumentAttribute : [NSColor clearColor]} but that didn't fix it.
Given this code snippet:
NSData *data = [self.hiddenText RTFFromRange:NSMakeRange(0, [self.hiddenText length]) documentAttributes:nil];
NSAttributedString *result = [[NSAttributedString alloc] initWithData:data options:@{} documentAttributes:nil error:nil];
On El Capitan (10.11.6) I see this:
(lldb) po text
this is {
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x115c70ed0) fobj=0x100f64800, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}red{
NSBackgroundColor = "NSCalibratedRGBColorSpace 0.996078 0.643137 0.627451 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x115c70ed0) fobj=0x100f64800, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
} and the rest isn’t.{
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x115c70ed0) fobj=0x100f64800, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}
(lldb) po result
this is {
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x10bf4c330) fobj=0x100f64800, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}red{
NSBackgroundColor = "NSCalibratedRGBColorSpace 0.996078 0.643137 0.627451 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x10bf4c330) fobj=0x100f64800, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
} and the rest isn’t.{
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x10bf4c330) fobj=0x100f64800, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}
On Sierra (10.12.1) I see this (notice the NSBackgroundColor added to "and the rest isn’t" in the results):
(lldb) po text
this is {
NSColor = "NSCustomColorSpace Generic RGB colorspace 0 0 0 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x604002459b10) fobj=0x61200013fe40, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}red{
NSBackgroundColor = "NSCalibratedRGBColorSpace 0.996078 0.643137 0.627451 1";
NSColor = "NSCustomColorSpace Generic RGB colorspace 0 0 0 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x604002459b10) fobj=0x61200013fe40, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
} and the rest isn’t{
NSColor = "NSCustomColorSpace Generic RGB colorspace 0 0 0 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x604002459b10) fobj=0x61200013fe40, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}
(lldb) po result
this is {
NSColor = "NSCustomColorSpace Generic RGB colorspace 0 0 0 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x6040024b14d0) fobj=0x61200013fe40, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}red{
NSBackgroundColor = "NSCustomColorSpace Generic RGB colorspace 0.99608 0.64314 0.62745 1";
NSColor = "NSCustomColorSpace Generic RGB colorspace 0 0 0 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x6040024b14d0) fobj=0x61200013fe40, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
} and the rest isn’t{
NSBackgroundColor = "NSCustomColorSpace Generic Gray Gamma 2.2 Profile colorspace 1 1";
NSColor = "NSCustomColorSpace Generic RGB colorspace 0 0 0 1";
NSFont = "\"GillSans-Italic 9.00 pt. P [] (0x6040024b14d0) fobj=0x61200013fe40, spc=2.50\"";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}
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!
Apple just closed this as a duplicate of 28990609.