Jump To …
READMElib / psd / blend_mode.coffeelib / psd / channel_image.coffeelib / psd / color.coffeelib / psd / descriptor.coffeelib / psd / file.coffeelib / psd / header.coffeelib / psd / image.coffeelib / psd / image_export.coffeelib / psd / image_exports / png.coffeelib / psd / image_format.coffeelib / psd / image_formats / layer_raw.coffeelib / psd / image_formats / layer_rle.coffeelib / psd / image_formats / raw.coffeelib / psd / image_formats / rle.coffeelib / psd / image_mode.coffeelib / psd / image_modes / cmyk.coffeelib / psd / image_modes / greyscale.coffeelib / psd / image_modes / rgb.coffeelib / psd / init.coffeelib / psd / layer / blend_modes.coffeelib / psd / layer / blending_ranges.coffeelib / psd / layer / channel_image.coffeelib / psd / layer / helpers.coffeelib / psd / layer / info.coffeelib / psd / layer / mask.coffeelib / psd / layer / name.coffeelib / psd / layer / position_channels.coffeelib / psd / layer.coffeelib / psd / layer_info / blend_clipping_elements.coffeelib / psd / layer_info / blend_interior_elements.coffeelib / psd / layer_info / fill_opacity.coffeelib / psd / layer_info / gradient_fill.coffeelib / psd / layer_info / layer_id.coffeelib / psd / layer_info / layer_name_source.coffeelib / psd / layer_info / legacy_typetool.coffeelib / psd / layer_info / locked.coffeelib / psd / layer_info / metadata.coffeelib / psd / layer_info / nested_section_divider.coffeelib / psd / layer_info / object_effects.coffeelib / psd / layer_info / section_divider.coffeelib / psd / layer_info / solid_color.coffeelib / psd / layer_info / typetool.coffeelib / psd / layer_info / unicode_name.coffeelib / psd / layer_info / vector_mask.coffeelib / psd / layer_info / vector_origination.coffeelib / psd / layer_info / vector_stroke.coffeelib / psd / layer_info / vector_stroke_content.coffeelib / psd / layer_info.coffeelib / psd / layer_mask.coffeelib / psd / lazy_execute.coffeelib / psd / mask.coffeelib / psd / node.coffeelib / psd / nodes / ancestry.coffeelib / psd / nodes / build_preview.coffeelib / psd / nodes / group.coffeelib / psd / nodes / layer.coffeelib / psd / nodes / root.coffeelib / psd / nodes / search.coffeelib / psd / path_record.coffeelib / psd / resource.coffeelib / psd / resource_section.coffeelib / psd / resources / layer_comps.coffeelib / psd / resources.coffeelib / psd / util.coffeelib / psd.coffeeshims / init.coffeeshims / png.coffee

typetool.coffee

lib/psd/layer_info/
_ = require 'lodash'
parseEngineData = require 'parse-engine-data'
LayerInfo = require '../layer_info.coffee'
Descriptor = require '../descriptor.coffee'

module.exports = class TextElements extends LayerInfo
  @shouldParse: (key) -> key is 'TySh'

  TRANSFORM_VALUE = ['xx', 'xy', 'yx', 'yy', 'tx', 'ty']
  COORDS_VALUE = ['left', 'top', 'right', 'bottom']

  constructor: (layer, length) ->
    super(layer, length)

    @version = null
    @transform = {}
    @textVersion = null
    @descriptorVersion = null
    @textData = null
    @engineData = null
    @textValue = null
    @warpVersion = null
    @descriptorVersion = null
    @warpData = null
    @coords = {}

  parse: ->
    @version = @file.readShort()

    @parseTransformInfo()

    @textVersion = @file.readShort()
    @descriptorVersion = @file.readInt()

    @textData = new Descriptor(@file).parse()
    @textValue = @textData['Txt ']
    @engineData = parseEngineData(@textData.EngineData)

    @warpVersion = @file.readShort()

    @descriptorVersion = @file.readInt()

    @warpData = new Descriptor(@file).parse()

    for name, index in COORDS_VALUE
      @coords[name] = @file.readInt()

  parseTransformInfo: ->
    for name, index in TRANSFORM_VALUE
      @transform[name] = @file.readDouble()

  fonts: ->
    return [] unless @engineData?
    @engineData.ResourceDict.FontSet.map (f) -> f.Name

  sizes: ->
    return [] if not @engineData? and not @styles().FontSize?
    @styles().FontSize

  alignment: ->
    return [] unless @engineData?
    alignments = ['left', 'right', 'center', 'justify']
    @engineData.EngineDict.ParagraphRun.RunArray.map (s) ->
      alignments[Math.min(parseInt(s.ParagraphSheet.Properties.Justification, 10), 3)]

Return all colors used for text in this layer. The colors are returned in RGBA format as an array of arrays.

  colors: ->

If the color is opaque black, this field is sometimes omitted.

    return [[0, 0, 0, 255]] if not @engineData? or not @styles().FillColor?

    @styles().FillColor.map (s) ->
      values = s.Values.map (v) -> Math.round(v * 255)
      values.push values.shift() # Change ARGB -> RGBA for consistency
      values

  styles: ->
    return {} unless @engineData?
    return @_styles if @_styles?

    data = @engineData.EngineDict.StyleRun.RunArray.map (r) ->
      r.StyleSheet.StyleSheetData

    @_styles = _.reduce(data, (m, o) ->
      for own k, v of o
        m[k] or= []
        m[k].push v
      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:
      name: @fonts()[0]
      sizes: @sizes()
      colors: @colors()
      alignment: @alignment()
    left: @coords.left
    top: @coords.top
    right: @coords.right
    bottom: @coords.bottom
    transform: @transform

generated Tue May 12 2015 11:08:13 GMT-0400 (EDT)