Frage

i am trying to set the font of a textItem, using textItem.font which accepts a string, but i do not know the exact font names to refer in code, i am trying to achieve something like this

var newLayer = docRef_1.artLayers.add();
newLayer.kind=LayerKind.TEXT;
var textItemRef = newLayer.textItem;
textItemRef.contents = someCharacter;
textItemRef.size = 120;
textItemRef.font="Verdana-Bold";

but the font names to refer in code are not the same as they appear in photoshop UI for e.g Arial is ArialMT, arial bold is Arial-BoldMT. Where can i get all the font names? i could not find it in the javascript reference.

War es hilfreich?

Lösung

The fonts available to Photoshop are listed in app.fonts. To list all fonts to the Extendscript Tools console, execute:

for (i=0; i< app.fonts.length; i++) {
    $.writeln(app.fonts[i].name);
}

You can use the app.fonts.getByName('String') method to call the first font in the app.fonts array that matches String in its name.

Andere Tipps

There is a difference between the displayed font name and the internal font name. In your script you have to use the internal name. This function can help you:

var internalFontName = getInternalFontName("Trebuchet MS Bold");    

function getInternalFontName(pFontName) {
    for (var i = 0; i < app.fonts.length; i++) {
       if (pFontName == app.fonts[i].postScriptName) {
           return pFontName; // already is an internal font name.
       }
       if (pFontName == app.fonts[i].name) {
           return app.fonts[i].postScriptName; // found an internal name.
       }
   }   
   return null;
}  
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top