[evince] dvi: Fix drawing glyphs with transparency



commit 0891eb8e130103c2abe4b48b7f2b5fa42d0fdaa0
Author: Carlos Rendon <crendon gmail com>
Date:   Mon Nov 8 19:08:48 2010 +0100

    dvi: Fix drawing glyphs with transparency
    
    Fixes bug #494736.

 backend/dvi/cairo-device.c     |   24 ++++++++++++------------
 backend/dvi/mdvi-lib/dviread.c |   32 +-------------------------------
 2 files changed, 13 insertions(+), 43 deletions(-)
---
diff --git a/backend/dvi/cairo-device.c b/backend/dvi/cairo-device.c
index 51aea37..8d6553d 100644
--- a/backend/dvi/cairo-device.c
+++ b/backend/dvi/cairo-device.c
@@ -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,
diff --git a/backend/dvi/mdvi-lib/dviread.c b/backend/dvi/mdvi-lib/dviread.c
index 97b7b84..cd8cfa9 100644
--- a/backend/dvi/mdvi-lib/dviread.c
+++ b/backend/dvi/mdvi-lib/dviread.c
@@ -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);



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