mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
feat: add internal support for underlined text (closes #29)
This commit is contained in:
+4
-1
@@ -50,7 +50,7 @@ void Font::initDependencies(Context& ctx, const Dependency& dep) const {
|
||||
shadow_color.initDependencies(ctx, dep);
|
||||
}
|
||||
|
||||
FontP Font::make(int add_flags, String const* other_family, Color const* other_color, double const* other_size) const {
|
||||
FontP Font::make(int add_flags, bool add_underline, 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) {
|
||||
@@ -66,6 +66,9 @@ FontP Font::make(int add_flags, String const* other_family, Color const* other_c
|
||||
if (add_flags & FONT_SOFT) {
|
||||
f->color = f->separator_color;
|
||||
f->shadow_displacement = RealSize(0,0); // no shadow
|
||||
}
|
||||
if (add_underline) {
|
||||
f->underline = true;
|
||||
}
|
||||
if (other_color) {
|
||||
f->color = *other_color;
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public:
|
||||
}
|
||||
|
||||
/// 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;
|
||||
FontP make(int add_flags, bool add_underline, String const* other_family, Color const* other_color, double const* other_size) const;
|
||||
|
||||
/// Convert this font to a wxFont
|
||||
wxFont toWxFont(double scale) const;
|
||||
|
||||
@@ -34,7 +34,7 @@ struct Margins {
|
||||
// Helper class for TextElements::fromString, to allow persistent formating state accross recusive calls
|
||||
struct TextElementsFromString {
|
||||
// What formatting is enabled?
|
||||
int bold = 0, italic = 0, symbol = 0;
|
||||
int bold = 0, italic = 0, underline = 0, symbol = 0;
|
||||
int soft = 0, kwpph = 0, param = 0, line = 0, soft_line = 0;
|
||||
int code = 0, code_kw = 0, code_string = 0, param_ref = 0;
|
||||
int param_id = 0, li = 0;
|
||||
@@ -78,7 +78,9 @@ private:
|
||||
if (is_tag(text, tag_start, _( "<b"))) bold += 1;
|
||||
else if (is_tag(text, tag_start, _("</b"))) bold -= 1;
|
||||
else if (is_tag(text, tag_start, _( "<i"))) italic += 1;
|
||||
else if (is_tag(text, tag_start, _("</i"))) italic -= 1;
|
||||
else if (is_tag(text, tag_start, _("</i"))) italic -= 1;
|
||||
else if (is_tag(text, tag_start, _("<u"))) underline += 1;
|
||||
else if (is_tag(text, tag_start, _("</u"))) underline -= 1;
|
||||
else if (is_tag(text, tag_start, _( "<sym"))) symbol += 1;
|
||||
else if (is_tag(text, tag_start, _("</sym"))) symbol -= 1;
|
||||
else if (is_tag(text, tag_start, _( "<line"))) line += 1;
|
||||
@@ -299,7 +301,8 @@ private:
|
||||
(kwpph > 0 ? FONT_SOFT : FONT_NORMAL) |
|
||||
(code > 0 ? FONT_CODE : FONT_NORMAL) |
|
||||
(code_kw > 0 ? FONT_CODE_KW : FONT_NORMAL) |
|
||||
(code_string > 0 ? FONT_CODE_STRING : FONT_NORMAL),
|
||||
(code_string > 0 ? FONT_CODE_STRING : FONT_NORMAL),
|
||||
underline > 0,
|
||||
fonts.empty() ? nullptr : &fonts.back(),
|
||||
param > 0 || param_ref > 0
|
||||
? ¶m_colors[(param_id++) % param_colors_count]
|
||||
|
||||
@@ -645,7 +645,7 @@ String simplify_tagged(const String& str) {
|
||||
// (where </tag> is the negation of tag)
|
||||
bool add_or_cancel_tag(const String& tag, String& stack, bool all = false) {
|
||||
if (all || starts_with(tag, _("/")) ||
|
||||
starts_with(tag, _("b")) || starts_with(tag, _("i")) || starts_with(tag, _("sym"))) {
|
||||
starts_with(tag, _("b")) || starts_with(tag, _("i")) || starts_with(tag, _("sym")) || starts_with(tag, _("u"))) {
|
||||
// cancel out all close tags, but not all open tags,
|
||||
// so <xx></xx> is always removed
|
||||
// but </xx><xx> is not
|
||||
@@ -692,8 +692,8 @@ String simplify_tagged_overlap(const String& str) {
|
||||
Char c = str.GetChar(i);
|
||||
if (c == _('<')) {
|
||||
String tag = tag_at(str, i);
|
||||
if (starts_with(tag, _("b")) || starts_with(tag, _("i")) || starts_with(tag, _("sym")) ||
|
||||
starts_with(tag, _("/b")) || starts_with(tag, _("/i")) || starts_with(tag, _("/sym"))) {
|
||||
if (starts_with(tag, _("b")) || starts_with(tag, _("i")) || starts_with(tag, _("sym")) || starts_with(tag, _("u")) ||
|
||||
starts_with(tag, _("/b")) || starts_with(tag, _("/i")) || starts_with(tag, _("/sym")) || starts_with(tag, _("/u"))) {
|
||||
// optimize this tag
|
||||
if (open_tags.find(_("<") + tag + _(">")) == String::npos) {
|
||||
// we are not already inside this tag
|
||||
|
||||
Reference in New Issue
Block a user