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
-
undoManagerproperty -
fontDictproperty
Font Info
-
unitsPerEmproperty -
copyrightproperty -
designerproperty -
designerURLproperty -
manufacturerproperty -
manufacturerURLproperty -
versionMajorproperty -
versionMinorproperty -
dateproperty -
userDataproperty -
– userDataForKey: -
– setUserData:forKey: -
– removeUserDataForKey: -
tempDataproperty -
– setTempData:forKey: -
disablesNiceNamesproperty -
disablesAutomaticAlignmentproperty -
keepAlternatesTogetherproperty
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
-
customParametersproperty -
– 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
-
kerningproperty -
verticalKerningproperty -
– 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
-
featurePrefixesproperty -
– addFeaturePrefix: -
– countOfFeaturePrefixes -
– featurePrefixForTag: -
– insertObject:inFeaturePrefixesAtIndex: -
– removeFeaturePrefix: -
– charStringFromDisplayString: -
– disableUpdateInterface -
– stopUpdateInterface -
– enableUpdateInterface -
– isUpdateInterfaceEnabled -
gridMainproperty -
gridSubDivisionproperty -
– gridLength -
– compileTempFontError: -
tempOTFFontproperty
Properties
customParameters
List of custom parameters
@property (nonatomic, retain) NSMutableArray *customParametersdisablesAutomaticAlignment
Disables automatic alignment of components
@property (nonatomic) BOOL disablesAutomaticAlignmentdisablesNiceNames
disablesNiceNames
@property BOOL disablesNiceNamesDiscussion
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 *featurePrefixesfontDict
Returns the content of the font object to store it in pList.
@property (unsafe_unretained, readonly, nonatomic) NSMutableDictionary *fontDictDiscussion
This is used to store the data in the .glyphs file.
gridMain
The size of the grid.
@property (nonatomic, assign) NSUInteger gridMainDiscussion
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 gridSubDivisionDiscussion
Divides the grid.
See Also
keepAlternatesTogether
Keeps alternated glyphs next to the base glyph
@property (nonatomic) BOOL keepAlternatesTogetherkerning
the Kerning of the Font
@property (strong, nonatomic) MGOrderedDictionary *kerningDiscussion
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 *tempDatatempOTFFont
The path to the temp font
@property (nonatomic, strong, nullable) NSString *tempOTFFontDiscussion
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 *undoManagerDiscussion
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 *userDataDiscussion
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 *verticalKerningDiscussion
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 *)theClassParameters
- theClass
the Class
addClassFromCode:
Convient method to add a class with the Text
- (void)addClassFromCode:(NSString *)TextParameters
- Text
the class in FDK syntax, e.g. “@myClass = [A B];”
addCustomParameter:
adds a parameter to the list font
- (void)addCustomParameter:(GSCustomParameter *)PropertyParameters
- Property
addFeaturePrefix:
Adds the Prefix to the font
- (void)addFeaturePrefix:(GSClass *)thePrefixParameters
- thePrefix
the prefix
addFontMaster:
Adds the fontMaster to the font
- (void)addFontMaster:(GSFontMaster *)fontMasterParameters
- fontMaster
The master to add.
addGlyph:
Adds the Glyph object to the font.
- (void)addGlyph:(GSGlyph *)GlyphParameters
- Glyph
A GSGlyph object.
addGlyphsFromArray:
Adds the Glyphs object to the font.
- (void)addGlyphsFromArray:(NSArray *)GlyphsParameters
- Glyphs
A NSArray of GSGlyph objects.
addInstance:
Adds the Instance to the font
- (void)addInstance:(GSInstance *)InstanceParameters
- 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 *)StringParameters
- 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 *)GlyphParameters
- 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 *)TagParameters
- Tag
The class name.
compileTempFontError:
Recalculates the temp font.
- (BOOL)compileTempFontError:(out NSError *__autoreleasing *)ErrorParameters
- 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)compressKerningDiscussion
if a GSGlyph has a Kerning Group and Direct Kerning, the Kerning is changed to Class Kerning.
countOfFeatures
The count of the features
- (NSUInteger)countOfFeaturesReturn Value
The number of features in the Font.
countOfFontMasters
The count of masters in the font.
- (NSInteger)countOfFontMastersReturn Value
The number of layers currently in the font.
countOfInstances
The count of the Instances
- (NSUInteger)countOfInstancesReturn 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 *)keyParameters
- key
the name of the custom parameter
Return Value
YES/NO
customParameterForKey:
Returns the custom property with Name
- (GSCustomParameter *)customParameterForKey:(NSString *)keyParameters
- 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 *)keyParameters
- 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)disableUpdateInterfaceDiscussion
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)elementParameters
- element
the calling object
enableUpdateInterface
Reanables redrawing and updates.
- (void)enableUpdateInterfaceDiscussion
This only has an effect if disableUpdateInterface was called before
featureForTag:
Returns the feature with the name or tag.
- (GSFeature *)featureForTag:(NSString *)TagParameters
- Tag
The feature tag (like “smcp”)
featurePrefixForTag:
Returns the Prefix with the name.
- (GSClass *)featurePrefixForTag:(NSString *)TagParameters
- Tag
The prefix name.
filterGlyphs:
Returns all glyph names that are present and set to export
- (NSArray *_Nullable)filterGlyphs:(NSArray *)GlyphNamesParameters
- 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 *)GlyphNamesParameters
- GlyphNames
A array of glyph names
Return Value
A list of exporting glyphs
See Also
fontMasterAtIndex:
The master located at index
- (GSFontMaster *)fontMasterAtIndex:(NSInteger)IndexParameters
- 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 *)IdParameters
- 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 *)ErrorParameters
- 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)IndexParameters
- 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)CharParameters
- Char
A (unicode) char.
Return Value
a GSGlyph object
See Also
glyphForId:
Returns the GSGlyph with this ID.
- (GSGlyph *)glyphForId:(NSString *)IdParameters
- 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 *)NameParameters
- 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 *)UnicodeParameters
- 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 *)unicodesParameters
- 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 *)errorParameters
- 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)gridLengthReturn 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 *)GlyphNamesParameters
- 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 *)GlyphParameters
- 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 *)fontDictParameters
- 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 **)outErrorParameters
- 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)theIndexParameters
- 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)theIndexParameters
- theClass
the class
- theIndex
the index
insertObject:inFeaturePrefixesAtIndex:
Insert the Prefix at theIndex in the font
- (void)insertObject:(id)thePrefix inFeaturePrefixesAtIndex:(unsigned)theIndexParameters
- thePrefix
the prefix
- theIndex
the index
insertObject:inInstancesAtIndex:
Inserts the instance at Index
- (void)insertObject:(GSInstance *)Instance inInstancesAtIndex:(NSUInteger)indexParameters
- Instance
The instance to insert.
- index
The index at what to insert the instance.
isUpdateInterfaceEnabled
Check if the updating is enabled
- (BOOL)isUpdateInterfaceEnabledReturn Value
NO if disableUpdateInterface was called
keepsGlyphs:
Tests if all the glyphs are present and set to export
- (BOOL)keepsGlyphs:(NSArray<NSString*> *)GlyphNamesParameters
- 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)directionParameters
- 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)changeNameParameters
- 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)indexParameters
- index
The index
Return Value
The GSCustomParameter or nil of index is out of range
objectInFeaturesAtIndex:
The feature at index
- (GSFeature *)objectInFeaturesAtIndex:(NSUInteger)idxParameters
- idx
The index of the feature
Return Value
The feature located at theIndex.
objectInInstancesAtIndex:
The Instance at index
- (GSInstance *)objectInInstancesAtIndex:(NSUInteger)indexParameters
- index
The index of the instance.
Return Value
The Instance located at index.
removeClass:
Removes the class from the font
- (void)removeClass:(GSClass *)theClassParameters
- theClass
the class
removeFeaturePrefix:
Remove the Prefix at theIndex from the font
- (void)removeFeaturePrefix:(GSClass *)thePrefixParameters
- thePrefix
the prefix
removeFontMaster:
Removes the fontMaster from the font
- (void)removeFontMaster:(GSFontMaster *)fontMasterParameters
- fontMaster
The master to remove.
removeFontMasterAtIndex:
Removes the fontmaster with this id
- (void)removeFontMasterAtIndex:(NSInteger)IndexParameters
- Index
The index of the FontMaster to remove.
removeGlyph:
Removes the Glyph from the font
- (void)removeGlyph:(GSGlyph *)GlyphParameters
- Glyph
A GSGlyph to remove from the font.
removeGlyphs:
Removes the Glyphs from the font
- (void)removeGlyphs:(NSArray *)GlyphsParameters
- 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 *)RightKeyParameters
- 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)theIndexParameters
- theIndex
the index
removeObjectFromCustomParametersAtIndex:
Removes the parameter a theIndex
- (void)removeObjectFromCustomParametersAtIndex:(NSUInteger)indexParameters
- index
The index
removeObjectFromCustomParametersForKey:
Removes the parameter with this name from the font
- (void)removeObjectFromCustomParametersForKey:(id)keyParameters
- 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)indexParameters
- index
The of the Instance to be removed.
removeUserDataForKey:
Removed the object with this key.
- (void)removeUserDataForKey:(NSString *)keyParameters
- key
The to remove
replaceObjectInClassesAtIndex:withObject:
Replaces the the class a theIndex with Class
- (void)replaceObjectInClassesAtIndex:(NSUInteger)theIndex withObject:(GSClass *)theClassParameters
- theIndex
the index
- theClass
the class
resetCache
If you changed the glyphs array yourself, call that method to reset some chances.
- (void)resetCachesaveNameForGlyph:
Calculates a names that is unique for the font
- (NSString *)saveNameForGlyph:(GSGlyph *)GlyphParameters
- 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 *)GlyphNameParameters
- 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 *)keyParameters
- 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)directionParameters
- 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 *)keyParameters
- value
and object or nil
- key
the key
setUserData:forKey:
Adds something to the fonts userData.
- (void)setUserData:(nullable id)value forKey:(nonnull NSString *)keyParameters
- 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)stopUpdateInterfaceDiscussion
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)updateMetricsDiscussion
This will not apply the metrics keys.
userDataForKey:
convenience accessor to get to the content of the userData dict
- (id)userDataForKey:(NSString *)keyParameters
- key
the key
Return Value
the data stored with key