-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement flatten * fix comment * Add changelog
- Loading branch information
1 parent
887f0b9
commit 2557cbd
Showing
13 changed files
with
186 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"penpot-exporter": minor | ||
--- | ||
|
||
Implement Flatten object translation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"penpot-exporter": patch | ||
--- | ||
|
||
Fix complex svgs with multiple different fills |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { transformVectorPathsAsChildren } from '@plugin/transformers/partials'; | ||
|
||
import { GroupShape } from '@ui/lib/types/shapes/groupShape'; | ||
import { PathShape } from '@ui/lib/types/shapes/pathShape'; | ||
|
||
import { transformGroupNodeLike, transformPathNode } from '.'; | ||
|
||
/* | ||
* Vector nodes can have multiple vector paths, each with its own fills. | ||
* | ||
* If the fills are not mixed, we treat it like a normal `PathShape`. | ||
* If the fills are mixed, we treat the vector node as a `GroupShape` with multiple `PathShape` children. | ||
*/ | ||
export const transformVectorNode = async ( | ||
node: VectorNode, | ||
baseX: number, | ||
baseY: number | ||
): Promise<GroupShape | PathShape> => { | ||
if (node.fills !== figma.mixed) return transformPathNode(node, baseX, baseY); | ||
|
||
return { | ||
...transformGroupNodeLike(node, baseX, baseY), | ||
...(await transformVectorPathsAsChildren(node, baseX, baseY)) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { parseSVG } from 'svg-path-parser'; | ||
|
||
type BoundingBox = { x1: number; y1: number; x2: number; y2: number }; | ||
|
||
export const getBoundingBox = (vectorPath: VectorPath): BoundingBox => { | ||
const path = parseSVG(vectorPath.data); | ||
|
||
if (!path.length) return { x1: 0, y1: 0, x2: 0, y2: 0 }; | ||
|
||
const bounds = { x1: Infinity, y1: Infinity, x2: -Infinity, y2: -Infinity }; | ||
|
||
for (const points of path) { | ||
switch (points.code) { | ||
case 'M': | ||
case 'L': | ||
case 'C': | ||
bounds.x1 = Math.min(bounds.x1, points.x); | ||
bounds.y1 = Math.min(bounds.y1, points.y); | ||
bounds.x2 = Math.max(bounds.x2, points.x); | ||
bounds.y2 = Math.max(bounds.y2, points.y); | ||
} | ||
} | ||
|
||
return bounds; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters