mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-21 18:36:24 +00:00
Font: remove some of the sdl ttf compat API
This commit is contained in:
parent
0522df87eb
commit
eb82ba7914
@ -19,7 +19,7 @@
|
||||
#include "editor/controller/editor_controller.hpp"
|
||||
#include "editor/editor_display.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "font/sdl_ttf_compat.hpp" // for pango_line_width
|
||||
#include "font/sdl_ttf_compat.hpp" // for pango_line_size
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "lexical_cast.hpp"
|
||||
#include "overlay.hpp"
|
||||
@ -221,7 +221,7 @@ void editor_display::set_help_string(const std::string& str)
|
||||
point canvas_size = video::game_canvas_size();
|
||||
|
||||
while(size > 0) {
|
||||
if(font::pango_line_width(str, size) * 2 > canvas_size.x) {
|
||||
if(auto [lw, _] = font::pango_line_size(str, size); lw * 2 > canvas_size.x) {
|
||||
size--;
|
||||
} else {
|
||||
break;
|
||||
|
@ -73,37 +73,6 @@ std::pair<int, int> pango_line_size(const std::string& line, int font_size, font
|
||||
return { s.x, s.y };
|
||||
}
|
||||
|
||||
std::string pango_line_ellipsize(const std::string& text, int font_size, int max_width, font::pango_text::FONT_STYLE font_style)
|
||||
{
|
||||
if(pango_line_width(text, font_size, font_style) <= max_width) {
|
||||
return text;
|
||||
}
|
||||
if(pango_line_width(font::ellipsis, font_size, font_style) > max_width) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string current_substring;
|
||||
|
||||
try {
|
||||
utf8::iterator itor(text);
|
||||
for(; itor != utf8::iterator::end(text); ++itor) {
|
||||
std::string tmp = current_substring;
|
||||
tmp.append(itor.substr().first, itor.substr().second);
|
||||
|
||||
if(pango_line_width(tmp + font::ellipsis, font_size, font_style) > max_width) {
|
||||
return current_substring + font::ellipsis;
|
||||
}
|
||||
|
||||
current_substring = std::move(tmp);
|
||||
}
|
||||
} catch(const utf8::invalid_utf8_exception&) {
|
||||
WRN_FT << "Invalid UTF-8 string: \"" << text << "\"";
|
||||
return "";
|
||||
}
|
||||
|
||||
return text; // Should not happen
|
||||
}
|
||||
|
||||
std::string pango_word_wrap(const std::string& unwrapped_text, int font_size, int max_width, int max_height, int max_lines, bool /*partial_line*/)
|
||||
{
|
||||
// FIXME: what the hell does partial_line do in the SDL_ttf version?
|
||||
|
@ -44,19 +44,6 @@ texture pango_render_text(const std::string& text, int size, const color_t& colo
|
||||
*/
|
||||
std::pair<int, int> pango_line_size(const std::string& line, int font_size, font::pango_text::FONT_STYLE font_style = font::pango_text::STYLE_NORMAL);
|
||||
|
||||
/**
|
||||
* Determine the width of a line of text given a certain font size.
|
||||
*/
|
||||
inline int pango_line_width(const std::string& line, int font_size, font::pango_text::FONT_STYLE font_style = font::pango_text::STYLE_NORMAL)
|
||||
{
|
||||
return pango_line_size(line, font_size, font_style).first;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the text exceeds the specified max width, end it with an ellipsis (...)
|
||||
*/
|
||||
std::string pango_line_ellipsize(const std::string& text, int font_size, int max_width, font::pango_text::FONT_STYLE font_style = font::pango_text::STYLE_NORMAL);
|
||||
|
||||
/**
|
||||
* Uses Pango to word wrap text.
|
||||
*/
|
||||
|
@ -322,7 +322,7 @@ texture textbox::add_text_line(const std::u32string& text, const color_t& color)
|
||||
visible_string = "";
|
||||
}
|
||||
|
||||
int w = font::pango_line_width(visible_string, font_size_);
|
||||
auto [w, _] = font::pango_line_size(visible_string, font_size_);
|
||||
|
||||
if(wrap_ && w >= inner_location().w) {
|
||||
if(backup_itor != text.end()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user