Permalink
Browse files

Setting translation an rotation based on svg properties

  • Loading branch information...
nvh committed Jan 17, 2018
1 parent cea1e51 commit d19ad1ecfbd710eb6ea332f238af133cf3c16c81
Showing with 25 additions and 7 deletions.
  1. +25 −7 framer/SVGBaseLayer.coffee
View
@@ -82,18 +82,36 @@ class exports.SVGBaseLayer extends Layer
delete options.parent
delete options.element
pathProperties = ["fill", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-dasharray", "stroke-dashoffset", "name", "opacity"]
_.defaults options, @constructor.attributesFromElement(pathProperties, element)
if @_element.transform.baseVal.numberOfItems > 0
options.x ?= 0
options.y ?= 0
options.rotation ?= 0
indicesToRemove = []
for i in [0...@_element.transform.baseVal.numberOfItems]
console.log i
transform = @_element.transform.baseVal.getItem(i)
matrix = transform.matrix
switch transform.type
when 2 #SVG_TRANSFORM_TRANSLATE
options.x += matrix.e
options.y += matrix.f
#@_element.transform.baseVal.removeItem(i)
indicesToRemove.push(i)
when 4 #SVG_TRANSFORM_ROTATE
# We willingly ignore the translation from this matrix
options.rotation += - ((Math.atan2(matrix.c, matrix.d)) / Math.PI) * 180
indicesToRemove.push(i)
for index in indicesToRemove.reverse()
@_element.transform.baseVal.removeItem(0)
rect = @_element.getBoundingClientRect()
multiplier = Framer?.CurrentContext.pixelMultiplier ? 1
@_width = rect.width * multiplier
@_height = rect.height * multiplier
pathProperties = ["fill", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-dasharray", "stroke-dashoffset", "name", "opacity"]
_.defaults options, @constructor.attributesFromElement(pathProperties, element)
if @_element.transform.baseVal.numberOfItems > 0
translate = @_element.transform.baseVal.getItem(0).matrix
options.x ?= translate.e
options.y ?= translate.f
super(options)
for parent in @ancestors()

0 comments on commit d19ad1e

Please sign in to comment.