I am writing a script for photoshop to change font family to different font but the script works with some fonts and some not.
Here is the part of the script that is responsible for changing the font family:
var origDoc = activeDocument;
var fullName = origDoc.name;
var myLayerRef = origDoc.artLayers.add();
myLayerRef.kind = LayerKind.TEXT;
myLayerRef.name = fullName ;
var myTextRef = myLayerRef.textItem;
myTextRef.position = new Array( 100, 100);
myTextRef.size = 35;
myTextRef.font = 'Calibri'; //Font family name
myTextRef.contents = myLayerRef.name;
As you can see that the font family set for now is Calibri and when I run the script, the font changes to Calibri family, same for Verdana and others. BUT when I choose for example ‘Arial’, ‘Comic Sans MS’ the font keeps the default font family which is Myriad pro.
Also, when I set the font family to ‘Arial-BoldMT’ it works fine.
My goal is to have this font works which is like barcode font, but when I set its family name it doesn’t work either. (The font is installed on my computer).
https://www.barcodesinc.com/free-barcode-font/
I want to know based on what the font gets recognized or not.
2
Answers
Adobe Illustrator has the same trouble. It uses some ‘internal’ names for fonts. For example
Arial
isArialMT
,Comic Sans MS
isComicSansMS
etc. Sometimes it’s almost impossible to guess what is the ‘internal’ name of a given font. I wrote the little script that shows an ‘internal’ name of a selected text object:If you have Illustrator you can try it. As far as I can tell, your barcode fonts have the names:
Free3of9
andFree3of9Extended
.You probably want ArialMT.
There a difference between the font names and the postscript font names. Font name in the case is ArialMT, postscript name Arial.
One rather (inelegant) solution is to compare the postscript and font names to find out which is which. This script will work on a text layer and loop through your installed fonts and return the names. This just basic and fill fail on a non-text based layer.