]> www.fi.muni.cz Git - evince.git/commitdiff
dvi: Fix drawing glyphs with transparency
authorCarlos Rendon <crendon@gmail.com>
Mon, 8 Nov 2010 18:08:48 +0000 (19:08 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 8 Nov 2010 18:08:48 +0000 (19:08 +0100)
Fixes bug #494736.

backend/dvi/cairo-device.c
backend/dvi/mdvi-lib/dviread.c

index 51aea3790c5fe2d6501db737e759740d87242012..8d6553d6cd6ea89b98cd0f71a2e2ecf8855d27f4 100644 (file)
@@ -202,12 +202,9 @@ dvi_cairo_alloc_colors (void  *device_data,
                        int    density)
 {
        double  frac;
-       GdkColor color, color_fg, color_bg;
+       GdkColor color, color_fg;
        int     i, n;
-
-       color_bg.red = (bg >> 16) & 0xff;
-       color_bg.green = (bg >> 8) & 0xff;
-       color_bg.blue = (bg >> 0) & 0xff;
+       unsigned int alpha;
 
        color_fg.red = (fg >> 16) & 0xff;
        color_fg.green = (fg >> 8) & 0xff;
@@ -219,11 +216,12 @@ dvi_cairo_alloc_colors (void  *device_data,
                        pow ((double)i / n, 1 / gamma) :
                        1 - pow ((double)(n - i) / n, -gamma);
                
-               color.red = frac * ((double)color_fg.red - color_bg.red) + color_bg.red;
-               color.green = frac * ((double)color_fg.green - color_bg.green) + color_bg.green;
-               color.blue = frac * ((double)color_fg.blue - color_bg.blue) + color_bg.blue;
-               
-               pixels[i] = (color.red << 16) + (color.green << 8) + color.blue + 0xff000000;
+               color.red = frac * color_fg.red;
+               color.green = frac * color_fg.green;
+               color.blue = frac * color_fg.blue;
+               alpha = frac * 0xFF;
+
+               pixels[i] = (alpha << 24) + (color.red << 16) + (color.green << 8) + color.blue;
        }
 
        return npixels;
@@ -235,7 +233,7 @@ dvi_cairo_create_image (void *device_data,
                        Uint  height,
                        Uint  bpp)
 {
-       return cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
+       return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
 }
 
 static void
@@ -256,6 +254,8 @@ dvi_cairo_put_pixel (void *image, int x, int y, Ulong color)
        rowstride = cairo_image_surface_get_stride (surface);
        p = (guint32*) (cairo_image_surface_get_data (surface) + y * rowstride + x * 4);
 
+        /* per cairo docs, must flush before modifying outside of cairo */
+        cairo_surface_flush(surface);
        *p = color;
 }
 
@@ -343,7 +343,7 @@ mdvi_cairo_device_render (DviContext* dvi)
        memset (pixels, 0xff, page_height * rowstride);
 
        surface = cairo_image_surface_create_for_data (pixels,
-                                                      CAIRO_FORMAT_RGB24,
+                                                      CAIRO_FORMAT_ARGB32,
                                                       page_width, page_height,
                                                       rowstride);
        cairo_surface_set_user_data (surface, &key,
index 97b7b844103f961364ad32685e0a6a89091be020..cd8cfa916113e821e87c344de300ba998a8b95a5 100644 (file)
@@ -1166,43 +1166,13 @@ static void inline fix_after_horizontal(DviContext *dvi)
        (a), (b) > 0 ? '+' : '-', \
        (b) > 0 ? (b) : -(b), (c)
 
-/*
- * Draw rules with some sort of antialias support. Usefult for high-rate
- * scale factors.
- */ 
-
 static void draw_shrink_rule (DviContext *dvi, int x, int y, Uint w, Uint h, int f)
 {              
-       int hs, vs, npixels;
        Ulong fg, bg;
-       Ulong *pixels;
-       
-       hs = dvi->params.hshrink;
-       vs = dvi->params.vshrink;
+
        fg = dvi->curr_fg;
        bg = dvi->curr_bg;
 
-       if (MDVI_ENABLED(dvi, MDVI_PARAM_ANTIALIASED)) {
-               npixels = vs * hs + 1;
-               pixels = get_color_table(&dvi->device, npixels, bg, fg,
-                                        dvi->params.gamma, dvi->params.density);
-       
-               if (pixels) {
-                   int color;
-                   
-                   /*  Lines with width 1 should be perfectly visible
-                    *  in shrink about 15. That is the reason of constant
-                    */
-                    
-                   color = (pow (vs / h * hs, 2) + pow (hs / w * vs, 2)) / 225;
-                   if (color < npixels) {
-                       fg = pixels[color];
-                   } else {    
-                       fg = pixels[npixels - 1];
-                   }
-               }
-        }
-
        mdvi_push_color (dvi, fg, bg);
        dvi->device.draw_rule(dvi, x, y, w, h, f);
        mdvi_pop_color (dvi);