LoadHTMLFromStream question

General TRichView support forum. Please post your questions here
Post Reply
dimik78
Posts: 12
Joined: Wed Dec 29, 2010 12:48 pm

LoadHTMLFromStream question

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: LoadHTMLFromStream question

Post 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?
dimik78
Posts: 12
Joined: Wed Dec 29, 2010 12:48 pm

Re: LoadHTMLFromStream question

Post 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.
dimik78
Posts: 12
Joined: Wed Dec 29, 2010 12:48 pm

Re: LoadHTMLFromStream question

Post by dimik78 »

Thank you very much!
The fix solved my problem
dimik78
Posts: 12
Joined: Wed Dec 29, 2010 12:48 pm

Re: LoadHTMLFromStream question

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: LoadHTMLFromStream question

Post by Sergey Tkachenko »

Actually, LoadHTMLFromStream and LoadHTML append data to the end of the existing document (like similar methods for RTF, DocX, Markdown)
dimik78
Posts: 12
Joined: Wed Dec 29, 2010 12:48 pm

Re: LoadHTMLFromStream question

Post by dimik78 »

Thank you very much!
No further questions.
Post Reply