Standard paths semi-operational, and font caching (for ft2 retrieval engine) working.

Originally committed to SVN as r1274.
This commit is contained in:
Rodrigo Braz Monteiro 2007-06-20 21:08:31 +00:00
parent 01f49dda8d
commit 2fe424644a
3 changed files with 94 additions and 9 deletions

View File

@ -370,7 +370,7 @@ void FontsCollectorThread::Collect() {
}
// 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();
AppendText(_("done.\n\nScanning file for fonts..."));

View File

@ -40,6 +40,7 @@
////////////
// Includes
#include <wx/dir.h>
#include <wx/tokenzr.h>
#ifdef WIN32
#include <ft2build.h>
#include FT_FREETYPE_H
@ -50,6 +51,7 @@
#include "font_file_lister.h"
#include "text_file_writer.h"
#include "text_file_reader.h"
#include "standard_paths.h"
////////////////////
@ -111,6 +113,9 @@ void FontFileLister::DoClearData() {
void FontFileLister::DoGatherData() {
#ifdef WIN32
// Load cache
LoadCache();
// Get fonts folder
wxString source;
TCHAR szPath[MAX_PATH];
@ -143,6 +148,9 @@ void FontFileLister::DoGatherData() {
}
}
// Save cache
SaveCache();
#else
// TODO: implement fconfig
@ -176,12 +184,58 @@ bool FontFileLister::IsFilenameCached(wxString filename) {
//////////////
// Save cache
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
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 (...) {
}
}

View File

@ -37,6 +37,7 @@
///////////
// Headers
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include "standard_paths.h"
@ -51,10 +52,23 @@ StandardPaths *StandardPaths::GetInstance() {
///////////////
// Constructor
StandardPaths::StandardPaths() {
wxFileName aegiPath(wxStandardPaths::Get().GetExecutablePath());
SetPathValue(_T("?install"),aegiPath.GetPath());
SetPathValue(_T("?user"),wxStandardPaths::Get().GetUserDataDir());
SetPathValue(_T("?temp"),wxStandardPaths::Get().GetTempDir());
// Get paths
wxString dataDir = wxStandardPaths::Get().GetDataDir();
wxString userDir = wxStandardPaths::Get().GetUserDataDir();
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) {
// Decode
if (path[0] == _T('?')) {
// TODO
return path;
// Split ?part from rest
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