Skip to content

Instantly share code, notes, and snippets.

@awt2542
Created March 23, 2017 16:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awt2542/ce2a1d2dc8bc37b026268505ac6379e1 to your computer and use it in GitHub Desktop.
Save awt2542/ce2a1d2dc8bc37b026268505ac6379e1 to your computer and use it in GitHub Desktop.
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