mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 12:00:52 +00:00
Return a nil font if such a font can't be found; try to find an appropriate
font when loading a default font. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14711 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
72d35ad13a
commit
0de6fb2b19
2 changed files with 58 additions and 4 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Fri Oct 11 01:15:55 2002 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
* Source/NSFont.m (getNSFont): If fontWithName:size: returns nil,
|
||||
try various approximations to get a font.
|
||||
|
||||
Fri Oct 11 01:02:24 2002 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
Patch by Georg Fleischmann <georg@vhf.de>:
|
||||
* Source/NSFont.m ([NSFont -initWithName:matrix:fix:]): Release
|
||||
self and return nil if the font info is nil. This makes
|
||||
[NSFontManager -convertFont:...] work.
|
||||
|
||||
Thu Oct 10 19:56:29 2002 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
* Source/NSScrollView.m ([-scrollPageUp:]): Implemented.
|
||||
|
|
|
@ -143,11 +143,14 @@ static NSUserDefaults *defaults = nil;
|
|||
NSFont*
|
||||
getNSFont(NSString* key, NSString* defaultFontName, float fontSize)
|
||||
{
|
||||
NSString* fontName;
|
||||
|
||||
NSString *fontName;
|
||||
NSFont *font;
|
||||
|
||||
fontName = [defaults objectForKey: key];
|
||||
if (fontName == nil)
|
||||
fontName = defaultFontName;
|
||||
{
|
||||
fontName = defaultFontName;
|
||||
}
|
||||
|
||||
if (fontSize == 0)
|
||||
{
|
||||
|
@ -155,7 +158,40 @@ getNSFont(NSString* key, NSString* defaultFontName, float fontSize)
|
|||
[NSString stringWithFormat: @"%@Size", key]];
|
||||
}
|
||||
|
||||
return [NSFontClass fontWithName: fontName size: fontSize];
|
||||
font = [NSFontClass fontWithName: fontName size: fontSize];
|
||||
|
||||
/* That font couldn't be found (?). */
|
||||
if (font == nil)
|
||||
{
|
||||
/* Try the same size, but the defaultFontName. */
|
||||
font = [NSFontClass fontWithName: defaultFontName size: fontSize];
|
||||
|
||||
if (font == nil)
|
||||
{
|
||||
/* Try the default font name and size. */
|
||||
fontSize = [defaults floatForKey:
|
||||
[NSString stringWithFormat: @"%@Size", key]];
|
||||
|
||||
font = [NSFontClass fontWithName: defaultFontName size: fontSize];
|
||||
|
||||
/* It seems we can't get any font here! Try some well known
|
||||
* fonts as a last resort. */
|
||||
if (font == nil)
|
||||
{
|
||||
font = [NSFontClass fontWithName: @"Helvetica" size: 12.];
|
||||
}
|
||||
if (font == nil)
|
||||
{
|
||||
font = [NSFontClass fontWithName: @"Courier" size: 12.];
|
||||
}
|
||||
if (font == nil)
|
||||
{
|
||||
font = [NSFontClass fontWithName: @"Fixed" size: 12.];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -602,6 +638,12 @@ setNSFont(NSString* key, NSFont* font)
|
|||
matrixExplicitlySet = explicitlySet;
|
||||
fontInfo = RETAIN([GSFontInfo fontInfoForFontName: fontName
|
||||
matrix: fontMatrix]);
|
||||
if (fontInfo == nil)
|
||||
{
|
||||
RELEASE (self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
/* Cache the font for later use */
|
||||
NSMapInsert(globalFontMap, (void*)nameWithMatrix, (void*)self);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue