2

(Delphi XE4 / Win 7)

The TRichEdit component behaves strangely when both Western and Asian characters are to be displayed. Demo program (form, listbox, richedit with default setting from Object Inspector; Asian chars copied from a japanese website):

unit Unit1;

interface

uses
  System.Classes, Vcl.Forms, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.Controls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  arText: array[0..4] of string
        = ('00  AbC DEfgH  查找的资  AbC DEfgH  查找的资',
           '01  前大  ABCabc  為島  ABCabc  或繩  ABCabc',
           '02                  AbC DEfgH  繩最  ABCabc',
           '03  ABCabc  全面積  ABCabc  全面積  ABCabc',
           '04  方公里  AbC DEfgH  方公里');

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i:=0 to 4 do
  begin
    ListBox1.Items.Add(arText[i]);
    RichEdit1.Lines.Add(arText[i]);
  end;
end;

end.

Demo running:

In the listbox all Western characters have the correct and same size. In the richedit, however, Western chars are only displayed correctly if there are no Asian chars in front of them. Otherwise, all following western chars are displayed with a reduced size.

Note: If you edit the text while the program is running, inserted Western characters will be displayed with the correct size - regardless of the position where they are inserted (inserted characters marked red):

Is there a way to correctly display the text from Western and Asian letters in a richedit? What needs to be done to make it work? Thanks in advance for any help!

uliF
  • 31
  • 2
  • Find a font with glyphs for all characters you need (Arial Unicode MS?) and use it for the entire text? – Andreas Rejbrand May 24 '20 at 12:22
  • No, same look. Note that the default font for TListBox works perfectly (see screenshot). And in the richedit it's just the char size that is sort of messed up. – uliF May 24 '20 at 12:36
  • 3
    No, there are clearly two different fonts involved for the Latin words. One is a serif and the other a sans serif. Try selecting all text in the Rich Edit and setting the `SelAttributes` font name to `Arial Unicode MS`. It might be that the Rich Edit control chooses to change font mid-line to accommodate the need for glyphs. (After all, the Rich Edit control is a rich-text editor.) – Andreas Rejbrand May 24 '20 at 12:39
  • Or, if you don't need the Rich Edit control's capabilities, use a simple `TMemo`. Then you will certainly get a single font. – Andreas Rejbrand May 24 '20 at 12:45
  • Seems my eyes are too old - never noticed the serifs at the downsized letters. Shame on me! – uliF May 24 '20 at 12:58
  • Sorry, don't know what went wrong earlier with Arial Unicode MS (not only my eyes are too old...). With this font the char size is correct (but not the line spacing, but this can be "fixed"). Thanks a lot! – uliF May 24 '20 at 13:23
  • uliF: No problem! – Andreas Rejbrand May 24 '20 at 13:24
  • Still curious whether there is a way to fix this without installing a "special" font... – uliF May 24 '20 at 13:26

0 Answers0