2014-02-08 22:37:46 +09:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 yvt
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-02-08 22:37:46 +09:00
|
|
|
This file is part of OpenSpades.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-02-08 22:37:46 +09:00
|
|
|
OpenSpades 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-02-08 22:37:46 +09:00
|
|
|
OpenSpades 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.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-02-08 22:37:46 +09:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-02-08 22:37:46 +09:00
|
|
|
*/
|
|
|
|
|
2016-12-11 23:18:16 +09:00
|
|
|
#include <memory>
|
|
|
|
#include <regex>
|
|
|
|
|
|
|
|
#include "FTFont.h"
|
2014-02-08 22:37:46 +09:00
|
|
|
#include "FontData.h"
|
2016-12-11 23:18:16 +09:00
|
|
|
#include "Fonts.h"
|
2016-12-03 18:23:47 +09:00
|
|
|
#include "IRenderer.h"
|
|
|
|
#include "Quake3Font.h"
|
2016-12-11 23:18:16 +09:00
|
|
|
#include <Core/FileManager.h>
|
2014-02-08 22:37:46 +09:00
|
|
|
|
|
|
|
namespace spades {
|
|
|
|
namespace client {
|
2016-12-11 23:18:16 +09:00
|
|
|
namespace {
|
2019-07-23 22:25:12 +09:00
|
|
|
std::regex const g_fontNameRe(".*\\.(?:otf|ttf|ttc)", std::regex::icase);
|
|
|
|
|
2016-12-16 05:05:23 +09:00
|
|
|
struct GlobalFontInfo {
|
2019-07-20 17:10:27 +09:00
|
|
|
std::shared_ptr<ngclient::FTFontSet> guiFontSet;
|
2016-12-16 05:05:23 +09:00
|
|
|
|
|
|
|
GlobalFontInfo() {
|
|
|
|
SPLog("Loading built-in fonts");
|
|
|
|
|
2019-07-20 17:10:27 +09:00
|
|
|
guiFontSet = std::make_shared<ngclient::FTFontSet>();
|
2016-12-16 05:05:23 +09:00
|
|
|
|
|
|
|
if (FileManager::FileExists("Gfx/Fonts/AlteDIN1451.ttf")) {
|
|
|
|
guiFontSet->AddFace("Gfx/Fonts/AlteDIN1451.ttf");
|
|
|
|
SPLog("Font 'Alte DIN 1451' loaded");
|
|
|
|
} else {
|
|
|
|
SPLog("Font 'Alte DIN 1451' was not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preliminary custom font support
|
|
|
|
auto files = FileManager::EnumFiles("Fonts");
|
|
|
|
for (const auto &name : files) {
|
2019-07-23 22:25:12 +09:00
|
|
|
if (!std::regex_match(name, g_fontNameRe)) {
|
2016-12-16 05:05:23 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SPLog("Loading custom font '%s'", name.c_str());
|
|
|
|
|
|
|
|
auto path = "Fonts/" + name;
|
|
|
|
guiFontSet->AddFace(path);
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 23:18:16 +09:00
|
|
|
|
2016-12-16 05:05:23 +09:00
|
|
|
static GlobalFontInfo &GetInstance() {
|
|
|
|
static GlobalFontInfo instance;
|
|
|
|
return instance;
|
2016-12-11 23:18:16 +09:00
|
|
|
}
|
2016-12-16 05:05:23 +09:00
|
|
|
};
|
2019-07-20 15:31:36 +09:00
|
|
|
} // namespace
|
2016-12-11 23:18:16 +09:00
|
|
|
|
2016-12-16 05:05:23 +09:00
|
|
|
FontManager::FontManager(IRenderer *renderer) {
|
|
|
|
{
|
2019-07-20 15:31:36 +09:00
|
|
|
auto font = Handle<Quake3Font>::New(
|
|
|
|
renderer,
|
|
|
|
renderer->RegisterImage("Gfx/Fonts/SquareFontBig.png").GetPointerOrNull(),
|
|
|
|
(const int *)SquareFontBigMap, 48, 8.f, true);
|
2016-12-16 05:05:23 +09:00
|
|
|
font->SetGlyphYRange(11.f, 37.f);
|
|
|
|
SPLog("Font 'SquareFont (Large)' Loaded");
|
2019-07-20 15:31:36 +09:00
|
|
|
squareDesignFont = std::move(font).Cast<IFont>();
|
2016-12-11 23:18:16 +09:00
|
|
|
}
|
2019-07-20 17:10:27 +09:00
|
|
|
largeFont = Handle<ngclient::FTFont>::New(
|
|
|
|
renderer, GlobalFontInfo::GetInstance().guiFontSet, 34.f, 48.f)
|
|
|
|
.Cast<IFont>();
|
|
|
|
mediumFont = Handle<ngclient::FTFont>::New(
|
|
|
|
renderer, GlobalFontInfo::GetInstance().guiFontSet, 24.f, 32.f)
|
|
|
|
.Cast<IFont>();
|
|
|
|
headingFont = Handle<ngclient::FTFont>::New(
|
|
|
|
renderer, GlobalFontInfo::GetInstance().guiFontSet, 20.f, 26.f)
|
|
|
|
.Cast<IFont>();
|
|
|
|
guiFont = Handle<ngclient::FTFont>::New(
|
|
|
|
renderer, GlobalFontInfo::GetInstance().guiFontSet, 16.f, 20.f)
|
|
|
|
.Cast<IFont>();
|
2016-12-11 23:18:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
FontManager::~FontManager() {}
|
2019-07-20 15:31:36 +09:00
|
|
|
} // namespace client
|
|
|
|
} // namespace spades
|