mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Merge pull request #35 from TomTkacz/local_fonts
font rendering/exporting without installing system-wide
This commit is contained in:
+8
-1
@@ -64,7 +64,14 @@
|
||||
"cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x64-windows-static",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ]
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"variables": [
|
||||
{
|
||||
"name": "VCPKG_MANIFEST_FEATURES",
|
||||
"value": "fonts",
|
||||
"type": "STRING"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -21,7 +21,7 @@ On windows, the program can be compiled with Visual Studio (recommended) or with
|
||||
|
||||
=======
|
||||
````
|
||||
.\vcpkg install pkgconf wxwidgets boost-smart-ptr boost-regex boost-logic boost-pool boost-iterator hunspell --triplet=x64-windows-static
|
||||
.\vcpkg install pkgconf wxwidgets[fonts] boost-smart-ptr boost-regex boost-logic boost-pool boost-iterator hunspell --triplet=x64-windows-static
|
||||
````
|
||||
and/or
|
||||
````
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <data/font.hpp>
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/font.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Font
|
||||
|
||||
@@ -24,6 +27,51 @@ Font::Font()
|
||||
, flags(FONT_NORMAL)
|
||||
{}
|
||||
|
||||
bool Font::PreloadResourceFonts(String fontsDirectoryPath, bool recursive) {
|
||||
#if wxUSE_PRIVATE_FONTS
|
||||
String pathSeparator(wxFileName::GetPathSeparator());
|
||||
String appPath( wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath() );
|
||||
fontsDirectoryPath = appPath + pathSeparator + fontsDirectoryPath + (fontsDirectoryPath.EndsWith(pathSeparator) ? wxEmptyString : pathSeparator);
|
||||
|
||||
if (!wxDirExists(fontsDirectoryPath)) return false;
|
||||
|
||||
// tally fonts
|
||||
vector<String> fontFilePaths;
|
||||
TallyResourceFonts(fontsDirectoryPath, fontFilePaths, recursive);
|
||||
if (fontFilePaths.size() == 0) return false;
|
||||
|
||||
// load fonts
|
||||
bool preloadHadErrors = false;
|
||||
for (String fontFilePath : fontFilePaths) {
|
||||
if (!wxFont::AddPrivateFont(fontFilePath)) {
|
||||
preloadHadErrors = true;
|
||||
}
|
||||
}
|
||||
|
||||
return preloadHadErrors;
|
||||
|
||||
#endif // wxUSE_PRIVATE_FONTS
|
||||
return false;
|
||||
}
|
||||
|
||||
void Font::TallyResourceFonts(String fontsDirectoryPath, vector<String>& fontFilePaths, bool recursive) {
|
||||
wxDir fontsDirectory(fontsDirectoryPath);
|
||||
String fontFileName = wxEmptyString;
|
||||
bool hasNext = fontsDirectory.GetFirst(&fontFileName);
|
||||
while (hasNext) {
|
||||
String fontFilePath = fontsDirectoryPath + fontFileName;
|
||||
if (wxDirExists(fontFilePath)) {
|
||||
if (recursive) {
|
||||
TallyResourceFonts(fontFilePath + wxFileName::GetPathSeparator(), fontFilePaths, true);
|
||||
}
|
||||
}
|
||||
else if (fontFilePath.EndsWith(_(".ttf")) || fontFilePath.EndsWith(_(".otf"))) {
|
||||
fontFilePaths.push_back(fontFilePath);
|
||||
}
|
||||
hasNext = fontsDirectory.GetNext(&fontFileName);
|
||||
}
|
||||
}
|
||||
|
||||
bool Font::update(Context& ctx) {
|
||||
bool changes = false;
|
||||
changes |= name .update(ctx);
|
||||
|
||||
@@ -49,6 +49,10 @@ public:
|
||||
|
||||
Font();
|
||||
|
||||
/// Load fonts (.ttf or .otf) from the given directory and its subdirectories, returns true if there were errors
|
||||
static bool PreloadResourceFonts(String fontsDirectoryPath, bool recursive);
|
||||
/// Adds font file paths from the given directory into fontFilePaths
|
||||
static void TallyResourceFonts(String fontsDirectoryPath, vector<String>& fontFilePaths, bool recursive);
|
||||
/// Update the scritables, returns true if there is a change
|
||||
bool update(Context& ctx);
|
||||
/// Add the given dependency to the dependent_scripts list for the variables this font depends on
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <data/locale.hpp>
|
||||
#include <data/installer.hpp>
|
||||
#include <data/format/formats.hpp>
|
||||
#include <data/font.hpp>
|
||||
#include <cli/cli_main.hpp>
|
||||
#include <cli/text_io_handler.hpp>
|
||||
#include <gui/welcome_window.hpp>
|
||||
@@ -86,6 +87,7 @@ int MSE::OnRun() {
|
||||
// Platform friendly appname
|
||||
SetAppName(_("magicseteditor"));
|
||||
#endif
|
||||
Font::PreloadResourceFonts(_("Magic - Fonts"), false);
|
||||
wxInitAllImageHandlers();
|
||||
wxFileSystem::AddHandler(new wxInternetFSHandler); // needed for update checker
|
||||
wxSocketBase::Initialize();
|
||||
|
||||
Reference in New Issue
Block a user