-1

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;
    }
  }
}
Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
  • This function seems to get a font name, which then has to find the corresponding font, so that it can find the post script name. As a programmer with a knowledge of fonts, that looks right to me. So: how fast does this function run? Did you have a specific improvement in mind that the scripting guide in the photoshop/scripting dir rules out as being possible? Do you want to improve *this function* or its *repeated use* during processing? (e.g. if you call it many times, then just build a {fontname:fontpsname} lookup object on script startup and use that for instance lookup) – Mike 'Pomax' Kamermans Oct 10 '15 at 17:02
  • 1
    turns out maybe you didn't do your research first. The JS scripting guide for CS2 on http://www.adobe.com/devnet/photoshop/scripting.html tells us that there is a `getByName` function, on page 173 of http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/JavaScriptReferenceGuide.pdf, trivially found by checking the index for "fonts", which points to page 52, and says fonts are a TextFonts object, which points to page 173. – Mike 'Pomax' Kamermans Oct 10 '15 at 17:20
  • I've fallen out of habit of checking the Adobe docs, so you got me on that one. – Ghoul Fool Oct 11 '15 at 10:30

1 Answers1

2

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);
Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125