2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSFont</title>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
<abstract>The font class</abstract>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
1997-04-22 18:23:58 +00:00
|
|
|
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
1997-02-18 00:29:25 +00:00
|
|
|
Date: February 1997
|
|
|
|
A completely rewritten version of the original source by Scott Christley.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
1997-08-18 17:10:23 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
#include <Foundation/NSSet.h>
|
2002-09-27 08:52:04 +00:00
|
|
|
#include <Foundation/NSMapTable.h>
|
2002-09-27 12:25:02 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-05-12 12:37:02 +00:00
|
|
|
#include <AppKit/NSGraphicsContext.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSFont.h>
|
|
|
|
#include <AppKit/NSFontManager.h>
|
2000-03-27 18:28:51 +00:00
|
|
|
#include <AppKit/GSFontInfo.h>
|
2002-05-08 03:28:09 +00:00
|
|
|
#include <AppKit/NSView.h>
|
2002-10-09 02:47:40 +00:00
|
|
|
#include <gnustep/gui/GSFusedSilicaContext.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2000-09-01 23:49:53 +00:00
|
|
|
/* We cache all the 4 default fonts after we first get them.
|
|
|
|
But when a default font is changed, the variable is set to YES
|
|
|
|
so all default fonts are forced to be recomputed. */
|
|
|
|
static BOOL systemCacheNeedsRecomputing = NO;
|
|
|
|
static BOOL boldSystemCacheNeedsRecomputing = NO;
|
|
|
|
static BOOL userCacheNeedsRecomputing = NO;
|
|
|
|
static BOOL userFixedCacheNeedsRecomputing = NO;
|
2002-09-27 12:25:02 +00:00
|
|
|
static NSFont *placeHolder = nil;
|
2000-09-01 23:49:53 +00:00
|
|
|
|
2001-05-21 15:24:20 +00:00
|
|
|
@interface NSFont (Private)
|
|
|
|
- (id) initWithName: (NSString*)name
|
2002-09-27 12:25:02 +00:00
|
|
|
matrix: (const float*)fontMatrix
|
2003-01-26 19:21:40 +00:00
|
|
|
fix: (BOOL)explicitlySet
|
|
|
|
screenFont: (BOOL)screenFont;
|
2001-05-21 15:24:20 +00:00
|
|
|
@end
|
|
|
|
|
2002-09-18 18:00:30 +00:00
|
|
|
static int currentVersion = 2;
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
/*
|
|
|
|
* Just to ensure that we use a standard name in the cache.
|
|
|
|
*/
|
|
|
|
static NSString*
|
2003-01-26 19:21:40 +00:00
|
|
|
newNameWithMatrix(NSString *name, const float *matrix, BOOL fix,
|
|
|
|
BOOL screenFont)
|
2002-09-27 12:25:02 +00:00
|
|
|
{
|
|
|
|
NSString *nameWithMatrix;
|
|
|
|
|
|
|
|
nameWithMatrix = [[NSString alloc] initWithFormat:
|
2003-01-26 19:21:40 +00:00
|
|
|
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f %c %c", name,
|
2002-09-27 12:25:02 +00:00
|
|
|
matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5],
|
2003-01-26 19:21:40 +00:00
|
|
|
(fix == NO) ? 'N' : 'Y',
|
|
|
|
screenFont ? 'S' : 'P'];
|
2002-09-27 12:25:02 +00:00
|
|
|
return nameWithMatrix;
|
|
|
|
}
|
|
|
|
|
2002-07-06 02:54:36 +00:00
|
|
|
/**
|
|
|
|
<unit>
|
|
|
|
<heading>NSFont</heading>
|
|
|
|
|
|
|
|
<p>The NSFont class allows control of the fonts used for displaying
|
|
|
|
text anywhere on the screen. The primary methods for getting a
|
|
|
|
particular font are -fontWithName:matrix: and -fontWithName:size: which
|
|
|
|
take the name and size of a particular font and return the NSFont object
|
|
|
|
associated with that font. In addition there are several convenience
|
|
|
|
mathods which make it easier to get certain types of fonts. </p>
|
|
|
|
|
|
|
|
<p>In particular, there are several methods to get the standard fonts
|
|
|
|
used by the Application to display text for a partiuclar purpose. See
|
|
|
|
the class methods listed below for more information. These default
|
|
|
|
fonts can be set using the user defaults system. The default
|
|
|
|
font names available are:
|
2002-08-29 10:07:51 +00:00
|
|
|
</p>
|
2002-07-06 02:54:36 +00:00
|
|
|
<list>
|
|
|
|
<item>NSBoldFont Helvetica-Bold</item>
|
|
|
|
<item>NSControlContentFont Helvetica</item>
|
|
|
|
<item>NSFont Helvetica (System Font)</item>
|
|
|
|
<item>NSLabelFont Helvetica</item>
|
|
|
|
<item>NSMenuFont Helvetica</item>
|
|
|
|
<item>NSMessageFont Helvetica</item>
|
|
|
|
<item>NSPaletteFont Helvetica-Bold</item>
|
|
|
|
<item>NSTitleBarFont Helvetica-Bold</item>
|
|
|
|
<item>NSToolTipsFont Helvetica</item>
|
|
|
|
<item>NSUserFixedPitchFont Courier</item>
|
|
|
|
<item>NSUserFont Helvetica</item>
|
|
|
|
</list>
|
2002-08-29 10:07:51 +00:00
|
|
|
<p>
|
|
|
|
The default sizes are:
|
|
|
|
</p>
|
2002-07-06 02:54:36 +00:00
|
|
|
<list>
|
|
|
|
<item>NSBoldFontSize (none)</item>
|
|
|
|
<item>NSControlContentFontSize (none)</item>
|
|
|
|
<item>NSFontSize 12 (System Font Size)</item>
|
|
|
|
<item>NSLabelFontSize 12</item>
|
|
|
|
<item>NSMenuFontSize (none)</item>
|
|
|
|
<item>NSMessageFontSize (none)</item>
|
|
|
|
<item>NSPaletteFontSize (none)</item>
|
|
|
|
<item>NSSmallFontSize 9</item>
|
|
|
|
<item>NSTitleBarFontSize (none)</item>
|
|
|
|
<item>NSToolTipsFontSize (none)</item>
|
|
|
|
<item>NSUserFixedPitchFontSize (none)</item>
|
|
|
|
<item>NSUserFontSize (none)</item>
|
|
|
|
</list>
|
2002-08-29 10:07:51 +00:00
|
|
|
<p>
|
2002-07-06 02:54:36 +00:00
|
|
|
Font sizes list with (none) default to NSFontSize.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
</unit> */
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSFont
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
/* Class variables*/
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2000-06-11 00:31:50 +00:00
|
|
|
/* Fonts that are preferred by the application */
|
|
|
|
NSArray *_preferredFonts;
|
|
|
|
|
2001-01-03 10:39:02 +00:00
|
|
|
/* Class for fonts */
|
|
|
|
static Class NSFontClass = 0;
|
|
|
|
|
2002-09-27 08:52:04 +00:00
|
|
|
/* Cache all created fonts for reuse. */
|
|
|
|
static NSMapTable* globalFontMap = 0;
|
2001-05-21 15:24:20 +00:00
|
|
|
|
2001-01-03 10:39:02 +00:00
|
|
|
static NSUserDefaults *defaults = nil;
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
NSFont*
|
|
|
|
getNSFont(NSString* key, NSString* defaultFontName, float fontSize)
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-10-10 23:27:51 +00:00
|
|
|
NSString *fontName;
|
|
|
|
NSFont *font;
|
|
|
|
|
2001-01-03 10:39:02 +00:00
|
|
|
fontName = [defaults objectForKey: key];
|
2000-04-29 08:53:33 +00:00
|
|
|
if (fontName == nil)
|
2002-10-10 23:27:51 +00:00
|
|
|
{
|
|
|
|
fontName = defaultFontName;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
if (fontSize == 0)
|
|
|
|
{
|
2001-01-03 10:39:02 +00:00
|
|
|
fontSize = [defaults floatForKey:
|
|
|
|
[NSString stringWithFormat: @"%@Size", key]];
|
2000-04-29 08:53:33 +00:00
|
|
|
}
|
1997-07-07 16:56:52 +00:00
|
|
|
|
2002-10-10 23:27:51 +00:00
|
|
|
font = [NSFontClass fontWithName: fontName size: fontSize];
|
|
|
|
|
|
|
|
/* That font couldn't be found (?). */
|
|
|
|
if (font == nil)
|
|
|
|
{
|
|
|
|
/* Try the same size, but the defaultFontName. */
|
|
|
|
font = [NSFontClass fontWithName: defaultFontName size: fontSize];
|
|
|
|
|
|
|
|
if (font == nil)
|
|
|
|
{
|
|
|
|
/* Try the default font name and size. */
|
|
|
|
fontSize = [defaults floatForKey:
|
|
|
|
[NSString stringWithFormat: @"%@Size", key]];
|
|
|
|
|
|
|
|
font = [NSFontClass fontWithName: defaultFontName size: fontSize];
|
|
|
|
|
|
|
|
/* It seems we can't get any font here! Try some well known
|
|
|
|
* fonts as a last resort. */
|
|
|
|
if (font == nil)
|
|
|
|
{
|
|
|
|
font = [NSFontClass fontWithName: @"Helvetica" size: 12.];
|
|
|
|
}
|
|
|
|
if (font == nil)
|
|
|
|
{
|
|
|
|
font = [NSFontClass fontWithName: @"Courier" size: 12.];
|
|
|
|
}
|
|
|
|
if (font == nil)
|
|
|
|
{
|
|
|
|
font = [NSFontClass fontWithName: @"Fixed" size: 12.];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return font;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
void
|
|
|
|
setNSFont(NSString* key, NSFont* font)
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-01-03 10:39:02 +00:00
|
|
|
[defaults setObject: [font fontName] forKey: key];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2000-09-01 23:49:53 +00:00
|
|
|
systemCacheNeedsRecomputing = YES;
|
|
|
|
boldSystemCacheNeedsRecomputing = YES;
|
|
|
|
userCacheNeedsRecomputing = YES;
|
|
|
|
userFixedCacheNeedsRecomputing = YES;
|
|
|
|
|
2002-09-27 08:52:04 +00:00
|
|
|
/* Don't care about errors */
|
2001-01-03 10:39:02 +00:00
|
|
|
[defaults synchronize];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1997-02-18 00:29:25 +00:00
|
|
|
// Class methods
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (void) initialize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-01-03 10:39:02 +00:00
|
|
|
if (self == [NSFont class])
|
2000-04-29 08:53:33 +00:00
|
|
|
{
|
2001-01-03 10:39:02 +00:00
|
|
|
NSFontClass = self;
|
2002-09-27 12:25:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The placeHolder is a dummy NSFont instance which is never used
|
|
|
|
* as a font ... the initialiser knows that whenever it gets the
|
|
|
|
* placeHolder it should either return a cached font or return a
|
|
|
|
* newly allocated font to replace it. This mechanism stops the
|
|
|
|
* +fontWithName:... methods from having to allocete fonts instances
|
|
|
|
* which would immediately have to be released for replacement by
|
|
|
|
* a cache object.
|
|
|
|
*/
|
|
|
|
placeHolder = [self alloc];
|
2002-09-27 08:52:04 +00:00
|
|
|
globalFontMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSNonRetainedObjectMapValueCallBacks, 64);
|
2001-05-21 15:24:20 +00:00
|
|
|
|
2001-01-03 10:39:02 +00:00
|
|
|
if (defaults == nil)
|
|
|
|
{
|
|
|
|
defaults = RETAIN([NSUserDefaults standardUserDefaults]);
|
|
|
|
}
|
2002-09-16 18:23:13 +00:00
|
|
|
|
2002-09-18 18:00:30 +00:00
|
|
|
[self setVersion: currentVersion];
|
2000-04-29 08:53:33 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-09-02 00:15:13 +00:00
|
|
|
/* Getting the preferred user fonts. */
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2002-09-27 08:26:13 +00:00
|
|
|
/**
|
|
|
|
* Return the default bold font for use in menus and heading in standard
|
|
|
|
* gui components.<br />
|
|
|
|
* This is deprecated in MacOSX
|
|
|
|
*/
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) boldSystemFontOfSize: (float)fontSize
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
2000-09-01 23:49:53 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSBoldFont", @"Helvetica-Bold", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (boldSystemCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSBoldFont", @"Helvetica-Bold", 0));
|
|
|
|
boldSystemCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1996-09-12 19:24:32 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 08:26:13 +00:00
|
|
|
/**
|
|
|
|
* Return the default font for use in menus and heading in standard
|
|
|
|
* gui components.<br />
|
|
|
|
* This is deprecated in MacOSX
|
|
|
|
*/
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) systemFontOfSize: (float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-09-01 23:49:53 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSFont", @"Helvetica", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (systemCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSFont", @"Helvetica", 0));
|
|
|
|
systemCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 08:26:13 +00:00
|
|
|
/**
|
|
|
|
* Return the default fixed pitch font for use in locations other
|
|
|
|
* than standard gui components.
|
|
|
|
*/
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) userFixedPitchFontOfSize: (float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-09-01 23:49:53 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSUserFixedPitchFont", @"Courier", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (userFixedCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSUserFixedPitchFont", @"Courier", 0));
|
|
|
|
userFixedCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 08:26:13 +00:00
|
|
|
/**
|
|
|
|
* Return the default font for use in locations other
|
|
|
|
* than standard gui components.
|
|
|
|
*/
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) userFontOfSize: (float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-09-01 23:49:53 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSUserFont", @"Helvetica", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (userCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSUserFont", @"Helvetica", 0));
|
|
|
|
userCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 08:26:13 +00:00
|
|
|
/**
|
|
|
|
* Return an array of the names of preferred fonts.
|
|
|
|
*/
|
|
|
|
+ (NSArray*) preferredFontNames
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
return _preferredFonts;
|
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
/* Setting the preferred user fonts*/
|
1997-02-18 00:29:25 +00:00
|
|
|
|
2002-04-03 16:59:43 +00:00
|
|
|
+ (void) setUserFixedPitchFont: (NSFont*)aFont
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-04-03 16:59:43 +00:00
|
|
|
setNSFont (@"NSUserFixedPitchFont", aFont);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-04-03 16:59:43 +00:00
|
|
|
+ (void) setUserFont: (NSFont*)aFont
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-04-03 16:59:43 +00:00
|
|
|
setNSFont (@"NSUserFont", aFont);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 08:26:13 +00:00
|
|
|
+ (void) setPreferredFontNames: (NSArray*)fontNames
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_preferredFonts, fontNames);
|
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
/* Getting various fonts*/
|
1999-04-28 03:52:36 +00:00
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) controlContentFontOfSize: (float)fontSize
|
1999-04-28 03:52:36 +00:00
|
|
|
{
|
2000-12-07 00:22:51 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSControlContentFont", @"Helvetica", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (userCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSControlContentFont", @"Helvetica", 0));
|
|
|
|
userCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1999-04-28 03:52:36 +00:00
|
|
|
}
|
|
|
|
|
2001-05-01 21:19:33 +00:00
|
|
|
+ (NSFont*) labelFontOfSize: (float)fontSize
|
|
|
|
{
|
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSLabelFont", @"Helvetica", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (userCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSLabelFont", @"Helvetica", 0));
|
|
|
|
userCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) menuFontOfSize: (float)fontSize
|
1999-04-28 03:52:36 +00:00
|
|
|
{
|
2000-12-07 00:22:51 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSMenuFont", @"Helvetica", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (userCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSMenuFont", @"Helvetica", 0));
|
|
|
|
userCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1999-04-28 03:52:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) titleBarFontOfSize: (float)fontSize
|
1999-04-28 03:52:36 +00:00
|
|
|
{
|
2000-12-07 00:22:51 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
2001-01-26 12:16:59 +00:00
|
|
|
return getNSFont (@"NSTitleBarFont", @"Helvetica-Bold", fontSize);
|
2000-12-07 00:22:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (boldSystemCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSTitleBarFont", @"Helvetica-Bold", 0));
|
|
|
|
boldSystemCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1999-04-28 03:52:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) messageFontOfSize: (float)fontSize
|
1999-04-28 03:52:36 +00:00
|
|
|
{
|
2000-12-07 00:22:51 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSMessageFont", @"Helvetica", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (userCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSMessageFont", @"Helvetica", 0));
|
|
|
|
userCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1999-04-28 03:52:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) paletteFontOfSize: (float)fontSize
|
1999-04-28 03:52:36 +00:00
|
|
|
{
|
|
|
|
// Not sure on this one.
|
2000-12-07 00:22:51 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSPaletteFont", @"Helvetica-Bold", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (boldSystemCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSPaletteFont", @"Helvetica-Bold", 0));
|
|
|
|
boldSystemCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1999-04-28 03:52:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
+ (NSFont*) toolTipsFontOfSize: (float)fontSize
|
1999-04-28 03:52:36 +00:00
|
|
|
{
|
|
|
|
// Not sure on this one.
|
2000-12-07 00:22:51 +00:00
|
|
|
static NSFont *font = nil;
|
|
|
|
|
|
|
|
if (fontSize != 0)
|
|
|
|
{
|
|
|
|
return getNSFont (@"NSToolTipsFont", @"Helvetica", fontSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((font == nil) || (userCacheNeedsRecomputing == YES))
|
|
|
|
{
|
|
|
|
ASSIGN (font, getNSFont (@"NSToolTipsFont", @"Helvetica", 0));
|
|
|
|
userCacheNeedsRecomputing = NO;
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
1999-04-28 03:52:36 +00:00
|
|
|
}
|
|
|
|
|
2001-05-01 21:19:33 +00:00
|
|
|
//
|
|
|
|
// Font Sizes
|
|
|
|
//
|
|
|
|
+ (float) labelFontSize
|
|
|
|
{
|
2002-05-13 22:15:53 +00:00
|
|
|
float fontSize = [defaults floatForKey: @"NSLabelFontSize"];
|
|
|
|
|
|
|
|
if (fontSize == 0)
|
|
|
|
{
|
|
|
|
fontSize = 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fontSize;
|
2001-05-01 21:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (float) smallSystemFontSize
|
|
|
|
{
|
2002-05-13 22:15:53 +00:00
|
|
|
float fontSize = [defaults floatForKey: @"NSSmallFontSize"];
|
|
|
|
|
|
|
|
if (fontSize == 0)
|
|
|
|
{
|
|
|
|
fontSize = 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fontSize;
|
2001-05-01 21:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (float) systemFontSize
|
|
|
|
{
|
2002-05-13 22:15:53 +00:00
|
|
|
float fontSize = [defaults floatForKey: @"NSFontSize"];
|
|
|
|
|
|
|
|
if (fontSize == 0)
|
|
|
|
{
|
|
|
|
fontSize = 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fontSize;
|
2001-05-01 21:19:33 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
/**
|
|
|
|
* Returns an autoreleased font with name aFontName and matrix fontMatrix.<br />
|
|
|
|
* The fontMatrix is a standard size element matrix as used in PostScript
|
|
|
|
* to describe the scaling of the font, typically it just includes
|
|
|
|
* the font size as [fontSize 0 0 fontSize 0 0]. You can use the constant
|
|
|
|
* NSFontIdentityMatrix in place of [1 0 0 1 0 0]. If NSFontIdentityMatrix,
|
|
|
|
* then the font will automatically flip itself when set in a flipped view.
|
|
|
|
*/
|
2002-04-03 16:59:43 +00:00
|
|
|
+ (NSFont*) fontWithName: (NSString*)aFontName
|
2000-04-29 08:53:33 +00:00
|
|
|
matrix: (const float*)fontMatrix
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-09-27 12:25:02 +00:00
|
|
|
NSFont *font;
|
|
|
|
BOOL fix;
|
2002-05-13 22:15:53 +00:00
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
if (fontMatrix == NSFontIdentityMatrix)
|
|
|
|
fix = NO;
|
|
|
|
else
|
|
|
|
fix = YES;
|
2002-05-13 22:15:53 +00:00
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
font = [placeHolder initWithName: aFontName
|
|
|
|
matrix: fontMatrix
|
|
|
|
fix: fix
|
|
|
|
screenFont: NO];
|
2002-05-13 22:15:53 +00:00
|
|
|
|
2002-09-27 09:05:02 +00:00
|
|
|
return AUTORELEASE(font);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
/**
|
|
|
|
* Returns an autoreleased font with name aFontName and size fontSize.<br />
|
|
|
|
* Fonts created using this method will automatically flip themselves
|
|
|
|
* when set in a flipped view.
|
|
|
|
*/
|
2002-04-03 16:59:43 +00:00
|
|
|
+ (NSFont*) fontWithName: (NSString*)aFontName
|
2000-04-29 08:53:33 +00:00
|
|
|
size: (float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-09-27 12:25:02 +00:00
|
|
|
NSFont *font;
|
|
|
|
float fontMatrix[6] = { 0, 0, 0, 0, 0, 0 };
|
2002-02-26 18:31:07 +00:00
|
|
|
|
|
|
|
if (fontSize == 0)
|
|
|
|
{
|
|
|
|
fontSize = [defaults floatForKey: @"NSUserFontSize"];
|
|
|
|
if (fontSize == 0)
|
|
|
|
{
|
|
|
|
fontSize = 12;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fontMatrix[0] = fontSize;
|
|
|
|
fontMatrix[3] = fontSize;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
font = [placeHolder initWithName: aFontName
|
|
|
|
matrix: fontMatrix
|
|
|
|
fix: NO
|
|
|
|
screenFont: NO];
|
2002-09-27 12:25:02 +00:00
|
|
|
return AUTORELEASE(font);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-04-03 16:59:43 +00:00
|
|
|
+ (void) useFont: (NSString*)aFontName
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-04-03 16:59:43 +00:00
|
|
|
[GSCurrentContext() useFont: aFontName];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
2002-09-27 12:25:02 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Called -init on NSFont ... illegal"];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** <init />
|
|
|
|
* Initializes a newly created font instance from the name and
|
|
|
|
* information given in the fontMatrix. The fontMatrix is a standard
|
|
|
|
* size element matrix as used in PostScript to describe the scaling
|
|
|
|
* of the font, typically it just includes the font size as
|
|
|
|
* [fontSize 0 0 fontSize 0 0].<br />
|
|
|
|
* This method may destroy the receiver and return a cached instance.
|
|
|
|
*/
|
|
|
|
- (id) initWithName: (NSString*)name
|
|
|
|
matrix: (const float*)fontMatrix
|
|
|
|
fix: (BOOL)explicitlySet
|
2003-01-26 19:21:40 +00:00
|
|
|
screenFont: (BOOL)screen;
|
2002-09-27 12:25:02 +00:00
|
|
|
{
|
|
|
|
NSString *nameWithMatrix;
|
|
|
|
NSFont *font;
|
|
|
|
|
|
|
|
/* Should never be called on an initialised font! */
|
|
|
|
NSAssert(fontName == nil, NSInternalInconsistencyException);
|
|
|
|
|
|
|
|
/* Check whether the font is cached */
|
2003-01-26 19:21:40 +00:00
|
|
|
nameWithMatrix = newNameWithMatrix(name, fontMatrix, explicitlySet,
|
|
|
|
screen);
|
2002-09-27 12:25:02 +00:00
|
|
|
font = (id)NSMapGet(globalFontMap, (void*)nameWithMatrix);
|
|
|
|
if (font == nil)
|
|
|
|
{
|
|
|
|
if (self == placeHolder)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If we are initialising the placeHolder, we actually want to
|
|
|
|
* leave it be (for later re-use) and initialise a newly created
|
|
|
|
* instance instead.
|
|
|
|
*/
|
|
|
|
self = [NSFontClass alloc];
|
|
|
|
}
|
|
|
|
fontName = [name copy];
|
|
|
|
memcpy(matrix, fontMatrix, sizeof(matrix));
|
|
|
|
matrixExplicitlySet = explicitlySet;
|
2003-01-26 19:21:40 +00:00
|
|
|
screenFont = screen;
|
2002-09-27 12:25:02 +00:00
|
|
|
fontInfo = RETAIN([GSFontInfo fontInfoForFontName: fontName
|
2003-01-26 19:21:40 +00:00
|
|
|
matrix: fontMatrix
|
|
|
|
screenFont: screen]);
|
2002-10-10 23:27:51 +00:00
|
|
|
if (fontInfo == nil)
|
|
|
|
{
|
|
|
|
RELEASE (self);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
/* Cache the font for later use */
|
|
|
|
NSMapInsert(globalFontMap, (void*)nameWithMatrix, (void*)self);
|
|
|
|
}
|
2002-05-08 03:28:09 +00:00
|
|
|
else
|
2002-09-27 12:25:02 +00:00
|
|
|
{
|
2002-09-27 13:37:29 +00:00
|
|
|
if (self != placeHolder)
|
|
|
|
{
|
|
|
|
RELEASE(self);
|
|
|
|
}
|
2002-09-27 12:25:02 +00:00
|
|
|
self = RETAIN(font);
|
|
|
|
}
|
|
|
|
RELEASE(nameWithMatrix);
|
|
|
|
|
2001-05-21 15:24:20 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
- (void) dealloc
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-09-27 12:25:02 +00:00
|
|
|
if (fontName != nil)
|
|
|
|
{
|
|
|
|
NSString *nameWithMatrix;
|
2002-09-27 08:52:04 +00:00
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
nameWithMatrix = newNameWithMatrix(fontName, matrix,
|
|
|
|
matrixExplicitlySet, screenFont);
|
2002-09-27 12:25:02 +00:00
|
|
|
NSMapRemove(globalFontMap, (void*)nameWithMatrix);
|
|
|
|
RELEASE(nameWithMatrix);
|
|
|
|
RELEASE(fontName);
|
|
|
|
}
|
|
|
|
TEST_RELEASE(fontInfo);
|
1997-02-18 00:29:25 +00:00
|
|
|
[super dealloc];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-01-07 00:46:12 +00:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
2002-09-27 12:25:02 +00:00
|
|
|
NSString *nameWithMatrix;
|
|
|
|
NSString *description;
|
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
nameWithMatrix = newNameWithMatrix(fontName, matrix, matrixExplicitlySet,
|
|
|
|
screenFont);
|
2002-09-27 12:25:02 +00:00
|
|
|
description = [[super description] stringByAppendingFormat: @" %@",
|
|
|
|
nameWithMatrix];
|
|
|
|
RELEASE(nameWithMatrix);
|
|
|
|
return description;
|
2001-01-07 00:46:12 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 14:39:32 +00:00
|
|
|
- (BOOL) isEqual: (id)anObject
|
|
|
|
{
|
|
|
|
int i;
|
2000-04-29 08:53:33 +00:00
|
|
|
const float*obj_matrix;
|
2000-04-24 14:39:32 +00:00
|
|
|
if (anObject == self)
|
|
|
|
return YES;
|
|
|
|
if ([anObject isKindOfClass: self->isa] == NO)
|
|
|
|
return NO;
|
|
|
|
if ([[anObject fontName] isEqual: fontName] == NO)
|
|
|
|
return NO;
|
|
|
|
obj_matrix = [anObject matrix];
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
if (obj_matrix[i] != matrix[i])
|
|
|
|
return NO;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned) hash
|
|
|
|
{
|
|
|
|
int i, sum;
|
|
|
|
sum = 0;
|
|
|
|
for (i = 0; i < 6; i++)
|
2000-04-29 08:53:33 +00:00
|
|
|
sum += matrix[i]* ((i+1)* 17);
|
2000-04-24 14:39:32 +00:00
|
|
|
return ([fontName hash] + sum);
|
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
/**
|
|
|
|
* The NSFont class caches instances ... to actually make copies
|
|
|
|
* of instances would defeat the whole point of caching, so the
|
|
|
|
* effect of copying an NSFont is imply to retain it.
|
|
|
|
*/
|
2000-04-29 08:53:33 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
2000-03-31 22:53:17 +00:00
|
|
|
{
|
2002-09-27 12:25:02 +00:00
|
|
|
return RETAIN(self);
|
2000-03-31 22:53:17 +00:00
|
|
|
}
|
|
|
|
|
2002-05-08 03:28:09 +00:00
|
|
|
- (NSFont *)_flippedViewFont
|
|
|
|
{
|
|
|
|
float fontMatrix[6];
|
|
|
|
memcpy(fontMatrix, matrix, sizeof(matrix));
|
|
|
|
fontMatrix[3] *= -1;
|
2003-01-26 19:21:40 +00:00
|
|
|
return AUTORELEASE([placeHolder initWithName: fontName
|
|
|
|
matrix: fontMatrix
|
|
|
|
fix: YES
|
|
|
|
screenFont: screenFont]);
|
2002-05-08 03:28:09 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
//
|
|
|
|
// Setting the Font
|
|
|
|
//
|
2002-05-08 03:28:09 +00:00
|
|
|
/** Sets the receiver as the font used for text drawing operations. If the
|
|
|
|
current view is a flipped view, the reciever automatically flips itself
|
|
|
|
to display correctly in the flipped view, as long as the font was created
|
|
|
|
without explicitly setting the font matrix */
|
2000-04-29 08:53:33 +00:00
|
|
|
- (void) set
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-05-12 12:37:02 +00:00
|
|
|
NSGraphicsContext *ctxt = GSCurrentContext();
|
|
|
|
|
2002-05-08 03:28:09 +00:00
|
|
|
if (matrixExplicitlySet == NO && [[NSView focusView] isFlipped])
|
2002-10-09 02:47:40 +00:00
|
|
|
[ctxt GSSetFont: [[self _flippedViewFont] fontRef]];
|
2002-05-08 03:28:09 +00:00
|
|
|
else
|
2002-10-09 02:47:40 +00:00
|
|
|
[ctxt GSSetFont: [self fontRef]];
|
2002-05-08 03:28:09 +00:00
|
|
|
|
2001-11-20 05:00:20 +00:00
|
|
|
[ctxt useFont: fontName];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
//
|
|
|
|
// Querying the Font
|
|
|
|
//
|
2000-04-29 08:53:33 +00:00
|
|
|
- (float) pointSize { return [fontInfo pointSize]; }
|
|
|
|
- (NSString*) fontName { return fontName; }
|
|
|
|
- (const float*) matrix { return matrix; }
|
|
|
|
|
|
|
|
- (NSString*) encodingScheme { return [fontInfo encodingScheme]; }
|
|
|
|
- (NSString*) familyName { return [fontInfo familyName]; }
|
|
|
|
- (NSRect) boundingRectForFont { return [fontInfo boundingRectForFont]; }
|
|
|
|
- (BOOL) isFixedPitch { return [fontInfo isFixedPitch]; }
|
|
|
|
- (BOOL) isBaseFont { return [fontInfo isBaseFont]; }
|
|
|
|
|
|
|
|
/* Usually the display name of font is the font name.*/
|
|
|
|
- (NSString*) displayName { return fontName; }
|
|
|
|
|
|
|
|
- (NSDictionary*) afmDictionary { return [fontInfo afmDictionary]; }
|
|
|
|
- (NSString*) afmFileContents { return [fontInfo afmFileContents]; }
|
2003-01-26 19:21:40 +00:00
|
|
|
|
|
|
|
- (NSFont*) printerFont
|
|
|
|
{
|
|
|
|
if (!screenFont)
|
|
|
|
return self;
|
|
|
|
return [placeHolder initWithName: fontName
|
|
|
|
matrix: matrix
|
|
|
|
fix: matrixExplicitlySet
|
|
|
|
screenFont: NO];
|
|
|
|
}
|
|
|
|
- (NSFont*) screenFont
|
|
|
|
{
|
|
|
|
if (screenFont)
|
|
|
|
return self;
|
|
|
|
return [placeHolder initWithName: fontName
|
|
|
|
matrix: matrix
|
|
|
|
fix: matrixExplicitlySet
|
|
|
|
screenFont: YES];
|
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
- (float) ascender { return [fontInfo ascender]; }
|
|
|
|
- (float) descender { return [fontInfo descender]; }
|
|
|
|
- (float) capHeight { return [fontInfo capHeight]; }
|
|
|
|
- (float) italicAngle { return [fontInfo italicAngle]; }
|
|
|
|
- (NSSize) maximumAdvancement { return [fontInfo maximumAdvancement]; }
|
|
|
|
- (NSSize) minimumAdvancement { return [fontInfo minimumAdvancement]; }
|
|
|
|
- (float) underlinePosition { return [fontInfo underlinePosition]; }
|
|
|
|
- (float) underlineThickness { return [fontInfo underlineThickness]; }
|
|
|
|
- (float) xHeight { return [fontInfo xHeight]; }
|
2000-06-11 00:31:50 +00:00
|
|
|
- (float) defaultLineHeightForFont { return [fontInfo defaultLineHeightForFont]; }
|
2000-04-29 08:53:33 +00:00
|
|
|
|
|
|
|
/* Computing font metrics attributes*/
|
|
|
|
- (float) widthOfString: (NSString*)string
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-03-27 18:28:51 +00:00
|
|
|
return [fontInfo widthOfString: string];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-01-07 00:46:12 +00:00
|
|
|
/* The following methods have to be implemented by backends */
|
1997-02-18 00:29:25 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Manipulating Glyphs
|
|
|
|
//
|
2000-04-29 08:53:33 +00:00
|
|
|
- (NSSize) advancementForGlyph: (NSGlyph)aGlyph
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-03-27 18:28:51 +00:00
|
|
|
return [fontInfo advancementForGlyph: aGlyph];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
- (NSRect) boundingRectForGlyph: (NSGlyph)aGlyph
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-03-27 18:28:51 +00:00
|
|
|
return [fontInfo boundingRectForGlyph: aGlyph];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
- (BOOL) glyphIsEncoded: (NSGlyph)aGlyph
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-01-07 00:46:12 +00:00
|
|
|
return [fontInfo glyphIsEncoded: aGlyph];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-01-07 00:46:12 +00:00
|
|
|
- (NSMultibyteGlyphPacking) glyphPacking
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
return [fontInfo glyphPacking];
|
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
- (NSGlyph) glyphWithName: (NSString*)glyphName
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
2001-01-07 00:46:12 +00:00
|
|
|
return [fontInfo glyphWithName: glyphName];
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
|
|
|
|
2000-04-29 08:53:33 +00:00
|
|
|
- (NSPoint) positionOfGlyph: (NSGlyph)curGlyph
|
|
|
|
precededByGlyph: (NSGlyph)prevGlyph
|
|
|
|
isNominal: (BOOL*)nominal
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-03-27 18:28:51 +00:00
|
|
|
return [fontInfo positionOfGlyph: curGlyph precededByGlyph: prevGlyph
|
|
|
|
isNominal: nominal];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
|
|
|
|
forCharacter: (unichar)aChar
|
|
|
|
struckOverRect: (NSRect)aRect
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
return [fontInfo positionOfGlyph: aGlyph
|
2002-09-27 12:25:02 +00:00
|
|
|
forCharacter: aChar
|
|
|
|
struckOverRect: aRect];
|
2000-06-11 00:31:50 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
|
|
|
|
struckOverGlyph: (NSGlyph)baseGlyph
|
|
|
|
metricsExist: (BOOL *)flag
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
return [fontInfo positionOfGlyph: aGlyph
|
|
|
|
struckOverGlyph: baseGlyph
|
2002-09-27 12:25:02 +00:00
|
|
|
metricsExist: flag];
|
2000-06-11 00:31:50 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
|
|
|
|
struckOverRect: (NSRect)aRect
|
|
|
|
metricsExist: (BOOL *)flag
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
return [fontInfo positionOfGlyph: aGlyph
|
2002-09-27 12:25:02 +00:00
|
|
|
struckOverRect: aRect
|
|
|
|
metricsExist: flag];
|
2000-06-11 00:31:50 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 12:25:02 +00:00
|
|
|
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
|
|
|
|
withRelation: (NSGlyphRelation)relation
|
|
|
|
toBaseGlyph: (NSGlyph)baseGlyph
|
|
|
|
totalAdvancement: (NSSize *)offset
|
|
|
|
metricsExist: (BOOL *)flag
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
return [fontInfo positionOfGlyph: aGlyph
|
2002-09-27 12:25:02 +00:00
|
|
|
withRelation: relation
|
|
|
|
toBaseGlyph: baseGlyph
|
|
|
|
totalAdvancement: offset
|
|
|
|
metricsExist: flag];
|
2000-06-11 00:31:50 +00:00
|
|
|
}
|
|
|
|
|
2001-01-07 00:46:12 +00:00
|
|
|
- (int) positionsForCompositeSequence: (NSGlyph *)glyphs
|
|
|
|
numberOfGlyphs: (int)numGlyphs
|
|
|
|
pointArray: (NSPoint *)points
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NSGlyph base = glyphs[0];
|
|
|
|
|
|
|
|
points[0] = NSZeroPoint;
|
|
|
|
|
|
|
|
for (i = 1; i < numGlyphs; i++)
|
|
|
|
{
|
|
|
|
BOOL flag;
|
|
|
|
// This only places the glyphs relative to the base glyph
|
|
|
|
// not to each other
|
|
|
|
points[i] = [self positionOfGlyph: glyphs[i]
|
|
|
|
struckOverGlyph: base
|
2002-09-27 12:25:02 +00:00
|
|
|
metricsExist: &flag];
|
2000-06-11 00:31:50 +00:00
|
|
|
if (!flag)
|
|
|
|
return i - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2001-01-07 00:46:12 +00:00
|
|
|
- (NSStringEncoding) mostCompatibleStringEncoding
|
2000-06-11 00:31:50 +00:00
|
|
|
{
|
|
|
|
return [fontInfo mostCompatibleStringEncoding];
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
2001-01-03 10:39:02 +00:00
|
|
|
- (Class) classForCoder
|
|
|
|
{
|
|
|
|
return NSFontClass;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[aCoder encodeObject: fontName];
|
2001-01-07 00:46:12 +00:00
|
|
|
[aCoder encodeArrayOfObjCType: @encode(float) count: 6 at: matrix];
|
2002-09-27 12:25:02 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &matrixExplicitlySet];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-09-27 12:25:02 +00:00
|
|
|
int version = [aDecoder versionForClassName: @"NSFont"];
|
|
|
|
id name;
|
|
|
|
float fontMatrix[6];
|
|
|
|
BOOL fix;
|
|
|
|
|
|
|
|
name = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeArrayOfObjCType: @encode(float)
|
|
|
|
count: 6
|
|
|
|
at: fontMatrix];
|
2002-09-18 18:00:30 +00:00
|
|
|
if (version == currentVersion)
|
|
|
|
{
|
2002-09-27 08:26:13 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL)
|
2002-09-27 12:25:02 +00:00
|
|
|
at: &fix];
|
2002-09-16 18:23:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fontMatrix[0] == fontMatrix[3]
|
2002-09-27 12:25:02 +00:00
|
|
|
&& fontMatrix[1] == 0.0 && fontMatrix[2] == 0.0)
|
|
|
|
fix = NO;
|
|
|
|
else
|
|
|
|
fix = YES;
|
2002-09-16 18:23:13 +00:00
|
|
|
}
|
2002-09-27 12:25:02 +00:00
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
self = [self initWithName: name
|
|
|
|
matrix: fontMatrix
|
|
|
|
fix: fix
|
|
|
|
screenFont: NO];
|
2002-09-16 18:23:13 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
@end /* NSFont */
|
2001-05-01 21:19:33 +00:00
|
|
|
|
2001-05-12 12:37:02 +00:00
|
|
|
@implementation NSFont (GNUstep)
|
|
|
|
//
|
|
|
|
// Private method for NSFontManager and backend
|
|
|
|
//
|
|
|
|
- (GSFontInfo*) fontInfo
|
|
|
|
{
|
|
|
|
return fontInfo;
|
|
|
|
}
|
|
|
|
|
2002-10-09 02:47:40 +00:00
|
|
|
- (void *) fontRef
|
|
|
|
{
|
|
|
|
if (_fontRef == nil)
|
|
|
|
_fontRef = [NSGraphicsContext CGFontReferenceFromFont: self];
|
|
|
|
return _fontRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-12 12:37:02 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
2001-05-01 21:19:33 +00:00
|
|
|
int NSConvertGlyphsToPackedGlyphs(NSGlyph *glBuf,
|
|
|
|
int count,
|
|
|
|
NSMultibyteGlyphPacking packing,
|
|
|
|
char *packedGlyphs)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|