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
if WPRichText.IsSelected then
begin
if not WPRichText.SelectedTextAttr.GetFontName(fnt) then
fnt := ' ';
dxBarFontNameCombo1.Text := := fnt;
end
else dxBarFontNameCombo1.Text := WPRichText.CurrAttr.FontName;
- 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.
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