1 Reply Latest reply: Jun 11, 2013 12:58 PM by Tom Ruark RSS

    Problem with getting font name in PS CS5/CS6 plugin

    JoeyJojoII

      Hello,

       

      When I call GetString method such as:

       

      error = sPSActionDescriptor->GetString(descFont, keyFontName, fontName, stringLength);

      on some .psd file which contains text layer(s), I get error -1715.

       

       

      Weirdly, this doesn't occure on all versions of Photoshop, for example I created a file in PS CS5, and this error occurs both in CS4 and CS6, but it works fine in CS5.

       

      If anyone could tell me why this is happening, I would be really grateful.

       

       

      Thank you!

        • 1. Re: Problem with getting font name in PS CS5/CS6 plugin
          Tom Ruark Adobe Employee

          Your layer probably has a layer style.

           

          Try this script and see if it gets your font information for you. You will need to convert to C/C++ of course but see if this script can find your font on the document.

           

          var fontsInUse = [];

          var colorsInUse = [];

           

           

          if ( documents.length > 0 ) {

           

              GetFontUsage( activeDocument.layers, fontsInUse );

             

                    alert( fontsInUse );

           

           

              GetColorUsage( activeDocument.layers, colorsInUse );

           

           

                    alert( colorsInUse );

           

           

          } else {

                    alert( "Please open a document." );

          }

           

           

           

           

          function GetFontUsage( l, f ) {

              for ( var i = 0; i < l.length; i++ ) {

                  if ( l[i].typename == "LayerSet" ) {

                      GetFontUsage( l[i].layers, f );

                  } else if ( l[i].typename == "ArtLayer" && l[i].kind == LayerKind.TEXT  ) {

                      try {

                          f.push( l[i].textItem.font );

                      }

                      catch(e) {

                          f.push( GetFontUsageFromDescriptor( l[i] ) );

                      }

                  }

              }

          }

           

           

          function GetColorUsage( l, f ) {

              for ( var i = 0; i < l.length; i++ ) {

                  if ( l[i].typename == "LayerSet" ) {

                      GetFontUsage( l[i].layers, f );

                  } else if ( l[i].typename == "ArtLayer" && l[i].kind == LayerKind.TEXT  ) {

                      try {

                          f.push( Math.round(l[i].textItem.color.rgb.red) + ":" +

                                  Math.round(l[i].textItem.color.rgb.green) + ":" +

                                  Math.round(l[i].textItem.color.rgb.blue));

                      }

                      catch(e) {

                          f.push( GetColorUsageFromDescriptor( l[i] ) );

                      }

                  }

              }

          }

           

           

          // text layer probably has a layer style

          // we will try to select the layer

          // pull the descriptor

          // and see if we can find a font

          function GetFontUsageFromDescriptor( l ) {

              var layerFontName = "";

             

              var lastActive = activeDocument.activeLayer;

              activeDocument.activeLayer = l;

             

              var ktextKeyStr = stringIDToTypeID("textKey");

                    var ref = new ActionReference();

                    ref.putProperty(charIDToTypeID('Prpr'), ktextKeyStr);

                    ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'),

                                                                                                                                            charIDToTypeID('Trgt'));

                    var desc = executeActionGet(ref);

           

                    if ( desc.hasKey( ktextKeyStr ) ) {

                              var descText = desc.getObjectValue( ktextKeyStr );

                  var kparagraphStyleRangeStr = stringIDToTypeID( "paragraphStyleRange" );

                  if ( descText.hasKey( kparagraphStyleRangeStr ) ) {

                      var paraList = descText.getList(  kparagraphStyleRangeStr );

                      var kparagraphStyleStr = stringIDToTypeID("paragraphStyle");

                      var paraDesc = paraList.getObjectValue( 0 );

                      if ( paraDesc.hasKey( kparagraphStyleStr ) ) {

                          var paraStyle = paraDesc.getObjectValue( kparagraphStyleStr );

                          var kdefaultStyleStr = stringIDToTypeID("defaultStyle");

                          if ( paraStyle.hasKey( kdefaultStyleStr ) ) {

                              var defStyle = paraStyle.getObjectValue( kdefaultStyleStr );

                              var kfontPostScriptNameStr = stringIDToTypeID("fontPostScriptName");

                              if ( defStyle.hasKey( kfontPostScriptNameStr ) ) {

                                  layerFontName = defStyle.getString( kfontPostScriptNameStr );

                              }

                          }

                      }

                  }

                    }

           

           

              activeDocument.activeLayer = lastActive;

           

           

              return layerFontName;

          }

           

           

          // text layer probably has a layer style

          // we will try to select the layer

          // pull the descriptor

          // and see if we can find a color

          function GetColorUsageFromDescriptor( l ) {

              var layerColor = "";

             

              var lastActive = activeDocument.activeLayer;

              activeDocument.activeLayer = l;

             

              var ktextKeyStr = stringIDToTypeID("textKey");

                    var ref = new ActionReference();

                    ref.putProperty(charIDToTypeID('Prpr'), ktextKeyStr);

                    ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'),

                                                                                                                                            charIDToTypeID('Trgt'));

                    var desc = executeActionGet(ref);

           

                    if ( desc.hasKey( ktextKeyStr ) ) {

                              var descText = desc.getObjectValue( ktextKeyStr );

                  var kparagraphStyleRangeStr = stringIDToTypeID( "paragraphStyleRange" );

                  if ( descText.hasKey( kparagraphStyleRangeStr ) ) {

                      var paraList = descText.getList(  kparagraphStyleRangeStr );

                      var kparagraphStyleStr = stringIDToTypeID("paragraphStyle");

                      var paraDesc = paraList.getObjectValue( 0 );

                      if ( paraDesc.hasKey( kparagraphStyleStr ) ) {

                          var paraStyle = paraDesc.getObjectValue( kparagraphStyleStr );

                          var kdefaultStyleStr = stringIDToTypeID("defaultStyle");

                          if ( paraStyle.hasKey( kdefaultStyleStr ) ) {

                              var defStyle = paraStyle.getObjectValue( kdefaultStyleStr );

                              var kColorStr = stringIDToTypeID("color");

                              if ( defStyle.hasKey( kColorStr ) ) {

                                  var colorDesc = defStyle.getObjectValue( kColorStr );

                                  layerColor += Math.round( colorDesc.getInteger( stringIDToTypeID("red" ) ) ) + ":";

                                  layerColor += Math.round( colorDesc.getInteger( stringIDToTypeID("green" ) ) ) + ":";

                                  layerColor += Math.round( colorDesc.getInteger( stringIDToTypeID("blue" ) ) );

                              }

                          }

                      }

                  }

                    }

           

           

              activeDocument.activeLayer = lastActive;

           

           

              return layerColor;

          }