SketchAPI icon indicating copy to clipboard operation
SketchAPI copied to clipboard

ShapePath.fromSVGPath not always working

Open mathieudutour opened this issue 5 years ago • 0 comments

When using ShapePath.fromSVGPath() with 'M240.08977769002323 195.69850181279688 M239.3389469189814 195.1249563058996 C329.1454695492273 191.83757520309732, 417.69707285312586 192.24985209192084, 601.5937121041572 193.98028760970763 M241.05711356212504 196.68565523660524 C329.0479087098456 195.0380945943925, 420.3544447319207 193.20209954632867, 600.5812513132819 195.93692264612972 M602.3623436938979 193.92319836278298 C599.4983826340579 259.1529885463191, 600.143084615553 326.7579119833871, 601.9295369418934 427.13641338984405 M601.2463570210457 195.8343797591363 C601.2790604283608 266.6232716856265, 602.1004597194354 339.95563978579116, 601.7746292375971 426.1871639477388 M599.7889754966361 426.15904064807074 C476.06104758627583 423.963484270309, 353.3564042781988 424.36327284983713, 240.97519291504395 425.8922125641362 M601.71993195043 427.9425716405573 C458.19244360456565 428.65556431008844, 313.81672395034224 427.87930139906285, 238.6408044735431 427.26695682997615 M238.23112615678585 426.8610846886658 C240.79075570086826 339.49629173798263, 242.1892296948075 250.17763391077088, 238.08237091371606 196.05917539422663 M238.11927768471378 426.6964039854597 C240.61967386298411 350.677674293837, 240.97841629213212 272.91024784797133, 238.17374285206776 194.06502985694144 M239.08548944623843 195.0979169350586 C239.47035319742847 195.13928871219025, 239.7527201044854 195.6180244244106, 240.21063287646382 195.62685797013802 M238.9977034317816 195.0217496746931 C239.32019889207984 195.2703062043428, 239.65002134116844 195.46988778782628, 240.0411750080069 195.75589699030778', the resulting path only have 2 curve points instead of 20.

Changing https://github.com/sketch-hq/SketchAPI/blob/develop/Source/dom/layers/ShapePath.js#L81-L87 to

    return new this({
      sketchObject: MSShapePathLayer.layerWithPath_integralFrame(
        MSPath.pathWithBezierPath(
          SVGPathInterpreter.bezierPathFromCommands(svgPath)
        ),
        true
      ),
    })

gives the expected result.

Not sure why setting an integral frame would yield such a different result but ¯_(ツ)_/¯

ref mathieudutour/rough-sketch#8, https://github.com/mathieudutour/rough-sketch/commit/169e9f4b2f8b80267edaa9ce9e2090dcfb22d0e4

mathieudutour avatar Jan 09 '20 10:01 mathieudutour