[evince/BUG_color_crash] use default color when annotation has no color




commit c76be8ba6fa3515423bf68324b87dbde397a616f
Author: Nelson Benítez León <nbenitezl gmail com>
Date:   Sun Jun 5 11:52:56 2022 -0400

    use default color when annotation has no color
    
    Annotations may come with a NULL color, use
    a default color there instead of letting
    undefined GdkRGBA to crash the application.
    
    We take the chance to share this default color
    to be the same we already use when creating
    an annotation from Evince.
    
    We also take the chance to replace deprecated
    function ev_annotation_set_color() with
    ev_annotation_set_rgba()
    
    Fixes crash in #1800

 backend/pdf/ev-poppler.c    | 4 +++-
 libdocument/ev-annotation.h | 2 ++
 libview/ev-view.c           | 4 ++--
 3 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.c b/backend/pdf/ev-poppler.c
index 4d77658a2..b87673412 100644
--- a/backend/pdf/ev-poppler.c
+++ b/backend/pdf/ev-poppler.c
@@ -2701,7 +2701,9 @@ poppler_annot_color_to_gdk_rgba (PopplerAnnot *poppler_annot,
                color->alpha = 1.0;
 
                g_free (poppler_color);
-       } /* TODO: else use a default color */
+       } else { /* default color */
+               *color = EV_ANNOTATION_DEFAULT_COLOR;
+       }
 }
 
 static EvAnnotationTextIcon
diff --git a/libdocument/ev-annotation.h b/libdocument/ev-annotation.h
index ab5c96245..8b82beb86 100644
--- a/libdocument/ev-annotation.h
+++ b/libdocument/ev-annotation.h
@@ -115,6 +115,8 @@ typedef enum {
         EV_ANNOTATION_TEXT_MARKUP_SQUIGGLY
 } EvAnnotationTextMarkupType;
 
+#define EV_ANNOTATION_DEFAULT_COLOR ((const GdkRGBA) { 1., 1., 0, 1.});
+
 /* EvAnnotation */
 EV_PUBLIC
 GType                ev_annotation_get_type                  (void) G_GNUC_CONST;
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 7c6605a75..1ffbf16b5 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -3717,7 +3717,7 @@ ev_view_create_annotation_real (EvView *view,
        EvAnnotation   *annot;
        EvRectangle     doc_rect, popup_rect;
        EvPage         *page;
-       GdkColor        color = { 0, 65535, 65535, 0 };
+       GdkRGBA         color = EV_ANNOTATION_DEFAULT_COLOR;
        GdkRectangle    view_rect;
        cairo_region_t *region;
 
@@ -3749,7 +3749,7 @@ ev_view_create_annotation_real (EvView *view,
        g_object_unref (page);
 
        ev_annotation_set_area (annot, &doc_rect);
-       ev_annotation_set_color (annot, &color);
+       ev_annotation_set_rgba (annot, &color);
 
        if (EV_IS_ANNOTATION_MARKUP (annot)) {
                popup_rect.x1 = doc_rect.x2;


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