Merge pull request #51 from gnustep/NSFontCollection_branch

Merge NSFontCollection branch as nobody replied to my last comment.
This commit is contained in:
Fred Kiefer 2020-03-24 08:42:32 +01:00 committed by GitHub
commit ba165e185b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1036 additions and 142 deletions

View file

@ -54,6 +54,10 @@
- (NSArray*) availableFontDescriptors;
- (NSArray *) availableFontNamesMatchingFontDescriptor: (NSFontDescriptor *)descriptor;
- (NSArray *) matchingFontDescriptorsFor: (NSDictionary *)attributes;
- (NSArray *) matchingDescriptorsForFamily: (NSString *)family
options: (NSDictionary *)options
inclusion: (NSArray *)queryDescriptors
exculsion: (NSArray *)exclusionDescriptors;
/* Note that these are only called once. NSFont will remember the returned
values. Backends may override these. */

View file

@ -157,6 +157,7 @@
#import <AppKit/NSDocumentController.h>
#import <AppKit/NSDrawer.h>
#import <AppKit/NSFileWrapperExtensions.h>
#import <AppKit/NSFontCollection.h>
#import <AppKit/NSFontDescriptor.h>
#import <AppKit/NSGestureRecognizer.h>
#import <AppKit/NSGlyphGenerator.h>

View file

@ -105,27 +105,54 @@ enum {
};
typedef NSUInteger NSRequestUserAttentionType;
#define NSAppKitVersionNumber10_0 577
#define NSAppKitVersionNumber10_1 620
#define NSAppKitVersionNumber10_2 663
#define NSAppKitVersionNumber10_2_3 663.6
#define NSAppKitVersionNumber10_3 743
#define NSAppKitVersionNumber10_3_2 743.14
#define NSAppKitVersionNumber10_3_3 743.2
#define NSAppKitVersionNumber10_3_5 743.24
#define NSAppKitVersionNumber10_3_7 743.33
#define NSAppKitVersionNumber10_3_9 743.36
#define NSAppKitVersionNumber10_4 824
#define NSAppKitVersionNumber10_4_1 824.1
#define NSAppKitVersionNumber10_4_3 824.23
#define NSAppKitVersionNumber10_4_4 824.33
#define NSAppKitVersionNumber10_4_7 824.41
#define NSAppKitVersionNumber10_5 949
#define NSAppKitVersionNumber10_5_2 949.27
#define NSAppKitVersionNumber10_5_3 949.33
#define NSAppKitVersionNumber10_6 1038
#define NSAppKitVersionNumber10_7 1138
#define NSAppKitVersionNumber10_7_2 1138.23
#define NSAppKitVersionNumber10_0 577
#define NSAppKitVersionNumber10_1 620
#define NSAppKitVersionNumber10_2 663
#define NSAppKitVersionNumber10_2_3 663.6
#define NSAppKitVersionNumber10_3 743
#define NSAppKitVersionNumber10_3_2 743.14
#define NSAppKitVersionNumber10_3_3 743.2
#define NSAppKitVersionNumber10_3_5 743.24
#define NSAppKitVersionNumber10_3_7 743.33
#define NSAppKitVersionNumber10_3_9 743.36
#define NSAppKitVersionNumber10_4 824
#define NSAppKitVersionNumber10_4_1 824.1
#define NSAppKitVersionNumber10_4_3 824.23
#define NSAppKitVersionNumber10_4_4 824.33
#define NSAppKitVersionNumber10_4_7 824.41
#define NSAppKitVersionNumber10_5 949
#define NSAppKitVersionNumber10_5_2 949.27
#define NSAppKitVersionNumber10_5_3 949.33
#define NSAppKitVersionNumber10_6 1038
#define NSAppKitVersionNumber10_7 1138
#define NSAppKitVersionNumber10_7_2 1138.23;
#define NSAppKitVersionNumber10_7_3 1138.32;
#define NSAppKitVersionNumber10_7_4 1138.47;
#define NSAppKitVersionNumber10_8 1187;
#define NSAppKitVersionNumber10_9 1265;
#define NSAppKitVersionNumber10_10 1343;
#define NSAppKitVersionNumber10_10_2 1344;
#define NSAppKitVersionNumber10_10_3 1347;
#define NSAppKitVersionNumber10_10_4 1348;
#define NSAppKitVersionNumber10_10_5 1348;
#define NSAppKitVersionNumber10_10_Max 1349;
#define NSAppKitVersionNumber10_11 1404;
#define NSAppKitVersionNumber10_11_1 1404.13;
#define NSAppKitVersionNumber10_11_2 1404.34;
#define NSAppKitVersionNumber10_11_3 1404.34;
#define NSAppKitVersionNumber10_12 1504;
#define NSAppKitVersionNumber10_12_1 1504.60;
#define NSAppKitVersionNumber10_12_2 1504.76;
#define NSAppKitVersionNumber10_13 1561;
#define NSAppKitVersionNumber10_13_1 1561.1;
#define NSAppKitVersionNumber10_13_2 1561.2;
#define NSAppKitVersionNumber10_13_4 1561.4;
#define NSAppKitVersionNumber10_14 1671;
#define NSAppKitVersionNumber10_14_1 1671.1;
#define NSAppKitVersionNumber10_14_2 1671.2;
#define NSAppKitVersionNumber10_14_3 1671.3;
#define NSAppKitVersionNumber10_14_4 1671.4;
#define NSAppKitVersionNumber10_14_5 1671.5;
APPKIT_EXPORT const double NSAppKitVersionNumber;
#endif

