Re: language based scaning,
Re: language based scaning,
- Subject: Re: language based scaning,
- From: Douglas Davidson <email@hidden>
- Date: Thu, 15 Oct 2009 15:00:31 -0700
On Oct 15, 2009, at 1:02 PM, Jens Alfke wrote:
NSString, mostly. Call -characters and loop over the UniChar[] array
it returns.
It's possible there are APIs for language/script detection at a
lower level, like CoreText, but this may be the wrong list to find
experts on that.
Another possibility that just occurred to me — assuming you're
loading the text into an NSTextView already, you can look at the
layout information which should tell you the directionality of each
run. This is probably somewhere in NSLayoutManager, but I'm not an
expert on that class.
Yes, there are better ways to do this. What they are depends a bit on
exactly what is wanted. The easiest case is one where you do no work,
and just let the system handle things--for example, if you set the
paragraph alignment to "natural", then the text system automatically
aligns to the left or right depending on whether the text is LTR or
RTL. If you need to detect the language of a piece of text,
CFStringTokenizer can do that; in Snow Leopard there is also a higher-
level language detection feature, as part of text checking, which is
available via NSTextView. If you want to find pieces of text that are
in a given script, you can use NSCharacterSet--that's better than
getting an array of characters and looping over it manually. And yes,
if you want the resolved layout directionality of a bit of text as it
is laid out, you can ask for the NSGlyphAttributeBidiLevel in
NSLayoutManager, but that's probably more detailed than you really want.
Douglas Davidson
_______________________________________________
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