Skip to content

Commit

Permalink
Allow user font dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg authored and kevingranade committed Feb 11, 2020
1 parent 75b4189 commit a619b02
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
/cmake-build-debug/
/config/
/data/*.template
/data/font/
/data/mods/user-default-mods.json
/dep/
/doxygen_doc/html/*
/doxygen_doc/latex/*
/font/
/graveyard/
/memorial/
/mods/
Expand Down
5 changes: 5 additions & 0 deletions src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ bool main_menu::opening_screen()
return false;
}

if( !assure_dir_exist( PATH_INFO::user_font() ) ) {
popup( _( "Unable to make fonts directory. Check permissions." ) );
return false;
}

if( !assure_dir_exist( PATH_INFO::user_sound() ) ) {
popup( _( "Unable to make sound directory. Check permissions." ) );
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/path_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ std::string PATH_INFO::fontdir()
{
return datadir_value + "font/";
}
std::string PATH_INFO::user_font()
{
return user_dir_value + "font/";
}
std::string PATH_INFO::fontlist()
{
return config_dir_value + "fontlist.txt";
Expand Down
3 changes: 1 addition & 2 deletions src/path_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ std::string defaulttilejson();
std::string defaulttilepng();
std::string fontdata();
std::string fontdir();
std::string user_font();
std::string fontlist();
std::string graveyarddir();
std::string help();
Expand All @@ -50,10 +51,8 @@ std::string savedir();
std::string sokoban();
std::string templatedir();
std::string user_dir();
std::string user_gfx();
std::string user_keybindings();
std::string user_moddir();
std::string user_sound();
std::string worldoptions();
std::string crash();
std::string tileset_conf();
Expand Down
25 changes: 18 additions & 7 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,7 @@ static void save_font_list()
try {
std::set<std::string> bitmap_fonts;
write_to_file( PATH_INFO::fontlist(), [&]( std::ostream & fout ) {
font_folder_list( fout, PATH_INFO::user_font(), bitmap_fonts );
font_folder_list( fout, PATH_INFO::fontdir(), bitmap_fonts );

#if defined(_WIN32)
Expand Down Expand Up @@ -3584,13 +3585,18 @@ std::unique_ptr<Font> Font::load_font( const std::string &typeface, int fontsize
{
if( ends_with( typeface, ".bmp" ) || ends_with( typeface, ".png" ) ) {
// Seems to be an image file, not a font.
// Try to load as bitmap font.
// Try to load as bitmap font from user font dir, then from font dir.
try {
return std::unique_ptr<Font>( std::make_unique<BitmapFont>( fontwidth, fontheight,
PATH_INFO::fontdir() + typeface ) );
PATH_INFO::user_font() + typeface ) );
} catch( std::exception &err ) {
dbg( D_ERROR ) << "Failed to load " << typeface << ": " << err.what();
// Continue to load as truetype font
try {
return std::unique_ptr<Font>( std::make_unique<BitmapFont>( fontwidth, fontheight,
PATH_INFO::fontdir() + typeface ) );
} catch( std::exception &err ) {
dbg( D_ERROR ) << "Failed to load " << typeface << ": " << err.what();
// Continue to load as truetype font
}
}
}
// Not loaded as bitmap font (or it failed), try to load as truetype
Expand Down Expand Up @@ -3881,19 +3887,24 @@ CachedTTFFont::CachedTTFFont( const int w, const int h, std::string typeface, in
int faceIndex = 0;
if( const cata::optional<std::string> sysfnt = find_system_font( typeface, faceIndex ) ) {
typeface = *sysfnt;
dbg( D_INFO ) << "Using font [" + typeface + "].";
dbg( D_INFO ) << "Using font [" + typeface + "] found in the system.";
}
if( !file_exist( typeface ) ) {
faceIndex = 0;
typeface = PATH_INFO::user_font() + typeface + ".ttf";
dbg( D_INFO ) << "Using compatible font [" + typeface + "] found in user font dir.";
}
//make fontdata compatible with wincurse
if( !file_exist( typeface ) ) {
faceIndex = 0;
typeface = PATH_INFO::fontdir() + typeface + ".ttf";
dbg( D_INFO ) << "Using compatible font [" + typeface + "].";
dbg( D_INFO ) << "Using compatible font [" + typeface + "] found in font dir.";
}
//different default font with wincurse
if( !file_exist( typeface ) ) {
faceIndex = 0;
typeface = PATH_INFO::fontdir() + "fixedsys.ttf";
dbg( D_INFO ) << "Using fallback font [" + typeface + "].";
dbg( D_INFO ) << "Using fallback font [" + typeface + "] found in font dir.";
}
dbg( D_INFO ) << "Loading truetype font [" + typeface + "].";
if( fontsize <= 0 ) {
Expand Down

0 comments on commit a619b02

Please sign in to comment.