-
Notifications
You must be signed in to change notification settings - Fork 1
/
el_text.cpp
188 lines (168 loc) · 3.9 KB
/
el_text.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "litehtml/html.h"
#include "litehtml/el_text.h"
#include "litehtml/document.h"
litehtml::el_text::el_text(const tchar_t* text, const std::shared_ptr<litehtml::document>& doc) : element(doc)
{
if(text)
{
m_text = text;
}
m_text_transform = text_transform_none;
m_use_transformed = false;
m_draw_spaces = true;
}
litehtml::el_text::~el_text()
{
}
void litehtml::el_text::get_content_size( size& sz, int max_width )
{
sz = m_size;
}
void litehtml::el_text::get_text( tstring& text )
{
text += m_text;
}
const litehtml::tchar_t* litehtml::el_text::get_style_property( const tchar_t* name, bool inherited, const tchar_t* def /*= 0*/ )
{
if(inherited)
{
element::ptr el_parent = parent();
if (el_parent)
{
return el_parent->get_style_property(name, inherited, def);
}
}
return def;
}
void litehtml::el_text::parse_styles(bool is_reparse)
{
m_text_transform = (text_transform) value_index(get_style_property(_t("text-transform"), true, _t("none")), text_transform_strings, text_transform_none);
if(m_text_transform != text_transform_none)
{
m_transformed_text = m_text;
m_use_transformed = true;
get_document()->container()->transform_text(m_transformed_text, m_text_transform);
}
if(is_white_space())
{
m_transformed_text = _t(" ");
m_use_transformed = true;
} else
{
if(m_text == _t("\t"))
{
m_transformed_text = _t(" ");
m_use_transformed = true;
}
if(m_text == _t("\n") || m_text == _t("\r"))
{
m_transformed_text = _t("");
m_use_transformed = true;
}
}
font_metrics fm;
uint_ptr font = 0;
element::ptr el_parent = parent();
if (el_parent)
{
font = el_parent->get_font(&fm);
}
if(is_break())
{
m_size.height = 0;
m_size.width = 0;
} else
{
m_size.height = fm.height;
m_size.width = get_document()->container()->text_width(m_use_transformed ? m_transformed_text.c_str() : m_text.c_str(), font);
}
m_draw_spaces = fm.draw_spaces;
}
int litehtml::el_text::get_base_line()
{
element::ptr el_parent = parent();
if (el_parent)
{
return el_parent->get_base_line();
}
return 0;
}
void litehtml::el_text::draw( uint_ptr hdc, int x, int y, const position* clip )
{
if(is_white_space() && !m_draw_spaces)
{
return;
}
position pos = m_pos;
pos.x += x;
pos.y += y;
if(pos.does_intersect(clip))
{
element::ptr el_parent = parent();
if (el_parent)
{
document::ptr doc = get_document();
uint_ptr font = el_parent->get_font();
litehtml::web_color color = el_parent->get_color(_t("color"), true, doc->get_def_color());
doc->container()->draw_text(hdc, m_use_transformed ? m_transformed_text.c_str() : m_text.c_str(), font, color, pos);
}
}
}
int litehtml::el_text::line_height() const
{
element::ptr el_parent = parent();
if (el_parent)
{
return el_parent->line_height();
}
return 0;
}
litehtml::uint_ptr litehtml::el_text::get_font( font_metrics* fm /*= 0*/ )
{
element::ptr el_parent = parent();
if (el_parent)
{
return el_parent->get_font(fm);
}
return 0;
}
litehtml::style_display litehtml::el_text::get_display() const
{
return display_inline_text;
}
litehtml::white_space litehtml::el_text::get_white_space() const
{
element::ptr el_parent = parent();
if (el_parent) return el_parent->get_white_space();
return white_space_normal;
}
litehtml::element_position litehtml::el_text::get_element_position(css_offsets* offsets) const
{
element::ptr p = parent();
while(p && p->get_display() == display_inline)
{
if(p->get_element_position() == element_position_relative)
{
if(offsets)
{
*offsets = p->get_css_offsets();
}
return element_position_relative;
}
p = p->parent();
}
return element_position_static;
}
litehtml::css_offsets litehtml::el_text::get_css_offsets() const
{
element::ptr p = parent();
while(p && p->get_display() == display_inline)
{
if(p->get_element_position() == element_position_relative)
{
return p->get_css_offsets();
}
p = p->parent();
}
return css_offsets();
}