[Commit] Xft xftfreetype.c,1.34,1.35 xftrender.c,1.16,1.17

Keith Packard commit@keithp.com
Fri, 02 May 2003 14:42:58 -0700


Committed by: keithp

Update of /local/src/CVS/Xft
In directory home.keithp.com:/tmp/cvs-serv2596

Modified Files:
	xftfreetype.c xftrender.c 
Log Message:
Must switch to non-ARGB format when mixing ARGB and non-ARGB fonts


Index: xftfreetype.c
===================================================================
RCS file: /local/src/CVS/Xft/xftfreetype.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- xftfreetype.c	1 May 2003 00:13:17 -0000	1.34
+++ xftfreetype.c	2 May 2003 21:42:56 -0000	1.35
@@ -702,55 +702,16 @@
 	    case FC_RGBA_BGR:
 	    case FC_RGBA_VRGB:
 	    case FC_RGBA_VBGR:
-		pf.depth = 32;
-		pf.type = PictTypeDirect;
-		pf.direct.alpha = 24;
-		pf.direct.alphaMask = 0xff;
-		pf.direct.red = 16;
-		pf.direct.redMask = 0xff;
-		pf.direct.green = 8;
-		pf.direct.greenMask = 0xff;
-		pf.direct.blue = 0;
-		pf.direct.blueMask = 0xff;
-		format = XRenderFindFormat(dpy, 
-					   PictFormatType|
-					   PictFormatDepth|
-					   PictFormatAlpha|
-					   PictFormatAlphaMask|
-					   PictFormatRed|
-					   PictFormatRedMask|
-					   PictFormatGreen|
-					   PictFormatGreenMask|
-					   PictFormatBlue|
-					   PictFormatBlueMask,
-					   &pf, 0);
+		format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
 		break;
 	    default:
-		pf.depth = 8;
-		pf.type = PictTypeDirect;
-		pf.direct.alpha = 0;
-		pf.direct.alphaMask = 0xff;
-		format = XRenderFindFormat(dpy, 
-					   PictFormatType|
-					   PictFormatDepth|
-					   PictFormatAlpha|
-					   PictFormatAlphaMask,
-					   &pf, 0);
+		format = XRenderFindStandardFormat (dpy, PictStandardA8);
 		break;
 	    }
 	}
 	else
 	{
-	    pf.depth = 1;
-	    pf.type = PictTypeDirect;
-	    pf.direct.alpha = 0;
-	    pf.direct.alphaMask = 0x1;
-	    format = XRenderFindFormat(dpy, 
-				       PictFormatType|
-				       PictFormatDepth|
-				       PictFormatAlpha|
-				       PictFormatAlphaMask,
-				       &pf, 0);
+	    format = XRenderFindStandardFormat (dpy, PictStandardA1);
 	}
 	
 	if (!format)

Index: xftrender.c
===================================================================
RCS file: /local/src/CVS/Xft/xftrender.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- xftrender.c	17 Apr 2003 04:29:24 -0000	1.16
+++ xftrender.c	2 May 2003 21:42:56 -0000	1.17
@@ -386,6 +386,31 @@
 	free (glyphs);
 }
 
+/*
+ * Choose which format to draw text in when drawing with fonts
+ * of different formats.  The trick is that ARGB formats aren't
+ * compatible with A formats as PictOpAdd does the wrong thing, so
+ * fall back to an A format when presented with an ARGB and A format
+ */
+
+#define XftIsARGBFormat(a)  ((a)->depth == 32)
+
+static XRenderPictFormat *
+XftPreferFormat (Display *dpy, XRenderPictFormat *a, XRenderPictFormat *b)
+{
+    XRenderPictFormat	*prefer = 0;
+    
+    if (a == b)
+	prefer = a;
+    else if (XftIsARGBFormat(a) != XftIsARGBFormat(b))
+	prefer = XRenderFindStandardFormat (dpy, PictStandardA8);
+    else if (a->depth > b->depth)
+	prefer = a;
+    else
+	prefer = b;
+    return prefer;
+}
+
 void
 XftGlyphFontSpecRender (Display			    *dpy,
 			int			    op,
@@ -399,6 +424,7 @@
     int		    i, j;
     XftFont	    *prevPublic;
     XftFontInt	    *firstFont;
+    XRenderPictFormat	*format;
     FT_UInt	    missing[XFT_NMISSING];
     int		    nmissing;
     int		    n;
@@ -496,6 +522,7 @@
     if (i == nglyphs)
 	goto bail2;
     glyph = firstFont->glyphs[g];
+    format = firstFont->format;
     x = glyphs[i].x + glyph->metrics.xOff;
     y = glyphs[i].y + glyph->metrics.yOff;
     prevPublic = 0;
@@ -516,6 +543,8 @@
 	    if (pub != prevPublic || x != glyphs[i].x || y != glyphs[i].y)
 	    {
 		prevPublic = pub;
+		if (font->format != format)
+		    format = XftPreferFormat (dpy, font->format, format);
 		x = glyphs[i].x;
 		y = glyphs[i].y;
 		++nelt;
@@ -586,17 +615,17 @@
     }
     switch (width) {
     case 1:
-	XRenderCompositeText8 (dpy, op, src, dst, firstFont->format,
+	XRenderCompositeText8 (dpy, op, src, dst, format,
 			       srcx, srcy, glyphs[0].x, glyphs[0].y,
 			       elts, nelt);
 	break;
     case 2:
-	XRenderCompositeText16 (dpy, op, src, dst, firstFont->format,
+	XRenderCompositeText16 (dpy, op, src, dst, format,
 				srcx, srcy, glyphs[0].x, glyphs[0].y,
 				(XGlyphElt16 *) elts, nelt);
 	break;
     case 4:
-	XRenderCompositeText32 (dpy, op, src, dst, firstFont->format,
+	XRenderCompositeText32 (dpy, op, src, dst, format,
 				srcx, srcy, glyphs[0].x, glyphs[0].y,
 				(XGlyphElt32 *) elts, nelt);
 	break;