Index: Source/NSAttributedString.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSAttributedString.m,v retrieving revision 1.49 diff -u -r1.49 NSAttributedString.m --- Source/NSAttributedString.m 9 Aug 2004 22:51:38 -0000 1.49 +++ Source/NSAttributedString.m 3 Jun 2005 16:36:21 -0000 @@ -876,18 +876,33 @@ - (void) fixFontAttributeInRange: (NSRange)range { + unsigned int i; if (NSMaxRange (range) > [self length]) { [NSException raise: NSRangeException format: @"RangeError in method -fixFontAttributeInRange:"]; } - // FIXME: Should check for each character if it is supported by the - // assigned font - /* - Note that this needs to be done on a script basis. Per-character checks - are difficult to do at all, don't give reasonable results, and would have - really poor performance. - */ + for (i = range.location; i < range.location + range.length; i++) + { + unichar ch = [[self string] characterAtIndex: i]; + NSFont *f = [self attribute: NSFontAttributeName + atIndex: i + effectiveRange: NULL]; + + if (ch>32 && ![f glyphForCharacter: ch]) + { + f = [f substituteFontWithCharacter: ch]; + if (f) + [self addAttribute: GSSubstituteFontAttributeName + value: f + range: NSMakeRange(i, 1)]; + } + else + { + [self removeAttribute: GSSubstituteFontAttributeName + range: NSMakeRange(i, 1)]; + } + } } - (void) fixParagraphStyleAttributeInRange: (NSRange)range Index: Source/NSFont.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSFont.m,v retrieving revision 1.80 diff -u -r1.80 NSFont.m --- Source/NSFont.m 9 Apr 2005 12:01:32 -0000 1.80 +++ Source/NSFont.m 3 Jun 2005 16:36:21 -0000 @@ -931,6 +931,41 @@ return AUTORELEASE(RETAIN(cachedScreenFont)); } +-(NSFont *) substituteFontWithCharacter: (unichar)ch +{ +static NSArray *substitutionFonts; +static int c; + NSFont *f; + int i; + + if (!substitutionFonts) + { + NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; + substitutionFonts = [[defs objectForKey: @"GSSubstituteFonts"] retain]; + c = [substitutionFonts count]; + if (substitutionFonts && !c) + { + substitutionFonts = [[[NSFontManager sharedFontManager] + availableFonts] retain]; + c = [substitutionFonts count]; + } + } + + for (i = 0; i < c; i++) + { + f=[[isa alloc] initWithName: [substitutionFonts objectAtIndex: i] + matrix: matrix + fix: matrixExplicitlySet + screenFont: screenFont + role: role]; + if ([f glyphForCharacter: ch]) + return AUTORELEASE(f); + RELEASE(f); + } + + return nil; +} + - (float) ascender { return [fontInfo ascender]; } - (float) descender { return [fontInfo descender]; } - (float) capHeight { return [fontInfo capHeight]; } Index: Source/GSTypesetter.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/GSTypesetter.m,v retrieving revision 1.5 diff -u -r1.5 GSTypesetter.m --- Source/GSTypesetter.m 31 Jul 2003 23:52:09 -0000 1.5 +++ Source/GSTypesetter.m 3 Jun 2005 16:36:21 -0000 @@ -51,7 +51,11 @@ -(NSFont *) fontForCharactersWithAttributes: (NSDictionary *)attributes { - NSFont *f = [attributes valueForKey: NSFontAttributeName]; + NSFont *f; + + f = [attributes valueForKey: GSSubstituteFontAttributeName]; + if (!f) + f = [attributes valueForKey: NSFontAttributeName]; if (!f) f = [NSFont userFontOfSize: 0]; return f; Index: Source/externs.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/externs.m,v retrieving revision 1.44 diff -u -r1.44 externs.m --- Source/externs.m 29 Feb 2004 04:39:48 -0000 1.44 +++ Source/externs.m 3 Jun 2005 16:36:21 -0000 @@ -426,6 +426,7 @@ NSString *NSBaselineOffsetAttributeName = @"NSBaselineOffsetAttributeName"; NSString *NSKernAttributeName = @"NSKernAttributeName"; NSString *NSLinkAttributeName = @"NSLinkAttributeName"; +NSString *GSSubstituteFontAttributeName = @"GSSubstituteFontAttributeName"; // NSToolbar notifications NSString *NSToolbarDidRemoveItemNotification = @"NSToolbarDidRemoveItemNotification"; Index: Headers/AppKit/NSAttributedString.h =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/AppKit/NSAttributedString.h,v retrieving revision 1.1 diff -u -r1.1 NSAttributedString.h --- Headers/AppKit/NSAttributedString.h 31 Jul 2003 23:52:08 -0000 1.1 +++ Headers/AppKit/NSAttributedString.h 3 Jun 2005 16:36:21 -0000 @@ -58,9 +58,10 @@ APPKIT_EXPORT NSString *NSBaselineOffsetAttributeName; APPKIT_EXPORT NSString *NSKernAttributeName; APPKIT_EXPORT NSString *NSLinkAttributeName; +APPKIT_EXPORT NSString *GSSubstituteFontAttributeName; /* Currently supported values for NSUnderlineStyleAttributeName. */ -enum +enum { GSNoUnderlineStyle = 0, NSSingleUnderlineStyle = 1