View file

@ -0,0 +1,151 @@
/* Definition of class NSFontCollection
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: Tue Dec 10 11:51:33 EST 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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 Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
#ifndef _NSFontCollection_h_GNUSTEP_GUI_INCLUDE
#define _NSFontCollection_h_GNUSTEP_GUI_INCLUDE
#import <Foundation/NSObject.h>
#import <AppKit/AppKitDefines.h>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
#if defined(__cplusplus)
extern "C" {
#endif
@class NSFontDescriptor, NSLocale, NSError, NSArray, NSMutableArray, NSDictionary, NSMutableDictionary;
enum {
NSFontCollectionVisibilityProcess = (1UL << 0),
NSFontCollectionVisibilityUser = (1UL << 1),
NSFontCollectionVisibilityComputer = (1UL << 2)
};
typedef NSUInteger NSFontCollectionVisibility;
typedef NSString* NSFontCollectionMatchingOptionKey;
APPKIT_EXPORT NSFontCollectionMatchingOptionKey const NSFontCollectionIncludeDisabledFontsOption;
APPKIT_EXPORT NSFontCollectionMatchingOptionKey const NSFontCollectionRemoveDuplicatesOption;
APPKIT_EXPORT NSFontCollectionMatchingOptionKey const NSFontCollectionDisallowAutoActivationOption;
typedef NSString* NSFontCollectionName;
@interface NSFontCollection : NSObject <NSCopying, NSMutableCopying, NSCoding>
{
NSMutableDictionary *_fontCollectionDictionary;
}
// Initializers...
+ (NSFontCollection *) fontCollectionWithDescriptors: (NSArray *)queryDescriptors;
+ (NSFontCollection *) fontCollectionWithAllAvailableDescriptors;
+ (NSFontCollection *) fontCollectionWithLocale: (NSLocale *)locale;
+ (BOOL) showFontCollection: (NSFontCollection *)collection
withName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility
error: (NSError **)error;
+ (BOOL) hideFontCollectionWithName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility
error: (NSError **)error;
+ (BOOL) renameFontCollectionWithName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility
toName: (NSFontCollectionName)name
error: (NSError **)error;
+ (NSArray *) allFontCollectionNames;
+ (NSFontCollection *) fontCollectionWithName: (NSFontCollectionName)name;
+ (NSFontCollection *) fontCollectionWithName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility;
// Descriptors
- (NSArray *) queryDescriptors;
- (NSArray *) exclusionDescriptors;
- (NSArray *) matchingDescriptors;
- (NSArray *) matchingDescriptorsWithOptions: (NSDictionary *)options;
- (NSArray *) matchingDescriptorsForFamily: (NSString *)family;
- (NSArray *) matchingDescriptorsForFamily: (NSString *)family options: (NSDictionary *)options;
@end
@interface NSMutableFontCollection : NSFontCollection
+ (NSMutableFontCollection *) fontCollectionWithDescriptors: (NSArray *)queryDescriptors;
+ (NSMutableFontCollection *) fontCollectionWithAllAvailableDescriptors;
+ (NSMutableFontCollection *) fontCollectionWithLocale: (NSLocale *)locale;
+ (NSMutableFontCollection *) fontCollectionWithName: (NSFontCollectionName)name;
+ (NSMutableFontCollection *) fontCollectionWithName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility;
- (NSArray *) queryDescriptors;
- (void) setQueryDescriptors: (NSArray *)queryDescriptors;
- (NSArray *) exclusionDescriptors;
- (void) setExclusionDescriptors: (NSArray *)exclusionDescriptors;
- (void)addQueryForDescriptors: (NSArray *)descriptors;
- (void)removeQueryForDescriptors: (NSArray *)descriptors;
@end
// NSFontCollectionDidChangeNotification
APPKIT_EXPORT NSString * const NSFontCollectionDidChangeNotification;
// Notification user info dictionary keys
typedef NSString * NSFontCollectionUserInfoKey;
APPKIT_EXPORT NSFontCollectionUserInfoKey const NSFontCollectionActionKey;
APPKIT_EXPORT NSFontCollectionUserInfoKey const NSFontCollectionNameKey;
APPKIT_EXPORT NSFontCollectionUserInfoKey const NSFontCollectionOldNameKey;
APPKIT_EXPORT NSFontCollectionUserInfoKey const NSFontCollectionVisibilityKey;
// Values for NSFontCollectionAction
typedef NSString * NSFontCollectionActionTypeKey;
APPKIT_EXPORT NSFontCollectionActionTypeKey const NSFontCollectionWasShown;
APPKIT_EXPORT NSFontCollectionActionTypeKey const NSFontCollectionWasHidden;
APPKIT_EXPORT NSFontCollectionActionTypeKey const NSFontCollectionWasRenamed;
// Standard named collections
APPKIT_EXPORT NSFontCollectionName const NSFontCollectionAllFonts;
APPKIT_EXPORT NSFontCollectionName const NSFontCollectionUser;
APPKIT_EXPORT NSFontCollectionName const NSFontCollectionFavorites;
APPKIT_EXPORT NSFontCollectionName const NSFontCollectionRecentlyUsed;
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSFontCollection_h_GNUSTEP_GUI_INCLUDE */

11
MISSING
View file

