Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / render_image.cpp
blob63e622d7b67148e15c3af40d8d39da3b1765d38d
1 #include "html.h"
2 #include "render_image.h"
3 #include "document.h"
5 int litehtml::render_item_image::_render(int x, int y, const containing_block_context &containing_block_size, formatting_context* fmt_ctx, bool second_pass)
7 int parent_width = containing_block_size.width;
9 calc_outlines(parent_width);
11 m_pos.move_to(x, y);
13 document::ptr doc = src_el()->get_document();
15 litehtml::size sz;
16 src_el()->get_content_size(sz, containing_block_size.width);
18 m_pos.width = sz.width;
19 m_pos.height = sz.height;
21 src_el()->css_w().set_line_height(height());
23 if(src_el()->css().get_height().is_predefined() && src_el()->css().get_width().is_predefined())
25 m_pos.height = sz.height;
26 m_pos.width = sz.width;
28 // check for max-width
29 if(!src_el()->css().get_max_width().is_predefined())
31 int max_width = doc->to_pixels(src_el()->css().get_max_width(), src_el()->css().get_font_size(), parent_width);
32 if(m_pos.width > max_width)
34 m_pos.width = max_width;
36 if(sz.width)
38 m_pos.height = (int) ((float) m_pos.width * (float) sz.height / (float)sz.width);
39 } else
41 m_pos.height = sz.height;
45 // check for max-height
46 if(!src_el()->css().get_max_height().is_predefined())
48 int max_height = calc_max_height(sz.height, containing_block_size.height);
49 if(m_pos.height > max_height)
51 m_pos.height = max_height;
53 if(sz.height)
55 m_pos.width = (int) ((float )m_pos.height * (float)sz.width / (float)sz.height);
56 } else
58 m_pos.width = sz.width;
61 } else if(!src_el()->css().get_height().is_predefined() && src_el()->css().get_width().is_predefined())
63 if (!get_predefined_height(m_pos.height, containing_block_size.height))
65 m_pos.height = (int)src_el()->css().get_height().val();
68 // check for max-height
69 if(!src_el()->css().get_max_height().is_predefined())
71 int max_height = calc_max_height(sz.height, containing_block_size.height);
72 if(m_pos.height > max_height)
74 m_pos.height = max_height;
78 if(sz.height)
80 m_pos.width = (int) ((float )m_pos.height * (float)sz.width / (float)sz.height);
81 } else
83 m_pos.width = sz.width;
85 } else if(src_el()->css().get_height().is_predefined() && !src_el()->css().get_width().is_predefined())
87 m_pos.width = (int) src_el()->css().get_width().calc_percent(parent_width);
89 // check for max-width
90 if(!src_el()->css().get_max_width().is_predefined())
92 int max_width = doc->to_pixels(src_el()->css().get_max_width(), src_el()->css().get_font_size(), parent_width);
93 if(m_pos.width > max_width)
95 m_pos.width = max_width;
99 if(sz.width)
101 m_pos.height = (int) ((float) m_pos.width * (float) sz.height / (float)sz.width);
102 } else
104 m_pos.height = sz.height;
106 } else
108 m_pos.width = (int) src_el()->css().get_width().calc_percent(parent_width);
109 m_pos.height = 0;
110 if (!get_predefined_height(m_pos.height, containing_block_size.height))
112 m_pos.height = (int)src_el()->css().get_height().val();
115 // check for max-height
116 if(!src_el()->css().get_max_height().is_predefined())
118 int max_height = calc_max_height(sz.height, containing_block_size.height);
119 if(m_pos.height > max_height)
121 m_pos.height = max_height;
125 // check for max-height
126 if(!src_el()->css().get_max_width().is_predefined())
128 int max_width = doc->to_pixels(src_el()->css().get_max_width(), src_el()->css().get_font_size(), parent_width);
129 if(m_pos.width > max_width)
131 m_pos.width = max_width;
136 m_pos.x += content_offset_left();
137 m_pos.y += content_offset_top();
139 return m_pos.width + content_offset_left() + content_offset_right();
142 int litehtml::render_item_image::calc_max_height(int image_height, int containing_block_height)
144 document::ptr doc = src_el()->get_document();
145 return doc->to_pixels(src_el()->css().get_max_height(), src_el()->css().get_font_size(),
146 containing_block_height == 0 ? image_height : containing_block_height);