TWPBlockAttribute Styles Question

  • I have been trying to figure out how to do the following and can't seem to figure it out. I would like to be able to tell if the selected text contains a font style (ex Bold), does not contain that style, or contains and doesn't not contain it. I have been trying to use TWPBlockAttribute with the InStyle and ExStyle, but can't seem to figure it out.

    example:

    This is a test.=>No Bold
    This is a test.=>Bold
    This is a test.=>Both

    Thanks for any help you can provide.
    :D

    • Offizieller Beitrag

    Hi,

    When you open unit WPRich.PAS you will find

    Code
    function TWPCustomRichText.FontSelect: Boolean;var  FontDialog1: TFontDialog;  BlockAttr: TWPBlockAttribute;begin  Result := FALSE;  if Changing then  begin    FontDialog1 := nil;    try      FontDialog1 := TFontDialog.Create(Self);      if Printer.Printers.Count > 0 then        FontDialog1.Device := fdPrinter;      if Memo.Selected then      begin        Memo.GetBlockAttr(BlockAttr, TRUE);        // Also assigns the asttributes to 'Attr'        if BlockAttr.FontDiffers then          FontDialog1.Options := FontDialog1.Options + [fdNoFaceSel];        if BlockAttr.SizeDiffers then          FontDialog1.Options := FontDialog1.Options + [fdNoSizeSel];      end;      FontDialog1.Font.Assign(UpdateFontValues);      if FontDialog1.Execute then      begin        ApplyFont(FontDialog1.Font);        Changed;        Result := TRUE;      end;    finally      FontDialog1.Free;    end;    Changed;  end;end;

    BlockAttr is defined as

    To solve your problem you need to check InStyle and ExStyle.
    A flag in InStyle is set when the style is defined, in ExStyle it is set when it is cleared.

    So if afsBold is set in both variables this means "both"

    Julian

  • I have tried this, but on all the versions of WPTools 4 that I have, if ANY part of the selection contains BOLD, I get:

    InStyle.Contains(afsBold) == true
    ExStyle.Contains(afsBold) == false

    I have yet to find any way to get it to give me:

    InStyle.Contains(afsBold) == true
    ExStyle.Contains(afsBold) == true

    Please help me with this. Is there another option somewhere else that could affect this? Is this a bug?

    Thanx. :lol:

    • Offizieller Beitrag

    Hi,

    Those two variables are initialized using a loop (pointer pa) over the attributes of all selected characters:

    Code
    BlockAttr.InStyle := BlockAttr.InStyle + pa^.Style;
              BlockAttr.ExStyle := BlockAttr.ExStyle - pa^.Style;


    ExStyle is initialized with all styles set.

    This means ExStyle.Contains(afsBold) == false is correct if a single afsBold was used. It must be used with not or '!'.

    My post "A flag in InStyle is set when the style is defined, in ExStyle it is set when it is cleared." was somewhat incomplete, it should read

    A flag in InStyle is set when the style is defined for one or more characters, in ExStyle it is set when it is clear in all characters.

    Julian