Author: fredkiefer Date: Mon Sep 19 22:53:34 2016 New Revision: 40092 URL: http://svn.gna.org/viewcvs/gnustep?rev=40092&view=rev Log: * Source/GSFontInfo.m (-fontDescriptor): Simplify creation of font descriptor. Use only the minimal attributes. * Source/NSFontDescriptor.m (-postscriptName): Generate PS name from font name itself.
Modified: libs/gui/trunk/ChangeLog libs/gui/trunk/Source/GSFontInfo.m libs/gui/trunk/Source/NSFontDescriptor.m Modified: libs/gui/trunk/ChangeLog URL: http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=40092&r1=40091&r2=40092&view=diff ============================================================================== --- libs/gui/trunk/ChangeLog (original) +++ libs/gui/trunk/ChangeLog Mon Sep 19 22:53:34 2016 @@ -1,3 +1,10 @@ +2016-09-19 Fred Kiefer <fredkie...@gmx.de> + + * Source/GSFontInfo.m (-fontDescriptor): Simplify creation of font + descriptor. Use only the minimal attributes. + * Source/NSFontDescriptor.m (-postscriptName): Generate PS name + from font name itself. + 2016-08-02 Fred Kiefer <fredkie...@gmx.de> * Source/NSDocumentController.m: Add missing semicolon. Modified: libs/gui/trunk/Source/GSFontInfo.m URL: http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/GSFontInfo.m?rev=40092&r1=40091&r2=40092&view=diff ============================================================================== --- libs/gui/trunk/Source/GSFontInfo.m (original) +++ libs/gui/trunk/Source/GSFontInfo.m Mon Sep 19 22:53:34 2016 @@ -767,40 +767,34 @@ if (fontDescriptor == nil) { // Create a new one - NSAffineTransform *transform = [NSAffineTransform new]; - NSAffineTransformStruct ats; - NSDictionary *attributes; - NSDictionary *fontTraits; - float fweight = (weight - 6) / 6.0; - float fslant = italicAngle / 30.0; - - ats.m11 = matrix[0]; - ats.m12 = matrix[1]; - ats.m21 = matrix[2]; - ats.m22 = matrix[3]; - ats.tX = matrix[4]; - ats.tY = matrix[5]; - [transform setTransformStruct: ats]; - - fontTraits = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithUnsignedInt: traits], - NSFontSymbolicTrait, - [NSNumber numberWithFloat: fweight], - NSFontWeightTrait, - [NSNumber numberWithFloat: fslant], - NSFontSlantTrait, - nil]; - attributes = [NSDictionary dictionaryWithObjectsAndKeys: - familyName, NSFontFamilyAttribute, - fontName, NSFontNameAttribute, - //fontFace, NSFontFaceAttribute, - fontTraits, NSFontTraitsAttribute, - transform, NSFontMatrixAttribute, - nil]; - RELEASE(transform); - fontDescriptor = [[NSFontDescriptor alloc] initWithFontAttributes: attributes]; - } - + if ((matrix[0] == matrix[3]) && (matrix[1] == 0.0) && + (matrix[2] == 0.0) && (matrix[4] == 0.0) && (matrix[5] == 0.0)) + { + ASSIGN(fontDescriptor, [NSFontDescriptor fontDescriptorWithName: fontName + size: matrix[0]]); + } + else + { + NSAffineTransform *transform = [NSAffineTransform new]; + NSAffineTransformStruct ats; + NSDictionary *attributes; + + ats.m11 = matrix[0]; + ats.m12 = matrix[1]; + ats.m21 = matrix[2]; + ats.m22 = matrix[3]; + ats.tX = matrix[4]; + ats.tY = matrix[5]; + [transform setTransformStruct: ats]; + + attributes = [NSDictionary dictionaryWithObjectsAndKeys: + fontName, NSFontNameAttribute, + transform, NSFontMatrixAttribute, + nil]; + RELEASE(transform); + fontDescriptor = [[NSFontDescriptor alloc] initWithFontAttributes: attributes]; + } + } return fontDescriptor; } Modified: libs/gui/trunk/Source/NSFontDescriptor.m URL: http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSFontDescriptor.m?rev=40092&r1=40091&r2=40092&view=diff ============================================================================== --- libs/gui/trunk/Source/NSFontDescriptor.m (original) +++ libs/gui/trunk/Source/NSFontDescriptor.m Mon Sep 19 22:53:34 2016 @@ -41,18 +41,18 @@ #import "AppKit/NSFontManager.h" @interface NSFontManager (GNUstep) -- (NSArray *) matchingFontDescriptorsFor: (NSDictionary *)attributes; +- (NSArray*) matchingFontDescriptorsFor: (NSDictionary*)attributes; @end @implementation NSFontDescriptor -+ (id) fontDescriptorWithFontAttributes: (NSDictionary *)attributes ++ (id) fontDescriptorWithFontAttributes: (NSDictionary*)attributes { return AUTORELEASE([[self alloc] initWithFontAttributes: attributes]); } -+ (id) fontDescriptorWithName: (NSString *)name - matrix: (NSAffineTransform *)matrix ++ (id) fontDescriptorWithName: (NSString*)name + matrix: (NSAffineTransform*)matrix { return [self fontDescriptorWithFontAttributes: [NSDictionary dictionaryWithObjectsAndKeys: @@ -61,7 +61,7 @@ nil]]; } -+ (id) fontDescriptorWithName: (NSString *)name size: (CGFloat)size ++ (id) fontDescriptorWithName: (NSString*)name size: (CGFloat)size { return [self fontDescriptorWithFontAttributes: [NSDictionary dictionaryWithObjectsAndKeys: @@ -70,13 +70,13 @@ nil]]; } -- (NSDictionary *) fontAttributes +- (NSDictionary*) fontAttributes { return _attributes; } -- (NSFontDescriptor *) fontDescriptorByAddingAttributes: - (NSDictionary *)attributes +- (NSFontDescriptor*) fontDescriptorByAddingAttributes: + (NSDictionary*)attributes { NSMutableDictionary *m = [_attributes mutableCopy]; NSFontDescriptor *new; @@ -89,32 +89,32 @@ return new; } -- (NSFontDescriptor *) fontDescriptorWithFace: (NSString *)face +- (NSFontDescriptor*) fontDescriptorWithFace: (NSString*)face { return [self fontDescriptorByAddingAttributes: [NSDictionary dictionaryWithObject: face forKey: NSFontFaceAttribute]]; } -- (NSFontDescriptor *) fontDescriptorWithFamily: (NSString *)family +- (NSFontDescriptor*) fontDescriptorWithFamily: (NSString*)family { return [self fontDescriptorByAddingAttributes: [NSDictionary dictionaryWithObject: family forKey: NSFontFamilyAttribute]]; } -- (NSFontDescriptor *) fontDescriptorWithMatrix: (NSAffineTransform *)matrix +- (NSFontDescriptor*) fontDescriptorWithMatrix: (NSAffineTransform*)matrix { return [self fontDescriptorByAddingAttributes: [NSDictionary dictionaryWithObject: matrix forKey: NSFontMatrixAttribute]]; } -- (NSFontDescriptor *) fontDescriptorWithSize: (CGFloat)size +- (NSFontDescriptor*) fontDescriptorWithSize: (CGFloat)size { return [self fontDescriptorByAddingAttributes: [NSDictionary dictionaryWithObject: [NSString stringWithFormat:@"%f", size] forKey: NSFontSizeAttribute]]; } -- (NSFontDescriptor *) fontDescriptorWithSymbolicTraits: +- (NSFontDescriptor*) fontDescriptorWithSymbolicTraits: (NSFontSymbolicTraits)symbolicTraits { NSDictionary *traits; @@ -139,7 +139,7 @@ forKey: NSFontTraitsAttribute]]; } -- (id) initWithFontAttributes: (NSDictionary *)attributes +- (id) initWithFontAttributes: (NSDictionary*)attributes { if ((self = [super init]) != nil) { @@ -151,7 +151,7 @@ return self; } -- (void) encodeWithCoder: (NSCoder *)aCoder +- (void) encodeWithCoder: (NSCoder*)aCoder { if ([aCoder allowsKeyedCoding]) { @@ -163,7 +163,7 @@ } } -- (id) initWithCoder: (NSCoder *)aDecoder +- (id) initWithCoder: (NSCoder*)aDecoder { if ([aDecoder allowsKeyedCoding]) { @@ -182,7 +182,7 @@ [super dealloc]; } -- (id) copyWithZone: (NSZone *)z +- (id) copyWithZone: (NSZone*)z { NSFontDescriptor *f = [object_getClass(self) allocWithZone: z]; @@ -193,7 +193,7 @@ return f; } -- (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *)keys +- (NSArray*) matchingFontDescriptorsWithMandatoryKeys: (NSSet*)keys { NSMutableDictionary *attributes= [NSMutableDictionary dictionaryWithCapacity: 4]; NSEnumerator *keyEnumerator; @@ -219,7 +219,7 @@ return [[NSFontManager sharedFontManager] matchingFontDescriptorsFor: attributes]; } -- (NSFontDescriptor *) matchingFontDescriptorWithMandatoryKeys: (NSSet *)keys +- (NSFontDescriptor*) matchingFontDescriptorWithMandatoryKeys: (NSSet*)keys { NSArray *found = [self matchingFontDescriptorsWithMandatoryKeys: keys]; @@ -233,12 +233,12 @@ } } -- (NSAffineTransform *) matrix +- (NSAffineTransform*) matrix { return [self objectForKey: NSFontMatrixAttribute]; } -- (id) objectForKey: (NSString *)attribute +- (id) objectForKey: (NSString*)attribute { return [_attributes objectForKey: attribute]; } @@ -257,20 +257,13 @@ } } -- (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 || [face isEqualToString: @"Regular"]) - return family; - return [NSString stringWithFormat: @"%@-%@", family, face]; +- (NSString*) postscriptName +{ + NSString *fontName = [self objectForKey: NSFontNameAttribute]; + return [fontName stringByReplacingOccurrencesOfString: @" " + withString: @"" + options: 0 + range: NSMakeRange(0, [fontName length])]; } - (NSFontSymbolicTraits) symbolicTraits _______________________________________________ Gnustep-cvs mailing list Gnustep-cvs@gna.org https://mail.gna.org/listinfo/gnustep-cvs