add support for Ayatana indicator to Notification plugin
[claws.git] / src / plugins / litehtml_viewer / litehtml / el_text.cpp
bloba22224a3575029680422dc75c36d5412e7c77247
1 #include "html.h"
2 #include "el_text.h"
3 #include "render_item.h"
5 litehtml::el_text::el_text(const char* text, const document::ptr& doc) : element(doc)
7 if(text)
9 m_text = text;
11 m_use_transformed = false;
12 m_draw_spaces = true;
13 css_w().set_display(display_inline_text);
16 void litehtml::el_text::get_content_size( size& sz, int max_width )
18 sz = m_size;
21 void litehtml::el_text::get_text( string& text )
23 text += m_text;
26 void litehtml::el_text::compute_styles(bool recursive)
28 element::ptr el_parent = parent();
29 if (el_parent)
31 css_w().set_line_height(el_parent->css().get_line_height());
32 css_w().set_font(el_parent->css().get_font());
33 css_w().set_font_metrics(el_parent->css().get_font_metrics());
34 css_w().set_white_space(el_parent->css().get_white_space());
35 css_w().set_text_transform(el_parent->css().get_text_transform());
37 css_w().set_display(display_inline_text);
38 css_w().set_float(float_none);
40 if(m_css.get_text_transform() != text_transform_none)
42 m_transformed_text = m_text;
43 m_use_transformed = true;
44 get_document()->container()->transform_text(m_transformed_text, m_css.get_text_transform());
45 } else
47 m_use_transformed = false;
50 element::ptr p = parent();
51 while(p && p->css().get_display() == display_inline)
53 if(p->css().get_position() == element_position_relative)
55 css_w().set_offsets(p->css().get_offsets());
56 css_w().set_position(element_position_relative);
57 break;
59 p = p->parent();
61 if(p)
63 css_w().set_position(element_position_static);
66 if(is_white_space())
68 m_transformed_text = " ";
69 m_use_transformed = true;
70 } else
72 if(m_text == "\t")
74 m_transformed_text = " ";
75 m_use_transformed = true;
77 if(m_text == "\n" || m_text == "\r")
79 m_transformed_text = "";
80 m_use_transformed = true;
84 font_metrics fm;
85 uint_ptr font = 0;
86 if (el_parent)
88 font = el_parent->css().get_font();
89 fm = el_parent->css().get_font_metrics();
91 if(is_break() || !font)
93 m_size.height = 0;
94 m_size.width = 0;
95 } else
97 m_size.height = fm.height;
98 m_size.width = get_document()->container()->text_width(m_use_transformed ? m_transformed_text.c_str() : m_text.c_str(), font);
100 m_draw_spaces = fm.draw_spaces;
103 void litehtml::el_text::draw(uint_ptr hdc, int x, int y, const position *clip, const std::shared_ptr<render_item> &ri)
105 if(is_white_space() && !m_draw_spaces)
107 return;
110 position pos = ri->pos();
111 pos.x += x;
112 pos.y += y;
114 if(pos.does_intersect(clip))
116 element::ptr el_parent = parent();
117 if (el_parent)
119 document::ptr doc = get_document();
121 uint_ptr font = el_parent->css().get_font();
122 if(font)
124 web_color color = el_parent->css().get_color();
125 doc->container()->draw_text(hdc, m_use_transformed ? m_transformed_text.c_str() : m_text.c_str(), font,
126 color, pos);
132 litehtml::string litehtml::el_text::dump_get_name()
134 return "text: \"" + get_escaped_string(m_text) + "\"";
137 std::vector<std::tuple<litehtml::string, litehtml::string>> litehtml::el_text::dump_get_attrs()
139 return std::vector<std::tuple<string, string>>();