TWPStyleCollection.SavetoFile

  • Hello

    I'm struggling to save the StyleCollection. I have set SaveToStreamFormat as wpSaveINIFormat. The application adds a line to the ini file of [WPTOOLS-STYLES]. The styles are not saved.

    What may I be doing wrong?

    Thanks.

    Rob.

  • Julian

    I can get that to work. Thanks.

    However, I am now trying to save to a CSS extension. This is the code:

    WPStyleDlg.Execute;
    // Get the styles from the Editor (that is where they are stored)
    WPStyleCollectionLetters.ReadStyles(RichText);
    //Save changes to the Styles Collection
    WPStyleCollectionLetters.SavetoFile(sAppPath + 'Letters.css');

    The application falls over on the last line with a message of 'We need EditBox to save CSS' from procedure TWPStyleCollection.SaveToCSSStream(Stream: TStream) in WPCTRStylecol.pas.

    The message speaks for itself, but RichText has been assigned to a TWPRichText. WPStyleDlg has got it's EditBox pointing to RichText.

    Where else to I need to specify RichText? Also, how come I can save to an ini file but not a CSS file?

    Thanks.

    Rob.

    • Offizieller Beitrag

    Hi,

    I tested with:

    Code
    WPStyleCollection1.SaveToStreamFormat := wpSaveCSSFormat;   WPStyleCollection1.ReadStyles(WPRichText1);   WPStyleCollection1.SaveToFile('c:\styles.css');

    and this object:

    The INI format is the native format for the StyleCollection (see the items in the ParStyles collection). The CSS format needs translation which is currently only available in the RTF-Engine.

    Julian

  • Julian

    I'm sorry to persist, but I'm still struggling with styles.

    I've gone back to saving to an ini file. In the OnCreate of the WP form I load the styles from the ini file into WPStyleCollectionLetters (a TWPStyleCollection) using the following code.

    WPStyleCollectionLetters.LoadFromFile(sAppPath + 'Letters.ini');

    When a new blank RichText is created as part of the Activation routine I have the following code.

    WPStyleDlg.EditBox := RichText;
    WPStyleCollectionLetters.Update(RichText.HeaderFooter.RTFProps);

    I assume the last line makes the styles in WPStyleCollectionLetters available to the RichText.

    I store the style names in a combo, select the text I wish to apply a style to and try and apply using the combo. When the combo changes I have the following line.

    RichText.CurrAttr.StyleName := dxBarComboStyles.CurText;

    The style is not being applied although in one instance I can get the number for the level to be added. The colour, font and font size is ignored.

    Contents of ini file is

    [WPTOOLS-STYLES]
    [WPTOOLS-STYLES]
    [Header 1]
    CharFont=Futura Hv BT
    CharFontSize=1200
    CharColor=clGray
    NumberStyle=3
    [Body]
    CharFont=Futura Lt BT
    CharFontSize=1000
    [TESTING]
    CharFont=Arial Black
    CharColor=clRed
    CharFontSize=1800


    Any help would be greatly appreciated.

    Rob.

    • Offizieller Beitrag

    Hi,

    >> The style is not being applied although in one instance I can get the number for the level to be added. The colour, font and font size is ignored. <<

    This is because they are defined by the text itself. Only undefined values are loaded from the attached style (or the parent TParagraph)

    If you want to override all character attributes you need to clear them, you can do so using:

    WPRichText1.TextCursor.CurrAttribute.BeginUpdate;
    WPRichText1.TextCursor.CurrAttribute.ClearAttr(true, true);
    WPRichText1.TextCursor.CurrAttribute.EndUpdate;

    You can also use the procedure
    WPRichText1.TextCursor.CurrAttribute.SetStyle

    with the number of the style.

    Julian Ziersch

  • Thanks Julian, I'm slowly getting there.

    There is still a little problem.

    I create a couple of styles, in this case using Futura HV BT and Futura LV BT fonts.

    I look at the ini file and they are there in the styles but they are being applied as Arial. Also, if I go to change them using the styles dialog they show as Arial, despite being saved correctly as Futura.

    Why might this be?

    Thanks.

    Rob.

  • Julian, forget my last post.

    I now realize that the styles are stored with the WPRichText and that meets my needs. I'll not be needing to use a StyleCollection.

    However, I have found a small problem. If I set the very first line to a particular style it changes as expexted on the WPRichText but the attributes for this line only are not being saved. The other lines attributes are saved.

    Rob.

    • Offizieller Beitrag

    Hi,

    >>I now realize that the styles are stored with the WPRichText and that meets my needs. I'll not be needing to use a StyleCollection. <<
    That's correct. It will usually not be needed.

    >>However, I have found a small problem. If I set the very first line to a particular style it changes as expexted on the WPRichText but the attributes for this line only are not being saved. The other lines attributes are saved.<<

    Which save format do you use?

    Julian