Low level insert text and set font sizes and colors

  • Soylent green? - about setting font sizes, colors

    I want three lines of text:

    Unfortunately, it doesn't become green, and all three lines use a large font. Any ideas what goes wrong?

  • With some help from Julian, I found out how to make this work:

    Julian asked me to give my explanation with my words, here it is (I hope it's correct!):

    WPTools 5 stores styles, character attributes etc. separately from the text (unlike the RTF format itself). Text is stored in RTFData, and all formatting is stored in the RTFProps attribute as seen in the code. When running rtf.ActiveText.RTFProps.AttrInterface.SetFontSize(txt1,24), it stores new information about txt1 in RTFProps.

    The mistake in the first code, that I presented, was that TParagraph.ASet doesn't do anything to TParagraph (as you might expect), but it modifies the information stored in RTFProps about that paragraph. Since all three paragraphs refer to the same layout info in RTFProps, they were all three affected by the .ASet() method.

    When using WPTools, it is important not to think in RTF-like manners, but instead to think in objects and how data is actually stored. If in doubt, look into the source code of WPTools (which should be bought if you run into trouble like this).

    Lars.

    • Offizieller Beitrag

    Hi,

    thanks for your post - I know that I am not always clear (or ever???) so it is good if somebody else writes, too.

    But I think I need to clarify:

    The RTFProps is an object which holds the paragraph styles, numbers styles, color palette, font array and also the records which describe the character attributes.

    Paragraph properties, such as indent etc are in fact stored in the paragraph itself. Character attributes are defined by an index only, an index into the array of character attribute records hosted by RTFProps.

    To modify a TWPCharAttr record the AttrInterface can be used.

    And why all this abstractation?

    In the general case you have a TWPRichText (or the ancestor) which uses its own RTFData which uses its own TWPRtfProp object. But sometimes it makes sense to let 2 TWPRichText work with one RTFDataCollection - to create and editor with split screen support.

    If you need to work with two texts simultaneously it is a big advantage if properties which are index based (such as fonts or colors) use the same index value for the same meaning (for example: font #3 is always courier). Here you would use 1 RTFProps object with 2 (or more) RTFDataCollection with 2 TWPRichText. In this case the same set paragraph styles (also identified by a simple number) are also used by all the texts.
    The WPReporter uses this feature. So if a style used by the template is changed the text in the created report will automatically change accordingly - without a recreation of the report!

    If you have ideas how to use this architecture in an application it would be great if you can post an answer here.

    Julian