@ -6,7 +6,6 @@ MISSING HEADERS
> NSAccessibilityCustomRotor.h
> NSAccessibilityElement.h
> NSAccessibilityProtocols.h
> NSAlignmentFeedbackFilter.h
> NSCollectionViewCompositionalLayout.h
> NSCollectionViewFlowLayout.h
> NSCollectionViewGridLayout.h
@ -20,7 +19,6 @@ MISSING HEADERS
> NSFilePromiseProvider.h
> NSFilePromiseReceiver.h
> NSFontAssetRequest.h
> NSFontCollection.h
> NSGlyphInfo.h
> NSGridView.h
> NSItemProvider.h
@ -36,8 +34,6 @@ MISSING HEADERS
> NSPathControl.h
> NSPathControlItem.h
> NSPersistentDocument.h
> NSPressureConfiguration.h
> NSQuickDrawView.h
> NSRuleEditor.h
> NSScrubber.h
> NSScrubberItemView.h
@ -61,8 +57,6 @@ MISSING HEADERS
> NSTextInputClient.h
> NSTextInputContext.h
> NSTitlebarAccessoryViewController.h
> NSTouch.h
> NSTouchBar.h
> NSTypesetter.h
> NSUserActivity.h
> NSUserInterfaceCompression.h
@ -110,3 +104,8 @@ Mac Specific
> NSWindowScripting.h
> NSHapticFeedback.h
> NSAppleScriptExtensions.h
> NSAlignmentFeedbackFilter.h
> NSTouch.h
> NSTouchBar.h
> NSQuickDrawView.h
> NSPressureConfiguration.h

View file

@ -105,6 +105,7 @@ NSEPSImageRep.m \
NSEvent.m \
NSFileWrapperExtensions.m \
NSFont.m \
NSFontCollection.m \
NSFontDescriptor.m \
NSFontManager.m \
NSFontPanel.m \
@ -395,6 +396,7 @@ NSEvent.h \
NSFileWrapper.h \
NSFileWrapperExtensions.h \
NSFont.h \
NSFontCollection.h \
NSFontDescriptor.h \
NSFontManager.h \
NSFontPanel.h \

View file

