Skip to content

Commit

Permalink
FIxed bug in setting font property
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Jul 11, 2017
1 parent 4ce455d commit 0697f93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions framer/TextLayer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class exports.TextLayer extends Layer
do (property) =>
@on "change:#{property}", (value) =>
# make an exception for fontSize, as it needs to be set on the inner style
if property isnt "fontSize"
if not (property in ["fontSize", "font"])
@_styledText.resetStyle(property)
@renderText()

Expand Down Expand Up @@ -492,7 +492,7 @@ class exports.TextLayer extends Layer
# Check if value contains number. We then assume proper use of font.
# Otherwise, we default to setting the fontFamily.
if /\d/.test(value)
layer._elementHTML.style.font = value
layer._styledText.setStyle("font", value)
else
layer.fontFamily = value
, "_elementHTML"
Expand Down
24 changes: 23 additions & 1 deletion test/tests/TextLayerTest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe "TextLayer", ->
padding: 10
layerA.style.padding.should.equal "20px"

describe "webfonts", ->
describe "Fonts", ->
it "sets the weight if the font property is set", ->
l = new TextLayer
font: Utils.loadWebFont("Raleway", 800)
Expand All @@ -295,6 +295,28 @@ describe "TextLayer", ->
l.fontFamily.should.equal "Raleway"
expect(l.fontWeight).to.equal 400

it "should set the font property correctly", ->
tagLayer1 = new TextLayer
x: 24
y: 24
text: "tag"
fontSize: 15
fontFamily: "Courier"
fontWeight: 400
lineHeight: 1.6
color: "white"
backgroundColor: "red"

tagLayer2 = new TextLayer
x: 24
y: 200
text: "tag"
font: "400 15px/1.6 Courier"
color: "white"
backgroundColor: "red"

tagLayer1.size.should.eql tagLayer2.size

describe "textOverflow", ->
it "should enable clipping", ->
l = new TextLayer
Expand Down

0 comments on commit 0697f93

Please sign in to comment.