Skip to main content
xavixanxe
Inspiring
September 14, 2019
Answered

FontFamily name not working on create new paragraph style

  • September 14, 2019
  • 6 replies
  • 752 views

Hi everyone, 

I'm trying to create a new paragraph style with the font family Avenir LT Std, but I think it does'nt work because of the spaces in the font family name, so I tried to do it in the same way with Harting font and it worked fine. Any idea about how scaping spaces and if it's suposed to be needed?

I tried also using app.fonts.item("Avenir LT Std") but it didn't work neither. If I make an alert with app.fonts.item("Avenir LT Std").fontFamily it shows correctly font name, but not working if I put that as the style fontFamily property. 

This is the code I'm trying to use: 

 

            newStyle = doc.paragraphStyles.add({name:"header",
                                                appliedFont : "Avenir LT Std",
                                                fontStyle : "55 Roman",
                                                pointSize : 16});

 

Thanks for your help.

This topic has been closed for replies.
Correct answer Sajeev Sridharan

Try this,

 

app.activeDocument.paragraphStyles.add({name:"header", appliedFont : "Avenir LT Std\t55 Roman", pointSize : 16});

6 replies

xavixanxe
xavixanxeAuthor
Inspiring
September 16, 2019

It does. 

Thanks a lot.

Community Expert
September 16, 2019

Wheras this indeed is working, if the font is available:

var myFontNameString = "Avenir LT Std" +"\t"+ "55 Roman";

var doc = app.documents[0];
var newStyle = doc.paragraphStyles.add
(
	{
		name:"header",
		appliedFont : myFontNameString,
		pointSize : 16
	}
);

 

Regards,
Uwe Laubender
( ACP )

Community Expert
September 16, 2019

Hi xavixanxe,

ok, then my assumptions were wrong.

I cannot explain why the following code will throw an error even if myFont.isValid returns true:

 

var myFont = app.fonts.itemByName( "Avenir LT Std" );

var doc = app.documents[0];
var newStyle = doc.paragraphStyles.add
(
	{
		name : "header",
		appliedFont : myFont,
		pointSize : 16
	}
);

 

Regards,
Uwe Laubender

( ACP )

 

xavixanxe
xavixanxeAuthor
Inspiring
September 16, 2019

Hi Laubender, 

Thanks for your answer.

First sentence returned "true", second one returned "false".

Avenir is a font we use a lot, it's installed in all computers in the office.

Wich is the difference between my initial code and Sajeev proposal? We both use same font, don't we? 

 

 

Community Expert
September 16, 2019

appliedFont : "Avenir LT Std"

 

Hi xavixanxe,

my take on this is: It does not work because

 

app.fonts.itemByName("Avenir LT Std").isValid or

app.documents[0].fonts.itemByName("Avenir LT Std").isValid

 

will both return false instead of true.

 

FWIW: You may have noticed that you cannot add a new paragraph style with a font that is not available.

E.g. not installed with the system or made available through a Document fonts folder.

 

Regards,
Uwe Laubender

( ACP )

 

 

Sajeev SridharanCorrect answer
Legend
September 14, 2019

Try this,

 

app.activeDocument.paragraphStyles.add({name:"header", appliedFont : "Avenir LT Std\t55 Roman", pointSize : 16});

xavixanxe
xavixanxeAuthor
Inspiring
September 14, 2019

It worked!

It would be nice a brief explanation about why it works this way and it doesn't in the other way. Paragraph style has both properties, fontFamily and fontStyle, doesn't it? Have spaces in the font name something to do with all this? 

 

Thanks so much!