mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 04:20:46 +00:00
Changed GSFontEnumerator so that only [enumerateFontsAndFamilies]
must be subclassed. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11377 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bb47d9c045
commit
f2816c29d7
1 changed files with 18 additions and 69 deletions
|
@ -37,10 +37,6 @@ static Class fontInfoClass = Nil;
|
||||||
|
|
||||||
static GSFontEnumerator *sharedEnumerator = nil;
|
static GSFontEnumerator *sharedEnumerator = nil;
|
||||||
|
|
||||||
@interface NSFontManager (GNUstepBackend)
|
|
||||||
- (BOOL) _includeFont: (NSString*)fontName;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation GSFontEnumerator
|
@implementation GSFontEnumerator
|
||||||
|
|
||||||
+ (void) setDefaultClass: (Class)defaultClass
|
+ (void) setDefaultClass: (Class)defaultClass
|
||||||
|
@ -48,95 +44,48 @@ static GSFontEnumerator *sharedEnumerator = nil;
|
||||||
fontEnumeratorClass = defaultClass;
|
fontEnumeratorClass = defaultClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithFontManager: manager
|
- (id) init
|
||||||
{
|
{
|
||||||
[super init];
|
[super init];
|
||||||
fontManager = manager;
|
[self enumerateFontsAndFamilies];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ sharedEnumeratorWithFontManager: manager
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
RELEASE(allFontNames);
|
||||||
|
RELEASE(allFontFamilies);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (GSFontEnumerator*) sharedEnumerator
|
||||||
{
|
{
|
||||||
if (!sharedEnumerator)
|
if (!sharedEnumerator)
|
||||||
sharedEnumerator = [[fontEnumeratorClass alloc]
|
sharedEnumerator = [[fontEnumeratorClass alloc] init];
|
||||||
initWithFontManager: manager];
|
|
||||||
return sharedEnumerator;
|
return sharedEnumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) allFonts
|
- (void) enumerateFontsAndFamilies
|
||||||
{
|
{
|
||||||
|
// This method has to set up the ivars allFontNames and allFontFamilies
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) availableFonts
|
- (NSArray*) availableFonts
|
||||||
{
|
{
|
||||||
int i;
|
return allFontNames;
|
||||||
NSArray *fontsList;
|
|
||||||
NSMutableArray *fontNames;
|
|
||||||
|
|
||||||
fontsList = [self allFonts];
|
|
||||||
fontNames = [NSMutableArray arrayWithCapacity: [fontsList count]];
|
|
||||||
|
|
||||||
for (i = 0; i < [fontsList count]; i++)
|
|
||||||
{
|
|
||||||
GSFontInfo *font = (GSFontInfo*)[fontsList objectAtIndex: i];
|
|
||||||
NSString *name = [font fontName];
|
|
||||||
|
|
||||||
if ([fontManager _includeFont: name])
|
|
||||||
[fontNames addObject: name];
|
|
||||||
}
|
|
||||||
|
|
||||||
return fontNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) availableFontFamilies
|
- (NSArray*) availableFontFamilies
|
||||||
{
|
{
|
||||||
int i;
|
return [[allFontFamilies allKeys] sortedArrayUsingSelector:
|
||||||
NSArray *fontsList;
|
@selector(compare:)];
|
||||||
NSMutableSet *fontFamilies;
|
|
||||||
|
|
||||||
fontsList = [self allFonts];
|
|
||||||
fontFamilies = [NSMutableSet setWithCapacity: [fontsList count]];
|
|
||||||
for (i = 0; i < [fontsList count]; i++)
|
|
||||||
{
|
|
||||||
GSFontInfo *font = (GSFontInfo*)[fontsList objectAtIndex: i];
|
|
||||||
|
|
||||||
[fontFamilies addObject: [font familyName]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [fontFamilies allObjects];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) availableMembersOfFontFamily: (NSString*)family
|
- (NSArray*) availableMembersOfFontFamily: (NSString*)family
|
||||||
{
|
{
|
||||||
int i, j;
|
return [allFontFamilies objectForKey: family];
|
||||||
NSArray *fontFamilies = [self availableFontFamilies];
|
|
||||||
NSMutableArray *fontNames = [NSMutableArray array];
|
|
||||||
NSFontTraitMask traits;
|
|
||||||
|
|
||||||
for (i = 0; i < [fontFamilies count]; i++)
|
|
||||||
{
|
|
||||||
NSArray *fontDefs = [self availableMembersOfFontFamily:
|
|
||||||
[fontFamilies objectAtIndex: i]];
|
|
||||||
|
|
||||||
for (j = 0; j < [fontDefs count]; j++)
|
|
||||||
{
|
|
||||||
NSArray *fontDef = [fontDefs objectAtIndex: j];
|
|
||||||
|
|
||||||
traits = [[fontDef objectAtIndex: 3] unsignedIntValue];
|
|
||||||
// Check if the font has exactly the given mask
|
|
||||||
//if (traits == fontTraitMask)
|
|
||||||
{
|
|
||||||
NSString *name = [fontDef objectAtIndex: 0];
|
|
||||||
|
|
||||||
if ([fontManager _includeFont: name])
|
|
||||||
[fontNames addObject: name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fontNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue