Inherits from NSObject
Conforms to GSContainerProtocol
GSUserDataProtocol
NSCoding
NSCopying
Declared in GSLayer.h

Overview

The class defining the layer object

Layer Align Components

Tasks

Info

Metrics

Bezier Handling

Shapes

Anchors

Image

Guides

Selection

Updating

Attributes

Other Methods

Properties

BSB

The bottom side bearing

@property (nonatomic, assign) CGFloat BSB

LSB

The left side bearing.

@property (nonatomic) CGFloat LSB

RSB

The right side bearing.

@property (nonatomic) CGFloat RSB

TSB

The top side bearing

@property (nonatomic, assign) CGFloat TSB

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

bottomMetricsKey

The metrics key for the bottom side bearing

@property (nonatomic, strong, nullable) NSString *bottomMetricsKey

color

The NSColor object of the color label

@property (strong, nonatomic, nullable) NSColor *color

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

font

Returns the containing GSFont object

@property (readonly, nonatomic, nullable) GSFont *font

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

hints

The array of hints

@property (nonatomic, strong, nullable) NSArray<GSHint*> *hints

isAligned

YES if the layer is automatically aligned

@property (nonatomic, readonly) BOOL isAligned

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

parent

Returns the containing GSGlyph object

@property (weak, nonatomic, nullable) GSGlyph *parent

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

vertOrigin

Holds an offset from the top of the glyph (ascender) to be applied in vertical typesetting.

@property (nonatomic) CGFloat vertOrigin

Discussion

Used with vertWidth.

vertWidth

The vertical width

@property (nonatomic, assign) CGFloat vertWidth

vertWidthMetricsKey

The metrics key for the vertical width

@property (nonatomic, strong, nullable) NSString *vertWidthMetricsKey

visible

If the layer is visible

@property (nonatomic) BOOL visible

Discussion

This is controlled from the Layer panel

width

The width.

@property (nonatomic, assign) CGFloat width

widthMetricsKey

The metrics key for the width

@property (nonatomic, strong, nullable) NSString *widthMetricsKey

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.

addExtremePoints

Add Extreme Points to all paths.

- (void)addExtremePoints

addExtremePointsForce:

Add Extreme Points to all paths.

- (void)addExtremePointsForce:(BOOL)force

Parameters

force

Forces extremes if YES.

addHint:

Adds the Hint to the Layer.

- (void)addHint:(GSHint *)hint

Parameters

hint

A GSHint.

addHintCheck:

checks if a hint with the same type and index path is already present.

- (void)addHintCheck:(GSHint *)hint

addInflectionPoints

Adds nodes in segment inflections.

- (void)addInflectionPoints

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.

alignComponents

Helper function to fix component position.

- (void)alignComponents

Discussion

Call this every time you need to access the component. If the first component is a letter and the second is a accent, the Letter is placed at the origin, the width of the glyphs is copied from the referenced Glyph. If it find corresponding anchors it alignes the accents on it.

anchorForName:

Returns the corresponding anchor for an anchor name.

- (GSAnchor *)anchorForName:(NSString *)name

Parameters

name

The name of the anchor, e.g. “top”

Return Value

The GSAnchor object for the anchor name.

anchorForName:traverseComponents:

Returns a GSAnchor with for the given name.

- (GSAnchor *_Nullable)anchorForName:(NSString *_Nonnull)name traverseComponents:(BOOL)checkComponents

Parameters

name

The name of the anchor

checkComponents

If it should look into components

Return Value

The anchor or nil

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

clear

Empties the layer.

- (void)clear

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

Parameters

checkSelection

Only selected objects if YES.

keep

Replaces background layer if NO.

copyAnchorsFromComponents

Decomposes only the anchors.

- (void)copyAnchorsFromComponents

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

countOfAnchors

The count of the anchors

- (NSInteger)countOfAnchors

countOfComponents

Number of components in the layer.

- (NSUInteger)countOfComponents

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

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.

glyphMetrics

Metrics for the Layer

- (GSGlyphMetrics)glyphMetrics

Return Value

The vertical metrics from the fonts fontMaster with the same layerId/associatedlayerId and the width of 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

Discussion

This can be a Palette entry (for MS color fonts) or the Master color for color layer fonts

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

Parameters

index

An index within the bounds of the the guides array.

Return Value

A GSComponent object.

objectInHintsAtIndex:

Returns the GSHint at the specified index.

- (GSHint *_Nullable)objectInHintsAtIndex:(NSUInteger)index

Parameters

index

An index within the bounds of the hints array.

Return Value

The GSHint object for the specified hint index.

objectInShapesAtIndex:

Returns the shape at index.

- (nullable GSShape *)objectInShapesAtIndex:(NSUInteger)index

Parameters

index

An index within the bounds of the the paths array.

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.

setNeedUpdateMetrics

marks the RSB and LSB to need update.

- (void)setNeedUpdateMetrics

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

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

syncLeftMetrics

Recalculates the LSB using the metrics keys.

- (void)syncLeftMetrics

syncMetrics

Recalculates the LSB and RSB using the metrics keys.

- (void)syncMetrics

syncRightMetrics

Recalculates the RSB using the metrics keys.

- (void)syncRightMetrics

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.

undoManager

The undoManager of the parent (GSGlyph).

- (NSUndoManager *)undoManager

Return Value

An NSUndoManager object.

updateMetrics

Recalculates the LSB and RSB.

- (void)updateMetrics