mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Tidied
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6536 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1d8ffc96a1
commit
33ae13a994
1 changed files with 102 additions and 96 deletions
198
Source/NSFont.m
198
Source/NSFont.m
|
@ -38,146 +38,149 @@
|
|||
|
||||
@implementation NSFont
|
||||
|
||||
/* Class variables */
|
||||
/* 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). */
|
||||
Convention (see the red book).*/
|
||||
static NSMutableSet* fontsUsed = nil;
|
||||
|
||||
NSFont* getNSFont(NSString* key, NSString* defaultFontName,
|
||||
float fontSize)
|
||||
NSFont*
|
||||
getNSFont(NSString* key, NSString* defaultFontName, float fontSize)
|
||||
{
|
||||
NSString* fontName;
|
||||
|
||||
fontName = [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
||||
if (!fontName)
|
||||
fontName = [[NSUserDefaults standardUserDefaults] objectForKey: key];
|
||||
if (fontName == nil)
|
||||
fontName = defaultFontName;
|
||||
|
||||
if (!fontSize) {
|
||||
fontSize = [[NSUserDefaults standardUserDefaults]
|
||||
floatForKey:[NSString stringWithFormat:@"%@Size", key]];
|
||||
if (!fontSize)
|
||||
fontSize = 12;
|
||||
}
|
||||
if (fontSize == 0)
|
||||
{
|
||||
fontSize = [[NSUserDefaults standardUserDefaults]
|
||||
floatForKey: [NSString stringWithFormat: @"%@Size", key]];
|
||||
if (fontSize == 0)
|
||||
fontSize = 12;
|
||||
}
|
||||
|
||||
return [NSFont fontWithName:fontName size:fontSize];
|
||||
return [NSFont fontWithName: fontName size: fontSize];
|
||||
}
|
||||
|
||||
void setNSFont(NSString* key, NSFont* font)
|
||||
void
|
||||
setNSFont(NSString* key, NSFont* font)
|
||||
{
|
||||
NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
[standardDefaults setObject:[font fontName] forKey:key];
|
||||
[standardDefaults setObject: [font fontName] forKey: key];
|
||||
|
||||
/* Don't care about errors */
|
||||
/* Don't care about errors*/
|
||||
[standardDefaults synchronize];
|
||||
}
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
+ (void) initialize
|
||||
{
|
||||
static BOOL initialized = NO;
|
||||
|
||||
if (!initialized) {
|
||||
initialized = YES;
|
||||
fontsUsed = [NSMutableSet new];
|
||||
}
|
||||
if (!initialized)
|
||||
{
|
||||
initialized = YES;
|
||||
fontsUsed = [NSMutableSet new];
|
||||
}
|
||||
}
|
||||
|
||||
/* Getting the preferred user fonts */
|
||||
/* Getting the preferred user fonts*/
|
||||
|
||||
// This is deprecated in MacOSX
|
||||
+ (NSFont*)boldSystemFontOfSize:(float)fontSize
|
||||
+ (NSFont*) boldSystemFontOfSize: (float)fontSize
|
||||
{
|
||||
return getNSFont (@"NSBoldFont", @"Helvetica-Bold", fontSize);
|
||||
}
|
||||
|
||||
// This is deprecated in MacOSX
|
||||
+ (NSFont*)systemFontOfSize:(float)fontSize
|
||||
+ (NSFont*) systemFontOfSize: (float)fontSize
|
||||
{
|
||||
return getNSFont (@"NSFont", @"Helvetica", fontSize);
|
||||
}
|
||||
|
||||
+ (NSFont*)userFixedPitchFontOfSize:(float)fontSize
|
||||
+ (NSFont*) userFixedPitchFontOfSize: (float)fontSize
|
||||
{
|
||||
return getNSFont (@"NSUserFixedPitchFont", @"Courier", fontSize);
|
||||
}
|
||||
|
||||
+ (NSFont*)userFontOfSize:(float)fontSize
|
||||
+ (NSFont*) userFontOfSize: (float)fontSize
|
||||
{
|
||||
return getNSFont (@"NSUserFont", @"Helvetica", fontSize);
|
||||
}
|
||||
|
||||
/* Setting the preferred user fonts */
|
||||
/* Setting the preferred user fonts*/
|
||||
|
||||
+ (void)setUserFixedPitchFont:(NSFont*)font
|
||||
+ (void) setUserFixedPitchFont: (NSFont*)font
|
||||
{
|
||||
setNSFont (@"NSUserFixedPitchFont", font);
|
||||
}
|
||||
|
||||
+ (void)setUserFont:(NSFont*)font
|
||||
+ (void) setUserFont: (NSFont*)font
|
||||
{
|
||||
setNSFont (@"NSUserFont", font);
|
||||
}
|
||||
|
||||
/* Getting various fonts */
|
||||
/* Getting various fonts*/
|
||||
|
||||
#ifndef STRICT_OPENSTEP
|
||||
+ (NSFont *)controlContentFontOfSize:(float)fontSize
|
||||
+ (NSFont*) controlContentFontOfSize: (float)fontSize
|
||||
{
|
||||
return [NSFont fontWithName:@"Helvetica" size:fontSize];
|
||||
return [NSFont fontWithName: @"Helvetica" size: fontSize];
|
||||
}
|
||||
|
||||
+ (NSFont *)menuFontOfSize:(float)fontSize
|
||||
+ (NSFont*) menuFontOfSize: (float)fontSize
|
||||
{
|
||||
return [NSFont fontWithName:@"Helvetica" size:fontSize];
|
||||
return [NSFont fontWithName: @"Helvetica" size: fontSize];
|
||||
}
|
||||
|
||||
+ (NSFont *)titleBarFontOfSize:(float)fontSize
|
||||
+ (NSFont*) titleBarFontOfSize: (float)fontSize
|
||||
{
|
||||
return [self boldSystemFontOfSize:fontSize];
|
||||
return [self boldSystemFontOfSize: fontSize];
|
||||
}
|
||||
|
||||
+ (NSFont *)messageFontOfSize:(float)fontSize
|
||||
+ (NSFont*) messageFontOfSize: (float)fontSize
|
||||
{
|
||||
return [self systemFontOfSize:fontSize];
|
||||
return [self systemFontOfSize: fontSize];
|
||||
}
|
||||
|
||||
+ (NSFont *)paletteFontOfSize:(float)fontSize
|
||||
+ (NSFont*) paletteFontOfSize: (float)fontSize
|
||||
{
|
||||
// Not sure on this one.
|
||||
return [self boldSystemFontOfSize:fontSize];
|
||||
return [self boldSystemFontOfSize: fontSize];
|
||||
}
|
||||
|
||||
+ (NSFont *)toolTipsFontOfSize:(float)fontSize
|
||||
+ (NSFont*) toolTipsFontOfSize: (float)fontSize
|
||||
{
|
||||
// Not sure on this one.
|
||||
return [NSFont fontWithName:@"Helvetica" size:fontSize];
|
||||
return [NSFont fontWithName: @"Helvetica" size: fontSize];
|
||||
}
|
||||
#endif
|
||||
|
||||
- initWithName:(NSString*)name matrix:(const float*)fontMatrix
|
||||
- (id) initWithName: (NSString*)name matrix: (const float*)fontMatrix
|
||||
{
|
||||
[fontsUsed addObject:name];
|
||||
[fontsUsed addObject: name];
|
||||
fontName = RETAIN(name);
|
||||
memcpy(matrix, fontMatrix, sizeof(matrix));
|
||||
fontInfo = RETAIN([GSFontInfo fontInfoForFontName: name matrix: fontMatrix]);
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (NSFont*)fontWithName:(NSString*)name
|
||||
matrix:(const float*)fontMatrix
|
||||
+ (NSFont*) fontWithName: (NSString*)name
|
||||
matrix: (const float*)fontMatrix
|
||||
{
|
||||
return AUTORELEASE([[NSFont alloc] initWithName: name matrix: fontMatrix]);
|
||||
}
|
||||
|
||||
+ (NSFont*)fontWithName:(NSString*)name
|
||||
size:(float)fontSize
|
||||
+ (NSFont*) fontWithName: (NSString*)name
|
||||
size: (float)fontSize
|
||||
{
|
||||
NSFont *font;
|
||||
NSFont*font;
|
||||
float fontMatrix[6] = { fontSize, 0, 0, fontSize, 0, 0 };
|
||||
|
||||
font = [self fontWithName: name matrix: fontMatrix];
|
||||
|
@ -185,15 +188,15 @@ void setNSFont(NSString* key, NSFont* font)
|
|||
return font;
|
||||
}
|
||||
|
||||
+ (void)useFont:(NSString*)name
|
||||
+ (void) useFont: (NSString*)name
|
||||
{
|
||||
[fontsUsed addObject:name];
|
||||
[fontsUsed addObject: name];
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
- (void)dealloc
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(fontName);
|
||||
RELEASE(fontInfo);
|
||||
|
@ -203,7 +206,7 @@ void setNSFont(NSString* key, NSFont* font)
|
|||
- (BOOL) isEqual: (id)anObject
|
||||
{
|
||||
int i;
|
||||
const float *obj_matrix;
|
||||
const float*obj_matrix;
|
||||
if (anObject == self)
|
||||
return YES;
|
||||
if ([anObject isKindOfClass: self->isa] == NO)
|
||||
|
@ -222,14 +225,14 @@ void setNSFont(NSString* key, NSFont* font)
|
|||
int i, sum;
|
||||
sum = 0;
|
||||
for (i = 0; i < 6; i++)
|
||||
sum += matrix[i] * ((i+1) * 17);
|
||||
sum += matrix[i]* ((i+1)* 17);
|
||||
return ([fontName hash] + sum);
|
||||
}
|
||||
|
||||
//
|
||||
// Private method for NSFontManager
|
||||
//
|
||||
- (GSFontInfo *) fontInfo
|
||||
- (GSFontInfo*) fontInfo
|
||||
{
|
||||
return fontInfo;
|
||||
}
|
||||
|
@ -237,14 +240,14 @@ void setNSFont(NSString* key, NSFont* font)
|
|||
//
|
||||
// NSCopying Protocol
|
||||
//
|
||||
- copyWithZone: (NSZone *)zone
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
NSFont *new_font;
|
||||
NSFont*new_font;
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
new_font = RETAIN(self);
|
||||
else
|
||||
{
|
||||
new_font = (NSFont *)NSCopyObject(self, 0, zone);
|
||||
new_font = (NSFont*)NSCopyObject(self, 0, zone);
|
||||
new_font->fontName = [fontName copyWithZone: zone];
|
||||
new_font->fontInfo = [fontInfo copyWithZone: zone];
|
||||
}
|
||||
|
@ -254,7 +257,7 @@ void setNSFont(NSString* key, NSFont* font)
|
|||
//
|
||||
// Setting the Font
|
||||
//
|
||||
- (void)set
|
||||
- (void) set
|
||||
{
|
||||
[fontInfo set];
|
||||
}
|
||||
|
@ -262,72 +265,72 @@ void setNSFont(NSString* key, NSFont* font)
|
|||
//
|
||||
// Querying the Font
|
||||
//
|
||||
- (float)pointSize { return [fontInfo pointSize]; }
|
||||
- (NSString*)fontName { return fontName; }
|
||||
- (const float*)matrix { return matrix; }
|
||||
- (float) pointSize { return [fontInfo pointSize]; }
|
||||
- (NSString*) fontName { return fontName; }
|
||||
- (const float*) matrix { return matrix; }
|
||||
|
||||
- (NSString *)encodingScheme { return [fontInfo encodingScheme]; }
|
||||
- (NSString*)familyName { return [fontInfo familyName]; }
|
||||
- (NSRect)boundingRectForFont { return [fontInfo boundingRectForFont]; }
|
||||
- (BOOL)isFixedPitch { return [fontInfo isFixedPitch]; }
|
||||
- (BOOL)isBaseFont { return [fontInfo isBaseFont]; }
|
||||
- (NSString*) encodingScheme { return [fontInfo encodingScheme]; }
|
||||
- (NSString*) familyName { return [fontInfo familyName]; }
|
||||
- (NSRect) boundingRectForFont { return [fontInfo boundingRectForFont]; }
|
||||
- (BOOL) isFixedPitch { return [fontInfo isFixedPitch]; }
|
||||
- (BOOL) isBaseFont { return [fontInfo isBaseFont]; }
|
||||
|
||||
/* Usually the display name of font is the font name. */
|
||||
- (NSString*)displayName { return fontName; }
|
||||
/* Usually the display name of font is the font name.*/
|
||||
- (NSString*) displayName { return fontName; }
|
||||
|
||||
- (NSDictionary*)afmDictionary { return [fontInfo afmDictionary]; }
|
||||
- (NSString*)afmFileContents { return [fontInfo afmFileContents]; }
|
||||
- (NSFont*)printerFont { return self; }
|
||||
- (NSFont*)screenFont { return self; }
|
||||
- (float)ascender { return [fontInfo ascender]; }
|
||||
- (float)descender { return [fontInfo descender]; }
|
||||
- (float)capHeight { return [fontInfo capHeight]; }
|
||||
- (float)italicAngle { return [fontInfo italicAngle]; }
|
||||
- (NSSize)maximumAdvancement { return [fontInfo maximumAdvancement]; }
|
||||
- (NSSize)minimumAdvancement { return [fontInfo minimumAdvancement]; }
|
||||
- (float)underlinePosition { return [fontInfo underlinePosition]; }
|
||||
- (float)underlineThickness { return [fontInfo underlineThickness]; }
|
||||
- (float)xHeight { return [fontInfo xHeight]; }
|
||||
- (NSDictionary*) afmDictionary { return [fontInfo afmDictionary]; }
|
||||
- (NSString*) afmFileContents { return [fontInfo afmFileContents]; }
|
||||
- (NSFont*) printerFont { return self; }
|
||||
- (NSFont*) screenFont { return self; }
|
||||
- (float) ascender { return [fontInfo ascender]; }
|
||||
- (float) descender { return [fontInfo descender]; }
|
||||
- (float) capHeight { return [fontInfo capHeight]; }
|
||||
- (float) italicAngle { return [fontInfo italicAngle]; }
|
||||
- (NSSize) maximumAdvancement { return [fontInfo maximumAdvancement]; }
|
||||
- (NSSize) minimumAdvancement { return [fontInfo minimumAdvancement]; }
|
||||
- (float) underlinePosition { return [fontInfo underlinePosition]; }
|
||||
- (float) underlineThickness { return [fontInfo underlineThickness]; }
|
||||
- (float) xHeight { return [fontInfo xHeight]; }
|
||||
|
||||
/* Computing font metrics attributes */
|
||||
- (float)widthOfString:(NSString*)string
|
||||
/* Computing font metrics attributes*/
|
||||
- (float) widthOfString: (NSString*)string
|
||||
{
|
||||
return [fontInfo widthOfString: string];
|
||||
}
|
||||
|
||||
- (float*)widths
|
||||
- (float*) widths
|
||||
{
|
||||
return [fontInfo widths];
|
||||
}
|
||||
|
||||
/* The following methods have to implemented by backends */
|
||||
/* The following methods have to implemented by backends*/
|
||||
|
||||
//
|
||||
// Manipulating Glyphs
|
||||
//
|
||||
- (NSSize)advancementForGlyph:(NSGlyph)aGlyph
|
||||
- (NSSize) advancementForGlyph: (NSGlyph)aGlyph
|
||||
{
|
||||
return [fontInfo advancementForGlyph: aGlyph];
|
||||
}
|
||||
|
||||
- (NSRect)boundingRectForGlyph:(NSGlyph)aGlyph
|
||||
- (NSRect) boundingRectForGlyph: (NSGlyph)aGlyph
|
||||
{
|
||||
return [fontInfo boundingRectForGlyph: aGlyph];
|
||||
}
|
||||
|
||||
- (BOOL)glyphIsEncoded:(NSGlyph)aGlyph
|
||||
- (BOOL) glyphIsEncoded: (NSGlyph)aGlyph
|
||||
{
|
||||
return [fontInfo glyphIsEncoded: aGlyph ];
|
||||
}
|
||||
|
||||
- (NSGlyph)glyphWithName:(NSString*)glyphName
|
||||
- (NSGlyph) glyphWithName: (NSString*)glyphName
|
||||
{
|
||||
return [fontInfo glyphWithName: glyphName ];
|
||||
}
|
||||
|
||||
- (NSPoint)positionOfGlyph:(NSGlyph)curGlyph
|
||||
precededByGlyph:(NSGlyph)prevGlyph
|
||||
isNominal:(BOOL *)nominal
|
||||
- (NSPoint) positionOfGlyph: (NSGlyph)curGlyph
|
||||
precededByGlyph: (NSGlyph)prevGlyph
|
||||
isNominal: (BOOL*)nominal
|
||||
{
|
||||
return [fontInfo positionOfGlyph: curGlyph precededByGlyph: prevGlyph
|
||||
isNominal: nominal];
|
||||
|
@ -344,9 +347,12 @@ void setNSFont(NSString* key, NSFont* font)
|
|||
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
[aDecoder decodeValueOfObjCType: @encode(id) at: &fontName];
|
||||
[aDecoder decodeArrayOfObjCType: @encode(float) count: 6 at: matrix];
|
||||
return RETAIN([[self class] fontWithName: fontName matrix: matrix]);
|
||||
id name;
|
||||
float fontMatrix[6];
|
||||
|
||||
name = [aDecoder decodeObject];
|
||||
[aDecoder decodeArrayOfObjCType: @encode(float) count: 6 at: fontMatrix];
|
||||
return [self initWithName: name matrix: fontMatrix];
|
||||
}
|
||||
|
||||
@end /* NSFont */
|
||||
|
|
Loading…
Reference in a new issue