Page 1 of 1

LoadHTMLFromStream question

Posted: Fri Mar 03, 2023 12:24 pm
by dimik78
Hi,

We used to load HTML то TRichView THtmlViewer component.
It has such properties as DefBackground, DefFontName, DefFontSize.

Now we try to use new method LoadHTMLFromStream.
Is there any possibility to specify default style for LoadHTMLFromStream?

Re: LoadHTMLFromStream question

Posted: Fri Mar 03, 2023 3:22 pm
by Sergey Tkachenko
There is a global singleton object in RVDefReadProps unit (or fmxRVDefReadProps in FireMonkey version): RVDefaultLoadProperties.
It defines default properties for reading HTML and Markdown, for all TRichView and ScaleRichView controls.

Font names

RVDefaultLoadProperties has properties DefaultFontName and DefaultMonoSpacedFontName.
You can define more default fonts using GenericFontNames[] array property.
An index of this property can be one of values: rvgffRVDefault, rvgffSerif, rvgffSansSerif, rvgffMonospace, rvgffCursive, rvgffFantasy, rvgffSystemUI, rvgffUISerif, rvgffUISansSerif,r vgffUIMonospace, rvgffUIRrounded, rvgffEmoji, rvgffMath, rvgffFangsong, rvgffRVSymbols, rvgffRVBullets.
Most these values correspond to values of CSS font-family.
DefaultFontName simply provides access to GenericFontNames[rvgffRVDefault], DefaultMonoSpacedFontName to GenericFontNames[rvgffMonospace].

Font sizes

RVDefaultLoadProperties has property DefaultFontSizeDouble measured in half-points (default value is 24 meaning 12pt).
You can define more sizes using DefaultFontSizesDouble[] array property.
An index of this property can be one of values:

Code: Select all

    VALUE             HTML SIZE   CSS SIZE
    rvfstDefault,      //  (used if unspecified)
    rvfstXXSmall,      //  1      xx-small
    rvfstXSmall,       //  -      x-small
    rvfstSmall,        //  2      small
    rvfstMedium,       //  3      medium
    rvfstLarge,        //  4      large
    rvfstXLarge,       //  5      x-large
    rvfstXXLarge,      //  6      xx-large
    rvfstXXXLarge);    //  7      xxx-large
DefaultFontSizeDouble simply provides access to DefaultFontSizesDouble[rvfstDefault].

Background color

The default background color is hard-coded, clWindow (or white for FireMonkey).
Should I add a property?

Re: LoadHTMLFromStream question

Posted: Sat Mar 04, 2023 8:50 am
by dimik78
Sergey, thank you for your prompt reply!

Your advice helped me, but not completely.

I try set

Code: Select all

RVDefaultLoadProperties.DefaultFontName := 'Arial';
RVDefaultLoadProperties.DefaultMonoSpacedFontName := 'Arial';
but in some cases after loading the html the font still stay 'Times New Roman'.

I tried to see what was going on under the debugger and I think I found the problem.

In method TRVHTMLLoader.GetCurrentRVTextStyle (unit RVHtmlLoad) there are these lines:

Code: Select all

begin
   HTMLStyle := FReader.CurrentStyle;
   
   .......
   
   Result.FontName := RVDefaultLoadProperties.GetFontName(HTMLStyle.FontFamilies);
end;
and HTMLStyle.FontFamilies always set 'Times New Roman'.
I may be doing something wrong and would appreciate your help.

Referring to background color, clWindow colour for background is fine with me.

Re: LoadHTMLFromStream question

Posted: Sat Mar 04, 2023 9:36 am
by Sergey Tkachenko

Re: LoadHTMLFromStream question

Posted: Sat Mar 04, 2023 12:50 pm
by dimik78
Thank you very much!
The fix solved my problem

Re: LoadHTMLFromStream question

Posted: Sat Mar 04, 2023 2:39 pm
by dimik78
Good evening!

Everything is working fine, but there are a few minor remarks.

Previously, when using TRVHTMLViewImporter it was possible to call AppendHtmlViewer, which added data to the end of the document and worked with ReadOnly documents.

Now there is only InsertHTMLFromStreamEd method, which requires calling Format and MoveCaret methods and also scrolls the editor window down.

It would be nice to have an AppendHTMLFromStream method which would work like AppendRVFFromStream.

Re: LoadHTMLFromStream question

Posted: Sat Mar 04, 2023 6:29 pm
by Sergey Tkachenko
Actually, LoadHTMLFromStream and LoadHTML append data to the end of the existing document (like similar methods for RTF, DocX, Markdown)

Re: LoadHTMLFromStream question

Posted: Sun Mar 05, 2023 8:49 am
by dimik78
Thank you very much!
No further questions.