Ticket #841: libass_fontupdate_dialog-2.patch

File libass_fontupdate_dialog-2.patch, 3.4 KB (added by nielsm, 2 years ago)

Semi-working patch (builds and mostly works)

  • src/subtitles_provider_libass.cpp

     
    4646#include "utils.h" 
    4747#include "standard_paths.h" 
    4848#include <wx/filefn.h> 
     49#include <wx/thread.h> 
     50#include <wx/dialog.h> 
     51#include <wx/gauge.h> 
     52#include <wx/utils.h> 
    4953 
    5054#ifdef __APPLE__ 
    5155extern "C" { 
     
    5458} 
    5559#endif 
    5660 
    57 #define STUB_MSG _("Please wait, caching fonts..."); 
    5861 
     62 
     63DEFINE_EVENT_TYPE(AEGISUB_LIBASS_FONTUPDATE_FINISH) 
     64 
     65class AegisubLibassFontupdateFinishEvent : public wxEvent { 
     66public: 
     67        AegisubLibassFontupdateFinishEvent() 
     68                : wxEvent(0, AEGISUB_LIBASS_FONTUPDATE_FINISH) 
     69        { } 
     70        virtual wxEvent *Clone() const { 
     71                return new AegisubLibassFontupdateFinishEvent(*this); 
     72        } 
     73}; 
     74 
     75class LibassFontUpdateThread : public wxThread { 
     76        wxEvtHandler *completion_event_handler; 
     77        ASS_Renderer *renderer; 
     78 
     79public: 
     80        LibassFontUpdateThread(wxEvtHandler *completion_event_handler, ASS_Renderer *renderer) 
     81                : wxThread(wxTHREAD_JOINABLE) 
     82                , completion_event_handler(completion_event_handler) 
     83                , renderer(renderer) 
     84        { 
     85                Create(); 
     86                Run(); 
     87        } 
     88 
     89        ExitCode Entry() { 
     90                printf("=== begin fonts updating ===\n"); 
     91                ass_fonts_update(renderer); 
     92                printf("=== end fonts updating ===\n"); 
     93                completion_event_handler->AddPendingEvent(AegisubLibassFontupdateFinishEvent()); 
     94                return 0; 
     95        } 
     96}; 
     97 
     98 
     99class LibassFontUpdateStatusDialog : public wxDialog { 
     100        void OnDoneUpdating(AegisubLibassFontupdateFinishEvent &evt) { 
     101                Destroy(); 
     102        } 
     103         
     104        void OnTimer(wxTimerEvent &evt) { 
     105                Show(); 
     106        } 
     107         
     108        wxTimer timer; 
     109 
     110public: 
     111        LibassFontUpdateStatusDialog() 
     112                : wxDialog(0, -1, _T(""), wxDefaultPosition, wxDefaultSize, 0) 
     113                , timer(this, -1) 
     114        { 
     115                wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL); 
     116 
     117                main_sizer->Add(new wxStaticText(this, -1, _("Please wait, caching fonts...")), 0, wxEXPAND|wxALL, 12); 
     118 
     119                wxGauge *gauge = new wxGauge(this, -1, 1, wxDefaultPosition, wxSize(350, -1)); 
     120                gauge->Pulse(); 
     121                main_sizer->Add(gauge, 0, wxEXPAND|wxALL&~wxTOP, 12); 
     122                 
     123                Connect(-1, -1, AEGISUB_LIBASS_FONTUPDATE_FINISH, 
     124                        (wxObjectEventFunction)&LibassFontUpdateStatusDialog::OnDoneUpdating, 
     125                        0, this); 
     126                Connect(timer.GetId(), -1, wxEVT_TIMER, 
     127                        (wxObjectEventFunction)&LibassFontUpdateStatusDialog::OnTimer, 
     128                        0, this); 
     129                 
     130                timer.Start(500, true); 
     131 
     132                SetSizerAndFit(main_sizer); 
     133                CentreOnScreen(); 
     134        } 
     135         
     136        void WaitForUpdatingFinish(wxThread *thread) { 
     137                wxWindowDisabler disabler(this); 
     138                wxApp &app = *wxTheApp; 
     139                while (thread->IsAlive()) { 
     140                        while (app.Pending()) 
     141                                app.Dispatch(); 
     142                        wxYield(); 
     143                } 
     144                thread->Wait(); 
     145        } 
     146}; 
     147 
     148 
     149 
    59150/////////////// 
    60151// Constructor 
    61152LibassSubtitlesProvider::LibassSubtitlesProvider() { 
     
    93184        const char *config_path = NULL; 
    94185#endif 
    95186 
    96         ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 1); 
     187        printf("enter ass_set_fonts\n"); 
     188        ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 0); 
     189 
     190        printf("create font update status dlg\n"); 
     191        LibassFontUpdateStatusDialog *fonts_update_dlg = new LibassFontUpdateStatusDialog; 
     192        printf("create font update thread\n"); 
     193        wxThread * update_thread = new LibassFontUpdateThread(fonts_update_dlg, ass_renderer); 
     194        printf("show font update dialog\n"); 
     195        fonts_update_dlg->WaitForUpdatingFinish(update_thread); 
     196        printf("back from font update dialog\n"); 
    97197} 
    98198 
    99199