GSLayer Class Reference
Inherits from | NSObject |
Conforms to | GSContainerProtocol GSUserDataProtocol NSCoding NSCopying |
Declared in | GSLayer.h |
Tasks
Info
parent
font
glyph
name
color
colorIndex
visible
– propertyListValueFormat:
layerId
associatedMasterId
Metrics
LSB
RSB
width
TSB
BSB
vertWidth
vertOrigin
hasAlignedWidth
isAligned
leftMetricsKey
widthMetricsKey
rightMetricsKey
topMetricsKey
bottomMetricsKey
vertWidthMetricsKey
Bezier Handling
bezierPath
openBezierPath
– drawBezierPath
drawOpenBezierPath
selNode
– initWithDict:format:
– compareString
Shapes
shapes
– countOfShapes
– addShape:
allShapes
paths
components
– enumerateShapesUsingBlock:
– removeShape:
– dividePathAtNode:
– elementDidChange:
– countOfPaths
– countOfComponents
– objectInShapesAtIndex:
– indexPathOfShape:
Anchors
anchors
– countOfAnchors
– addAnchor:
– removeAnchor:
– removeAnchorWithName:
– anchorForName:
– anchorForName:traverseComponents:
– anchorNamesTraversingComponents
– copyAnchorsFromComponents
– makeComponents
– copyDecomposedLayer
– decomposeComponents
– decomposeComponent:
– decomposeComponentDontNotifiy:
componentNames
background
– contentToBackgroundCheckSelection:keepOldBackground:
– swapForegroundWithBackground
– clear
Image
Guides
guides
– countOfGuides
– objectInGuidesAtIndex:
hints
– countOfHints
– addHint:
– addHintCheck:
– objectInHintsAtIndex:
– removeHint:
tempData
– setTempData:forKey:
– tempDataForKey:
– previousKerningForLayer:direction:
– nextKerningForLayer:direction:
– setPreviousKerning:forLayer:direction:
– setNextKerning:forLayer:direction:
– previousKerningExeptionForLayer:direction:
– setPreviousKerningExeption:forLayer:direction:
– nextKerningExeptionForLayer:direction:
– setNextKerningExeption:forLayer:direction:
Selection
Updating
– stopUpdates
– startUpdates
– enableFutureUpdates
– setNeedUpdateShapes
– setNeedUpdateMetrics
– syncMetrics
– syncLeftMetrics
– syncRightMetrics
– updateMetrics
– associatedFontMaster
– glyphMetrics
– bounds
– boundsOfSelection
– cleanUpPaths
– checkConnections
– correctPathDirection
– addExtremePoints
– addExtremePointsForce:
– addInflectionPoints
– calculateIntersectionsStartPoint:endPoint:
– calculateIntersectionsStartPoint:endPoint:decompose:
– undoManager
– glyph
– selectedObjects
– bezierData
– transformSelection:
– horizontalShift:otherShifts:
– drawInPen:
– layerColor:
Attributes
Other Methods
Properties
allShapes
this is only for iterating over all shapes, including recursion over groups. it will not show the groups but directly its content
@property (nonatomic, readonly) GSProxyShapes
*allShapes
anchors
An array of GSAnchor objects
@property (strong, nonatomic)
NSDictionary<NSString*GSAnchor*> *anchors
associatedMasterId
The associatedMasterId is used to connect a layer which is not a master layer to a FontMaster.
@property (strong, nonatomic, nullable) NSString
*associatedMasterId
Discussion
This is needed for copies of layers (e.g. for different versions) to access vertical metrics stored in the FontMaster. It could look like this: “FBCA074D-FCF3-427E-A700-7E318A949AE5”
attributes
Place to store data.
@property (strong, nonatomic, nullable) NSDictionary
*attributes
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).
background
The background layer for this layer
@property (strong, nonatomic, nullable) GSLayer
*background
backgroundImage
The image placed in the layer
@property (strong, nonatomic, nullable) GSBackgroundImage
*backgroundImage
bezierPath
Returns the bezierpath for the layer. Ignores open paths.
@property (nonatomic, strong, nullable) NSBezierPath
*bezierPath
See Also
bottomMetricsKey
The metrics key for the bottom side bearing
@property (nonatomic, strong, nullable) NSString
*bottomMetricsKey
colorIndex
Returns the index of the color label
@property (assign, nonatomic) NSInteger colorIndex
Return Value
0–11, anything else means no label
componentNames
An array containing names of the components in the layer
@property (strong, nonatomic) NSArray *componentNames
Discussion
Warning: This replaces all components in the layer.
components
this is only for iterating over all components, including recursion over groups.
@property (nonatomic, readonly) GSProxyShapes
*components
drawOpenBezierPath
The openbBezierPath for drawing the layer. It inclused the paths and componetents.
@property (nonatomic, strong, nullable) NSBezierPath
*drawOpenBezierPath
glyph
A pointer to the containing GSGlyph object
@property (readonly, nonatomic, nullable) GSGlyph
*glyph
guides
An array containing all GSGuide objects of the layer
@property (strong, nonatomic) NSArray<GSGuide*>
*guides
hasAlignedWidth
YES if the layer has automatically aligned spacing
@property (nonatomic, readonly) BOOL hasAlignedWidth
layerId
The layer key is used to access the layer in the glyphs layer dictionary.
@property (strong, nonatomic) NSString *layerId
Discussion
For master layers this should be the id of the FontMaster. It could look like this: “FBCA074D-FCF3-427E-A700-7E318A949AE5”
leftMetricsKey
The metrics key for the left side bearing
@property (nonatomic, strong, nullable) NSString
*leftMetricsKey
name
The title of the layer.
@property (strong, nonatomic, nullable) NSString *name
Discussion
for master layers this is the name of the associated FontMaster, otherwise it is a custom string (e.g. a date to keep track of history).
openBezierPath
Returns the bezierpath for open paths in the layer
@property (nonatomic, strong, nullable) NSBezierPath
*openBezierPath
paths
this is only for iterating over all paths, including recursion over groups.
@property (nonatomic, readonly) GSProxyShapes *paths
rightMetricsKey
The metrics key for the right side bearing
@property (nonatomic, strong, nullable) NSString
*rightMetricsKey
selNode
if there is one node selected, return it, otherwise return nil
@property (nonatomic, unsafe_unretained, readonly, nullable)
GSNode *selNode
selection
An array of GSElement objects.
@property (strong, nonatomic)
NSMutableOrderedSet<GSSelectableElement*> *selection
Discussion
All currently selected elements, otherwise nil.
shapes
An array of GSShape objects
@property (strong, nonatomic, nullable)
NSArray<GSShape*> *shapes
tempData
a dictionary that stores data. It will not be written to disk.
@property (nonatomic, strong, nullable) NSDictionary
*tempData
topMetricsKey
The metrics key for the top side bearing
@property (nonatomic, strong, nullable) NSString
*topMetricsKey
Instance Methods
addAnchor:
Adds the Anchor to the Layer.
- (void)addAnchor:(GSAnchor *)anchor
Parameters
- anchor
-
A Anchor.
addBackgroundImageWithURL:
Add the image at the given URL as layer image.
- (void)addBackgroundImageWithURL:(NSURL
*)URL
Parameters
- URL
-
The Image URL
Discussion
It verifies if it really is an Image.
addExtremePointsForce:
Add Extreme Points to all paths.
- (void)addExtremePointsForce:(BOOL)force
Parameters
- force
-
Forces extremes if YES.
addHintCheck:
checks if a hint with the same type and index path is already present.
- (void)addHintCheck:(GSHint *)hint
addSelection:
adds a element to the selection.
- (void)addSelection:(GSSelectableElement
*)newSelection
Parameters
- newSelection
-
The element to add to the selection.
addShape:
Add a path to the layer
- (void)addShape:(GSShape *)shape
Parameters
- shape
-
A GSShape object.
Discussion
The path will be added to the end of the layer’s paths array.
anchorForName:
Returns the corresponding anchor for an anchor name.
- (GSAnchor *)anchorForName:(NSString *)name
Parameters
- name
-
The name of the anchor, e.g. “top”
anchorForName:traverseComponents:
- (GSAnchor *_Nullable)anchorForName:(NSString
*_Nonnull)name
traverseComponents:(BOOL)checkComponents
Return Value
The anchor or nil
See Also
anchorNamesTraversingComponents
All anchor names from nested components
- (NSArray<NSString*>
*)anchorNamesTraversingComponents
Return Value
A list of anchor names
associatedFontMaster
The master to which the layer belongs.
- (GSFontMaster *)associatedFontMaster
Return Value
The GSFontMaster to which the layer belongs.
attributeForKey:
convenience accessor to get to the content of the attributes dict
- (NSObject *_Nullable)attributeForKey:(NSString
*)key
Parameters
- key
-
the key
Return Value
the data stored with key
bezierData
Returns the bezierpath encoded as NSData.
- (nullable NSData *)bezierData
Return Value
a bezierpath encoded as NSData.
Discussion
This is necessary to send the bezierpath over the Distributed Objects Bridge.
bounds
The bounding box of the layer.
- (NSRect)bounds
Return Value
An NSRect encompassing all paths and components in the layer.
boundsOfSelection
The bounding box of the current selection.
- (NSRect)boundsOfSelection
Return Value
An NSRect encompassing all selected paths, components and anchors on the layer.
calculateIntersectionsStartPoint:endPoint:
Calculates the intersection of all Paths with the line between StartPoint and EndPoint
- (NSArray
*)calculateIntersectionsStartPoint:(NSPoint)startPoint
endPoint:(NSPoint)endPoint
Parameters
- startPoint
-
the first point
- endPoint
-
the second point
Return Value
a list of point values
calculateIntersectionsStartPoint:endPoint:decompose:
Calculates the intersection of all Paths with the line between StartPoint and EndPoint
- (NSArray
*)calculateIntersectionsStartPoint:(NSPoint)startPoint
endPoint:(NSPoint)endPoint
decompose:(BOOL)decompose
Parameters
- startPoint
-
the first point
- endPoint
-
the second point
- decompose
-
indecates if components should be intersected, too.
Return Value
a list of point values
checkConnections
Checks is all nodes have the correct connection setting and corrects them if necessary.
- (void)checkConnections
cleanUpPaths
Tidies up paths in the layer (removes double points, unnecessary nodes, etc.)
- (void)cleanUpPaths
compareString
Returns a string to easily compare the paths of the layers. Layers are compatible if they have the same compareString.
- (NSString *)compareString
Return Value
An NSString.
Discussion
The string has a letter for each node, all components and all anchor names
Offcurve = o, Curve = c, Line = l.
contentToBackgroundCheckSelection:keepOldBackground:
Moves objects to the background.
-
(void)contentToBackgroundCheckSelection:(BOOL)checkSelection
keepOldBackground:(BOOL)keep
copyDecomposedLayer
A GSLayer copy with all components decomposed.
- (GSLayer *)copyDecomposedLayer
Return Value
The layer containing only paths.
correctPathDirection
Corrects the path directions and reorders the paths in the layer.
- (void)correctPathDirection
countOfGuides
Number of guides in the layer.
- (NSUInteger)countOfGuides
Return Value
NSUInteger containing the count of local guides.
countOfHints
The number of hints in the layer
- (NSUInteger)countOfHints
Return Value
Count of hints.
countOfPaths
Returns the count of paths in the layer.
- (NSUInteger)countOfPaths
Return Value
The count of paths in the layer.
countOfShapes
Returns the count of paths in the layer.
- (NSUInteger)countOfShapes
Return Value
The count of paths in the layer.
decomposeComponent:
Decomposes the Component.
- (void)decomposeComponent:(GSComponent
*)component
Parameters
- component
-
The componet to decompose
decomposeComponentDontNotifiy:
Decomposes the Component but does not trigger a UI update
- (void)decomposeComponentDontNotifiy:(GSComponent
*)aComponent
Parameters
- aComponent
-
The componet to decompose
Discussion
This is helpful in places where you just need the result but not need to redraw automatically
decomposeComponents
Decomposes components.
- (void)decomposeComponents
Discussion
This will also effect nested compontens.
dividePathAtNode:
returns the node before the opening.
- (GSNode *_Nullable)dividePathAtNode:(GSNode
*)node
drawBezierPath
The bezierPath for drawing the layer. It inclused the paths and componetents.
- (NSBezierPath *)drawBezierPath
drawInPen:
Draw the layer with a pen object
- (void)drawInPen:(NSObject<GSPenProtocol>
*)pen
Parameters
- pen
-
An object that conforms to the GSPenProtocol
elementDidChange:
Is called from element objects (anchors, components) if it has changed.
- (void)elementDidChange:(nullable GSElement
*)element
Parameters
- element
-
The changed element
enableFutureUpdates
Enables updating but doesn’t notify for past changes
- (void)enableFutureUpdates
See Also
enumerateShapesUsingBlock:
this will recurse into groups and such
- (void)enumerateShapesUsingBlock:(void ( ^ ) ( GSShape *obj
, NSIndexPath *indexPath , BOOL *stop ))block
glyph
The glyph to which the layer belongs. Equivalent to the parent property.
- (GSGlyph *)glyph
Return Value
The GSGlyph object for the layer.
horizontalShift:otherShifts:
Shifts the layer horizontally
- (void)horizontalShift:(CGFloat)shift
otherShifts:(NSDictionary *_Nullable)otherShifts
Parameters
- shift
-
The Shift value.
- otherShifts
-
A dict with shift values for the hole shift operation. Keys are glyphs names, value NSNumbers.
Discussion
This OtherShifts dict contains the shift values that will be applied to other glyphs at the same time. This is used to prevent diplacemnt of components if the base glyphs are shifted.
indexPathOfShape:
the index path of the shape.
- (NSIndexPath *)indexPathOfShape:(GSShape
*)shape
Discussion
it is a indexpath to allow access to nested groups
initWithDict:format:
initialises a layer with a dictionary loaded from a pList.
- (instancetype)initWithDict:(NSDictionary
*)layerDict
format:(GSFormatVersion)formatVersion
Parameters
- layerDict
-
A dictionary
layerColor:
The color for the layer.
- (NSColor *)layerColor:(BOOL)dark
Parameters
- dark
-
If drawing in dark mode
Return Value
the color as NSColor
makeComponents
Builds the compound glyph from the components suggested in GlyphData.xml (decompose attribute).
- (void)makeComponents
nextKerningExeptionForLayer:direction:
Returns a boolean value if self + RightLayer has a kerning exeption.
- (BOOL)nextKerningExeptionForLayer:(GSLayer
*)nextLayer
direction:(GSWritingDirection)direction
Parameters
- nextLayer
-
The GSLayer after the current layer
Return Value
True
if there is an exeption
nextKerningForLayer:direction:
Return the kern value for the sequence self + RightLayer.
- (CGFloat)nextKerningForLayer:(GSLayer *)nextLayer
direction:(GSWritingDirection)direction
Parameters
- nextLayer
-
The GSLayer after the current layer
Return Value
The kerning value as float or MaxInt if there is no value
Discussion
This checks if there is class kerning or exception.
Warning: returns MaxInt if no value is defined for that pair
objectInGuidesAtIndex:
Returns the guide loacated at theIndex.
- (nullable GSGuide
*)objectInGuidesAtIndex:(NSUInteger)index
Return Value
A GSComponent object.
objectInHintsAtIndex:
Returns the GSHint at the specified index.
- (GSHint
*_Nullable)objectInHintsAtIndex:(NSUInteger)index
Return Value
The GSHint object for the specified hint index.
objectInShapesAtIndex:
Returns the shape at index.
- (nullable GSShape
*)objectInShapesAtIndex:(NSUInteger)index
Return Value
A GSShape object.
previousKerningExeptionForLayer:direction:
Returns a boolean value if LeftLayer + self has a kerning exeption.
- (BOOL)previousKerningExeptionForLayer:(GSLayer
*)previousLayer
direction:(GSWritingDirection)direction
Parameters
- previousLayer
-
The GSLayer before the current layer
Return Value
True
if there is an exeption
previousKerningForLayer:direction:
Return the kern value for the sequence LeftLayer + self.
- (CGFloat)previousKerningForLayer:(GSLayer
*)previousLayer
direction:(GSWritingDirection)direction
Parameters
- previousLayer
-
The GSLayer before the current layer
Return Value
The kerning value as float or MaxInt if there is no value
Discussion
This checks if there is class kerning or exception.
Warning: returns MaxInt if no value is defined for that pair
propertyListValueFormat:
Returns the content of the object to store it in pList.
- (NSDictionary
*)propertyListValueFormat:(GSFormatVersion)format
Parameters
- format
-
the version of the dict
Discussion
This is used to store the data in the .glyphs file.
removeAnchor:
Removes the anchor from the Layer.
- (void)removeAnchor:(GSAnchor *)anchor
Parameters
- anchor
-
A GSAnchor object.
removeAnchorWithName:
Removes the anchor with the name AnchorName from the layer.
- (void)removeAnchorWithName:(NSString
*)anchorName
Parameters
- anchorName
-
An anchor name.
removeAttributeForKey:
Removed the object with this key.
- (void)removeAttributeForKey:(NSString *)key
Parameters
- key
-
The key to remove
removeHint:
Removes the Hint from the Layer.
- (void)removeHint:(GSHint *)hint
Parameters
- hint
-
A Hint.
removeShape:
This is necessary for scripting over Distributed Object (JSTalk)
- (void)removeShape:(GSShape *)shape
Parameters
- shape
-
The Shape to remove from the layer.
selectedObjects
Returns the element dicts of all selected elements
- (NSDictionary *)selectedObjects
setAttribute:forKey:
Adds something to the fonts attributes.
- (void)setAttribute:(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.
setNeedUpdateShapes
Is called from an object after it changed the outline of the layer.
- (void)setNeedUpdateShapes
setNextKerning:forLayer:direction:
Sets the kerning for the sequence self + RightLayer.
- (void)setNextKerning:(CGFloat)value
forLayer:(GSLayer *)nextLayer
direction:(GSWritingDirection)direction
Parameters
- value
-
the kern value as float
- nextLayer
-
The GSLayer after the current layer
Discussion
This checks if there is class kerning or exception.
setNextKerningExeption:forLayer:direction:
Sets, if LeftLayer + self has a exception or not.
- (void)setNextKerningExeption:(BOOL)exeption
forLayer:(GSLayer *)nextLayer
direction:(GSWritingDirection)direction
Parameters
- exeption
-
if it is a exetion or not
- nextLayer
-
The layer to the right
setPreviousKerning:forLayer:direction:
Sets the kerning for the sequence LeftLayer + self.
- (void)setPreviousKerning:(CGFloat)value
forLayer:(GSLayer *)previousLayer
direction:(GSWritingDirection)direction
Parameters
- value
-
the kern value as float
- previousLayer
-
The GSLayer before the current layer
Discussion
This checks if there is class kerning or exception.
setPreviousKerningExeption:forLayer:direction:
Sets, if LeftLayer + self has a exception or not.
- (void)setPreviousKerningExeption:(BOOL)exeption
forLayer:(GSLayer *)previousLayer
direction:(GSWritingDirection)direction
Parameters
- exeption
-
if it is a exetion or not
- previousLayer
-
The layer on the left
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
startUpdates
Enables updating and combined notifies for all changes that occured while disabled.
- (void)startUpdates
See Also
stopUpdates
Disables updating
- (void)stopUpdates
Discussion
Warning: Always make sure to call startUpdates
See Also
swapForegroundWithBackground
Moves objects from the layer to its background layer and vice versa.
- (void)swapForegroundWithBackground
tempDataForKey:
return value for key in tempData
- (nullable id)tempDataForKey:(nonnull NSString
*)key
Parameters
- key
-
the key
Return Value
a value or nil
transformSelection:
Transforms all selected elements.
- (void)transformSelection:(NSAffineTransform
*)transform
Parameters
- transform
-
the transfrom.
Discussion
This applies the Transform to all elements in the selection.