When the family changes, score all faces in the new family and select the one that differs the least from what we want.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14504 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2002-09-21 15:52:42 +00:00
parent 86c6559b88
commit d1780257ae
2 changed files with 64 additions and 7 deletions

View file

@ -1,4 +1,11 @@
2002-09-29 Richard Frith-Macdonald <rfm@gnu.org>
2002-09-21 17:48 Alexander Malmberg <alexander@malmberg.org>
* Source/NSFontPanel.m (-_familySelectionChanged:, score_difference):
If an exact match for the wanted weight and traits can't be found,
score all faces in the new family and select the one that differs
the least.
2002-09-19 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GNUmakefile: Set flags to generate documentation using
templates.

View file

@ -738,6 +738,31 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
@implementation NSFontPanel (NSBrowserDelegate)
static int score_difference(int weight1, int traits1,
int weight2, int traits2)
{
int score, t;
score = (weight1 - weight2);
score = 10 * score * score;
t = traits1 ^ traits2;
if (t & NSFixedPitchFontMask) score += 1000;
if (t & NSCompressedFontMask) score += 150;
if (t & NSPosterFontMask) score += 200;
if (t & NSSmallCapsFontMask) score += 200;
if (t & NSCondensedFontMask) score += 150;
if (t & NSExpandedFontMask) score += 150;
if (t & NSNarrowFontMask) score += 150;
if (t & NSBoldFontMask) score += 20;
if (t & NSItalicFontMask) score += 45;
return score;
}
- (void) _familySelectionChanged: (id)sender
{
NSFontManager *fm = [NSFontManager sharedFontManager];
@ -749,16 +774,41 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
ASSIGN(_faceList, [fm availableMembersOfFontFamily:
[_familyList objectAtIndex: row]]);
_family = row;
// Select a face with similar properties
// Select a face with the same properties
for (i = 0; i < [_faceList count]; i++)
{
NSArray *font_info = [_faceList objectAtIndex: i];
if (([[font_info objectAtIndex: 2] intValue] == _weight) &&
([[font_info objectAtIndex: 3] unsignedIntValue] == _traits))
break;
if (([[font_info objectAtIndex: 2] intValue] == _weight)
&& ([[font_info objectAtIndex: 3] unsignedIntValue] == _traits))
break;
}
// Find the face that differs the least from what we want
if (i == [_faceList count])
{
int best, best_score, score;
best_score = 1e6;
best = -1;
for (i = 0; i < [_faceList count]; i++)
{
NSArray *font_info = [_faceList objectAtIndex: i];
score = score_difference(_weight, _traits,
[[font_info objectAtIndex: 2] intValue],
[[font_info objectAtIndex: 3] unsignedIntValue]);
if (score < best_score)
{
best = i;
best_score = score;
}
}
if (best != -1)
i = best;
}
if (i == [_faceList count])
i = 0;