Permalink
Browse files

Rerendering after all fonts of StyledText are loaded

  • Loading branch information...
nvh committed Jul 21, 2017
1 parent 364ccbf commit b39ecb693020cc8c7cc98186cc79669cb66b497e
Showing with 26 additions and 2 deletions.
  1. +17 −0 framer/StyledText.coffee
  2. +5 −0 framer/TextLayer.coffee
  3. +4 −2 framer/Utils.coffee
View
@@ -182,6 +182,14 @@ class StyledTextBlock
getStyle: (style) ->
_.first(@inlineStyles).getStyle(style)
getFonts: ->
fonts = []
for style in @inlineStyles
font = style.getStyle("fontFamily")
if font?
fonts.push(font)
return fonts
replaceText: (search, replace) ->
currentIndex = 0
for style in @inlineStyles
@@ -295,6 +303,15 @@ class exports.StyledText
getStyle: (style, block=null) ->
return (block ? _.first(@blocks))?.getStyle(style) ? @element?.style[style]
getFonts: ->
fonts = []
elementFont = @element?.style["fontFamily"]
if elementFont?
fonts.push(elementFont)
for block in @blocks
fonts = fonts.concat block.getFonts()
return _.uniq(fonts)
measure: (currentSize) ->
constraints = {}
constraints.width = currentSize.width * currentSize.multiplier
View
@@ -144,6 +144,11 @@ class exports.TextLayer extends Layer
set: (value) ->
@_styledText = new StyledText(value)
@_styledText.setElement(@_elementHTML)
fonts = @_styledText.getFonts()
promise = Utils.isFontFamilyLoaded(fonts)
if _.isObject(promise)
promise.then =>
@renderText()
#Vekter properties
@define "autoWidth", @proxyProperty("_styledText.autoWidth",
View
@@ -495,10 +495,12 @@ Utils.deviceFont = (os) ->
# Load fonts from Google Web Fonts
_isFontLoadedResults = {}
Utils.isFontFamilyLoaded = (font, timeout = 10000) ->
Utils.isFontFamilyLoaded = (fonts, timeout = 10000) ->
if not _.isArray(fonts)
fonts = [fonts]
return Utils.loadWebFontConfig
custom:
families: [font]
families: fonts
timeout: timeout
fontsFromConfig = (config) ->

0 comments on commit b39ecb6

Please sign in to comment.