Re: unicode fraction symbol in a NSTextView
Re: unicode fraction symbol in a NSTextView
- Subject: Re: unicode fraction symbol in a NSTextView
- From: Steve Christensen <email@hidden>
- Date: Wed, 22 Jun 2016 10:29:20 -0700
Where are you specifying the text encoding of the HTML "document" passed to NSMutableAttributedString(HTML:, documentAttributes:)? The default encoding for HTML used to be ISO-8859-1, not UTF-8, for HTML 4 and earlier (and could continue to be interpreted that way by NSAttributedString for compatibility). That could explain the extra character being displayed since the string you're passing as the HTML parameter to NSMutableAttributedString doesn't include, for example, a charset="utf8" meta tag in its <head> that would specify the desired encoding.
And, unless you're doing some extra formatting not shown in your code snippet, is there any reason you wouldn't be initializing ats with NSAttributedString(string:s)?
> On Jun 22, 2016, at 9:32 AM, tridiak <email@hidden> wrote:
>
> I am setting some text to a NSTextView which includes the ‘½’ character.
>
> s = name + “ CR "
> switch (CR) {
> case 0.5:
> s=s+”½” // \u{00bd}
> case 0.33:
> s=s+"⅓"
> case 0.25:
> s=s+"¼"
> case 0.2:
> s=s+"⅕"
> case 0.17:
> s=s+"⅙"
> case 0.14:
> s=s+"⅐"
> case 0.13:
> s=s+"⅛"
> default:
> if CR<1 {s=s+String(format:"%.1f", CR)}
> else {s=s+String(format:"%.0f", CR)}
> }
> s=s+"\n”
>
> let d : NSData = s.dataUsingEncoding(NSUTF8StringEncoding)!
> let ats : NSMutableAttributedString = NSMutableAttributedString(HTML: d, documentAttributes: nil)!
> self.blab.textStorage?.setAttributedString(ats)
>
>
> What I see is 'Aasimar CR ½’ instead of 'Aasimar CR ½’.
> Where is the ‘Â' coming from?
> Is it the font or some swift-obj-C confusion?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden