[evince] libdocument: Fixing display of overlapping annotations



commit 3a9dd8173b457ca8811ced4e2ba1549c6489497c
Author: Fabian Franzen <flammi88 googlemail com>
Date:   Thu Aug 31 12:36:39 2017 +0200

    libdocument: Fixing display of overlapping annotations
    
    If two PDF annotations overlap, one might "shadow" the other,
    making it imposible for the user to click on of them if the
    smaller one is below the larger one.
    
    This fix calculates the area of bounding box and always puts
    the smaller sized annotations on top of the larger ones.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787070

 libdocument/ev-mapping-list.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/libdocument/ev-mapping-list.c b/libdocument/ev-mapping-list.c
index f1cb198..6ca1b34 100644
--- a/libdocument/ev-mapping-list.c
+++ b/libdocument/ev-mapping-list.c
@@ -99,6 +99,13 @@ ev_mapping_list_nth (EvMappingList *mapping_list,
         return (EvMapping *)g_list_nth_data (mapping_list->list, n);
 }
 
+static gdouble
+get_mapping_area_size (EvMapping *mapping)
+{
+       return (mapping->area.x2 - mapping->area.x1) *
+              (mapping->area.y2 - mapping->area.y1);
+}
+
 /**
  * ev_mapping_list_get:
  * @mapping_list: an #EvMappingList
@@ -115,9 +122,10 @@ ev_mapping_list_get (EvMappingList *mapping_list,
                     gdouble        y)
 {
        GList *list;
+       EvMapping *found = NULL;
 
-        g_return_val_if_fail (mapping_list != NULL, NULL);
-
+       g_return_val_if_fail (mapping_list != NULL, NULL);
+       
        for (list = mapping_list->list; list; list = list->next) {
                EvMapping *mapping = list->data;
 
@@ -125,11 +133,18 @@ ev_mapping_list_get (EvMappingList *mapping_list,
                    (y >= mapping->area.y1) &&
                    (x <= mapping->area.x2) &&
                    (y <= mapping->area.y2)) {
-                       return mapping;
+
+                       /* In case of only one match choose that. Otherwise
+                        * compare the area of the bounding boxes and return the
+                        * smallest element.
+                        * In this way we allow most of the elements to be selectable
+                        * by the user */
+                       if(!found || (get_mapping_area_size(mapping) < get_mapping_area_size(found)))
+                               found = mapping;
                }
        }
 
-       return NULL;
+       return found;
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]