Add <font:$family> tag, closes #24

This commit is contained in:
Twan van Laarhoven
2020-05-12 22:27:57 +02:00
parent 41ed84e678
commit dbb6d34bb3
6 changed files with 22 additions and 5 deletions
+4 -1
View File
@@ -50,7 +50,7 @@ void Font::initDependencies(Context& ctx, const Dependency& dep) const {
shadow_color.initDependencies(ctx, dep);
}
FontP Font::make(int add_flags, Color* other_color, double* other_size) const {
FontP Font::make(int add_flags, String const* other_family, Color const* other_color, double const* other_size) const {
FontP f(new Font(*this));
f->flags |= add_flags;
if (add_flags & FONT_CODE_STRING) {
@@ -73,6 +73,9 @@ FontP Font::make(int add_flags, Color* other_color, double* other_size) const {
if (other_size) {
f->size = *other_size;
}
if (other_family && !other_family->empty()) {
f->name = *other_family;
}
return f;
}
+2 -2
View File
@@ -59,8 +59,8 @@ public:
return shadow_displacement.width != 0 || shadow_displacement.height != 0;
}
/// Add style to a font, and optionally change the color and size
FontP make(int add_flags, Color* other_color, double* other_size) const;
/// Add style to a font, and optionally change the font family, color and size
FontP make(int add_flags, String const* other_family, Color const* other_color, double const* other_size) const;
/// Convert this font to a wxFont
wxFont toWxFont(double scale) const;
+10
View File
@@ -78,6 +78,7 @@ struct TextElementsFromString {
int param_id;
vector<Color> colors;
vector<double> sizes;
vector<String> fonts;
/// put angle brackets around the text?
bool bracket;
@@ -138,6 +139,14 @@ struct TextElementsFromString {
} else if (is_substr(text, tag_start, _("</color"))) {
if (!colors.empty()) colors.pop_back();
}
else if (is_substr(text, tag_start, _( "<font"))) {
size_t colon = text.find_first_of(_(">:"), tag_start);
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
fonts.push_back(text.substr(colon+1, pos-colon-2));
}
} else if (is_substr(text, tag_start, _("</font"))) {
if (!fonts.empty()) fonts.pop_back();
}
else if (is_substr(text, tag_start, _( "<size"))) {
size_t colon = text.find_first_of(_(">:"), tag_start);
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
@@ -251,6 +260,7 @@ private:
(code > 0 ? FONT_CODE : FONT_NORMAL) |
(code_kw > 0 ? FONT_CODE_KW : FONT_NORMAL) |
(code_string > 0 ? FONT_CODE_STRING : FONT_NORMAL),
fonts.empty() ? nullptr : &fonts.back(),
param > 0 || param_ref > 0
? &param_colors[(param_id++) % param_colors_count]
: !colors.empty()
+1 -1
View File
@@ -613,7 +613,7 @@ void check_tagged(const String& str, bool check_balance) {
}
for (size_t j = i + 1 ; j + 1 < end ; ++j) {
Char c = str.GetChar(j);
if (c == _(' ') || c == _('<')) {
if (c == ESCAPED_LANGLE || c == _('<')) {
queue_message(MESSAGE_WARNING, _("Invalid character in tag"));
}
}