FAQ: Go through the text and enlarge all text by +1

    • Offizieller Beitrag

    Q: This code does not work properly. It should go through the text and enlarge all text by +1. But it always starts with making all text size 1.

    Code
    procedure TForm1.IncTextSize;vari,l : Integer;begin WPRichText1.SelectAll; l:=WPRichText1.SelLength;  WPRichText1.SelLength:=0; i:=0; WPRichText1.CPPosition:=0; while i<=l do   begin   WPRichText1.CPAttr.BeginUpdate;   WPRichText1.CPAttr.Size:=Editor.CPAttr.Size+1;   WPRichText1.CPAttr.EndUpdate;   WPRichText1.CPMoveNext;   inc(i);  end; WPRichText1.Refresh;end;

    A: Instead of changing the font you can simply do this:

    WPRichText1.Resizing := WPRichText1.Resizing + 1;

    or, to permanently change the characters:

    Code
    var   i, jj : Integer;   ca : TWPCharAttr;begin  for j := 0 to WPRichText1.RTFData.RTFProps.Attributes.CharAttrCount-1 do  begin     WPRichText1.RTFData.RTFProps.Attributes.GetCharAttr(j, ca);     ca.Values[WPAT_CharFontSize] := ca.Values[WPAT_CharFontSize] + 10;     WPRichText1.RTFData.RTFProps.Attributes.OverrideCharAttr(j, ca);  end;

    This will only work for the character attributes, not the styles.

    For the styles do this:

    Code
    for j := 0 to WPRichText1.ParStyles.Count -1 do  begin     if WPRichText1.ParStyles[j].TextStyle.AGet(WPAT_CharFontSize, i) then        WPRichText1.ParStyles[j].TextStyle.ASet(WPAT_CharFontSize, i+10);  end;

    At the end don't forget

    Code
    WPRichText1.ReformatAll(true, true);