Permalink
Browse files

Fixing problem with gradient svg’s

  • Loading branch information...
nvh committed Jul 13, 2017
1 parent c7d4cda commit 3c5bbb655401b7d10dd8d9d6e956bc779734e69f
Showing with 26 additions and 13 deletions.
  1. +2 −0 framer/Layer.coffee
  2. +12 −13 framer/SVGLayer.coffee
  3. +1 −0 test/tests.coffee
  4. +11 −0 test/tests/SVGLayerTest.coffee
View
@@ -88,6 +88,8 @@ layerProxiedValue = (value, layer, property) ->
proxiedValue[subProperty] = subValue
layer[property] = proxiedValue
exports.layerProxiedValue = layerProxiedValue
layerPropertyPointTransformer = (value, layer, property) ->
if _.isFunction(value)
value = value(layer, property)
View
@@ -1,6 +1,6 @@
{_} = require "./Underscore"
{Color} = require "./Color"
{Layer, layerProperty} = require "./Layer"
{Layer, layerProperty, layerProxiedValue} = require "./Layer"
validFill = (value) ->
Color.validColorValue(value) or _.startsWith(value, "url(")
@@ -17,28 +17,27 @@ class exports.SVGLayer extends Layer
# Backwards compatibility for old Vekter exporter
options.color ?= options.backgroundColor
super options
@updateGradientSVG()
@define "fill", layerProperty(@, "fill", "fill", null, validFill, toFill)
@define "stroke", layerProperty(@, "stroke", "stroke", null, validFill, toFill)
@define "color", layerProperty(@, "color", "color", null, Color.validColorValue, Color.toColor, null, ((layer, value) -> layer.fill = value), "_elementHTML", true)
@define "gradient",
get: ->
return @_gradient
set: (value) ->
return layerProxiedValue(@_gradient, @, "gradient") if Gradient.isGradientObject(@_gradient)
return null
set: (value) -> # Copy semantics!
if Gradient.isGradient(value)
@_gradient = value
else
gradientOptions = Gradient._asPlainObject(value)
if not _.isEmpty(gradientOptions)
@_gradient = new Gradient(gradientOptions)
else
@_gradient = null
@_gradient = new Gradient(value)
else if not value and Gradient.isGradientObject(@_gradient)
@_gradient = null
@updateGradientSVG()
updateGradientSVG: =>
if not Gradient.isGradient(@_gradient)
@_elementGradientSVG.innerHTML = ""
updateGradientSVG: ->
return if @__constructor
if not Gradient.isGradient(@gradient)
@_elementGradientSVG?.innerHTML = ""
return
if not @_elementGradientSVG
View
@@ -43,6 +43,7 @@ require "./tests/LayerDraggableTest"
require "./tests/ContextTest"
require "./tests/ScrollComponentTest"
require "./tests/TextLayerTest"
require "./tests/SVGLayerTest"
require "./tests/PageComponentTest"
require "./tests/VersionTest"
require "./tests/ColorTest"
@@ -0,0 +1,11 @@
describe.only "SVGLayer", ->
describe "gradients", ->
it "should generate unique gradient id per instance", ->
a = new SVGLayer
gradient: new Gradient
b = new SVGLayer
gradient: new Gradient
a._elementGradientSVG.innerHTML.should.not.be.equal b._elementGradientSVG.innerHTML

0 comments on commit 3c5bbb6

Please sign in to comment.