Update current version of litehtml. Fix a crash when document contains no fonts
[claws.git] / src / plugins / litehtml_viewer / litehtml / el_before_after.cpp
index 5c9ca342fdd5ab02c65fdb5f377d8bb1cb31c90e..bf0127d2f59433628590a4d462a9b6f916f5c737 100644 (file)
-#include "html.h"\r
-#include "el_before_after.h"\r
-#include "el_text.h"\r
-#include "el_space.h"\r
-#include "el_image.h"\r
-\r
-litehtml::el_before_after_base::el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before) : html_tag(doc)\r
-{\r
-       if(before)\r
-       {\r
-               set_tagName(_t("::before"));\r
-       } else\r
-       {\r
-               set_tagName(_t("::after"));\r
-       }\r
-}\r
-\r
-litehtml::el_before_after_base::~el_before_after_base()\r
-{\r
-\r
-}\r
-\r
-void litehtml::el_before_after_base::add_style(const litehtml::style& st)\r
-{\r
-       html_tag::add_style(st);\r
-\r
-       tstring content = get_style_property(_t("content"), false, _t(""));\r
-       if(!content.empty())\r
-       {\r
-               int idx = value_index(content.c_str(), content_property_string);\r
-               if(idx < 0)\r
-               {\r
-                       tstring fnc;\r
-                       tstring::size_type i = 0;\r
-                       while(i < content.length() && i != tstring::npos)\r
-                       {\r
-                               if(content.at(i) == _t('"'))\r
-                               {\r
-                                       fnc.clear();\r
-                                       i++;\r
-                                       tstring::size_type pos = content.find(_t('"'), i);\r
-                                       tstring txt;\r
-                                       if(pos == tstring::npos)\r
-                                       {\r
-                                               txt = content.substr(i);\r
-                                               i = tstring::npos;\r
-                                       } else\r
-                                       {\r
-                                               txt = content.substr(i, pos - i);\r
-                                               i = pos + 1;\r
-                                       }\r
-                                       add_text(txt);\r
-                               } else if(content.at(i) == _t('('))\r
-                               {\r
-                                       i++;\r
-                                       litehtml::trim(fnc);\r
-                                       litehtml::lcase(fnc);\r
-                                       tstring::size_type pos = content.find(_t(')'), i);\r
-                                       tstring params;\r
-                                       if(pos == tstring::npos)\r
-                                       {\r
-                                               params = content.substr(i);\r
-                                               i = tstring::npos;\r
-                                       } else\r
-                                       {\r
-                                               params = content.substr(i, pos - i);\r
-                                               i = pos + 1;\r
-                                       }\r
-                                       add_function(fnc, params);\r
-                                       fnc.clear();\r
-                               } else\r
-                               {\r
-                                       fnc += content.at(i);\r
-                                       i++;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
-void litehtml::el_before_after_base::add_text( const tstring& txt )\r
-{\r
-       tstring word;\r
-       tstring esc;\r
-       for(tstring::size_type i = 0; i < txt.length(); i++)\r
-       {\r
-               if( (txt.at(i) == _t(' ')) || (txt.at(i) == _t('\t')) || (txt.at(i) == _t('\\') && !esc.empty()) )\r
-               {\r
-                       if(esc.empty())\r
-                       {\r
-                               if(!word.empty())\r
-                               {\r
-                                       element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());\r
-                                       appendChild(el);\r
-                                       word.clear();\r
-                               }\r
-\r
-                               element::ptr el = std::make_shared<el_space>(txt.substr(i, 1).c_str(), get_document());\r
-                               appendChild(el);\r
-                       } else\r
-                       {\r
-                               word += convert_escape(esc.c_str() + 1);\r
-                               esc.clear();\r
-                               if(txt.at(i) == _t('\\'))\r
-                               {\r
-                                       esc += txt.at(i);\r
-                               }\r
-                       }\r
-               } else\r
-               {\r
-                       if(!esc.empty() || txt.at(i) == _t('\\'))\r
-                       {\r
-                               esc += txt.at(i);\r
-                       } else\r
-                       {\r
-                               word += txt.at(i);\r
-                       }\r
-               }\r
-       }\r
-\r
-       if(!esc.empty())\r
-       {\r
-               word += convert_escape(esc.c_str() + 1);\r
-       }\r
-       if(!word.empty())\r
-       {\r
-               element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());\r
-               appendChild(el);\r
-               word.clear();\r
-       }\r
-}\r
-\r
-void litehtml::el_before_after_base::add_function( const tstring& fnc, const tstring& params )\r
-{\r
-       int idx = value_index(fnc.c_str(), _t("attr;counter;url"));\r
-       switch(idx)\r
-       {\r
-       // attr\r
-       case 0:\r
-               {\r
-                       tstring p_name = params;\r
-                       trim(p_name);\r
-                       lcase(p_name);\r
-                       element::ptr el_parent = parent();\r
-                       if (el_parent)\r
-                       {\r
-                               const tchar_t* attr_value = el_parent->get_attr(p_name.c_str());\r
-                               if (attr_value)\r
-                               {\r
-                                       add_text(attr_value);\r
-                               }\r
-                       }\r
-               }\r
-               break;\r
-       // counter\r
-       case 1:\r
-               break;\r
-       // url\r
-       case 2:\r
-               {\r
-                       tstring p_url = params;\r
-                       trim(p_url);\r
-                       if(!p_url.empty())\r
-                       {\r
-                               if(p_url.at(0) == _t('\'') || p_url.at(0) == _t('\"'))\r
-                               {\r
-                                       p_url.erase(0, 1);\r
-                               }\r
-                       }\r
-                       if(!p_url.empty())\r
-                       {\r
-                               if(p_url.at(p_url.length() - 1) == _t('\'') || p_url.at(p_url.length() - 1) == _t('\"'))\r
-                               {\r
-                                       p_url.erase(p_url.length() - 1, 1);\r
-                               }\r
-                       }\r
-                       if(!p_url.empty())\r
-                       {\r
-                               element::ptr el = std::make_shared<el_image>(get_document());\r
-                               el->set_attr(_t("src"), p_url.c_str());\r
-                               el->set_attr(_t("style"), _t("display:inline-block"));\r
-                               el->set_tagName(_t("img"));\r
-                               appendChild(el);\r
-                               el->parse_attributes();\r
-                       }\r
-               }\r
-               break;\r
-       }\r
-}\r
-\r
-litehtml::tchar_t litehtml::el_before_after_base::convert_escape( const tchar_t* txt )\r
-{\r
-       tchar_t* sss = 0;\r
-       return (tchar_t) t_strtol(txt, &sss, 16);\r
-}\r
-\r
-void litehtml::el_before_after_base::apply_stylesheet( const litehtml::css& stylesheet )\r
-{\r
-\r
-}\r
+#include "html.h"
+#include "el_before_after.h"
+#include "el_text.h"
+#include "el_space.h"
+#include "el_image.h"
+
+litehtml::el_before_after_base::el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before) : html_tag(doc)
+{
+       if(before)
+       {
+               set_tagName(_t("::before"));
+       } else
+       {
+               set_tagName(_t("::after"));
+       }
+}
+
+litehtml::el_before_after_base::~el_before_after_base()
+{
+
+}
+
+void litehtml::el_before_after_base::add_style(const litehtml::style& st)
+{
+       html_tag::add_style(st);
+
+       tstring content = get_style_property(_t("content"), false, _t(""));
+       if(!content.empty())
+       {
+               int idx = value_index(content.c_str(), content_property_string);
+               if(idx < 0)
+               {
+                       tstring fnc;
+                       tstring::size_type i = 0;
+                       while(i < content.length() && i != tstring::npos)
+                       {
+                               if(content.at(i) == _t('"'))
+                               {
+                                       fnc.clear();
+                                       i++;
+                                       tstring::size_type pos = content.find(_t('"'), i);
+                                       tstring txt;
+                                       if(pos == tstring::npos)
+                                       {
+                                               txt = content.substr(i);
+                                               i = tstring::npos;
+                                       } else
+                                       {
+                                               txt = content.substr(i, pos - i);
+                                               i = pos + 1;
+                                       }
+                                       add_text(txt);
+                               } else if(content.at(i) == _t('('))
+                               {
+                                       i++;
+                                       litehtml::trim(fnc);
+                                       litehtml::lcase(fnc);
+                                       tstring::size_type pos = content.find(_t(')'), i);
+                                       tstring params;
+                                       if(pos == tstring::npos)
+                                       {
+                                               params = content.substr(i);
+                                               i = tstring::npos;
+                                       } else
+                                       {
+                                               params = content.substr(i, pos - i);
+                                               i = pos + 1;
+                                       }
+                                       add_function(fnc, params);
+                                       fnc.clear();
+                               } else
+                               {
+                                       fnc += content.at(i);
+                                       i++;
+                               }
+                       }
+               }
+       }
+}
+
+void litehtml::el_before_after_base::add_text( const tstring& txt )
+{
+       tstring word;
+       tstring esc;
+       for(tstring::size_type i = 0; i < txt.length(); i++)
+       {
+               if( (txt.at(i) == _t(' ')) || (txt.at(i) == _t('\t')) || (txt.at(i) == _t('\\') && !esc.empty()) )
+               {
+                       if(esc.empty())
+                       {
+                               if(!word.empty())
+                               {
+                                       element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());
+                                       appendChild(el);
+                                       word.clear();
+                               }
+
+                               element::ptr el = std::make_shared<el_space>(txt.substr(i, 1).c_str(), get_document());
+                               appendChild(el);
+                       } else
+                       {
+                               word += convert_escape(esc.c_str() + 1);
+                               esc.clear();
+                               if(txt.at(i) == _t('\\'))
+                               {
+                                       esc += txt.at(i);
+                               }
+                       }
+               } else
+               {
+                       if(!esc.empty() || txt.at(i) == _t('\\'))
+                       {
+                               esc += txt.at(i);
+                       } else
+                       {
+                               word += txt.at(i);
+                       }
+               }
+       }
+
+       if(!esc.empty())
+       {
+               word += convert_escape(esc.c_str() + 1);
+       }
+       if(!word.empty())
+       {
+               element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());
+               appendChild(el);
+               word.clear();
+       }
+}
+
+void litehtml::el_before_after_base::add_function( const tstring& fnc, const tstring& params )
+{
+       int idx = value_index(fnc.c_str(), _t("attr;counter;url"));
+       switch(idx)
+       {
+       // attr
+       case 0:
+               {
+                       tstring p_name = params;
+                       trim(p_name);
+                       lcase(p_name);
+                       element::ptr el_parent = parent();
+                       if (el_parent)
+                       {
+                               const tchar_t* attr_value = el_parent->get_attr(p_name.c_str());
+                               if (attr_value)
+                               {
+                                       add_text(attr_value);
+                               }
+                       }
+               }
+               break;
+       // counter
+       case 1:
+               break;
+       // url
+       case 2:
+               {
+                       tstring p_url = params;
+                       trim(p_url);
+                       if(!p_url.empty())
+                       {
+                               if(p_url.at(0) == _t('\'') || p_url.at(0) == _t('\"'))
+                               {
+                                       p_url.erase(0, 1);
+                               }
+                       }
+                       if(!p_url.empty())
+                       {
+                               if(p_url.at(p_url.length() - 1) == _t('\'') || p_url.at(p_url.length() - 1) == _t('\"'))
+                               {
+                                       p_url.erase(p_url.length() - 1, 1);
+                               }
+                       }
+                       if(!p_url.empty())
+                       {
+                               element::ptr el = std::make_shared<el_image>(get_document());
+                               el->set_attr(_t("src"), p_url.c_str());
+                               el->set_attr(_t("style"), _t("display:inline-block"));
+                               el->set_tagName(_t("img"));
+                               appendChild(el);
+                               el->parse_attributes();
+                       }
+               }
+               break;
+       }
+}
+
+litehtml::tchar_t litehtml::el_before_after_base::convert_escape( const tchar_t* txt )
+{
+       tchar_t* sss = 0;
+       return (tchar_t) t_strtol(txt, &sss, 16);
+}
+
+void litehtml::el_before_after_base::apply_stylesheet( const litehtml::css& stylesheet )
+{
+
+}