Skip to content

Commit

Permalink
fix for Sketch 52
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour committed Sep 5, 2018
1 parent 6463e86 commit 4b34c9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/my-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ function getOptionsFromLayer(layer) {
let options = {}

const fill = (layer.style.fills || []).filter(
f => f.sketchObject.isEnabled() && f.fill === 'Color'
f => f.sketchObject.isEnabled() && f.fill === sketch.Style.FillType.Color
)[0]

if (fill) {
options.fill = fill.color
}

const border = (layer.style.borders || []).filter(
f => f.sketchObject.isEnabled() && f.fillType === 'Color'
f => f.sketchObject.isEnabled() && f.fillType === sketch.Style.FillType.Color
)[0]

if (border) {
Expand All @@ -44,11 +44,15 @@ export default function(context) {
}

selection.forEach(layer => {
if (layer.type !== 'Shape') {
if (!layer.sketchObject.pathInFrameWithTransforms) {
return
}

const rc = new RoughSketch(layer.parent)
// override the wrapper to have a proper object
layer = sketch.Shape.fromNative(layer.sketchObject)

const rc = new RoughSketch(layer.parent.type === 'Page' ? layer : layer.parent)

const newLayer = rc.path(
getPathFromLayer(layer),
getOptionsFromLayer(layer)
Expand All @@ -62,8 +66,8 @@ export default function(context) {
// hide previous layer
layer.hidden = true
layer.selected = false
// select new one

// select new one
newLayer.selected = true
})
}
14 changes: 8 additions & 6 deletions src/roughjs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { RoughGenerator } from 'roughjs/src/generator' // we hook into the internals to write the wrapper ourselves
import sketch from 'sketch'

const shapeFromPath = MSShapeGroup.shapeWithBezierPath || MSShapeGroup.layerWithPath

export class RoughSketch {
constructor(layer, config) {
this.layer = sketch.fromNative(layer);
this.layer = layer;
this._init(config);
}

Expand Down Expand Up @@ -79,7 +81,7 @@ export class RoughSketch {
switch (drawing.type) {
case 'path': {
let closed = MOPointer.alloc().init()
path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath(
path = sketch.Shape.fromNative(shapeFromPath(
MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed(
this._opsToPath(drawing),
closed
Expand All @@ -95,7 +97,7 @@ export class RoughSketch {
}
case 'fillPath': {
let closed = MOPointer.alloc().init()
path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath(
path = sketch.Shape.fromNative(shapeFromPath(
MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed(
this._opsToPath(drawing),
closed
Expand All @@ -113,7 +115,7 @@ export class RoughSketch {
}
case 'path2Dfill': {
let closed = MOPointer.alloc().init()
path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath(
path = sketch.Shape.fromNative(shapeFromPath(
MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed(
drawing.path,
closed
Expand All @@ -136,7 +138,7 @@ export class RoughSketch {
})

let closed = MOPointer.alloc().init()
const mask = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath(
const mask = sketch.Shape.fromNative(shapeFromPath(
MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed(
drawing.path,
closed
Expand Down Expand Up @@ -176,7 +178,7 @@ export class RoughSketch {
fweight = o.strokeWidth / 2;
}
let closed = MOPointer.alloc().init()
let path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath(
let path = sketch.Shape.fromNative(shapeFromPath(
MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed(
this._opsToPath(drawing),
closed
Expand Down

0 comments on commit 4b34c9e

Please sign in to comment.