How to strip font attributes

  • Hi + tx for an answer:

    I use a TDBWPRichText to let the user create RTF text elements. My app merges These elements together. However, sometimes I want to have the final rtf to have only one font, not the individual fonts of the elements.

    So how do I remove all Arial 10 pt from my RTFs and - if necessary - reaplace it by Tahoma 8 pt?

    tx Bernd

    • Offizieller Beitrag

    Hi,

    If you do a SelectAll you can can use CurrAttr to apply a certain font to the complete text or change the size.

    To remove a certain font you need to go through the complete text and check all character attributes.


    par := WPRichText1.FirstPar;
    while par<>nil do
    begin
    for i := 0 to par.CharCount-1 do
    begin
    WPRichText1.AttrHelper.CharAttr := par.CharAttr[i];
    if WPRichText1.AttrHelper.GetFontName(s) and SameStr(s,'Arial')
    and WPRichText1.AttrHelper.GetFontSize(size) and (size=10)
    then
    begin
    WPRichText1.AttrHelper.SetFontName('Tahoma');
    WPRichText1.AttrHelper.SetFontSize(8);
    par.CharAttr[i] := (par.CharAttr[i] and $FF000000) or
    WPRichText1.AttrHelper.CharAttr;
    end;
    end;
    par := par.next;
    end;