forked from mia/Aegisub
Standard paths semi-operational, and font caching (for ft2 retrieval engine) working.
Originally committed to SVN as r1274.
This commit is contained in:
parent
01f49dda8d
commit
2fe424644a
3 changed files with 94 additions and 9 deletions
|
@ -370,7 +370,7 @@ void FontsCollectorThread::Collect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect font data
|
// Collect font data
|
||||||
AppendText(_("Collecting font data from system... "));
|
AppendText(_("Collecting font data from system. This might take a while, depending on the number of fonts installed. Results are cached and subsequent executions will be faster... "));
|
||||||
CollectFontData();
|
CollectFontData();
|
||||||
AppendText(_("done.\n\nScanning file for fonts..."));
|
AppendText(_("done.\n\nScanning file for fonts..."));
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
////////////
|
////////////
|
||||||
// Includes
|
// Includes
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
|
#include <wx/tokenzr.h>
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
@ -50,6 +51,7 @@
|
||||||
#include "font_file_lister.h"
|
#include "font_file_lister.h"
|
||||||
#include "text_file_writer.h"
|
#include "text_file_writer.h"
|
||||||
#include "text_file_reader.h"
|
#include "text_file_reader.h"
|
||||||
|
#include "standard_paths.h"
|
||||||
|
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
|
@ -111,6 +113,9 @@ void FontFileLister::DoClearData() {
|
||||||
void FontFileLister::DoGatherData() {
|
void FontFileLister::DoGatherData() {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
|
// Load cache
|
||||||
|
LoadCache();
|
||||||
|
|
||||||
// Get fonts folder
|
// Get fonts folder
|
||||||
wxString source;
|
wxString source;
|
||||||
TCHAR szPath[MAX_PATH];
|
TCHAR szPath[MAX_PATH];
|
||||||
|
@ -143,6 +148,9 @@ void FontFileLister::DoGatherData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save cache
|
||||||
|
SaveCache();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// TODO: implement fconfig
|
// TODO: implement fconfig
|
||||||
|
@ -176,12 +184,58 @@ bool FontFileLister::IsFilenameCached(wxString filename) {
|
||||||
//////////////
|
//////////////
|
||||||
// Save cache
|
// Save cache
|
||||||
void FontFileLister::SaveCache() {
|
void FontFileLister::SaveCache() {
|
||||||
// TODO
|
try {
|
||||||
|
// Open file
|
||||||
|
TextFileWriter file(StandardPaths::DecodePath(_T("?user/fontcache.dat")));
|
||||||
|
|
||||||
|
// For each face...
|
||||||
|
for (FontMap::iterator iter = fontTable.begin();iter!=fontTable.end();iter++) {
|
||||||
|
// Write face name
|
||||||
|
wxString line = iter->first + _T("?");
|
||||||
|
size_t len = iter->second.Count();
|
||||||
|
|
||||||
|
// Write file names
|
||||||
|
for (size_t i=0;i<len;i++) {
|
||||||
|
line += iter->second[i];
|
||||||
|
if (i != len-1) line += _T("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write line
|
||||||
|
file.WriteLineToFile(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
// Load cache
|
// Load cache
|
||||||
void FontFileLister::LoadCache() {
|
void FontFileLister::LoadCache() {
|
||||||
// TODO
|
try {
|
||||||
|
// Load cache
|
||||||
|
TextFileReader file(StandardPaths::DecodePath(_T("?user/fontcache.dat")));
|
||||||
|
|
||||||
|
// Read each line
|
||||||
|
while (file.HasMoreLines()) {
|
||||||
|
// Read line
|
||||||
|
wxString line = file.ReadLineFromFile();
|
||||||
|
int pos = line.Find(_T('?'));
|
||||||
|
|
||||||
|
// Get face name
|
||||||
|
wxString face = line.Left(pos);
|
||||||
|
if (face.IsEmpty()) continue;
|
||||||
|
|
||||||
|
// Get files
|
||||||
|
wxStringTokenizer tkn(line.Mid(pos+1),_T("|"));
|
||||||
|
while (tkn.HasMoreTokens()) {
|
||||||
|
wxString file = tkn.GetNextToken();
|
||||||
|
if (!file.IsEmpty()) {
|
||||||
|
AddFont(file,face);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
///////////
|
///////////
|
||||||
// Headers
|
// Headers
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
|
#include <wx/filename.h>
|
||||||
#include "standard_paths.h"
|
#include "standard_paths.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,10 +52,23 @@ StandardPaths *StandardPaths::GetInstance() {
|
||||||
///////////////
|
///////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
StandardPaths::StandardPaths() {
|
StandardPaths::StandardPaths() {
|
||||||
wxFileName aegiPath(wxStandardPaths::Get().GetExecutablePath());
|
// Get paths
|
||||||
SetPathValue(_T("?install"),aegiPath.GetPath());
|
wxString dataDir = wxStandardPaths::Get().GetDataDir();
|
||||||
SetPathValue(_T("?user"),wxStandardPaths::Get().GetUserDataDir());
|
wxString userDir = wxStandardPaths::Get().GetUserDataDir();
|
||||||
SetPathValue(_T("?temp"),wxStandardPaths::Get().GetTempDir());
|
wxString tempDir = wxStandardPaths::Get().GetTempDir();
|
||||||
|
|
||||||
|
// Set paths
|
||||||
|
DoSetPathValue(_T("?data"),dataDir);
|
||||||
|
DoSetPathValue(_T("?user"),userDir);
|
||||||
|
DoSetPathValue(_T("?temp"),tempDir);
|
||||||
|
|
||||||
|
// Create paths if they don't exist
|
||||||
|
wxFileName folder(dataDir + _T("/"));
|
||||||
|
if (!folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
|
||||||
|
folder.Assign(userDir + _T("/"));
|
||||||
|
if (!folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
|
||||||
|
folder.Assign(tempDir + _T("/"));
|
||||||
|
if (!folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,8 +77,25 @@ StandardPaths::StandardPaths() {
|
||||||
wxString StandardPaths::DoDecodePath(wxString path) {
|
wxString StandardPaths::DoDecodePath(wxString path) {
|
||||||
// Decode
|
// Decode
|
||||||
if (path[0] == _T('?')) {
|
if (path[0] == _T('?')) {
|
||||||
// TODO
|
// Split ?part from rest
|
||||||
return path;
|
path.Replace(_T("\\"),_T("/"));
|
||||||
|
int pos = path.Find(_T("/"));
|
||||||
|
wxString path1,path2;
|
||||||
|
if (pos == wxNOT_FOUND) path1 = path;
|
||||||
|
else {
|
||||||
|
path1 = path.Left(pos);
|
||||||
|
path2 = path.Mid(pos+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace ?part if valid
|
||||||
|
std::map<wxString,wxString>::iterator iter = paths.find(path1);
|
||||||
|
if (iter == paths.end()) return path;
|
||||||
|
wxString final = iter->second + _T("/") + path2;
|
||||||
|
final.Replace(_T("//"),_T("/"));
|
||||||
|
#ifdef WIN32
|
||||||
|
final.Replace(_T("/"),_T("\\"));
|
||||||
|
#endif
|
||||||
|
return final;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing to decode
|
// Nothing to decode
|
||||||
|
|
Loading…
Reference in a new issue