mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Ask the delegate whether a font should be included in the font panel in NSFontPanel, not when returning fonts from NSFontManager.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17980 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
98a44831b1
commit
a019b68603
3 changed files with 109 additions and 74 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2003-10-26 15:18 Alexander Malmberg <alexander@malmberg.org>
|
||||
Matt Rice <ratmice@yahoo.com>
|
||||
|
||||
* Source/NSFontManager.m (-availableFonts, -availableFontFamilies,
|
||||
availableMembersOfFontFamily:): Don't check delegate; always return
|
||||
all fonts.
|
||||
(-_includeFont:): Move...
|
||||
|
||||
* Source/NSFontPanel.m (_includeFont:delegate:): Here.
|
||||
(-_familySelectionChanged:, reloadDefaultFontFamilies): Use that
|
||||
method to check with the delegate which fonts should be included in
|
||||
the font panel.
|
||||
(-_doPreview, -_fontForSelection:): Check that the face list isn't
|
||||
empty before accessing it.
|
||||
(-_getOriginalSize): Move to the Private category to match the
|
||||
@interface.
|
||||
|
||||
2003-10-25 16:52 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Source/GSNibTemplates.m: initWithFrame is not supposed to be called
|
||||
|
|
|
@ -49,9 +49,6 @@ static NSFontPanel *fontPanel = nil;
|
|||
static Class fontManagerClass = Nil;
|
||||
static Class fontPanelClass = Nil;
|
||||
|
||||
@interface NSFontManager (GNUstepPrivate)
|
||||
- (BOOL) _includeFont: (NSString*)fontName;
|
||||
@end
|
||||
|
||||
@implementation NSFontManager
|
||||
|
||||
|
@ -125,22 +122,7 @@ static Class fontPanelClass = Nil;
|
|||
*/
|
||||
- (NSArray*) availableFonts
|
||||
{
|
||||
unsigned int i;
|
||||
NSArray *fontsList = [_fontEnumerator availableFonts];
|
||||
NSMutableArray *fontNames = [NSMutableArray
|
||||
arrayWithCapacity: [fontsList count]];
|
||||
|
||||
for (i = 0; i < [fontsList count]; i++)
|
||||
{
|
||||
NSString *name = [fontsList objectAtIndex: i];
|
||||
|
||||
if ([self _includeFont: name])
|
||||
{
|
||||
[fontNames addObject: name];
|
||||
}
|
||||
}
|
||||
|
||||
return fontNames;
|
||||
return [_fontEnumerator availableFonts];
|
||||
}
|
||||
|
||||
- (NSArray*) availableFontFamilies
|
||||
|
@ -167,12 +149,7 @@ static Class fontPanelClass = Nil;
|
|||
traits = [[fontDef objectAtIndex: 3] unsignedIntValue];
|
||||
// Check if the font has exactly the given mask
|
||||
if (traits == fontTraitMask)
|
||||
{
|
||||
NSString *name = [fontDef objectAtIndex: 0];
|
||||
|
||||
if ([self _includeFont: name])
|
||||
[fontNames addObject: name];
|
||||
}
|
||||
[fontNames addObject: [fontDef objectAtIndex: 0]];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,23 +158,7 @@ static Class fontPanelClass = Nil;
|
|||
|
||||
- (NSArray*) availableMembersOfFontFamily: (NSString*)family
|
||||
{
|
||||
unsigned int i;
|
||||
NSArray *fontsList = [_fontEnumerator availableMembersOfFontFamily: family];
|
||||
NSMutableArray *fonts = [NSMutableArray
|
||||
arrayWithCapacity: [fontsList count]];
|
||||
|
||||
for (i = 0; i < [fontsList count]; i++)
|
||||
{
|
||||
NSArray *fontDef = [fontsList objectAtIndex: i];
|
||||
NSString *name = [fontDef objectAtIndex: 0];
|
||||
|
||||
if ([self _includeFont: name])
|
||||
{
|
||||
[fonts addObject: fontDef];
|
||||
}
|
||||
}
|
||||
|
||||
return fonts;
|
||||
return [_fontEnumerator availableMembersOfFontFamily: family];
|
||||
}
|
||||
|
||||
- (NSString*) localizedNameForFamily: (NSString*)family
|
||||
|
@ -997,18 +958,3 @@ static Class fontPanelClass = Nil;
|
|||
|
||||
@end
|
||||
|
||||
@implementation NSFontManager (GNUstepPrivate)
|
||||
|
||||
/*
|
||||
* Ask delegate if to include a font
|
||||
*/
|
||||
- (BOOL) _includeFont: (NSString*)fontName
|
||||
{
|
||||
if ((_delegate != nil)
|
||||
&& [_delegate respondsToSelector: @selector(fontManager: willIncludeFont:)])
|
||||
return [_delegate fontManager: self willIncludeFont: fontName];
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -93,6 +93,8 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
|
||||
- (void) _getOriginalSize;
|
||||
- (id)_initWithoutGModel;
|
||||
|
||||
- (BOOL) _includeFont: (NSString *)fontName delegate: (id)delegate;
|
||||
@end
|
||||
|
||||
@implementation NSFontPanel
|
||||
|
@ -173,9 +175,36 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
- (void) reloadDefaultFontFamilies
|
||||
{
|
||||
NSFontManager *fm = [NSFontManager sharedFontManager];
|
||||
id fmDelegate = [fm delegate];
|
||||
NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser];
|
||||
NSArray *fontFamilies = [fm availableFontFamilies];
|
||||
unsigned int i,j;
|
||||
|
||||
DESTROY(_familyList);
|
||||
|
||||
/*
|
||||
Build an array of all families that have a font that will be included.
|
||||
*/
|
||||
_familyList = [[NSMutableArray alloc]
|
||||
initWithCapacity: [fontFamilies count]];
|
||||
|
||||
for (i = 0; i < [fontFamilies count]; i++)
|
||||
{
|
||||
NSArray *familyMembers;
|
||||
familyMembers = [fm availableMembersOfFontFamily:
|
||||
[fontFamilies objectAtIndex: i]];
|
||||
|
||||
for (j = 0; j < [familyMembers count]; j++)
|
||||
{
|
||||
if ([self _includeFont: [[familyMembers objectAtIndex: j] objectAtIndex: 0]
|
||||
delegate: fmDelegate])
|
||||
{
|
||||
[_familyList addObject: [fontFamilies objectAtIndex: i]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ASSIGN(_familyList, [fm availableFontFamilies]);
|
||||
// Reload the display.
|
||||
[familyBrowser loadColumnZero];
|
||||
// Reselect the current font. (Hopefully still there)
|
||||
|
@ -325,14 +354,6 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
}
|
||||
*/
|
||||
|
||||
- (void) _getOriginalSize
|
||||
{
|
||||
/* Used in setMinSize: */
|
||||
_originalMinSize = [self minSize];
|
||||
/* Used in setContentSize: */
|
||||
_originalSize = [[self contentView] frame].size;
|
||||
}
|
||||
|
||||
- (void) setAccessoryView: (NSView*)aView
|
||||
{
|
||||
NSRect accessoryViewFrame, bottomFrame;
|
||||
|
@ -487,7 +508,7 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
|
||||
@end
|
||||
|
||||
@implementation NSFontPanel (Privat)
|
||||
@implementation NSFontPanel (Private)
|
||||
|
||||
- (id) _initWithoutGModel
|
||||
{
|
||||
|
@ -779,7 +800,7 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
{
|
||||
familyName = [_familyList objectAtIndex: _family];
|
||||
}
|
||||
if (_face == -1)
|
||||
if (_face == -1 || ![_faceList count])
|
||||
{
|
||||
faceName = @"NoFace";
|
||||
}
|
||||
|
@ -816,7 +837,8 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
{
|
||||
float size;
|
||||
NSString *fontName;
|
||||
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
||||
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
||||
unsigned i = [_faceList count];
|
||||
|
||||
size = [sizeField floatValue];
|
||||
if (size == 0.0)
|
||||
|
@ -832,7 +854,6 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
}
|
||||
if (_face < 0)
|
||||
{
|
||||
unsigned i = [_faceList count];
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
|
@ -843,7 +864,15 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
}
|
||||
else
|
||||
{
|
||||
fontName = [[_faceList objectAtIndex: _face] objectAtIndex: 0];
|
||||
/*
|
||||
i really should be >= 0 here, except for the very obscure case where
|
||||
the delegate has refused all fonts (so that our family and face lists
|
||||
are completely empty).
|
||||
*/
|
||||
if (i)
|
||||
fontName = [[_faceList objectAtIndex: _face] objectAtIndex: 0];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
// FIXME: We should check if the font is correct
|
||||
|
@ -888,6 +917,31 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|||
[self _doPreview];
|
||||
}
|
||||
|
||||
/*
|
||||
Ask the NSFontManager:s delegate if a font should be included. For speed,
|
||||
the delegate is an argument; a repeat-caller can then cache it.
|
||||
*/
|
||||
- (BOOL) _includeFont: (NSString*)fontName delegate: (id)fmDelegate
|
||||
{
|
||||
if (fmDelegate != nil
|
||||
&& [fmDelegate respondsToSelector: @selector(fontManager:willIncludeFont:)])
|
||||
{
|
||||
return [fmDelegate fontManager: [NSFontManager sharedFontManager]
|
||||
willIncludeFont: fontName];
|
||||
}
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void) _getOriginalSize
|
||||
{
|
||||
/* Used in setMinSize: */
|
||||
_originalMinSize = [self minSize];
|
||||
/* Used in setContentSize: */
|
||||
_originalSize = [[self contentView] frame].size;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -921,13 +975,31 @@ static int score_difference(int weight1, int traits1,
|
|||
- (void) _familySelectionChanged: (id)sender
|
||||
{
|
||||
NSFontManager *fm = [NSFontManager sharedFontManager];
|
||||
id fmDelegate = [fm delegate];
|
||||
|
||||
NSBrowser *faceBrowser = [[self contentView] viewWithTag: NSFPFaceBrowser];
|
||||
NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser];
|
||||
int row = [familyBrowser selectedRowInColumn: 0];
|
||||
unsigned int i;
|
||||
|
||||
ASSIGN(_faceList, [fm availableMembersOfFontFamily:
|
||||
[_familyList objectAtIndex: row]]);
|
||||
unsigned int i;
|
||||
NSArray *entireFaceList;
|
||||
|
||||
|
||||
entireFaceList = [fm availableMembersOfFontFamily:
|
||||
[_familyList objectAtIndex:row]];
|
||||
|
||||
DESTROY(_faceList);
|
||||
_faceList = [[NSMutableArray alloc] initWithCapacity: [entireFaceList count]];
|
||||
|
||||
for (i = 0; i < [entireFaceList count]; i++)
|
||||
{
|
||||
id aFace = [entireFaceList objectAtIndex:i];
|
||||
if ([self _includeFont: [aFace objectAtIndex:0] delegate: fmDelegate])
|
||||
{
|
||||
[_faceList addObject: aFace];
|
||||
}
|
||||
}
|
||||
|
||||
_family = row;
|
||||
|
||||
// Select a face with the same properties
|
||||
|
|
Loading…
Reference in a new issue