diff --git a/ChangeLog b/ChangeLog index 3a2ee5cb7..ff791dc1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ +2004-05-12 16:50 Alexander Malmberg + + * Source/NSParagraphStyle.m (+defaultWritingDirectionForLanguage:): + Implement. Patch from Christopher Culver. + 2004-05-12 15:52 Alexander Malmberg - * (-_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 diff --git a/Headers/AppKit/NSParagraphStyle.h b/Headers/AppKit/NSParagraphStyle.h index 5e8a9698f..2f1fd7b75 100644 --- a/Headers/AppKit/NSParagraphStyle.h +++ b/Headers/AppKit/NSParagraphStyle.h @@ -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 diff --git a/Source/NSParagraphStyle.m b/Source/NSParagraphStyle.m index 069352740..dc0b27808 100644 --- a/Source/NSParagraphStyle.m +++ b/Source/NSParagraphStyle.m @@ -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