You are on page 1of 1

CHAPTER 2: Text Text formatting 65

the selection (using ITextAttributeSuite::CountParagraphStyles and


ITextAttributeSuite::CountCharacterStyles), and iterate through them (using
ITextAttributeSuite::GetNthParagraphStyle and ITextAttributeSuite::GetNthCharacterStyle).

To get the style from an arbitrary position in the story, navigate to the appropriate strand—either the
paragraph (kParaAttrStrandBoss) or character (kCharAttrStrandBoss) attribute strands. Obtain the
IAttributeStrand interface, which supports the IAttributeStrand::GetStyleUID method, returning the style
for a particular text position.

Sample code

See SnpManipulateTextStyle::UpdateParaStyle for an example of accessing the style at a given text index.

Obtaining the value of an attribute applied to text


You can access the single named attribute that applies to a text selection or a text index or range.

Solution

If you have a selection, obtaining the text attribute suite interface (ITextAttributeSuite) from the same boss
class as the text selection (ISelectionUtils::QueryActiveTextSelectionSuite) provides you with methods that
expose the state of a particular attribute (see ITextAttributeSuite::FeatureState). For example,
ITextAttributeSuite::GetCapsModeState indicates whether a certain mode applies to all the text, none of
the text, or some of the text (if the attribute changes along the selection).

To determine whether there is an attribute override, use ITextAttributeSuite::CountAttributes, passing in


the ClassID for the attribute of interest. An attribute is provided for each time the attribute value changes
across the range of the selection. ITextAttributeSuite::QueryAttributeN provides the set of attributes that
apply to the selection for a particular attribute class.

To get the attribute value from an arbitrary position in the story, use the IComposeScanner interface (on
kTextStoryBoss). The method IComposeScanner::QueryAttributeAt provides the attribute that applies to
the identified text index.

There is an iterator class (TextAttributeRunIterator) that allows the set of attributes that apply to a range of
text to be accessed, dealing with the changes in attributes that can occur across ranges.

Sample code

 See SnpApplyTextStyleAttributes::CycleSmallAllCaps for an example.

 See SnpInspectTextModel::InspectStoryPointSizes for an example of using a TextAttributeRunIterator


to access the attributes in a range of text.

Modifying the value of an attribute for text


You can modify an attribute applied to a text selection or text range.

You might also like