Permalink
Browse files

Fixed default lineHeight, and setting fontWeight and textAlign throug…

…h states
  • Loading branch information...
nvh committed Sep 1, 2017
1 parent e982caf commit fa5ddfa85c205c6f05e62b779323d3c1f2a34f16
Showing with 48 additions and 3 deletions.
  1. +8 −3 framer/TextLayer.coffee
  2. +40 −0 test/tests/TextLayerTest.coffee
View
@@ -61,7 +61,12 @@ class exports.TextLayer extends Layer
@styledTextOptions = options.styledText
options.color ?= @_styledText.getStyle("color")
options.fontSize ?= parseFloat(@_styledText.getStyle("fontSize"))
options.lineHeight ?= parseFloat(@_styledText.getStyle("lineHeight"))
lineHeight = @_styledText.getStyle("lineHeight")
if not lineHeight? or lineHeight is "normal"
lineHeight = 1.25
else
lineHeight = parseFloat(lineHeight)
options.lineHeight ?= lineHeight
else
_.defaults options,
backgroundColor: "transparent"
@@ -178,15 +183,15 @@ class exports.TextLayer extends Layer
promise.then ->
setTimeout(layer.renderText, 0)
)
@define "fontWeight", textProperty(@, "fontWeight")
@define "fontWeight", textProperty(@, "fontWeight", null)
@define "fontStyle", textProperty(@, "fontStyle", "normal", _.isString)
@define "textDecoration", textProperty(@, "textDecoration", null, _.isString)
@define "fontSize", textProperty(@, "fontSize", null, _.isNumber, null, (layer, value) ->
return if value is null or layer.__constructor
style = LayerStyle["fontSize"](layer)
layer._styledText.setStyle("fontSize", style)
)
@define "textAlign", textProperty(@, "textAlign")
@define "textAlign", textProperty(@, "textAlign", null)
@define "letterSpacing", textProperty(@, "letterSpacing", null, _.isNumber)
@define "lineHeight", textProperty(@, "lineHeight", null, _.isNumber)
@@ -516,6 +516,46 @@ describe "TextLayer", ->
tagLayer1.size.should.eql tagLayer2.size
it "should set a default lineHeight", ->
home = new TextLayer({
"styledText": {
"blocks": [{
"inlineStyles": [{
"startIndex": 0,
"endIndex": 4,
"css": {
"fontSize": "16px",
}
}],
"text": "HOME"
}]
},
})
home.lineHeight.should.equal 1.25
it "should set the font weight correctly through a state", ->
home = new TextLayer({
"styledText": {
"blocks": [{
"inlineStyles": [{
"startIndex": 0,
"endIndex": 4,
"css": {
"fontSize": "16px",
}
}],
"text": "HOME"
}]
},
})
home.states.selected =
fontWeight: 800
backgroundColor: "black"
home.stateSwitch("selected")
expect(home.fontWeight).to.equal 800
describe "textOverflow", ->
it "should enable clipping", ->
l = new TextLayer

0 comments on commit fa5ddfa

Please sign in to comment.