forked from mia/Aegisub
Improved (but still far from perfect) Fonts Collector performance
Originally committed to SVN as r1714.
This commit is contained in:
parent
a69fe9e71e
commit
3acc7b35a8
4 changed files with 77 additions and 27 deletions
|
@ -40,6 +40,7 @@
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include <wx/wfstream.h>
|
#include <wx/wfstream.h>
|
||||||
#include <wx/zipstrm.h>
|
#include <wx/zipstrm.h>
|
||||||
|
#include <wx/fontenum.h>
|
||||||
#include "ass_override.h"
|
#include "ass_override.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
|
@ -94,12 +95,17 @@ DialogFontsCollector::DialogFontsCollector(wxWindow *parent)
|
||||||
|
|
||||||
// Action radio box
|
// Action radio box
|
||||||
wxArrayString choices;
|
wxArrayString choices;
|
||||||
choices.Add(_T("Check fonts for availability"));
|
choices.Add(_("Check fonts for availability"));
|
||||||
choices.Add(_T("Copy fonts to folder"));
|
choices.Add(_("Copy fonts to folder"));
|
||||||
choices.Add(_T("Copy fonts to zipped archive"));
|
choices.Add(_("Copy fonts to zipped archive"));
|
||||||
choices.Add(_T("Attach fonts to current subtitles"));
|
choices.Add(_("Attach fonts to current subtitles"));
|
||||||
|
#ifdef __WXDEBUG__
|
||||||
|
choices.Add(_("DEBUG: Verify all fonts in system"));
|
||||||
|
#endif
|
||||||
CollectAction = new wxRadioBox(this,RADIO_BOX,_T("Action"),wxDefaultPosition,wxDefaultSize,choices,1);
|
CollectAction = new wxRadioBox(this,RADIO_BOX,_T("Action"),wxDefaultPosition,wxDefaultSize,choices,1);
|
||||||
CollectAction->SetSelection(Options.AsInt(_T("Fonts Collector Action")));
|
size_t lastAction = Options.AsInt(_T("Fonts Collector Action"));
|
||||||
|
if (lastAction >= choices.GetCount()) lastAction = 0;
|
||||||
|
CollectAction->SetSelection(lastAction);
|
||||||
|
|
||||||
// Log box
|
// Log box
|
||||||
LogBox = new wxStyledTextCtrl(this,-1,wxDefaultPosition,wxSize(300,210),0,_T(""));
|
LogBox = new wxStyledTextCtrl(this,-1,wxDefaultPosition,wxSize(300,210),0,_T(""));
|
||||||
|
@ -384,27 +390,35 @@ void FontsCollectorThread::Collect() {
|
||||||
wxMutexGuiLeave();
|
wxMutexGuiLeave();
|
||||||
|
|
||||||
// Scan file
|
// Scan file
|
||||||
AssDialogue *curDiag;
|
if (collector->CollectAction->GetSelection() != 4) {
|
||||||
curLine = 0;
|
AssDialogue *curDiag;
|
||||||
for (std::list<AssEntry*>::iterator cur=subs->Line.begin();cur!=subs->Line.end();cur++) {
|
curLine = 0;
|
||||||
// Collect from style
|
for (std::list<AssEntry*>::iterator cur=subs->Line.begin();cur!=subs->Line.end();cur++) {
|
||||||
curStyle = AssEntry::GetAsStyle(*cur);
|
// Collect from style
|
||||||
if (curStyle) {
|
curStyle = AssEntry::GetAsStyle(*cur);
|
||||||
AddFont(curStyle->font,true);
|
if (curStyle) {
|
||||||
}
|
AddFont(curStyle->font,0);
|
||||||
|
}
|
||||||
|
|
||||||
// Collect from dialogue
|
// Collect from dialogue
|
||||||
else {
|
else {
|
||||||
curDiag = AssEntry::GetAsDialogue(*cur);
|
curDiag = AssEntry::GetAsDialogue(*cur);
|
||||||
if (curDiag) {
|
if (curDiag) {
|
||||||
curLine++;
|
curLine++;
|
||||||
curDiag->ParseASSTags();
|
curDiag->ParseASSTags();
|
||||||
curDiag->ProcessParameters(GetFonts);
|
curDiag->ProcessParameters(GetFonts);
|
||||||
curDiag->ClearBlocks();
|
curDiag->ClearBlocks();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For maitenance, gather all on system
|
||||||
|
else {
|
||||||
|
wxArrayString fonts = wxFontEnumerator::GetFacenames();
|
||||||
|
for (size_t i=0;i<fonts.Count();i++) AddFont(fonts[i],2);
|
||||||
|
}
|
||||||
|
|
||||||
// Copy fonts
|
// Copy fonts
|
||||||
wxMutexGuiEnter();
|
wxMutexGuiEnter();
|
||||||
AppendText(wxString(_("Done.")) + _T("\n\n"));
|
AppendText(wxString(_("Done.")) + _T("\n\n"));
|
||||||
|
@ -484,7 +498,7 @@ bool FontsCollectorThread::ProcessFont(wxString name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just checking, found
|
// Just checking, found
|
||||||
else if (action == 0) {
|
else if (action == 0 || action == 4) {
|
||||||
AppendText(_("Found.\n"),1);
|
AppendText(_("Found.\n"),1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -565,14 +579,14 @@ bool FontsCollectorThread::AttachFont(wxString filename) {
|
||||||
// Get fonts from ass overrides
|
// Get fonts from ass overrides
|
||||||
void FontsCollectorThread::GetFonts (wxString tagName,int par_n,AssOverrideParameter *param,void *usr) {
|
void FontsCollectorThread::GetFonts (wxString tagName,int par_n,AssOverrideParameter *param,void *usr) {
|
||||||
if (tagName == _T("\\fn")) {
|
if (tagName == _T("\\fn")) {
|
||||||
instance->AddFont(param->AsText(),false);
|
instance->AddFont(param->AsText(),1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Adds a font
|
// Adds a font
|
||||||
void FontsCollectorThread::AddFont(wxString fontname,bool isStyle) {
|
void FontsCollectorThread::AddFont(wxString fontname,int mode) {
|
||||||
// @-fonts (CJK vertical layout variations) should be listed as the non-@ name
|
// @-fonts (CJK vertical layout variations) should be listed as the non-@ name
|
||||||
if (fontname.StartsWith(_T("@"), 0))
|
if (fontname.StartsWith(_T("@"), 0))
|
||||||
fontname.Remove(0, 1);
|
fontname.Remove(0, 1);
|
||||||
|
@ -580,8 +594,9 @@ void FontsCollectorThread::AddFont(wxString fontname,bool isStyle) {
|
||||||
if (fonts.Index(fontname) == wxNOT_FOUND) {
|
if (fonts.Index(fontname) == wxNOT_FOUND) {
|
||||||
fonts.Add(fontname);
|
fonts.Add(fontname);
|
||||||
|
|
||||||
if (isStyle) AppendText(wxString::Format(_("\"%s\" found on style \"%s\".\n"), fontname.c_str(), curStyle->name.c_str()));
|
if (mode == 0) AppendText(wxString::Format(_("\"%s\" found on style \"%s\".\n"), fontname.c_str(), curStyle->name.c_str()));
|
||||||
if (!isStyle) AppendText(wxString::Format(_("\"%s\" found on dialogue line \"%d\".\n"), fontname.c_str(), curLine));
|
else if (mode == 1) AppendText(wxString::Format(_("\"%s\" found on dialogue line \"%d\".\n"), fontname.c_str(), curLine));
|
||||||
|
else AppendText(wxString::Format(_("\"%s\" found.\n"), fontname.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ private:
|
||||||
bool AttachFont(wxString filename);
|
bool AttachFont(wxString filename);
|
||||||
|
|
||||||
void Collect();
|
void Collect();
|
||||||
void AddFont(wxString fontname,bool isStyle);
|
void AddFont(wxString fontname,int mode);
|
||||||
void CollectFontData();
|
void CollectFontData();
|
||||||
void AppendText(wxString text,int colour=0);
|
void AppendText(wxString text,int colour=0);
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,11 @@ void FontFileLister::ClearCache() {
|
||||||
////////////
|
////////////
|
||||||
// Add font
|
// Add font
|
||||||
void FontFileLister::AddFont(wxString filename,wxString facename) {
|
void FontFileLister::AddFont(wxString filename,wxString facename) {
|
||||||
|
// See if it's a valid facename
|
||||||
|
facename.Trim(true).Trim(false);
|
||||||
|
if (facename.IsEmpty()) return;
|
||||||
|
if (facename.Lower().StartsWith(_T("copyright "))) return;
|
||||||
|
|
||||||
// Add filename to general list
|
// Add filename to general list
|
||||||
if (fontFiles.Index(filename) == wxNOT_FOUND) {
|
if (fontFiles.Index(filename) == wxNOT_FOUND) {
|
||||||
fontFiles.Add(filename);
|
fontFiles.Add(filename);
|
||||||
|
|
|
@ -64,6 +64,21 @@ FreetypeFontFileLister::~FreetypeFontFileLister() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
|
// Get name from face
|
||||||
|
wxString GetName(FT_Face &face,int i) {
|
||||||
|
// Get name
|
||||||
|
FT_SfntName name;
|
||||||
|
FT_Get_Sfnt_Name(face,i,&name);
|
||||||
|
char *str = new char[name.string_len+1];
|
||||||
|
memcpy(str,name.string,name.string_len);
|
||||||
|
str[name.string_len] = 0;
|
||||||
|
wxString final(str, wxConvLocal);
|
||||||
|
delete [] str;
|
||||||
|
return final;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
// Gather data from system
|
// Gather data from system
|
||||||
void FreetypeFontFileLister::DoInitialize() {
|
void FreetypeFontFileLister::DoInitialize() {
|
||||||
|
@ -104,8 +119,23 @@ void FreetypeFontFileLister::DoInitialize() {
|
||||||
fterr = FT_New_Face(ft2lib, fontfiles[i].mb_str(*wxConvFileName), facenum, &face);
|
fterr = FT_New_Face(ft2lib, fontfiles[i].mb_str(*wxConvFileName), facenum, &face);
|
||||||
if (fterr) break;
|
if (fterr) break;
|
||||||
|
|
||||||
|
// Special names for TTF and OTF
|
||||||
|
int nameCount = 0;
|
||||||
|
wxString ext = fontfiles[i].Right(4).Lower();
|
||||||
|
if (ext == _T(".otf") || ext == _T(".ttf") || ext == _T(".ttc_")) nameCount = FT_Get_Sfnt_Name_Count(face);
|
||||||
|
if (nameCount >= 5) {
|
||||||
|
wxString family = GetName(face,1);
|
||||||
|
wxString subFamily = GetName(face,2);
|
||||||
|
wxString fullName = GetName(face,4);
|
||||||
|
//AddFont(fontfiles[i],family);
|
||||||
|
AddFont(fontfiles[i],family + _T(" ") + subFamily);;
|
||||||
|
AddFont(fontfiles[i],fullName);
|
||||||
|
AddFont(fontfiles[i],GetName(face,11));
|
||||||
|
}
|
||||||
|
|
||||||
// Add font
|
// Add font
|
||||||
AddFont(fontfiles[i],wxString(face->family_name, wxConvLocal));
|
AddFont(fontfiles[i],wxString(face->family_name, wxConvLocal));
|
||||||
|
if (face->style_name) AddFont(fontfiles[i],wxString(face->family_name, wxConvLocal) + _T(" ") + wxString(face->style_name, wxConvLocal));
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue