meltingice / psd.js

A Photoshop PSD file parser for NodeJS and browsers
MIT License
2.73k stars 390 forks source link

How to understand the text style ranges after calling text tool export #282

Closed velara3 closed 1 year ago

velara3 commented 1 year ago

If I have a text layer that has more than one set of styles is there a way to know what style range applies to what range of text?

 var textData = node.get("typeTool").export().font;

  var alignment = textData.alignment;
  var colors = textData.colors;
  var fonts = textData.names;
  var leading = textData.leading;
  var sizes = textData.sizes;
  var styles = textData.styles;
  var textDecoration = textData.textDecoration;
  var weights = textData.weights;
  var lengths = textData.lengthArray;
  var numberOfRanges = lengths.length;  // 3
  var numberOfFonts = fonts.length; // 4

In my test example there are four entries in the names array (font names) and the lengths array there is three entries. They don't quite line up with the style ranges.

Also, what is AdobeInvisFont? It is one entry in the font names. Is it related?

velara3 commented 1 year ago

It looks like the lengths are deltas from one style range to the other and that the InvisFont can be discarded.