mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Merge pull request #35 from TomTkacz/local_fonts
font rendering/exporting without installing system-wide
This commit is contained in:
+49
-1
@@ -8,7 +8,10 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <data/font.hpp>
|
||||
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/font.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Font
|
||||
|
||||
Font::Font()
|
||||
@@ -23,6 +26,51 @@ Font::Font()
|
||||
, separator_color(Color(0,0,0,128))
|
||||
, 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;
|
||||
|
||||
+8
-4
@@ -45,10 +45,14 @@ public:
|
||||
RealSize shadow_displacement; ///< Position of the shadow
|
||||
double shadow_blur; ///< Blur radius of the shadow
|
||||
Color separator_color; ///< Color for <sep> text
|
||||
int flags; ///< FontFlags for this font
|
||||
|
||||
int flags; ///< FontFlags for this font
|
||||
|
||||
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
|
||||
@@ -64,7 +68,7 @@ public:
|
||||
|
||||
/// Convert this font to a wxFont
|
||||
wxFont toWxFont(double scale) const;
|
||||
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user