About Character attributes and paragraph styles

    • Offizieller Beitrag

    Q: I don't see the character attributes defined in a paragraph style:

    A: The Style concept of WPTools is much more robust than in Version 4. But on the other hand it also locks any attribute which is defined at a higher level.

    You can understand the text attributes to be virtual attributes of the TWPTextStyle. This attributes can be overridden in the paragraphs. The characters itself can also override some of the attributes (the first 15).

    To set an attribute usually ASet( WPAT_..., value ) is used. This works for the TWPTextStyles and the TParagraphs. For the characters the provided interfaces (WPRichText.WritingAttr for example) or WPRichText.TextCursor.CurrentAttr has to be used. There are other 'A' function, ASetColor, ASetAddCharStyle etc.

    To clear the current writing mode use
    WPRichText1.WritingAttr.Clear;

    After "Clear" any text which is typed or inserted using InputString is displayed with the attributes defined in the paragraph or the attached text style.

    Q: When reading the attributes, for example to display in toolbar, I don't get the attributes from attached styles

    A: When reading the current attributes the interfaces WPRichText.WritingTextAttr and WPRichText.SelectedTextAttr can be used. WPRichText.TextCursor.CurrentAttr selects automatically the first or the second if text is currently selected.

    Unless the flag wpDontInitSelTextAttrWithDefaultFont was set in property EditOptionsEx, the interface SelectedTextAttr will report the default attributes when the selected text does not define a certain attribute. (Note: WPTools 5 differentiates between defined and undefined, = null attributes.)

    In case an attribute is not defined, SelectedTextAttr will report false in the respective "Get" function. In this case you can read the attribute from the current paragraph, i.e. WPRichText1.ActiveParagraph.AGetInherited( WAPT_Alignment, value ) will assign the alignmetn to the variable "value" or return false if the property was not found in the paragraph or an attached style sheet.

    Note: The interface TWPRichText.CurrAttr works on a higher level than SelectedTextAttr and WritingTextAttr. It uses properties instead of Get and Set method and so it does not differentiate between undefined properties and properties with the value 0 (for indents for example).