1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSFont.m
|
|
|
|
|
|
|
|
The font class
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gnustep/gui/NSFont.h>
|
|
|
|
#include <gnustep/gui/NSFontManager.h>
|
1996-09-12 19:24:32 +00:00
|
|
|
#include <gnustep/gui/NSFontPrivate.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1996-06-21 15:08:08 +00:00
|
|
|
NSFont *gnustep_gui_user_fixed_font;
|
|
|
|
NSFont *gnustep_gui_user_font;
|
1996-09-12 19:24:32 +00:00
|
|
|
NSString *gnustep_gui_system_family = @"";
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
// Global Strings
|
1996-09-12 19:24:32 +00:00
|
|
|
NSString *NSAFMAscender = @"AFMAscender";
|
|
|
|
NSString *NSAFMCapHeight = @"AFMCapHeight";
|
|
|
|
NSString *NSAFMCharacterSet = @"AFMCharacterSet";
|
|
|
|
NSString *NSAFMDescender = @"AFMDescender";
|
|
|
|
NSString *NSAFMEncodingScheme = @"AFMEncodingScheme";
|
|
|
|
NSString *NSAFMFamilyName = @"AFMFamilyName";
|
|
|
|
NSString *NSAFMFontName = @"AFMFontName";
|
|
|
|
NSString *NSAFMFormatVersion = @"AFMFormatVersion";
|
|
|
|
NSString *NSAFMFullName = @"AFMFullName";
|
|
|
|
NSString *NSAFMItalicAngle = @"AFMItalicAngle";
|
|
|
|
NSString *NSAFMMappingScheme = @"AFMMappingScheme";
|
|
|
|
NSString *NSAFMNotice = @"AFMNotice";
|
|
|
|
NSString *NSAFMUnderlinePosition = @"AFMUnderlinePosition";
|
|
|
|
NSString *NSAFMUnderlineThickness = @"AFMUnderlineThickness";
|
|
|
|
NSString *NSAFMVersion = @"AFMVersion";
|
|
|
|
NSString *NSAFMWeight = @"AFMWeight";
|
|
|
|
NSString *NSAFMXHeight = @"AFMXHeight";
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
@implementation NSFont
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [NSFont class])
|
|
|
|
{
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"Initialize NSFont class\n");
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
// Initial version
|
|
|
|
[self setVersion:1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Creating a Font Object
|
|
|
|
//
|
|
|
|
+ (NSFont *)boldSystemFontOfSize:(float)fontSize
|
|
|
|
{
|
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
|
|
|
NSFont *f;
|
|
|
|
|
1996-09-12 19:24:32 +00:00
|
|
|
f = [fm fontWithFamily:gnustep_gui_system_family traits:NSBoldFontMask
|
1996-05-30 20:03:15 +00:00
|
|
|
weight:0 size:fontSize];
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSFont *)fontWithName:(NSString *)fontName
|
|
|
|
matrix:(const float *)fontMatrix
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSFont *)fontWithName:(NSString *)fontName
|
|
|
|
size:(float)fontSize
|
|
|
|
{
|
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
|
|
|
NSFont *f;
|
|
|
|
|
1996-09-12 19:24:32 +00:00
|
|
|
// +++ We need to extract the family name from the font name
|
|
|
|
f = [fm fontWithFamily:fontName traits:0 weight:400 size:fontSize];
|
1996-05-30 20:03:15 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSFont *)systemFontOfSize:(float)fontSize
|
|
|
|
{
|
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
|
|
|
NSFont *f;
|
|
|
|
|
1996-09-12 19:24:32 +00:00
|
|
|
f = [fm fontWithFamily:gnustep_gui_system_family traits:0
|
|
|
|
weight:400 size:fontSize];
|
1996-05-30 20:03:15 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSFont *)userFixedPitchFontOfSize:(float)fontSize
|
|
|
|
{
|
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
1996-06-21 15:08:08 +00:00
|
|
|
return [fm convertFont:gnustep_gui_user_fixed_font toSize:fontSize];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSFont *)userFontOfSize:(float)fontSize
|
|
|
|
{
|
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
1996-06-21 15:08:08 +00:00
|
|
|
return [fm convertFont:gnustep_gui_user_font toSize:fontSize];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Font
|
|
|
|
//
|
|
|
|
+ (void)setUserFixedPitchFont:(NSFont *)aFont
|
|
|
|
{
|
1996-06-21 15:08:08 +00:00
|
|
|
gnustep_gui_user_fixed_font = aFont;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)setUserFont:(NSFont *)aFont
|
|
|
|
{
|
1996-06-21 15:08:08 +00:00
|
|
|
gnustep_gui_user_font = aFont;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)useFont:(NSString *)fontName
|
|
|
|
{}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
1996-09-12 19:24:32 +00:00
|
|
|
- init
|
|
|
|
{
|
|
|
|
[super init];
|
|
|
|
|
|
|
|
family_name = @"";
|
|
|
|
font_name = @"";
|
|
|
|
type_face = @"";
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Font
|
|
|
|
//
|
|
|
|
- (void)set
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Querying the Font
|
|
|
|
//
|
|
|
|
- (NSDictionary *)afmDictionary
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)afmFileContents
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)boundingRectForFont
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)displayName
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)familyName
|
|
|
|
{
|
|
|
|
return family_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)fontName
|
|
|
|
{
|
|
|
|
return font_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isBaseFont
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (const float *)matrix
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float)pointSize
|
|
|
|
{
|
|
|
|
return point_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSFont *)printerFont
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSFont *)screenFont
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)widthOfString:(NSString *)string
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return 0;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float *)widths
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Manipulating Glyphs
|
|
|
|
//
|
|
|
|
- (NSSize)advancementForGlyph:(NSGlyph)aGlyph
|
|
|
|
{
|
|
|
|
return NSZeroSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)boundingRectForGlyph:(NSGlyph)aGlyph
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)glyphIsEncoded:(NSGlyph)aGlyph
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPoint)positionOfGlyph:(NSGlyph)curGlyph
|
|
|
|
precededByGlyph:(NSGlyph)prevGlyph
|
|
|
|
isNominal:(BOOL *)nominal
|
|
|
|
{
|
|
|
|
return NSZeroPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
{
|
|
|
|
[super encodeWithCoder:aCoder];
|
|
|
|
|
|
|
|
[aCoder encodeObject: family_name];
|
|
|
|
[aCoder encodeObject: font_name];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &point_size];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(NSFontTraitMask) at: &font_traits];
|
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
{
|
|
|
|
[super initWithCoder:aDecoder];
|
|
|
|
|
|
|
|
family_name = [aDecoder decodeObject];
|
|
|
|
font_name = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &point_size];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(NSFontTraitMask) at: &font_traits];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
1996-09-12 19:24:32 +00:00
|
|
|
|
|
|
|
@implementation NSFont (GNUstepPrivate)
|
|
|
|
|
|
|
|
- (void)setFamilyName:(NSString *)familyName
|
|
|
|
{
|
|
|
|
NSMutableString *s = [NSMutableString stringWithCString: ""];
|
|
|
|
|
|
|
|
// New family name so new font name
|
|
|
|
// Format is family name, dash, typeface
|
|
|
|
family_name = familyName;
|
|
|
|
[s appendString: family_name];
|
|
|
|
|
|
|
|
if ([type_face compare: @""] != NSOrderedSame)
|
|
|
|
{
|
|
|
|
[s appendString: @"-"];
|
|
|
|
[s appendString: type_face];
|
|
|
|
}
|
|
|
|
font_name = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFontName:(NSString *)fontName
|
|
|
|
{
|
|
|
|
font_name = fontName;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPointSize:(float)value
|
|
|
|
{
|
|
|
|
point_size = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSFontTraitMask)traits
|
|
|
|
{
|
|
|
|
return font_traits;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTraits:(NSFontTraitMask)traits
|
|
|
|
{
|
|
|
|
// Only if the traits have changed
|
|
|
|
if (font_traits != traits)
|
|
|
|
{
|
|
|
|
// Figure out a new typeface
|
|
|
|
NSMutableString *s = [NSMutableString stringWithCString: ""];
|
|
|
|
|
|
|
|
// Bold
|
|
|
|
if (traits & NSBoldFontMask)
|
|
|
|
[s appendString: @"Bold"];
|
|
|
|
|
|
|
|
// +++ How do we determine whether to use Italic or Oblique?
|
|
|
|
if (traits & NSItalicFontMask)
|
|
|
|
[s appendString: @"Italic"];
|
|
|
|
|
|
|
|
[self setTypeface: s];
|
|
|
|
}
|
|
|
|
font_traits = traits;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)weight
|
|
|
|
{
|
|
|
|
return font_weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setWeight:(int)value
|
|
|
|
{
|
|
|
|
NSFontTraitMask t = font_traits;
|
|
|
|
|
|
|
|
font_weight = value;
|
|
|
|
// Make the font bold or unbold based upon the weight
|
|
|
|
if (font_weight <= 400)
|
|
|
|
t = t ^ NSUnboldFontMask;
|
|
|
|
else
|
|
|
|
t = t ^ NSBoldFontMask;
|
|
|
|
[self setTraits:t];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)typeface
|
|
|
|
{
|
|
|
|
return type_face;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTypeface:(NSString *)str
|
|
|
|
{
|
|
|
|
NSMutableString *s = [NSMutableString stringWithCString: ""];
|
|
|
|
|
|
|
|
// New typeface so new font name
|
|
|
|
// Format is family name, dash, typeface
|
|
|
|
type_face = str;
|
|
|
|
[s appendString: family_name];
|
|
|
|
|
|
|
|
if ([type_face compare: @""] != NSOrderedSame)
|
|
|
|
{
|
|
|
|
[s appendString: @"-"];
|
|
|
|
[s appendString: type_face];
|
|
|
|
}
|
|
|
|
font_name = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|