widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #13975
[Merge] lp:~widelands-dev/widelands/rip_out_old_fontrenderer into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/rip_out_old_fontrenderer into lp:widelands.
Commit message:
Removed the legacy font renderer
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/rip_out_old_fontrenderer/+merge/350442
Since we broke savegame compatibility, we don't need to keep it around any more.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/rip_out_old_fontrenderer into lp:widelands.
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2017-12-02 12:43:38 +0000
+++ src/CMakeLists.txt 2018-07-23 09:14:48 +0000
@@ -108,7 +108,6 @@
editor
graphic
graphic_fonthandler
- graphic_fonthandler_legacy
graphic_text
graphic_text_constants
helper
=== modified file 'src/editor/ui_menus/main_menu_load_or_save_map.cc'
--- src/editor/ui_menus/main_menu_load_or_save_map.cc 2018-04-27 06:11:05 +0000
+++ src/editor/ui_menus/main_menu_load_or_save_map.cc 2018-07-23 09:14:48 +0000
@@ -25,7 +25,7 @@
#include "base/i18n.h"
#include "base/wexception.h"
#include "editor/editorinteractive.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "io/filesystem/filesystem.h"
#include "io/filesystem/layered_filesystem.h"
#include "map_io/widelands_map_loader.h"
@@ -58,7 +58,7 @@
directory_info_(this, padding_, get_inner_h() - 2 * buth_ - 4 * padding_),
ok_(this,
"ok",
- UI::g_fh1->fontset()->is_rtl() ? get_inner_w() / 2 - butw_ - padding_ :
+ UI::g_fh->fontset()->is_rtl() ? get_inner_w() / 2 - butw_ - padding_ :
get_inner_w() / 2 + padding_,
get_inner_h() - padding_ - buth_,
butw_,
@@ -67,7 +67,7 @@
_("OK")),
cancel_(this,
"cancel",
- UI::g_fh1->fontset()->is_rtl() ? get_inner_w() / 2 + padding_ :
+ UI::g_fh->fontset()->is_rtl() ? get_inner_w() / 2 + padding_ :
get_inner_w() / 2 - butw_ - padding_,
get_inner_h() - padding_ - buth_,
butw_,
=== modified file 'src/editor/ui_menus/main_menu_map_options.cc'
--- src/editor/ui_menus/main_menu_map_options.cc 2018-05-13 07:15:39 +0000
+++ src/editor/ui_menus/main_menu_map_options.cc 2018-07-23 09:14:48 +0000
@@ -26,7 +26,7 @@
#include "base/i18n.h"
#include "editor/editorinteractive.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "logic/map.h"
#include "ui_basic/editbox.h"
@@ -51,7 +51,7 @@
max_w_(get_inner_w() - 2 * padding_),
ok_(this,
"ok",
- UI::g_fh1->fontset()->is_rtl() ? padding_ : butw_ + 2 * padding_,
+ UI::g_fh->fontset()->is_rtl() ? padding_ : butw_ + 2 * padding_,
get_inner_h() - padding_ - labelh_,
butw_,
labelh_,
@@ -59,7 +59,7 @@
_("OK")),
cancel_(this,
"cancel",
- UI::g_fh1->fontset()->is_rtl() ? butw_ + 2 * padding_ : padding_,
+ UI::g_fh->fontset()->is_rtl() ? butw_ + 2 * padding_ : padding_,
get_inner_h() - padding_ - labelh_,
butw_,
labelh_,
=== modified file 'src/editor/ui_menus/main_menu_new_map.cc'
--- src/editor/ui_menus/main_menu_new_map.cc 2018-04-27 06:11:05 +0000
+++ src/editor/ui_menus/main_menu_new_map.cc 2018-07-23 09:14:48 +0000
@@ -28,7 +28,7 @@
#include "base/i18n.h"
#include "base/macros.h"
#include "editor/editorinteractive.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/image.h"
#include "graphic/texture.h"
#include "logic/editor_game_base.h"
@@ -118,7 +118,7 @@
cancel_button_.sigclicked.connect(boost::bind(&MainMenuNewMap::clicked_cancel, this));
ok_button_.sigclicked.connect(boost::bind(&MainMenuNewMap::clicked_create_map, this));
- if (UI::g_fh1->fontset()->is_rtl()) {
+ if (UI::g_fh->fontset()->is_rtl()) {
button_box_.add(&ok_button_);
button_box_.add(&cancel_button_);
} else {
=== modified file 'src/editor/ui_menus/main_menu_random_map.cc'
--- src/editor/ui_menus/main_menu_random_map.cc 2018-04-27 06:11:05 +0000
+++ src/editor/ui_menus/main_menu_random_map.cc 2018-07-23 09:14:48 +0000
@@ -31,7 +31,7 @@
#include "base/wexception.h"
#include "editor/editorinteractive.h"
#include "editor/map_generator.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "logic/editor_game_base.h"
#include "logic/map.h"
#include "logic/map_objects/world/world.h"
@@ -378,7 +378,7 @@
// ---------- "Generate Map" button ----------
cancel_button_.sigclicked.connect(boost::bind(&MainMenuNewRandomMap::clicked_cancel, this));
ok_button_.sigclicked.connect(boost::bind(&MainMenuNewRandomMap::clicked_create_map, this));
- if (UI::g_fh1->fontset()->is_rtl()) {
+ if (UI::g_fh->fontset()->is_rtl()) {
button_box_.add(&ok_button_);
button_box_.add(&cancel_button_);
} else {
=== modified file 'src/editor/ui_menus/main_menu_save_map_make_directory.cc'
--- src/editor/ui_menus/main_menu_save_map_make_directory.cc 2018-06-01 08:50:29 +0000
+++ src/editor/ui_menus/main_menu_save_map_make_directory.cc 2018-07-23 09:14:48 +0000
@@ -20,7 +20,7 @@
#include "editor/ui_menus/main_menu_save_map_make_directory.h"
#include "base/i18n.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "io/filesystem/layered_filesystem.h"
MainMenuSaveMapMakeDirectory::MainMenuSaveMapMakeDirectory(UI::Panel* const parent,
@@ -41,7 +41,7 @@
edit_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, 0, 4, UI::PanelStyle::kWui),
ok_button_(this,
"ok",
- UI::g_fh1->fontset()->is_rtl() ? padding_ : get_inner_w() - butw_ - padding_,
+ UI::g_fh->fontset()->is_rtl() ? padding_ : get_inner_w() - butw_ - padding_,
get_inner_h() - padding_ - buth_,
butw_,
buth_,
@@ -49,7 +49,7 @@
_("OK")),
cancel_button_(this,
"cancel",
- UI::g_fh1->fontset()->is_rtl() ? get_inner_w() - butw_ - padding_ : padding_,
+ UI::g_fh->fontset()->is_rtl() ? get_inner_w() - butw_ - padding_ : padding_,
get_inner_h() - padding_ - buth_,
butw_,
buth_,
=== modified file 'src/graphic/CMakeLists.txt'
--- src/graphic/CMakeLists.txt 2018-07-08 09:53:54 +0000
+++ src/graphic/CMakeLists.txt 2018-07-23 09:14:48 +0000
@@ -245,44 +245,11 @@
)
-# Font handlers and text
-
-wl_library(graphic_fonthandler_legacy
+# Font handler and text
+wl_library(graphic_fonthandler
SRCS
- font.cc
- font.h
font_handler.cc
font_handler.h
- richtext.cc
- richtext.h
- text_parser.cc
- text_parser.h
- USES_ICU
- USES_SDL2_TTF
- DEPENDS
- base_exceptions
- base_geometry
- base_i18n
- base_log
- base_utf8
- graphic
- graphic_align
- graphic_color
- graphic_fonthandler
- graphic_surface
- graphic_text
- graphic_text_constants
- graphic_text_layout
- graphic_wordwrap
- helper
- io_fileread
- io_filesystem
-)
-
-wl_library(graphic_fonthandler
- SRCS
- font_handler1.cc
- font_handler1.h
DEPENDS
base_macros
graphic_image_cache
=== removed file 'src/graphic/font.cc'
--- src/graphic/font.cc 2018-04-07 16:59:00 +0000
+++ src/graphic/font.cc 1970-01-01 00:00:00 +0000
@@ -1,245 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "graphic/font.h"
-
-#include <map>
-
-#include <unicode/unistr.h>
-
-#include "base/i18n.h"
-#include "base/utf8.h"
-#include "graphic/font_handler1.h" // We need the fontset for the size offset
-#include "graphic/text/bidi.h"
-#include "graphic/text/font_set.h"
-#include "graphic/text_constants.h"
-#include "io/filesystem/layered_filesystem.h"
-
-namespace {
-
-struct FontDescr {
- std::string name;
- int size;
-
- bool operator<(const FontDescr& o) const {
- return size < o.size || (size == o.size && name < o.name);
- }
-};
-
-using FontMap = std::map<FontDescr, UI::Font*>;
-
-FontMap g_fontmap;
-
-} // anonymous namespace
-
-namespace UI {
-
-/**
- * Open a font file and load the corresponding font.
- */
-Font::Font(const std::string& name, int input_size) {
- // Load the TrueType Font
- std::string filename = "i18n/fonts/";
- filename += name;
- size_ = input_size;
-
- // We must keep this File Read open, otherwise the following calls are
- // crashing. do not know why...
- fontfile_.open(*g_fs, filename);
-
- SDL_RWops* const ops = SDL_RWFromMem(fontfile_.data(0), fontfile_.get_size());
- if (!ops)
- throw wexception("could not load font!: RWops Pointer invalid");
-
- font_ = TTF_OpenFontIndexRW(ops, 1, input_size, 0);
- if (!font_)
- throw wexception("could not load font!: %s", TTF_GetError());
-
- // Compute the line skip based on some glyphs by sampling some letters,
- // special characters, and accented/umlauted versions of capital A
- // It seems more reasonable to use TTF_FontLineSkip(), but the fonts
- // we use claim to have a very excessive line skip.
- static uint16_t glyphs[] = {
- 'A', '_', '@', ',', 'q', 'y', '"', 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5};
- computed_typical_miny_ = 0;
- computed_typical_maxy_ = 0;
-
- for (unsigned int idx = 0; idx < sizeof(glyphs) / sizeof(glyphs[0]); ++idx) {
- int miny, maxy;
- if (TTF_GlyphMetrics(font_, glyphs[idx], nullptr, nullptr, &miny, &maxy, nullptr) < 0)
- continue; // error, e.g. glyph not found
-
- if (miny < computed_typical_miny_)
- computed_typical_miny_ = miny;
- if (maxy > computed_typical_maxy_)
- computed_typical_maxy_ = maxy;
- }
-}
-
-/**
- * Free all resources associated with this font.
- */
-Font::~Font() {
- TTF_CloseFont(font_);
- font_ = nullptr;
-}
-
-/**
- * \return the maximum height of glyphs of this font.
- */
-uint32_t Font::height() const {
- return TTF_FontHeight(font_);
-}
-
-/**
- * \return the maximum height of glyphs of this font.
- */
-uint32_t Font::size() const {
- return size_;
-}
-
-/**
- * \return the maximum ascent from the font baseline
- */
-uint32_t Font::ascent() const {
- return TTF_FontAscent(font_);
-}
-
-/**
- * Return the font for the given name and size.
- *
- * \note Fonts are cached and need not be freed explicitly. \see shutdown
- */
-Font* Font::get(const std::string& name, int size) {
- size += UI::g_fh1->fontset()->size_offset();
- FontDescr descr;
- descr.name = name;
- descr.size = size;
-
- FontMap::iterator it = g_fontmap.find(descr);
- if (it == g_fontmap.end()) {
- Font* font = new Font(name, size);
- it = g_fontmap.insert(std::make_pair(descr, font)).first;
- }
-
- return it->second;
-}
-
-/**
- * Free all registered fonts.
- */
-void Font::shutdown() {
- while (!g_fontmap.empty()) {
- delete g_fontmap.begin()->second;
- g_fontmap.erase(g_fontmap.begin());
- }
-}
-
-/**
- * Prepare the TTF style settings for rendering in this style.
- */
-void TextStyle::setup() const {
- int32_t font_style = TTF_STYLE_NORMAL;
- if (bold)
- font_style |= TTF_STYLE_BOLD;
- if (italics)
- font_style |= TTF_STYLE_ITALIC;
- if (underline)
- font_style |= TTF_STYLE_UNDERLINE;
- TTF_SetFontStyle(font->get_ttf_font(), font_style);
-}
-
-/**
- * Get a width estimate for text wrapping.
- */
-uint32_t TextStyle::calc_width_for_wrapping(const UChar& c) const {
- int result = 0;
- TTF_GlyphMetrics(font->get_ttf_font(), c, nullptr, nullptr, nullptr, nullptr, &result);
- return result;
-}
-
-/**
- * Get a width estimate for text wrapping.
- */
-uint32_t TextStyle::calc_width_for_wrapping(const std::string& text) const {
- int result = 0;
- const icu::UnicodeString parseme(text.c_str(), "UTF-8");
- for (int i = 0; i < parseme.length(); ++i) {
- UChar c = parseme.charAt(i);
- if (!i18n::is_diacritic(c)) {
- result += calc_width_for_wrapping(c);
- }
- }
- return result;
-}
-
-/**
- * Compute the bare width (without caret padding) of the given string.
- */
-uint32_t TextStyle::calc_bare_width(const std::string& text) const {
- int w, h;
- setup();
-
- TTF_SizeUTF8(font->get_ttf_font(), text.c_str(), &w, &h);
- return w;
-}
-
-/**
- * \note Please only use this function once you understand the definitions
- * of ascent/descent etc.
- *
- * Computes the actual line height we should use for rendering the given text.
- * This is heuristic, because it pre-initializes the miny and maxy values to
- * the ones that are typical for Latin scripts, so that lineskips should always
- * be the same for such scripts.
- */
-void TextStyle::calc_bare_height_heuristic(const std::string& text,
- int32_t& miny,
- int32_t& maxy) const {
- miny = font->computed_typical_miny_;
- maxy = font->computed_typical_maxy_;
-
- setup();
- std::string::size_type pos = 0;
- while (pos < text.size()) {
- uint16_t ch = Utf8::utf8_to_unicode(text, pos);
- int32_t glyphminy, glyphmaxy;
- TTF_GlyphMetrics(font->get_ttf_font(), ch, nullptr, nullptr, &glyphminy, &glyphmaxy, nullptr);
- miny = std::min(miny, glyphminy);
- maxy = std::max(maxy, glyphmaxy);
- }
-}
-
-/*
-=============================
-
-Default styles
-
-=============================
-*/
-
-TextStyle::TextStyle()
- : font(Font::get(UI::g_fh1->fontset()->sans(), UI_FONT_SIZE_SMALL)),
- fg(UI_FONT_CLR_FG),
- bold(true),
- italics(false),
- underline(false) {
-}
-
-} // namespace UI
=== removed file 'src/graphic/font.h'
--- src/graphic/font.h 2018-04-07 16:59:00 +0000
+++ src/graphic/font.h 1970-01-01 00:00:00 +0000
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef WL_GRAPHIC_FONT_H
-#define WL_GRAPHIC_FONT_H
-
-#include <SDL_ttf.h>
-#include <unicode/uchar.h>
-
-#include "graphic/color.h"
-#include "io/fileread.h"
-
-namespace UI {
-
-struct TextStyle;
-
-/**
- * Margin around text that is kept to make space for the caret.
- */
-#define LINE_MARGIN 1
-
-/**
- * Wrapper object around a font.
- *
- * Fonts in our sense are defined by the general font shape (given by the font
- * name) and the size of the font.
- */
-struct Font {
- friend struct TextStyle;
-
- static void shutdown();
- static Font* get(const std::string& name, int size);
-
- uint32_t size() const;
- uint32_t ascent() const;
- uint32_t height() const;
-
- TTF_Font* get_ttf_font() const {
- return font_;
- }
-
-private:
- Font(const std::string& name, int size);
- ~Font();
-
- FileRead fontfile_;
- TTF_Font* font_;
-
- /**
- * Work around weird fonts with very large lineskip, to get something
- * that makes more sense as the default skip in Latin scripts.
- */
- int32_t computed_typical_miny_;
- int32_t computed_typical_maxy_;
-
- int size_;
-};
-
-/**
- * Text style combines font with other characteristics like color
- * and style (italics, bold).
- */
-// TODO(GunChleoc): This struct will disappear with the old font handler
-struct TextStyle {
- TextStyle();
-
- static TextStyle makebold(Font* font, RGBColor fg) {
- TextStyle ts;
- ts.font = font;
- ts.bold = true;
- ts.fg = fg;
- return ts;
- }
-
- uint32_t calc_bare_width(const std::string& text) const;
- uint32_t calc_width_for_wrapping(const UChar& c) const;
- uint32_t calc_width_for_wrapping(const std::string& text) const;
- void calc_bare_height_heuristic(const std::string& text, int32_t& miny, int32_t& maxy) const;
- void setup() const;
-
- Font* font;
- RGBColor fg;
- bool bold : 1;
- bool italics : 1;
- bool underline : 1;
-
- bool operator==(const TextStyle& o) const {
- return font == o.font && fg == o.fg && bold == o.bold && italics == o.italics &&
- underline == o.underline;
- }
- bool operator!=(const TextStyle& o) const {
- return !(*this == o);
- }
-};
-
-} // namespace UI
-
-#endif // end of include guard: WL_GRAPHIC_FONT_H
=== removed file 'src/graphic/font_handler.cc'
--- src/graphic/font_handler.cc 2018-04-07 16:59:00 +0000
+++ src/graphic/font_handler.cc 1970-01-01 00:00:00 +0000
@@ -1,255 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Some Methods taken from Wesnoth.
- * http://www.wesnoth.org
- */
-
-#include "graphic/font_handler.h"
-
-#include <list>
-#include <memory>
-
-#include <SDL_ttf.h>
-#include <boost/algorithm/string.hpp>
-#include <boost/format.hpp>
-
-#include "base/log.h"
-#include "base/wexception.h"
-#include "graphic/font.h"
-#include "graphic/font_handler1.h" // We need the fontset for the BiDi algorithm
-#include "graphic/graphic.h"
-#include "graphic/rendertarget.h"
-#include "graphic/text/bidi.h"
-#include "graphic/text_layout.h"
-#include "graphic/texture.h"
-#include "graphic/wordwrap.h"
-
-namespace UI {
-
-namespace {
-/**
- * Draw the caret for the given text rendered exactly at the given point
- * (including \ref LINE_MARGIN).
- */
-void draw_caret(RenderTarget& dst,
- const TextStyle& style,
- const Vector2f& dstpoint,
- const std::string& text,
- uint32_t caret_offset) {
- int caret_x = style.calc_bare_width(text.substr(0, caret_offset));
-
- const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png");
- Vector2i caretpt = Vector2i::zero();
- caretpt.x = dstpoint.x + caret_x + LINE_MARGIN - caret_image->width();
- caretpt.y = dstpoint.y + (style.font->height() - caret_image->height()) / 2;
- dst.blit(caretpt, caret_image);
-}
-
-} // namespace
-
-/// The global unique \ref FontHandler object
-FontHandler* g_fh = nullptr;
-
-/**
- * The line cache stores unprocessed rendered lines of text.
- */
-struct LineCacheEntry {
- /*@{*/
- TextStyle style;
- std::string text;
- /*@}*/
-
- /*@{*/
- std::unique_ptr<const Image> image;
- uint32_t width;
- uint32_t height;
- /*@}*/
-};
-
-using LineCache = std::list<LineCacheEntry>;
-
-static const unsigned MaxLineCacheSize = 500;
-
-/**
- * Internal data of the \ref FontHandler.
- */
-struct FontHandler::Data {
- LineCache linecache;
-
- const LineCacheEntry& get_line(const TextStyle& style, const std::string& text);
-
- ~Data() {
- while (!linecache.empty()) {
- linecache.pop_back();
- }
- }
-
-private:
- void render_line(LineCacheEntry& lce);
-};
-
-/**
- * Plain Constructor
- */
-FontHandler::FontHandler() : d(new Data) {
-}
-
-FontHandler::~FontHandler() {
- flush();
- Font::shutdown();
-}
-
-void FontHandler::flush() {
- d.reset(new Data);
-}
-
-/**
- * Get a cache entry for the given text (without linebreaks!) rendered
- * in the given style.
- *
- * If there is no pre-existing cache entry, a new one is created.
- */
-const LineCacheEntry& FontHandler::Data::get_line(const UI::TextStyle& style,
- const std::string& text) {
- for (LineCache::iterator it = linecache.begin(); it != linecache.end(); ++it) {
- if (it->style != style || it->text != text)
- continue;
-
- // Found a hit, move to front
- if (it != linecache.begin())
- linecache.splice(linecache.begin(), linecache, it);
- return *it;
- }
-
- // Cache miss; render a new image.
- LineCache::iterator it = linecache.insert(linecache.begin(), LineCacheEntry());
- it->style = style;
- it->text = text;
- it->image = nullptr;
- render_line(*it);
-
- while (linecache.size() > MaxLineCacheSize) {
- linecache.pop_back();
- }
-
- return *it;
-}
-
-/**
- * Render the image of a \ref LineCacheEntry whose key data has
- * already been filled in.
- */
-void FontHandler::Data::render_line(LineCacheEntry& lce) {
- TTF_Font* font = lce.style.font->get_ttf_font();
- SDL_Color sdl_fg = {lce.style.fg.r, lce.style.fg.g, lce.style.fg.b, SDL_ALPHA_OPAQUE};
- std::string renderme = i18n::make_ligatures(lce.text.c_str());
-
- if (i18n::has_rtl_character(lce.text.c_str())) {
- renderme = i18n::line2bidi(renderme.c_str());
- }
-
- // Work around an Issue in SDL_TTF that dies when the surface
- // has zero width
- int width = 0;
- if (TTF_SizeUTF8(font, renderme.c_str(), &width, nullptr) < 0 || !width) {
- lce.width = 0;
- lce.height = TTF_FontHeight(font);
- return;
- }
-
- lce.style.setup();
-
- SDL_Surface* text_surface = TTF_RenderUTF8_Blended(font, renderme.c_str(), sdl_fg);
- if (!text_surface) {
- log("FontHandler::render_line, an error : %s\n", TTF_GetError());
- log("Text was: '%s'\n", renderme.c_str());
- return;
- }
-
- lce.image.reset(new Texture(text_surface));
- lce.width = lce.image->width();
- lce.height = lce.image->height();
-}
-
-/**
- * Draw unwrapped, single-line text (i.e. no line breaks).
- */
-void FontHandler::draw_text(RenderTarget& dst,
- const TextStyle& style,
- Vector2i dstpoint,
- const std::string& text,
- Align align,
- uint32_t caret) {
- // Erase every backslash in front of brackets
- std::string copytext = boost::replace_all_copy(text, "\\<", "<");
- boost::replace_all(copytext, "\\>", ">");
- copytext = i18n::make_ligatures(copytext.c_str());
- const LineCacheEntry& lce = d->get_line(style, copytext);
-
- UI::correct_for_align(align, lce.width + 2 * LINE_MARGIN, &dstpoint);
-
- if (lce.image)
- dst.blit(Vector2i(dstpoint.x + LINE_MARGIN, dstpoint.y), lce.image.get());
-
- if (caret <= copytext.size())
- draw_caret(dst, style, dstpoint.cast<float>(), copytext, caret);
-}
-
-/**
- * Draw unwrapped, un-aligned single-line text at the given point, and return the width of the text.
- */
-uint32_t FontHandler::draw_text_raw(RenderTarget& dst,
- const UI::TextStyle& style,
- Vector2i dstpoint,
- const std::string& text) {
- const LineCacheEntry& lce = d->get_line(style, text);
-
- if (lce.image) {
- dst.blit(dstpoint, lce.image.get());
- }
-
- return lce.width;
-}
-
-/**
- * Compute the total size of the given text, when wrapped to the given
- * maximum width and rendered in the given text style.
- */
-void FontHandler::get_size(
- const TextStyle& textstyle, const std::string& text, uint32_t& w, uint32_t& h, uint32_t wrap) {
- WordWrap ww(textstyle.font->size(), textstyle.fg, wrap);
- ww.wrap(text);
- w = ww.width();
- h = ww.height();
-}
-
-/**
- * Calculates size of a given text.
- */
-void FontHandler::get_size(const std::string& fontname,
- int32_t const fontsize,
- const std::string& text,
- uint32_t& w,
- uint32_t& h,
- uint32_t const wrap) {
- // use bold style by default for historical reasons
- get_size(TextStyle::makebold(Font::get(fontname, fontsize), RGBColor(255, 255, 255)), text, w, h,
- wrap);
-}
-
-} // namespace UI
=== renamed file 'src/graphic/font_handler1.cc' => 'src/graphic/font_handler.cc'
--- src/graphic/font_handler1.cc 2018-04-07 16:59:00 +0000
+++ src/graphic/font_handler.cc 2018-07-23 09:14:48 +0000
@@ -17,7 +17,7 @@
*
*/
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include <memory>
@@ -53,7 +53,7 @@
// Utility class to render a rich text string. The returned string is cached in
// the ImageCache, so repeated calls to render with the same arguments should not
// be a problem.
-class FontHandler1 : public IFontHandler1 {
+class FontHandler : public IFontHandler {
private:
// A transient cache for the generated rendered texts
class RenderCache : public TransientCache<RenderedText> {
@@ -69,7 +69,7 @@
};
public:
- FontHandler1(ImageCache* image_cache, const std::string& locale)
+ FontHandler(ImageCache* image_cache, const std::string& locale)
: texture_cache_(new TextureCache(kTextureCacheSize)),
render_cache_(new RenderCache(kRenderCacheSize)),
fontsets_(),
@@ -77,7 +77,7 @@
rt_renderer_(new RT::Renderer(image_cache, texture_cache_.get(), fontsets_)),
image_cache_(image_cache) {
}
- ~FontHandler1() override {
+ ~FontHandler() override {
}
// This will render the 'text' with a width restriction of 'w'. If 'w' == 0, no restriction is
@@ -112,10 +112,10 @@
ImageCache* const image_cache_; // not owned
};
-IFontHandler1* create_fonthandler(ImageCache* image_cache, const std::string& locale) {
- return new FontHandler1(image_cache, locale);
+IFontHandler* create_fonthandler(ImageCache* image_cache, const std::string& locale) {
+ return new FontHandler(image_cache, locale);
}
-IFontHandler1* g_fh1 = nullptr;
+IFontHandler* g_fh = nullptr;
} // namespace UI
=== removed file 'src/graphic/font_handler.h'
--- src/graphic/font_handler.h 2018-04-07 16:59:00 +0000
+++ src/graphic/font_handler.h 1970-01-01 00:00:00 +0000
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef WL_GRAPHIC_FONT_HANDLER_H
-#define WL_GRAPHIC_FONT_HANDLER_H
-
-#include <limits>
-#include <memory>
-#include <string>
-
-#include "base/vector.h"
-#include "graphic/align.h"
-
-class RenderTarget;
-
-namespace UI {
-
-struct TextStyle;
-
-/**
- * Main class for string rendering. Manages the cache of pre-rendered strings.
- */
-struct FontHandler {
- FontHandler();
- ~FontHandler();
-
- void draw_text(RenderTarget&,
- const TextStyle&,
- Vector2i dstpoint,
- const std::string& text,
- Align align = UI::Align::kLeft,
- uint32_t caret = std::numeric_limits<uint32_t>::max());
- uint32_t
- draw_text_raw(RenderTarget&, const TextStyle&, Vector2i dstpoint, const std::string& text);
-
- void get_size(const TextStyle&,
- const std::string& text,
- uint32_t& w,
- uint32_t& h,
- uint32_t wrap = std::numeric_limits<uint32_t>::max());
- void get_size(const std::string& fontname,
- int32_t size,
- const std::string& text,
- uint32_t& w,
- uint32_t& h,
- uint32_t wrap = std::numeric_limits<uint32_t>::max());
-
- // Delete the whole cache.
- void flush();
-
-private:
- struct Data;
- std::unique_ptr<Data> d;
-};
-
-extern FontHandler* g_fh;
-}
-
-#endif // end of include guard: WL_GRAPHIC_FONT_HANDLER_H
=== renamed file 'src/graphic/font_handler1.h' => 'src/graphic/font_handler.h'
--- src/graphic/font_handler1.h 2018-04-07 16:59:00 +0000
+++ src/graphic/font_handler.h 2018-07-23 09:14:48 +0000
@@ -33,10 +33,10 @@
/**
* Main class for string rendering. Manages the cache of pre-rendered strings.
*/
-class IFontHandler1 {
+class IFontHandler {
public:
- IFontHandler1() = default;
- virtual ~IFontHandler1() {
+ IFontHandler() = default;
+ virtual ~IFontHandler() {
}
/// Renders the given text into a set of images. The images are cached in a transient cache,
@@ -52,13 +52,13 @@
/// game has changed.
virtual void reinitialize_fontset(const std::string& locale) = 0;
- DISALLOW_COPY_AND_ASSIGN(IFontHandler1);
+ DISALLOW_COPY_AND_ASSIGN(IFontHandler);
};
-/// Create a new FontHandler1.
-IFontHandler1* create_fonthandler(ImageCache* image_cache, const std::string& locale);
+/// Create a new FontHandler.
+IFontHandler* create_fonthandler(ImageCache* image_cache, const std::string& locale);
-extern IFontHandler1* g_fh1;
+extern IFontHandler* g_fh;
}
#endif // end of include guard: WL_GRAPHIC_FONT_HANDLER1_H
=== removed file 'src/graphic/richtext.cc'
--- src/graphic/richtext.cc 2018-04-07 16:59:00 +0000
+++ src/graphic/richtext.cc 1970-01-01 00:00:00 +0000
@@ -1,508 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "graphic/richtext.h"
-
-#include "base/rect.h"
-#include "graphic/font.h"
-#include "graphic/font_handler.h"
-#include "graphic/font_handler1.h" // Needed for fontset's direction
-#include "graphic/graphic.h"
-#include "graphic/image.h"
-#include "graphic/rendertarget.h"
-#include "graphic/text/bidi.h"
-#include "graphic/text_layout.h"
-#include "graphic/text_parser.h"
-
-namespace UI {
-
-namespace {
-int32_t const h_space = 3;
-} // namespace
-
-/**
- * Layouted rich text is essentially a bunch of drawable elements, each with a
- * rectangular bounding box.
- */
-struct Element {
- explicit Element(const Recti& bounding_box) : bbox(bounding_box) {
- }
- virtual ~Element() {
- }
-
- /**
- * Draw the element, assuming that @p dst is already set up to be
- * relative to the element's internal frame of reference.
- */
- virtual void draw(RenderTarget& dst) = 0;
-
- Recti bbox;
-};
-
-struct ImageElement : Element {
- ImageElement(const Recti& bounding_box, const Image* init_image)
- : Element(bounding_box), image(init_image) {
- }
-
- void draw(RenderTarget& dst) override {
- dst.blit(Vector2i::zero(), image);
- }
-
- const Image* image;
-};
-
-struct TextlineElement : Element {
- TextlineElement(const Recti& bounding_box,
- const TextStyle& init_style,
- std::vector<std::string>::const_iterator words_begin,
- std::vector<std::string>::const_iterator words_end)
- : Element(bounding_box), style(init_style), words(words_begin, words_end) {
- }
-
- void draw(RenderTarget& dst) override {
- assert(words.size());
- uint32_t spacewidth = style.calc_bare_width(" ");
-
- std::vector<std::string> result_words;
- std::vector<std::string>::iterator it = result_words.begin();
-
- // Reorder words for BiDi
- if (UI::g_fh1->fontset()->is_rtl() && i18n::has_rtl_character(words)) {
- std::string previous_word;
- for (std::vector<std::string>::iterator source_it = words.begin();
- source_it != words.end(); ++source_it) {
- std::string& word = *source_it;
- if (source_it != words.end()) {
- if (i18n::has_rtl_character(word.c_str()) ||
- i18n::has_rtl_character(previous_word.c_str())) {
- it = result_words.insert(result_words.begin(), word);
- } else { // Sequences of Latin words go to the right from current position
- if (it < result_words.end()) {
- ++it;
- }
- it = result_words.insert(it, word);
- }
- previous_word = word;
- }
- }
- } else {
- for (std::string& word : words) {
- result_words.push_back(word);
- }
- }
- // Now render
- uint32_t x = g_fh->draw_text_raw(dst, style, Vector2i::zero(), result_words[0]);
-
- it = result_words.begin() + 1;
- if (it != result_words.end()) {
- do {
- if (style.underline)
- x += g_fh->draw_text_raw(dst, style, Vector2i(x, 0), " ");
- else
- x += spacewidth;
- x += g_fh->draw_text_raw(dst, style, Vector2i(x, 0), *it++);
- } while (it != result_words.end());
- }
- }
-
- TextStyle style;
- std::vector<std::string> words;
-};
-
-struct RichTextImpl {
- /// Solid background color for all elements
- RGBColor background_color;
-
- /// Layouted elements
- std::vector<Element*> elements;
-
- /// Width of the rich-text area, controlled by the user of the
- /// rich-text field
- uint32_t width;
-
- /// Height of parsed rich-text area, determined by layouting
- uint32_t height;
-
- RichTextImpl();
- ~RichTextImpl();
-
- void clear();
-};
-
-RichText::RichText() : m(new RichTextImpl) {
-}
-
-RichText::~RichText() {
-}
-
-RichTextImpl::RichTextImpl() : background_color(0, 0, 0) {
- width = 0;
- height = 0;
-}
-
-RichTextImpl::~RichTextImpl() {
- clear();
-}
-
-/**
- * Reset all layouting data.
- */
-void RichTextImpl::clear() {
- while (!elements.empty()) {
- delete elements.back();
- elements.pop_back();
- }
-
- height = 0;
-}
-
-/**
- * Set the width for the rich text field.
- * Default width is undefined. This must be called before @ref parse.
- */
-void RichText::set_width(uint32_t gwidth) {
- m->width = gwidth;
-}
-
-/**
- * Set a solid background color that is used by @ref draw when a
- * solid background is requested.
- */
-void RichText::set_background_color(RGBColor color) {
- m->background_color = color;
-}
-
-/**
- * @return the width of the rich text field, set by @ref set_width
- */
-uint32_t RichText::width() {
- return m->width;
-}
-
-/**
- * @return the actual total height of layouted rich text, computed by @ref parse
- */
-uint32_t RichText::height() {
- return m->height;
-}
-
-struct TextBuilder {
- RichTextImpl& rti;
-
- /// Current richtext block
- std::vector<RichtextBlock>::iterator richtext;
-
- /// Extent of images in the current richtext block
- /*@{*/
- uint32_t images_width;
- uint32_t images_height;
- /*@}*/
-
- /// Maximum width, in pixels, for current line of text
- uint32_t maxwidth;
-
- /// y-coordinate of top of current line of text
- uint32_t text_y;
-
- /// Width of the current line, in pixels
- uint32_t linewidth;
-
- /// Current text block
- std::vector<TextBlock>::const_iterator textblock;
- TextStyle style;
- uint32_t spacewidth;
- uint32_t linespacing;
-
- struct Elt {
- TextlineElement* element;
- int32_t miny, maxy;
- };
-
- /// Elements in the current line (also already added to the full richtext list
- /// of elements, but we keep this around to store miny/maxy data to adjust all
- /// parts of a line onto the same text baseline).
- std::vector<Elt> elements;
-
- explicit TextBuilder(RichTextImpl& impl)
- : rti(impl),
- images_width(0),
- images_height(0),
- maxwidth(0),
- text_y(0),
- linewidth(0),
- spacewidth(0),
- linespacing(0) {
- }
-
- /**
- * Update data that is specific to the current @ref textblock.
- */
- void reset_block() {
- style.font = Font::get(textblock->get_font_face(), textblock->get_font_size());
- style.fg = textblock->get_font_color();
-
- style.bold = textblock->get_font_weight() == "bold";
- style.italics = textblock->get_font_style() == "italic";
- style.underline = textblock->get_font_decoration() == "underline";
-
- spacewidth = style.calc_bare_width(" ");
- linespacing = textblock->get_line_spacing();
- }
-
- /**
- * Properly align elements in the current line, and advance @ref text_y and
- * other data so that we can begin the next line.
- */
- void advance_line() {
- int32_t miny = 0;
- int32_t maxy = 0;
-
- if (elements.empty()) {
- style.calc_bare_height_heuristic(" ", miny, maxy);
- } else {
- int32_t alignref_left = 0;
- int32_t alignref_right = rti.width;
-
- if (text_y < rti.height + images_height) {
- if (mirror_alignment(richtext->get_image_align()) == UI::Align::kRight) {
- alignref_right -= images_width + h_space;
- } else {
- // Note: center image alignment with text is not properly supported
- // It is unclear what the semantics should be.
- alignref_left += images_width + h_space;
- }
- }
-
- int32_t textleft = 0;
-
- switch (mirror_alignment(richtext->get_text_align())) {
- case UI::Align::kRight:
- textleft = alignref_right - int32_t(linewidth);
- break;
- case UI::Align::kCenter:
- textleft = alignref_left + (alignref_right - alignref_left - int32_t(linewidth)) / 2;
- break;
- case UI::Align::kLeft:
- textleft = alignref_left;
- break;
- }
-
- for (std::vector<Elt>::const_iterator it = elements.begin(); it != elements.end(); ++it) {
- it->element->bbox.x += textleft;
- miny = std::min(miny, it->miny);
- maxy = std::max(maxy, it->maxy);
- }
-
- int32_t baseline = text_y + maxy;
- for (std::vector<Elt>::const_iterator it = elements.begin(); it != elements.end(); ++it)
- it->element->bbox.y = baseline - it->element->style.font->ascent();
- }
-
- text_y += maxy - miny + linespacing;
- if (text_y >= rti.height + images_height)
- maxwidth = rti.width;
-
- elements.clear();
- linewidth = 0;
- }
-};
-
-/**
- * Parse and layout the given rich text.
- */
-void RichText::parse(const std::string& rtext) {
- m->clear();
-
- std::vector<RichtextBlock> blocks;
- TextParser p;
- std::string copy(rtext);
- p.parse(copy, blocks);
-
- // Guard against weirdness in text and image alignment
- m->width = std::min(m->width, uint32_t(std::numeric_limits<int32_t>::max()));
-
- TextBuilder text(*m);
-
- for (text.richtext = blocks.begin(); text.richtext != blocks.end(); ++text.richtext) {
- const std::vector<TextBlock>& cur_text_blocks = text.richtext->get_text_blocks();
- const std::vector<std::string>& cur_block_images = text.richtext->get_images();
-
- // First obtain the data of all images of this richtext block and prepare
- // the corresponding elements, then do the alignment once the total width
- // is known
- const uint32_t firstimageelement = m->elements.size();
- text.images_height = 0;
- text.images_width = 0;
-
- for (std::vector<std::string>::const_iterator image_it = cur_block_images.begin();
- image_it != cur_block_images.end(); ++image_it) {
- const Image* image = g_gr->images().get(*image_it);
- if (!image)
- continue;
-
- Recti bbox;
- bbox.x = text.images_width;
- bbox.y = m->height;
- bbox.w = image->width();
- bbox.h = image->height();
-
- text.images_height = std::max<int>(text.images_height, bbox.h);
- text.images_width += bbox.w;
-
- m->elements.push_back(new ImageElement(bbox, image));
- }
-
- // Fix up the alignment
- int32_t imagealigndelta = 0;
-
- switch (mirror_alignment(text.richtext->get_image_align())) {
- case UI::Align::kCenter:
- imagealigndelta = (int32_t(m->width) - int32_t(text.images_width)) / 2;
- break;
- case UI::Align::kRight:
- imagealigndelta = int32_t(m->width) - int32_t(text.images_width);
- break;
- case UI::Align::kLeft:
- break;
- }
-
- for (uint32_t idx = firstimageelement; idx < m->elements.size(); ++idx)
- m->elements[idx]->bbox.x += imagealigndelta;
-
- // Now layout the text elements; they are already broken down to words,
- // which makes our job a bit easier.
- text.text_y = m->height;
- text.maxwidth = m->width;
- text.linewidth = 0;
-
- if (text.images_height > 0) {
- if (h_space + text.images_width < text.maxwidth)
- text.maxwidth -= h_space + text.images_width;
- else
- text.text_y = m->height + text.images_height;
- }
-
- text.textblock = cur_text_blocks.begin();
-
- while (text.textblock != cur_text_blocks.end()) {
- text.reset_block();
-
- const std::vector<std::string>& words = text.textblock->get_words();
- const std::vector<std::vector<std::string>::size_type>& line_breaks =
- text.textblock->get_line_breaks();
-
- uint32_t word_cnt = 0;
- std::vector<std::vector<std::string>::size_type>::const_iterator br_it =
- line_breaks.begin();
-
- while (word_cnt < words.size() || br_it != line_breaks.end()) {
- if (br_it != line_breaks.end() && *br_it <= word_cnt) {
- text.advance_line();
- ++br_it;
- continue;
- }
-
- // Now eat up words up to the next line break
- assert(word_cnt < words.size());
-
- bool wrap = false;
- uint32_t nrwords = 0;
- TextBuilder::Elt elt;
- elt.miny = elt.maxy = 0;
-
- Recti bbox;
- bbox.x = text.linewidth ? text.linewidth + text.spacewidth : 0;
- bbox.y = 0; // filled in later
- bbox.w = 0;
- bbox.h = text.style.font->height();
-
- // TODO(GunChleoc): Arabic: width calculation for alignment is broken (Arabic)
- do {
- uint32_t wordwidth = text.style.calc_bare_width(words[word_cnt + nrwords]);
-
- if (nrwords)
- wordwidth += text.spacewidth;
-
- // Break only if this is not the first word of the line
- if ((text.linewidth || nrwords) && bbox.x + bbox.w + wordwidth > text.maxwidth) {
- wrap = true;
- break;
- }
-
- int32_t wordminy, wordmaxy;
- text.style.calc_bare_height_heuristic(words[word_cnt + nrwords], wordminy, wordmaxy);
- elt.maxy = std::max(elt.maxy, wordmaxy);
- elt.miny = std::min(elt.miny, wordminy);
-
- bbox.w += wordwidth;
- ++nrwords;
- } while (word_cnt + nrwords < words.size() &&
- (br_it == line_breaks.end() || *br_it > word_cnt + nrwords));
-
- if (nrwords) {
- m->elements.push_back(new TextlineElement(
- bbox, text.style, words.begin() + word_cnt, words.begin() + word_cnt + nrwords));
- word_cnt += nrwords;
-
- elt.element = static_cast<TextlineElement*>(m->elements.back());
- text.elements.push_back(elt);
- text.linewidth = bbox.x + bbox.w;
- }
-
- if (wrap)
- text.advance_line();
- }
-
- ++text.textblock;
- }
-
- if (!text.elements.empty())
- text.advance_line();
-
- // Update total height
- m->height = std::max(m->height + text.images_height, text.text_y);
- }
-}
-
-/**
- * Draw pre-parsed and layouted rich text content at the given offset.
- *
- * @p background if true, all richtext elements are given a solid background,
- * per the color set by @ref set_background_color
- *
- * @note this function may draw content outside the box given offset
- * and @ref width and @ref height, if there were wrapping problems.
- */
-void RichText::draw(RenderTarget& dst, const Vector2i& offset, bool background) {
- for (std::vector<Element*>::const_iterator elt = m->elements.begin(); elt != m->elements.end();
- ++elt) {
- Recti oldbox;
- Vector2i oldofs = Vector2i::zero();
- Recti bbox((*elt)->bbox.origin() + offset, (*elt)->bbox.w, (*elt)->bbox.h);
-
- if (dst.enter_window(bbox, &oldbox, &oldofs)) {
- if (background)
- dst.fill_rect(Recti(0, 0, bbox.w, bbox.h), m->background_color);
- (*elt)->draw(dst);
- dst.set_window(oldbox, oldofs);
- }
- }
-}
-
-} // namespace UI
=== removed file 'src/graphic/richtext.h'
--- src/graphic/richtext.h 2018-04-07 16:59:00 +0000
+++ src/graphic/richtext.h 1970-01-01 00:00:00 +0000
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef WL_GRAPHIC_RICHTEXT_H
-#define WL_GRAPHIC_RICHTEXT_H
-
-#include <limits>
-#include <memory>
-#include <string>
-
-#include "base/vector.h"
-#include "graphic/color.h"
-
-class RenderTarget;
-
-namespace UI {
-
-struct RichTextImpl;
-
-/**
- * Provides rich-text layouting and rendering functionality.
- *
- * Layouts the rich text as a tight fit, i.e. without any border around the
- * text. The final, layouted extents of the text can be obtained from @ref width and @ref height.
- */
-struct RichText {
- RichText();
- ~RichText();
-
- void set_width(uint32_t width = std::numeric_limits<uint32_t>::max());
- void set_background_color(RGBColor color);
-
- uint32_t width();
- uint32_t height();
-
- void parse(const std::string& text);
- void draw(RenderTarget& dst, const Vector2i& offset, bool background = false);
-
-private:
- std::unique_ptr<RichTextImpl> m;
-};
-
-} // namespace UI
-
-#endif // end of include guard: WL_GRAPHIC_RICHTEXT_H
=== modified file 'src/graphic/text_layout.cc'
--- src/graphic/text_layout.cc 2018-07-19 13:34:59 +0000
+++ src/graphic/text_layout.cc 2018-07-23 09:14:48 +0000
@@ -25,7 +25,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/image.h"
#include "graphic/text/bidi.h"
@@ -50,18 +50,18 @@
}
int text_width(const std::string& text, int ptsize) {
- return UI::g_fh1->render(
+ return UI::g_fh->render(
as_editorfont(
text.substr(
0, g_gr->max_texture_size_for_font_rendering() / text_height() - 1),
- ptsize - UI::g_fh1->fontset()->size_offset()))
+ ptsize - UI::g_fh->fontset()->size_offset()))
->width();
}
int text_height(int ptsize, UI::FontSet::Face face) {
- return UI::g_fh1->render(as_aligned(UI::g_fh1->fontset()->representative_character(),
+ return UI::g_fh->render(as_aligned(UI::g_fh->fontset()->representative_character(),
UI::Align::kLeft,
- ptsize - UI::g_fh1->fontset()->size_offset(),
+ ptsize - UI::g_fh->fontset()->size_offset(),
RGBColor(0, 0, 0), face))
->height();
}
@@ -243,10 +243,10 @@
std::shared_ptr<const UI::RenderedText>
autofit_ui_text(const std::string& text, int width, RGBColor color, int fontsize) {
std::shared_ptr<const UI::RenderedText> result =
- UI::g_fh1->render(as_uifont(richtext_escape(text), fontsize, color));
+ UI::g_fh->render(as_uifont(richtext_escape(text), fontsize, color));
if (width > 0) { // Autofit
for (; result->width() > width && fontsize >= kMinimumFontSize; --fontsize) {
- result = UI::g_fh1->render(
+ result = UI::g_fh->render(
as_condensed(richtext_escape(text), UI::Align::kLeft, fontsize, color));
}
}
@@ -264,7 +264,7 @@
* character. Otherwise, mirror if the current fontset is RTL.
*/
Align mirror_alignment(Align alignment, const std::string& checkme) {
- bool do_swap_alignment = checkme.empty() ? UI::g_fh1->fontset()->is_rtl() :
+ bool do_swap_alignment = checkme.empty() ? UI::g_fh->fontset()->is_rtl() :
i18n::has_rtl_character(checkme.c_str(), 20);
if (do_swap_alignment) {
switch (alignment) {
=== modified file 'src/graphic/text_layout.h'
--- src/graphic/text_layout.h 2018-07-19 13:34:59 +0000
+++ src/graphic/text_layout.h 2018-07-23 09:14:48 +0000
@@ -24,7 +24,7 @@
#include "graphic/align.h"
#include "graphic/color.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/image.h"
#include "graphic/panel_styles.h"
#include "graphic/text/font_set.h"
=== removed file 'src/graphic/text_parser.cc'
--- src/graphic/text_parser.cc 2018-04-07 16:59:00 +0000
+++ src/graphic/text_parser.cc 1970-01-01 00:00:00 +0000
@@ -1,286 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "graphic/text_parser.h"
-
-#include <algorithm>
-#include <cstring>
-#include <string>
-#include <vector>
-
-#include "base/log.h"
-#include "graphic/font_handler1.h"
-#include "graphic/text/bidi.h"
-#include "graphic/text/font_set.h"
-#include "graphic/text_layout.h"
-#include "helper.h"
-
-namespace UI {
-
-RichtextBlock::RichtextBlock() : image_align_(UI::Align::kLeft), text_align_(UI::Align::kLeft) {
-}
-
-RichtextBlock::RichtextBlock(const RichtextBlock& src) {
- images_.clear();
- text_blocks_.clear();
- for (uint32_t i = 0; i < src.images_.size(); ++i)
- images_.push_back(src.images_[i]);
- for (uint32_t i = 0; i < src.text_blocks_.size(); ++i)
- text_blocks_.push_back(src.text_blocks_[i]);
- image_align_ = src.image_align_;
- text_align_ = src.text_align_;
-}
-
-TextBlock::TextBlock()
- : font_size_(10),
- font_color_(RGBColor(255, 255, 0)),
- font_weight_("normal"),
- font_style_("normal"),
- font_decoration_("none"),
- font_face_((UI::g_fh1->fontset())->sans()),
- line_spacing_(0) {
-}
-
-void TextParser::parse(std::string& text, std::vector<RichtextBlock>& blocks) {
- bool more_richtext_blocks = true;
- // First while loop parses all richtext blocks (images)
- while (more_richtext_blocks) {
- RichtextBlock new_richtext_block;
- std::string unparsed_text;
- std::string richtext_format;
-
- more_richtext_blocks =
- extract_format_block(text, unparsed_text, richtext_format, std::string("<rt"),
- std::string(">"), std::string("</rt>"));
- parse_richtexttext_attributes(richtext_format, &new_richtext_block);
-
- std::vector<TextBlock> text_blocks;
-
- // Second while loop parses all textblocks of current richtext block
- bool more_text_blocks = true;
- while (more_text_blocks) {
- std::string block_format;
- TextBlock new_block;
-
- std::vector<std::string> words;
- std::vector<std::vector<std::string>::size_type> line_breaks;
-
- more_text_blocks = parse_textblock(unparsed_text, block_format, words, line_breaks);
- parse_text_attributes(block_format, new_block);
-
- new_block.set_words(words);
- new_block.set_line_breaks(line_breaks);
- text_blocks.push_back(new_block);
- }
- new_richtext_block.set_text_blocks(text_blocks);
- blocks.push_back(new_richtext_block);
- }
-}
-
-bool TextParser::parse_textblock(std::string& block,
- std::string& block_format,
- std::vector<std::string>& words,
- std::vector<std::vector<std::string>::size_type>& line_breaks) {
- std::string block_text;
-
- const bool extract_more =
- extract_format_block(block, block_text, block_format, "<p", ">", "</p>");
-
- // Split the the text because of " "
- std::vector<std::string> unwrapped_words;
- split_words(block_text, &unwrapped_words);
-
- // Handle user defined line breaks, and save them
- for (const std::string& temp_words : unwrapped_words) {
- for (std::string line = temp_words;;) {
- line = i18n::make_ligatures(line.c_str());
- std::string::size_type next_break = line.find("<br>");
-
- if (next_break == std::string::npos) {
- if (line.size()) {
- std::string word = line;
- replace_entities(&word);
- words.push_back(word);
- }
- break;
- } else if (next_break) {
- std::string word = line.substr(0, next_break);
- replace_entities(&word);
- words.push_back(word);
- }
- line_breaks.push_back(words.size());
- line.erase(0, next_break + 4);
- }
- }
- return extract_more;
-}
-
-void TextParser::split_words(const std::string& in, std::vector<std::string>* plist) {
- std::string::size_type pos = 0;
-
- while (pos < in.size()) {
- while (pos < in.size() && isspace(in[pos]))
- ++pos;
- if (pos >= in.size())
- break;
-
- std::string::size_type nextspace = pos;
- while (nextspace < in.size() && !isspace(in[nextspace]))
- ++nextspace;
-
- if (nextspace > pos)
- plist->push_back(in.substr(pos, nextspace - pos));
-
- pos = nextspace;
- }
-}
-
-bool TextParser::extract_format_block(std::string& block,
- std::string& block_text,
- std::string& block_format,
- const std::string& block_start,
- const std::string& format_end,
- const std::string& block_end) {
- if (block.compare(0, block_start.size(), block_start)) {
- const std::string::size_type format_begin_pos = block.find(block_start);
- if (format_begin_pos == std::string::npos) {
- return false;
- }
- block.erase(0, format_begin_pos);
- }
-
- block.erase(0, block_start.size());
- if (block.size() && *block.begin() == ' ')
- block.erase(0, 1);
-
- const std::string::size_type format_end_pos = block.find(format_end);
- if (format_end_pos == std::string::npos) {
- return false;
- }
-
- // Append block_format
- block_format.erase();
- block_format.append(block.substr(0, format_end_pos));
-
- // Delete whole format block
- block.erase(0, format_end_pos + format_end.size());
-
- // Find end of block
- const std::string::size_type block_end_pos = block.find(block_end);
- if (block_end_pos == std::string::npos) {
- return false;
- }
- // Extract text of block
- block_text.erase();
- block_text.append(block.substr(0, block_end_pos));
-
- // Erase text including closing tag
- block.erase(0, block_end_pos + block_end.size());
- // Is something left
- return block.find(block_start) != std::string::npos;
-}
-
-void TextParser::parse_richtexttext_attributes(std::string format, RichtextBlock* const element) {
- if (format.empty())
- return;
- if (format[0] == ' ')
- format.erase(0, 1);
-
- while (format.size()) {
- std::string::size_type const key_end = format.find('=');
- if (key_end == std::string::npos)
- return;
- else {
- std::string const key = format.substr(0, key_end);
- format.erase(0, key_end + 1);
- std::string::size_type val_end = format.find(' ');
- if (val_end == std::string::npos)
- val_end = format.size();
- std::string val = format.substr(0, val_end);
- format.erase(0, val_end + 1);
- if (key == "image") {
- const std::vector<std::string> images(split_string(val, ";"));
- element->set_images(images);
- } else if (key == "image-align")
- element->set_image_align(set_align(val));
- else if (key == "text-align")
- element->set_text_align(set_align(val));
- }
- }
-}
-
-void TextParser::parse_text_attributes(std::string format, TextBlock& element) {
- if (format.empty())
- return;
- if (format[0] == ' ')
- format.erase(0, 1);
-
- while (format.size()) {
- std::string::size_type const key_end = format.find('=');
- if (key_end == std::string::npos) {
- return;
- } else {
- std::string key = format.substr(0, key_end);
- format.erase(0, key_end + 1);
- std::string::size_type val_end = format.find(' ');
- if (val_end == std::string::npos)
- val_end = format.size();
- std::string val = format.substr(0, val_end);
- format.erase(0, val_end + 1);
- if (key == "font-size") {
- element.set_font_size(atoi(val.c_str()));
- } else if (key == "font-face") {
- const UI::FontSet& fontset = *UI::g_fh1->fontset();
- if (val == fontset.condensed() || val == "condensed") {
- val = fontset.condensed();
- } else if (val == fontset.serif() || val == "serif") {
- val = fontset.serif();
- } else {
- val = fontset.sans();
- }
- element.set_font_style(val);
- } else if (key == "line-spacing") {
- element.set_line_spacing(atoi(val.c_str()));
- } else if (key == "font-color") {
- std::string::size_type const offset = val[0] == '#';
- std::string const r = "0x" + val.substr(offset, 2);
- std::string const g = "0x" + val.substr(offset + 2, 2);
- std::string const b = "0x" + val.substr(offset + 4, 2);
-
- char* ptr;
- long int const red = strtol(r.c_str(), &ptr, 0);
- long int const green = strtol(g.c_str(), &ptr, 0);
- long int const blue = strtol(b.c_str(), &ptr, 0);
- element.set_font_color(RGBColor(red, green, blue));
- } else if (key == "font-weight") {
- element.set_font_weight(val);
- } else if (key == "font-style") {
- element.set_font_style(val);
- } else if (key == "font-decoration") {
- element.set_font_decoration(val);
- }
- }
- }
-}
-
-Align TextParser::set_align(const std::string& align) {
- return align == "right" ? UI::Align::kRight : align == "center" ? UI::Align::kCenter :
- UI::Align::kLeft;
-}
-}
=== removed file 'src/graphic/text_parser.h'
--- src/graphic/text_parser.h 2018-04-07 16:59:00 +0000
+++ src/graphic/text_parser.h 1970-01-01 00:00:00 +0000
@@ -1,185 +0,0 @@
-/*
- * Copyright (C) 2002-2018 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef WL_GRAPHIC_TEXT_PARSER_H
-#define WL_GRAPHIC_TEXT_PARSER_H
-
-#include <string>
-#include <vector>
-
-#include "graphic/align.h"
-#include "graphic/color.h"
-
-namespace UI {
-
-/**
- * Corresponds to a richtext block that is enclosed in <p></p> tags.
- * Has uniform font style, contains text pre-split into words, and keeps track of
- * manual line breaks (<br>) in a separate structure.
- */
-struct TextBlock {
- TextBlock();
- // Copy and assignement operators are autogenerated.
-
- void set_font_size(int32_t const font_size) {
- font_size_ = font_size;
- }
- int32_t get_font_size() const {
- return font_size_;
- }
-
- void set_font_color(const RGBColor& font_color) {
- font_color_ = font_color;
- }
- RGBColor get_font_color() const {
- return font_color_;
- }
-
- void set_font_weight(const std::string& font_weight) {
- font_weight_ = font_weight;
- }
- const std::string& get_font_weight() const {
- return font_weight_;
- }
-
- void set_font_style(const std::string& font_style) {
- font_style_ = font_style;
- }
- const std::string& get_font_style() const {
- return font_style_;
- }
-
- void set_font_decoration(const std::string& font_decoration) {
- font_decoration_ = font_decoration;
- }
- const std::string& get_font_decoration() const {
- return font_decoration_;
- }
-
- void set_font_face(const std::string& font_face) {
- font_face_ = font_face;
- }
- const std::string& get_font_face() const {
- return font_face_;
- }
-
- void set_line_spacing(int32_t const line_spacing) {
- line_spacing_ = line_spacing;
- }
- int32_t get_line_spacing() const {
- return line_spacing_;
- }
-
- void set_words(const std::vector<std::string>& words) {
- words_ = words;
- }
- const std::vector<std::string>& get_words() const {
- return words_;
- }
-
- void set_line_breaks(const std::vector<std::vector<std::string>::size_type>& line_breaks) {
- line_breaks_ = line_breaks;
- }
- const std::vector<std::vector<std::string>::size_type>& get_line_breaks() const {
- return line_breaks_;
- }
-
-private:
- int32_t font_size_;
- RGBColor font_color_;
- std::string font_weight_;
- std::string font_style_;
- std::string font_decoration_;
- std::string font_face_;
- int32_t line_spacing_;
- std::vector<std::string> words_;
-
- /**
- * Position of manual line breaks (<br>) with respect to @ref words_.
- * Sorted in ascending order.
- * An entry j in this vector means that a manual line break occurs
- * before the j-th word in @ref words_. In particular, an entry 0
- * means that a manual line break occurs before the first word.
- * Entries can appear with multiplicity, indicating that multiple
- * manual line breaks exist without any words in-between.
- */
- std::vector<std::vector<std::string>::size_type> line_breaks_;
-};
-
-struct RichtextBlock {
- RichtextBlock();
- RichtextBlock(const RichtextBlock& src);
-
- void set_images(const std::vector<std::string>& images) {
- images_ = images;
- }
- const std::vector<std::string>& get_images() const {
- return images_;
- }
-
- void set_image_align(Align const image_align) {
- image_align_ = image_align;
- }
- Align get_image_align() const {
- return image_align_;
- }
-
- void set_text_align(Align const text_align) {
- text_align_ = text_align;
- }
- Align get_text_align() const {
- return text_align_;
- }
-
- void set_text_blocks(const std::vector<TextBlock>& text_blocks) {
- text_blocks_ = text_blocks;
- }
- const std::vector<TextBlock>& get_text_blocks() const {
- return text_blocks_;
- }
-
-private:
- std::vector<std::string> images_;
- std::vector<TextBlock> text_blocks_;
- Align image_align_;
- Align text_align_;
-};
-
-struct TextParser {
- void parse(std::string& text, std::vector<RichtextBlock>& blocks);
-
-private:
- void parse_richtexttext_attributes(std::string format, RichtextBlock*);
- bool parse_textblock(std::string& block,
- std::string& block_format,
- std::vector<std::string>& words,
- std::vector<std::vector<std::string>::size_type>& line_breaks);
- void parse_text_attributes(std::string format, TextBlock&);
- bool extract_format_block(std::string& block,
- std::string& block_text,
- std::string& block_format,
- const std::string& block_start,
- const std::string& format_end,
- const std::string& block_end);
- Align set_align(const std::string&);
- void split_words(const std::string& in, std::vector<std::string>* plist);
-};
-}
-
-#endif // end of include guard: WL_GRAPHIC_TEXT_PARSER_H
=== modified file 'src/graphic/wordwrap.cc'
--- src/graphic/wordwrap.cc 2018-04-07 16:59:00 +0000
+++ src/graphic/wordwrap.cc 2018-07-23 09:14:48 +0000
@@ -29,7 +29,7 @@
#include "base/log.h"
#include "graphic/color.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text/bidi.h"
@@ -42,7 +42,7 @@
: draw_caret_(false),
fontsize_(fontsize),
color_(color),
- font_(RT::load_font(UI::g_fh1->fontset()->sans_bold(), fontsize_)) {
+ font_(RT::load_font(UI::g_fh->fontset()->sans_bold(), fontsize_)) {
wrapwidth_ = gwrapwidth;
if (wrapwidth_ < std::numeric_limits<uint32_t>::max()) {
@@ -312,8 +312,8 @@
point.x += wrapwidth_ - kLineMargin;
}
- std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh1->render(
- as_editorfont(lines_[line].text, fontsize_ - UI::g_fh1->fontset()->size_offset(), color_));
+ std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(
+ as_editorfont(lines_[line].text, fontsize_ - UI::g_fh->fontset()->size_offset(), color_));
UI::correct_for_align(alignment, rendered_text->width(), &point);
rendered_text->draw(dst, point);
=== modified file 'src/logic/map_objects/map_object.cc'
--- src/logic/map_objects/map_object.cc 2018-07-08 15:16:16 +0000
+++ src/logic/map_objects/map_object.cc 2018-07-23 09:14:48 +0000
@@ -29,7 +29,7 @@
#include "base/log.h"
#include "base/wexception.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text_layout.h"
@@ -489,7 +489,7 @@
// We always render this so we can have a stable position for the statistics string.
std::shared_ptr<const UI::RenderedText> rendered_census =
- UI::g_fh1->render(as_condensed(census, UI::Align::kCenter, font_size), 120 * scale);
+ UI::g_fh->render(as_condensed(census, UI::Align::kCenter, font_size), 120 * scale);
Vector2i position = field_on_dst.cast<int>() - Vector2i(0, 48) * scale;
if (draw_text & TextToDraw::kCensus) {
rendered_census->draw(*dst, position, UI::Align::kCenter);
@@ -497,7 +497,7 @@
if (draw_text & TextToDraw::kStatistics && !statictics.empty()) {
std::shared_ptr<const UI::RenderedText> rendered_statistics =
- UI::g_fh1->render(as_condensed(statictics, UI::Align::kCenter, font_size));
+ UI::g_fh->render(as_condensed(statictics, UI::Align::kCenter, font_size));
position.y += rendered_census->height() + text_height(font_size) / 4;
rendered_statistics->draw(*dst, position, UI::Align::kCenter);
}
=== modified file 'src/ui_basic/CMakeLists.txt'
--- src/ui_basic/CMakeLists.txt 2017-06-12 11:07:47 +0000
+++ src/ui_basic/CMakeLists.txt 2018-07-23 09:14:48 +0000
@@ -64,7 +64,6 @@
graphic_align
graphic_color
graphic_fonthandler
- graphic_fonthandler_legacy
graphic_styles
graphic_surface
graphic_text
=== modified file 'src/ui_basic/button.cc'
--- src/ui_basic/button.cc 2018-07-08 12:08:11 +0000
+++ src/ui_basic/button.cc 2018-07-23 09:14:48 +0000
@@ -19,7 +19,7 @@
#include "ui_basic/button.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/image.h"
#include "graphic/rendertarget.h"
=== modified file 'src/ui_basic/checkbox.cc'
--- src/ui_basic/checkbox.cc 2018-04-07 16:59:00 +0000
+++ src/ui_basic/checkbox.cc 2018-07-23 09:14:48 +0000
@@ -19,7 +19,7 @@
#include "ui_basic/checkbox.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text_layout.h"
@@ -81,7 +81,7 @@
}
rendered_text_ = label_text_.empty() ?
nullptr :
- UI::g_fh1->render(as_uifont(label_text_), text_width(get_w(), pic_width));
+ UI::g_fh->render(as_uifont(label_text_), text_width(get_w(), pic_width));
if (rendered_text_.get()) {
w = std::max(rendered_text_->width() + kPadding + pic_width, w);
h = std::max(rendered_text_->height(), h);
@@ -147,7 +147,7 @@
Vector2i text_anchor(kStateboxSize + kPadding, 0);
if (rendered_text_.get()) {
- if (UI::g_fh1->fontset()->is_rtl()) {
+ if (UI::g_fh->fontset()->is_rtl()) {
text_anchor.x = 0;
image_anchor.x = rendered_text_->width() + kPadding;
image_anchor.y = (get_h() - kStateboxSize) / 2;
=== modified file 'src/ui_basic/dropdown.cc'
--- src/ui_basic/dropdown.cc 2018-07-13 11:23:52 +0000
+++ src/ui_basic/dropdown.cc 2018-07-23 09:14:48 +0000
@@ -26,7 +26,7 @@
#include "base/i18n.h"
#include "base/macros.h"
#include "graphic/align.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "ui_basic/mouse_constants.h"
@@ -38,7 +38,7 @@
int base_height(int button_dimension) {
return std::max(
button_dimension,
- UI::g_fh1->render(as_uifont(UI::g_fh1->fontset()->representative_character()))->height() + 2);
+ UI::g_fh->render(as_uifont(UI::g_fh->fontset()->representative_character()))->height() + 2);
}
} // namespace
=== modified file 'src/ui_basic/editbox.cc'
--- src/ui_basic/editbox.cc 2018-06-01 08:54:25 +0000
+++ src/ui_basic/editbox.cc 2018-07-23 09:14:48 +0000
@@ -25,7 +25,7 @@
#include <boost/format.hpp>
#include "graphic/color.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/style_manager.h"
@@ -89,11 +89,11 @@
set_thinks(false);
m_->background_style = g_gr->styles().editbox_style(style);
- m_->fontname = UI::g_fh1->fontset()->sans();
+ m_->fontname = UI::g_fh->fontset()->sans();
m_->fontsize = font_size;
// Set alignment to the UI language's principal writing direction
- m_->align = UI::g_fh1->fontset()->is_rtl() ? UI::Align::kRight : UI::Align::kLeft;
+ m_->align = UI::g_fh->fontset()->is_rtl() ? UI::Align::kRight : UI::Align::kLeft;
m_->caret = 0;
m_->scrolloffset = 0;
// yes, use *signed* max as maximum length; just a small safe-guard.
@@ -367,7 +367,7 @@
const int max_width = get_w() - 2 * kMarginX;
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_editorfont(m_->text, m_->fontsize));
+ UI::g_fh->render(as_editorfont(m_->text, m_->fontsize));
const int linewidth = rendered_text->width();
const int lineheight = m_->text.empty() ? text_height(m_->fontsize) : rendered_text->height();
@@ -381,7 +381,7 @@
// Crop to max_width while blitting
if (max_width < linewidth) {
// Fix positioning for BiDi languages.
- if (UI::g_fh1->fontset()->is_rtl()) {
+ if (UI::g_fh->fontset()->is_rtl()) {
point.x = 0.f;
}
// We want this always on, e.g. for mixed language savegame filenames
=== modified file 'src/ui_basic/fileview_panel.cc'
--- src/ui_basic/fileview_panel.cc 2018-05-13 07:15:39 +0000
+++ src/ui_basic/fileview_panel.cc 2018-07-23 09:14:48 +0000
@@ -56,15 +56,7 @@
size_t index = boxes_.size() - 1;
UI::MultilineTextarea* textarea =
- new UI::MultilineTextarea(boxes_.at(index).get(), 0, 0, Scrollbar::kSize, 0, style_);
- try {
- textarea->force_new_renderer();
- textarea->set_text(content);
- } catch (const std::exception& e) {
- log("Fileview: falling back to OLD font renderer: %s\n", e.what());
- textarea->force_new_renderer(false);
- textarea->set_text(content);
- }
+ new UI::MultilineTextarea(boxes_.at(index).get(), 0, 0, Scrollbar::kSize, 0, style_, content);
textviews_.push_back(std::unique_ptr<UI::MultilineTextarea>(std::move(textarea)));
add((boost::format("about_%" PRIuS) % index).str(), title, boxes_.at(index).get(), "");
=== modified file 'src/ui_basic/listselect.cc'
--- src/ui_basic/listselect.cc 2018-05-16 04:41:24 +0000
+++ src/ui_basic/listselect.cc 2018-07-23 09:14:48 +0000
@@ -25,7 +25,7 @@
#include "base/log.h"
#include "graphic/align.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/style_manager.h"
@@ -296,7 +296,7 @@
if (selection_mode_ == ListselectLayout::kDropdown) {
for (size_t i = 0; i < entry_records_.size(); ++i) {
const EntryRecord& er = *entry_records_[i];
- std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh1->render(
+ std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(
as_uifont(richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));
int picw = max_pic_width_ ? max_pic_width_ + 10 : 0;
int difference = rendered_text->width() + picw + 8 - get_eff_w();
@@ -342,7 +342,7 @@
const EntryRecord& er = *entry_records_[idx];
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_uifont(richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));
+ UI::g_fh->render(as_uifont(richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));
int lineheight = std::max(get_lineheight(), rendered_text->height());
@@ -379,7 +379,7 @@
// Now draw pictures
if (er.pic) {
- dst.blit(Vector2i(UI::g_fh1->fontset()->is_rtl() ? get_eff_w() - er.pic->width() - 1 : 1,
+ dst.blit(Vector2i(UI::g_fh->fontset()->is_rtl() ? get_eff_w() - er.pic->width() - 1 : 1,
y + (get_lineheight() - er.pic->height()) / 2),
er.pic);
}
@@ -391,7 +391,7 @@
}
// Shift for image width
- if (!UI::g_fh1->fontset()->is_rtl()) {
+ if (!UI::g_fh->fontset()->is_rtl()) {
point.x += picw;
}
=== modified file 'src/ui_basic/messagebox.cc'
--- src/ui_basic/messagebox.cc 2018-04-27 06:11:05 +0000
+++ src/ui_basic/messagebox.cc 2018-07-23 09:14:48 +0000
@@ -20,7 +20,7 @@
#include "ui_basic/messagebox.h"
#include "base/i18n.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "ui_basic/window.h"
@@ -48,7 +48,7 @@
int width, height = 0;
{
std::shared_ptr<const UI::RenderedText> temp_rendered_text =
- g_fh1->render(as_uifont(text), maxwidth);
+ g_fh->render(as_uifont(text), maxwidth);
width = temp_rendered_text->width();
height = temp_rendered_text->height();
}
@@ -56,7 +56,7 @@
// Stupid heuristic to avoid excessively long lines
if (height < 2 * UI_FONT_SIZE_SMALL) {
std::shared_ptr<const UI::RenderedText> temp_rendered_text =
- g_fh1->render(as_uifont(text), maxwidth / 2);
+ g_fh->render(as_uifont(text), maxwidth / 2);
width = temp_rendered_text->width();
height = temp_rendered_text->height();
}
@@ -82,13 +82,13 @@
ok_button_.reset(new Button(this, "ok",
type_ == MBoxType::kOk ?
(width - button_w) / 2 :
- UI::g_fh1->fontset()->is_rtl() ? left_button_x : right_button_x,
+ UI::g_fh->fontset()->is_rtl() ? left_button_x : right_button_x,
button_y, button_w, 0, UI::ButtonStyle::kWuiPrimary, _("OK")));
ok_button_->sigclicked.connect(boost::bind(&WLMessageBox::clicked_ok, boost::ref(*this)));
if (type_ == MBoxType::kOkCancel) {
cancel_button_.reset(
- new Button(this, "cancel", UI::g_fh1->fontset()->is_rtl() ? right_button_x : left_button_x,
+ new Button(this, "cancel", UI::g_fh->fontset()->is_rtl() ? right_button_x : left_button_x,
button_y, button_w, 0, UI::ButtonStyle::kWuiSecondary, _("Cancel")));
cancel_button_->sigclicked.connect(
boost::bind(&WLMessageBox::clicked_back, boost::ref(*this)));
=== modified file 'src/ui_basic/multilineeditbox.cc'
--- src/ui_basic/multilineeditbox.cc 2018-06-01 08:54:25 +0000
+++ src/ui_basic/multilineeditbox.cc 2018-07-23 09:14:48 +0000
@@ -22,7 +22,7 @@
#include <boost/bind.hpp>
#include "base/utf8.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/style_manager.h"
@@ -171,7 +171,7 @@
do {
--cursor;
- // TODO(GunChleoc): When switchover to g_fh1 is complete, see if we can go full ICU here.
+ // TODO(GunChleoc): When switchover to g_fh is complete, see if we can go full ICU here.
} while (cursor > 0 && Utf8::is_utf8_extended(text[cursor]));
return cursor;
=== modified file 'src/ui_basic/multilinetextarea.cc'
--- src/ui_basic/multilinetextarea.cc 2018-04-27 06:11:05 +0000
+++ src/ui_basic/multilinetextarea.cc 2018-07-23 09:14:48 +0000
@@ -22,7 +22,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/rendertarget.h"
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
@@ -45,8 +45,6 @@
text_(text),
color_(UI_FONT_CLR_FG),
align_(align),
- force_new_renderer_(false),
- use_old_renderer_(false),
scrollbar_(this, get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, h, style, false) {
set_thinks(false);
@@ -67,36 +65,36 @@
recompute();
}
+void MultilineTextarea::set_color(RGBColor fg) {
+ color_ = fg;
+ recompute();
+}
+
/**
* Recompute the text rendering or rich-text layouting,
* and adjust scrollbar settings accordingly.
*/
void MultilineTextarea::recompute() {
- int height = 0;
-
// We wrap the text twice. We need to do this to account for the presence/absence of the
// scollbar.
bool scrollbar_was_enabled = scrollbar_.is_enabled();
for (int i = 0; i < 2; ++i) {
- if (!is_richtext(text_)) {
- use_old_renderer_ = false;
- height = UI::g_fh1->render(make_richtext(), get_eff_w() - 2 * RICHTEXT_MARGIN)->height();
- } else if (force_new_renderer_) {
- use_old_renderer_ = false;
- height = UI::g_fh1->render(text_, get_eff_w() - 2 * RICHTEXT_MARGIN)->height();
- } else {
- use_old_renderer_ = true;
- rt.set_width(get_eff_w() - 2 * RICHTEXT_MARGIN);
- rt.parse(text_);
- height = rt.height() + 2 * RICHTEXT_MARGIN;
+ int height = 0;
+ if (!text_.empty()) {
+ if (!is_richtext(text_)) {
+ text_ = make_richtext();
+ }
+ try {
+ rendered_text_ = UI::g_fh->render(text_, get_eff_w() - 2 * RICHTEXT_MARGIN);
+ } catch (const std::exception& e) {
+ log("Error rendering richtext: %s. Text is:\n%s\n", e.what(), text_.c_str());
+ text_ = make_richtext();
+ rendered_text_ = UI::g_fh->render(text_, get_eff_w() - 2 * RICHTEXT_MARGIN);
+ }
+ height = rendered_text_->height();
}
- bool setbottom = false;
-
- if (scrollmode_ == ScrollMode::kScrollLog || scrollmode_ == ScrollMode::kScrollLogForced) {
- if (scrollbar_.get_scrollpos() >= scrollbar_.get_steps() - 1)
- setbottom = true;
- } else if (scrollmode_ == ScrollMode::kNoScrolling) {
+ if (scrollmode_ == ScrollMode::kNoScrolling) {
scrollbar_.set_scrollpos(0);
scrollbar_.set_steps(1);
set_desired_size(get_w(), height);
@@ -104,8 +102,12 @@
}
scrollbar_.set_steps(height - get_h());
- if (setbottom)
- scrollbar_.set_scrollpos(height - get_h());
+
+ if (scrollmode_ == ScrollMode::kScrollLog || scrollmode_ == ScrollMode::kScrollLogForced) {
+ if (scrollbar_.get_scrollpos() >= scrollbar_.get_steps() - 1) {
+ scrollbar_.set_scrollpos(height - get_h());
+ }
+ }
if (scrollbar_.is_enabled() == scrollbar_was_enabled) {
break; // No need to wrap twice.
@@ -133,31 +135,23 @@
* Redraw the textarea
*/
void MultilineTextarea::draw(RenderTarget& dst) {
- if (use_old_renderer_) {
- rt.draw(dst, Vector2i(RICHTEXT_MARGIN, RICHTEXT_MARGIN - scrollbar_.get_scrollpos()));
- } else {
- std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh1->render(
- is_richtext(text_) ? text_ : make_richtext(), get_eff_w() - 2 * RICHTEXT_MARGIN);
- uint32_t blit_width = std::min(rendered_text->width(), static_cast<int>(get_eff_w()));
- uint32_t blit_height = std::min(rendered_text->height(), get_inner_h());
-
- if (blit_width > 0 && blit_height > 0) {
- int anchor = 0;
- Align alignment = mirror_alignment(align_, text_);
- switch (alignment) {
- case UI::Align::kCenter:
- anchor = (get_eff_w() - blit_width) / 2;
- break;
- case UI::Align::kRight:
- anchor = get_eff_w() - blit_width - RICHTEXT_MARGIN;
- break;
- case UI::Align::kLeft:
- anchor = RICHTEXT_MARGIN;
- }
- rendered_text->draw(dst, Vector2i(anchor, 0),
- Recti(0, scrollbar_.get_scrollpos(), blit_width, blit_height));
- }
- }
+ if (text_.empty()) {
+ return;
+ }
+ int anchor = 0;
+ Align alignment = mirror_alignment(align_, text_);
+ switch (alignment) {
+ case UI::Align::kCenter:
+ anchor = (get_eff_w() - rendered_text_->width()) / 2;
+ break;
+ case UI::Align::kRight:
+ anchor = get_eff_w() - rendered_text_->width() - RICHTEXT_MARGIN;
+ break;
+ case UI::Align::kLeft:
+ anchor = RICHTEXT_MARGIN;
+ }
+ rendered_text_->draw(dst, Vector2i(anchor, 0),
+ Recti(0, scrollbar_.get_scrollpos(), rendered_text_->width(), rendered_text_->height() - scrollbar_.get_scrollpos()));
}
bool MultilineTextarea::handle_mousewheel(uint32_t which, int32_t x, int32_t y) {
=== modified file 'src/ui_basic/multilinetextarea.h'
--- src/ui_basic/multilinetextarea.h 2018-04-27 06:11:05 +0000
+++ src/ui_basic/multilinetextarea.h 2018-07-23 09:14:48 +0000
@@ -24,7 +24,6 @@
#include "graphic/align.h"
#include "graphic/color.h"
-#include "graphic/richtext.h"
#include "graphic/text_layout.h"
#include "ui_basic/panel.h"
#include "ui_basic/scrollbar.h"
@@ -65,20 +64,7 @@
return scrollbar_.is_enabled() ? get_w() - Scrollbar::kSize : get_w();
}
- void set_color(RGBColor fg) {
- color_ = fg;
- }
-
- // Most MultilineTextareas that contain richtext markup still use the old
- // font renderer, but some are already switched over the the new font
- // renderer. The markup is incompatible, so we need to be able to tell the
- // MultilineTextarea which one to use. MultilineTextareas without markup
- // automatically use the new font renderer.
- // TODO(GunChleoc): Remove this function once the switchover to the new font
- // renderer is complete.
- void force_new_renderer(bool force = true) {
- force_new_renderer_ = force;
- }
+ void set_color(RGBColor fg);
// Drawing and event handlers
void draw(RenderTarget&) override;
@@ -103,13 +89,10 @@
std::string make_richtext();
std::string text_;
+ std::shared_ptr<const UI::RenderedText> rendered_text_;
RGBColor color_;
const Align align_;
- bool force_new_renderer_;
- bool use_old_renderer_;
- RichText rt;
-
Scrollbar scrollbar_;
ScrollMode scrollmode_;
};
=== modified file 'src/ui_basic/panel.cc'
--- src/ui_basic/panel.cc 2018-07-12 10:33:26 +0000
+++ src/ui_basic/panel.cc 2018-07-23 09:14:48 +0000
@@ -20,7 +20,7 @@
#include "ui_basic/panel.h"
#include "base/log.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text/font_set.h"
@@ -1083,7 +1083,7 @@
constexpr uint32_t kTipWidthMax = 360;
std::shared_ptr<const UI::RenderedText> rendered_text =
- g_fh1->render(text_to_render, kTipWidthMax);
+ g_fh->render(text_to_render, kTipWidthMax);
if (rendered_text->rects.empty()) {
return false;
}
=== modified file 'src/ui_basic/panel.h'
--- src/ui_basic/panel.h 2018-07-12 10:33:26 +0000
+++ src/ui_basic/panel.h 2018-07-23 09:14:48 +0000
@@ -32,7 +32,7 @@
#include "base/rect.h"
#include "base/vector.h"
#include "graphic/align.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/panel_styles.h"
class RenderTarget;
=== modified file 'src/ui_basic/progressbar.cc'
--- src/ui_basic/progressbar.cc 2018-04-07 16:59:00 +0000
+++ src/ui_basic/progressbar.cc 2018-07-23 09:14:48 +0000
@@ -23,7 +23,7 @@
#include <boost/format.hpp>
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/rendertarget.h"
#include "graphic/text_layout.h"
@@ -89,7 +89,7 @@
UI_FONT_CLR_BRIGHT.hex_value() % floorf(fraction * 100.f))
.str();
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_uifont(progress_text));
+ UI::g_fh->render(as_uifont(progress_text));
Vector2i pos(get_w() / 2, get_h() / 2);
UI::center_vertically(rendered_text->height(), &pos);
rendered_text->draw(dst, pos, UI::Align::kCenter);
=== modified file 'src/ui_basic/progresswindow.cc'
--- src/ui_basic/progresswindow.cc 2018-04-07 16:59:00 +0000
+++ src/ui_basic/progresswindow.cc 2018-07-23 09:14:48 +0000
@@ -24,7 +24,7 @@
#endif
#include "base/i18n.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text/font_set.h"
@@ -99,7 +99,7 @@
rt.fill_rect(label_rectangle_, PROGRESS_FONT_COLOR_BG);
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_uifont(description, UI_FONT_SIZE_SMALL, PROGRESS_FONT_COLOR_FG));
+ UI::g_fh->render(as_uifont(description, UI_FONT_SIZE_SMALL, PROGRESS_FONT_COLOR_FG));
UI::center_vertically(rendered_text->height(), &label_center_);
rendered_text->draw(rt, label_center_, UI::Align::kCenter);
=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc 2018-04-27 06:11:05 +0000
+++ src/ui_basic/slider.cc 2018-07-23 09:14:48 +0000
@@ -20,7 +20,7 @@
#include <cmath>
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/style_manager.h"
@@ -526,7 +526,7 @@
for (uint32_t i = 0; i < labels.size(); i++) {
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_condensed(labels[i], UI::Align::kCenter, UI_FONT_SIZE_SMALL - 2));
+ UI::g_fh->render(as_condensed(labels[i], UI::Align::kCenter, UI_FONT_SIZE_SMALL - 2));
rendered_text->draw(
dst, Vector2i(gap_1 + i * gap_n, get_h() - rendered_text->height()), UI::Align::kCenter);
}
=== modified file 'src/ui_basic/spinbox.cc'
--- src/ui_basic/spinbox.cc 2018-04-27 06:11:05 +0000
+++ src/ui_basic/spinbox.cc 2018-07-23 09:14:48 +0000
@@ -28,7 +28,7 @@
#include "base/log.h"
#include "base/macros.h"
#include "base/wexception.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc 2018-06-07 17:43:27 +0000
+++ src/ui_basic/table.cc 2018-07-23 09:14:48 +0000
@@ -21,7 +21,7 @@
#include <boost/bind.hpp>
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/rendertarget.h"
#include "graphic/text/bidi.h"
#include "graphic/text/font_set.h"
@@ -301,7 +301,7 @@
continue;
}
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_uifont(richtext_escape(entry_string)));
+ UI::g_fh->render(as_uifont(richtext_escape(entry_string)));
// Fix text alignment for BiDi languages if the entry contains an RTL character. We want
// this always on, e.g. for mixed language savegame filenames.
=== modified file 'src/ui_basic/tabpanel.cc'
--- src/ui_basic/tabpanel.cc 2018-05-13 07:15:39 +0000
+++ src/ui_basic/tabpanel.cc 2018-07-23 09:14:48 +0000
@@ -19,7 +19,7 @@
#include "ui_basic/tabpanel.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/style_manager.h"
@@ -62,7 +62,7 @@
tooltip(tooltip_text),
panel(contents) {
if (!init_title.empty()) {
- rendered_title = UI::g_fh1->render(as_uifont(init_title));
+ rendered_title = UI::g_fh->render(as_uifont(init_title));
set_size(std::max(kTabPanelButtonHeight, rendered_title->width() + 2 * kTabPanelTextMargin),
kTabPanelButtonHeight);
}
=== modified file 'src/ui_basic/textarea.cc'
--- src/ui_basic/textarea.cc 2018-04-07 16:59:00 +0000
+++ src/ui_basic/textarea.cc 2018-07-23 09:14:48 +0000
@@ -19,7 +19,7 @@
#include "ui_basic/textarea.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/rendertarget.h"
namespace UI {
=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc 2018-04-27 06:11:05 +0000
+++ src/ui_basic/window.cc 2018-07-23 09:14:48 +0000
@@ -22,7 +22,7 @@
#include <SDL_keycode.h>
#include "base/log.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/style_manager.h"
=== modified file 'src/ui_fsmenu/helpwindow.cc'
--- src/ui_fsmenu/helpwindow.cc 2018-04-27 06:11:05 +0000
+++ src/ui_fsmenu/helpwindow.cc 2018-07-23 09:14:48 +0000
@@ -63,7 +63,6 @@
helptext = err.what();
}
- textarea_->force_new_renderer();
textarea_->set_size(width - 2 * margin, height - btn->get_h() - 3 * margin);
textarea_->set_text(helptext);
=== modified file 'src/ui_fsmenu/mapselect.cc'
--- src/ui_fsmenu/mapselect.cc 2018-05-22 11:29:41 +0000
+++ src/ui_fsmenu/mapselect.cc 2018-07-23 09:14:48 +0000
@@ -26,7 +26,7 @@
#include "base/i18n.h"
#include "base/log.h"
#include "base/wexception.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "io/filesystem/layered_filesystem.h"
#include "logic/filesystem_constants.h"
#include "logic/game_controller.h"
@@ -44,7 +44,7 @@
: FullscreenMenuLoadMapOrGame(),
checkbox_space_(25),
// Less padding for big fonts; space is tight.
- checkbox_padding_(UI::g_fh1->fontset()->size_offset() > 0 ? 0 : 2 * padding_),
+ checkbox_padding_(UI::g_fh->fontset()->size_offset() > 0 ? 0 : 2 * padding_),
// Main title
title_(this, 0, 0, _("Choose a map"), UI::Align::kCenter),
=== modified file 'src/ui_fsmenu/options.cc'
--- src/ui_fsmenu/options.cc 2018-05-13 07:15:39 +0000
+++ src/ui_fsmenu/options.cc 2018-07-23 09:14:48 +0000
@@ -31,7 +31,7 @@
#include "base/log.h"
#include "base/wexception.h"
#include "graphic/default_resolution.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/text/bidi.h"
#include "graphic/text/font_set.h"
@@ -218,14 +218,13 @@
os_(opt) {
// Set up UI Elements
title_.set_fontsize(UI_FONT_SIZE_BIG);
- translation_info_.force_new_renderer();
// Buttons
- button_box_.add(UI::g_fh1->fontset()->is_rtl() ? &ok_ : &cancel_);
+ button_box_.add(UI::g_fh->fontset()->is_rtl() ? &ok_ : &cancel_);
button_box_.add_inf_space();
button_box_.add(&apply_);
button_box_.add_inf_space();
- button_box_.add(UI::g_fh1->fontset()->is_rtl() ? &cancel_ : &ok_);
+ button_box_.add(UI::g_fh->fontset()->is_rtl() ? &cancel_ : &ok_);
// Tabs
tabs_.add("options_interface", _("Interface"), &box_interface_, "");
@@ -702,7 +701,7 @@
WLApplication::get()->set_input_grab(opt.inputgrab);
i18n::set_locale(opt.language);
- UI::g_fh1->reinitialize_fontset(i18n::get_locale());
+ UI::g_fh->reinitialize_fontset(i18n::get_locale());
g_sound_handler.set_disable_music(!opt.music);
g_sound_handler.set_disable_fx(!opt.fx);
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2018-07-20 07:23:34 +0000
+++ src/wlapplication.cc 2018-07-23 09:14:48 +0000
@@ -54,7 +54,6 @@
#include "editor/editorinteractive.h"
#include "graphic/default_resolution.h"
#include "graphic/font_handler.h"
-#include "graphic/font_handler1.h"
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
#include "helper.h"
@@ -338,9 +337,8 @@
if (TTF_Init() == -1)
throw wexception("True Type library did not initialize: %s\n", TTF_GetError());
- UI::g_fh1 = UI::create_fonthandler(
+ UI::g_fh = UI::create_fonthandler(
&g_gr->images(), i18n::get_locale()); // This will create the fontset, so loading it first.
- UI::g_fh = new UI::FontHandler();
g_gr->initialize(
config.get_bool("debug_gl_trace", false) ? Graphic::TraceGl::kYes : Graphic::TraceGl::kNo,
@@ -372,10 +370,6 @@
delete UI::g_fh;
UI::g_fh = nullptr;
- assert(UI::g_fh1);
- delete UI::g_fh1;
- UI::g_fh1 = nullptr;
-
TTF_Quit(); // TODO(unknown): not here
assert(g_fs);
@@ -846,10 +840,6 @@
}
void WLApplication::shutdown_hardware() {
- if (UI::g_fh) {
- // TODO(unknown): this should really not be needed, but currently is :(
- UI::g_fh->flush();
- }
delete g_gr;
g_gr = nullptr;
=== modified file 'src/wui/actionconfirm.cc'
--- src/wui/actionconfirm.cc 2018-04-27 06:11:05 +0000
+++ src/wui/actionconfirm.cc 2018-07-23 09:14:48 +0000
@@ -23,7 +23,7 @@
#include "base/macros.h"
#include "economy/economy.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "logic/map_objects/tribes/building.h"
#include "logic/map_objects/tribes/ship.h"
@@ -135,7 +135,6 @@
UI::MultilineTextarea* textarea = new UI::MultilineTextarea(
main_box, 0, 0, 200, 74, UI::PanelStyle::kWui, message, UI::Align::kCenter,
UI::MultilineTextarea::ScrollMode::kNoScrolling);
- textarea->force_new_renderer();
UI::Button* okbtn = new UI::Button(button_box, "ok", 0, 0, 80, 34, UI::ButtonStyle::kWuiMenu,
g_gr->images().get("images/wui/menu_okay.png"));
@@ -147,10 +146,10 @@
cancelbtn->sigclicked.connect(boost::bind(&ActionConfirm::die, this));
button_box->add(
- UI::g_fh1->fontset()->is_rtl() ? okbtn : cancelbtn, UI::Box::Resizing::kFillSpace);
+ UI::g_fh->fontset()->is_rtl() ? okbtn : cancelbtn, UI::Box::Resizing::kFillSpace);
button_box->add_space(2 * padding);
button_box->add(
- UI::g_fh1->fontset()->is_rtl() ? cancelbtn : okbtn, UI::Box::Resizing::kFillSpace);
+ UI::g_fh->fontset()->is_rtl() ? cancelbtn : okbtn, UI::Box::Resizing::kFillSpace);
main_box->add(textarea);
main_box->add_space(1.5 * padding);
main_box->add(button_box, UI::Box::Resizing::kFullSize);
=== modified file 'src/wui/attack_box.cc'
--- src/wui/attack_box.cc 2018-05-14 05:48:31 +0000
+++ src/wui/attack_box.cc 2018-07-23 09:14:48 +0000
@@ -25,7 +25,7 @@
#include <boost/format.hpp>
#include "base/macros.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
#include "logic/map_objects/tribes/soldier.h"
=== modified file 'src/wui/attack_box.h'
--- src/wui/attack_box.h 2018-04-27 06:11:05 +0000
+++ src/wui/attack_box.h 2018-07-23 09:14:48 +0000
@@ -23,7 +23,7 @@
#include <list>
#include <memory>
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
#include "logic/map_objects/bob.h"
=== modified file 'src/wui/building_statistics_menu.cc'
--- src/wui/building_statistics_menu.cc 2018-05-13 07:15:39 +0000
+++ src/wui/building_statistics_menu.cc 2018-07-23 09:14:48 +0000
@@ -25,7 +25,7 @@
#include <boost/format.hpp>
#include "base/i18n.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "logic/map_objects/tribes/militarysite.h"
#include "logic/map_objects/tribes/productionsite.h"
#include "logic/map_objects/tribes/tribes.h"
@@ -84,7 +84,7 @@
0,
1,
UI::PanelStyle::kWui,
- kLabelFontSize - UI::g_fh1->fontset()->size_offset()), // We need consistent height here
+ kLabelFontSize - UI::g_fh->fontset()->size_offset()), // We need consistent height here
unproductive_label2_(
&unproductive_box_,
/** TRANSLATORS: This is the second part of productivity with input field */
=== modified file 'src/wui/chat_overlay.cc'
--- src/wui/chat_overlay.cc 2018-05-16 05:21:30 +0000
+++ src/wui/chat_overlay.cc 2018-07-23 09:14:48 +0000
@@ -24,7 +24,7 @@
#include "base/macros.h"
#include "base/wexception.h"
#include "chat/chat.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/rendertarget.h"
#include "graphic/text/rt_errors.h"
#include "profile/profile.h"
@@ -169,11 +169,11 @@
std::shared_ptr<const UI::RenderedText> im(nullptr);
try {
- im = UI::g_fh1->render(m->all_text_, get_w());
+ im = UI::g_fh->render(m->all_text_, get_w());
} catch (RT::WidthTooSmall&) {
// Oops, maybe one long word? We render again, not limiting the width, but
// render everything in one single line.
- im = UI::g_fh1->render(m->all_text_);
+ im = UI::g_fh->render(m->all_text_);
}
assert(im != nullptr);
=== modified file 'src/wui/encyclopedia_window.cc'
--- src/wui/encyclopedia_window.cc 2018-05-13 07:15:39 +0000
+++ src/wui/encyclopedia_window.cc 2018-07-23 09:14:48 +0000
@@ -167,7 +167,6 @@
cr->resume();
table = cr->pop_table();
}
- contents_.at(tab_name)->force_new_renderer();
contents_.at(tab_name)
->set_text(as_message(table->get_string("title"), table->get_string("text")));
} catch (LuaError& err) {
=== modified file 'src/wui/game_chat_panel.cc'
--- src/wui/game_chat_panel.cc 2018-05-18 18:00:01 +0000
+++ src/wui/game_chat_panel.cc 2018-07-23 09:14:48 +0000
@@ -50,7 +50,6 @@
editbox.ok.connect(boost::bind(&GameChatPanel::key_enter, this));
editbox.cancel.connect(boost::bind(&GameChatPanel::key_escape, this));
editbox.activate_history(true);
- chatbox.force_new_renderer(true);
set_handle_mouse(true);
set_can_focus(true);
=== modified file 'src/wui/game_message_menu.cc'
--- src/wui/game_message_menu.cc 2018-05-14 08:24:46 +0000
+++ src/wui/game_message_menu.cc 2018-07-23 09:14:48 +0000
@@ -340,23 +340,7 @@
game.get_gametime(), player.player_number(), id));
}
centerviewbtn_->set_enabled(message->position());
-
- // TODO(GunChleoc): Programming by exception is ugly, but we need try/catch here for
- // saveloading.
- // Revisit this when we delete the old font renderer.
- try {
- message_body.force_new_renderer();
- message_body.set_text(as_message(message->heading(), message->body()));
- } catch (const std::exception& e) {
- log("Game Message Menu: falling back to old font renderer:\n%s\n%s\n",
- message->body().c_str(), e.what());
- message_body.force_new_renderer(false);
- message_body.set_text(
- (boost::format("<rt><p font-size=18 font-weight=bold font-color=D1D1D1>%s<br></p>"
- "<p font-size=8> <br></p></rt>%s") %
- message->heading() % message->body())
- .str());
- }
+ message_body.set_text(as_message(message->heading(), message->body()));
update_archive_button_tooltip();
return;
}
=== modified file 'src/wui/game_objectives_menu.cc'
--- src/wui/game_objectives_menu.cc 2018-04-27 06:11:05 +0000
+++ src/wui/game_objectives_menu.cc 2018-07-23 09:14:48 +0000
@@ -86,15 +86,5 @@
* An entry in the objectives menu has been selected
*/
void GameObjectivesMenu::selected(uint32_t const t) {
- const std::string text = t == ListType::no_selection_index() ? "" : list[t].descr();
- // TODO(GunChleoc): When all campaigns, scenarios and win conditions have been converted, simply
- // add the text above.
- try {
- objectivetext.force_new_renderer();
- objectivetext.set_text(text);
- } catch (const std::exception& e) {
- log("Objectives: falling back to old font renderer:\n%s\n%s\n", text.c_str(), e.what());
- objectivetext.force_new_renderer(false);
- objectivetext.set_text(text);
- }
+ objectivetext.set_text(t == ListType::no_selection_index() ? "" : list[t].descr());
}
=== modified file 'src/wui/game_tips.cc'
--- src/wui/game_tips.cc 2018-04-07 16:59:00 +0000
+++ src/wui/game_tips.cc 2018-07-23 09:14:48 +0000
@@ -22,7 +22,7 @@
#include <memory>
#include "base/i18n.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text_layout.h"
@@ -108,7 +108,7 @@
rt.blit(pt, pic_background);
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_game_tip(tips_[index].text), w);
+ UI::g_fh->render(as_game_tip(tips_[index].text), w);
pt = Vector2i((g_gr->get_xres() - rendered_text->width()) / 2,
(g_gr->get_yres() - rendered_text->height()) / 2);
rendered_text->draw(rt, pt);
=== modified file 'src/wui/gamedetails.cc'
--- src/wui/gamedetails.cc 2018-07-19 13:34:59 +0000
+++ src/wui/gamedetails.cc 2018-07-23 09:14:48 +0000
@@ -77,8 +77,6 @@
UI::MultilineTextarea::ScrollMode::kNoScrolling),
minimap_icon_(this, 0, 0, 0, 0, nullptr),
button_box_(new UI::Box(this, 0, 0, UI::Box::Vertical)) {
- name_label_.force_new_renderer();
- descr_.force_new_renderer();
add(&name_label_, UI::Box::Resizing::kFullSize);
add_space(padding_);
=== modified file 'src/wui/helpwindow.cc'
--- src/wui/helpwindow.cc 2018-04-27 06:11:05 +0000
+++ src/wui/helpwindow.cc 2018-07-23 09:14:48 +0000
@@ -55,7 +55,6 @@
cr->resume();
std::unique_ptr<LuaTable> return_table = cr->pop_table();
return_table->do_not_warn_about_unaccessed_keys(); // We won't display the title here
- textarea_->force_new_renderer();
textarea_->set_text(as_richtext(return_table->get_string("text")));
} catch (LuaError& err) {
textarea_->set_text(err.what());
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2018-07-20 08:42:23 +0000
+++ src/wui/interactive_base.cc 2018-07-23 09:14:48 +0000
@@ -30,7 +30,7 @@
#include "economy/flag.h"
#include "economy/road.h"
#include "graphic/default_resolution.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/rendertarget.h"
#include "graphic/text_constants.h"
#include "graphic/text_layout.h"
@@ -441,7 +441,7 @@
}
if (!node_text.empty()) {
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_condensed(node_text));
+ UI::g_fh->render(as_condensed(node_text));
rendered_text->draw(
dst, Vector2i(get_w() - 5, get_h() - rendered_text->height() - 5), UI::Align::kRight);
}
@@ -451,13 +451,13 @@
// Blit in-game clock
const std::string gametime(gametimestring(egbase().get_gametime(), true));
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_condensed(gametime));
+ UI::g_fh->render(as_condensed(gametime));
rendered_text->draw(dst, Vector2i(5, 5));
// Blit FPS when playing a game in debug mode
if (get_display_flag(dfDebug)) {
static boost::format fps_format("%5.1f fps (avg: %5.1f fps)");
- rendered_text = UI::g_fh1->render(as_condensed(
+ rendered_text = UI::g_fh->render(as_condensed(
(fps_format % (1000.0 / frametime_) % (1000.0 / (avg_usframetime_ / 1000))).str()));
rendered_text->draw(dst, Vector2i((get_w() - rendered_text->width()) / 2, 5));
}
=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc 2018-04-29 09:20:29 +0000
+++ src/wui/interactive_gamebase.cc 2018-07-23 09:14:48 +0000
@@ -22,7 +22,7 @@
#include <boost/format.hpp>
#include "base/macros.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/rendertarget.h"
#include "graphic/text_constants.h"
#include "graphic/text_layout.h"
@@ -126,7 +126,7 @@
}
if (!game_speed.empty()) {
- std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh1->render(game_speed);
+ std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(game_speed);
rendered_text->draw(dst, Vector2i(get_w() - 5, 5), UI::Align::kRight);
}
}
=== modified file 'src/wui/load_or_save_game.cc'
--- src/wui/load_or_save_game.cc 2018-06-26 08:54:30 +0000
+++ src/wui/load_or_save_game.cc 2018-07-23 09:14:48 +0000
@@ -30,7 +30,7 @@
#include "base/time_string.h"
#include "game_io/game_loader.h"
#include "game_io/game_preload_packet.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "helper.h"
#include "io/filesystem/layered_filesystem.h"
#include "logic/filesystem_constants.h"
=== modified file 'src/wui/login_box.cc'
--- src/wui/login_box.cc 2018-04-27 06:11:05 +0000
+++ src/wui/login_box.cc 2018-07-23 09:14:48 +0000
@@ -20,7 +20,7 @@
#include "wui/login_box.h"
#include "base/i18n.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "profile/profile.h"
#include "ui_basic/button.h"
#include "ui_basic/messagebox.h"
@@ -48,12 +48,12 @@
UI::Button* loginbtn = new UI::Button(
this, "login",
- UI::g_fh1->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 :
+ UI::g_fh->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 :
(get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2,
get_inner_h() - 20 - margin, 200, 20, UI::ButtonStyle::kWuiPrimary, _("Login"));
loginbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_ok, boost::ref(*this)));
UI::Button* cancelbtn =
- new UI::Button(this, "cancel", UI::g_fh1->fontset()->is_rtl() ?
+ new UI::Button(this, "cancel", UI::g_fh->fontset()->is_rtl() ?
(get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2 :
(get_inner_w() / 2 - 200) / 2,
loginbtn->get_y(), 200, 20, UI::ButtonStyle::kWuiSecondary, _("Cancel"));
=== modified file 'src/wui/mapdetails.cc'
--- src/wui/mapdetails.cc 2018-07-19 13:34:59 +0000
+++ src/wui/mapdetails.cc 2018-07-23 09:14:48 +0000
@@ -27,7 +27,7 @@
#include "base/i18n.h"
#include "base/log.h"
#include "base/wexception.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/text_constants.h"
#include "io/filesystem/layered_filesystem.h"
#include "logic/game_controller.h"
@@ -56,8 +56,6 @@
descr_(&main_box_, 0, 0, UI::Scrollbar::kSize, 0, style, ""),
suggested_teams_box_(
new UI::SuggestedTeamsBox(this, 0, 0, UI::Box::Vertical, padding_, 0, w)) {
- name_label_.force_new_renderer();
- descr_.force_new_renderer();
main_box_.add(&name_label_);
main_box_.add_space(padding_);
=== modified file 'src/wui/multiplayersetupgroup.h'
--- src/wui/multiplayersetupgroup.h 2018-04-07 16:59:00 +0000
+++ src/wui/multiplayersetupgroup.h 2018-07-23 09:14:48 +0000
@@ -24,7 +24,7 @@
#include <memory>
#include <string>
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
#include "network/network_player_settings_backend.h"
=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc 2018-04-07 16:59:00 +0000
+++ src/wui/plot_area.cc 2018-07-23 09:14:48 +0000
@@ -26,7 +26,7 @@
#include "base/i18n.h"
#include "base/wexception.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text_layout.h"
@@ -176,7 +176,7 @@
const RGBColor& color,
const Vector2i& pos,
RenderTarget& dst) {
- std::shared_ptr<const UI::RenderedText> tick = UI::g_fh1->render(ytick_text_style(value, color));
+ std::shared_ptr<const UI::RenderedText> tick = UI::g_fh->render(ytick_text_style(value, color));
Vector2i point(pos); // Un-const this
UI::center_vertically(tick->height(), &point);
tick->draw(dst, point, UI::Align::kRight);
@@ -184,12 +184,12 @@
uint32_t calc_plot_x_max_ticks(int32_t plot_width) {
// Render a number with 3 digits (maximal length which should appear)
- return plot_width / UI::g_fh1->render(ytick_text_style(" -888 ", kAxisLineColor))->width();
+ return plot_width / UI::g_fh->render(ytick_text_style(" -888 ", kAxisLineColor))->width();
}
int calc_slider_label_width(const std::string& label) {
// Font size and style as used by DiscreteSlider
- return UI::g_fh1->render(as_condensed(label, UI::Align::kLeft, UI_FONT_SIZE_SMALL - 2))->width();
+ return UI::g_fh->render(as_condensed(label, UI::Align::kLeft, UI_FONT_SIZE_SMALL - 2))->width();
}
/**
@@ -261,7 +261,7 @@
// The space at the end is intentional to have the tick centered
// over the number, not to the left
if (how_many_ticks != 0) {
- std::shared_ptr<const UI::RenderedText> xtick = UI::g_fh1->render(
+ std::shared_ptr<const UI::RenderedText> xtick = UI::g_fh->render(
xtick_text_style((boost::format("-%u ") % (max_x / how_many_ticks * i)).str()));
Vector2i pos(posx, inner_h - kSpaceBottom + 10);
UI::center_vertically(xtick->height(), &pos);
@@ -282,7 +282,7 @@
// print the used unit
std::shared_ptr<const UI::RenderedText> xtick =
- UI::g_fh1->render(xtick_text_style(get_generic_unit_name(unit)));
+ UI::g_fh->render(xtick_text_style(get_generic_unit_name(unit)));
Vector2i pos(2, kSpacing + 2);
UI::center_vertically(xtick->height(), &pos);
xtick->draw(dst, pos);
=== modified file 'src/wui/soldierlist.cc'
--- src/wui/soldierlist.cc 2018-07-08 15:16:16 +0000
+++ src/wui/soldierlist.cc 2018-07-23 09:14:48 +0000
@@ -23,7 +23,7 @@
#include <boost/format.hpp>
#include "base/macros.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "logic/map_objects/tribes/building.h"
@@ -380,7 +380,7 @@
// We don't want translators to translate this twice, so it's a bit involved.
int w =
- UI::g_fh1->render(as_uifont(
+ UI::g_fh->render(as_uifont(
(boost::format("%s ") // We need some extra space to fix bug 724169
% (boost::format(
/** TRANSLATORS: Health, Attack, Defense, Evade */
@@ -389,7 +389,7 @@
.str()))
->width();
uint32_t maxtextwidth =
- std::max(w, UI::g_fh1->render(as_uifont(_("Click soldier to send away")))->width());
+ std::max(w, UI::g_fh->render(as_uifont(_("Click soldier to send away")))->width());
set_min_desired_breadth(maxtextwidth + 4);
UI::Box* buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal);
=== modified file 'src/wui/story_message_box.cc'
--- src/wui/story_message_box.cc 2018-04-27 06:11:05 +0000
+++ src/wui/story_message_box.cc 2018-07-23 09:14:48 +0000
@@ -41,7 +41,7 @@
: UI::Window(game->get_ipl(), "story_message_box", x, y, w, h, title.c_str()),
main_box_(this, kPadding, kPadding, UI::Box::Vertical, 0, 0, kPadding),
button_box_(&main_box_, kPadding, kPadding, UI::Box::Horizontal, 0, 0, kPadding),
- textarea_(&main_box_, 0, 0, 100, 100, UI::PanelStyle::kWui),
+ textarea_(&main_box_, 0, 0, 100, 100, UI::PanelStyle::kWui, body),
ok_(&button_box_, "ok", 0, 0, 120, 0, UI::ButtonStyle::kWuiPrimary, _("OK")),
desired_speed_(game->game_controller()->desired_speed()),
game_(game) {
@@ -55,18 +55,6 @@
game_->get_ipl()->map_view()->scroll_to_field(coords, MapView::Transition::Jump);
}
- // TODO(GunChleoc): When all campaigns and scenarios have been converted, simply add the body
- // text above.
- try {
- textarea_.force_new_renderer();
- textarea_.set_text(body);
- } catch (const std::exception& e) {
- log(
- "Story Message Box: falling back to old font renderer:\n%s\n%s\n", body.c_str(), e.what());
- textarea_.force_new_renderer(false);
- textarea_.set_text(body);
- }
-
// Add and configure the panels
main_box_.set_size(get_inner_w() - 3 * kPadding, get_inner_h() - 2 * kPadding);
=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc 2018-04-07 16:59:00 +0000
+++ src/wui/waresdisplay.cc 2018-07-23 09:14:48 +0000
@@ -26,7 +26,7 @@
#include "base/i18n.h"
#include "base/wexception.h"
-#include "graphic/font_handler1.h"
+#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text_layout.h"
@@ -332,7 +332,7 @@
info_color_for_ware(id));
std::shared_ptr<const UI::RenderedText> rendered_text =
- UI::g_fh1->render(as_waresinfo(info_for_ware(id)));
+ UI::g_fh->render(as_waresinfo(info_for_ware(id)));
rendered_text->draw(dst, Vector2i(p.x + w - rendered_text->width() - 1,
p.y + WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + 1 -
rendered_text->height()));
Follow ups