1#ifndef LH_HTML_H
2#define LH_HTML_H
3
4#include <stdlib.h>
5#include <string>
6#include <ctype.h>
7#include <vector>
8#include <map>
9#include <cstring>
10#include <algorithm>
11#include <sstream>
12#include <functional>
13#include "os_types.h"
14#include "types.h"
15#include "background.h"
16#include "borders.h"
17#include "html_tag.h"
18#include "web_color.h"
19#include "media_query.h"
20
21namespace litehtml
22{
23 struct list_marker
24 {
25 tstring image;
26 const tchar_t* baseurl;
27 list_style_type marker_type;
28 web_color color;
29 position pos;
30 int index;
31 uint_ptr font;
32 };
33
34 // call back interface to draw text, images and other elements
35 class document_container
36 {
37 public:
38 virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) = 0;
39 virtual void delete_font(litehtml::uint_ptr hFont) = 0;
40 virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) = 0;
41 virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) = 0;
42 virtual int pt_to_px(int pt) const = 0;
43 virtual int get_default_font_size() const = 0;
44 virtual const litehtml::tchar_t* get_default_font_name() const = 0;
45 virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) = 0;
46 virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) = 0;
47 virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) = 0;
48 virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) = 0;
49 virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) = 0;
50
51 virtual void set_caption(const litehtml::tchar_t* caption) = 0;
52 virtual void set_base_url(const litehtml::tchar_t* base_url) = 0;
53 virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) = 0;
54 virtual void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) = 0;
55 virtual void set_cursor(const litehtml::tchar_t* cursor) = 0;
56 virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) = 0;
57 virtual void import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl) = 0;
58 virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) = 0;
59 virtual void del_clip() = 0;
60 virtual void get_client_rect(litehtml::position& client) const = 0;
61 virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
62 const litehtml::string_map &attributes,
63 const std::shared_ptr<litehtml::document> &doc) = 0;
64
65 virtual void get_media_features(litehtml::media_features& media) const = 0;
66 virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const = 0;
67 virtual litehtml::tstring resolve_color(const litehtml::tstring& /*color*/) const { return litehtml::tstring(); }
68 virtual void split_text(const char* text, const std::function<void(const tchar_t*)>& on_word, const std::function<void(const tchar_t*)>& on_space);
69
70 protected:
71 ~document_container() = default;
72 };
73
74 void trim(tstring &s);
75 void lcase(tstring &s);
76 int value_index(const tstring& val, const tstring& strings, int defValue = -1, tchar_t delim = _t(';'));
77 bool value_in_list(const tstring& val, const tstring& strings, tchar_t delim = _t(';'));
78 tstring::size_type find_close_bracket(const tstring &s, tstring::size_type off, tchar_t open_b = _t('('), tchar_t close_b = _t(')'));
79 void split_string(const tstring& str, string_vector& tokens, const tstring& delims, const tstring& delims_preserve = _t(""), const tstring& quote = _t("\""));
80 void join_string(tstring& str, const string_vector& tokens, const tstring& delims);
81 double t_strtod(const tchar_t* string, tchar_t** endPtr);
82
83 int t_strcasecmp(const tchar_t *s1, const tchar_t *s2);
84 int t_strncasecmp(const tchar_t *s1, const tchar_t *s2, size_t n);
85
86 inline int t_isdigit(int c)
87 {
88 return (c >= '0' && c <= '9');
89 }
90
91 inline int t_tolower(int c)
92 {
93 return (c >= 'A' && c <= 'Z' ? c + 'a' - 'A' : c);
94 }
95
96 inline int round_f(float val)
97 {
98 int int_val = (int) val;
99 if(val - int_val >= 0.5)
100 {
101 int_val++;
102 }
103 return int_val;
104 }
105
106 inline int round_d(double val)
107 {
108 int int_val = (int) val;
109 if(val - int_val >= 0.5)
110 {
111 int_val++;
112 }
113 return int_val;
114 }
115}
116
117#endif // LH_HTML_H
118

source code of qttools/src/assistant/qlitehtml/src/3rdparty/litehtml/include/litehtml/html.h