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.
Is there a way to get the count of text style ranges of a search or page item contents?
1 person found this helpful
to get the number of formatting switches, and (contrary to what I thought)
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
- "a " -- in a regular font
- "new" -- in an italic font
- " 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.