@ -3,11 +3,14 @@
Private class for handling font info
Copyright (C) 2000 Free Software Foundation, Inc.
Copyright (C) 2000, 2020 Free Software Foundation, Inc.
Author: Adam Fedor <fedor@gnu.org>
Date: Mar 2000
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: March 2020
This file is part of the GNUstep.
This library is free software; you can redistribute it and/or
@ -22,8 +25,8 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
@ -110,7 +113,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
NSMutableArray *fontDescriptors;
NSEnumerator *keyEnumerator;
NSString *family;
fontDescriptors = [[NSMutableArray alloc] init];
keyEnumerator = [allFontFamilies keyEnumerator];
while ((family = [keyEnumerator nextObject]) != nil)
@ -118,7 +121,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
NSArray *fontDefs = [allFontFamilies objectForKey: family];
NSEnumerator *fdEnumerator;
NSArray *fontDef;
fdEnumerator = [fontDefs objectEnumerator];
while ((fontDef = [fdEnumerator nextObject]) != nil)
{
@ -128,10 +131,10 @@ static GSFontEnumerator *sharedEnumerator = nil;
NSNumber *traits = [fontDef objectAtIndex: 3];
NSDictionary *fontTraits;
float fweight = ([weight intValue] - 6) / 6.0;
fontTraits = [NSDictionary dictionaryWithObjectsAndKeys:
traits, NSFontSymbolicTrait,
[NSNumber numberWithFloat: fweight],
[NSNumber numberWithFloat: fweight],
NSFontWeightTrait,
nil];
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
@ -141,7 +144,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
fontTraits, NSFontTraitsAttribute,
nil];
fd = [[NSFontDescriptor alloc] initWithFontAttributes: attributes];
[fontDescriptors addObject: fd];
RELEASE(fd);
}
@ -183,80 +186,146 @@ static GSFontEnumerator *sharedEnumerator = nil;
return found;
}
- (BOOL) _fontDescriptor: (NSFontDescriptor *)fd matches: (NSDictionary *)attributes
{
// Get all the keys from the attributes and see if they match
NSArray *keys = [attributes allKeys];
NSEnumerator *keyEnumerator;
NSString *key;
BOOL match = YES;
keyEnumerator = [keys objectEnumerator];
while ((key = [keyEnumerator nextObject]) != nil)
{
id valueA = [attributes objectForKey: key];
if (valueA != nil)
{
id valueB = [fd objectForKey: key];
if (valueB == nil)
{
match = NO;
break;
}
// Special handling for NSFontTraitsAttribute
if ([key isEqual: NSFontTraitsAttribute])
{
NSNumber *traitsA = [valueA objectForKey: NSFontSymbolicTrait];
NSNumber *traitsB = [valueB objectForKey: NSFontSymbolicTrait];
// FIXME: For now we only compare symbolic traits
if ((traitsA != nil) &&
((traitsB == nil) ||
([traitsA unsignedIntValue] != [traitsB unsignedIntValue])))
{
match = NO;
break;
}
}
else if ([key isEqual: NSFontCharacterSetAttribute])
{
if (![valueB isSupersetOfSet: valueA])
{
match = NO;
break;
}
}
else
{
if (![valueA isEqual: valueB])
{
match = NO;
break;
}
}
}
}
return match;
}
- (NSArray *) matchingFontDescriptorsFor: (NSDictionary *)attributes
{
NSMutableArray *found;
NSEnumerator *fdEnumerator;
NSFontDescriptor *fd;
NSArray *keys = [attributes allKeys];
found = [NSMutableArray arrayWithCapacity: 3];
// Get an enumerator for all available font descriptors
fdEnumerator = [[self availableFontDescriptors] objectEnumerator];
while ((fd = [fdEnumerator nextObject]) != nil)
{
NSEnumerator *keyEnumerator;
NSString *key;
BOOL match = YES;
keyEnumerator = [keys objectEnumerator];
while ((key = [keyEnumerator nextObject]) != nil)
{
id valueA = [attributes objectForKey: key];
if (valueA != nil)
{
id valueB = [fd objectForKey: key];
if (valueB == nil)
{
match = NO;
break;
}
// Special handling for NSFontTraitsAttribute
if ([key isEqual: NSFontTraitsAttribute])
{
NSNumber *traitsA = [valueA objectForKey: NSFontSymbolicTrait];
NSNumber *traitsB = [valueB objectForKey: NSFontSymbolicTrait];
// FIXME: For now we only compare symbolic traits
if ((traitsA != nil) &&
((traitsB == nil) ||
([traitsA unsignedIntValue] != [traitsB unsignedIntValue])))
{
match = NO;
break;
}
}
else if ([key isEqual: NSFontCharacterSetAttribute])
{
if (![valueB isSupersetOfSet: valueA])
{
match = NO;
break;
}
}
else
{
if (![valueA isEqual: valueB])
{
match = NO;
break;
}
}
}
}
if (match)
{
[found addObject: fd];
}
if ([self _fontDescriptor: fd matches: attributes])
{
[found addObject: fd];
}
}
return found;
}
// Font collection methods....
- (BOOL) _fontDescriptor: (NSFontDescriptor *)fd matchesAny: (NSArray *)a
{
NSEnumerator *en = [a objectEnumerator];
NSFontDescriptor *o;
while ((o = [en nextObject]) != nil)
{
if ([self _fontDescriptor: fd matches: [o fontAttributes]])
{
return YES;
}
}
return NO;
}
/*
* This method implements the filtering of font descriptors to match the given restrictions.
* This code should be implemented more effiently in the backend.
* Currently we ignore the options as these may only be implemented in the backend.
*/
- (NSArray *) matchingDescriptorsForFamily: (NSString *)family
options: (NSDictionary *)options
inclusion: (NSArray *)queryDescriptors
exculsion: (NSArray *)exclusionDescriptors
{
NSMutableArray *r = [NSMutableArray arrayWithCapacity: 50];
NSEnumerator *en = [[self availableFontDescriptors] objectEnumerator];
NSFontDescriptor *fd;
while ((fd = [en nextObject]) != nil)
{
// Check if the font descriptor matches the family value if one is given
if ((family != nil) &&
![[fd objectForKey: NSFontFamilyAttribute] isEqualToString: family])
{
continue;
}
// Check if the font descriptor matches any of the query descriptors
if (![self _fontDescriptor: fd matchesAny: queryDescriptors])
{
continue;
}
// Check if the font descriptor matches none of the exclusion descriptors
if ([self _fontDescriptor: fd matchesAny: exclusionDescriptors])
{
continue;
}
// Add it to the result
[r addObject: fd];
}
return r;
}
- (NSString *) defaultSystemFontName
{
return @"Helvetica";
@ -287,7 +356,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
fontInfoClass = defaultClass;
}
+ (GSFontInfo*) fontInfoForFontName: (NSString*)nfontName
+ (GSFontInfo*) fontInfoForFontName: (NSString*)nfontName
matrix: (const CGFloat *)fmatrix
screenFont: (BOOL)screenFont;
{
@ -295,7 +364,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
@"Called with fontInfoClass unset."
@" The shared NSApplication instance must be created before methods that"
@" need the backend may be called.");
return AUTORELEASE([[fontInfoClass alloc] initWithFontName: nfontName
return AUTORELEASE([[fontInfoClass alloc] initWithFontName: nfontName
matrix: fmatrix
screenFont: screenFont]);
}
@ -304,7 +373,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
{
static NSDictionary *dict = nil;
NSNumber *num;
if (dict == nil)
{
dict = [NSDictionary dictionaryWithObjectsAndKeys:
@ -340,11 +409,11 @@ static GSFontEnumerator *sharedEnumerator = nil;
RETAIN(dict);
}
if ((weightString == nil) ||
if ((weightString == nil) ||
((num = [dict objectForKey: weightString]) == nil))
{
return 5;
}
}
else
{
return [num intValue];
@ -361,7 +430,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
@"thin", @"light", @"book", @"regular",
@"medium", @"demibold", @"semibold",
@"bold", @"extrabold", @"heavy",
@"black", @"ultrablack", @"extrablack",
@"black", @"ultrablack", @"extrablack",
nil];
RETAIN(arr);
}
@ -434,16 +503,16 @@ static GSFontEnumerator *sharedEnumerator = nil;
NSString *weightString;
fontDictionary = [[NSMutableDictionary alloc] initWithCapacity: 25];
[fontDictionary setObject: fontName forKey: NSAFMFontName];
if (familyName != nil)
{
[fontDictionary setObject: familyName
[fontDictionary setObject: familyName
forKey: NSAFMFamilyName];
}
if (ascender != 0.0)
{
[fontDictionary setObject: [NSNumber numberWithFloat: ascender]
[fontDictionary setObject: [NSNumber numberWithFloat: ascender]
forKey: NSAFMAscender];
}
if (descender != 0.0)
@ -477,7 +546,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
forKey: NSAFMUnderlineThickness];
}
weightString = [GSFontInfo stringForWeight: weight];
weightString = [GSFontInfo stringForWeight: weight];
if (weightString != nil)
{
[fontDictionary setObject: weightString forKey: NSAFMWeight];
@ -503,8 +572,8 @@ static GSFontEnumerator *sharedEnumerator = nil;
}
- (NSString*) encodingScheme
{
return encodingScheme;
{
return encodingScheme;
}
- (NSRect) boundingRectForFont
@ -543,58 +612,58 @@ static GSFontEnumerator *sharedEnumerator = nil;
}
- (BOOL) isBaseFont
{
return isBaseFont;
{
return isBaseFont;
}
- (BOOL) isFixedPitch
{
return isFixedPitch;
{
return isFixedPitch;
}
- (CGFloat) ascender
{
return ascender;
{
return ascender;
}
- (CGFloat) descender
{
return descender;
{
return descender;
}
- (CGFloat) capHeight
{
return capHeight;
{
return capHeight;
}
- (CGFloat) italicAngle
{
return italicAngle;
{
return italicAngle;
}
- (NSSize) maximumAdvancement
{
return maximumAdvancement;
{
return maximumAdvancement;
}
- (NSSize) minimumAdvancement
{
return minimumAdvancement;
{
return minimumAdvancement;
}
- (CGFloat) underlinePosition
{
return underlinePosition;
{
return underlinePosition;
}
- (CGFloat) underlineThickness
{
return underlineThickness;
{
return underlineThickness;
}
- (CGFloat) xHeight
{
return xHeight;
{
return xHeight;
}
- (CGFloat) defaultLineHeightForFont
@ -657,22 +726,22 @@ static GSFontEnumerator *sharedEnumerator = nil;
if (curGlyph == NSNullGlyph)
advance = [self advancementForGlyph: prevGlyph];
else
else
// Should check kerning
advance = [self advancementForGlyph: prevGlyph];
return NSMakePoint (advance.width, advance.height);
return NSMakePoint (advance.width, advance.height);
}
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
forCharacter: (unichar)aChar
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
forCharacter: (unichar)aChar
struckOverRect: (NSRect)aRect
{
return NSZeroPoint;
}
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
struckOverGlyph: (NSGlyph)baseGlyph
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
struckOverGlyph: (NSGlyph)baseGlyph
metricsExist: (BOOL *)flag
{
if (flag)
@ -681,8 +750,8 @@ static GSFontEnumerator *sharedEnumerator = nil;
return NSZeroPoint;
}
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
struckOverRect: (NSRect)aRect
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
struckOverRect: (NSRect)aRect
metricsExist: (BOOL *)flag
{
if (flag)
@ -691,10 +760,10 @@ static GSFontEnumerator *sharedEnumerator = nil;
return NSZeroPoint;
}
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
withRelation: (NSGlyphRelation)relation
- (NSPoint) positionOfGlyph: (NSGlyph)aGlyph
withRelation: (NSGlyphRelation)relation
toBaseGlyph: (NSGlyph)baseGlyph
totalAdvancement: (NSSize *)offset
totalAdvancement: (NSSize *)offset
metricsExist: (BOOL *)flag
{
NSRect baseRect = [self boundingRectForGlyph: baseGlyph];
@ -778,7 +847,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
NSAffineTransform *transform = [NSAffineTransform new];
NSAffineTransformStruct ats;
NSDictionary *attributes;
ats.m11 = matrix[0];
ats.m12 = matrix[1];
ats.m21 = matrix[2];
@ -786,7 +855,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
ats.tX = matrix[4];
ats.tY = matrix[5];
[transform setTransformStruct: ats];
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
fontName, NSFontNameAttribute,
transform, NSFontMatrixAttribute,

625
Source/NSFontCollection.m Normal file
View file

@ -0,0 +1,625 @@
/* Implementation of class NSFontCollection
Copyright (C) 2019, 2020 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: Tue Dec 10 11:51:33 EST 2019
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: March 2020
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSError.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSLocale.h>
#import <Foundation/NSLock.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#import <AppKit/NSFontCollection.h>
#import <AppKit/NSFontDescriptor.h>
#import <GNUstepGUI/GSFontInfo.h>
static NSMutableDictionary *_availableFontCollections = nil;
static NSLock *_fontCollectionLock = nil;
/*
* Private functions...
*/
@interface NSFontCollection (Private)
+ (NSFontCollection *) _readFileAtPath: (NSString *)path;
+ (void) _loadAvailableFontCollections;
- (BOOL) _writeToFileAtPath: (NSString *)path;
- (BOOL) _writeToFile;
- (BOOL) _removeFile;
- (NSMutableDictionary *) _fontCollectionDictionary;
- (void) _setFontCollectionDictionary: (NSMutableDictionary *)dict;
- (void) _setQueryDescriptors: (NSArray *)queryDescriptors;
- (void) _setFullFileName: (NSString *)fn;
- (NSString *) _fullFileName;
- (void) _setName: (NSString *)n;
- (NSString *) _name;
@end
/*
* Private functions...
*/
@implementation NSFontCollection (Private)
/**
* Load all font collections....
*/
+ (void) _loadAvailableFontCollections
{
[_fontCollectionLock lock];
if (_availableFontCollections != nil)
{
// Nothing to do ... already loaded
[_fontCollectionLock unlock];
}
else
{
NSString *dir = nil;
NSEnumerator *e = nil;
NSFileManager *fm = [NSFileManager defaultManager];
// Create the global array of font collections...
_availableFontCollections = [[NSMutableDictionary alloc] init];
/*
* Load font lists found in standard paths into the array
*/
e = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSAllDomainsMask, YES) objectEnumerator];
while ((dir = (NSString *)[e nextObject]))
{
BOOL flag;
NSDirectoryEnumerator *de = nil;
NSString *file = nil;
dir = [dir stringByAppendingPathComponent: @"FontCollections"];
if (![fm fileExistsAtPath: dir isDirectory: &flag] || !flag)
{
// Only process existing directories
continue;
}
de = [fm enumeratorAtPath: dir];
while ((file = [de nextObject]))
{
if ([[file pathExtension] isEqualToString: @"collection"])
{
NSString *name = [file stringByDeletingPathExtension];
NSString *path = [dir stringByAppendingPathComponent: file];
NSFontCollection *newCollection = [self _readFileAtPath: path];
if (newCollection != nil && name != nil)
{
[newCollection _setFullFileName: path];
[newCollection _setName: name];
[_availableFontCollections setObject: newCollection
forKey: name];
}
}
}
}
[_fontCollectionLock unlock];
}
}
+ (NSFontCollection *) _readFileAtPath: (NSString *)path
{
NSData *d = [NSData dataWithContentsOfFile: path];
NSKeyedUnarchiver *u = [[NSKeyedUnarchiver alloc] initForReadingWithData: d];
NSFontCollection *fc = [[NSFontCollection alloc] initWithCoder: u];
RELEASE(u);
return AUTORELEASE(fc);
}
/*
* Writing and Removing Files
*/
- (BOOL) _writeToFileAtPath: (NSString *)path
{
BOOL success = NO;
NSMutableData *m = [[NSMutableData alloc] initWithCapacity: 1024];
NSKeyedArchiver *a = [[NSKeyedArchiver alloc] initForWritingWithMutableData: m];
[self encodeWithCoder: a];
[a finishEncoding];
RELEASE(a);
// Write the file....
NSDebugLLog(@"NSFontCollection", @"Writing to %@", path);
success = [m writeToFile: path atomically: YES];
RELEASE(m);
return success;
}
- (BOOL) _writeToFile
{
NSFileManager *fm = [NSFileManager defaultManager];
BOOL success = NO;
NSString *path = [self _fullFileName];
/*
* We need to initialize before saving, to avoid the new file being
* counted as a different collection thus making it appear twice
*/
[NSFontCollection _loadAvailableFontCollections];
if (path == nil)
{
// Find library....
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
if ([paths count] == 0)
{
NSLog(@"Failed to find Library directory for user");
return NO;
}
path = [[paths objectAtIndex: 0]
stringByAppendingPathComponent: @"FontCollections"];
if ([fm fileExistsAtPath: path] == NO)
{
if ([fm createDirectoryAtPath: path
withIntermediateDirectories: YES
attributes: nil
error: NULL])
{
NSDebugLLog(@"NSFontCollection", @"Created standard directory %@", path);
}
else
{
NSLog(@"Failed attempt to create directory %@", path);
return NO;
}
}
NSDebugLLog(@"NSFontCollection", @"Font collection name = %@", [self _name]);
path = [path stringByAppendingPathComponent:
[[self _name] stringByAppendingPathExtension: @"collection"]];
[self _setFullFileName: path];
}
// Create the archive...
success = [self _writeToFileAtPath: path];
if (success)
{
[_fontCollectionLock lock];
if ([[_availableFontCollections allValues] containsObject: self] == NO)
{
[_availableFontCollections setObject: self forKey: [self _name]];
}
[_fontCollectionLock unlock];
}
return success;
}
- (BOOL) _removeFile
{
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir;
NSString *path = [self _fullFileName];
BOOL result = NO;
/*
* We need to initialize before saving, to avoid the new file being
* counted as a different collection thus making it appear twice
*/
[NSFontCollection _loadAvailableFontCollections];
if (path == nil)
{
// the standard path for saving font collections
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
if ([paths count] == 0)
{
NSLog(@"Failed to find Library directory for user");
return NO;
}
path = [[[[paths objectAtIndex: 0]
stringByAppendingPathComponent: @"FontCollections"]
stringByAppendingPathComponent: [self _name]]
stringByAppendingPathExtension: @"collection"];
}
if (![fm fileExistsAtPath: path isDirectory: &isDir] || isDir)
{
NSLog(@"Failed to find font collection file to delete");
return NO;
}
else
{
// Remove the file
result = [[NSFileManager defaultManager] removeFileAtPath: path
handler: nil];
// Remove the collection from the global list of font collections
[_fontCollectionLock lock];
[_availableFontCollections removeObjectForKey: [self _name]];
[_fontCollectionLock unlock];
// Reset file name
[self _setFullFileName: nil];
}
return result;
}
- (NSMutableDictionary *) _fontCollectionDictionary
{
return _fontCollectionDictionary;
}
- (void) _setFontCollectionDictionary: (NSMutableDictionary *)dict
{
ASSIGNCOPY(_fontCollectionDictionary, dict);
}
- (void) _setQueryDescriptors: (NSArray *)queryDescriptors
{
return [_fontCollectionDictionary setObject: queryDescriptors
forKey: @"NSFontCollectionFontDescriptors"];
}
- (NSMutableDictionary *) _fontCollectionAttributes
{
NSMutableDictionary *attrs = [_fontCollectionDictionary objectForKey:
@"NSFontCollectionAttributes"];
if (attrs == nil)
{
attrs = [NSMutableDictionary dictionary];
[_fontCollectionDictionary setObject: attrs
forKey: @"NSFontCollectionAttributes"];
}
return attrs;
}
- (void) _setName: (NSString *)n
{
[[self _fontCollectionAttributes] setObject: n
forKey: @"NSFontCollectionName"];
}
- (NSString *) _name
{
return [[self _fontCollectionAttributes] objectForKey: @"NSFontCollectionName"];
}
- (void) _setFullFileName: (NSString *)fn
{
[[self _fontCollectionAttributes] setObject: fn
forKey: @"NSFontCollectionFileName"];
}
- (NSString *) _fullFileName
{
return [[self _fontCollectionAttributes] objectForKey: @"NSFontCollectionFileName"];
}
@end
/*
* NSFontCollection
*/
@implementation NSFontCollection
+ (void) initialize
{
if (self == [NSFontCollection class])
{
[self _loadAvailableFontCollections];
}
}
// Initializers...
- (instancetype) initWithDescriptors: (NSArray *)queryDescriptors
{
self = [super init];
if (self != nil)
{
_fontCollectionDictionary = [[NSMutableDictionary alloc] initWithCapacity: 10];
[self _setQueryDescriptors: queryDescriptors];
}
return self;
}
- (instancetype) init
{
return [self initWithDescriptors: [NSArray array]];
}
- (void) dealloc
{
RELEASE(_fontCollectionDictionary);
[super dealloc];
}
+ (NSFontCollection *) fontCollectionWithDescriptors: (NSArray *)queryDescriptors
{
NSFontCollection *fc = [[NSFontCollection alloc] initWithDescriptors: queryDescriptors];
return AUTORELEASE(fc);
}
+ (NSFontCollection *) fontCollectionWithAllAvailableDescriptors
{
NSFontCollection *fc = [_availableFontCollections objectForKey: NSFontCollectionAllFonts];
if (fc == nil)
{
NSDictionary *fa = [NSDictionary dictionary];
NSFontDescriptor *fd = [NSFontDescriptor fontDescriptorWithFontAttributes: fa];
fc = [self fontCollectionWithDescriptors: [NSArray arrayWithObject: fd]];
if (fc != nil)
{
[fc _setName: NSFontCollectionAllFonts];
[fc _writeToFile];
}
}
return fc;
}
+ (NSFontCollection *) fontCollectionWithLocale: (NSLocale *)locale
{
NSDictionary *fa = [NSDictionary dictionaryWithObject: [locale languageCode]
forKey: @"NSCTFontDesignLanguagesAttribute"];
NSFontDescriptor *fd = [NSFontDescriptor fontDescriptorWithFontAttributes: fa];
return [self fontCollectionWithDescriptors: [NSArray arrayWithObject: fd]];
}
+ (BOOL) showFontCollection: (NSFontCollection *)collection
withName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility
error: (NSError **)error
{
[collection _setName: name];
return [collection _writeToFile];
}
+ (BOOL) hideFontCollectionWithName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility
error: (NSError **)error
{
NSFontCollection *collection = [_availableFontCollections objectForKey: name];
return [collection _removeFile];
}
+ (BOOL) renameFontCollectionWithName: (NSFontCollectionName)aname
visibility: (NSFontCollectionVisibility)visibility
toName: (NSFontCollectionName)name
error: (NSError **)error
{
NSFontCollection *collection = [_availableFontCollections objectForKey: aname];
BOOL rv = [collection _removeFile];
if (rv == YES)
{
[collection _setName: name];
[collection _writeToFile];
}
return rv;
}
+ (NSArray *) allFontCollectionNames
{
return [_availableFontCollections allKeys];
}
+ (NSFontCollection *) fontCollectionWithName: (NSFontCollectionName)name
{
NSFontCollection *fc = [_availableFontCollections objectForKey: name];
if (fc == nil)
{
fc = [[NSFontCollection alloc] init];
[fc _setName: name];
AUTORELEASE(fc);
}
return fc;
}
+ (NSFontCollection *) fontCollectionWithName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility
{
return [self fontCollectionWithName: name];
}
// Descriptors
- (NSArray *) queryDescriptors
{
return [_fontCollectionDictionary objectForKey: @"NSFontCollectionFontDescriptors"];
}
- (NSArray *) exclusionDescriptors
{
return [_fontCollectionDictionary objectForKey: @"NSFontExclusionDescriptorAttributes"];
}
- (NSArray *) matchingDescriptors
{
return [self matchingDescriptorsWithOptions: nil];
}
- (NSArray *) matchingDescriptorsWithOptions: (NSDictionary *)options
{
return [self matchingDescriptorsForFamily: nil options: options];
}
- (NSArray *) matchingDescriptorsForFamily: (NSString *)family
{
return [self matchingDescriptorsForFamily: family options: nil];
}
- (NSArray *) matchingDescriptorsForFamily: (NSString *)family options: (NSDictionary *)options
{
GSFontEnumerator *fen = [GSFontEnumerator sharedEnumerator];
return [fen matchingDescriptorsForFamily: family
options: options
inclusion: [self queryDescriptors]
exculsion: [self exclusionDescriptors]];
}
- (instancetype) copyWithZone: (NSZone *)zone
{
NSFontCollection *fc = [[NSFontCollection allocWithZone: zone] init];
[fc _setFontCollectionDictionary: _fontCollectionDictionary];
return fc;
}
- (instancetype) mutableCopyWithZone: (NSZone *)zone
{
NSMutableFontCollection *fc = [[NSMutableFontCollection allocWithZone: zone] init];
[fc _setFontCollectionDictionary: [_fontCollectionDictionary mutableCopyWithZone: zone]];
return fc;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
if ([coder allowsKeyedCoding])
{
[coder encodeObject: _fontCollectionDictionary
forKey: @"NSFontCollectionDictionary"];
}
else
{
[coder encodeObject: _fontCollectionDictionary];
}
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super init];
if (self != nil)
{
if ([coder allowsKeyedCoding])
{
ASSIGN(_fontCollectionDictionary,
[coder decodeObjectForKey: @"NSFontCollectionDictionary"]);
}
}
else
{
[coder decodeValueOfObjCType: @encode(id) at: &_fontCollectionDictionary];
}
return self;
}
@end
@implementation NSMutableFontCollection
+ (NSMutableFontCollection *) fontCollectionWithDescriptors: (NSArray *)queryDescriptors
{
return [[NSFontCollection fontCollectionWithDescriptors: queryDescriptors] mutableCopy];
}
+ (NSMutableFontCollection *) fontCollectionWithAllAvailableDescriptors
{
return [[NSFontCollection fontCollectionWithAllAvailableDescriptors] mutableCopy];
}
+ (NSMutableFontCollection *) fontCollectionWithLocale: (NSLocale *)locale
{
return [[NSFontCollection fontCollectionWithLocale: locale] mutableCopy];
}
+ (NSMutableFontCollection *) fontCollectionWithName: (NSFontCollectionName)name
{
return [[NSFontCollection fontCollectionWithName: name] mutableCopy];
}
+ (NSMutableFontCollection *) fontCollectionWithName: (NSFontCollectionName)name
visibility: (NSFontCollectionVisibility)visibility
{
return [[NSFontCollection fontCollectionWithName: name visibility: visibility] mutableCopy];
}
- (NSArray *) queryDescriptors
{
return [super queryDescriptors];
}
- (void) setQueryDescriptors: (NSArray *)queryDescriptors
{
[super _setQueryDescriptors: [queryDescriptors mutableCopy]];
}
- (NSArray *) exclusionDescriptors
{
return [_fontCollectionDictionary objectForKey: @"NSFontExclusionDescriptorAttributes"];
}
- (void) setExclusionDescriptors: (NSArray *)exclusionDescriptors
{
[_fontCollectionDictionary setObject: [exclusionDescriptors mutableCopy]
forKey: @"NSFontExclusionDescriptorAttributes"];
}
- (void) addQueryForDescriptors: (NSArray *)descriptors
{
NSMutableArray *arr = [[self queryDescriptors] mutableCopy];
NSMutableArray *ed = [[self exclusionDescriptors] mutableCopy];
[ed removeObjectsInArray: descriptors];
[arr addObjectsFromArray: descriptors];
[self setQueryDescriptors: arr];
[self setExclusionDescriptors: ed];
RELEASE(arr);
RELEASE(ed);
}
- (void) removeQueryForDescriptors: (NSArray *)descriptors
{
NSMutableArray *arr = [[self queryDescriptors] mutableCopy];
NSMutableArray *ed = [[self exclusionDescriptors] mutableCopy];
[ed addObjectsFromArray: descriptors];
[arr removeObjectsInArray: descriptors];
[self setQueryDescriptors: arr];
[self setExclusionDescriptors: ed];
RELEASE(arr);
RELEASE(ed);
}
@end

View file

@ -32,6 +32,7 @@
#import "AppKit/NSApplication.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSAppearance.h"
#import "AppKit/NSFontCollection.h"
// Global strings
NSString *NSModalPanelRunLoopMode = @"NSModalPanelRunLoopMode";
@ -812,10 +813,25 @@ const NSAppearanceName NSAppearanceNameAccessibilityHighContrastVibrantDark =
@"NSAppearanceNameAccessibilityHighContrastVibrantDark";
const NSAppearanceName NSAppearanceNameLightContent = @"NSAppearanceNameLightContent";
// Values for NSFontCollectionAction
NSFontCollectionActionTypeKey const NSFontCollectionWasShown = @"NSFontCollectionWasShown";
NSFontCollectionActionTypeKey const NSFontCollectionWasHidden = @"NSFontCollectionWasHidden";
NSFontCollectionActionTypeKey const NSFontCollectionWasRenamed = @"NSFontCollectionWasRenamed";
// Standard named collections
NSFontCollectionName const NSFontCollectionAllFonts = @"NSFontCollectionAllFonts";
NSFontCollectionName const NSFontCollectionUser = @"NSFontCollectionUser";
NSFontCollectionName const NSFontCollectionFavorites = @"NSFontCollectionFavorites";
NSFontCollectionName const NSFontCollectionRecentlyUsed = @"NSFontCollectionRecentlyUsed";
// Collections
NSFontCollectionMatchingOptionKey const NSFontCollectionIncludeDisabledFontsOption = @"NSFontCollectionIncludeDisabledFontsOption";
NSFontCollectionMatchingOptionKey const NSFontCollectionRemoveDuplicatesOption = @"NSFontCollectionRemoveDuplicatesOption";
NSFontCollectionMatchingOptionKey const NSFontCollectionDisallowAutoActivationOption = @"NSFontCollectionDisallowAutoActivationOption";
// Speech recognition...
const NSString *GSSpeechRecognizerDidRecognizeWordNotification = @"GSSpeechRecognizerDidRecognizeWordNotification";
extern void __objc_gui_force_linking (void);
void