Added: font-family style option

This commit is contained in:
Nimetu 2016-07-24 16:07:31 +03:00
parent 74a4e107b6
commit 9e17c46d19
2 changed files with 36 additions and 3 deletions

View file

@ -77,7 +77,7 @@ namespace NLGUI
class CStyleParams class CStyleParams
{ {
public: public:
CStyleParams () : TextColor(255,255,255,255) CStyleParams () : FontFamily(""), TextColor(255,255,255,255)
{ {
FontSize=10; FontSize=10;
FontWeight=400; FontWeight=400;
@ -92,6 +92,7 @@ namespace NLGUI
uint FontSize; uint FontSize;
uint FontWeight; uint FontWeight;
bool FontOblique; bool FontOblique;
std::string FontFamily;
NLMISC::CRGBA TextColor; NLMISC::CRGBA TextColor;
bool Underlined; bool Underlined;
bool StrikeThrough; bool StrikeThrough;
@ -508,6 +509,15 @@ namespace NLGUI
return _GlobalColor.back(); return _GlobalColor.back();
} }
// Current font name
std::vector<std::string> _FontFamily;
inline const char* getFontFamily() const
{
if (_FontFamily.empty())
return "";
return _FontFamily.back().c_str();
}
// Current font size // Current font size
std::vector<uint> _FontSize; std::vector<uint> _FontSize;
inline uint getFontSize() const inline uint getFontSize() const

View file

@ -1218,6 +1218,7 @@ namespace NLGUI
registerAnchorName(MY_HTML_A); registerAnchorName(MY_HTML_A);
CStyleParams style; CStyleParams style;
style.FontFamily = getFontFamily();
style.FontSize = getFontSize(); style.FontSize = getFontSize();
style.TextColor = LinkColor; style.TextColor = LinkColor;
style.Underlined = true; style.Underlined = true;
@ -1226,6 +1227,7 @@ namespace NLGUI
if (present[HTML_A_STYLE] && value[HTML_A_STYLE]) if (present[HTML_A_STYLE] && value[HTML_A_STYLE])
getStyleParams(value[HTML_A_STYLE], style); getStyleParams(value[HTML_A_STYLE], style);
_FontFamily.push_back(style.FontFamily);
_FontSize.push_back(style.FontSize); _FontSize.push_back(style.FontSize);
_TextColor.push_back(style.TextColor); _TextColor.push_back(style.TextColor);
_FontUnderlined.push_back(style.Underlined); _FontUnderlined.push_back(style.Underlined);
@ -1568,7 +1570,7 @@ namespace NLGUI
if (present[MY_HTML_INPUT_ALT] && value[MY_HTML_INPUT_ALT]) if (present[MY_HTML_INPUT_ALT] && value[MY_HTML_INPUT_ALT])
tooltip = value[MY_HTML_INPUT_ALT]; tooltip = value[MY_HTML_INPUT_ALT];
// by default not inherited // by default not inherited, font family defaults to system font
CStyleParams style; CStyleParams style;
style.TextColor = TextColor; style.TextColor = TextColor;
style.FontSize = TextFontSize; style.FontSize = TextFontSize;
@ -1579,6 +1581,7 @@ namespace NLGUI
getStyleParams(value[MY_HTML_INPUT_STYLE], style); getStyleParams(value[MY_HTML_INPUT_STYLE], style);
_TextColor.push_back(style.TextColor); _TextColor.push_back(style.TextColor);
_FontFamily.push_back(style.FontFamily);
_FontSize.push_back(style.FontSize); _FontSize.push_back(style.FontSize);
_FontWeight.push_back(style.FontWeight); _FontWeight.push_back(style.FontWeight);
_FontOblique.push_back(style.FontOblique); _FontOblique.push_back(style.FontOblique);
@ -1794,6 +1797,7 @@ namespace NLGUI
} }
} }
popIfNotEmpty(_FontFamily);
popIfNotEmpty(_FontSize); popIfNotEmpty(_FontSize);
popIfNotEmpty(_TextColor); popIfNotEmpty(_TextColor);
popIfNotEmpty(_FontWeight); popIfNotEmpty(_FontWeight);
@ -2039,7 +2043,7 @@ namespace NLGUI
// Got one form ? // Got one form ?
if (!(_Forms.empty())) if (!(_Forms.empty()))
{ {
// not inherited by default // not inherited by default, font family defaults to system font
CStyleParams style; CStyleParams style;
style.TextColor = TextColor; style.TextColor = TextColor;
style.FontWeight = FONT_WEIGHT_NORMAL; style.FontWeight = FONT_WEIGHT_NORMAL;
@ -2050,6 +2054,7 @@ namespace NLGUI
getStyleParams(value[MY_HTML_TEXTAREA_STYLE], style); getStyleParams(value[MY_HTML_TEXTAREA_STYLE], style);
_TextColor.push_back(style.TextColor); _TextColor.push_back(style.TextColor);
_FontFamily.push_back(style.FontFamily);
_FontSize.push_back(style.FontSize); _FontSize.push_back(style.FontSize);
_FontWeight.push_back(style.FontWeight); _FontWeight.push_back(style.FontWeight);
_FontOblique.push_back(style.FontOblique); _FontOblique.push_back(style.FontOblique);
@ -2136,6 +2141,7 @@ namespace NLGUI
{ {
CStyleParams style; CStyleParams style;
style.TextColor = getTextColor(); style.TextColor = getTextColor();
style.FontFamily = getFontFamily();
style.FontSize = getFontSize(); style.FontSize = getFontSize();
style.FontWeight = getFontWeight(); style.FontWeight = getFontWeight();
style.FontOblique = getFontOblique(); style.FontOblique = getFontOblique();
@ -2146,6 +2152,7 @@ namespace NLGUI
getStyleParams(value[MY_HTML_SPAN_STYLE], style); getStyleParams(value[MY_HTML_SPAN_STYLE], style);
_TextColor.push_back(style.TextColor); _TextColor.push_back(style.TextColor);
_FontFamily.push_back(style.FontFamily);
_FontSize.push_back(style.FontSize); _FontSize.push_back(style.FontSize);
_FontWeight.push_back(style.FontWeight); _FontWeight.push_back(style.FontWeight);
_FontOblique.push_back(style.FontOblique); _FontOblique.push_back(style.FontOblique);
@ -2300,6 +2307,7 @@ namespace NLGUI
popIfNotEmpty (_FontSize); popIfNotEmpty (_FontSize);
break; break;
case HTML_A: case HTML_A:
popIfNotEmpty (_FontFamily);
popIfNotEmpty (_FontSize); popIfNotEmpty (_FontSize);
popIfNotEmpty (_TextColor); popIfNotEmpty (_TextColor);
popIfNotEmpty (_FontUnderlined); popIfNotEmpty (_FontUnderlined);
@ -2371,6 +2379,7 @@ namespace NLGUI
_Forms.back().Entries.push_back (entry); _Forms.back().Entries.push_back (entry);
} }
popIfNotEmpty (_FontFamily);
popIfNotEmpty (_FontSize); popIfNotEmpty (_FontSize);
popIfNotEmpty (_FontWeight); popIfNotEmpty (_FontWeight);
popIfNotEmpty (_FontOblique); popIfNotEmpty (_FontOblique);
@ -2537,6 +2546,7 @@ namespace NLGUI
} }
break; break;
case HTML_SPAN: case HTML_SPAN:
popIfNotEmpty (_FontFamily);
popIfNotEmpty (_FontSize); popIfNotEmpty (_FontSize);
popIfNotEmpty (_FontWeight); popIfNotEmpty (_FontWeight);
popIfNotEmpty (_FontOblique); popIfNotEmpty (_FontOblique);
@ -4008,6 +4018,7 @@ namespace NLGUI
// Compatible with current parameters ? // Compatible with current parameters ?
if (!skipLine && if (!skipLine &&
(getTextColor() == _CurrentViewLink->getColor()) && (getTextColor() == _CurrentViewLink->getColor()) &&
(getFontFamily() == _CurrentViewLink->getFontName()) &&
(getFontSize() == (uint)_CurrentViewLink->getFontSize()) && (getFontSize() == (uint)_CurrentViewLink->getFontSize()) &&
(getFontUnderlined() == _CurrentViewLink->getUnderlined()) && (getFontUnderlined() == _CurrentViewLink->getUnderlined()) &&
(getFontStrikeThrough() == _CurrentViewLink->getStrikeThrough()) && (getFontStrikeThrough() == _CurrentViewLink->getStrikeThrough()) &&
@ -4072,6 +4083,7 @@ namespace NLGUI
} }
newLink->setText(tmpStr); newLink->setText(tmpStr);
newLink->setColor(getTextColor()); newLink->setColor(getTextColor());
newLink->setFontName(getFontFamily());
newLink->setFontSize(getFontSize()); newLink->setFontSize(getFontSize());
newLink->setEmbolden(embolden); newLink->setEmbolden(embolden);
newLink->setOblique(getFontOblique()); newLink->setOblique(getFontOblique());
@ -5762,6 +5774,17 @@ namespace NLGUI
style.FontOblique = true; style.FontOblique = true;
} }
else else
if (it->first == "font-family")
{
if (it->second == "inherit")
style.FontFamily = getFontFamily();
else
if (it->second == "monospace")
style.FontFamily = "monospace";
else
style.FontFamily = "";
}
else
if (it->first == "font-weight") if (it->first == "font-weight")
{ {
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight