How to specify default font when printing HTML with TRichView v21.0
Posted: Thu Mar 02, 2023 10:00 pm
I have updated to the latest TRichView v21.0. I have two components dropped into my Delphi form:
[list]RichView1
RVStyle1[/list]
I then set RichView1.Style to RVStyle1
I then have the following function to display HTML:
[code]procedure TMyForm.renderHtml( const htmlMsg : string );
var s : TStringStream;
begin
s := TStringStream.Create( htmlMsg );
try
RichView1.Clear;
RichView1.LoadHTMLFromStream( s );
RichView1.Format;
finally
s.Free;
end;
end;[/code]
My problem is that the HTML is showing in what appears to be Times Roman font.
Using Delphi's Object Inspector, I review what is in RVStyle1.TextStyles and see this list of TFontInfo instances: 0 - Normal text, 1 - Heading, 2 - Subheading, 3 - Keywords, 4 - Jump 1, and 5 - Jump 2
Looking into each of these TFontInfo instances, they all have FontName = 'Arial'. So I do not understand why Arial is not being used. As I said above, the HTML looks like it is using font "Times Roman".
Reading a variety of TRichView support posts, I see that the following needs to be performed, although what this code does is simply set the FontName for each style to "Arial" which is what I already see in the object inspector:
[code]procedure TFontTestForm.FontReplace(rv:TRichView);
// Ref: https://richedit.com/support/trichview. ... ment_3.htm
var i:Integer;
RVEStyle: TRVStyle;
begin
RVEStyle := rv.Style;
for i := 0 to RVEStyle.TextStyles.Count-1 do
RVEStyle.TextStyles[i].FontName := 'Tahoma';
rv.Format;
end;[/code]
So, even after calling FontReplace(RichView1) in my FormCreate method, I am still seeing my HTML printed in Times Roman when calling renderHtml(). For example, I tried this:
[code]renderHtml( 'Hello, <b>this</b> <u>is</u> a <i>senseless</i> <font color="red">sentence</font>.');[/code]
Then I thought I needed to specify the font style ("Normal text"), so I tried this:
[code]renderHtml( '<font style="Normal text">' +
'Hello, <b>this</b> <u>is</u> a <i>senseless</i> <font color="red">sentence</font>.'
+ '</font>'
);[/code]
Please help. This should be a simple task, but I do not know what I am doing wrong.
Thank you,
- SV
[list]RichView1
RVStyle1[/list]
I then set RichView1.Style to RVStyle1
I then have the following function to display HTML:
[code]procedure TMyForm.renderHtml( const htmlMsg : string );
var s : TStringStream;
begin
s := TStringStream.Create( htmlMsg );
try
RichView1.Clear;
RichView1.LoadHTMLFromStream( s );
RichView1.Format;
finally
s.Free;
end;
end;[/code]
My problem is that the HTML is showing in what appears to be Times Roman font.
Using Delphi's Object Inspector, I review what is in RVStyle1.TextStyles and see this list of TFontInfo instances: 0 - Normal text, 1 - Heading, 2 - Subheading, 3 - Keywords, 4 - Jump 1, and 5 - Jump 2
Looking into each of these TFontInfo instances, they all have FontName = 'Arial'. So I do not understand why Arial is not being used. As I said above, the HTML looks like it is using font "Times Roman".
Reading a variety of TRichView support posts, I see that the following needs to be performed, although what this code does is simply set the FontName for each style to "Arial" which is what I already see in the object inspector:
[code]procedure TFontTestForm.FontReplace(rv:TRichView);
// Ref: https://richedit.com/support/trichview. ... ment_3.htm
var i:Integer;
RVEStyle: TRVStyle;
begin
RVEStyle := rv.Style;
for i := 0 to RVEStyle.TextStyles.Count-1 do
RVEStyle.TextStyles[i].FontName := 'Tahoma';
rv.Format;
end;[/code]
So, even after calling FontReplace(RichView1) in my FormCreate method, I am still seeing my HTML printed in Times Roman when calling renderHtml(). For example, I tried this:
[code]renderHtml( 'Hello, <b>this</b> <u>is</u> a <i>senseless</i> <font color="red">sentence</font>.');[/code]
Then I thought I needed to specify the font style ("Normal text"), so I tried this:
[code]renderHtml( '<font style="Normal text">' +
'Hello, <b>this</b> <u>is</u> a <i>senseless</i> <font color="red">sentence</font>.'
+ '</font>'
);[/code]
Please help. This should be a simple task, but I do not know what I am doing wrong.
Thank you,
- SV