1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSFont.m
|
|
|
|
|
|
|
|
The font class
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
|
|
|
|
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-02-18 00:29:25 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
#include <Foundation/NSSet.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSFont.h>
|
|
|
|
#include <AppKit/NSFontManager.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
// Global Strings
|
1997-02-18 00:29:25 +00:00
|
|
|
NSString*NSAFMAscender = @"Ascender";
|
|
|
|
NSString*NSAFMCapHeight = @"CapHeight";
|
|
|
|
NSString*NSAFMCharacterSet = @"CharacterSet";
|
|
|
|
NSString*NSAFMDescender = @"Descender";
|
|
|
|
NSString*NSAFMEncodingScheme = @"EncodingScheme";
|
|
|
|
NSString*NSAFMFamilyName = @"FamilyName";
|
|
|
|
NSString*NSAFMFontName = @"FontName";
|
|
|
|
NSString*NSAFMFormatVersion = @"FormatVersion";
|
|
|
|
NSString*NSAFMFullName = @"FullName";
|
|
|
|
NSString*NSAFMItalicAngle = @"ItalicAngle";
|
|
|
|
NSString*NSAFMMappingScheme = @"MappingScheme";
|
|
|
|
NSString*NSAFMNotice = @"Notice";
|
|
|
|
NSString*NSAFMUnderlinePosition = @"UnderlinePosition";
|
|
|
|
NSString*NSAFMUnderlineThickness = @"UnderlineThickness";
|
|
|
|
NSString*NSAFMVersion = @"Version";
|
|
|
|
NSString*NSAFMWeight = @"Weight";
|
|
|
|
NSString*NSAFMXHeight = @"XHeight";
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
@implementation NSFont
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
/* Class variables */
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
/* Register all the fonts used by the current print operation to be able to
|
|
|
|
dump the %%DocumentFonts comment required by the Adobe Document Structuring
|
|
|
|
Convention (see the red book). */
|
|
|
|
static NSMutableSet* fontsUsed = nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-03-17 18:43:27 +00:00
|
|
|
static NSFont* getFont(NSString* key, NSString* defaultFontName, float fontSize)
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
NSString* fontName;
|
1997-03-17 18:43:27 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
fontName = [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
|
|
|
if (!fontName)
|
1997-03-17 18:43:27 +00:00
|
|
|
fontName = defaultFontName;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
return [NSFont fontWithName:fontName size:fontSize];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
static void setFont(NSString* key, NSFont* font)
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
[standardDefaults setObject:[font fontName] forKey:key];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
/* Don't care about errors */
|
|
|
|
[standardDefaults 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
|
|
|
//
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (void)initialize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
static BOOL initialized = NO;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
if (!initialized) {
|
|
|
|
initialized = YES;
|
|
|
|
fontsUsed = [NSMutableSet new];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
/* Getting the preferred user fonts */
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (NSFont*)boldSystemFontOfSize:(float)fontSize
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return getFont (@"NSBoldFont", @"Helvetica-Bold", fontSize);
|
1996-09-12 19:24:32 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (NSFont*)systemFontOfSize:(float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return getFont (@"NSFont", @"Helvetica", fontSize);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (NSFont*)userFixedPitchFontOfSize:(float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return getFont (@"NSUserFixedPitchFont", @"Courier", fontSize);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (NSFont*)userFontOfSize:(float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return getFont (@"NSUserFont", @"Helvetica", fontSize);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
/* Setting the preferred user fonts */
|
|
|
|
|
|
|
|
+ (void)setUserFixedPitchFont:(NSFont*)font
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
setFont (@"NSUserFixedPitchFont", font);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (void)setUserFont:(NSFont*)font
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
setFont (@"NSUserFont", font);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
/* The following method should be rewritten in the backend and it has to be
|
|
|
|
called as part of the implementation. */
|
|
|
|
+ (NSFont*)fontWithName:(NSString*)name
|
|
|
|
matrix:(const float*)fontMatrix
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[fontsUsed addObject:name];
|
1996-05-30 20:03:15 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (NSFont*)fontWithName:(NSString*)name
|
|
|
|
size:(float)fontSize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
float fontMatrix[6] = { fontSize, 0, 0, fontSize, 0, 0 };
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
return [self fontWithName:name matrix:fontMatrix];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
+ (void)useFont:(NSString*)name
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[fontsUsed addObject:name];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
|
|
|
- (void)dealloc
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[fontName release];
|
|
|
|
[super dealloc];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
//
|
|
|
|
// Setting the Font
|
|
|
|
//
|
|
|
|
- (void)set
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
//
|
|
|
|
// Querying the Font
|
|
|
|
//
|
|
|
|
- (float)pointSize { return matrix[3]; }
|
|
|
|
- (NSString*)fontName { return fontName; }
|
|
|
|
- (const float*)matrix { return matrix; }
|
|
|
|
|
|
|
|
/* The backends should rewrite the following methods to provide a more
|
|
|
|
appropiate behavior than these. */
|
|
|
|
|
|
|
|
- (NSString *)encodingScheme { return nil; }
|
|
|
|
- (NSString*)familyName { return nil; }
|
|
|
|
- (NSRect)boundingRectForFont { return NSZeroRect; }
|
|
|
|
- (BOOL)isFixedPitch { return NO; }
|
|
|
|
- (BOOL)isBaseFont { return YES; }
|
|
|
|
|
|
|
|
/* Usually the display name of font is the font name. */
|
|
|
|
- (NSString*)displayName { return fontName; }
|
|
|
|
|
|
|
|
- (NSDictionary*)afmDictionary { return nil; }
|
|
|
|
- (NSString*)afmFileContents { return nil; }
|
|
|
|
- (NSFont*)printerFont { return self; }
|
|
|
|
- (NSFont*)screenFont { return self; }
|
|
|
|
- (float)ascender { return 0.0; }
|
|
|
|
- (float)descender { return 0.0; }
|
|
|
|
- (float)capHeight { return 0.0; }
|
|
|
|
- (float)italicAngle { return 0.0; }
|
|
|
|
- (NSSize)maximumAdvancement { return NSZeroSize; }
|
1997-03-05 19:46:41 +00:00
|
|
|
- (NSSize)minimumAdvancement { return NSZeroSize; }
|
1997-02-18 00:29:25 +00:00
|
|
|
- (float)underlinePosition { return 0.0; }
|
|
|
|
- (float)underlineThickness { return 0.0; }
|
|
|
|
- (float)xHeight { return 0.0; }
|
|
|
|
|
|
|
|
/* Computing font metrics attributes */
|
|
|
|
- (float)widthOfString:(NSString*)string
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return 0;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (float*)widths
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
/* The following methods have to implemented by backends */
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Manipulating Glyphs
|
|
|
|
//
|
|
|
|
- (NSSize)advancementForGlyph:(NSGlyph)aGlyph
|
|
|
|
{
|
|
|
|
return NSZeroSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)boundingRectForGlyph:(NSGlyph)aGlyph
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)glyphIsEncoded:(NSGlyph)aGlyph
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (NSGlyph)glyphWithName:(NSString*)glyphName
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
- (NSPoint)positionOfGlyph:(NSGlyph)curGlyph
|
|
|
|
precededByGlyph:(NSGlyph)prevGlyph
|
|
|
|
isNominal:(BOOL *)nominal
|
|
|
|
{
|
|
|
|
return NSZeroPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[aCoder encodeObject:fontName];
|
|
|
|
[aCoder encodeArrayOfObjCType:"f" count:6 at:matrix];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
fontName = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeArrayOfObjCType:"f" count:6 at:matrix];
|
1996-12-05 13:07:59 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
@end /* NSFont */
|