| | 62 | |
| | 63 | DEFINE_EVENT_TYPE(AEGISUB_LIBASS_FONTUPDATE_FINISH) |
| | 64 | |
| | 65 | class AegisubLibassFontupdateFinishEvent : public wxEvent { |
| | 66 | public: |
| | 67 | AegisubLibassFontupdateFinishEvent() |
| | 68 | : wxEvent(0, AEGISUB_LIBASS_FONTUPDATE_FINISH) |
| | 69 | { } |
| | 70 | virtual wxEvent *Clone() const { |
| | 71 | return new AegisubLibassFontupdateFinishEvent(*this); |
| | 72 | } |
| | 73 | }; |
| | 74 | |
| | 75 | class LibassFontUpdateThread : public wxThread { |
| | 76 | wxEvtHandler *completion_event_handler; |
| | 77 | ASS_Renderer *renderer; |
| | 78 | |
| | 79 | public: |
| | 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 | |
| | 99 | class 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 | |
| | 110 | public: |
| | 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 | |
| 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"); |