Mariusz Jędrzejowski
asked on
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.
ASKER
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.
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
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
ASKER
how do you add it ?
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;
ASKER
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+#967 5+'Courier new'+#$D, 'Courier New', 18, clRed);
AddText(#9671+#8609+#8609+ #8609+#860 9+'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.
AddText(#9671+#9675+#9675+
AddText(#9671+#8609+#8609+
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.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
procedure TForm2.Fuente1Click(Sender
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