Return postscript font name quickly

Issue

Using CS2, is there not a quicker way to get the postscript name of a font than looping over all installed fonts and comparing names?

function gimmePostScriptFontName(f)
{
  numOfFonts = app.fonts.length;
  for (var i = 0, numOfFonts; i < numOfFonts; i++)
  {
    fnt = app.fonts[i].name;

    if (f == fnt)
    {
      return app.fonts[i].postScriptName;
    }
  }
}

Solution

For future reference:

var myLayer = app.activeDocument.layers[0]; // top layer
// just make sure it's a text layer :)

var myFont = app.fonts.getByName(myLayer.textItem.font).name;
alert(myFont);

Answered By – Ghoul Fool

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published