3 Replies Latest reply on Aug 7, 2009 7:20 AM by [Jongware]

    (AS) Trying to get character ranges for applied font styles in a paragraph.

    tictacmoose1

      The truth is I am trying to search for all the results of a particular paragraph style, copying that info into another document and making sure all the applied font styles come with it (ie. bolds, italics). Once I get a search result I cant seem to access where a certain font style is being used. So my thought process was to copy all the items found and paste that into the other document then go back and try to find the character ranges that a certain font style was being applied to then go back to the new document and apply the character style to those ranges. So if I am totally doing this the long way, I can really use your help. Its a very long document I am searching and I would hate to try to figure out what was bold or italic. Thanks for any help or direction.

        • 1. Re: (AS) Trying to get character ranges for applied font styles in a paragraph.
          [Jongware] Most Valuable Participant

          You are describing TextStyleRanges. For any valid selection of indesign formatted text (such as Search results), this array contains the properties from one part to the next. Adobe forgot to include a 'changed-this-into-that' property, so you'll have to examine just the FontStyle of each separate TextStyleRange.

           

          I.e., "This is bold and red text" contains 4 text styles: regular text, +bold, +bold and red, regular again -- the "Bold" does not automatically toggle off and on per next range.

           

          I found the first and last TextStyleRange may actually extend beyond the string you are examining, so some care is needed. If you searched the above sample string for "is bold", it may contain two text style ranges, the first containing the text "This is " and the 2nd "bold". This might be slightly CS-version dependent as well...

           

          I don't have a clue how to code it in AS -- hope it's of any use, nevertheless.

          • 2. Re: (AS) Trying to get character ranges for applied font styles in a paragraph.
            tictacmoose1 Level 1

            Is there a way to get the count of text style ranges of a search or page item contents?

            • 3. Re: (AS) Trying to get character ranges for applied font styles in a paragraph.
              [Jongware] Most Valuable Participant

              Absolutely.

              I experimented a bit in JavaScript, and given a returned Find Text array foundText[xx], you can safely use

               

              foundText[0].textStyleRanges.length

               

              to get the number of formatting switches, and (contrary to what I thought)

               

              foundText[0].textStyleRanges[0].contents

               

              returns, correctly, the first part of the text string in a certain text formatting. S'pose you have a source text (let's take a fairly random one )

               

              Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty ...

               

              and you searched for "a new nation". Then the found text will contain 3 text style ranges, containing

              1. "a " -- in a regular font
              2. "new" -- in an italic font
              3. " nation" -- regular again.

               

              The text style ranges are opaque in the sense it's not easily determined where it differs from its parent (paragraph) style, or from the next or previous text style range. If you remove the italics from the word 'new' and apply a character style instead (containing no formatting), it will still be a separate piece, without any special formatting (although you wouldn't know until you checked all possibilities).

              As I understand you are only interested in the font styles (bold, italic, both), just those should be easy to check.

              1 person found this helpful