Python API for "Expand Outline"

Is there a way to access this in Python? Can’t find it on GSPath.

ah, found it: .flattenOutlinesRemoveOverlap_origHints_secondaryPath_extraHandles_error_(False, None, None, None, None)

The function from the context menu calls this:

	NSArray *newPaths = [NSClassFromString(@"GlyphsFilterOffsetCurve") offsetPath:path offsetX:width / 2 offsetY:height / 2 makeStroke:!fill position:pos objects:returnObjects capStyleStart:capStart capStyleEnd:capEnd keepCompatibleOutlines:YES extraHandles:nil];

There is some more code before to get the settings from the path.

I refactored it that you can run (from version 3181)

NSArray *newPaths = [path expandedStroke];
1 Like

Thank you, Georg!

This same path, same parameters,
The newPaths obtained using objective-c are incorrect, while the newPaths obtained using pyobjc are correct.
Why?

What is incorrect. And can you post the python code that you have used?

python:

path = Layer.paths[0]
print(path.nodes)
OffsetCurve = NSClassFromString("GlyphsFilterOffsetCurve")
newPaths = OffsetCurve.offsetPath_offsetX_offsetY_makeStroke_position_objects_capStyleStart_capStyleEnd_keepCompatibleOutlines_extraHandles_(path, 30, 20, True, 0.5, None, 0, 0,True,None)
for newPath in newPaths:
	print(newPath)
	print(newPath.nodes)

incoming path is:

(
	<GSNode x=117.0 y=325.0 line>,
	<GSNode x=483.0 y=325.0 line>
)

Traverse each one newPaths is:

<GSPath 4 nodes>
(
	<GSNode x=117.0 y=345.0 line>,
	<GSNode x=117.0 y=305.0 line>,
	<GSNode x=483.0 y=305.0 line>,
	<GSNode x=483.0 y=345.0 line>
)

objc:

GSPath *path = (GSPath *)[Layer.paths objectAtIndex:0];
Log(path.nodes)
NSArray *newPaths = [NSClassFromString(@"GlyphsFilterOffsetCurve") offsetPath:path offsetX:30 offsetY:20 makeStroke:YES position:0.5 objects:nil capStyleStart:0 capStyleEnd:0 keepCompatibleOutlines:YES extraHandles:nil];
for(GSPath *path in paths){
    Log(path);
    Log(path.nodes);
}

incoming path is:

(
    "<GSNode 0x6000018eedc0> 117 325 LINE",
    "<GSNode 0x6000019fa040> 483 325 LINE"
)

Traverse each one newPaths is:

<GSPath 0x600001c02640> nodes: 2
(
    "<GSNode 0x600001c005a0> 117 325 LINE",
    "<GSNode 0x600001c02b20> 483 325 LINE"
)

Can you try this code:

GSPath *path = (GSPath *)[Layer.paths objectAtIndex:0];
Log(path.nodes)
NSArray *newPaths = [NSClassFromString(@"GlyphsFilterOffsetCurve") offsetPath:path offsetX:30 offsetY:20 makeStroke:YES position:0.5 objects:nil capStyleStart:0 capStyleEnd:0 keepCompatibleOutlines:YES extraHandles:nil];
for(GSPath *path in newPaths){
    Log(path);
    Log(path.nodes);
}

Sorry, I made a mistake in copying. My code was originally like this below.

GSPath *path = (GSPath *)[Layer.paths objectAtIndex:0];
Log(path.nodes)
NSArray *paths = [NSClassFromString(@"GlyphsFilterOffsetCurve") offsetPath:path offsetX:30 offsetY:20 makeStroke:YES position:0.5 objects:nil capStyleStart:0 capStyleEnd:0 keepCompatibleOutlines:YES extraHandles:nil];
for(GSPath *path in paths){
    Log(path);
    Log(path.nodes);
}

After copying it to this topic, in order to be consistent with the newPaths traversal above, I changed the paths to newPaths. However, I forgot to change the traversal below, which has nothing to do with it. The newPaths obtained are incorrect,it’s also
ncoming path is:

(
    "<GSNode 0x6000018eedc0> 117 325 LINE",
    "<GSNode 0x6000019fa040> 483 325 LINE"
)

Traverse each one newPaths is:

<GSPath 0x600001c02640> nodes: 2
(
    "<GSNode 0x600001c005a0> 117 325 LINE",
    "<GSNode 0x600001c02b20> 483 325 LINE"
)

what version of Glyphs do you use?
I get this:

(
    "<GSNode 0x600000f4f720> 136 105 LINE",
    "<GSNode 0x600000f4f540> 134 388 LINE"
)
<GSPath 0x600000fe6100> nodes: 4
(
    "<GSNode 0x600000fe6040> 106.001 104.859 LINE",
    "<GSNode 0x600000fe6ac0> 165.999 105.141 LINE",
    "<GSNode 0x600000fe5fe0> 163.999 388.141 LINE",
    "<GSNode 0x600000fe69a0> 104.001 387.859 LINE"
)

3252 and 3151 all like this, I don’t know where the problem is with me,where did you declare

+ (NSArray *)offsetPath:(GSPath *)path offsetX:(float)width offsetY:(float)height makeStroke:(bool)fill position:(float)pos objects:(nullable NSArray *)returnObjects capStyleStart:(GSLineCapStyle)capStart capStyleEnd:(GSLineCapStyle)capEnd keepCompatibleOutlines:(bool)keep extraHandles:(nullable NSMutableArray *)extraHandles;