[evince/BUG_tooltip_annots_aacid] pdf: support 'de facto' tooltip feature
- From: Nelson Benítez León <nbenitez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/BUG_tooltip_annots_aacid] pdf: support 'de facto' tooltip feature
- Date: Fri, 27 Mar 2020 23:23:32 +0000 (UTC)
commit 7f189425527cce8fc545a198aaa19821328a22e8
Author: Nelson Benítez León <nbenitezl gmail com>
Date: Sat Mar 14 17:57:41 2020 -0400
pdf: support 'de facto' tooltip feature
Most pdf readers implement a tooltip feature by
showing the string content of 'TU' field of a
widget annotation that is not linked to any
form field.
Normally, widget annotations carry a reference to a
form field which are used together to implement the
different form widgets. But, the PDF spec does not
forbid standalone (i.e. not linked to any form field)
widget annotations, and the fact is they're been used
by most pdf readers to show a tooltip when the area
of that AnnotWidget is hovered.
According to issue reported files, 'pdfTeX' seems to
be one of the pdf producers incorporating this tooltip
feature.
The support for this feature has been recently been
added to poppler-glib with following api:
gchar*
poppler_form_field_get_alternate_ui_name (PopplerFormField *field)
so this commit uses that api to show tooltips on pdf's
that carry them. For that we add a new 'tooltip' field
to EvFormField and show it when hovering the field's
area and when tooltip is not empty.
Evince issue #842
Poppler issue:
https://gitlab.freedesktop.org/poppler/poppler/issues/34
backend/pdf/ev-poppler.cc | 5 +++++
libdocument/ev-form-field.c | 2 ++
libdocument/ev-form-field.h | 1 +
libview/ev-view.c | 34 +++++++++++++++++++++++++++++++++-
4 files changed, 41 insertions(+), 1 deletion(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index a6383a15..6bc7eecb 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -2665,11 +2665,15 @@ ev_form_field_from_poppler_field (PdfDocument *pdf_document,
gdouble font_size;
gboolean is_read_only;
PopplerAction *action;
+ gchar *alt_name = NULL;
id = poppler_form_field_get_id (poppler_field);
font_size = poppler_form_field_get_font_size (poppler_field);
is_read_only = poppler_form_field_is_read_only (poppler_field);
action = poppler_form_field_get_action (poppler_field);
+#if POPPLER_CHECK_VERSION(0, 87, 0)
+ alt_name = poppler_form_field_get_alternate_ui_name (poppler_field);
+#endif
switch (poppler_form_field_get_field_type (poppler_field)) {
case POPPLER_FORM_FIELD_TEXT: {
@@ -2759,6 +2763,7 @@ ev_form_field_from_poppler_field (PdfDocument *pdf_document,
ev_field->font_size = font_size;
ev_field->is_read_only = is_read_only;
+ ev_field->tooltip = alt_name;
if (action)
ev_field->activation_link = ev_link_from_action (pdf_document, action);
diff --git a/libdocument/ev-form-field.c b/libdocument/ev-form-field.c
index c234e967..e162a37d 100644
--- a/libdocument/ev-form-field.c
+++ b/libdocument/ev-form-field.c
@@ -45,6 +45,7 @@ ev_form_field_init (EvFormField *field)
field->page = NULL;
field->changed = FALSE;
field->is_read_only = FALSE;
+ field->tooltip = NULL;
}
static void
@@ -56,6 +57,7 @@ ev_form_field_finalize (GObject *object)
field->page = NULL;
g_clear_object (&field->activation_link);
+ g_clear_pointer (&field->tooltip, g_free);
(* G_OBJECT_CLASS (ev_form_field_parent_class)->finalize) (object);
}
diff --git a/libdocument/ev-form-field.h b/libdocument/ev-form-field.h
index d0571a2a..f01799aa 100644
--- a/libdocument/ev-form-field.h
+++ b/libdocument/ev-form-field.h
@@ -113,6 +113,7 @@ struct _EvFormField
EvPage *page;
gboolean changed;
+ gchar *tooltip;
};
struct _EvFormFieldClass
diff --git a/libview/ev-view.c b/libview/ev-view.c
index ffbe1704..6f09194e 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -2205,7 +2205,7 @@ ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y)
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}
- if (link || annot)
+ if (link || annot || field)
g_object_set (view, "has-tooltip", TRUE, NULL);
}
@@ -4911,6 +4911,26 @@ get_annot_area (EvView *view,
annot, area);
}
+static void
+get_field_area (EvView *view,
+ gint x,
+ gint y,
+ EvFormField *field,
+ GdkRectangle *area)
+{
+ EvMappingList *field_mapping;
+ gint page;
+ gint x_offset = 0, y_offset = 0;
+
+ x += view->scroll_x;
+ y += view->scroll_y;
+
+ find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+
+ field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache, page);
+ ev_view_get_area_from_mapping (view, page, field_mapping, field, area);
+}
+
static gboolean
ev_view_query_tooltip (GtkWidget *widget,
gint x,
@@ -4919,6 +4939,7 @@ ev_view_query_tooltip (GtkWidget *widget,
GtkTooltip *tooltip)
{
EvView *view = EV_VIEW (widget);
+ EvFormField *field;
EvLink *link;
EvAnnotation *annot;
gchar *text;
@@ -4939,6 +4960,17 @@ ev_view_query_tooltip (GtkWidget *widget,
}
}
+ field = ev_view_get_form_field_at_location (view, x, y);
+ if (field && field->tooltip && *(field->tooltip) != '\0') {
+ GdkRectangle field_area;
+
+ get_field_area (view, x, y, field, &field_area);
+ gtk_tooltip_set_text (tooltip, field->tooltip);
+ gtk_tooltip_set_tip_area (tooltip, &field_area);
+
+ return TRUE;
+ }
+
link = ev_view_get_link_at_location (view, x, y);
if (!link)
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]