Browse Source

Add --ttf-dir to specify location of path to ttf (#1253)

pull/1265/head
Trihedraf 5 years ago committed by GitHub
parent
commit
508e4c635c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      Source/diablo.cpp
  2. 39
      SourceS/paths.cpp
  3. 4
      SourceS/paths.h
  4. 13
      SourceX/DiabloUI/fonts.cpp
  5. 8
      SourceX/DiabloUI/fonts.h

6
Source/diablo.cpp

@ -101,6 +101,8 @@ static void print_help_and_exit()
printInConsole(" %-20s %-30s\n", "--data-dir", "Specify the folder of diabdat.mpq");
printInConsole(" %-20s %-30s\n", "--save-dir", "Specify the folder of save files");
printInConsole(" %-20s %-30s\n", "--config-dir", "Specify the location of diablo.ini");
printInConsole(" %-20s %-30s\n", "--ttf-dir", "Specify the location of the .ttf font");
printInConsole(" %-20s %-30s\n", "--ttf-name", "Specify the name of a custom .ttf font");
printInConsole(" %-20s %-30s\n", "-n", "Skip startup videos");
printInConsole(" %-20s %-30s\n", "-f", "Display frames per second");
printInConsole(" %-20s %-30s\n", "-x", "Run in windowed mode");
@ -141,6 +143,10 @@ static void diablo_parse_flags(int argc, char **argv)
SetPrefPath(argv[++i]);
} else if (strcasecmp("--config-dir", argv[i]) == 0) {
SetConfigPath(argv[++i]);
} else if (strcasecmp("--ttf-dir", argv[i]) == 0) {
SetTtfPath(argv[++i]);
} else if (strcasecmp("--ttf-name", argv[i]) == 0) {
SetTtfName(argv[++i]);
} else if (strcasecmp("-n", argv[i]) == 0) {
gbShowIntro = false;
} else if (strcasecmp("-f", argv[i]) == 0) {

39
SourceS/paths.cpp

@ -6,6 +6,14 @@
#include "sdl2_to_1_2_backports.h"
#endif
#ifndef TTF_FONT_DIR
#define TTF_FONT_DIR ""
#endif
#ifndef TTF_FONT_NAME
#define TTF_FONT_NAME "CharisSILB.ttf"
#endif
namespace dvl {
namespace {
@ -13,6 +21,8 @@ namespace {
std::string *basePath = NULL;
std::string *prefPath = NULL;
std::string *configPath = NULL;
std::string *ttfPath = NULL;
std::string *ttfName = NULL;
void AddTrailingSlash(std::string *path) {
#ifdef _WIN32
@ -60,6 +70,20 @@ const std::string &GetConfigPath()
return *configPath;
}
const std::string &GetTtfPath()
{
if (ttfPath == NULL)
ttfPath = new std::string(TTF_FONT_DIR);
return *ttfPath;
}
const std::string &GetTtfName()
{
if (ttfName == NULL)
ttfName = new std::string(TTF_FONT_NAME);
return *ttfName;
}
void SetBasePath(const char *path)
{
if (basePath == NULL) basePath = new std::string;
@ -82,4 +106,19 @@ void SetConfigPath(const char *path)
AddTrailingSlash(configPath);
}
void SetTtfPath(const char *path)
{
if (ttfPath == NULL)
ttfPath = new std::string;
*ttfPath = path;
AddTrailingSlash(ttfPath);
}
void SetTtfName(const char *path)
{
if (ttfName == NULL)
ttfName = new std::string;
*ttfName = path;
}
} // namespace dvl

4
SourceS/paths.h

@ -7,9 +7,13 @@ namespace dvl {
const std::string &GetBasePath();
const std::string &GetPrefPath();
const std::string &GetConfigPath();
const std::string &GetTtfPath();
const std::string &GetTtfName();
void SetBasePath(const char *path);
void SetPrefPath(const char *path);
void SetConfigPath(const char *path);
void SetTtfPath(const char *path);
void SetTtfName(const char *path);
} // namespace dvl

13
SourceX/DiabloUI/fonts.cpp

@ -1,5 +1,6 @@
#include "DiabloUI/fonts.h"
#include "file_util.h"
#include "../SourceS/paths.h"
namespace dvl {
@ -61,18 +62,14 @@ void LoadTtfFont() {
was_fonts_init = true;
}
const char* ttf_font_path = TTF_FONT_NAME;
if (!FileExists(ttf_font_path))
{
ttf_font_path = TTF_FONT_DIR TTF_FONT_NAME;
}
std::string ttf_font_path = GetTtfPath() + GetTtfName();
#ifdef __linux__
if (!FileExists(ttf_font_path))
if (!FileExists(ttf_font_path.c_str()))
{
ttf_font_path = "/usr/share/fonts/truetype/" TTF_FONT_NAME;
ttf_font_path = "/usr/share/fonts/truetype/" + GetTtfName();
}
#endif
font = TTF_OpenFont(ttf_font_path, 17);
font = TTF_OpenFont(ttf_font_path.c_str(), 17);
if (font == NULL) {
SDL_Log("TTF_OpenFont: %s", TTF_GetError());
return;

8
SourceX/DiabloUI/fonts.h

@ -6,14 +6,6 @@
#include "DiabloUI/art.h"
#ifndef TTF_FONT_DIR
#define TTF_FONT_DIR ""
#endif
#ifndef TTF_FONT_NAME
#define TTF_FONT_NAME "CharisSILB.ttf"
#endif
namespace dvl {
enum _artFontTables {

Loading…
Cancel
Save