Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
convertToTextLayer
convertToTextLayer = (layer) ->
t = new TextLayer
name: layer.name
frame: layer.frame
parent: layer.parent
cssObj = {}
css = layer._info.metadata.css
css.forEach (rule) ->
return if _.includes rule, '/*'
arr = rule.split(': ')
cssObj[arr[0]] = arr[1].replace(';','')
t.style = cssObj
importPath = layer.__framerImportedFromPath
if _.includes importPath, '@2x'
t.fontSize *= 2
t.lineHeight = (parseInt(t.lineHeight)*2)+'px'
t.letterSpacing *= 2
t.y -= (parseInt(t.lineHeight)-t.fontSize)/2 # compensate for how CSS handles line height
t.y -= t.fontSize * 0.1 # sketch padding
t.x -= t.fontSize * 0.08 # sketch padding
t.width += t.fontSize * 0.5 # sketch padding
t.text = layer._info.metadata.string
layer.destroy()
return t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.