Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the default font to Terminus and slightly improve fallback handling #37573

Merged
merged 2 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions data/fontdata.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"fontblending": false,
"fontwidth": 8,
"fontheight": 16,
"fontsize": 16,
"typeface": "unifont",
"map_fontwidth": 8,
"map_fontheight": 16,
"map_fontsize": 16,
"map_typeface": "unifont",
"overmap_fontwidth": 8,
"overmap_fontheight": 16,
"overmap_fontsize": 16,
"overmap_typeface": "unifont"
"//1": "If more than one font is specified for a typeface the list is treated as a fallback order.",
"//2": "unifont will always be used as a 'last resort' fallback even if not listed here.",
"typeface": [
"Terminus",
"unifont"
],
"map_typeface": [
"Terminus",
"unifont"
],
"overmap_typeface": [
"Terminus",
"unifont"
]
}
12 changes: 12 additions & 0 deletions src/font_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef FONT_LOADER_H
#define FONT_LOADER_H

#include <algorithm>
#include <fstream>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -51,6 +52,17 @@ class font_loader
} else {
config.read( "overmap_typeface", overmap_typeface );
}

// Ensure that unifont is always loaded as a fallback font to prevent users from shooting themselves in the foot
auto ensure_unifont_loaded = []( std::vector<std::string> &font_list ) {
if( std::find( std::begin( font_list ), std::end( font_list ), "unifont" ) == font_list.end() ) {
font_list.emplace_back( "unifont" );
}
};
ensure_unifont_loaded( typeface );
ensure_unifont_loaded( map_typeface );
ensure_unifont_loaded( overmap_typeface );

} catch( const std::exception &err ) {
throw std::runtime_error( std::string( "loading font settings from " ) + path + " failed: " +
err.what() );
Expand Down
4 changes: 2 additions & 2 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ void options_manager::add_options_graphics()

add( "MAP_FONT_WIDTH", "graphics", translate_marker( "Map font width" ),
translate_marker( "Set the map font width. Requires restart." ),
8, 100, 8, COPT_CURSES_HIDE
8, 100, 16, COPT_CURSES_HIDE
);

add( "MAP_FONT_HEIGHT", "graphics", translate_marker( "Map font height" ),
Expand All @@ -1696,7 +1696,7 @@ void options_manager::add_options_graphics()

add( "OVERMAP_FONT_WIDTH", "graphics", translate_marker( "Overmap font width" ),
translate_marker( "Set the overmap font width. Requires restart." ),
8, 100, 8, COPT_CURSES_HIDE
8, 100, 16, COPT_CURSES_HIDE
);

add( "OVERMAP_FONT_HEIGHT", "graphics", translate_marker( "Overmap font height" ),
Expand Down