mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 11:41:06 +00:00
Clean up for font descriptor and missing MacOSX 10.4 methods for NSFont.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25383 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3296c3c0e5
commit
49e48c0ce6
7 changed files with 397 additions and 219 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2007-08-08 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* 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 <FredKiefer@gmx.de>
|
2007-08-08 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/AppKit/NSScreen.h: Add method userSpaceScaleFactor.
|
* Headers/AppKit/NSScreen.h: Add method userSpaceScaleFactor.
|
||||||
|
|
|
@ -32,16 +32,17 @@
|
||||||
#define _GNUstep_H_NSFont
|
#define _GNUstep_H_NSFont
|
||||||
#import <GNUstepBase/GSVersionMacros.h>
|
#import <GNUstepBase/GSVersionMacros.h>
|
||||||
|
|
||||||
#include <Foundation/NSCoder.h>
|
#include <Foundation/NSObject.h>
|
||||||
#include <Foundation/NSGeometry.h>
|
#include <Foundation/NSGeometry.h>
|
||||||
#include <Foundation/NSString.h>
|
|
||||||
#include <AppKit/AppKitDefines.h>
|
#include <AppKit/AppKitDefines.h>
|
||||||
// For NSControlSize
|
// For NSControlSize
|
||||||
#include <AppKit/NSColor.h>
|
#include <AppKit/NSColor.h>
|
||||||
#import <AppKit/NSFontDescriptor.h>
|
|
||||||
|
|
||||||
@class NSDictionary;
|
@class NSAffineTransform;
|
||||||
@class NSCharacterSet;
|
@class NSCharacterSet;
|
||||||
|
@class NSDictionary;
|
||||||
|
@class NSFontDescriptor;
|
||||||
|
@class NSGraphicsContext;
|
||||||
|
|
||||||
typedef unsigned int NSGlyph;
|
typedef unsigned int NSGlyph;
|
||||||
|
|
||||||
|
@ -51,7 +52,6 @@ enum {
|
||||||
NSNullGlyph = 0x0
|
NSNullGlyph = 0x0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef enum _NSGlyphRelation {
|
typedef enum _NSGlyphRelation {
|
||||||
NSGlyphBelow,
|
NSGlyphBelow,
|
||||||
NSGlyphAbove,
|
NSGlyphAbove,
|
||||||
|
@ -65,6 +65,16 @@ typedef enum _NSMultibyteGlyphPacking {
|
||||||
NSFourByteGlyphPacking
|
NSFourByteGlyphPacking
|
||||||
} NSMultibyteGlyphPacking;
|
} 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;
|
APPKIT_EXPORT const float *NSFontIdentityMatrix;
|
||||||
|
|
||||||
@interface NSFont : NSObject <NSCoding, NSCopying>
|
@interface NSFont : NSObject <NSCoding, NSCopying>
|
||||||
|
@ -121,9 +131,12 @@ APPKIT_EXPORT const float *NSFontIdentityMatrix;
|
||||||
+ (NSFont*) controlContentFontOfSize: (float)fontSize;
|
+ (NSFont*) controlContentFontOfSize: (float)fontSize;
|
||||||
+ (NSFont*) labelFontOfSize: (float)fontSize;
|
+ (NSFont*) labelFontOfSize: (float)fontSize;
|
||||||
+ (NSFont*) menuBarFontOfSize: (float)fontSize;
|
+ (NSFont*) menuBarFontOfSize: (float)fontSize;
|
||||||
+ (NSFont *) fontWithDescriptor:(NSFontDescriptor *) descriptor size:(float) size;
|
#endif
|
||||||
+ (NSFont *) fontWithDescriptor:(NSFontDescriptor *) descriptor size:(float) size
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
textTransform:(NSAffineTransform *) transform;
|
+ (NSFont*) fontWithDescriptor: (NSFontDescriptor*)descriptor size: (float)size;
|
||||||
|
+ (NSFont*) fontWithDescriptor: (NSFontDescriptor*)descriptor
|
||||||
|
size: (float)size
|
||||||
|
textTransform: (NSAffineTransform*)transform;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -149,6 +162,10 @@ APPKIT_EXPORT const float *NSFontIdentityMatrix;
|
||||||
+ (void) setUserFont: (NSFont*)aFont;
|
+ (void) setUserFont: (NSFont*)aFont;
|
||||||
+ (void) useFont: (NSString*)aFontName;
|
+ (void) useFont: (NSString*)aFontName;
|
||||||
- (void) set;
|
- (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
|
// Querying the Font
|
||||||
|
@ -181,7 +198,11 @@ APPKIT_EXPORT const float *NSFontIdentityMatrix;
|
||||||
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
||||||
- (unsigned) numberOfGlyphs;
|
- (unsigned) numberOfGlyphs;
|
||||||
- (NSCharacterSet*) coveredCharacterSet;
|
- (NSCharacterSet*) coveredCharacterSet;
|
||||||
|
#endif
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
- (NSFontDescriptor*) fontDescriptor;
|
- (NSFontDescriptor*) fontDescriptor;
|
||||||
|
- (NSFontRenderingMode) renderingMode;
|
||||||
|
- (NSFont*) screenFontWithRenderingMode: (NSFontRenderingMode)mode;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -31,15 +31,19 @@
|
||||||
#ifndef _GNUstep_H_NSFontDescriptor
|
#ifndef _GNUstep_H_NSFontDescriptor
|
||||||
#define _GNUstep_H_NSFontDescriptor
|
#define _GNUstep_H_NSFontDescriptor
|
||||||
|
|
||||||
#import "Foundation/NSSet.h"
|
#import <GNUstepBase/GSVersionMacros.h>
|
||||||
#import "AppKit/NSController.h"
|
|
||||||
#import "AppKit/NSAffineTransform.h"
|
|
||||||
|
|
||||||
#if OS_API_VERSION(100300, GS_API_LATEST)
|
#include <Foundation/NSObject.h>
|
||||||
|
|
||||||
@class NSString;
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
|
||||||
|
|
||||||
|
@class NSAffineTransform;
|
||||||
|
@class NSArray;
|
||||||
@class NSCoder;
|
@class NSCoder;
|
||||||
|
@class NSSet;
|
||||||
|
@class NSString;
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
typedef uint32_t NSFontSymbolicTraits;
|
typedef uint32_t NSFontSymbolicTraits;
|
||||||
|
|
||||||
typedef enum _NSFontFamilyClass
|
typedef enum _NSFontFamilyClass
|
||||||
|
@ -57,6 +61,10 @@ typedef enum _NSFontFamilyClass
|
||||||
NSFontSymbolicClass = 12 << 28
|
NSFontSymbolicClass = 12 << 28
|
||||||
} NSFontFamilyClass;
|
} NSFontFamilyClass;
|
||||||
|
|
||||||
|
enum _NSFontFamiliyClassMask {
|
||||||
|
NSFontFamiliyClassMask = 0xF0000000
|
||||||
|
};
|
||||||
|
|
||||||
enum _NSFontTrait
|
enum _NSFontTrait
|
||||||
{
|
{
|
||||||
NSFontItalicTrait = 0x0001,
|
NSFontItalicTrait = 0x0001,
|
||||||
|
@ -68,6 +76,8 @@ enum _NSFontTrait
|
||||||
NSFontUIOptimizedTrait = 0x1000
|
NSFontUIOptimizedTrait = 0x1000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
extern NSString *NSFontFamilyAttribute;
|
extern NSString *NSFontFamilyAttribute;
|
||||||
extern NSString *NSFontNameAttribute;
|
extern NSString *NSFontNameAttribute;
|
||||||
extern NSString *NSFontFaceAttribute;
|
extern NSString *NSFontFaceAttribute;
|
||||||
|
@ -95,16 +105,20 @@ extern NSString *NSFontVariationAxisNameKey;
|
||||||
@interface NSFontDescriptor : NSObject <NSCoding>
|
@interface NSFontDescriptor : NSObject <NSCoding>
|
||||||
{
|
{
|
||||||
NSDictionary *_attributes;
|
NSDictionary *_attributes;
|
||||||
void *_backendPrivate; // caches an FT_Face
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id) fontDescriptorWithFontAttributes: (NSDictionary *)attributes;
|
+ (id) fontDescriptorWithFontAttributes: (NSDictionary *)attributes;
|
||||||
+ (id) fontDescriptorWithName: (NSString *)name
|
+ (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
|
+ (id) fontDescriptorWithName: (NSString *)name
|
||||||
size: (float)size;
|
matrix: (NSAffineTransform *)matrix;
|
||||||
|
#endif
|
||||||
|
|
||||||
- (NSDictionary *) fontAttributes;
|
- (NSDictionary *) fontAttributes;
|
||||||
|
- (id) initWithFontAttributes: (NSDictionary *)attributes;
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
- (NSFontDescriptor *) fontDescriptorByAddingAttributes:
|
- (NSFontDescriptor *) fontDescriptorByAddingAttributes:
|
||||||
(NSDictionary *)attributes;
|
(NSDictionary *)attributes;
|
||||||
- (NSFontDescriptor *) fontDescriptorWithFace: (NSString *)face;
|
- (NSFontDescriptor *) fontDescriptorWithFace: (NSString *)face;
|
||||||
|
@ -113,16 +127,17 @@ extern NSString *NSFontVariationAxisNameKey;
|
||||||
- (NSFontDescriptor *) fontDescriptorWithSize: (float)size;
|
- (NSFontDescriptor *) fontDescriptorWithSize: (float)size;
|
||||||
- (NSFontDescriptor *) fontDescriptorWithSymbolicTraits:
|
- (NSFontDescriptor *) fontDescriptorWithSymbolicTraits:
|
||||||
(NSFontSymbolicTraits)traits;
|
(NSFontSymbolicTraits)traits;
|
||||||
- (id) initWithFontAttributes: (NSDictionary *)attributes;
|
|
||||||
- (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *)keys;
|
- (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *)keys;
|
||||||
|
|
||||||
- (id) objectForKey: (NSString *)attribute;
|
- (id) objectForKey: (NSString *)attribute;
|
||||||
- (NSAffineTransform *)matrix;
|
- (NSAffineTransform *) matrix;
|
||||||
- (float) pointSize;
|
- (float) pointSize;
|
||||||
- (NSString *) postscriptName;
|
- (NSString *) postscriptName;
|
||||||
- (NSFontSymbolicTraits) symbolicTraits;
|
- (NSFontSymbolicTraits) symbolicTraits;
|
||||||
|
#endif
|
||||||
|
|
||||||
@end
|
@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 */
|
#endif /* _GNUstep_H_NSFontDescriptor */
|
||||||
|
|
|
@ -91,6 +91,7 @@ NSEPSImageRep.m \
|
||||||
NSEvent.m \
|
NSEvent.m \
|
||||||
NSFileWrapper.m \
|
NSFileWrapper.m \
|
||||||
NSFont.m \
|
NSFont.m \
|
||||||
|
NSFontDescriptor.m \
|
||||||
NSFontManager.m \
|
NSFontManager.m \
|
||||||
NSFontPanel.m \
|
NSFontPanel.m \
|
||||||
NSForm.m \
|
NSForm.m \
|
||||||
|
|
251
Source/NSFont.m
251
Source/NSFont.m
|
@ -27,6 +27,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <Foundation/NSAffineTransform.h>
|
||||||
|
#include <Foundation/NSCoder.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSUserDefaults.h>
|
#include <Foundation/NSUserDefaults.h>
|
||||||
#include <Foundation/NSSet.h>
|
#include <Foundation/NSSet.h>
|
||||||
|
@ -37,6 +39,7 @@
|
||||||
|
|
||||||
#include "AppKit/NSGraphicsContext.h"
|
#include "AppKit/NSGraphicsContext.h"
|
||||||
#include "AppKit/NSFont.h"
|
#include "AppKit/NSFont.h"
|
||||||
|
#include <AppKit/NSFontDescriptor.h>
|
||||||
#include "AppKit/NSFontManager.h"
|
#include "AppKit/NSFontManager.h"
|
||||||
#include "AppKit/NSView.h"
|
#include "AppKit/NSView.h"
|
||||||
#include "GNUstepGUI/GSFontInfo.h"
|
#include "GNUstepGUI/GSFontInfo.h"
|
||||||
|
@ -444,13 +447,14 @@ static void setNSFont(NSString *key, NSFont *font)
|
||||||
*/
|
*/
|
||||||
placeHolder = [self alloc];
|
placeHolder = [self alloc];
|
||||||
globalFontMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
globalFontMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
NSNonRetainedObjectMapValueCallBacks, 64);
|
NSNonRetainedObjectMapValueCallBacks, 64);
|
||||||
|
|
||||||
if (defaults == nil)
|
if (defaults == nil)
|
||||||
{
|
{
|
||||||
defaults = RETAIN([NSUserDefaults standardUserDefaults]);
|
defaults = RETAIN([NSUserDefaults standardUserDefaults]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_preferredFonts = [defaults objectForKey: @"NSPreferredFonts"];
|
||||||
[self setVersion: currentVersion];
|
[self setVersion: currentVersion];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,7 +501,7 @@ static void setNSFont(NSString *key, NSFont *font)
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSFont *) fontWithDescriptor: (NSFontDescriptor *)descriptor
|
+ (NSFont *) fontWithDescriptor: (NSFontDescriptor *)descriptor
|
||||||
size: (float)size
|
size: (float)size
|
||||||
{
|
{
|
||||||
return [self fontWithDescriptor: descriptor size: size textTransform: nil];
|
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!)
|
// the transform/matrix can be used to rotate/scale/shear the whole font (independently of the CTM!)
|
||||||
|
|
||||||
+ (NSFont *) fontWithDescriptor: (NSFontDescriptor *)descriptor
|
+ (NSFont *) fontWithDescriptor: (NSFontDescriptor *)descriptor
|
||||||
size: (float)size
|
size: (float)size
|
||||||
textTransform: (NSAffineTransform *)transform
|
textTransform: (NSAffineTransform *)transform
|
||||||
{
|
{
|
||||||
NSArray *a;
|
NSArray *a;
|
||||||
|
NSFontDescriptor *fd;
|
||||||
|
|
||||||
if (size == 0.0)
|
if (size == 0.0)
|
||||||
size = [NSFont systemFontSize]; // default
|
size = [NSFont systemFontSize]; // default
|
||||||
|
@ -522,13 +527,17 @@ static void setNSFont(NSString *key, NSFont *font)
|
||||||
}
|
}
|
||||||
|
|
||||||
// match all keys
|
// match all keys
|
||||||
|
// FIXME: Matching on size and matrix seems nonsensical.
|
||||||
a = [descriptor matchingFontDescriptorsWithMandatoryKeys:
|
a = [descriptor matchingFontDescriptorsWithMandatoryKeys:
|
||||||
[NSSet setWithArray: [[descriptor fontAttributes] allKeys]]];
|
[NSSet setWithArray: [[descriptor fontAttributes] allKeys]]];
|
||||||
|
|
||||||
if ([a count] == 0)
|
if ([a count] == 0)
|
||||||
return nil;
|
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
|
+ (void) setPreferredFontNames: (NSArray*)fontNames
|
||||||
{
|
{
|
||||||
ASSIGN(_preferredFonts, fontNames);
|
ASSIGN(_preferredFonts, fontNames);
|
||||||
|
// FIXME: Should this store back the preferred fonts in the user defaults?
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getting various fonts*/
|
/* Getting various fonts*/
|
||||||
|
@ -918,8 +928,11 @@ static BOOL flip_hack;
|
||||||
without explicitly setting the font matrix */
|
without explicitly setting the font matrix */
|
||||||
- (void) set
|
- (void) set
|
||||||
{
|
{
|
||||||
NSGraphicsContext *ctxt = GSCurrentContext();
|
[self setInContext: GSCurrentContext()];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setInContext: (NSGraphicsContext*)ctxt
|
||||||
|
{
|
||||||
if (matrixExplicitlySet == NO && ([[NSView focusView] isFlipped] || flip_hack))
|
if (matrixExplicitlySet == NO && ([[NSView focusView] isFlipped] || flip_hack))
|
||||||
[ctxt GSSetFont: [[self _flippedViewFont] fontRef]];
|
[ctxt GSSetFont: [[self _flippedViewFont] fontRef]];
|
||||||
else
|
else
|
||||||
|
@ -946,6 +959,23 @@ static BOOL flip_hack;
|
||||||
return matrix;
|
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
|
- (NSString*) encodingScheme
|
||||||
{
|
{
|
||||||
return [fontInfo encodingScheme];
|
return [fontInfo encodingScheme];
|
||||||
|
@ -1018,6 +1048,18 @@ static BOOL flip_hack;
|
||||||
return AUTORELEASE(RETAIN(cachedScreenFont));
|
return AUTORELEASE(RETAIN(cachedScreenFont));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSFont*) screenFontWithRenderingMode: (NSFontRenderingMode)mode
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return [self screenFont];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSFontRenderingMode) renderingMode
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return NSFontDefaultRenderingMode;
|
||||||
|
}
|
||||||
|
|
||||||
- (float) ascender { return [fontInfo ascender]; }
|
- (float) ascender { return [fontInfo ascender]; }
|
||||||
- (float) descender { return [fontInfo descender]; }
|
- (float) descender { return [fontInfo descender]; }
|
||||||
- (float) capHeight { return [fontInfo capHeight]; }
|
- (float) capHeight { return [fontInfo capHeight]; }
|
||||||
|
@ -1424,194 +1466,3 @@ int NSConvertGlyphsToPackedGlyphs(NSGlyph *glBuf,
|
||||||
|
|
||||||
return j;
|
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
|
|
||||||
|
|
254
Source/NSFontDescriptor.m
Normal file
254
Source/NSFontDescriptor.m
Normal file
|
@ -0,0 +1,254 @@
|
||||||
|
/** <title>NSFontDescriptor</title>
|
||||||
|
|
||||||
|
<abstract>The font descriptor class</abstract>
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Author: H. Nikolaus Schaller <hns@computer.org>
|
||||||
|
Date: 2006
|
||||||
|
Extracted from NSFont: Fred Kiefer <fredkiefer@gmx.de>
|
||||||
|
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 <Foundation/NSArray.h>
|
||||||
|
#include <Foundation/NSCoder.h>
|
||||||
|
#include <Foundation/NSDictionary.h>
|
||||||
|
#include <Foundation/NSEnumerator.h>
|
||||||
|
#include <Foundation/NSString.h>
|
||||||
|
#include <Foundation/NSValue.h>
|
||||||
|
|
||||||
|
#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
|
|
@ -222,6 +222,31 @@ NSString *NSAFMVersion = @"Version";
|
||||||
NSString *NSAFMWeight = @"Weight";
|
NSString *NSAFMWeight = @"Weight";
|
||||||
NSString *NSAFMXHeight = @"XHeight";
|
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
|
// NSScreen Global device dictionary key strings
|
||||||
NSString *NSDeviceResolution = @"NSDeviceResolution";
|
NSString *NSDeviceResolution = @"NSDeviceResolution";
|
||||||
NSString *NSDeviceColorSpaceName = @"NSDeviceColorSpaceName";
|
NSString *NSDeviceColorSpaceName = @"NSDeviceColorSpaceName";
|
||||||
|
|
Loading…
Reference in a new issue