• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

multiple fonts in a textItem using jsx

New Here ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

Hi,

I am saving currentLayer.textItem.contents to a text file. That part is working. But I would also like to save attributes about the textItem, specifically the fonts being used and style attributes in the textItem.

However, I am only able to find the first font using currentLayer.textItem.font . Can I somehow find a list of all fonts and attributes used in a specific textItem?

Thanks

TOPICS
Actions and scripting

Views

11.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Mar 21, 2013 Mar 21, 2013

As Mark has said it can get very messy getting the information you want, here is a snippet that a few people have worked on and might be of use to you...

    function getColorFromDescriptor(colorDesc, keyClass) {
      var colorObject = new SolidColor();
      switch (keyClass) {
      case "Grsc":
        colorObject.grey.grey = color.getDouble(charIDToTypeID('Gry '));
        break;
      case "RGBC":
        colorObject.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
        colorObject.rgb.gre

...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

if available - search in estk after the properties of text item

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

Hi pixxxel schubser,

I'm not sure what you mean by "estk"?

Would I do that like this:

for (var i = 0; i<currentLayer.textItem.estk.properties.length; i++){

txtFile.writeln('property'+ i +':  ' +currentLayer.textItem.estk.properties);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

Using the standard DOM you can only access the attributes of first character of a text layer… or thats what I recall… It may be possible with action manager to dig deeper into this but I've never tried… More than likely too complex for me… I think pixxxel means for you to look in the Object Model Viewer ( omv ) of the ExtendScript Toolkit ( estk ) just key comm+/ on the mac

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

As Mark has said it can get very messy getting the information you want, here is a snippet that a few people have worked on and might be of use to you...

    function getColorFromDescriptor(colorDesc, keyClass) {
      var colorObject = new SolidColor();
      switch (keyClass) {
      case "Grsc":
        colorObject.grey.grey = color.getDouble(charIDToTypeID('Gry '));
        break;
      case "RGBC":
        colorObject.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
        colorObject.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
        colorObject.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
        break;
      case "CMYC":
        colorObject.cmyk.cyan = colorDesc.getDouble(charIDToTypeID('Cyn '));
        colorObject.cmyk.magenta = colorDesc.getDouble(charIDToTypeID('Mgnt'));
        colorObject.cmyk.yellow = colorDesc.getDouble(charIDToTypeID('Ylw '));
        colorObject.cmyk.black = colorDesc.getDouble(charIDToTypeID('Blck'));
        break;
      case "LbCl":
        colorObject.lab.l = colorDesc.getDouble(charIDToTypeID('Lmnc'));
        colorObject.lab.a = colorDesc.getDouble(charIDToTypeID('A   '));
        colorObject.lab.b = colorDesc.getDouble(charIDToTypeID('B   '));
        break;
      default:
        return null;
      }
      return colorObject;
    };
    // get fonts and other parameters used in type layer
    function getFonts(textLayer) {
var font_content_detection = false;
      function markReturnedContentText(text) {
        if (font_content_detection) {
          return font_content_detection_symbols[0] + text + font_content_detection_symbols[1] + "\r";
        } else {
          return text;
        }
      }
      if (textLayer.kind == LayerKind.TEXT) {
        app.activeDocument.activeLayer = textLayer;
        var ref = new ActionReference();
        ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        var layerDesc = executeActionGet(ref);
        var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
        var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
        var fonts = [];
        for (var m = 0; m < rangeList.count; m++) {
          var styleDesc = rangeList.getObjectValue(m).getObjectValue(stringIDToTypeID('textStyle'));
          var aFrom = rangeList.getObjectValue(m).getInteger(stringIDToTypeID('from'));
          var aTo = rangeList.getObjectValue(m).getInteger(stringIDToTypeID('to'));
          if (m > 0) {
            if (rangeList.getObjectValue(m - 1)
              .getInteger(stringIDToTypeID('from')) == aFrom && rangeList.getObjectValue(m - 1)
              .getInteger(stringIDToTypeID('to')) == aTo) continue;
          }
          var theLetters = app.activeDocument.activeLayer.textItem.contents.substring(aFrom, aTo);
          var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'));
          var aSize = new UnitValue(styleDesc.getUnitDoubleValue(stringIDToTypeID('size')), "px");
          //Check if font has been transformed
            if (textDesc.hasKey(stringIDToTypeID('transform'))) {
                var mFactor = textDesc.getObjectValue(stringIDToTypeID('transform')).getUnitDoubleValue (stringIDToTypeID("yy") );
                aSize = Math.round(aSize * mFactor);
                }
          var aColor = getColorFromDescriptor(styleDesc.getObjectValue(charIDToTypeID("Clr ")), typeIDToCharID(styleDesc.getClass(charIDToTypeID("Clr "))));
      
          if (styleDesc.hasKey(stringIDToTypeID('leading'))) {
            var aLeading = new UnitValue(styleDesc.getUnitDoubleValue(stringIDToTypeID('leading')), "px");
          } else {
            var aLeading = "";
          }
        var txt = theLetters;
          var merged = false;
          if (txt.length > 0) {
            for (var x = 0; x < m; x++) {
              try {
                if (fonts.font === aFont && fonts.size === aSize && fonts.color.rgb.hexValue === aColor.rgb.hexValue && fonts.leading === aLeading) {
                  // It's a hack!!!
                  if (fonts.text !== txt) {
                    fonts.text += markReturnedContentText(txt);
                  }
                  merged = true;
                }
              } catch (e) {}
            }
            if (!merged) {
              fonts.push({
                text: markReturnedContentText(txt),
                font: aFont,
                size: aSize,
                color: aColor,
                leading: aLeading
              });
            }
          }

        };
        return fonts;
      }
  };
var f = getFonts(activeDocument.activeLayer);
for(var s in f) {
    $.writeln( f.font + " - " + f.color.rgb.hexValue + " - " + Number(f.size).toFixed(2) + " - [" + f.text + "] - " + Number(f.leading));
    }


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

Thank you, Thank you, Thank you. Paul and Mark and pixxxel schubser.

I like this forum and I don't mind messy. It worked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2016 Jul 01, 2016

Copy link to clipboard

Copied

LATEST

This was so helpful, thanks. One note, I think Adobe changed some of its endpoint names. In order to get this to work, I had to change lines 38 & 39 to:

if (textLayer.kind == TextType.POINTTEXT) { 

        app.activeDocument.activeLayer = textLayer.parent; 

I wasn't interested in the color functionality, so if there are bugs there, I don't know about them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines