photoshop cs3 scripting - font names

≯℡__Kan透↙ 提交于 2019-12-24 14:22:33

问题


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.


回答1:


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.




回答2:


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;
}  


来源:https://stackoverflow.com/questions/20575016/photoshop-cs3-scripting-font-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!