Skip to content

Commit

Permalink
Fixed line nodes (#96)
Browse files Browse the repository at this point in the history
* fixed line nodes

* fixed line nodes

* changeset

* changeset

* Update .changeset/new-spiders-travel.md

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
  • Loading branch information
Cenadros and jordisala1991 committed May 10, 2024
1 parent f5a8b9c commit 9355f28
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-lamps-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": patch
---

Fixed correct size for line nodes
5 changes: 5 additions & 0 deletions .changeset/new-spiders-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": patch
---

Fixed line node export when using opacity 0 on the line
4 changes: 2 additions & 2 deletions plugin-src/transformers/partials/transformVectorPaths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { translateVectorPaths } from '@plugin/translators';
import { createLineGeometry, translateVectorPaths } from '@plugin/translators';

import { PathAttributes } from '@ui/lib/types/shapes/pathShape';

Expand All @@ -10,7 +10,7 @@ const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): V
case 'VECTOR':
return node.vectorPaths;
case 'LINE':
return node.strokeGeometry;
return createLineGeometry(node);
}
};

Expand Down
25 changes: 25 additions & 0 deletions plugin-src/translators/translateVectorPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ export const translateVectorPaths = (
return segments;
};

export const createLineGeometry = (node: LineNode): VectorPaths => {
const commands: (MoveToCommand | LineToCommand)[] = [];

commands.push({
command: 'moveto',
code: 'M',
x: 0,
y: 0
});

commands.push({
command: 'lineto',
code: 'L',
x: node.width,
y: node.height
});

return [
{
windingRule: 'NONZERO',
data: commands.map(({ code, x, y }) => `${code} ${x} ${y}`).join(' ') + ' Z'
}
];
};

const translateVectorPath = (path: VectorPath, baseX: number, baseY: number): Segment[] => {
const normalizedPaths = parseSVG(path.data);

Expand Down

0 comments on commit 9355f28

Please sign in to comment.