How do I make Apple's Cocoa GUI controls not automatically "flip" lines that contain right-to-left text (such as arabic)?
Behold my test case, wherein I plan to keep the asterisks (**
) in the beginning of the lines when they are printed on screen:
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *autoReleasePool = [[NSAutoreleasePool alloc] init];
NSString *str1 = @"** english first then arabic تجر\n";
NSString *str2 = @"** تجر arabic first then english\n";
[str1 writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:NULL];
[str2 writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:NULL];
[autoReleasePool release];
return 0;
}
When I run this in Terminal.app I get:
$ gcc -framework Foundation test.m
$ ./a.out
** english first then arabic تجر
arabic first then english تجر **
In iTerm, though, the lines don't get "flipped":
$ gcc -framework Foundation test.m
$ ./a.out
** english first then arabic تجر
** تجر arabic first then english
Based on some cursory examination of iTerm's code, it looks like this is due to iTerm's "manual" character-by-character handling of output and Terminal.app's (assumed) use of OS-native string layout APIs. Is there any way to prevent this "flippage" from occurring when using, for example, NSTextView
to display these kinds of strings? I couldn't find any answers in Apple's documentation.
I'm running an english Mac OS 10.5.6 with english as the #1 language in the list under System Preferences > International > Language.