Yuri Kobets edited this page Aug 30, 2018 · 7 revisions


litehtml::document_container class draws the HTML elements and perform some actions depended of the platform. This is the only class you should implement in your application.

Below is the list of member function you have to implement.


virtual uint_ptr create_font(const tchar_t* faceName, int size, int weight, font_style italic, unsigned int decoration, litehtml::font_metrics* fm);

This function called by litehtml to create the font. create_font returns uint_ptr that identify the created font. Parameters:

  • faceName - the face name for the font. Note: faceName can contain some fonts as described in CSS specifications. You have to select the proper font.
  • size - font size in pixels.
  • weight - Defines from thin to thick characters. 400 is the same as normal, and 700 is the same as bold.
  • decoration - one or more flags:
    • const unsigned int font_decoration_none=0x00;
    • const unsigned int font_decoration_underline=0x01;
    • const unsigned int font_decoration_linethrough=0x02;
    • const unsigned int font_decoration_overline=0x04;
  • fm - you have to fill this structure with the font metrics:
    • height - the recommended vertical distance between baselines when setting consecutive lines of text with the font. This is greater than ascent+descent by a quantity known as the line spacing or external leading. When space is at a premium, most fonts can be set with only a distance of ascent+descent between lines.
    • ascent - the distance that the font extends above the baseline. Note that this is not always exactly equal to the maximum of the extents of all the glyphs in the font, but rather is picked to express the font designer's intent as to how the font should align with elements above it.
    • descent - the distance that the font extends below the baseline. This value is positive for typical fonts that include portions below the baseline. Note that this is not always exactly equal to the maximum of the extents of all the glyphs in the font, but rather is picked to express the font designer's intent as to how the font should align with elements below it.
    • x_height - height of the 'x' char (used for internal calculations).


virtual void delete_font(uint_ptr hFont);

delete the font created in create_font function


virtual int text_width(const tchar_t* text, uint_ptr hFont);

Returns the text width.


virtual void draw_text(uint_ptr hdc, const tchar_t* text, uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos);

This function draw the text string.


virtual int pt_to_px(int pt);

Convert points into pixels.


virtual int get_default_font_size();

Returns the default font size in pixels.


virtual const tchar_t* get_default_font_name();

Returns the default font face name.


virtual void draw_list_marker(uint_ptr hdc, const litehtml::list_marker& marker);

Draws the list marker. Use the parameter marker to find the marker type and position.


virtual void load_image(const tchar_t* src, const tchar_t* baseurl);

You can preload image in this function. litehtml does not cache the images, so you have to create own images cache if you need it.


virtual void get_image_size(const tchar_t* src, const tchar_t* baseurl, litehtml::size& sz);

Fill the sz parameter with image width and height.


virtual void draw_background(uint_ptr hdc, const litehtml::background_paint& bg);

Draw the background in this function. The parameter bg describes the element background (see background_paint description). Note the <img> html element are drawn as background.


virtual void draw_borders(uint_ptr hdc, const css_borders& borders, const litehtml::position& draw_pos, bool root);

Draw the element borders here. The parameter root is true if you have to draw the borders for the root element (usually this is <html>).


virtual	void set_caption(const tchar_t* caption);

litehtml calls this function with <title> html tag text. You can use the caption parameter to set the window caption text into the html page title.


virtual	void set_base_url(const tchar_t* base_url);

litehtml calls this function for the <base> html tag to set the base url. Save this string for future use in the functions that get the baseurl parameter.


virtual void link(litehtml::document* doc, litehtml::element::ptr el);

This function is used to process the <link> html tags. Note, litehtml processes the stylesheets references automatically and calls import_css function to load CSS file.


virtual void on_anchor_click(const tchar_t* url, litehtml::element::ptr el);

litehtml calls this function on anchor element click. You can open new website or do something other here.


virtual	void set_cursor(const tchar_t* cursor);

Define this function to handle the CSS cursor property.


virtual	void transform_text(litehtml::tstring& text, litehtml::text_transform tt);

Transform the text parameter according the tt value:

  • text_transform_capitalize - make the first char upper case.
  • text_transform_uppercase - make all chars upper case.
  • text_transform_lowercase - make all chars lower case.


virtual void import_css(tstring& text, const tstring& url, tstring& baseurl);

litehtml calls this function to load stylesheet. You have to download CSS file referred by url and baseurl parameters and copy content into text parameter.


virtual void set_clip(const litehtml::position& pos, bool valid_x, bool valid_y);

Set the painting clip rectangle here. valid_x and valid_y are ignored. Please note, litehtml can set some clip rects. You have to save the clip positions and apply clipping on draw something.


virtual void del_clip();

Deletes the last clipping.


virtual void get_client_rect(litehtml::position& client);

Fill the parameter client with the viewport position and size. Usually this is the size of the client rectangle of the window where you want to draw html.


virtual litehtml::element* create_element(const tchar_t* tag_name);

Using this function you can process custom tags. Just make your own litehtml::element and return is from this function. Parameter tag_name is the HTML tag (a, p, table etc.).


virtual void get_media_features(litehtml::media_features& media)

Fill the media with the parameters of media where you render HTML. litehtml process stylesheets using the media features. Call document::media_changed function when any media feature is changed (for example user is changed the window size).

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.