From f36ccd9e99a1ee9c5dfe706f68b1ed84eb759acf Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Wed, 20 Jun 2007 07:10:41 +0000 Subject: [PATCH] Fonts collector seemingly all fixed and done, except for lack of font caching and use of fc on unix. Originally committed to SVN as r1272. --- aegisub/changelog.txt | 8 ++- aegisub/dialog_fonts_collector.cpp | 88 ++++++++++++++++++++++++------ aegisub/dialog_fonts_collector.h | 2 + 3 files changed, 79 insertions(+), 19 deletions(-) diff --git a/aegisub/changelog.txt b/aegisub/changelog.txt index 818586108..e6639f125 100644 --- a/aegisub/changelog.txt +++ b/aegisub/changelog.txt @@ -112,13 +112,19 @@ Please visit http://aegisub.net to download latest version o Fixed glitches related to the Duration time edit box. (AMZ) o Tweaked the behavior of the margin boxes, now they no longer show padding zeros. (AMZ) o Actor and Effect fields now show a "ghosted" caption saying their name when they are not focused on and blank. (AMZ) +- Changes to Fonts Collector: + o Changed the font searching engine to something slower, but far more reliable. (jfs/AMZ) + o Added option to just verify if you have the fonts. (AMZ) + o You can now collect fonts directly to a zipped archive. (AMZ) + o Fixed behavior of the Escape key in it. (AMZ) + o Redesigned the interface and replaced the log window with a much better Scintilla control. (AMZ) + o You can now collect multiple times without reopening the dialog. (AMZ) - Added a much-needed options dialog with all the relevant config.dat options in it. (AMZ) - Various fixes to better handle paths/file names with non-ANSI characters on Windows (jfs/AMZ) - Misc. fixes for building on Linux (Azzy, equinox, jfs) - Added an option to automatically save the files whenever you change anything. (AMZ) - Added global hotkey for Video Play (default Ctrl+P). (AMZ) - Commiting changes in audio to the last line will insert a new line after it. (AMZ) -- Fonts collector can now collect fonts directly to a zipped archive; also, fixed behavior of the Escape key in it. (AMZ) - Added two options that allows you to specify where to keep the audio cache. (AMZ) - Improved Splash Screen behavior to show up even if the program is frozen loading subtitles, and to center on the current display. (AMZ) - Aegisub now remembers if it was maximized when it was last quit, and restores its state when opening again. (AMZ) diff --git a/aegisub/dialog_fonts_collector.cpp b/aegisub/dialog_fonts_collector.cpp index 6448c0294..88194fd8b 100644 --- a/aegisub/dialog_fonts_collector.cpp +++ b/aegisub/dialog_fonts_collector.cpp @@ -158,16 +158,36 @@ END_EVENT_TABLE() //////////////////// // Start processing void DialogFontsCollector::OnStart(wxCommandEvent &event) { - // Check if it's OK to do it - wxString foldername = DestBox->GetValue(); - wxFileName folder(foldername); + // Action being done int action = CollectAction->GetSelection(); + // Check if it's OK to do it + wxString foldername = DestBox->GetValue(); + if (action == 1) foldername += _T("//"); + wxFileName folder(foldername); + bool isFolder = folder.IsDir(); + + // Check if it's a folder + if (action == 1 && !isFolder) { + wxMessageBox(_("Invalid destination."),_("Error"),wxICON_EXCLAMATION | wxOK); + return; + } + // Make folder if it doesn't exist - if (action == 1 && !folder.DirExists()) { - folder.Mkdir(0777,wxPATH_MKDIR_FULL); + if (action == 1 || action == 2) { if (!folder.DirExists()) { - wxMessageBox(_("Invalid destination"),_("Error"),wxICON_EXCLAMATION | wxOK); + folder.Mkdir(0777,wxPATH_MKDIR_FULL); + if (!folder.DirExists()) { + wxMessageBox(_("Could not create destination folder."),_("Error"),wxICON_EXCLAMATION | wxOK); + return; + } + } + } + + // Check if we have a valid archive name + if (action == 2) { + if (isFolder || folder.GetName().IsEmpty() || folder.GetExt() != _T("zip")) { + wxMessageBox(_("Invalid path for .zip file."),_("Error"),wxICON_EXCLAMATION | wxOK); return; } } @@ -243,6 +263,7 @@ void DialogFontsCollector::Update(int value) { CloseButton->Enable(true); StartButton->Enable(true); CollectAction->Enable(true); + wxString dst = DestBox->GetValue(); // Get value if -1 if (value == -1) { @@ -264,17 +285,10 @@ void DialogFontsCollector::Update(int value) { DestLabel->Enable(true); DestLabel->SetLabel(_("Choose the folder where the fonts will be collected to.\nIt will be created if it doesn't exist.")); - // Remove filename from browser box - wxFileName fname1(DestBox->GetValue()+_T("/")); - if (fname1.DirExists()) { - DestBox->SetValue(fname1.GetPath()); - } - else { - wxFileName fname2(DestBox->GetValue()); - if (fname2.DirExists()) { - DestBox->SetValue(fname2.GetPath()); - } - else DestBox->SetValue(((AegisubApp*)wxTheApp)->folderName); + // Remove filename from browse box + if (dst.Right(4) == _T(".zip")) { + wxFileName fn(dst); + DestBox->SetValue(fn.GetPath()); } } @@ -284,6 +298,13 @@ void DialogFontsCollector::Update(int value) { BrowseButton->Enable(true); DestLabel->Enable(true); DestLabel->SetLabel(_("Enter the name of the destination zip file to collect the fonts to.\nIf a folder is entered, a default name will be used.")); + + // Add filename to browse box + if (dst.Right(4) != _T(".zip")) { + wxFileName fn(dst + _T("//")); + fn.SetFullName(_T("fonts.zip")); + DestBox->SetValue(fn.GetFullPath()); + } } } @@ -340,6 +361,14 @@ void FontsCollectorThread::Collect() { return; } + // Open zip stream if saving to compressed archive + wxFFileOutputStream *out = NULL; + zip = NULL; + if (oper == 2) { + out = new wxFFileOutputStream(destFolder); + zip = new wxZipOutputStream(*out); + } + // Collect font data AppendText(_("Collecting font data from system... ")); CollectFontData(); @@ -383,6 +412,15 @@ void FontsCollectorThread::Collect() { if (!result) ok = false; } + // Close ZIP archive + if (oper == 2) { + zip->Close(); + delete zip; + delete out; + + AppendText(wxString::Format(_("\nFinished writing to %s.\n"),destination.c_str()),1); + } + // Final result if (ok) { if (oper == 0) AppendText(_("Done. All fonts found."),1); @@ -471,7 +509,21 @@ int FontsCollectorThread::CopyFont(wxString filename) { //////////////// // Archive font bool FontsCollectorThread::ArchiveFont(wxString filename) { - return false; + // Open file + wxFFileInputStream in(filename); + if (!in.IsOk()) return false; + + // Write to archive + try { + wxFileName fn(filename); + zip->PutNextEntry(fn.GetFullName()); + zip->Write(in); + } + catch (...) { + return false; + } + + return true; } diff --git a/aegisub/dialog_fonts_collector.h b/aegisub/dialog_fonts_collector.h index 25c0c24c7..75a84e15a 100644 --- a/aegisub/dialog_fonts_collector.h +++ b/aegisub/dialog_fonts_collector.h @@ -49,6 +49,7 @@ class AssFile; class AssOverrideParameter; class DialogFontsCollector; class FrameMain; +class wxZipOutputStream; ///////////////// @@ -59,6 +60,7 @@ private: AssStyle *curStyle; wxString destination; DialogFontsCollector *collector; + wxZipOutputStream *zip; int curLine; wxString destFolder;