various fonts in TRichEdit

I need to use various fonts for various parts of text in TRichEdit, Delphi Tokyo. For part of the text I need 'Times New Roman' and for the other 'Symbol'. So far does not work what I tried. Either font is set the samo for the whole text or my selected character does not show up.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manuel Lopez-MichelonePhD candidateCommented:
I wrote a chess editor, to make easy to write chess diagrams. There are a lot of public domain chess fonts to use. I dont have Tokio´s version of Delphi, but I think the way the richedit component is still the old richedit since Delphi 7 at least. In my editor I simple add a button to change the font:

procedure TForm2.Fuente1Click(Sender: TObject);
begin
  if FontDialog1.Execute then
    with RichEdit1, FontDialog1 do
    begin
      SelAttributes.Name := Font.Name;
      SelAttributes.Size := Font.Size;
      SelAttributes.Color := Font.Color;
      SelAttributes.Pitch := Font.Pitch;
      SelAttributes.Style := Font.Style;
      SelAttributes.Height := Font.Height;
    end;
end;

Remember to add a fontDialog component as well. if still have problems, I can send all my code so you can figure out if is Tokio´s version or some simple error in your approach.
regards
Lopem
Mariusz JędrzejowskiAuthor Commented:
So far almost everything seems to work, but when I set the "pitch" to fpfixed the characters appear as having variable width for each font I tried.
Manuel Lopez-MichelonePhD candidateCommented:
I am not a truetype expert but I guess you can't set pitch to fpfixed to any font you like. In computer fonts you have proportional and non-proportional fonts. The non-proportional fonts are the ones with pitch fixed. The proportional fonts use different spaces points between letters (glyphs)

For instance, Courier New is a non-proportional font, but Times Roman its a proportional one. Is a property of a font and I dont think you can change them. Please, check https://en.wikipedia.org/wiki/Monospaced_font

regards,
Lopem
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Mariusz JędrzejowskiAuthor Commented:
I Tried "Courier New"and also other monospaced fonts, in vain.
Bez-tytu-u1.png
Bez-tytu-u.png
Geert GOracle dbaCommented:
how do you add it ?
fonts in richedit
procedure TForm1.AddText(msg: string; aFontName: string = ''; aFontSize: integer = 0; aFontColor: TColor = clBlack);
var re: TRichEdit;
begin
  re := RichEdit1;
  re.SelStart := Length(re.Text);
  re.SelLength := 0;
  if aFontName <> '' then
    re.SelAttributes.Name := aFontName;
  if aFontSize <> 0 then
    re.SelAttributes.Size := aFontSize;
  if aFontColor <> clBlack then
    re.SelAttributes.Color := aFontColor;
  re.SelText := msg;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  AddText('This is a piece of text in Courier new'#$D#$A, 'Courier New', 10, clRed);
  AddText('This is a piece of text in Times New Roman'#$D#$A, 'Times New Roman', 8, clGreen);
  AddText('This is a piece of text in Harlow Solid Italic'#$D#$A, 'Harlow Solid Italic', 14, clBlue);
end;

Open in new window

Mariusz JędrzejowskiAuthor Commented:
I used the same code as yours, only changed characters. Characters (arrows) at the bottom line are more or less arranged correctly, but they are not centered. This happens with many narrow characters, aligned to the left. I need them to be centered in their rectangle to be in vertical line with other characters.
 AddText(#9671+#9675+#9675+#9675+#9675+'Courier new'+#$D, 'Courier New', 18, clRed);
  AddText(#9671+#8609+#8609+#8609+#8609+'Courier new'+#$D, 'Courier New', 18, clRed);

Situation is even worse while using unicode components. Since the regular RichEdit allows only a very small number of characters, I tried DSUnicodeRichEdit from
https://delphi-sucks.com/2018/01/20/make-richedit-unicode-aware/
and it discards monospaced fonts. It shows all fonts as having variable character width. So I got out of the frying pan into the fire.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.