[evince] Fixed the calculus about the maximum width of the label with the page count
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] Fixed the calculus about the maximum width of the label with the page count
- Date: Thu, 21 Apr 2016 16:00:09 +0000 (UTC)
commit 524f28d50c2789dad53bc89ca55c6a907f90b3c3
Author: echo-devim <devim outlook it>
Date: Thu Apr 21 08:34:26 2016 +0200
Fixed the calculus about the maximum width of the label with the page count
With this patch Evince doesn't keep in memory the page_labels array
anymore for the documents that have the text of the page label equal to
the page number. In this manner is possible to manage properly the
documents that have a custom page label calculating the right width for
the label with the page count.
https://bugzilla.gnome.org/show_bug.cgi?id=764771
libdocument/ev-document.c | 24 ++++++++++++++----------
libmisc/ev-page-action-widget.c | 2 +-
2 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c
index 6af0ad7..425a2e7 100644
--- a/libdocument/ev-document.c
+++ b/libdocument/ev-document.c
@@ -115,15 +115,7 @@ ev_document_finalize (GObject *object)
document->priv->page_sizes = NULL;
}
- if (document->priv->page_labels) {
- gint i;
-
- for (i = 0; i < document->priv->n_pages; i++) {
- g_free (document->priv->page_labels[i]);
- }
- g_free (document->priv->page_labels);
- document->priv->page_labels = NULL;
- }
+ g_clear_pointer (&document->priv->page_labels, g_strfreev);
if (document->priv->info) {
ev_document_info_free (document->priv->info);
@@ -201,6 +193,7 @@ static void
ev_document_setup_cache (EvDocument *document)
{
EvDocumentPrivate *priv = document->priv;
+ gboolean custom_page_labels = FALSE;
gint i;
/* Cache some info about the document to avoid
@@ -260,7 +253,15 @@ ev_document_setup_cache (EvDocument *document)
page_label = _ev_document_get_page_label (document, page);
if (page_label) {
if (!priv->page_labels)
- priv->page_labels = g_new0 (gchar *, priv->n_pages);
+ priv->page_labels = g_new0 (gchar *, priv->n_pages + 1);
+
+ if (!custom_page_labels) {
+ gchar *real_page_label;
+
+ real_page_label = g_strdup_printf ("%d", i + 1);
+ custom_page_labels = g_strcmp0 (real_page_label, page_label) != 0;
+ g_free (real_page_label);
+ }
priv->page_labels[i] = page_label;
priv->max_label = MAX (priv->max_label,
@@ -269,6 +270,9 @@ ev_document_setup_cache (EvDocument *document)
g_object_unref (page);
}
+
+ if (!custom_page_labels)
+ g_clear_pointer (&priv->page_labels, g_strfreev);
}
static void
diff --git a/libmisc/ev-page-action-widget.c b/libmisc/ev-page-action-widget.c
index 31950aa..2c14c7e 100644
--- a/libmisc/ev-page-action-widget.c
+++ b/libmisc/ev-page-action-widget.c
@@ -119,7 +119,7 @@ ev_page_action_widget_update_max_width (EvPageActionWidget *action_widget)
max_page_label = ev_document_get_page_label (action_widget->document, n_pages - 1);
max_page_numeric_label = g_strdup_printf ("%d", n_pages);
- if (strcmp (max_page_label, max_page_numeric_label) != 0) {
+ if (ev_document_has_text_page_labels (action_widget->document) != 0) {
max_label = g_strdup_printf (_("(%d of %d)"), n_pages, n_pages);
/* Do not take into account the parentheses for the size computation */
max_label_len = g_utf8_strlen (max_label, -1) - 2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]