(+defaultWritingDirectionForLanguage:): Implement.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19291 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2004-05-12 14:54:08 +00:00
parent cfe33cfa9e
commit 476a373bf8
3 changed files with 41 additions and 4 deletions

View file

@ -1,7 +1,12 @@
2004-05-12 16:50 Alexander Malmberg <alexander@malmberg.org>
* Source/NSParagraphStyle.m (+defaultWritingDirectionForLanguage:):
Implement. Patch from Christopher Culver.
2004-05-12 15:52 Alexander Malmberg <alexander@malmberg.org>
* (-_generateGlyphsForRun:at:): Use a properly typed function
pointer for characterIsMember.
* Source/GSLayoutManager.m (-_generateGlyphsForRun:at:): Use a
properly typed function pointer for characterIsMember.
2004-05-08 Fred Kiefer <FredKiefer@gmx.de>

View file

@ -134,6 +134,11 @@ typedef enum _NSWritingDirection {
- (NSLineBreakMode) lineBreakMode;
#ifndef STRICT_OPENSTEP
/*
* Returns the writing direction of "language", which is an ISO 639
* two- or three letter code, e.g. "en", or an ISO language-region
* format, e.g. "en_GB"
*/
+ (NSWritingDirection) defaultWritingDirectionForLanguage: (NSString*) language;
- (NSWritingDirection) baseWritingDirection;
#endif

View file

@ -139,8 +139,35 @@ static NSParagraphStyle *defaultStyle = nil;
+ (NSWritingDirection) defaultWritingDirectionForLanguage: (NSString*) language
{
// FIXME
return NSWritingDirectionNaturalDirection;
static NSArray *rightToLeft;
NSWritingDirection writingDirection;
NSString *langCode = nil;
/* If language is 5/6 characters long with underscore in the middle,
treat it as ISO language-region format. */
if ([language length] == 5 && [language characterAtIndex: 2] == '_')
langCode = [language substringToIndex: 2];
else if ([language length] == 6 && [language characterAtIndex: 3] == '_')
langCode = [language substringToIndex: 3];
/* Else if it's just two or three chars long, treat as ISO 639 code. */
else if ([language length] == 2 || [language length] == 3)
langCode = language;
if (!rightToLeft)
// Holds languages whose current scripts are written right to left.
rightToLeft = [[NSArray alloc] initWithObjects: @"ar", @"ara", @"arc",
@"chi", @"fa", @"fas", @"he", @"heb", @"iw",
@"ji", @"kas", @"ks", @"ku", @"kur", @"pa",
@"pan", @"per" @"ps", @"pus", @"sd", @"snd",
@"syr", @"tk", @"tmh", @"tuk", @"ug",
@"uig", @"ur," @"urd", @"yi", @"yid", @"zh",
@"zho", nil];
if ([rightToLeft containsObject: langCode] == YES)
writingDirection = NSWritingDirectionRightToLeft;
else // If it's not RTL, assume LTR.
writingDirection = NSWritingDirectionLeftToRight;
return writingDirection;
}
- (void) dealloc