Created
March 23, 2017 16:34
-
-
Save awt2542/ce2a1d2dc8bc37b026268505ac6379e1 to your computer and use it in GitHub Desktop.
convertToTextLayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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