Copy link to clipboard
Copied
Hello guys, I'm having an error when try to replace a font using InDesign script like this:
function editTextFonts (openDoc, tfEditData, textFrame) {
var lines = textFrame.lines
var firstLine = lines.firstItem()
var oldFont = firstLine.appliedFont
if (!tfEditData.hasOwnProperty('font')) {
return oldFont
}
var font = tfEditData.font
var changeFont = oldFont.postscriptName.indexOf(font) === -1
if (!font || !changeFont) {
return oldFont
}
var newFont = findFontByPostscriptName(font, app.fonts)
if (newFont === null || newFont.status !== FontStatus.INSTALLED) {
return oldFont
}
for (var i = 0; i < lines.length; i++) {
var line = lines[i]
line.appliedFont = newFont.postscriptName
}
When tries to assign newFont.postscriptName in appliedFont I got the error: The requested font family is not available. I have checked and the font is properly installed, even the variable newFont has the status INSTALLED. Any help with this will be really appreciated
Are you sure that the PostScript name is always the same as the font name? Sometimes they are spelled differently.
Copy link to clipboard
Copied
What data type is newFont.postscriptName? If it's a string, maybe use
line.appliedFont = app.fonts.item(newFont.postscriptName);
P.
Copy link to clipboard
Copied
That didn't solve the problem, the problem is happening with some fonts, not all of them, and when you check the font with problems, they are already installed
Copy link to clipboard
Copied
Are you sure that the PostScript name is always the same as the font name? Sometimes they are spelled differently.
Copy link to clipboard
Copied
Hey Peter, actually changing newFont.postscriptName for newFont.name fixed the problem. Really appreciate the help