6 Replies Latest reply on Apr 18, 2008 3:42 AM by Peter Kahrel

    [CS3 JS] Correcting a Character Style Anomaly

      It used to be that you could define a character style to merely colour the text and give it an underline (e.g. for Hyperlinks) or just superscript the text (for Reference citations). When such styles, which do not call for a particular font or font size, are placed into InDesign CS, the styled text would take on the font and font size of the underlying paragraph style. However, after placing a Word .doc with these styles into a CS2 template, the font and font size becomes Times New Roman and 10 pt. The solution was to save an .rtf file and re-import the text. Now, in CS3 this work-around doesnt quite work: the font is okay, but the font size reverts to that default size of 10 pt.

      So, I would like a script that finds all occurrences of two specific character styles (Hyperlink and bibref) and then corrects the font size of the found text to that of the underlying paragraph style. These styles can appear anywhere within a document, including in tables. I have trawled through this forum and found enough to be able to search for the character styles, but I cannot fathom how to apply the font size of the underlying paragraph style. Any help will be greatly appreciated.

      By the way, re-applying the character styles doesnt work because the character styles dont define the font size; also clearing the overrides on the paragraph style while the text is selected isnt a viable solution, because other local formatting (i.e. italic) would be lost.
        • 1. Re: [CS3 JS] Correcting a Character Style Anomaly
          Peter Kahrel Adobe Community Professional & MVP
          What you need to do is to blank the fields for point size etc.:

          with (app.activeDocument.characterStyles.item ('bibref'))
          {
          appliedFont = NothingEnum.nothing;
          fontStyle = NothingEnum.nothing;
          pointSize = NothingEnum.nothing;
          }

          Peter
          • 2. Re: [CS3 JS] Correcting a Character Style Anomaly
            Level 1
            Hi Peter

            Thank you very much for your quick response. I tried your script and it did as you intended by clearing the Font, Font Style and Point Size in the character style, but unfortunately it did not correct the problem of the style becoming some default style and size (Times New Roman 10 pt) when placed into ID.

            In fact, I had already set up the 'bibref' and 'Hyperlink' character styles with these fields blanked out. Also, I made Adobe aware of this bug when CS2 came out and they warned me that CS3 wouldn't fix the problem; but I didn't realize that CS3 would be worse than CS2 so that using an rtf file wouldn't fix things.

            So, I am left with my initial query: is it possible to write a script to search for the character styles in question and apply the font size of the underlying paragraph style?

            Thanks a lot for any help you can give.
            • 3. Re: [CS3 JS] Correcting a Character Style Anomaly
              Peter Kahrel Adobe Community Professional & MVP
              It could be the case that there is some local formatting. After you use the script, try removing local formatting (Alt/Opt+click on the stylename in the UI). If that works, and if it's possible to remove local formatting, you can script that as well. First let's see if removing local formatting makes a difference.

              Peter
              • 4. Re: [CS3 JS] Correcting a Character Style Anomaly
                Level 1
                Hi Peter

                No that doesn't work. Because there is no font or font size described in the character style. What does work is to clear the overrides in the underlying paragraph style, but that is not a good solution for me because in some Hyperlinks we might have italic text, which would also be overridden.

                Thanks so much for your quick replies by the way. I wasn't expecting that.

                SImon
                • 5. Re: [CS3 JS] Correcting a Character Style Anomaly
                  Peter Kahrel Adobe Community Professional & MVP
                  Simon,

                  I can't reproduce this. If you send me one of your troublesome files I'll take a look (click my name in this message to see my email address).

                  Peter
                  • 6. Re: [CS3 JS] Correcting a Character Style Anomaly
                    Peter Kahrel Adobe Community Professional & MVP
                    This in the end fixed Simon's problem:

                    #target indesign;

                    charstyles = ['bibref', 'Hyperlink'];

                    app.findGrepPreferences = null;

                    for (i = 0; i < charstyles.length; i++)
                    reset_charstyle (charstyles[i]);

                    function reset_charstyle (cs)
                    {
                    app.findGrepPreferences.appliedCharacterStyle = cs;
                    var f = app.activeDocument.findGrep();
                    for (var j = 0; j < f.length; j++)
                    f[j].pointSize = f[j].appliedParagraphStyle.pointSize
                    }

                    Simon thinks that this problem occurs on PCs but not on Macs.

                    Peter