If a font can't be found in the usual ways, try as a composite name font

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14712 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2002-10-10 23:52:09 +00:00
parent e0159ddd70
commit 5002c33cb1

View file

@ -142,10 +142,32 @@ readNSString (StringContext *ctxt)
size: fontSize];
if (font == nil)
{
NSDebugMLLog(@"RTFParser",
@"Could not find font %@ size %f traits %d weight %d",
fontName, fontSize, traits, weight);
font = [NSFont userFontOfSize: fontSize];
/* Before giving up and using a default font, we try if this is
* not the case of a font with a composite name, such as
* 'Helvetica-Light'. In that case, even if we don't have
* exactly an 'Helvetica-Light' font family, we might have an
* 'Helvetica' one. */
NSRange range = [fontName rangeOfString:@"-"];
if (range.location != NSNotFound)
{
NSString *fontFamily = [fontName substringToIndex: range.location];
font = [[NSFontManager sharedFontManager] fontWithFamily: fontFamily
traits: traits
weight: weight
size: fontSize];
}
if (font == nil)
{
NSDebugMLLog(@"RTFParser",
@"Could not find font %@ size %f traits %d weight %d",
fontName, fontSize, traits, weight);
/* Last resort, default font. :-( */
font = [NSFont userFontOfSize: fontSize];
}
}
return font;