mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 16:20:38 +00:00
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:
parent
e0159ddd70
commit
5002c33cb1
1 changed files with 26 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue