Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix corner radius for vectors without strokecaps #75

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion plugin-src/transformers/partials/transformVectorPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,43 @@ const hasFillGeometry = (node: VectorNode | StarNode | LineNode | PolygonNode):
return 'fillGeometry' in node && node.fillGeometry.length > 0;
};

const hasStrokeGeometry = (node: VectorNode | StarNode | LineNode | PolygonNode): boolean => {
return 'strokeGeometry' in node && node.strokeGeometry.length > 0;
};

const hasStrokeCaps = (node: GeometryMixin & VectorLikeMixin): boolean => {
if (node.strokeCap !== figma.mixed) {
return node.strokeCap !== 'NONE';
}

if (node.vectorNetwork && node.vectorNetwork.vertices.length > 0) {
// check all vertices to see if they have stroke caps
return node.vectorNetwork.vertices.some(
vertex => vertex.strokeCap && vertex.strokeCap !== 'NONE'
);
}

return false;
};

const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): VectorPaths => {
console.log(node);
switch (node.type) {
case 'STAR':
case 'POLYGON':
return node.fillGeometry;
case 'VECTOR':
return hasFillGeometry(node) ? node.fillGeometry : node.vectorPaths;
// mixed vector & simple open figures
if (hasStrokeGeometry(node) && !hasStrokeCaps(node) && node.strokeGeometry.length > 0) {
return node.strokeGeometry;
}

// simple closed figures
if (hasFillGeometry(node)) {
return node.fillGeometry;
}

return node.vectorPaths;
case 'LINE':
return node.strokeGeometry;
}
Expand Down