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

InDesign script returns wrong value for paragraphStyle.fontStyle

Participant ,
Apr 05, 2024 Apr 05, 2024

Copy link to clipboard

Copied

I’m analyzing layouts, to find all fonts, we can’t use (license does not allow online-PDFs).

To make it less likely a problematic font is used again later on, I also want to find fonts, that are only defined in a style (even if they are not actually used). 

 

Generally this works fine, but unfortunately in some cases InDesing does report back wrong font styles (e.g. Book, instead of Regular). Font family names are always correct. 

 

———

 

My function to read paragraph styles looks something like this (simplified): 

 

 

function get_paragraph_style_fonts(doc){
    var p_styles = doc.allParagraphStyles;

    for(var i=0; i<p_styles.length; i++){
        var this_style_name = p_styles[i]['name'];
        var this_style_font_style = p_styles[i]['fontStyle'];
        
        alert(this_style_name + "\n" + this_style_font_style);
}

 

 

In the Layout my paragraph is set to Strada OT Regular:

 

para_style.jpg

 

 

 

 

 

 

 

 

 

 

 

 

But for whatever reason, the script shows it as Strada OT Book:

 

script_result.png

 

 

 

 

 

 

 

 

 

 

There is no GREP-style or nested format (I hope, this is the correct englisch term) interfering. 

 

I tried the following without any success:

  • duplicate / rename the format 
  • remove format and creating a new one from the styled text
  • export to IDML and reimport

 

The only thing, that removes the problem is to manually change the font style (e.g. from Regular to Medium), close the paragraph style dialog and then reset the font style to Regular. After this process, the function correctly alerts Strada OT Regular.

 

Unfortunately, this is no solution to my problem, as it can only be done manually (I can’t change the font style by script, because from the script I don’t know the font style to reset it properly).

 

———

 

I also had a look at the IDML file:

Although the font style is displayed correctly in InDesign (before export to idml and after reopening the IDML), in the IDML it is listed as Book. The only connection to Regular I can find is the parent style [No paragraph style]. This style indeed uses Regular. 

 

Here’s a screenshot of the IDML:

 

idml.png

 

———

 

This does not happen all the time, but regularely.

It is not only this document and not only this font. 

 

———

 

Does anybody have an idea, what’s going on?

Is this an InDesign bug (I think so)?

I there a way around this?

 

I can also ignore this, my script is still helpfull, but I would like to understand, whats going on. 

– And of course in the best cas fix the issue.

 

Best regards,

Martin 

TOPICS
Scripting

Views

307

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

Guide , Apr 09, 2024 Apr 09, 2024

Looking at the document from a plug-in, slightly simplified:

Fonts are specified as pair of attributes. In text, in text defaults, in styles.

One attribute specifies the font family, the other specifies the font style.

IDML is closer to that than other scripting.

When you choose a font from the big font menu, you change those two attributes.

The font family "Strada OT" as remembered in the document has 15 faces, each matching a different font style. "Book" is not among those.

The "wrong" paragraph sty

...

Votes

Translate

Translate
Community Expert ,
Apr 05, 2024 Apr 05, 2024

Copy link to clipboard

Copied

Hi @C330 S, can you isolate the offending style/element into a small demo document and post it? Perhaps it is a bug, but there is a lot to rule out first.

- Mark

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
Participant ,
Apr 08, 2024 Apr 08, 2024

Copy link to clipboard

Copied

Hi @m1b, thanks for your reply! I attached an demo document (as indd and as idml, both cc2019).

The file contains two paragraph styles, one with the error, one without (solved by changing the font style twice).

Unfortunately I can’t change the font family to some default font, as this would remove the problem. 

I’m also attaching the script, that shows the problem (sorry for debugging by alert). 

 

---

 

I found some more strange things: 

 

When I check ParagraphStyle.appliedFont.status, I get:

  • installed, if font is installed in the system or available through /Library/Application Support/Adobe/Fonts/
  • not available, even if the font is actually available through ›Document fonts‹ folder
    (in this case the UI shows no error at all)

 

ParagraphStyle.appliedFont returns either a string, or a Font-object. 

The Font object itself has a property fontStyleName, that can return the correct font style (e.g. Regular).

 

This works only if InDesign thinks, the font is available.
In this case, I get the correct font name through ParagraphStyle.appliedFont.fontStyleName

ParagraphStyle.fontStyle still can return garbage. 

 

This way, I can (mostly) work around the issue. 

 

---

 

It would still be to know more about this problem. 
It would be especially good to know, if it can be fixed, preferably in the documents.

 

The root cause for the issue seems to be some kind of corruption in my documents. 

This is something, that makes me a little nervous. 

 

Best regards, 

Martin 

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
Guide ,
Apr 09, 2024 Apr 09, 2024

Copy link to clipboard

Copied

Looking at the document from a plug-in, slightly simplified:

Fonts are specified as pair of attributes. In text, in text defaults, in styles.

One attribute specifies the font family, the other specifies the font style.

IDML is closer to that than other scripting.

When you choose a font from the big font menu, you change those two attributes.

The font family "Strada OT" as remembered in the document has 15 faces, each matching a different font style. "Book" is not among those.

The "wrong" paragraph style, similar to the IDML screenshot, specifies a font style "Book" though. InDesign has some hard wired font style names that it considers more or less equivalent. Therefor missing "Strada OT\tBook" via fallback ends up at "Strada OT\tRegular".

 

Let's try to reconstruct such a mishap.

Create a paragraph style "base" using a font that has "Book" and another font style, using the latter.

Create a second paragraph style "wrong", based on "base", using the same font family but now using "Book".

Font family is same so it is optimized away. Font style is stored locally.

Change paragraph style "base" to use Strada, the "wrong"will follow with the family but stick to "Book".

Hmm, leaves "wrong" still without the family attribute, even though the effect should be the same. "Strada OT\tBook".

 

Another attempt: Your paragraph style "wrong" initially has "Strada OT\tRegular".

A character style "Book" applies the font style, but not the font family.

Apply both styles to an entire paragraph.

Character Style Flyout Menu  >> Break Link To Style; produces an override with the font style.

Redefine the paragraph style, so that it picks up the "Book" font style override.

See, my "Strada wrong" is now referring to some random "ExtraLight-194.286" that I chose for the character style.

Ohne Titel.png

Note that the Character panel (without the character style) is not so generous with choices for the font style, thus my convoluted way to produce the override picked up by redefine.

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
Participant ,
Apr 09, 2024 Apr 09, 2024

Copy link to clipboard

Copied

LATEST

@Dirk Becker wow, this is amazing! Thank you very much! I could reproduce both scenarios. 

 

When a collegue of mine suggested, InDesign might consider Book and Regular to be the same(ish), I said to him Adobe wouldn’t do something like this. But of course they do…

 

I think in such a scenario, it would be better, to keep the font style, even if the new combination in the paragraph style would become meaningless. In most cases this is exactly, what happens: If I combine Arial + Condensed the way you described, I get an paragraph style with (non-existent) Arial Condensed. 

 

However, this means, my documents aren’t really corrupted, they just ›remember‹ the old font style and rely on the baked in assumption that Book and Regular are mostly the same. 

 

I think, if the font is actually installed, I could even update the ›wrong‹ font style. 

(I’m not sure, if I want to.)

 

Best regards, 

Martin

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