RvFontCombobox behavior with multiple fonts

General TRichView support forum. Please post your questions here
Post Reply
tomr
Posts: 50
Joined: Wed Dec 09, 2020 9:36 am

RvFontCombobox behavior with multiple fonts

Post by tomr »

Hello RichView Support,
I have a question regarding the behavior of the RVFontComboBox.

In Microsoft Word, when selecting text that contains two or more different fonts, the font combo box appears empty, indicating mixed formatting.
Verhalten in Word.png
Verhalten in Word.png (8.85 KiB) Viewed 332 times
In RichView, however, when I replicate this scenario, one of the fonts is always displayed instead. The selected font depends on the direction of the selection:
  • When selecting from top to bottom, the last font is shown.
Top to Bottom.png
Top to Bottom.png (24.01 KiB) Viewed 332 times
  • When selecting from bottom to top, the first font is shown.
Bottom To Top.png
Bottom To Top.png (22.3 KiB) Viewed 332 times
Is there a way to replicate the behavior of Microsoft Word, so that the combo box indicates mixed fonts instead of displaying a single one?

Kind regards,
Tom
standay
Posts: 335
Joined: Fri Jun 18, 2021 3:07 pm

Re: RvFontCombobox behavior with multiple fonts

Post by standay »

I used this code to do something like that:

Code: Select all

var
  fi, fi2: TFontInfo;
  i, FStart, FSOff, FEnd, FEoff: integer;
  rv: TCustomRichViewEdit;
 ...
 
  rv.GetSelectionBounds(FStart, FSOff, FEnd, FEoff, true);
  fi := rv.Style.TextStyles[rv.GetItemStyle(FStart)];
  
  for i := FStart to FEnd do
    begin
      fi2 := rv.Style.TextStyles[rv.GetItemStyle(i)];
      if fi.FontName <> fi2.FontName then
      begin
        cmbFontName.Text := '[Multiple]'; //or you could set to nothing
        break;
      end;
    end;
As far as I know, there's no other way other than to spin through your selection (you might have a different font in the middle of the selection, not just at the start or end). Keep in mind if you have a huge file and select it all, this can be slow. I stopped using it as I decided I didn't need it.

Stan (not with richview, just a user)
Sergey Tkachenko
Site Admin
Posts: 18083
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RvFontCombobox behavior with multiple fonts

Post by Sergey Tkachenko »

These combo-boxes display the font of the current text style.
Yes, it was done for performance reasons.
tomr
Posts: 50
Joined: Wed Dec 09, 2020 9:36 am

Re: RvFontCombobox behavior with multiple fonts

Post by tomr »

Hi,
Thank you both for your responses.
I will keep it that way then.
tomr
Posts: 50
Joined: Wed Dec 09, 2020 9:36 am

Re: RvFontCombobox behavior with multiple fonts

Post by tomr »

Sergey Tkachenko wrote: Sun Mar 22, 2026 6:13 pm These combo-boxes display the font of the current text style.
Yes, it was done for performance reasons.
Hi Sergey,
As you mentioned the current text style, I'm reporting a bug that can be reproduced in the demo.
Please enter the following text:

This is a text. This is another sentence
This is a new line
Ausgangssituation.png
Ausgangssituation.png (14.44 KiB) Viewed 54 times
Now select "another sentence" and change the font (I used Webdings).
Change Font.png
Change Font.png (14.88 KiB) Viewed 54 times
Font Changed.png
Font Changed.png (3.53 KiB) Viewed 54 times
After that, select the entire text. The font combo box will display the default font.
Change Font Back.png
Change Font Back.png (11.71 KiB) Viewed 54 times
Now click into the font combo box and press Enter. As a result, the entire text changes to Webdings.
Change Font After Enter.png
Change Font After Enter.png (9.8 KiB) Viewed 54 times
Shouldn’t it revert to the default font instead?
Post Reply