[pango] Win32: Enable colored underline drawing



commit f7927ff53afb8bbfdf7cc8f7b621c811f53ac6c5
Author: Nicolas Hake <nh nosebud de>
Date:   Mon Jul 11 13:20:41 2016 +0200

    Win32: Enable colored underline drawing
    
    Underline drawing was using the pen selected into DC before
    pango_win32_render_layout_line was called. Since layout allow the user to
    select underline colors, we have to create a temporary pen in the correct
    color before drawing it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768679

 pango/pangowin32.c |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index bdebc5f..d39cf8b 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -84,6 +84,8 @@ static double   pango_win32_font_real_get_metrics_factor (PangoFont *font);
 
 static void                  pango_win32_get_item_properties    (PangoItem        *item,
                                                                 PangoUnderline   *uline,
+                                                                PangoAttrColor   *uline_color,
+                                                                gboolean         *uline_set,
                                                                 PangoAttrColor   *fg_color,
                                                                 gboolean         *fg_set,
                                                                 PangoAttrColor   *bg_color,
@@ -1027,15 +1029,18 @@ pango_win32_render_layout_line (HDC              hdc,
     {
       COLORREF oldfg = 0;
       HBRUSH brush = NULL;
+      HPEN uline_pen, old_pen;
       POINT points[2];
       PangoUnderline uline = PANGO_UNDERLINE_NONE;
       PangoLayoutRun *run = tmp_list->data;
-      PangoAttrColor fg_color, bg_color;
-      gboolean fg_set, bg_set;
+      PangoAttrColor fg_color, bg_color, uline_color;
+      gboolean fg_set, bg_set, uline_set;
 
       tmp_list = tmp_list->next;
 
-      pango_win32_get_item_properties (run->item, &uline, &fg_color, &fg_set, &bg_color, &bg_set);
+      pango_win32_get_item_properties (run->item, &uline, &uline_color, &uline_set, &fg_color, &fg_set, 
&bg_color, &bg_set);
+      if (!uline_set)
+       uline_color = fg_color;
 
       if (uline == PANGO_UNDERLINE_NONE)
        pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
@@ -1074,6 +1079,15 @@ pango_win32_render_layout_line (HDC              hdc,
       if (fg_set)
        SetTextColor (hdc, oldfg);
 
+      if (uline != PANGO_UNDERLINE_NONE)
+       {
+         COLORREF uline_col = RGB ((uline_color.color.red) >> 8,
+                                   (uline_color.color.green) >> 8,
+                                   (uline_color.color.blue) >> 8);
+         uline_pen = CreatePen (PS_SOLID, 1, uline_col);
+         old_pen = SelectObject (hdc, uline_pen);
+       }
+
       switch (uline)
        {
        case PANGO_UNDERLINE_NONE:
@@ -1123,6 +1137,11 @@ pango_win32_render_layout_line (HDC              hdc,
          break;
        }
 
+      if (uline != PANGO_UNDERLINE_NONE)
+       {
+         SelectObject (hdc, old_pen);
+         DeleteObject (uline_pen);
+       }
 
       x_off += logical_rect.width;
     }
@@ -1177,6 +1196,8 @@ pango_win32_render_layout (HDC          hdc,
 static void
 pango_win32_get_item_properties (PangoItem      *item,
                                 PangoUnderline *uline,
+                                PangoAttrColor *uline_color,
+                                gboolean       *uline_set,
                                 PangoAttrColor *fg_color,
                                 gboolean       *fg_set,
                                 PangoAttrColor *bg_color,
@@ -1201,6 +1222,14 @@ pango_win32_get_item_properties (PangoItem      *item,
            *uline = ((PangoAttrInt *)attr)->value;
          break;
 
+       case PANGO_ATTR_UNDERLINE_COLOR:
+         if (uline_color)
+           *uline_color = *((PangoAttrColor *)attr);
+         if (uline_set)
+           *uline_set = TRUE;
+
+         break;
+
        case PANGO_ATTR_FOREGROUND:
          if (fg_color)
            *fg_color = *((PangoAttrColor *)attr);


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