diff --git a/ChangeLog b/ChangeLog index cf873586d..6831ddf4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-08-08 Fred Kiefer + + * Headers/AppKit/NSFont.h: Add MacOSX 10.4 methods and constants. + * Source/NSFont.m: Add MacOSX 10.4 methods. Remove + NSFontDescriptor code. + * Source/NSFont.m (+initialize): Read in preferred fonts from user defaults. + * Headers/AppKit/NSFontDescriptor.h: Clean up includes. + * Source/NSFontDescriptor.m: New file, split out from NSFont.m. + * Source/externs.m: Moved NSFontDescriptor strings to here. + * GNUMakefile: Add NSFontDescriptor.m + 2007-08-08 Fred Kiefer * Headers/AppKit/NSScreen.h: Add method userSpaceScaleFactor. diff --git a/Headers/AppKit/NSFont.h b/Headers/AppKit/NSFont.h index b857f8bf9..3a565921c 100644 --- a/Headers/AppKit/NSFont.h +++ b/Headers/AppKit/NSFont.h @@ -32,16 +32,17 @@ #define _GNUstep_H_NSFont #import -#include +#include #include -#include #include // For NSControlSize #include -#import -@class NSDictionary; +@class NSAffineTransform; @class NSCharacterSet; +@class NSDictionary; +@class NSFontDescriptor; +@class NSGraphicsContext; typedef unsigned int NSGlyph; @@ -51,7 +52,6 @@ enum { NSNullGlyph = 0x0 }; - typedef enum _NSGlyphRelation { NSGlyphBelow, NSGlyphAbove, @@ -65,6 +65,16 @@ typedef enum _NSMultibyteGlyphPacking { NSFourByteGlyphPacking } NSMultibyteGlyphPacking; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +typedef enum _NSFontRenderingMode +{ + NSFontDefaultRenderingMode = 0, + NSFontAntialiasedRenderingMode, + NSFontIntegerAdvancementsRenderingMode, + NSFontAntialiasedIntegerAdvancementsRenderingMode +} NSFontRenderingMode; +#endif + APPKIT_EXPORT const float *NSFontIdentityMatrix; @interface NSFont : NSObject @@ -121,9 +131,12 @@ APPKIT_EXPORT const float *NSFontIdentityMatrix; + (NSFont*) controlContentFontOfSize: (float)fontSize; + (NSFont*) labelFontOfSize: (float)fontSize; + (NSFont*) menuBarFontOfSize: (float)fontSize; -+ (NSFont *) fontWithDescriptor:(NSFontDescriptor *) descriptor size:(float) size; -+ (NSFont *) fontWithDescriptor:(NSFontDescriptor *) descriptor size:(float) size - textTransform:(NSAffineTransform *) transform; +#endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) ++ (NSFont*) fontWithDescriptor: (NSFontDescriptor*)descriptor size: (float)size; ++ (NSFont*) fontWithDescriptor: (NSFontDescriptor*)descriptor + size: (float)size + textTransform: (NSAffineTransform*)transform; #endif // @@ -149,6 +162,10 @@ APPKIT_EXPORT const float *NSFontIdentityMatrix; + (void) setUserFont: (NSFont*)aFont; + (void) useFont: (NSString*)aFontName; - (void) set; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (void) setInContext: (NSGraphicsContext*)context; +- (NSAffineTransform*) textTransform; +#endif // // Querying the Font @@ -181,7 +198,11 @@ APPKIT_EXPORT const float *NSFontIdentityMatrix; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) - (unsigned) numberOfGlyphs; - (NSCharacterSet*) coveredCharacterSet; +#endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) - (NSFontDescriptor*) fontDescriptor; +- (NSFontRenderingMode) renderingMode; +- (NSFont*) screenFontWithRenderingMode: (NSFontRenderingMode)mode; #endif // diff --git a/Headers/AppKit/NSFontDescriptor.h b/Headers/AppKit/NSFontDescriptor.h index d40cde1b9..3fb305920 100644 --- a/Headers/AppKit/NSFontDescriptor.h +++ b/Headers/AppKit/NSFontDescriptor.h @@ -31,15 +31,19 @@ #ifndef _GNUstep_H_NSFontDescriptor #define _GNUstep_H_NSFontDescriptor -#import "Foundation/NSSet.h" -#import "AppKit/NSController.h" -#import "AppKit/NSAffineTransform.h" +#import -#if OS_API_VERSION(100300, GS_API_LATEST) +#include -@class NSString; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) + +@class NSAffineTransform; +@class NSArray; @class NSCoder; +@class NSSet; +@class NSString; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) typedef uint32_t NSFontSymbolicTraits; typedef enum _NSFontFamilyClass @@ -57,6 +61,10 @@ typedef enum _NSFontFamilyClass NSFontSymbolicClass = 12 << 28 } NSFontFamilyClass; +enum _NSFontFamiliyClassMask { + NSFontFamiliyClassMask = 0xF0000000 +}; + enum _NSFontTrait { NSFontItalicTrait = 0x0001, @@ -68,6 +76,8 @@ enum _NSFontTrait NSFontUIOptimizedTrait = 0x1000 }; +#endif + extern NSString *NSFontFamilyAttribute; extern NSString *NSFontNameAttribute; extern NSString *NSFontFaceAttribute; @@ -95,16 +105,20 @@ extern NSString *NSFontVariationAxisNameKey; @interface NSFontDescriptor : NSObject { NSDictionary *_attributes; - void *_backendPrivate; // caches an FT_Face } + (id) fontDescriptorWithFontAttributes: (NSDictionary *)attributes; + (id) fontDescriptorWithName: (NSString *)name - matrix: (NSAffineTransform *)matrix; + size: (float)size; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) + (id) fontDescriptorWithName: (NSString *)name - size: (float)size; + matrix: (NSAffineTransform *)matrix; +#endif - (NSDictionary *) fontAttributes; +- (id) initWithFontAttributes: (NSDictionary *)attributes; + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) - (NSFontDescriptor *) fontDescriptorByAddingAttributes: (NSDictionary *)attributes; - (NSFontDescriptor *) fontDescriptorWithFace: (NSString *)face; @@ -113,16 +127,17 @@ extern NSString *NSFontVariationAxisNameKey; - (NSFontDescriptor *) fontDescriptorWithSize: (float)size; - (NSFontDescriptor *) fontDescriptorWithSymbolicTraits: (NSFontSymbolicTraits)traits; -- (id) initWithFontAttributes: (NSDictionary *)attributes; - (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *)keys; + - (id) objectForKey: (NSString *)attribute; -- (NSAffineTransform *)matrix; +- (NSAffineTransform *) matrix; - (float) pointSize; - (NSString *) postscriptName; - (NSFontSymbolicTraits) symbolicTraits; +#endif @end -#endif /* OS_API_VERSION(100300, GS_API_LATEST) */ +#endif /* OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) */ #endif /* _GNUstep_H_NSFontDescriptor */ diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 9552cc414..0aa369b23 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -91,6 +91,7 @@ NSEPSImageRep.m \ NSEvent.m \ NSFileWrapper.m \ NSFont.m \ +NSFontDescriptor.m \ NSFontManager.m \ NSFontPanel.m \ NSForm.m \ diff --git a/Source/NSFont.m b/Source/NSFont.m index e8263ef02..7f2332613 100644 --- a/Source/NSFont.m +++ b/Source/NSFont.m @@ -27,6 +27,8 @@ */ #include "config.h" +#include +#include #include #include #include @@ -37,6 +39,7 @@ #include "AppKit/NSGraphicsContext.h" #include "AppKit/NSFont.h" +#include #include "AppKit/NSFontManager.h" #include "AppKit/NSView.h" #include "GNUstepGUI/GSFontInfo.h" @@ -444,13 +447,14 @@ static void setNSFont(NSString *key, NSFont *font) */ placeHolder = [self alloc]; globalFontMap = NSCreateMapTable(NSObjectMapKeyCallBacks, - NSNonRetainedObjectMapValueCallBacks, 64); + NSNonRetainedObjectMapValueCallBacks, 64); if (defaults == nil) - { - defaults = RETAIN([NSUserDefaults standardUserDefaults]); - } + { + defaults = RETAIN([NSUserDefaults standardUserDefaults]); + } + _preferredFonts = [defaults objectForKey: @"NSPreferredFonts"]; [self setVersion: currentVersion]; } } @@ -497,7 +501,7 @@ static void setNSFont(NSString *key, NSFont *font) } + (NSFont *) fontWithDescriptor: (NSFontDescriptor *)descriptor - size: (float)size + size: (float)size { return [self fontWithDescriptor: descriptor size: size textTransform: nil]; } @@ -505,10 +509,11 @@ static void setNSFont(NSString *key, NSFont *font) // the transform/matrix can be used to rotate/scale/shear the whole font (independently of the CTM!) + (NSFont *) fontWithDescriptor: (NSFontDescriptor *)descriptor - size: (float)size - textTransform: (NSAffineTransform *)transform + size: (float)size + textTransform: (NSAffineTransform *)transform { NSArray *a; + NSFontDescriptor *fd; if (size == 0.0) size = [NSFont systemFontSize]; // default @@ -522,13 +527,17 @@ static void setNSFont(NSString *key, NSFont *font) } // match all keys + // FIXME: Matching on size and matrix seems nonsensical. a = [descriptor matchingFontDescriptorsWithMandatoryKeys: [NSSet setWithArray: [[descriptor fontAttributes] allKeys]]]; if ([a count] == 0) return nil; - return [a objectAtIndex: 0]; // return first matching font + // return first matching font + fd = [a objectAtIndex: 0]; + // FIXME: Use NSFontManger to get a font name and create that font + return nil; } @@ -558,6 +567,7 @@ static void setNSFont(NSString *key, NSFont *font) + (void) setPreferredFontNames: (NSArray*)fontNames { ASSIGN(_preferredFonts, fontNames); + // FIXME: Should this store back the preferred fonts in the user defaults? } /* Getting various fonts*/ @@ -918,8 +928,11 @@ static BOOL flip_hack; without explicitly setting the font matrix */ - (void) set { - NSGraphicsContext *ctxt = GSCurrentContext(); + [self setInContext: GSCurrentContext()]; +} +- (void) setInContext: (NSGraphicsContext*)ctxt +{ if (matrixExplicitlySet == NO && ([[NSView focusView] isFlipped] || flip_hack)) [ctxt GSSetFont: [[self _flippedViewFont] fontRef]]; else @@ -946,6 +959,23 @@ static BOOL flip_hack; return matrix; } +- (NSAffineTransform*) textTransform +{ + NSAffineTransform *transform; + NSAffineTransformStruct tstruct; + + tstruct.m11 = matrix[0]; + tstruct.m12 = matrix[1]; + tstruct.m21 = matrix[2]; + tstruct.m22 = matrix[3]; + tstruct.tX = matrix[4]; + tstruct.tY = matrix[5]; + + transform = [NSAffineTransform transform]; + [transform setTransformStruct: tstruct]; + return transform; +} + - (NSString*) encodingScheme { return [fontInfo encodingScheme]; @@ -1018,6 +1048,18 @@ static BOOL flip_hack; return AUTORELEASE(RETAIN(cachedScreenFont)); } +- (NSFont*) screenFontWithRenderingMode: (NSFontRenderingMode)mode +{ + // FIXME + return [self screenFont]; +} + +- (NSFontRenderingMode) renderingMode +{ + // FIXME + return NSFontDefaultRenderingMode; +} + - (float) ascender { return [fontInfo ascender]; } - (float) descender { return [fontInfo descender]; } - (float) capHeight { return [fontInfo capHeight]; } @@ -1424,194 +1466,3 @@ int NSConvertGlyphsToPackedGlyphs(NSGlyph *glBuf, return j; } - -NSString *NSFontFamilyAttribute=@"Family"; -NSString *NSFontNameAttribute=@"Name"; -NSString *NSFontFaceAttribute=@"Face"; -NSString *NSFontSizeAttribute=@"Size"; -NSString *NSFontVisibleNameAttribute=@"VisibleName"; -NSString *NSFontColorAttribute=@"Color"; -NSString *NSFontMatrixAttribute=@"Matrix"; -NSString *NSFontVariationAttribute=@"Variation"; -NSString *NSFontCharacterSetAttribute=@"CharacterSet"; -NSString *NSFontCascadeListAttribute=@"CascadeList"; -NSString *NSFontTraitsAttribute=@"Traits"; -NSString *NSFontFixedAdvanceAttribute=@"FixedAdvance"; - -NSString *NSFontSymbolicTrait=@"SymbolicTrait"; -NSString *NSFontWeightTrait=@"WeightTrait"; -NSString *NSFontWidthTrait=@"WidthTrait"; -NSString *NSFontSlantTrait=@"SlantTrait"; - -NSString *NSFontVariationAxisIdentifierKey=@"VariationAxisIdentifier"; -NSString *NSFontVariationAxisMinimumValueKey=@"VariationAxisMinimumValue"; -NSString *NSFontVariationAxisMaximumValueKey=@"VariationAxisMaximumValue"; -NSString *NSFontVariationAxisDefaultValueKey=@"VariationAxisDefaultValue"; -NSString *NSFontVariationAxisNameKey=@"VariationAxisName"; - - -@implementation NSFontDescriptor - -+ (id) fontDescriptorWithFontAttributes: (NSDictionary *) attributes; -{ - return [[[self alloc] initWithFontAttributes:attributes] autorelease]; -} - -+ (id) fontDescriptorWithName: (NSString *)name - matrix: (NSAffineTransform *)matrix -{ - return [self fontDescriptorWithFontAttributes: - [NSDictionary dictionaryWithObjectsAndKeys: - name, NSFontNameAttribute, - matrix, NSFontMatrixAttribute, - nil]]; -} - -+ (id) fontDescriptorWithName: (NSString *)name size: (float)size -{ - return [self fontDescriptorWithFontAttributes: - [NSDictionary dictionaryWithObjectsAndKeys: - name, NSFontNameAttribute, - [NSString stringWithFormat: @"%f", size], NSFontSizeAttribute, - nil]]; -} - -- (NSDictionary *) fontAttributes -{ - return _attributes; -} - -- (NSFontDescriptor *) fontDescriptorByAddingAttributes: - (NSDictionary *)attributes -{ - NSFontDescriptor *fd = [super copy]; - - if (fd != nil) - { - NSMutableDictionary *m = [_attributes mutableCopy]; - - fd->_attributes = m; // current attributes - [m addEntriesFromDictionary: attributes]; // change - } - return AUTORELEASE(fd); -} - -- (NSFontDescriptor *) fontDescriptorWithFace: (NSString *)face -{ - return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: face forKey: NSFontFaceAttribute]]; -} - -- (NSFontDescriptor *) fontDescriptorWithFamily: (NSString *)family -{ - return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: family forKey: NSFontFamilyAttribute]]; -} - -- (NSFontDescriptor *) fontDescriptorWithMatrix: (NSAffineTransform *)matrix -{ - return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: matrix forKey: NSFontMatrixAttribute]]; -} - -- (NSFontDescriptor *) fontDescriptorWithSize: (float)size -{ - return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: [NSNumber numberWithFloat: size] - forKey: NSFontSizeAttribute]]; -} - -- (NSFontDescriptor *) fontDescriptorWithSymbolicTraits: - (NSFontSymbolicTraits)traits -{ - return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedInt: traits] - forKey: NSFontSymbolicTrait]]; -} - -- (id) initWithFontAttributes: (NSDictionary *) attributes; -{ - if ((self = [super init]) != nil) - { - if (attributes) - _attributes = [attributes copy]; - else - _attributes = [NSDictionary new]; - } - return self; -} - -- (void) encodeWithCoder: (NSCoder *)aCoder -{ -} - -- (id) initWithCoder: (NSCoder *)aDecoder -{ - if (![aDecoder allowsKeyedCoding]) - ; // TODO FIXME (copied from mgstep) - _attributes = RETAIN([aDecoder decodeObjectForKey: @"NSAttributes"]); - return self; -} - -- (void) dealloc; -{ - RELEASE(_attributes); - [super dealloc]; -} - -- (id) copyWithZone: (NSZone *)z -{ - NSFontDescriptor *f = [isa allocWithZone: z]; - - if (f != nil) - { - f->_attributes = [_attributes copyWithZone: z]; - } - return f; -} - -/* -TODO FIXME: how to port this from mgStep ? -- (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *) keys; // this is the core font search engine that knows about font directories -{ - return BACKEND; -} -*/ - -- (NSAffineTransform *) matrix -{ - return [_attributes objectForKey: NSFontMatrixAttribute]; -} - -- (id) objectForKey: (NSString *)attribute -{ - return [_attributes objectForKey: attribute]; -} - -- (float) pointSize -{ - return [[_attributes objectForKey: NSFontSizeAttribute] floatValue]; -} - -- (NSFontSymbolicTraits) symbolicTraits -{ - return [[_attributes objectForKey: NSFontSymbolicTrait] unsignedIntValue]; -} - -- (NSString *) postscriptName; -{ - NSMutableString *family; - NSString *face; - - family = AUTORELEASE([[self objectForKey:NSFontFamilyAttribute] mutableCopy]); - face = [self objectForKey: NSFontFaceAttribute]; - [family replaceOccurrencesOfString: @" " - withString: @"" - options: 0 - range: NSMakeRange(0, [family length])]; - if ([face isEqualToString:@"Regular"]) - return family; - return [NSString stringWithFormat: @"%@-%@", family, face]; -} - -@end diff --git a/Source/NSFontDescriptor.m b/Source/NSFontDescriptor.m new file mode 100644 index 000000000..49d92203d --- /dev/null +++ b/Source/NSFontDescriptor.m @@ -0,0 +1,254 @@ +/** NSFontDescriptor + + The font descriptor class + + Copyright (C) 2007 Free Software Foundation, Inc. + + Author: H. Nikolaus Schaller + Date: 2006 + Extracted from NSFont: Fred Kiefer + Date August 2007 + + 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, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include "config.h" +#include +#include +#include +#include +#include +#include + +#include "AppKit/NSAffineTransform.h" +#include "AppKit/NSFontDescriptor.h" + +@implementation NSFontDescriptor + ++ (id) fontDescriptorWithFontAttributes: (NSDictionary *)attributes +{ + return AUTORELEASE([[self alloc] initWithFontAttributes: attributes]); +} + ++ (id) fontDescriptorWithName: (NSString *)name + matrix: (NSAffineTransform *)matrix +{ + return [self fontDescriptorWithFontAttributes: + [NSDictionary dictionaryWithObjectsAndKeys: + name, NSFontNameAttribute, + matrix, NSFontMatrixAttribute, + nil]]; +} + ++ (id) fontDescriptorWithName: (NSString *)name size: (float)size +{ + return [self fontDescriptorWithFontAttributes: + [NSDictionary dictionaryWithObjectsAndKeys: + name, NSFontNameAttribute, + [NSString stringWithFormat: @"%f", size], NSFontSizeAttribute, + nil]]; +} + +- (NSDictionary *) fontAttributes +{ + return _attributes; +} + +- (NSFontDescriptor *) fontDescriptorByAddingAttributes: + (NSDictionary *)attributes +{ + NSMutableDictionary *m = [_attributes mutableCopy]; + + [m addEntriesFromDictionary: attributes]; + + return [isa fontDescriptorWithFontAttributes: m] ; +} + +- (NSFontDescriptor *) fontDescriptorWithFace: (NSString *)face +{ + return [self fontDescriptorByAddingAttributes: + [NSDictionary dictionaryWithObject: face forKey: NSFontFaceAttribute]]; +} + +- (NSFontDescriptor *) fontDescriptorWithFamily: (NSString *)family +{ + return [self fontDescriptorByAddingAttributes: + [NSDictionary dictionaryWithObject: family forKey: NSFontFamilyAttribute]]; +} + +- (NSFontDescriptor *) fontDescriptorWithMatrix: (NSAffineTransform *)matrix +{ + return [self fontDescriptorByAddingAttributes: + [NSDictionary dictionaryWithObject: matrix forKey: NSFontMatrixAttribute]]; +} + +- (NSFontDescriptor *) fontDescriptorWithSize: (float)size +{ + return [self fontDescriptorByAddingAttributes: + [NSDictionary dictionaryWithObject: [NSNumber numberWithFloat: size] + forKey: NSFontSizeAttribute]]; +} + +- (NSFontDescriptor *) fontDescriptorWithSymbolicTraits: + (NSFontSymbolicTraits)traits +{ + return [self fontDescriptorByAddingAttributes: + [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedInt: traits] + forKey: NSFontSymbolicTrait]]; +} + +- (id) initWithFontAttributes: (NSDictionary *) attributes +{ + if ((self = [super init]) != nil) + { + if (attributes) + _attributes = [attributes copy]; + else + _attributes = [NSDictionary new]; + } + return self; +} + +- (void) encodeWithCoder: (NSCoder *)aCoder +{ + if ([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: _attributes forKey: @"NSAttributes"]; + } + else + { + // FIXME + } +} + +- (id) initWithCoder: (NSCoder *)aDecoder +{ + if ([aDecoder allowsKeyedCoding]) + { + _attributes = RETAIN([aDecoder decodeObjectForKey: @"NSAttributes"]); + } + else + { + // FIXME + } + return self; +} + +- (void) dealloc; +{ + RELEASE(_attributes); + [super dealloc]; +} + +- (id) copyWithZone: (NSZone *)z +{ + NSFontDescriptor *f = [isa allocWithZone: z]; + + if (f != nil) + { + f->_attributes = [_attributes copyWithZone: z]; + } + return f; +} + +// this is the core font search engine that knows about font directories +- (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *)keys +{ + NSMutableArray *found; + NSEnumerator *fdEnumerator; + NSFontDescriptor *fd; + + found = [NSMutableArray arrayWithCapacity: 3]; + // FIXME: Get an enumerator for all available font descriptors + fdEnumerator = nil; + while ((fd = [fdEnumerator nextObject]) != nil) + { + NSEnumerator *keyEnumerator; + NSString *key; + BOOL match = YES; + + keyEnumerator = [keys objectEnumerator]; + while ((key = [keyEnumerator nextObject]) != nil) + { + id value = [self objectForKey: key]; + + if (value != nil) + { + if (![value isEqual: [fd objectForKey: key]]) + { + match = NO; + break; + } + } + } + + if (match) + { + [found addObject: fd]; + } + } + + return found; +} + + +- (NSAffineTransform *) matrix +{ + return [_attributes objectForKey: NSFontMatrixAttribute]; +} + +- (id) objectForKey: (NSString *)attribute +{ + return [_attributes objectForKey: attribute]; +} + +- (float) pointSize +{ + id size = [_attributes objectForKey: NSFontSizeAttribute]; + + if (size) + { + return [size floatValue]; + } + else + { + return 0.0; + } +} + +- (NSFontSymbolicTraits) symbolicTraits +{ + return [[_attributes objectForKey: NSFontSymbolicTrait] unsignedIntValue]; +} + +- (NSString *) postscriptName +{ + NSMutableString *family; + NSString *face; + + family = AUTORELEASE([[self objectForKey: NSFontFamilyAttribute] mutableCopy]); + face = [self objectForKey: NSFontFaceAttribute]; + [family replaceOccurrencesOfString: @" " + withString: @"" + options: 0 + range: NSMakeRange(0, [family length])]; + if ([face isEqualToString: @"Regular"]) + return family; + return [NSString stringWithFormat: @"%@-%@", family, face]; +} + +@end diff --git a/Source/externs.m b/Source/externs.m index 9280fa9ef..77dc0236e 100644 --- a/Source/externs.m +++ b/Source/externs.m @@ -222,6 +222,31 @@ NSString *NSAFMVersion = @"Version"; NSString *NSAFMWeight = @"Weight"; NSString *NSAFMXHeight = @"XHeight"; +// NSFontDescriptor global strings +NSString *NSFontFamilyAttribute = @"Family"; +NSString *NSFontNameAttribute = @"Name"; +NSString *NSFontFaceAttribute = @"Face"; +NSString *NSFontSizeAttribute = @"Size"; +NSString *NSFontVisibleNameAttribute = @"VisibleName"; +NSString *NSFontColorAttribute = @"Color"; +NSString *NSFontMatrixAttribute = @"Matrix"; +NSString *NSFontVariationAttribute = @"Variation"; +NSString *NSFontCharacterSetAttribute = @"CharacterSet"; +NSString *NSFontCascadeListAttribute = @"CascadeList"; +NSString *NSFontTraitsAttribute = @"Traits"; +NSString *NSFontFixedAdvanceAttribute = @"FixedAdvance"; + +NSString *NSFontSymbolicTrait = @"SymbolicTrait"; +NSString *NSFontWeightTrait = @"WeightTrait"; +NSString *NSFontWidthTrait = @"WidthTrait"; +NSString *NSFontSlantTrait = @"SlantTrait"; + +NSString *NSFontVariationAxisIdentifierKey = @"VariationAxisIdentifier"; +NSString *NSFontVariationAxisMinimumValueKey = @"VariationAxisMinimumValue"; +NSString *NSFontVariationAxisMaximumValueKey = @"VariationAxisMaximumValue"; +NSString *NSFontVariationAxisDefaultValueKey = @"VariationAxisDefaultValue"; +NSString *NSFontVariationAxisNameKey = @"VariationAxisName"; + // NSScreen Global device dictionary key strings NSString *NSDeviceResolution = @"NSDeviceResolution"; NSString *NSDeviceColorSpaceName = @"NSDeviceColorSpaceName";