-
-
Notifications
You must be signed in to change notification settings - Fork 251
document_container
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 litehtml::uint_ptr create_font(const char* faceName, int size, int weight, litehtml::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 ofascent+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).
-
height - the recommended vertical distance between baselines when setting consecutive lines of text with the font. This is greater than
virtual void delete_font(uint_ptr hFont);
delete the font created in create_font function
virtual int text_width(const char* text, uint_ptr hFont);
Returns the text width.
virtual void draw_text(uint_ptr hdc, const char* 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 char* 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 char* src, const char* 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 char* src, const char* 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 char* 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 char* 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 char* 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 char* cursor);
Define this function to handle the CSS cursor property.
virtual void transform_text(std::string& 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(std::string& text, const std::string& url, std::string& 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, const litehtml::border_radiuses& bdr_radius);
Set the painting clip rectangle here. bdr_radius
defines borders radius for rounded rectangles. 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 char* 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).