Lot of work

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6070 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2000-02-22 17:49:04 +00:00
parent 31a05a9e19
commit 9588b7579c

View file

@ -137,12 +137,20 @@ static Class fontPanelClass = Nil;
{ {
self = [super init]; self = [super init];
_action = @selector(fontChanged:); _action = @selector(changeFont:);
_storedTag = NSNoFontChangeAction; _storedTag = NSNoFontChangeAction;
return self; return self;
} }
- (void) dealloc
{
TEST_RELEASE(_selectedFont);
TEST_RELEASE(_fontMenu);
[super dealloc];
}
// //
// information on available fonts // information on available fonts
// //
@ -156,8 +164,10 @@ static Class fontPanelClass = Nil;
for (i=0; i < [fontsList count]; i++) for (i=0; i < [fontsList count]; i++)
{ {
NSFont *font = (NSFont *)[fontsList objectAtIndex: i]; NSFont *font = (NSFont *)[fontsList objectAtIndex: i];
NSString *name = [font fontName];
[fontNames addObject: [font fontName]];
if ([self _includeFont: name])
[fontNames addObject: name];
} }
return fontNames; return fontNames;
@ -183,25 +193,32 @@ static Class fontPanelClass = Nil;
- (NSArray *)availableFontNamesWithTraits:(NSFontTraitMask)fontTraitMask - (NSArray *)availableFontNamesWithTraits:(NSFontTraitMask)fontTraitMask
{ {
int i; int i, j;
NSArray *fontsList = [self _allFonts]; NSArray *fontFamilies = [self availableFontFamilies];
NSMutableSet *fontNames = [NSMutableSet setWithCapacity: NSMutableArray *fontNames = [NSMutableArray array];
[fontsList count]];
NSFontTraitMask traits; NSFontTraitMask traits;
for (i=0; i < [fontsList count]; i++) for (i=0; i < [fontFamilies count]; i++)
{ {
NSFont *font = (NSFont *)[fontsList objectAtIndex: i]; NSArray *fontDefs = [self availableMembersOfFontFamily:
[fontFamilies objectAtIndex: i]];
traits = [self traitsOfFont: font];
// Check if the font has exactly the given mask for (j=0; j < [fontDefs count]; j++)
if (traits == fontTraitMask) {
{ NSArray *fontDef = [fontDefs objectAtIndex: j];
[fontNames addObject: [font fontName]]; 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];
}
}
} }
return [fontNames allObjects]; return fontNames;
} }
// This are somewhat strange methods, as they are not in the list, // This are somewhat strange methods, as they are not in the list,
@ -218,16 +235,20 @@ static Class fontPanelClass = Nil;
if ([[font familyName] isEqualToString: family]) if ([[font familyName] isEqualToString: family])
{ {
NSMutableArray *fontDef = [NSMutableArray arrayWithCapacity: 4]; NSString *name = [font fontName];
[fontDef addObject: [font fontName]]; if ([self _includeFont: name])
// TODO How do I get the font extention name? {
[fontDef addObject: @""]; NSMutableArray *fontDef = [NSMutableArray arrayWithCapacity: 4];
[fontDef addObject: [NSNumber numberWithInt: [fontDef addObject: name];
[self weightOfFont: font]]]; // TODO How do I get the font extention name?
[fontDef addObject: [NSNumber numberWithUnsignedInt: [fontDef addObject: @""];
[self traitsOfFont: font]]]; [fontDef addObject: [NSNumber numberWithInt:
[fontDefs addObject: fontDef]; [self weightOfFont: font]]];
[fontDef addObject: [NSNumber numberWithUnsignedInt:
[self traitsOfFont: font]]];
[fontDefs addObject: fontDef];
}
} }
} }
@ -248,8 +269,8 @@ static Class fontPanelClass = Nil;
- (void)setSelectedFont:(NSFont *)fontObject - (void)setSelectedFont:(NSFont *)fontObject
isMultiple:(BOOL)flag isMultiple:(BOOL)flag
{ {
_selectedFont = fontObject; ASSIGN(_selectedFont, fontObject);
_multible = flag; _multiple = flag;
if (_fontMenu != nil) if (_fontMenu != nil)
{ {
@ -299,7 +320,8 @@ static Class fontPanelClass = Nil;
// TODO Update the rest of the font menu to reflect this font // TODO Update the rest of the font menu to reflect this font
} }
[fontPanel setPanelFont: fontObject isMultiple: flag]; if (fontPanel != nil)
[fontPanel setPanelFont: fontObject isMultiple: flag];
} }
- (NSFont *)selectedFont - (NSFont *)selectedFont
@ -309,7 +331,7 @@ static Class fontPanelClass = Nil;
- (BOOL)isMultiple - (BOOL)isMultiple
{ {
return _multible; return _multiple;
} }
// //
@ -322,8 +344,9 @@ static Class fontPanelClass = Nil;
[self sendAction]; [self sendAction];
// We update our own selected font // We update our own selected font
[self setSelectedFont: [self convertFont: _selectedFont] if (_selectedFont != nil)
isMultiple: _multible]; [self setSelectedFont: [self convertFont: _selectedFont]
isMultiple: _multiple];
} }
- (void)removeFontTrait:(id)sender - (void)removeFontTrait:(id)sender
@ -333,8 +356,9 @@ static Class fontPanelClass = Nil;
[self sendAction]; [self sendAction];
// We update our own selected font // We update our own selected font
[self setSelectedFont: [self convertFont: _selectedFont] if (_selectedFont != nil)
isMultiple: _multible]; [self setSelectedFont: [self convertFont: _selectedFont]
isMultiple: _multiple];
} }
- (void)modifyFont:(id)sender - (void)modifyFont:(id)sender
@ -343,8 +367,9 @@ static Class fontPanelClass = Nil;
[self sendAction]; [self sendAction];
// We update our own selected font // We update our own selected font
[self setSelectedFont: [self convertFont: _selectedFont] if (_selectedFont != nil)
isMultiple: _multible]; [self setSelectedFont: [self convertFont: _selectedFont]
isMultiple: _multiple];
} }
- (void)modifyFontViaPanel:(id)sender - (void)modifyFontViaPanel:(id)sender
@ -353,8 +378,9 @@ static Class fontPanelClass = Nil;
[self sendAction]; [self sendAction];
// We update our own selected font // We update our own selected font
[self setSelectedFont: [self convertFont: _selectedFont] if (_selectedFont != nil)
isMultiple: _multible]; [self setSelectedFont: [self convertFont: _selectedFont]
isMultiple: _multiple];
} }
// //
@ -363,13 +389,23 @@ static Class fontPanelClass = Nil;
- (NSFont *)convertFont:(NSFont *)fontObject - (NSFont *)convertFont:(NSFont *)fontObject
{ {
NSFont *newFont = fontObject; NSFont *newFont = fontObject;
int i;
float size;
float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
14.0, 16.0, 18.0, 24.0, 36.0, 48.0, 64.0};
if (fontObject == nil)
return nil;
switch (_storedTag) switch (_storedTag)
{ {
case NSNoFontChangeAction: case NSNoFontChangeAction:
break; break;
case NSViaPanelFontAction: case NSViaPanelFontAction:
// TODO get the panel to convert the font with panelConvertFont: if (fontPanel != nil)
{
newFont = [fontPanel panelConvertFont: fontObject];
}
break; break;
case NSAddTraitFontAction: case NSAddTraitFontAction:
newFont = [self convertFont: fontObject toHaveTrait: _trait]; newFont = [self convertFont: fontObject toHaveTrait: _trait];
@ -378,14 +414,30 @@ static Class fontPanelClass = Nil;
newFont = [self convertFont: fontObject toNotHaveTrait: _trait]; newFont = [self convertFont: fontObject toNotHaveTrait: _trait];
break; break;
case NSSizeUpFontAction: case NSSizeUpFontAction:
// FIXME: How much should we size up? size = [fontObject pointSize];
for (i = 0; i < sizeof(sizes)/sizeof(float); i++)
{
if (sizes[i] > size)
{
size = sizes [i];
break;
}
}
newFont = [self convertFont: fontObject newFont = [self convertFont: fontObject
toSize: [fontObject pointSize]+1.0]; toSize: size];
break; break;
case NSSizeDownFontAction: case NSSizeDownFontAction:
// FIXME: How much should we size down? size = [fontObject pointSize];
for (i = sizeof(sizes)/sizeof(float) -1; i >= 0; i--)
{
if (sizes[i] < size)
{
size = sizes[i];
break;
}
}
newFont = [self convertFont: fontObject newFont = [self convertFont: fontObject
toSize: [fontObject pointSize]-1.0]; toSize: size];
break; break;
case NSHeavierFontAction: case NSHeavierFontAction:
newFont = [self convertWeight: YES ofFont: fontObject]; newFont = [self convertWeight: YES ofFont: fontObject];
@ -546,22 +598,52 @@ static Class fontPanelClass = Nil;
float size = [fontObject pointSize]; float size = [fontObject pointSize];
NSString *family = [fontObject familyName]; NSString *family = [fontObject familyName];
int w = [self weightOfFont: fontObject]; int w = [self weightOfFont: fontObject];
// We check what weights we have for this family. We must
// also check to see if that font has the correct traits!
NSArray *fontDefs = [self availableMembersOfFontFamily: family];
if (upFlag) if (upFlag)
{ {
int i;
// The documentation is a bit unclear about the range of weights // The documentation is a bit unclear about the range of weights
// sometimes it says 0 to 9 and sometimes 0 to 15 // sometimes it says 0 to 9 and sometimes 0 to 15
w = MIN(15, w+1); int next_w = 15;
for (i = 0; i < [fontDefs count]; i++)
{
NSArray *fontDef = [fontDefs objectAtIndex: i];
int w1 = [[fontDef objectAtIndex: 2] intValue];
if (w1 > w && w1 < next_w &&
[[fontDef objectAtIndex: 3] unsignedIntValue] == trait)
next_w = w1;
}
w = next_w;
} }
else else
{ {
w = MAX(0, w-1); int i;
int next_w = 0;
for (i = 0; i < [fontDefs count]; i++)
{
NSArray *fontDef = [fontDefs objectAtIndex: i];
int w1 = [[fontDef objectAtIndex: 2] intValue];
if (w1 < w && w1 > next_w &&
[[fontDef objectAtIndex: 3] unsignedIntValue] == trait)
next_w = w1;
}
w = next_w;
} }
newFont = [self fontWithFamily: family newFont = [self fontWithFamily: family
traits: trait traits: trait
weight: w weight: w
size: size]; size: size];
if (newFont == nil) if (newFont == nil)
return fontObject; return fontObject;
else else
@ -579,18 +661,24 @@ static Class fontPanelClass = Nil;
NSArray *fontDefs = [self availableMembersOfFontFamily: family]; NSArray *fontDefs = [self availableMembersOfFontFamily: family];
int i; int i;
//NSLog(@"Searching font %@:%i:%i", family, weight, traits);
for (i = 0; i < [fontDefs count]; i++) for (i = 0; i < [fontDefs count]; i++)
{ {
NSArray *fontDef = [fontDefs objectAtIndex: i]; NSArray *fontDef = [fontDefs objectAtIndex: i];
if (([[fontDef objectAtIndex: 3] intValue] == weight) && //NSLog(@"Testing font %@:%i:%i", [fontDef objectAtIndex: 0],
([[fontDef objectAtIndex: 4] unsignedIntValue] == traits)) // [[fontDef objectAtIndex: 2] intValue],
// [[fontDef objectAtIndex: 3] unsignedIntValue]);
if (([[fontDef objectAtIndex: 2] intValue] == weight) &&
([[fontDef objectAtIndex: 3] unsignedIntValue] == traits))
{ {
return [NSFont fontWithName: [fontDef objectAtIndex: 1] //NSLog(@"Found font");
return [NSFont fontWithName: [fontDef objectAtIndex: 0]
size: size]; size: size];
} }
} }
//NSLog(@"Didnt find font");
return nil; return nil;
} }
@ -612,22 +700,30 @@ static Class fontPanelClass = Nil;
- (BOOL)fontNamed:(NSString *)typeface - (BOOL)fontNamed:(NSString *)typeface
hasTraits:(NSFontTraitMask)fontTraitMask; hasTraits:(NSFontTraitMask)fontTraitMask;
{ {
int i; int i, j;
NSArray *fontsList = [self _allFonts]; NSArray *fontFamilies = [self availableFontFamilies];
NSFontTraitMask traits;
for (i=0; i < [fontsList count]; i++)
for (i=0; i < [fontFamilies count]; i++)
{ {
NSFont *font = (NSFont *)[fontsList objectAtIndex: i]; NSArray *fontDefs = [self availableMembersOfFontFamily:
[fontFamilies objectAtIndex: i]];
if ([[font fontName] isEqualToString: typeface])
for (j=0; j < [fontDefs count]; j++)
{ {
// FIXME: This is not exactly the right condition NSArray *fontDef = [fontDefs objectAtIndex: j];
if (([self traitsOfFont: font] & fontTraitMask) == fontTraitMask)
if ([[fontDef objectAtIndex: 3] isEqualToString: typeface])
{ {
return YES; traits = [[fontDef objectAtIndex: 3] unsignedIntValue];
// FIXME: This is not exactly the right condition
if ((traits & fontTraitMask) == fontTraitMask)
{
return YES;
}
else
return NO;
} }
else
return NO;
} }
} }
@ -658,7 +754,9 @@ static Class fontPanelClass = Nil;
[[_fontMenu itemAtIndex: i] setEnabled: flag]; [[_fontMenu itemAtIndex: i] setEnabled: flag];
} }
} }
[fontPanel setEnabled: flag];
if (fontPanel != nil)
[fontPanel setEnabled: flag];
} }
// //
@ -669,7 +767,9 @@ static Class fontPanelClass = Nil;
if (create && _fontMenu == nil) if (create && _fontMenu == nil)
{ {
NSMenuItem *menuItem; NSMenuItem *menuItem;
// As the font menu is stored in a instance variable we
// dont autorelease it
_fontMenu = [NSMenu new]; _fontMenu = [NSMenu new];
[_fontMenu setTitle: @"Font Menu"]; [_fontMenu setTitle: @"Font Menu"];
@ -755,7 +855,7 @@ static Class fontPanelClass = Nil;
- (void)setDelegate:(id)anObject - (void)setDelegate:(id)anObject
{ {
ASSIGN(_delegate, anObject); _delegate = anObject;
} }
// //
@ -805,6 +905,7 @@ static Class fontPanelClass = Nil;
{ {
NSArray *fontsList; NSArray *fontsList;
NSLog(@"NSFontManager _allFonts called: This should not happen");
// Allocate the font list // Allocate the font list
fontsList = [NSMutableArray array]; fontsList = [NSMutableArray array];