forked from litehtml/litehtml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.h
95 lines (87 loc) · 4.16 KB
/
html.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once
#include <stdlib.h>
#include <string>
#include <ctype.h>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <sstream>
#include "os_types.h"
#include "types.h"
#include "background.h"
#include "borders.h"
#include "html_tag.h"
#include "web_color.h"
#include "media_query.h"
namespace litehtml
{
struct list_marker
{
tstring image;
const tchar_t* baseurl;
list_style_type marker_type;
web_color color;
position pos;
uint_ptr font;
uint value;
};
// call back interface to draw text, images and other elements
class document_container
{
public:
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;
virtual void delete_font(litehtml::uint_ptr hFont) = 0;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) = 0;
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;
virtual int pt_to_px(int pt) = 0;
virtual int get_default_font_size() const = 0;
virtual const litehtml::tchar_t* get_default_font_name() const = 0;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) = 0;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) = 0;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) = 0;
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) = 0;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) = 0;
virtual void set_caption(const litehtml::tchar_t* caption) = 0;
virtual void set_base_url(const litehtml::tchar_t* base_url) = 0;
virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) = 0;
virtual void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) = 0;
virtual void set_cursor(const litehtml::tchar_t* cursor) = 0;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) = 0;
virtual void import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl) = 0;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) = 0;
virtual void del_clip() = 0;
virtual void get_client_rect(litehtml::position& client) const = 0;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
const litehtml::string_map &attributes,
const std::shared_ptr<litehtml::document> &doc) = 0;
virtual void get_media_features(litehtml::media_features& media) const = 0;
virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const = 0;
virtual litehtml::tstring resolve_color(const litehtml::tstring& color) const { return litehtml::tstring(); }
};
void trim(tstring &s);
void lcase(tstring &s);
int value_index(const tstring& val, const tstring& strings, int defValue = -1, tchar_t delim = _t(';'));
bool value_in_list(const tstring& val, const tstring& strings, tchar_t delim = _t(';'));
tstring::size_type find_close_bracket(const tstring &s, tstring::size_type off, tchar_t open_b = _t('('), tchar_t close_b = _t(')'));
void split_string(const tstring& str, string_vector& tokens, const tstring& delims, const tstring& delims_preserve = _t(""), const tstring& quote = _t("\""));
void join_string(tstring& str, const string_vector& tokens, const tstring& delims);
inline int round_f(float val)
{
int int_val = (int) val;
if(val - int_val >= 0.5)
{
int_val++;
}
return int_val;
}
inline int round_d(double val)
{
int int_val = (int) val;
if(val - int_val >= 0.5)
{
int_val++;
}
return int_val;
}
}