Skip to content

Commit

Permalink
👁️ Additional defaults for blend modes (#124)
Browse files Browse the repository at this point in the history
Blend mode appears to be omitted from the `fig` model when it's set to `NORMAL`. This leads to a key error when processing a node. This small tweak uses `get` to ensure we fall back to `NORMAL` when the `blendMode` key isn't set.
  • Loading branch information
tmdvs authored Jul 15, 2024
1 parent f47fdd9 commit 9613bc5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/converter/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def convert_crop_image_to_mask(fig_node: dict) -> None:
"visible": old.get("visible", True),
"horizontalConstraint": old.get("horizontalConstraint", "MIN"),
"verticalConstraint": old.get("verticalConstraint", "MIN"),
"blendMode": old["blendMode"],
"opacity": old["opacity"],
"blendMode": old.get("blendMode", "NORMAL"),
"opacity": old.get("opacity", 1),
"resizeToFit": True,
"children": [
{
Expand Down Expand Up @@ -205,8 +205,8 @@ def cropped_image_layer(fig_node: dict, fill: dict) -> dict:
"visible": fig_node.get("visible", True),
"horizontalConstraint": fig_node.get("horizontalConstraint", "MIN"),
"verticalConstraint": fig_node.get("verticalConstraint", "MIN"),
"blendMode": fig_node["blendMode"],
"opacity": fig_node["opacity"],
"blendMode": fig_node.get("blendMode", "NORMAL"),
"opacity": fig_node.get("opacity", 1),
"fillPaints": [fill],
}
del image_layer["fillPaints"][0]["transform"]
Expand Down Expand Up @@ -375,10 +375,10 @@ def convert_effects(fig_node: dict) -> _Effects:


def context_settings(fig_node: dict) -> ContextSettings:
blend_mode = BLEND_MODE[fig_node["blendMode"]]
opacity = fig_node["opacity"]
blend_mode = BLEND_MODE[fig_node.get("blendMode", "NORMAL")]
opacity = fig_node.get("opacity", 1)

if fig_node["blendMode"] == "NORMAL" and opacity == 1:
if blend_mode == BlendMode.NORMAL and opacity == 1:
# Sketch interprets normal at 100% opacity as pass-through
opacity = 0.99

Expand Down

0 comments on commit 9613bc5

Please sign in to comment.