Re: unicode fraction symbol in a NSTextView
> On 23/06/2016, at 5:29 AM, Steve Christensenwrote: > > 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 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)? > Copied from another project which uses an html document to be inserted into the NSTextView. This project did have a database which did not have an HTML layout field and I forgot to change to NSAttributedString(string:s). Found another DB which has an HTML data field (after I posted the original email), so I will drop my hand created version and use that. I don’t deal with HTML much (besides basic websites) and completely forgot about the encoding. Thanks for all the help. > >> On Jun 22, 2016, at 9:32 AM, tridiak 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 (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
unicode fraction symbol in a NSTextView
Almost certainly not the font itself. Looks like classic mojibake. The sequence which you seem to report, capital A circumflex, one-half might be in the encoding ISO-8859-1 (aka Windows-1252 aka informally Latin1). If so we have c2 - capital A circumflex bd - one half But what is the UTF-8 form of one-half? It is c2bd. So this seems the classic case of interpreting UTF-8 as ISO-8859-1. Where that is happening is for you to find, but my bet is that it is later than you think. On 22 June 2016 at 17:32, tridiak> 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} > ... > 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? ___ 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: unicode fraction symbol in a NSTextView
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 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, tridiakwrote: > > 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 (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: unicode fraction symbol in a NSTextView
Since the symbol is outside the ASCII range and your output encoding is UTF-8, that character requires 2 octets. Clearly, whatever application is reading the file isn't using UTF-8 encoding. Switch that application to UTF-8 and the character will display correctly. Sent from my iPhone > On Jun 22, 2016, at 9:32 AM, tridiakwrote: > > 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? > > TIA > > ___ > > 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/pscott%40skycoast.us > > This email sent to psc...@skycoast.us smime.p7s Description: S/MIME cryptographic signature ___ 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: unicode fraction symbol in a NSTextView
On Jun 22, 2016, at 09:32 , tridiakwrote: > > What I see is 'Aasimar CR ½’ instead of 'Aasimar CR ½’. > Where is the ‘Â' coming from? Well, the first thing you need to determine is whether this is the value of ’s’ itself, or the result of interpreting ’s’ as HTML. ___ 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
unicode fraction symbol in a NSTextView
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? TIA ___ 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