Re: UILabel HTML to attributed string conversion: odd font choice for em text
On Dec 17, 2013, at 10:44 AM, Steve Christensen puns...@mac.com wrote: This seems odd to me since there's a perfectly fine Avenir Next Medium Italic available. Is this an expected font choice for italic text given the setup above That seems wrong to me too. I just experimented in TextEdit on OS X 10.9 — created some text in Avenir Next Medium, then italicized one word. It came out Avenir Next Italic (not Medium Italic), which is slightly wrong (too light) but not as wrong as what you got on iOS. My best guess is that the metadata in the fonts themselves is wrong: maybe Medium Italic doesn’t have the same weight value as Medium. and, more importantly, is there a way for me to end up with an attributed string that's using the italic version of the base font short of manually walking each of the attribute runs and correcting the font? You could try creating some CSS to define a custom font/style mapping, then insert that into the HTML… —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: UILabel HTML to attributed string conversion: odd font choice for em text
On Dec 17, 2013, at 1:04 PM, Jens Alfke j...@mooseyard.com wrote: On Dec 17, 2013, at 10:44 AM, Steve Christensen puns...@mac.com wrote: This seems odd to me since there's a perfectly fine Avenir Next Medium Italic available. Is this an expected font choice for italic text given the setup above That seems wrong to me too. I just experimented in TextEdit on OS X 10.9 — created some text in Avenir Next Medium, then italicized one word. It came out Avenir Next Italic (not Medium Italic), which is slightly wrong (too light) but not as wrong as what you got on iOS. My best guess is that the metadata in the fonts themselves is wrong: maybe Medium Italic doesn’t have the same weight value as Medium. I just specifically set up an em run to use Avenir Next Medium Italic and I can't see any difference in font weight, so if it's something like that then the algorithm that makes that determination is pickier about it than I. and, more importantly, is there a way for me to end up with an attributed string that's using the italic version of the base font short of manually walking each of the attribute runs and correcting the font? You could try creating some CSS to define a custom font/style mapping, then insert that into the HTML… I'm doing this same sort of thing in several locations within the app which would mean providing CSS for each as a workaround. Not the most elegant solution but for now I have ended up post-processing the attributed string, replacing the font in italicized runs with an italicized version of the base font. If someone else can provide further enlightenment into something I've done wrong and how to fix it then I can rip out this bit but for now this will do. Thanks, Jens. - Steve ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UILabel HTML to attributed string conversion: odd font choice for em text
I have formatted text delivered to the app as HTML that I am converting to a NSAttributedString and then assigning to a UILabel like this: NSDictionary* options = @{ NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding), NSDefaultAttributesDocumentAttribute: @{ NSFontAttributeName:label.font, NSForegroundColorAttributeName: label.textColor, NSStrikethroughStyleAttributeName: @1, NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle) }, NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }; attributedString = [[NSAttributedString alloc] initWithData:data options:options documentAttributes:NULL error:error]; label.attributedText = attributedString; The UILabel has its font set to Avenir Next Medium, which the code above uses as the base font for the attributed string. The HTML is of the form: pBlah blah blah emblah blah blah/em blah blah blah/p What I'm seeing visually is that the normal paragraph text is fine but that the text inside the em tag is nearly unreadable. I added code to dump out the attribute runs and found that the starting paragraph text is what's expected: NSFont = UICTFont: 0x14c51680 font-family: \AvenirNext-Medium\; font-weight: normal; font-style: normal; font-size: 16.00pt; but that the text inside the em tag uses Avenir Next UltraLight Italic: NSFont = UICTFont: 0x14c51ee0 font-family: \AvenirNext-UltraLightItalic\; font-weight: normal; font-style: italic; font-size: 16.00pt; This seems odd to me since there's a perfectly fine Avenir Next Medium Italic available. Is this an expected font choice for italic text given the setup above and, more importantly, is there a way for me to end up with an attributed string that's using the italic version of the base font short of manually walking each of the attribute runs and correcting the font? Thanks, Steve ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com