• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Scripting fonts

Enthusiast ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Hello, there.

Any idea on how to deal with this?

lf_corullon_0-1594750531209.png

 

I really thought all fonts have all properties.

But I'm stucked on this... don't know how to deal with.

Trying to apply a font which is installed but I receive this...

 

Thanks in advance.

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 15, 2020 Jul 15, 2020

I know you said this wasn't the case, but I would check to ensure the status of the Font is Installed before processing. 

for (var i=0; i<myFonts.length; i++) {
	try {
          if (myFonts[i].status != FontStatus.INSTALLED) {continue;} //NEW LINE	
          var fStr = myFonts[i].fontFamily + " " + myFonts[i].fontStyleName;
		} catch(e) {
			var fStr = "Error";
			}

Votes

Translate

Translate
Community Expert ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Hi lf_corullon,

do you deal with fonts that are solely installed with a Document fonts folder?

Is this perhaps a variable font you are inspecting?

What's your exact version of InDesign and operating system?

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Hi, Uwe. Thanks for reply.

No. I'm dealing with app.fonts.

InDesign CC2020 15.1.1.103 on Win10 x64.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

What is the specific property you cannot get the value from?

What font is it? Where is it installed?

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

I'm just trying to get fontFamily and fontStyleName.

If I type some characters and ask for fontFamily and fontStyleName, I get no errors.

 

In my script scenario (where I am dealing with lots of fonts), the script gets this font name as "ChinChan Regular". But its style name is "Medium". I bypassed this font in the script code and it runs fine.

 

If I try your code, I get the error: "Design Axes are not supported for the font."

 

I also don't understand why try/catch doesn't work on this.

 

The font is activated by fontBase (as a lot of other fonts).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Suggestion: Do a text frame in InDesign. Type some characters with the problem font.

Select a character, run the following code on the text selection and post the results.

 

var appliedFont = app.selection[0].appliedFont;
var propertyValuePairs = [];
var e ;

for( x in appliedFont )
{
	try{
		propertyValuePairs[propertyValuePairs.length++] = 
		x +"\t"+appliedFont[x].toString();
	}catch(e)
	{
		propertyValuePairs[propertyValuePairs.length++] = 
		x +"\t"+"Error: "+e.number +", "+ e.message;
	};
};

propertyValuePairs.sort().join("\r");

 

Best,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Do you have a link to the font's foundry?

 

FWIW: numDesignAxe, designAxesName, designAxesRange and designAxesValue are specific properties of variable fonts. If the font is no variable font all the designAxes properties are not available. They should return error 15896.

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Font.html

 

Properties namefullName or fullNameNative should give you more info on the specific style.

Also of interest is the value of location. How is that?

 

Do you get your array of fonts this way? :

var fontArray = app.fonts.everyItem().getElements();

If not, try it this way. Maybe it makes a difference…

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

I'm with the documentation always open.

I got the array with just app.fonts.

Now I tried app.fonts.everyItem().getElements() and the script is incredible faster.

But, stopped at the same point.

The location property says "System Font".

 

What is puzzling me is if I use that font in a document and run the script, it works.

In a System scenario, the script stops. I assume is this font because I bypassed it and the script works.

But in a document tests, there is no problems/errors...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Hi, Uwe.

This workaround solves the problem.

But, of course, it's not viable, since a lot of other fonts could have this same "particularity".

 

lf_corullon_0-1594771647140.png

 

What I mean by "particularity"?

 

lf_corullon_1-1594771958125.png

"ChinChan Regular" is how the script reads the font name.

But, as you can see in the code below, I forced "Medium" in the code to see if it works...

 

Again, I can't understand why the script (in the loop context) gets the font name as "regular". Because if I run an alert in the selection in image 2, appliedFont.name shows "ChinChan Medium".

 

I'm getting crazy...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

What happens if you check fontStyleNameNative instead of fontStyleName, or fullName/fullNameNative? The system font name may have a different way of identifying the font than what you get from the appliedFont name property. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

Thanks, @brlanp311. But the same error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

Will it be the same issue if you run your script with InDesign CC 2019 or a previous version?

Just to rule out a bug with InDesign 2020.

 

Location said "System Font" ?

How is that? Usually a path to the font file is given.

Exception: Fonts from Adobe Fonts service

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

Tested in CC2019 and same error. Same font.

Yes, location said "System Font". Maybe because it's activated by font manager (but a lot of other fonts are too).

 

Any of you are willing to receive my code to test locally?

PS: Unfortunatelly, I can't share the code publicly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

I do not have the font and also not using fontBase so I cannot test your scenario.

My suggestion would be a test on your side without using fontBase.

Perhaps fontBase has an issue with the font in conjunction with InDesign?

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

Already tested. Same error with the font installed on Windows.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

Thank you so much, @brianp311 for your help.

I think it's a font issue. But not exclusive to this particular one.

Why try/catch doesn't work on this scenario?

Why if(myFonts[i].fontStyleName) doesn't work too?

 

Should I leave this, delete the code and move on?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

A simple script example that stops in error for me

 

var myFonts = app.fonts.everyItem().getElements();

var myProgress = new Window ("palette" , "Script by LFCorullón");
myProgress.pbar = myProgress.add("progressbar", undefined, 0, myFonts.length);
myProgress.pbar.preferredSize.width = 300;
myProgress.g = myProgress.add("group");
myProgress.g.orientation = "column";
myProgress.g.spacing = 2;
myProgress.str = myProgress.g.add("statictext" , [0,0,300,24]);
myProgress.str2 = myProgress.g.add("statictext" , [0,0,300,24]);
myProgress.str.text = "Start processing...";
myProgress.str2.text = "";
myProgress.show();

for (var i=0; i<myFonts.length; i++) {
	try {
		var fStr = myFonts[i].fontFamily + " " + myFonts[i].fontStyleName;
		} catch(e) {
			var fStr = "Error";
			}
	
	myProgress.pbar.value = i+1;
	myProgress.str.text = "Font " + (i+1) + " of " + myFonts.length;
	myProgress.str2.text = fStr;
	}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

I know you said this wasn't the case, but I would check to ensure the status of the Font is Installed before processing. 

for (var i=0; i<myFonts.length; i++) {
	try {
          if (myFonts[i].status != FontStatus.INSTALLED) {continue;} //NEW LINE	
          var fStr = myFonts[i].fontFamily + " " + myFonts[i].fontStyleName;
		} catch(e) {
			var fStr = "Error";
			}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

This one worked.

I really can't understand.

Because if I type some characters of that font, select them, and check for appliedFont.status it says INSTALLED. And, as mentioned, returns the right name and style.

I have a lot of fonts activated by font manager (fontBase). Some of them are processed, some (as ChinChan) not. At least, the script runs thru the end. Thanks again, Brian!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

I think the issue is that app.fonts is reading system fonts, whereas appliedFont is reading the doc.fonts, which were activated and installed. The system fonts may not necessarily be installed, so it was failing ID, even with the try/catch. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

But the fonts placed within Document fonts folder are not installed too. Or, are as installed as the ones activated by font managers. Or am I wrong?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

Not entirely sure. Maybe ID installs them for use in the Document. Unsure of the specific mechanisms of how that works. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

Hi lf_corullon,

I ran your script snippet with the progress bar without any problems on my Windows 10 machine on InDesign 15.1.1.103.

Did two small changes:

[1] A potential error will be written to an array.

[2] Added an alert that checks for the length of the error array.

If 0 the alert states that no problem was found:

 

ScriptResult-1.PNG

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

The problem here is try/catch is not working. The script enters the try and stops if any error happen (don't going to the catch statement).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2020 Jul 25, 2020

Copy link to clipboard

Copied

LATEST

Hi there,

 

Thanks for reaching out. I hope your issue is resolved now. We'd appreciate if you can mark the appropriate answer correct.

If you used any other method, please share it here. It'll help other users having similar concern.

If you still have issues, let us know. We'll be happy to help.

 

Regards,

Ashutosh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines