diff --git a/doc/type/tagged_string.txt b/doc/type/tagged_string.txt index 7815d9e4..bee04f33 100644 --- a/doc/type/tagged_string.txt +++ b/doc/type/tagged_string.txt @@ -15,10 +15,12 @@ This is written as the character with code 1 in files. | @""@ The text inside the tag is bold. | @""@ The text inside the tag is italic. | @""@ The text inside the tag is rendered as symbols, if a [[prop:style:symbol font]] is set for the text box. +| @""@ The text inside the tag is rendered with the given [[type:color]]. +| @""@ The text inside the tag is scaled by the a factor, for example @"text"@ makes the text twice as large. | @""@ Line breaks inside this tag use the [[prop:style:line height line]], and they show a horizontal line. | @""@ Line breaks inside this tag use the [[prop:style:soft line height]]. | @""@ An atomic piece of text. The cursor can never be inside it; it is selected as a whole. - The program automatically inserts + The program automatically inserts @""@. | @""@ The text inside the text is rendered in a monospace font. This is used for syntax highlighting script code. | @""@ The text inside the text is highlighted as a keyword in source code. | @""@ The text inside the text is highlighted as a string in source code. diff --git a/src/data/font.cpp b/src/data/font.cpp index f09d43fb..4fcf9c46 100644 --- a/src/data/font.cpp +++ b/src/data/font.cpp @@ -48,7 +48,7 @@ void Font::initDependencies(Context& ctx, const Dependency& dep) const { shadow_color.initDependencies(ctx, dep); } -FontP Font::make(int add_flags, Color* other_color) const { +FontP Font::make(int add_flags, Color* other_color, double* other_size) const { FontP f(new Font(*this)); f->flags |= add_flags; if (add_flags & FONT_CODE_STRING) { @@ -68,6 +68,9 @@ FontP Font::make(int add_flags, Color* other_color) const { if (other_color) { f->color = *other_color; } + if (other_size) { + f->size = *other_size; + } return f; } diff --git a/src/data/font.hpp b/src/data/font.hpp index bf459d53..4d775810 100644 --- a/src/data/font.hpp +++ b/src/data/font.hpp @@ -58,8 +58,8 @@ class Font : public IntrusivePtrBase { return shadow_displacement.width != 0 || shadow_displacement.height != 0; } - /// Add style to a font, and optionally change the color - FontP make(int add_flags, Color* other_color) const; + /// Add style to a font, and optionally change the color and size + FontP make(int add_flags, Color* other_color, double* other_size) const; /// Convert this font to a wxFont wxFont toWxFont(double scale) const; diff --git a/src/render/symbol/filter.cpp b/src/render/symbol/filter.cpp index bdf027af..7647f58b 100644 --- a/src/render/symbol/filter.cpp +++ b/src/render/symbol/filter.cpp @@ -20,12 +20,16 @@ template <> void GetDefaultMember::handle(const AColor& col) { } template <> void Reader::handle(AColor& col) { UInt r,g,b,a; - if (wxSscanf(getValue().c_str(),_("rgb(%u,%u,%u)"),&r,&g,&b)) { + String v = getValue(); + if (wxSscanf(v.c_str(),_("rgb(%u,%u,%u)"),&r,&g,&b)) { col.Set(r,g,b); col.alpha = 255; - } else if (wxSscanf(getValue().c_str(),_("rgba(%u,%u,%u,%u)"),&r,&g,&b,&a)) { + } else if (wxSscanf(v.c_str(),_("rgba(%u,%u,%u,%u)"),&r,&g,&b,&a)) { col.Set(r,g,b); col.alpha = a; + } else { + col = Color(v); + if (!col.Ok()) col = *wxBLACK; } } template <> void Writer::handle(const AColor& col) { diff --git a/src/render/text/element.cpp b/src/render/text/element.cpp index 8ebadf53..3dcf9843 100644 --- a/src/render/text/element.cpp +++ b/src/render/text/element.cpp @@ -76,6 +76,8 @@ struct TextElementsFromString { int soft, kwpph, param, line, soft_line; int code, code_kw, code_string, param_ref, error; int param_id; + vector colors; + vector sizes; /// put angle brackets around the text? bool bracket; @@ -121,6 +123,27 @@ struct TextElementsFromString { else if (is_substr(text, tag_start, _(":"), tag_start); + if (colon < pos - 1 && text.GetChar(colon) == _(':')) { + Color c = parse_color(text.substr(colon+1, pos-colon-2)); + if (!c.Ok()) c = style.font.color; + colors.push_back(c); + } + } else if (is_substr(text, tag_start, _(":"), tag_start); + if (colon < pos - 1 && text.GetChar(colon) == _(':')) { + double size = style.font.size; + String v = text.substr(colon+1, pos-colon-2); + v.ToDouble(&size); + sizes.push_back(size); + } + } else if (is_substr(text, tag_start, _(" @@ -222,7 +245,11 @@ struct TextElementsFromString { (code_string > 0 ? FONT_CODE_STRING : FONT_NORMAL), param > 0 || param_ref > 0 ? ¶m_colors[(param_id++) % param_colors_count] - : nullptr); + : !colors.empty() + ? &colors.back() + : nullptr, + !sizes.empty() ? &sizes.back() : nullptr + ); } }; diff --git a/src/util/io/reader.cpp b/src/util/io/reader.cpp index 8202145f..717b4e91 100644 --- a/src/util/io/reader.cpp +++ b/src/util/io/reader.cpp @@ -368,12 +368,15 @@ template <> void Reader::handle(Vector2D& vec) { } template <> void Reader::handle(Color& col) { + col = parse_color(getValue()); + if (!col.Ok()) col = *wxBLACK; +} +Color parse_color(const String& v) { UInt r,g,b; - if (wxSscanf(getValue().c_str(),_("rgb(%u,%u,%u)"),&r,&g,&b)) { - col.Set(r, g, b); + if (wxSscanf(v.c_str(),_("rgb(%u,%u,%u)"),&r,&g,&b)) { + return Color(r, g, b); } else { - col = Color(previous_value); - if (!col.Ok()) col = *wxBLACK; + return Color(v); } } diff --git a/src/util/io/reader.hpp b/src/util/io/reader.hpp index 8f9d0ccb..738dce00 100644 --- a/src/util/io/reader.hpp +++ b/src/util/io/reader.hpp @@ -251,6 +251,9 @@ void Reader::handle(IndexMap& m) { // ----------------------------------------------------------------------------- : Reflection for enumerations +/// Parse a color +Color parse_color(const String& value); + /// Implement enum reflection as used by Reader #define REFLECT_ENUM_READER(Enum) \ template<> void Reader::handle(Enum& enum_) { \