Skip to content

Commit

Permalink
Setting translation an rotation based on svg properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Jan 17, 2018
1 parent cea1e51 commit d19ad1e
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions framer/SVGBaseLayer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d19ad1e

Please sign in to comment.