diff --git a/changelog b/changelog index e687e5c7324..9d36fa3a8e2 100644 --- a/changelog +++ b/changelog @@ -36,6 +36,7 @@ Version 1.7.2+svn: leader is on a keep. (bug #13856 and #13855) * wmllint updated to accomodate new drake names. Gladiator changes must still be done by hand. + * No longer "crash" upon invalid pango markup Version 1.7.2: * Campaigns: diff --git a/src/gui/auxiliary/canvas.cpp b/src/gui/auxiliary/canvas.cpp index 4cda68872ed..58ea3b3ff45 100644 --- a/src/gui/auxiliary/canvas.cpp +++ b/src/gui/auxiliary/canvas.cpp @@ -884,9 +884,13 @@ void ttext::draw(surface& canvas, } static font::ttext text_renderer; + if(!text_renderer.set_text(text, text_markup_(variables))) { + ERR_GUI_D << "Text: Invalid markup in '" + << text << "' rendered as is.\n"; + text_renderer.set_text(text, false); + } - text_renderer.set_text(text, text_markup_(variables)). - set_font_size(font_size_). + text_renderer.set_font_size(font_size_). set_font_style(font_style_). set_foreground_colour(colour_). set_maximum_width(maximum_width_(variables)). @@ -898,7 +902,7 @@ void ttext::draw(surface& canvas, surface surf = text_renderer.render(); if(surf->w == 0) { - DBG_GUI_D << "Text: Rendering '" << + DBG_GUI_D << "Text: Rendering '" << text << "' resulted in an empty canvas, leave.\n"; return; } diff --git a/src/storyscreen/render.cpp b/src/storyscreen/render.cpp index 6319fad6ed4..6219d5d7cc4 100644 --- a/src/storyscreen/render.cpp +++ b/src/storyscreen/render.cpp @@ -268,8 +268,13 @@ void part_ui::render_title_box() titlebox_max_h = base_rect_.h - 2*titlebox_padding; font::ttext t; - t.set_text(titletxt, true) - .set_font_style(font::ttext::STYLE_NORMAL) + if(!t.set_text(titletxt, true)) { + ERR_NG << "Text: Invalid markup in '" + << titletxt << "' rendered as is.\n"; + t.set_text(titletxt, false); + } + + t.set_font_style(font::ttext::STYLE_NORMAL) .set_font_size(titlebox_font_size) .set_foreground_colour(titlebox_font_color) .set_maximum_width(titlebox_max_w) @@ -373,8 +378,12 @@ void part_ui::render_story_box() bool skip = false, last_key = true; font::ttext t; - t.set_text(p_.text(), true) - .set_font_style(font::ttext::STYLE_NORMAL) + if(!t.set_text(p_.text(), true)) { + ERR_NG << "Text: Invalid markup in '" + << p_.text() << "' rendered as is.\n"; + t.set_text(p_.text(), false); + } + t.set_font_style(font::ttext::STYLE_NORMAL) .set_foreground_colour(storybox_font_color) .set_maximum_width(max_width) .set_maximum_height(max_height); diff --git a/src/text.cpp b/src/text.cpp index 73d50a97308..94b4c899ee4 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -254,12 +254,17 @@ gui2::tpoint ttext::get_column_line(const gui2::tpoint& position) const } } -ttext& ttext::set_text(const std::string& text, const bool markedup) +bool ttext::set_text(const std::string& text, const bool markedup) { if(markedup != markedup_text_ || text != text_) { assert(layout_); if(markedup) { + if(!pango_parse_markup(text.c_str(), text.size() + , 0, NULL, NULL, NULL, NULL)) { + + return false; + } pango_layout_set_markup(layout_, text.c_str(), text.size()); } else { /* @@ -277,7 +282,7 @@ ttext& ttext::set_text(const std::string& text, const bool markedup) surface_dirty_ = true; } - return *this; + return true; } ttext& ttext::set_font_size(const unsigned font_size) diff --git a/src/text.hpp b/src/text.hpp index 925dbe86b35..4e7e96c4535 100644 --- a/src/text.hpp +++ b/src/text.hpp @@ -148,9 +148,22 @@ public: */ size_t get_length() const { return length_; } + /** + * Sets the text to render. + * + * @param text The text to render. + * @param markedup Should the text be rendered with pango + * markup. If the markup is invalid it's + * rendered as text without markup. + * + * @returns The status, if rendered as markup and the + * markup contains errors, false is returned + * else true. + */ + bool set_text(const std::string& text, const bool markedup); + /***** ***** ***** ***** Setters / getters ***** ***** ***** *****/ - ttext& set_text(const std::string& text, const bool markedup); const std::string& text() const { return text_; } ttext& set_font_size(const unsigned font_size);