GSFont Class Reference
Inherits from | NSObject |
Conforms to | GSContainerProtocol NSCoding NSCopying |
Overview
@brief: This class defines the font object.
Font info properties, that have a user interface, have proper accessors, eveything else is stored in the custom parameters
Tasks
Other Methods
-
undoManager
property -
fontDict
property
Font Info
-
unitsPerEm
property -
copyright
property -
designer
property -
designerURL
property -
manufacturer
property -
manufacturerURL
property -
versionMajor
property -
versionMinor
property -
date
property -
userData
property -
– userDataForKey:
-
– setUserData:forKey:
-
– removeUserDataForKey:
-
tempData
property -
– setTempData:forKey:
-
disablesNiceNames
property -
disablesAutomaticAlignment
property -
keepAlternatesTogether
property
Creating and Initializing a GSFont object
Glyphs
-
– countOfGlyphs
-
– glyphAtIndex:
-
– indexOfGlyph:
-
– resetCache
-
– glyphForName:
-
– glyphNamesForWildcard:error:
-
– glyphNames
-
– glyphForUnicode:
-
– glyphForUnicodes:
-
– newGlyphWithName:changeName:
-
– saveNameForGlyph:
-
– saveNameForName:
-
– glyphForId:
-
– keepsGlyphs:
-
– hasGlyphs:
-
– filterKeepGlyphs:
-
– filterGlyphs:
-
– glyphForCharacter:
-
– characterForGlyph:
-
– addGlyph:
-
– addGlyphsFromArray:
-
– removeGlyph:
-
– removeGlyphs:
-
– sortGlyphs
-
– sortKerning
-
– elementDidChange:
Custom Parameters
-
customParameters
property -
– customParameterForKey:
-
– countOfCustomParameters
-
– customValueForKey:
-
– customBoolValueForKey:
-
– setCustomParameter:forKey:
-
– addCustomParameter:
-
– removeObjectFromCustomParametersForKey:
-
– removeObjectFromCustomParametersAtIndex:
-
– objectInCustomParametersAtIndex:
-
– panose
Masters
-
– countOfFontMasters
-
– fontMasterAtIndex:
-
– fontMasterForId:
-
– insertFontMaster:atIndex:
-
– addFontMaster:
-
– removeFontMaster:
-
– removeFontMasterAtIndex:
-
– updateMetrics
Instances
-
– countOfInstances
-
– objectInInstancesAtIndex:
-
– insertObject:inInstancesAtIndex:
-
– addInstance:
-
– removeObjectFromInstancesAtIndex:
-
– generateInstance:error:
Kerning
-
kerning
property -
verticalKerning
property -
– compressKerning
-
– kerningForFontMasterID:LeftKey:RightKey:direction:
-
– setKerningForFontMasterID:LeftKey:RightKey:Value:direction:
-
– removeKerningForFontMasterID:LeftKey:RightKey:
Features
Classes
-
– classForTag:
-
– addClass:
-
– insertObject:inClassesAtIndex:
-
– removeObjectFromClassesAtIndex:
-
– removeClass:
-
– replaceObjectInClassesAtIndex:withObject:
-
– addClassFromCode:
FeaturePrefixes
-
featurePrefixes
property -
– addFeaturePrefix:
-
– countOfFeaturePrefixes
-
– featurePrefixForTag:
-
– insertObject:inFeaturePrefixesAtIndex:
-
– removeFeaturePrefix:
-
– charStringFromDisplayString:
-
– disableUpdateInterface
-
– stopUpdateInterface
-
– enableUpdateInterface
-
– isUpdateInterfaceEnabled
-
gridMain
property -
gridSubDivision
property -
– gridLength
-
– compileTempFontError:
-
tempOTFFont
property
Properties
customParameters
List of custom parameters
@property (nonatomic, retain) NSMutableArray *customParameters
disablesAutomaticAlignment
Disables automatic alignment of components
@property (nonatomic) BOOL disablesAutomaticAlignment
disablesNiceNames
disablesNiceNames
@property BOOL disablesNiceNames
Discussion
This is to prevent the automatic glyph name substitution. Set it to YES before you do big changes. Make sure to disable it after you are finished.
featurePrefixes
An array of GSClass objects that contain additional lookups
@property (nonatomic, strong) NSMutableArray *featurePrefixes
fontDict
Returns the content of the font object to store it in pList.
@property (unsafe_unretained, readonly, nonatomic) NSMutableDictionary *fontDict
Discussion
This is used to store the data in the .glyphs file.
gridMain
The size of the grid.
@property (nonatomic, assign) NSUInteger gridMain
Discussion
If it is 0
, all values are stored as floats. 1
and above will ALWAYS round the coordinates.
See Also
gridSubDivision
The subdivision of the grid.
@property (nonatomic, assign) NSUInteger gridSubDivision
Discussion
Divides the grid.
See Also
keepAlternatesTogether
Keeps alternated glyphs next to the base glyph
@property (nonatomic) BOOL keepAlternatesTogether
kerning
the Kerning of the Font
@property (strong, nonatomic) MGOrderedDictionary *kerning
Discussion
1) A Dict for each FontMaster (FontMaster id as key) 2) The Dict contains an entry for each glyph (the glyphID or GroupName (@MMK_L_XXX) is used as key) 3) These entries hold the values: glyphID or GroupName (@MMK_R_XXX) as key, kerning as value.
tempData
a mutable dictionary that stores data. It will not be written to disk.
@property (nonatomic, strong, nullable) NSMutableDictionary *tempData
tempOTFFont
The path to the temp font
@property (nonatomic, strong, nullable) NSString *tempOTFFont
Discussion
This font contains no outlines and no kerning but the full GSUB table. It is used for the feature preview in edit view.
undoManager
The undoManager of the document
@property (nonatomic, readonly, nullable) NSUndoManager *undoManager
Discussion
This is only used for font info and for adding/removing glyphs. Each glyph has it’s own undoManager.
See Also
userData
Place for plugins to store custom data.
@property (strong, nonatomic, nullable) NSMutableDictionary *userData
Discussion
Here it is possible to store something. Please use a unique key. The objects should be able to serialize to a plist. If they are not, they should return all infos to store in description (as String).
verticalKerning
the vertical Kerning of the Font
@property (strong, nonatomic) MGOrderedDictionary *verticalKerning
Discussion
1) A Dict for each FontMaster (FontMaster id as key) 2) The Dict contains an entry for each glyph (the glyphID or GroupName (@MMK_L_XXX) is used as key) 3) These entries hold the values: glyphID or GroupName (@MMK_R_XXX) as key, kerning as value.
Instance Methods
addClass:
Adds a class to the font
- (void)addClass:(GSClass *)theClass
Parameters
- theClass
the Class
addClassFromCode:
Convient method to add a class with the Text
- (void)addClassFromCode:(NSString *)Text
Parameters
- Text
the class in FDK syntax, e.g. “@myClass = [A B];”
addCustomParameter:
adds a parameter to the list font
- (void)addCustomParameter:(GSCustomParameter *)Property
Parameters
- Property
addFeaturePrefix:
Adds the Prefix to the font
- (void)addFeaturePrefix:(GSClass *)thePrefix
Parameters
- thePrefix
the prefix
addFontMaster:
Adds the fontMaster to the font
- (void)addFontMaster:(GSFontMaster *)fontMaster
Parameters
- fontMaster
The master to add.
addGlyph:
Adds the Glyph object to the font.
- (void)addGlyph:(GSGlyph *)Glyph
Parameters
- Glyph
A GSGlyph object.
addGlyphsFromArray:
Adds the Glyphs object to the font.
- (void)addGlyphsFromArray:(NSArray *)Glyphs
Parameters
- Glyphs
A NSArray of GSGlyph objects.
addInstance:
Adds the Instance to the font
- (void)addInstance:(GSInstance *)Instance
Parameters
- Instance
The Instance to add to the font.
charStringFromDisplayString:
Converts a string that contains slash seperated glyph names in a regular unicode string
- (NSString *)charStringFromDisplayString:(NSString *)String
Parameters
- String
A String containing slash seperated glyph names
Return Value
A UTF-16 string. For it will assigne a cached PUA codes for unencoded glyphs
characterForGlyph:
Returns a UTF32Char for the glyph.
- (UTF32Char)characterForGlyph:(GSGlyph *)Glyph
Parameters
- Glyph
a GSGlyph object
Return Value
a UTF32Char
Discussion
It uses the unicode to find the char value. For unencoded glyphs it returns a cached PUA value.
See Also
classForTag:
Returns the class with the name.
- (GSClass *)classForTag:(NSString *)Tag
Parameters
- Tag
The class name.
compileTempFontError:
Recalculates the temp font.
- (BOOL)compileTempFontError:(out NSError *__autoreleasing *)Error
Parameters
- Error
if there is a problem, it returns an NSError object (by reference) that contains details.
Return Value
YES if successfull, NO, if not.
Discussion
Call it, if you changed something like the glyph set or the features and need to make sure the temp font is up to date. This is usually done automatically.
See Also
compressKerning
Compresses the kerning
- (void)compressKerning
Discussion
if a GSGlyph has a Kerning Group and Direct Kerning, the Kerning is changed to Class Kerning.
countOfFeatures
The count of the features
- (NSUInteger)countOfFeatures
Return Value
The number of features in the Font.
countOfFontMasters
The count of masters in the font.
- (NSInteger)countOfFontMasters
Return Value
The number of layers currently in the font.
countOfInstances
The count of the Instances
- (NSUInteger)countOfInstances
Return Value
The number of Instances currently in the Font.
customBoolValueForKey:
A convenient method to check if a custom parameter is set and has a positiv setting
- (BOOL)customBoolValueForKey:(NSString *)key
Parameters
- key
the name of the custom parameter
Return Value
YES/NO
customParameterForKey:
Returns the custom property with Name
- (GSCustomParameter *)customParameterForKey:(NSString *)key
Parameters
- key
The name of the parameter
Return Value
The parameter object
Discussion
This will always return the first entry with this name. If there are multiple parameters with the same name, parse the customParameters array directly.
See Also
customValueForKey:
This returns the value of the parameter object with Name
- (id)customValueForKey:(NSString *)key
Parameters
- key
The name of the parameter
Return Value
The value of the parameter object object
Discussion
This will always return the first entry with this name. If there are multiple parameters with the same name, parse the customParameters array directly.
See Also
disableUpdateInterface
Delayes redrawing and updates.
- (void)disableUpdateInterface
Discussion
Will record the changes and update once in enableUpdateInterface
. If you don’t need updates, use stopUpdateInterface
Warning: Always call enableUpdateInterface afterwards
See Also
elementDidChange:
This is called be child objects to tell the containing class that it has changed
- (void)elementDidChange:(id)element
Parameters
- element
the calling object
enableUpdateInterface
Reanables redrawing and updates.
- (void)enableUpdateInterface
Discussion
This only has an effect if disableUpdateInterface was called before
featureForTag:
Returns the feature with the name or tag.
- (GSFeature *)featureForTag:(NSString *)Tag
Parameters
- Tag
The feature tag (like “smcp”)
featurePrefixForTag:
Returns the Prefix with the name.
- (GSClass *)featurePrefixForTag:(NSString *)Tag
Parameters
- Tag
The prefix name.
filterGlyphs:
Returns all glyph names that are present and set to export
- (NSArray *_Nullable)filterGlyphs:(NSArray *)GlyphNames
Parameters
- GlyphNames
A array of glyph names
Return Value
A list of all glyphs that are in the font
filterKeepGlyphs:
Returns all glyph names that are present and set to export
- (NSArray *_Nullable)filterKeepGlyphs:(NSArray *)GlyphNames
Parameters
- GlyphNames
A array of glyph names
Return Value
A list of exporting glyphs
See Also
fontMasterAtIndex:
The master located at index
- (GSFontMaster *)fontMasterAtIndex:(NSInteger)Index
Parameters
- Index
An index
Return Value
A GSFontMaster instance or nil if index is out of bounds
fontMasterForId:
Returns the fontmaster with this id
- (GSFontMaster *)fontMasterForId:(NSString *)Id
Parameters
- Id
The ID of the font master. This is supposed to be a Unique id
Return Value
A GSFontMaster instance.
generateInstance:error:
Generates an instance
- (GSFont *_Nullable)generateInstance:(GSInstance *)Instance error:(NSError *__autoreleasing *)Error
Parameters
- Instance
The Instance to use for interpolation.
- Error
if there is a problem, it returns an NSError object (by reference) that contains details.
Return Value
The interpolated font, or nil if something went wrong.
Discussion
It returns a new GSFont object with one master interpolated all glyphs/layers according to the settings in Instance.
glyphAtIndex:
The glyph object located at index.
- (GSGlyph *)glyphAtIndex:(NSInteger)Index
Parameters
- Index
An index within the bounds of the the glyphs array.
Return Value
a GSGlyph object.
Discussion
Checks for valid index and returns nil if index is to high.
glyphForCharacter:
Returns the glyph with the chars unicode.
- (GSGlyph *)glyphForCharacter:(UTF32Char)Char
Parameters
- Char
A (unicode) char.
Return Value
a GSGlyph object
See Also
glyphForId:
Returns the GSGlyph with this ID.
- (GSGlyph *)glyphForId:(NSString *)Id
Parameters
- Id
the ID of the glyph.
Return Value
a GSGlyph object.
Discussion
Warning: This is a bit slow.
glyphForName:
Returns the GSGlyph with this name.
- (GSGlyph *)glyphForName:(NSString *)Name
Parameters
- Name
the name of the glyph.
Return Value
a GSGlyph object.
Discussion
Warning: This is a bit slow.
glyphForUnicode:
Returns the GSGlyph with this this Unicode.
- (GSGlyph *)glyphForUnicode:(NSString *)Unicode
Parameters
- Unicode
the unicode as a hex string (‘004C’)
Return Value
a GSGlyph object or nil if not found.
See Also
- resetCache If you changed some glyphs and this method returns wrong results, call - resetCache
glyphForUnicodes:
Returns the GSGlyph with this this Unicode.
- (GSGlyph *)glyphForUnicodes:(NSOrderedSet *)unicodes
Parameters
- unicodes
a list of unicodes as hex strings (‘004C’)
Return Value
a GSGlyph object or nil if not found.
See Also
- resetCache If you changed some glyphs and this method returns wrong results, call - resetCache
glyphNamesForWildcard:error:
A list of glyph names matching query
- (NSArray *)glyphNamesForWildcard:(NSString *)query error:(NSError *__autoreleasing *)error
Parameters
- query
This can be a name containing wildcards (“a.*”) or a query (“script=arabic”)
- error
if something goes wrong, it contains an error on return
Return Value
a list of glyph names or nil
gridLength
The effective grid width.
- (CGFloat)gridLength
Return Value
The effective size of the grid
Discussion
Calculated by Grid / Subdivision
hasGlyphs:
Returns a Boolean value if the font contains the glyphs
- (BOOL)hasGlyphs:(NSArray *)GlyphNames
Parameters
- GlyphNames
A array of glyph names
Return Value
YES if all glyphs are in the font.
indexOfGlyph:
Returns the index of the glyph.
- (NSInteger)indexOfGlyph:(GSGlyph *)Glyph
Parameters
- Glyph
The Glyph you are looking for
Return Value
The Index of the glyph or NSNotFound if not found
initWithFontDict:
initializes a font with a dictionary loaded from a pList.
- (instancetype)initWithFontDict:(NSDictionary *)fontDict
Parameters
- fontDict
A dictionary
initWithURL:error:
Initializes a font with the contents of the location specified by a given URL.
- (instancetype)initWithURL:(NSURL *)fileURL error:(NSError **)outError
Parameters
- fileURL
the location of the file
- outError
If there is a error it contains an NSError object
Return Value
the GSFont object or nil
insertFontMaster:atIndex:
Inserts the FontMaster at Index
- (void)insertFontMaster:(GSFontMaster *)FontMaster atIndex:(NSUInteger)theIndex
Parameters
- FontMaster
The master to add to the font
- theIndex
The index to insert FontMaster.
insertObject:inClassesAtIndex:
Insert the Class at theIndex in the font
- (void)insertObject:(GSClass *)theClass inClassesAtIndex:(NSUInteger)theIndex
Parameters
- theClass
the class
- theIndex
the index
insertObject:inFeaturePrefixesAtIndex:
Insert the Prefix at theIndex in the font
- (void)insertObject:(id)thePrefix inFeaturePrefixesAtIndex:(unsigned)theIndex
Parameters
- thePrefix
the prefix
- theIndex
the index
insertObject:inInstancesAtIndex:
Inserts the instance at Index
- (void)insertObject:(GSInstance *)Instance inInstancesAtIndex:(NSUInteger)index
Parameters
- Instance
The instance to insert.
- index
The index at what to insert the instance.
isUpdateInterfaceEnabled
Check if the updating is enabled
- (BOOL)isUpdateInterfaceEnabled
Return Value
NO if disableUpdateInterface was called
keepsGlyphs:
Tests if all the glyphs are present and set to export
- (BOOL)keepsGlyphs:(NSArray<NSString*> *)GlyphNames
Parameters
- GlyphNames
A array of glyph names
Return Value
YES if all glyphs will end up in a exported font.
kerningForFontMasterID:LeftKey:RightKey:direction:
Returns a kerning value
- (CGFloat)kerningForFontMasterID:(id)FontMasterID LeftKey:(id)LeftKey RightKey:(id)RightKey direction:(GSWritingDirection)direction
Parameters
- FontMasterID
The Master id
- LeftKey
either a glyph id or a glyph group (@MM_L_XXX)
- RightKey
either a glyph id or a glyph group (@MM_R_XXX)
Return Value
the kerning value
newGlyphWithName:changeName:
Adds a new glyph with this glyphName to the font
- (GSGlyph *)newGlyphWithName:(NSString *)glyphName changeName:(BOOL)changeName
Parameters
- glyphName
The new glyph name
- changeName
If changeName is yes, the glyphName will be converted to nice-name, otherwise not.
Return Value
The new glyph.
objectInCustomParametersAtIndex:
The parameter at theIndex
- (id)objectInCustomParametersAtIndex:(NSUInteger)index
Parameters
- index
The index
Return Value
The GSCustomParameter or nil of index is out of range
objectInFeaturesAtIndex:
The feature at index
- (GSFeature *)objectInFeaturesAtIndex:(NSUInteger)idx
Parameters
- idx
The index of the feature
Return Value
The feature located at theIndex.
objectInInstancesAtIndex:
The Instance at index
- (GSInstance *)objectInInstancesAtIndex:(NSUInteger)index
Parameters
- index
The index of the instance.
Return Value
The Instance located at index.
removeClass:
Removes the class from the font
- (void)removeClass:(GSClass *)theClass
Parameters
- theClass
the class
removeFeaturePrefix:
Remove the Prefix at theIndex from the font
- (void)removeFeaturePrefix:(GSClass *)thePrefix
Parameters
- thePrefix
the prefix
removeFontMaster:
Removes the fontMaster from the font
- (void)removeFontMaster:(GSFontMaster *)fontMaster
Parameters
- fontMaster
The master to remove.
removeFontMasterAtIndex:
Removes the fontmaster with this id
- (void)removeFontMasterAtIndex:(NSInteger)Index
Parameters
- Index
The index of the FontMaster to remove.
removeGlyph:
Removes the Glyph from the font
- (void)removeGlyph:(GSGlyph *)Glyph
Parameters
- Glyph
A GSGlyph to remove from the font.
removeGlyphs:
Removes the Glyphs from the font
- (void)removeGlyphs:(NSArray *)Glyphs
Parameters
- Glyphs
A NSArray of GSGlyph to remove from the font.
removeKerningForFontMasterID:LeftKey:RightKey:
removes a kerning value
- (void)removeKerningForFontMasterID:(NSString *)FontMasterID LeftKey:(NSString *)LeftKey RightKey:(NSString *)RightKey
Parameters
- FontMasterID
The Master id
- LeftKey
either a glyph id or a glyph group (@MM_L_XXX)
- RightKey
either a glyph id or a glyph group (@MM_R_XXX)
removeObjectFromClassesAtIndex:
Remove the class at theIndex from the font
- (void)removeObjectFromClassesAtIndex:(NSUInteger)theIndex
Parameters
- theIndex
the index
removeObjectFromCustomParametersAtIndex:
Removes the parameter a theIndex
- (void)removeObjectFromCustomParametersAtIndex:(NSUInteger)index
Parameters
- index
The index
removeObjectFromCustomParametersForKey:
Removes the parameter with this name from the font
- (void)removeObjectFromCustomParametersForKey:(id)key
Parameters
- key
The name of the parameter
Discussion
It will only remove the first parameter with that name
removeObjectFromInstancesAtIndex:
Removes the Instance at Index.
- (void)removeObjectFromInstancesAtIndex:(NSUInteger)index
Parameters
- index
The of the Instance to be removed.
removeUserDataForKey:
Removed the object with this key.
- (void)removeUserDataForKey:(NSString *)key
Parameters
- key
The to remove
replaceObjectInClassesAtIndex:withObject:
Replaces the the class a theIndex with Class
- (void)replaceObjectInClassesAtIndex:(NSUInteger)theIndex withObject:(GSClass *)theClass
Parameters
- theIndex
the index
- theClass
the class
resetCache
If you changed the glyphs array yourself, call that method to reset some chances.
- (void)resetCache
saveNameForGlyph:
Calculates a names that is unique for the font
- (NSString *)saveNameForGlyph:(GSGlyph *)Glyph
Parameters
- Glyph
The Glyph
Return Value
The glyph name with a .0XX suffix if the name is already in use by another glyph
saveNameForName:
Calculates a names that is unique for the font
- (NSString *)saveNameForName:(NSString *)GlyphName
Parameters
- GlyphName
The glyph name
Return Value
The glyph name with a .0XX suffix if the name is already in use by another glyph
setCustomParameter:forKey:
Sets the key value pair in the font
- (void)setCustomParameter:(id)value forKey:(NSString *)key
Parameters
- value
a value
- key
The name of the parameter
Discussion
if a parameter with this name is already present, its value will be updated. Otherwise a new parameter will be added
setKerningForFontMasterID:LeftKey:RightKey:Value:direction:
adds a kerning value
- (void)setKerningForFontMasterID:(id)FontMasterID LeftKey:(id)LeftKey RightKey:(id)RightKey Value:(CGFloat)Value direction:(GSWritingDirection)direction
Parameters
- FontMasterID
The Master id
- LeftKey
either a glyph id or a glyph group (@MM_L_XXX)
- RightKey
either a glyph id or a glyph group (@MM_R_XXX)
- Value
the kerning value
setTempData:forKey:
Adds key/value to tempData. Pass nil as value to remove previous set data
- (void)setTempData:(nullable id)value forKey:(nonnull NSString *)key
Parameters
- value
and object or nil
- key
the key
setUserData:forKey:
Adds something to the fonts userData.
- (void)setUserData:(nullable id)value forKey:(nonnull NSString *)key
Parameters
- value
The object should be able to serialize to a plist. If they are not, they should return all infos to store in description (as String).
- key
Please use an uniqe key that gives some indecation who put it there (e.g. prefix it with your name or project).
Discussion
This also triggers undo/document dirty state.
stopUpdateInterface
Disable redrawing and updates completly.
- (void)stopUpdateInterface
Discussion
Changes will not trigger an update. Only use this calefully and call enableUpdateInterface if you need future updates.
Warning: Always call enableUpdateInterface afterwards
See Also
updateMetrics
Recalculate the LSB and RSB for all glyph
- (void)updateMetrics
Discussion
This will not apply the metrics keys.
userDataForKey:
convenience accessor to get to the content of the userData dict
- (id)userDataForKey:(NSString *)key
Parameters
- key
the key
Return Value
the data stored with key