Changed: Parse html style attribute

--HG--
branch : develop
feature/pipeline-tools
Nimetu 6 years ago
parent 78c39850ae
commit d62c139ee0

@ -105,6 +105,7 @@ namespace NLGUI
Height=-1;
MaxWidth=-1;
MaxHeight=-1;
BackgroundColor=NLMISC::CRGBA::Black;
}
uint FontSize;
uint FontWeight;
@ -119,6 +120,7 @@ namespace NLGUI
sint32 Height;
sint32 MaxWidth;
sint32 MaxHeight;
NLMISC::CRGBA BackgroundColor;
};
// ImageDownload system
@ -345,6 +347,9 @@ namespace NLGUI
// Get Home URL
virtual std::string home();
// Clear style stack and restore default style
void resetCssStyle();
// Parse style html tag
TStyle parseStyle(const std::string &str_styles);

@ -49,6 +49,14 @@ namespace NLGUI
#undef HTML_ATTR
#define HTML_ATTR(t,a) MY_HTML_##t##_##a
enum
{
HTML_ATTR(HTML,DIR) = 0,
HTML_ATTR(HTML,LANG),
HTML_ATTR(HTML,VERSION),
HTML_ATTR(HTML,STYLE),
};
enum
{
HTML_ATTR(A,ACCESSKEY) = 0,

@ -1489,6 +1489,13 @@ namespace NLGUI
// Paragraph ?
switch(element_number)
{
case HTML_HTML:
if (present[MY_HTML_HTML_STYLE] && value[MY_HTML_HTML_STYLE])
getStyleParams(value[MY_HTML_HTML_STYLE], _StyleDefault);
_Style = _StyleDefault;
setBackgroundColor(_Style.BackgroundColor);
break;
case HTML_HEAD:
_ReadingHeadTag = !_IgnoreHeadTag;
_IgnoreHeadTag = true;
@ -1708,17 +1715,21 @@ namespace NLGUI
break;
case HTML_BODY:
{
if (present[HTML_BODY_BGCOLOR] && value[HTML_BODY_BGCOLOR])
{
CRGBA bgColor;
if (scanHTMLColor(value[HTML_BODY_BGCOLOR], bgColor))
setBackgroundColor (bgColor);
}
pushStyle();
string style;
if (present[HTML_BODY_STYLE] && value[HTML_BODY_STYLE])
style = value[HTML_BODY_STYLE];
if (!style.empty())
getStyleParams(style, _Style);
CRGBA bgColor = _Style.BackgroundColor;
if (present[HTML_BODY_BGCOLOR] && value[HTML_BODY_BGCOLOR])
scanHTMLColor(value[HTML_BODY_BGCOLOR], bgColor);
if (bgColor != _Style.BackgroundColor)
setBackgroundColor(bgColor);
if (!style.empty())
{
@ -1743,10 +1754,6 @@ namespace NLGUI
image = image.substr(4, image.size()-5);
setBackground (image, scale, repeat);
}
// set default text style from <body>
getStyleParams(style, _StyleDefault);
_Style = _StyleDefault;
}
}
break;
@ -2737,6 +2744,9 @@ namespace NLGUI
case HTML_HEAD:
_ReadingHeadTag = false;
break;
case HTML_BODY:
popStyle();
break;
case HTML_FONT:
popStyle();
break;
@ -4915,9 +4925,7 @@ namespace NLGUI
_IgnoreBaseUrlTag = false;
// reset style
_StyleDefault = CStyleParams();
_Style = _StyleDefault;
_StyleParams.clear();
resetCssStyle();
// TR
@ -6252,6 +6260,18 @@ namespace NLGUI
return uri.toString();
}
// ***************************************************************************
void CGroupHTML::resetCssStyle()
{
_StyleDefault = CStyleParams();
_StyleDefault.TextColor = TextColor;
_StyleDefault.FontSize = TextFontSize;
_StyleDefault.BackgroundColor = BgColor;
_Style = _StyleDefault;
_StyleParams.clear();
}
// ***************************************************************************
// CGroupHTML::CStyleParams style;
// style.FontSize; // font-size: 10px;
@ -6485,6 +6505,14 @@ namespace NLGUI
if (fromString(it->second, b))
style.GlobalColor = b;
}
else
if (it->first == "background-color")
{
if (it->second == "inherit")
style.BackgroundColor = current.backgroundColor;
else
scanHTMLColor(it->second.c_str(), style.BackgroundColor);
}
}
}

@ -47,6 +47,15 @@ namespace NLGUI
#undef HTML_ATTR
#define HTML_ATTR(a,b) { (char*) #b }
HTAttr html_attr[] =
{
HTML_ATTR(HTML,DIR),
HTML_ATTR(HTML,LANG),
HTML_ATTR(HTML,VERSION),
HTML_ATTR(HTML,STYLE),
{ 0 }
};
HTAttr a_attr[] =
{
HTML_ATTR(A,ACCESSKEY),
@ -469,6 +478,8 @@ namespace NLGUI
// Change the HTML DTD
SGML_dtd *HTML_DTD = HTML_dtd ();
HTML_DTD->tags[HTML_HTML].attributes = html_attr;
HTML_DTD->tags[HTML_HTML].number_of_attributes = sizeof(html_attr) / sizeof(HTAttr) - 1;
HTML_DTD->tags[HTML_TABLE].attributes = table_attr;
HTML_DTD->tags[HTML_TABLE].number_of_attributes = sizeof(table_attr) / sizeof(HTAttr) - 1;
HTML_DTD->tags[HTML_TR].attributes = tr_attr;

Loading…
Cancel
Save