How to change the fonttype properly? (use DevExpress Combo)

  • Hi,

    I'm using a DBWPRichText with DevExpress-TdxBarComboBox.

    To change the font of the selected text, I've added action "Fonttype" to the control.

    1: When selecting some text with the same fonttype, the control is clearing the description of the fonttype in the dxBarComboBox (not showing the current fonttype).

    2: The editor doesn't recognize the change of the font (nor fontsize) as a change in the database, so how do I set this up properly?

    Regards, Stef

    • Offizieller Beitrag

    Hi,

    The interface SelectedTextAttr will NOT report any font name if the selected text uses different fonts. In this case it is correct to do not show any font name.

    But it will also not report any font name if the fonts are (partly) not defined. Since wptools works with attribute inheritance (similar to HTML/CSS) this can happen frequently.

    The interface

    CurrAttr

    implements a workaround to report the default font in case of undefined fonts.

    So if you use CurrAttr.FontName it should work for the current and the selected fonts to update the combo.

    Julian

  • I've tried to implement the above, but didn't succeed till now.

    Could you please tell me which events must be used (and how) to get the appropiate behaviour?
    Please keep in mind that I use a DBWPRichText with DevExpress-TdxBarComboBox.

    Regards,
    Stef

  • Stef

    I use the following to show the font in a TdxBarComboBox The code is in the OnChangeSelection event.


    Code
    // Change the font combo and font size first
      frmReport.dxBarFontNameCombo1.Text :=  WPRichText1.CurrAttr.FontName;
      frmReport.dxBarComboFontSize.CurText := inttostr(Trunc(WPRichText1.CurrAttr.Size));


    Rob.

  • Thank you.

    Only the first line of code is sufficiënt.
    When using the second line it is changing the size of selected text to one size just by selecting it (though the selected text contains two different fontsizes). Maybe that is because I use for both items a dxBarComboBox.

  • After some more testing I discovered that, the described behaviour also applies to selecing text with two different fonts.
    It is changing the fonttype of selected text to one type just by selecting it (though the selected text contains two different fonttypes).

    Could that be related to the dxBarComboBox?

  • What I need is the following:

    1. When selecting some text with the same fonttype, the control will show the description of the fonttype in the dxBarComboBox.

    2. When selecting some text with both defined and undefined fonttypes, the control will show the description of the defined fonttype in the dxBarComboBox.

    3. When selecting some text with two different defined fonttypes, the control will show no description in the dxBarComboBox.

    Please keep in mind that I use a TDBWPRichText component.

    One more question:
    How to make sure that text in the editor will always be defined, aspecially when typing new text directly into the editor.

    • Offizieller Beitrag

    Hi,

    WPRichText1.CurrAttr.FontName

    is a simplified property. It will display a font even if currently there is a) no font defined (using default font) or b) different fonts are active in selection.

    In my code I use a more complicated approach which uses the new WPTools 5 Attribute Interfaces (SelTextAttr and WritingTextAttr)

    The code is in unit WPCtrRich.PAS:

    if IsSelected then
    begin
    if not SelectedTextAttr.GetFontName(fnt) then
    fnt := ' ';
    FToolBar.UpdateSelection(wptName, fnt, 0);
    end else FToolBar.UpdateSelection(wptName, CurrAttr.FontName, 0);

    Here the WPToolBar is updated.

    In this code the combo is updated using CurrAttr.FontName if no text is selected, othewise the SeletectedTextAttr.GetFontName function(!) is used. That function returns FALSE if the selection uses different fonts.

    You can convert this code to DX as

    Code
    if WPRichText.IsSelected then
        begin
            if not WPRichText.SelectedTextAttr.GetFontName(fnt) then
               fnt := '  ';
            dxBarFontNameCombo1.Text :=  := fnt;
        end 
        else dxBarFontNameCombo1.Text := WPRichText.CurrAttr.FontName;
    Zitat

    2. When selecting some text with both defined and undefined fonttypes, the control will show the description of the defined fonttype in the dxBarComboBox.

    I don't see a chance to do that - undefined + defined = undefined in the SelectedTextAttr.

    Zitat

    How to make sure that text in the editor will always be defined, aspecially when typing new text directly into the editor.

    When loading RTF text the fonts which equal the default fonts are removed. If you dio not like this handling (it is required for proper paragraph style operation) you can disable this using the compiler define DONT_FIX_DEFSTYLE (used by WPIOReadRTF)

    When typing RTF text the property WriteTextAttr is used. Here you can check with GetFontName if one is defined. OnClear is a good event to initialize this interface.

    Regards,

    Julian Ziersch

    • Offizieller Beitrag

    >>Can you tell me where I can set: define DONT_FIX_DEFSTYLE ?

    IDE Menu, Project Options, Conditionals,
    entere there and do a BuildAll

    >>And also how to use the property WriteTextAttr with checking GetFontName.

    var f : string;
    if not WP.WritingTextAttr.GetFontName(f) then
    WP.WritingTextAttr.SetFontName('Arial');

    >>OnClear is a good event to initialize this interface???

    OnClear is a published event of TWPRichText

  • Hi Julian,

    Below you find some code that I've added to the OnChangeSelection of a TDBWPRichText (as you suggested).

    When text is selected and it is the default font, then the FontNameCombo will not show this font.
    Is there a way to show the default font also when it is selected? And at the same time NOT show any font in the FontNameCombo, when the selected text contains multiple fonts.

    procedure TFDossierTypes.WPTEditorTypesChangeSelection(Sender: TObject);
    var fnt : TFontname;
    begin
    if WPTEditorTypes.IsSelected then
    begin
    if not WPTEditorTypes.SelectedTextAttr.GetFontName(fnt) then
    fnt := '';
    FontNameCombo.Text := fnt;
    end else
    FontNameCombo.Text := WPTEditorTypes.CurrAttr.FontName;
    end;

  • Hi Julian,

    My problem is still not solved with version 5.20.5.

    When I select text only the default font is showing in the fontnamecombobox, other fonts are always blank.
    Also the fontsize is never mentioned when I select text.

    Please solve this problem a.s.a.p. as it is such basic functionality for any wordprocessor.

    Regards,
    Stef

    • Offizieller Beitrag

    Hi,

    I made a mistake when testing the change. Infact it worked - sometimes - but qwhen developing a test app I found out that selected text which used a font always reported a NULL font. I had to reports V5.20.5 - also to the chance to include a change to make it work with C++Builder 2006 Update 2. (I had to wait for German release of the update.)

    My demo is using a simple combo box "mbLettertype".

    Its uses this code:

    Now it appears to work.

    Julian