mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 10:11:15 +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
ab43ceed49
commit
bbe972eef7
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>
|
2002-09-26 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/gnustep/gui/NSBrowserCell.h
|
* Headers/gnustep/gui/NSBrowserCell.h
|
||||||
|
|
|
@ -277,7 +277,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- copyWithZone: (NSZone *)zone
|
- (id) copyWithZone: (NSZone *)zone
|
||||||
{
|
{
|
||||||
GSFontInfo *copy;
|
GSFontInfo *copy;
|
||||||
if (NSShouldRetainWithZone(self, zone))
|
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
|
/* We really want a mutable class for this, but this is quick and easy since
|
||||||
it's not really a public class anyway */
|
it's not really a public class anyway */
|
||||||
- mutableCopyWithZone: (NSZone *)zone
|
- (id) mutableCopyWithZone: (NSZone *)zone
|
||||||
{
|
{
|
||||||
GSFontInfo *copy;
|
GSFontInfo *copy;
|
||||||
copy = (GSFontInfo*) NSCopyObject (self, 0, zone);
|
copy = (GSFontInfo*) NSCopyObject (self, 0, zone);
|
||||||
|
@ -406,7 +406,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
||||||
return xHeight;
|
return xHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float)defaultLineHeightForFont
|
- (float) defaultLineHeightForFont
|
||||||
{
|
{
|
||||||
// ascent plus descent plus some suitable linegap
|
// ascent plus descent plus some suitable linegap
|
||||||
return [self ascender] - [self descender] + [self pointSize]/ 11.0;
|
return [self ascender] - [self descender] + [self pointSize]/ 11.0;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSUserDefaults.h>
|
#include <Foundation/NSUserDefaults.h>
|
||||||
#include <Foundation/NSSet.h>
|
#include <Foundation/NSSet.h>
|
||||||
|
#include <Foundation/NSMapTable.h>
|
||||||
|
|
||||||
#include <AppKit/NSGraphicsContext.h>
|
#include <AppKit/NSGraphicsContext.h>
|
||||||
#include <AppKit/NSFont.h>
|
#include <AppKit/NSFont.h>
|
||||||
|
@ -115,9 +116,8 @@ NSArray *_preferredFonts;
|
||||||
/* Class for fonts */
|
/* Class for fonts */
|
||||||
static Class NSFontClass = 0;
|
static Class NSFontClass = 0;
|
||||||
|
|
||||||
/* Store all created fonts for reuse.
|
/* Cache all created fonts for reuse. */
|
||||||
ATTENTION: This way a font will never get freed! */
|
static NSMapTable* globalFontMap = 0;
|
||||||
static NSMutableDictionary* globalFontDictionary = nil;
|
|
||||||
|
|
||||||
static NSUserDefaults *defaults = nil;
|
static NSUserDefaults *defaults = nil;
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ setNSFont(NSString* key, NSFont* font)
|
||||||
userCacheNeedsRecomputing = YES;
|
userCacheNeedsRecomputing = YES;
|
||||||
userFixedCacheNeedsRecomputing = YES;
|
userFixedCacheNeedsRecomputing = YES;
|
||||||
|
|
||||||
/* Don't care about errors*/
|
/* Don't care about errors */
|
||||||
[defaults synchronize];
|
[defaults synchronize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,8 @@ setNSFont(NSString* key, NSFont* font)
|
||||||
if (self == [NSFont class])
|
if (self == [NSFont class])
|
||||||
{
|
{
|
||||||
NSFontClass = self;
|
NSFontClass = self;
|
||||||
globalFontDictionary = [NSMutableDictionary new];
|
globalFontMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSNonRetainedObjectMapValueCallBacks, 64);
|
||||||
|
|
||||||
if (defaults == nil)
|
if (defaults == nil)
|
||||||
{
|
{
|
||||||
|
@ -483,19 +484,18 @@ setNSFont(NSString* key, NSFont* font)
|
||||||
NSString *nameWithMatrix;
|
NSString *nameWithMatrix;
|
||||||
|
|
||||||
nameWithMatrix = [NSString stringWithFormat:
|
nameWithMatrix = [NSString stringWithFormat:
|
||||||
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f",
|
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f", aFontName,
|
||||||
aFontName,
|
|
||||||
fontMatrix[0], fontMatrix[1], fontMatrix[2],
|
fontMatrix[0], fontMatrix[1], fontMatrix[2],
|
||||||
fontMatrix[3], fontMatrix[4], fontMatrix[5]];
|
fontMatrix[3], fontMatrix[4], fontMatrix[5]];
|
||||||
|
|
||||||
/* Check whether the font is cached */
|
/* Check whether the font is cached */
|
||||||
font = [globalFontDictionary objectForKey: nameWithMatrix];
|
font = (id)NSMapGet(globalFontMap, (void*)nameWithMatrix);
|
||||||
if(font == nil)
|
if (font == nil)
|
||||||
{
|
{
|
||||||
font = AUTORELEASE([[NSFontClass alloc] initWithName: aFontName
|
font = AUTORELEASE([[NSFontClass alloc] initWithName: aFontName
|
||||||
matrix: fontMatrix]);
|
matrix: fontMatrix]);
|
||||||
/* Cache the font for later use */
|
/* Cache the font for later use */
|
||||||
[globalFontDictionary setObject: font forKey: nameWithMatrix];
|
NSMapInsert(globalFontMap, (void*)nameWithMatrix, (void*)font);
|
||||||
}
|
}
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
|
@ -555,6 +555,13 @@ setNSFont(NSString* key, NSFont* font)
|
||||||
|
|
||||||
- (void) dealloc
|
- (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(fontName);
|
||||||
RELEASE(fontInfo);
|
RELEASE(fontInfo);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue