2#pragma warning(disable: 4100)
3#pragma warning(disable: 4457)
4#elif defined(__clang__)
5#pragma clang diagnostic ignored "-Wunused-parameter"
12litehtml::el_image::el_image(
const std::shared_ptr<litehtml::document>& doc) : html_tag(doc)
14 m_display = display_inline_block;
17litehtml::el_image::~el_image(
void )
22void litehtml::el_image::get_content_size( size& sz,
int max_width )
24 get_document()->container()->get_image_size(m_src.c_str(), 0, sz);
27int litehtml::el_image::calc_max_height(
int image_height)
29 document::ptr doc = get_document();
31 if (m_css_max_height.units() == css_units_percentage)
33 auto el_parent = parent();
36 if (!el_parent->get_predefined_height(percentSize))
42 return doc->cvt_units(m_css_max_height, m_font_size, percentSize);
45int litehtml::el_image::line_height()
const
50bool litehtml::el_image::is_replaced()
const
55int litehtml::el_image::render(
int x,
int y,
int max_width,
bool second_pass )
57 int parent_width = max_width;
59 calc_outlines(parent_width);
63 document::ptr doc = get_document();
66 doc->container()->get_image_size(m_src.c_str(), 0, sz);
68 m_pos.width = sz.width;
69 m_pos.height = sz.height;
71 if(m_css_height.is_predefined() && m_css_width.is_predefined())
73 m_pos.height = sz.height;
74 m_pos.width = sz.width;
77 if(!m_css_max_width.is_predefined())
79 int max_width = doc->cvt_units(m_css_max_width, m_font_size, parent_width);
80 if(m_pos.width > max_width)
82 m_pos.width = max_width;
86 m_pos.height = (int) ((
float) m_pos.width * (float) sz.height / (
float)sz.width);
89 m_pos.height = sz.height;
94 if(!m_css_max_height.is_predefined())
96 int max_height = calc_max_height(sz.height);
97 if(m_pos.height > max_height)
99 m_pos.height = max_height;
103 m_pos.width = (int) (m_pos.height * (
float)sz.width / (float)sz.height);
106 m_pos.width = sz.width;
109 }
else if(!m_css_height.is_predefined() && m_css_width.is_predefined())
111 if (!get_predefined_height(m_pos.height))
113 m_pos.height = (int)m_css_height.val();
117 if(!m_css_max_height.is_predefined())
119 int max_height = calc_max_height(sz.height);
120 if(m_pos.height > max_height)
122 m_pos.height = max_height;
128 m_pos.width = (int) (m_pos.height * (
float)sz.width / (float)sz.height);
131 m_pos.width = sz.width;
133 }
else if(m_css_height.is_predefined() && !m_css_width.is_predefined())
135 m_pos.width = (int) m_css_width.calc_percent(parent_width);
138 if(!m_css_max_width.is_predefined())
140 int max_width = doc->cvt_units(m_css_max_width, m_font_size, parent_width);
141 if(m_pos.width > max_width)
143 m_pos.width = max_width;
149 m_pos.height = (int) ((
float) m_pos.width * (float) sz.height / (
float)sz.width);
152 m_pos.height = sz.height;
156 m_pos.width = (int) m_css_width.calc_percent(parent_width);
158 if (!get_predefined_height(m_pos.height))
160 m_pos.height = (int)m_css_height.val();
164 if(!m_css_max_height.is_predefined())
166 int max_height = calc_max_height(sz.height);
167 if(m_pos.height > max_height)
169 m_pos.height = max_height;
174 if(!m_css_max_width.is_predefined())
176 int max_width = doc->cvt_units(m_css_max_width, m_font_size, parent_width);
177 if(m_pos.width > max_width)
179 m_pos.width = max_width;
184 calc_auto_margins(parent_width);
186 m_pos.x += content_margins_left();
187 m_pos.y += content_margins_top();
189 return m_pos.width + content_margins_left() + content_margins_right();
192void litehtml::el_image::parse_attributes()
194 m_src = get_attr(_t(
"src"), _t(
""));
196 const tchar_t* attr_height = get_attr(_t(
"height"));
199 m_style.add_property(_t(
"height"), attr_height, 0,
false);
201 const tchar_t* attr_width = get_attr(_t(
"width"));
204 m_style.add_property(_t(
"width"), attr_width, 0,
false);
208void litehtml::el_image::draw( uint_ptr hdc,
int x,
int y,
const position* clip )
210 position pos = m_pos;
214 position el_pos = pos;
219 if (el_pos.does_intersect(clip))
221 const background* bg = get_background();
224 background_paint bg_paint;
225 init_background_paint(pos, bg_paint, bg);
227 get_document()->container()->draw_background(hdc, bg_paint);
232 if(pos.does_intersect(clip))
234 if (pos.width > 0 && pos.height > 0) {
240 bg.border_box += m_padding;
241 bg.border_box += m_borders;
242 bg.repeat = background_repeat_no_repeat;
244 bg.color.green = 255;
246 bg.color.alpha = 255;
247 bg.image_size.width = pos.width;
248 bg.image_size.height = pos.height;
249 bg.border_radius = m_css_borders.radius.calc_percents(bg.border_box.width, bg.border_box.height);
250 bg.position_x = pos.x;
251 bg.position_y = pos.y;
252 get_document()->container()->draw_background(hdc, bg);
257 if (el_pos.does_intersect(clip))
259 position border_box = pos;
260 border_box += m_padding;
261 border_box += m_borders;
263 borders bdr = m_css_borders;
264 bdr.radius = m_css_borders.radius.calc_percents(border_box.width, border_box.height);
266 get_document()->container()->draw_borders(hdc, bdr, border_box, have_parent() ?
false :
true);
270void litehtml::el_image::parse_styles(
bool is_reparse )
272 html_tag::parse_styles(is_reparse);
276 if(!m_css_height.is_predefined() && !m_css_width.is_predefined())
278 get_document()->container()->load_image(m_src.c_str(), 0,
true);
281 get_document()->container()->load_image(m_src.c_str(), 0,
false);