mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Fix caching.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14588 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b566120f38
commit
a5b46e92b7
3 changed files with 63 additions and 51 deletions
|
@ -1,3 +1,8 @@
|
|||
2002-09-27 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSFont.m: Replace caching code which never released fonts
|
||||
with a cache which only holds fonts as long as something is using them.
|
||||
|
||||
2002-09-26 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/gnustep/gui/NSBrowserCell.h
|
||||
|
|
|
@ -105,7 +105,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
|||
matrix: (const float *)fmatrix;
|
||||
{
|
||||
return AUTORELEASE([[fontInfoClass alloc] initWithFontName: nfontName
|
||||
matrix: fmatrix]);
|
||||
matrix: fmatrix]);
|
||||
}
|
||||
|
||||
+ (int) weightForString: (NSString *)weightString
|
||||
|
@ -116,35 +116,35 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
|||
if (dict == nil)
|
||||
{
|
||||
dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt: 1], @"ultralight",
|
||||
[NSNumber numberWithInt: 2], @"thin",
|
||||
[NSNumber numberWithInt: 3], @"light",
|
||||
[NSNumber numberWithInt: 3], @"extralight",
|
||||
[NSNumber numberWithInt: 4], @"book",
|
||||
[NSNumber numberWithInt: 5], @"regular",
|
||||
[NSNumber numberWithInt: 5], @"plain",
|
||||
[NSNumber numberWithInt: 5], @"display",
|
||||
[NSNumber numberWithInt: 5], @"roman",
|
||||
[NSNumber numberWithInt: 5], @"semilight",
|
||||
[NSNumber numberWithInt: 6], @"medium",
|
||||
[NSNumber numberWithInt: 7], @"demi",
|
||||
[NSNumber numberWithInt: 7], @"demibold",
|
||||
[NSNumber numberWithInt: 8], @"semi",
|
||||
[NSNumber numberWithInt: 8], @"semibold",
|
||||
[NSNumber numberWithInt: 9], @"bold",
|
||||
[NSNumber numberWithInt: 10], @"extra",
|
||||
[NSNumber numberWithInt: 10], @"extrabold",
|
||||
[NSNumber numberWithInt: 11], @"heavy",
|
||||
[NSNumber numberWithInt: 11], @"heavyface",
|
||||
[NSNumber numberWithInt: 12], @"ultrabold",
|
||||
[NSNumber numberWithInt: 12], @"black",
|
||||
[NSNumber numberWithInt: 13], @"ultra",
|
||||
[NSNumber numberWithInt: 13], @"ultrablack",
|
||||
[NSNumber numberWithInt: 13], @"fat",
|
||||
[NSNumber numberWithInt: 14], @"extrablack",
|
||||
[NSNumber numberWithInt: 14], @"obese",
|
||||
[NSNumber numberWithInt: 14], @"nord",
|
||||
nil];
|
||||
[NSNumber numberWithInt: 1], @"ultralight",
|
||||
[NSNumber numberWithInt: 2], @"thin",
|
||||
[NSNumber numberWithInt: 3], @"light",
|
||||
[NSNumber numberWithInt: 3], @"extralight",
|
||||
[NSNumber numberWithInt: 4], @"book",
|
||||
[NSNumber numberWithInt: 5], @"regular",
|
||||
[NSNumber numberWithInt: 5], @"plain",
|
||||
[NSNumber numberWithInt: 5], @"display",
|
||||
[NSNumber numberWithInt: 5], @"roman",
|
||||
[NSNumber numberWithInt: 5], @"semilight",
|
||||
[NSNumber numberWithInt: 6], @"medium",
|
||||
[NSNumber numberWithInt: 7], @"demi",
|
||||
[NSNumber numberWithInt: 7], @"demibold",
|
||||
[NSNumber numberWithInt: 8], @"semi",
|
||||
[NSNumber numberWithInt: 8], @"semibold",
|
||||
[NSNumber numberWithInt: 9], @"bold",
|
||||
[NSNumber numberWithInt: 10], @"extra",
|
||||
[NSNumber numberWithInt: 10], @"extrabold",
|
||||
[NSNumber numberWithInt: 11], @"heavy",
|
||||
[NSNumber numberWithInt: 11], @"heavyface",
|
||||
[NSNumber numberWithInt: 12], @"ultrabold",
|
||||
[NSNumber numberWithInt: 12], @"black",
|
||||
[NSNumber numberWithInt: 13], @"ultra",
|
||||
[NSNumber numberWithInt: 13], @"ultrablack",
|
||||
[NSNumber numberWithInt: 13], @"fat",
|
||||
[NSNumber numberWithInt: 14], @"extrablack",
|
||||
[NSNumber numberWithInt: 14], @"obese",
|
||||
[NSNumber numberWithInt: 14], @"nord",
|
||||
nil];
|
||||
RETAIN(dict);
|
||||
}
|
||||
|
||||
|
@ -166,11 +166,11 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
|||
if (arr == nil)
|
||||
{
|
||||
arr = [NSArray arrayWithObjects: @"", @"ultralight",
|
||||
@"thin", @"light", @"book", @"regular",
|
||||
@"medium", @"demibold", @"semibold",
|
||||
@"bold", @"extrabold", @"heavy",
|
||||
@"black", @"ultrablack", @"extrablack",
|
||||
nil];
|
||||
@"thin", @"light", @"book", @"regular",
|
||||
@"medium", @"demibold", @"semibold",
|
||||
@"bold", @"extrabold", @"heavy",
|
||||
@"black", @"ultrablack", @"extrablack",
|
||||
nil];
|
||||
RETAIN(arr);
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone *)zone
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
{
|
||||
GSFontInfo *copy;
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
|
@ -295,7 +295,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
|||
|
||||
/* We really want a mutable class for this, but this is quick and easy since
|
||||
it's not really a public class anyway */
|
||||
- mutableCopyWithZone: (NSZone *)zone
|
||||
- (id) mutableCopyWithZone: (NSZone *)zone
|
||||
{
|
||||
GSFontInfo *copy;
|
||||
copy = (GSFontInfo*) NSCopyObject (self, 0, zone);
|
||||
|
@ -406,7 +406,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
|||
return xHeight;
|
||||
}
|
||||
|
||||
- (float)defaultLineHeightForFont
|
||||
- (float) defaultLineHeightForFont
|
||||
{
|
||||
// ascent plus descent plus some suitable linegap
|
||||
return [self ascender] - [self descender] + [self pointSize]/ 11.0;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
|
||||
#include <AppKit/NSGraphicsContext.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
|
@ -115,9 +116,8 @@ NSArray *_preferredFonts;
|
|||
/* Class for fonts */
|
||||
static Class NSFontClass = 0;
|
||||
|
||||
/* Store all created fonts for reuse.
|
||||
ATTENTION: This way a font will never get freed! */
|
||||
static NSMutableDictionary* globalFontDictionary = nil;
|
||||
/* Cache all created fonts for reuse. */
|
||||
static NSMapTable* globalFontMap = 0;
|
||||
|
||||
static NSUserDefaults *defaults = nil;
|
||||
|
||||
|
@ -149,7 +149,7 @@ setNSFont(NSString* key, NSFont* font)
|
|||
userCacheNeedsRecomputing = YES;
|
||||
userFixedCacheNeedsRecomputing = YES;
|
||||
|
||||
/* Don't care about errors*/
|
||||
/* Don't care about errors */
|
||||
[defaults synchronize];
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,8 @@ setNSFont(NSString* key, NSFont* font)
|
|||
if (self == [NSFont class])
|
||||
{
|
||||
NSFontClass = self;
|
||||
globalFontDictionary = [NSMutableDictionary new];
|
||||
globalFontMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks, 64);
|
||||
|
||||
if (defaults == nil)
|
||||
{
|
||||
|
@ -483,19 +484,18 @@ setNSFont(NSString* key, NSFont* font)
|
|||
NSString *nameWithMatrix;
|
||||
|
||||
nameWithMatrix = [NSString stringWithFormat:
|
||||
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f",
|
||||
aFontName,
|
||||
fontMatrix[0], fontMatrix[1], fontMatrix[2],
|
||||
fontMatrix[3], fontMatrix[4], fontMatrix[5]];
|
||||
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f", aFontName,
|
||||
fontMatrix[0], fontMatrix[1], fontMatrix[2],
|
||||
fontMatrix[3], fontMatrix[4], fontMatrix[5]];
|
||||
|
||||
/* Check whether the font is cached */
|
||||
font = [globalFontDictionary objectForKey: nameWithMatrix];
|
||||
if(font == nil)
|
||||
font = (id)NSMapGet(globalFontMap, (void*)nameWithMatrix);
|
||||
if (font == nil)
|
||||
{
|
||||
font = AUTORELEASE([[NSFontClass alloc] initWithName: aFontName
|
||||
matrix: fontMatrix]);
|
||||
matrix: fontMatrix]);
|
||||
/* Cache the font for later use */
|
||||
[globalFontDictionary setObject: font forKey: nameWithMatrix];
|
||||
NSMapInsert(globalFontMap, (void*)nameWithMatrix, (void*)font);
|
||||
}
|
||||
|
||||
return font;
|
||||
|
@ -555,6 +555,13 @@ setNSFont(NSString* key, NSFont* font)
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
NSString *nameWithMatrix = [NSString alloc];
|
||||
|
||||
nameWithMatrix = [nameWithMatrix initWithFormat:
|
||||
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f", fontName,
|
||||
matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]];
|
||||
NSMapRemove(globalFontMap, (void*)nameWithMatrix);
|
||||
RELEASE(nameWithMatrix);
|
||||
RELEASE(fontName);
|
||||
RELEASE(fontInfo);
|
||||
[super dealloc];
|
||||
|
|
Loading…
Reference in a new issue