Skip to content

Commit

Permalink
✂️ Avoid cropping images twice
Browse files Browse the repository at this point in the history
This can happen when the cropped image is inside an symbol that
was detached and overrides the crop transform. This can cause
the code to generate the cropping mask twice for the same
image resulting in duplicate layers and UUIDs and crashing Sketch.
  • Loading branch information
javitonino committed Jun 14, 2023
1 parent a1853dd commit 4f37018
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/converter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def base_styled(fig_node: dict) -> _BaseStyled:
if (
obj["hasClippingMask"]
and obj["clippingMaskMode"] == ClippingMaskMode.OUTLINE
and not fig_node.get("f2sForceOutline")
and not fig_node.get("f2s_cropped_image")
):
# Outline mask behave differently in fig files and Sketch in regard to fill/stroke colors
# Remove fill
Expand Down
4 changes: 2 additions & 2 deletions src/converter/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def convert_fill(fig_node: dict, fig_fill: dict) -> Fill:
isEnabled=fig_fill["visible"],
)
case {"type": "IMAGE"}:
if is_cropped_image(fig_fill):
if is_cropped_image(fig_fill) and not fig_node.get("f2s_cropped_image"):
# Extract images to a separate layer and retrigger conversion
convert_crop_image_to_mask(fig_node)

Expand Down Expand Up @@ -168,7 +168,7 @@ def convert_crop_image_to_mask(fig_node: dict) -> None:
**content,
"mask": True,
"maskType": "OUTLINE",
"f2sForceOutline": True,
"f2s_cropped_image": True,
},
*cropped_images,
],
Expand Down
2 changes: 1 addition & 1 deletion src/converter/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def ignored_layer_type(fig_layer: dict) -> None:
def convert_node(fig_node: dict, parent_type: str) -> AbstractLayer:
name = fig_node["name"]
type_ = get_node_type(fig_node, parent_type)
logging.debug(f"{type_}: {name}")
logging.debug(f"{type_}: {name} {fig_node['guid']}")

try:
sketch_item = CONVERTERS[type_](fig_node)
Expand Down

0 comments on commit 4f37018

Please sign in to comment.