Commit 2ac22aef authored by Ryan LeFevre's avatar Ryan LeFevre

Add CSS and export functions to type layers

parent a27023a9
...@@ -8,9 +8,6 @@ PSD.open(file).then(function (psd) { ...@@ -8,9 +8,6 @@ PSD.open(file).then(function (psd) {
type = node.get('typeTool'); type = node.get('typeTool');
if (!type) return; if (!type) return;
fonts = fonts.concat(type.fonts()); fonts = fonts.concat(type.fonts());
console.log(type.sizes());
console.log(type.alignment());
// type.styles();
}); });
console.log(_.uniq(fonts)); console.log(_.uniq(fonts));
......
...@@ -52,7 +52,7 @@ module.exports = class TextElements extends LayerInfo ...@@ -52,7 +52,7 @@ module.exports = class TextElements extends LayerInfo
sizes: -> sizes: ->
return [] if not @engineData? and not @styles().FontSize? return [] if not @engineData? and not @styles().FontSize?
_.uniq @styles().FontSize @styles().FontSize
alignment: -> alignment: ->
return [] unless @engineData? return [] unless @engineData?
...@@ -84,3 +84,31 @@ module.exports = class TextElements extends LayerInfo ...@@ -84,3 +84,31 @@ module.exports = class TextElements extends LayerInfo
m[k].push v m[k].push v
m m
, {}) , {})
# Creates the CSS string and returns it. Each property is newline separated
# and not all properties may be present depending on the document.
#
# Colors are returned in rgba() format and fonts may include some internal
# Photoshop fonts.
toCSS: ->
definition =
'font-family': @fonts().join(', ')
'font-size': "#{@sizes()[0]}pt"
'color': "rgba(#{@colors()[0].join(', ')})"
'text-align': @alignment()[0]
css = []
for k, v of definition
continue unless v?
css.push "#{k}: #{v};"
css.join("\n")
export: ->
value: @textValue
font: @fonts()[0]
left: @coords.left
top: @coords.top
right: @coords.right
bottom: @coords.bottom
transform: @transform
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment