libs-gui/Source/NSFont.m
Scott Christley 5d15da4e79 Some small changes to support backing-store.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@2244 72102866-910b-0410-8b05-ffd578937521
1997-03-17 18:43:27 +00:00

263 lines
6.2 KiB
Objective-C

/*
NSFont.m
The font class
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
Date: February 1997
A completely rewritten version of the original source by Scott Christley.
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
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.
*/
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSSet.h>
#include <AppKit/NSFont.h>
#include <AppKit/NSFontManager.h>
// Global Strings
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";
@implementation NSFont
/* Class variables */
/* 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;
static NSFont* getFont(NSString* key, NSString* defaultFontName, float fontSize)
{
NSString* fontName;
fontName = [[NSUserDefaults standardUserDefaults] objectForKey:key];
if (!fontName)
fontName = defaultFontName;
return [NSFont fontWithName:fontName size:fontSize];
}
static void setFont(NSString* key, NSFont* font)
{
NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults];
[standardDefaults setObject:[font fontName] forKey:key];
/* Don't care about errors */
[standardDefaults synchronize];
}
//
// Class methods
//
+ (void)initialize
{
static BOOL initialized = NO;
if (!initialized) {
initialized = YES;
fontsUsed = [NSMutableSet new];
}
}
/* Getting the preferred user fonts */
+ (NSFont*)boldSystemFontOfSize:(float)fontSize
{
return getFont (@"NSBoldFont", @"Helvetica-Bold", fontSize);
}
+ (NSFont*)systemFontOfSize:(float)fontSize
{
return getFont (@"NSFont", @"Helvetica", fontSize);
}
+ (NSFont*)userFixedPitchFontOfSize:(float)fontSize
{
return getFont (@"NSUserFixedPitchFont", @"Courier", fontSize);
}
+ (NSFont*)userFontOfSize:(float)fontSize
{
return getFont (@"NSUserFont", @"Helvetica", fontSize);
}
/* Setting the preferred user fonts */
+ (void)setUserFixedPitchFont:(NSFont*)font
{
setFont (@"NSUserFixedPitchFont", font);
}
+ (void)setUserFont:(NSFont*)font
{
setFont (@"NSUserFont", font);
}
/* 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
{
[fontsUsed addObject:name];
return nil;
}
+ (NSFont*)fontWithName:(NSString*)name
size:(float)fontSize
{
float fontMatrix[6] = { fontSize, 0, 0, fontSize, 0, 0 };
return [self fontWithName:name matrix:fontMatrix];
}
+ (void)useFont:(NSString*)name
{
[fontsUsed addObject:name];
}
//
// Instance methods
//
- (void)dealloc
{
[fontName release];
[super dealloc];
}
//
// Setting the Font
//
- (void)set
{
}
//
// 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; }
- (NSSize)minimumAdvancement { return NSZeroSize; }
- (float)underlinePosition { return 0.0; }
- (float)underlineThickness { return 0.0; }
- (float)xHeight { return 0.0; }
/* Computing font metrics attributes */
- (float)widthOfString:(NSString*)string
{
return 0;
}
- (float*)widths
{
return NULL;
}
/* The following methods have to implemented by backends */
//
// Manipulating Glyphs
//
- (NSSize)advancementForGlyph:(NSGlyph)aGlyph
{
return NSZeroSize;
}
- (NSRect)boundingRectForGlyph:(NSGlyph)aGlyph
{
return NSZeroRect;
}
- (BOOL)glyphIsEncoded:(NSGlyph)aGlyph
{
return NO;
}
- (NSGlyph)glyphWithName:(NSString*)glyphName
{
return -1;
}
- (NSPoint)positionOfGlyph:(NSGlyph)curGlyph
precededByGlyph:(NSGlyph)prevGlyph
isNominal:(BOOL *)nominal
{
return NSZeroPoint;
}
//
// NSCoding protocol
//
- (void)encodeWithCoder:aCoder
{
[aCoder encodeObject:fontName];
[aCoder encodeArrayOfObjCType:"f" count:6 at:matrix];
}
- initWithCoder:aDecoder
{
fontName = [aDecoder decodeObject];
[aDecoder decodeArrayOfObjCType:"f" count:6 at:matrix];
return self;
}
@end /* NSFont */