From: Marco Pesenti Gritti Date: Mon, 13 Jun 2005 18:45:06 +0000 (+0000) Subject: Separate scan and fill so that we can incrementally fill from the main X-Git-Tag: EVINCE_0_3_3~256 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=7fef38d9e59026334152230f1cd847e163e8457c;p=evince.git Separate scan and fill so that we can incrementally fill from the main 2005-06-13 Marco Pesenti Gritti * backend/ev-document-fonts.c: (ev_document_fonts_get_progress), (ev_document_fonts_scan), (ev_document_fonts_fill_model): * backend/ev-document-fonts.h: Separate scan and fill so that we can incrementally fill from the main thread. Add a progress api. * data/evince-properties.glade: * pdf/ev-poppler.cc: * shell/ev-jobs.c: (ev_job_fonts_new), (ev_job_fonts_run): * shell/ev-jobs.h: * shell/ev-properties.c: (update_progress_label), (job_fonts_finished_cb), (setup_fonts_view): Incrementally feel the list and show the progress percentage in a label like acrobat does. --- diff --git a/ChangeLog b/ChangeLog index b446f786..f2a3b7d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2005-06-13 Marco Pesenti Gritti + + * backend/ev-document-fonts.c: (ev_document_fonts_get_progress), + (ev_document_fonts_scan), (ev_document_fonts_fill_model): + * backend/ev-document-fonts.h: + + Separate scan and fill so that we can incrementally fill from + the main thread. Add a progress api. + + * data/evince-properties.glade: + * pdf/ev-poppler.cc: + * shell/ev-jobs.c: (ev_job_fonts_new), (ev_job_fonts_run): + * shell/ev-jobs.h: + * shell/ev-properties.c: (update_progress_label), + (job_fonts_finished_cb), (setup_fonts_view): + + Incrementally feel the list and show the progress + percentage in a label like acrobat does. + + You are going to need poppler cvs + 2005-06-11 Marco Pesenti Gritti * backend/ev-document-fonts.c: (ev_document_fonts_fill_model): diff --git a/backend/ev-document-fonts.c b/backend/ev-document-fonts.c index cd53d1e9..854383dd 100644 --- a/backend/ev-document-fonts.c +++ b/backend/ev-document-fonts.c @@ -47,12 +47,28 @@ ev_document_fonts_get_type (void) return type; } +double +ev_document_fonts_get_progress (EvDocumentFonts *document_fonts) +{ + EvDocumentFontsIface *iface = EV_DOCUMENT_FONTS_GET_IFACE (document_fonts); + + return iface->get_progress (document_fonts); +} + gboolean +ev_document_fonts_scan (EvDocumentFonts *document_fonts, + int n_pages) +{ + EvDocumentFontsIface *iface = EV_DOCUMENT_FONTS_GET_IFACE (document_fonts); + + return iface->scan (document_fonts, n_pages); +} + +void ev_document_fonts_fill_model (EvDocumentFonts *document_fonts, - GtkTreeModel *model, - int n_pages) + GtkTreeModel *model) { EvDocumentFontsIface *iface = EV_DOCUMENT_FONTS_GET_IFACE (document_fonts); - return iface->fill_model (document_fonts, model, n_pages); + iface->fill_model (document_fonts, model); } diff --git a/backend/ev-document-fonts.h b/backend/ev-document-fonts.h index 2a05e7ee..d069b9d8 100644 --- a/backend/ev-document-fonts.h +++ b/backend/ev-document-fonts.h @@ -53,16 +53,20 @@ struct _EvDocumentFontsIface { GTypeInterface base_iface; - /* Methods */ - gboolean (* fill_model) (EvDocumentFonts *document_fonts, - GtkTreeModel *model, - int n_pages); + /* Methods */ + gboolean (* scan) (EvDocumentFonts *document_fonts, + int n_pages); + double (* get_progress) (EvDocumentFonts *document_fonts); + void (* fill_model) (EvDocumentFonts *document_fonts, + GtkTreeModel *model); }; -GType ev_document_fonts_get_type (void); -gboolean ev_document_fonts_fill_model (EvDocumentFonts *document_fonts, - GtkTreeModel *model, - int n_pages); +GType ev_document_fonts_get_type (void); +gboolean ev_document_fonts_scan (EvDocumentFonts *document_fonts, + int n_pages); +double ev_document_fonts_get_progress (EvDocumentFonts *document_fonts); +void ev_document_fonts_fill_model (EvDocumentFonts *document_fonts, + GtkTreeModel *model); G_END_DECLS diff --git a/data/evince-properties.glade b/data/evince-properties.glade index a6727163..837ecd5a 100644 --- a/data/evince-properties.glade +++ b/data/evince-properties.glade @@ -16,7 +16,6 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_CENTER - True False @@ -85,10 +84,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -113,10 +108,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -141,10 +132,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -169,10 +156,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -197,10 +180,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -225,10 +204,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -253,10 +228,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -281,10 +252,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -309,10 +276,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -337,10 +300,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -365,10 +324,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -393,10 +348,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 0 @@ -422,10 +373,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 1 @@ -451,10 +398,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 1 @@ -480,10 +423,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 1 @@ -509,10 +448,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 1 @@ -538,10 +473,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 1 @@ -567,10 +498,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 1 @@ -596,10 +523,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_END - -1 - False - 0 1 @@ -624,10 +547,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_END - -1 - False - 0 1 @@ -652,10 +571,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_END - -1 - False - 0 1 @@ -680,10 +595,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_END - -1 - False - 0 1 @@ -708,10 +619,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_END - -1 - False - 0 1 @@ -736,10 +643,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_END - -1 - False - 0 1 @@ -769,10 +672,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 tab @@ -784,7 +683,7 @@ 12 True False - 0 + 6 @@ -799,13 +698,10 @@ True True - True + False False False True - False - False - False @@ -815,6 +711,27 @@ True + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + False @@ -835,10 +752,6 @@ 0.5 0 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 tab diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index 8d555aff..7c60d9cf 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -56,6 +56,10 @@ struct _PdfDocument PopplerPSFile *ps_file; gchar *password; + PopplerFontInfo *font_info; + PopplerFontsIter *fonts_iter; + int fonts_scanned_pages; + PdfDocumentSearch *search; }; @@ -100,6 +104,14 @@ pdf_document_dispose (GObject *object) if (pdf_document->document) { g_object_unref (pdf_document->document); } + + if (pdf_document->font_info) { + poppler_font_info_free (pdf_document->font_info); + } + + if (pdf_document->fonts_iter) { + poppler_fonts_iter_free (pdf_document->fonts_iter); + } } static void @@ -495,28 +507,55 @@ pdf_document_security_iface_init (EvDocumentSecurityIface *iface) iface->set_password = pdf_document_set_password; } +static gdouble +pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts); + int n_pages; + + n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document)); + + return (double)pdf_document->fonts_scanned_pages / (double)n_pages; +} + static gboolean -pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts, - GtkTreeModel *model, - int n_pages) +pdf_document_fonts_scan (EvDocumentFonts *document_fonts, + int n_pages) { -#ifdef POPPLER_FONT_INFO PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts); - PopplerFontInfo *info; - PopplerFontsIter *iter; gboolean result; g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE); - info = (PopplerFontInfo *)g_object_get_data (G_OBJECT (model), "font_info"); - if (info == NULL) { - info = poppler_font_info_new (pdf_document->document); - g_object_set_data_full (G_OBJECT (model), "font_info", - (PopplerFontInfo *)info, - (GDestroyNotify)poppler_font_info_free); + if (pdf_document->font_info == NULL) { + pdf_document->font_info = poppler_font_info_new (pdf_document->document); + } + + if (pdf_document->fonts_iter) { + poppler_fonts_iter_free (pdf_document->fonts_iter); } - result = poppler_font_info_scan (info, n_pages, &iter); + pdf_document->fonts_scanned_pages += n_pages; + + result = poppler_font_info_scan (pdf_document->font_info, n_pages, + &pdf_document->fonts_iter); + if (!result) { + pdf_document->fonts_scanned_pages = 0; + poppler_font_info_free (pdf_document->font_info); + pdf_document->font_info = NULL; + } + + return result; +} + +static void +pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts, + GtkTreeModel *model) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts); + PopplerFontsIter *iter = pdf_document->fonts_iter; + + g_return_if_fail (PDF_IS_DOCUMENT (document_fonts)); if (iter) { do { @@ -530,19 +569,15 @@ pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts, EV_DOCUMENT_FONTS_COLUMN_NAME, name, -1); } while (poppler_fonts_iter_next (iter)); - poppler_fonts_iter_free (iter); } - - return result; -#else - return FALSE; -#endif } static void pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface) { iface->fill_model = pdf_document_fonts_fill_model; + iface->scan = pdf_document_fonts_scan; + iface->get_progress = pdf_document_fonts_get_progress; } static gboolean diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index 82f310f4..20ebf856 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -347,15 +347,13 @@ static void ev_job_fonts_init (EvJobFonts *job) { /* Do Nothing */ } static void ev_job_fonts_class_init (EvJobFontsClass *class) { /* Do Nothing */ } EvJob * -ev_job_fonts_new (EvDocument *document, - GtkTreeModel *model) +ev_job_fonts_new (EvDocument *document) { EvJobFonts *job; job = g_object_new (EV_TYPE_JOB_FONTS, NULL); EV_JOB (job)->document = g_object_ref (document); - job->model = g_object_ref (model); return EV_JOB (job); } @@ -370,7 +368,7 @@ ev_job_fonts_run (EvJobFonts *job) ev_document_doc_mutex_lock (); fonts = EV_DOCUMENT_FONTS (EV_JOB (job)->document); - job->scan_completed = !ev_document_fonts_fill_model (fonts, job->model, 20); + job->scan_completed = !ev_document_fonts_scan (fonts, 20); EV_JOB (job)->finished = TRUE; diff --git a/shell/ev-jobs.h b/shell/ev-jobs.h index d585d867..900d0405 100644 --- a/shell/ev-jobs.h +++ b/shell/ev-jobs.h @@ -152,7 +152,6 @@ struct _EvJobLoadClass struct _EvJobFonts { EvJob parent; - GtkTreeModel *model; gboolean scan_completed; }; @@ -195,8 +194,7 @@ void ev_job_load_run (EvJobLoad *load); /* EvJobFonts */ GType ev_job_fonts_get_type (void); -EvJob *ev_job_fonts_new (EvDocument *document, - GtkTreeModel *model); +EvJob *ev_job_fonts_new (EvDocument *document); void ev_job_fonts_run (EvJobFonts *fonts); G_END_DECLS diff --git a/shell/ev-properties.c b/shell/ev-properties.c index 6007f134..e8eca8f4 100644 --- a/shell/ev-properties.c +++ b/shell/ev-properties.c @@ -105,62 +105,61 @@ set_property (GladeXML *xml, Property property, const char *text) gtk_label_set_text (GTK_LABEL (widget), text ? text : ""); } +static void +update_progress_label (GtkWidget *label, double progress) +{ + if (progress > 0) { + char *progress_text; + progress_text = g_strdup_printf (_("Gathering font information... %3d%%"), + (int) (progress * 100)); + gtk_label_set_text (GTK_LABEL (label), progress_text); + g_free (progress_text); + } else { + gtk_label_set_text (GTK_LABEL (label), ""); + } +} + static void job_fonts_finished_cb (EvJob *job, GtkTreeView *tree_view) { - GtkTreeModel *model = EV_JOB_FONTS (job)->model; + EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (job->document); + GtkWidget *progress_label; + double progress; + + progress_label = g_object_get_data (G_OBJECT (tree_view), "progress_label"); + progress = ev_document_fonts_get_progress (document_fonts); + update_progress_label (progress_label, progress); if (EV_JOB_FONTS (job)->scan_completed) { g_signal_handlers_disconnect_by_func (job, job_fonts_finished_cb, tree_view); - gtk_tree_view_set_model (tree_view, model); } else { - EvJob *new_job = ev_job_fonts_new (job->document, model); + EvJob *new_job; + + ev_document_fonts_fill_model (document_fonts, + gtk_tree_view_get_model (tree_view)); + new_job = ev_job_fonts_new (job->document); ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW); g_object_unref (new_job); } } -static void -fill_fonts_treeview (GtkTreeView *tree_view, - EvDocument *document) -{ - GtkListStore *list_store; - EvJob *job; - - list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING); - g_object_set_data_full (G_OBJECT (tree_view), "list_store", - list_store, g_object_unref); - - job = ev_job_fonts_new (document, GTK_TREE_MODEL (list_store)); - g_signal_connect_object (job, "finished", - G_CALLBACK (job_fonts_finished_cb), - tree_view, 0); - ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW); - g_object_unref (job); -} - static void setup_fonts_view (GladeXML *xml, EvDocument *document) { - GtkWidget *widget; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkListStore *list_store; - GtkTreeIter iter; - - widget = glade_xml_get_widget (xml, "fonts_treeview"); - - list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING); - gtk_list_store_append (list_store, &iter); - gtk_list_store_set (list_store, &iter, FONT_NAME_COL, _("Loading..."), -1); + EvJob *job; + GtkWidget *tree_view; + GtkWidget *progress_label; - gtk_tree_view_set_model (GTK_TREE_VIEW (widget), GTK_TREE_MODEL (list_store)); - g_object_unref (list_store); + tree_view = glade_xml_get_widget (xml, "fonts_treeview"); + progress_label = glade_xml_get_widget (xml, "font_progress_label"); column = gtk_tree_view_column_new (); gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (widget), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE); @@ -169,7 +168,18 @@ setup_fonts_view (GladeXML *xml, EvDocument *document) "text", EV_DOCUMENT_FONTS_COLUMN_NAME, NULL); - fill_fonts_treeview (GTK_TREE_VIEW (widget), document); + list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING); + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), + GTK_TREE_MODEL (list_store)); + + job = ev_job_fonts_new (document); + g_object_set_data (G_OBJECT (tree_view), "progress_label", + progress_label); + g_signal_connect_object (job, "finished", + G_CALLBACK (job_fonts_finished_cb), + tree_view, 0); + ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW); + g_object_unref (job); } GtkDialog *