[stsf-commit] xftbridge xftdraw.c, 1.1, 1.2 xftfreetype.c, 1.1, 1.2 xftglyphs.c, 1.1, 1.2 Xft.h, 1.1, 1.2 xftint.h, 1.1, 1.2

Jay Hobson stsf-commit at pdx.freedesktop.org
Thu Jul 29 10:54:39 PDT 2004


Committed by: jhobson


Index: xftdraw.c
===================================================================
RCS file: /cvs/stsf/xftbridge/xftdraw.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- xftdraw.c	5 Apr 2004 21:49:28 -0000	1.1
+++ xftdraw.c	29 Jul 2004 17:54:35 -0000	1.2
@@ -22,55 +22,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/*
- * Copyright © 2004 Sun Microsystems, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of Sun Microsystems, Inc. nor the names of 
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind.
- *
- * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
- * SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR
- * LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE,
- * MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES.
- * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
- * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
- * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
- * THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE
- * SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or intended
- * for use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- */
-
-/* $Id$ */
-
-
-/**
- * @file xftdraw.c
- * @brief Xft/STSF Bridge Library
- * @author Jay Hobson <jay.hobson at sun.com>
- * @version 0.8
- */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -543,9 +494,14 @@
     XSTStyle       xst_style;
     XSTFont        xst_font;
     double         xst_font_size;
+    uint32_t       xst_embolden;
+    uint32_t       xst_italicize;
+    uint32_t       xst_hinting;
+    uint32_t	   xst_embedding;
     XSTGlyphVector xst_vector;
     int            xst_vector_len;
     GC             xst_gc;
+    int            output_mode;
     unsigned int   xst_gc_color;
     XSTTypeEnv     local_xst_env;
     int            local_connect;
@@ -554,6 +510,7 @@
 
 struct XSTfonts {
     char            *fontURL;
+    FT_Face	     face;
     XSTFont          xst_font;
     int              xst_font_downloaded;
     struct XSTfonts *next;
@@ -739,6 +696,7 @@
 _XftCreateXSTObj ( Display *dpy, int all )
 {
     struct XSTdpy *tmp;
+    static int first_time = 1;
 
     /*
      * Did not find the dpy in the list, so create a new structure for it
@@ -749,6 +707,12 @@
     if ( tmp == NULL )
         return NULL;
 
+    if ( first_time )
+    {
+	first_time = 0;
+        XSTSetSysCtlFlag ( dpy, XST_SYS_CTL_EMBOLDEN_BITMAPS, 1 );
+    }
+
     /*
      * Fill in the structure by creating the XST objects. Only create the
      * XSTTypeEnv object. The rest will be filled in later when more info
@@ -762,9 +726,13 @@
         tmp->xst_style      = 0;
         tmp->xst_font       = 0;
         tmp->xst_font_size  = 0;
+        tmp->xst_embolden   = 0;
+        tmp->xst_italicize  = 0;
+        tmp->xst_hinting    = 0;
         tmp->xst_vector     = 0;
         tmp->xst_vector_len = 0;
         tmp->xst_gc         = 0;
+        tmp->output_mode    = 0;
         tmp->xst_gc_color   = 0;
         tmp->local_xst_env  = 0;
         tmp->local_connect  = 0;
@@ -773,148 +741,241 @@
 
     head                = tmp;
 
-    /*
-     * If we are displaying to a non local host, then connect to a local
-     * copy of the ST server. (If possible)
-     */
-    if ( !LocalConnection ( dpy ))
-    {
-        tmp->local_connect = 1;
-        tmp->local_xst_env = XSTTypeEnvNew ( NULL );
-    }
-
     return tmp;
 }
 
 XSTFont 
-_XftLoadXSTFont ( struct XSTdpy *xst_dpy, char *fileURL )
+_XftLoadXSTFont ( struct XSTdpy *xst_dpy, char *fileURL, FT_Face face )
 {
     struct XSTfonts *tmp = XSTFontList;
-    int              len = strlen ( fileURL );
+    int              len = 0;
     byte            *signature;
     XSTFont         *st_font_id;
     int              count;
-    
-    /*
-     * Check to see if we already know this font on the display system.
-     */
-    while ( tmp != NULL )
-    {
-        if ( !strcmp ( tmp->fontURL, fileURL ))
-	{
-	    return tmp->xst_font;
-	}
-	else
-	    tmp = tmp->next;
-    }
+    unsigned char   *font_data = NULL;
+    int              store_size;
+    int              store_pos;
+    unsigned char   *store_data;
+    int              amount_to_checksum = AMOUNT_TO_CHECKSUM;
 
-    /*
-     * Never opened before, so create a new entry
-     */
-    tmp = (struct XSTfonts *) malloc ( sizeof ( struct XSTfonts ));
+    if ( fileURL ) 
+    {   
 
-    if ( tmp == NULL )
-        return 0;
+        /*
+         * Check to see if we already know this font on the display system.
+         */
+        while ( tmp != NULL )
+        {
+            if ( tmp->fontURL && !strcmp ( tmp->fontURL, fileURL ))
+	    {
+	        return tmp->xst_font;
+	    }
+	    else
+	        tmp = tmp->next;
+        }
 
-    tmp->fontURL = (char *) malloc ( len + 1 );
+        len = strlen ( fileURL );
 
-    if ( tmp->fontURL == NULL )
+        /*
+         * Never opened before, so create a new entry
+         */
+        tmp = (struct XSTfonts *) malloc ( sizeof ( struct XSTfonts ));
+
+        if ( tmp == NULL )
+            return 0;
+
+        tmp->fontURL = (char *) malloc ( len + 1 );
+
+        if ( tmp->fontURL == NULL )
+        {
+	    free ( tmp );
+	    return 0;
+        }
+
+        /*
+         * Store the font URL so we can look it up in the future
+         */
+        strcpy ( tmp->fontURL, fileURL );
+        tmp->fontURL[len] = '\0';
+        tmp->face         = 0;
+    }
+    else if ( face )
     {
-	free ( tmp );
-	return 0;
+        /*
+         * Check to see if we already know this font on the display system.
+         */
+        while ( tmp != NULL )
+        {
+            if ( face == tmp->face )
+	    {
+	        return tmp->xst_font;
+	    }
+	    else
+	        tmp = tmp->next;
+        }
+
+        /*
+         * Never opened before, so create a new entry
+         */
+        tmp = (struct XSTfonts *) malloc ( sizeof ( struct XSTfonts ));
+
+        if ( tmp == NULL )
+            return 0;
+
+        tmp->fontURL = 0;
+        tmp->face    = 0;
     }
+    else
+	return 0;
 
-    /*
-     * Store the font URL so we can look it up in the future
-     */
-    strcpy ( tmp->fontURL, fileURL );
-    tmp->fontURL[len]        = '\0';
     tmp->xst_font            = 0;
     tmp->xst_font_downloaded = 0;
     tmp->next                = XSTFontList;
    
     XSTFontList              = tmp;
 
-    if ( xst_dpy->local_xst_env )
+    /*
+     * Get the length of the file here
+     */
+    if ( amount_to_checksum == 0 )
     {
-        /*
-         * We need to get the local font id so that we can get the 
-         * signature.
-         */ 
-        st_font_id = XSTTypeEnvFindFontsByURL ( NULL, 
-						xst_dpy->local_xst_env, 
-					        fileURL, &count );
+	struct stat buf;
+
+	if ( fileURL )
+	{
+	    stat ( fileURL, &buf );
+	    amount_to_checksum = buf.st_size;
+	}
+	else if ( face->stream )
+	    amount_to_checksum = face->stream->size;
+    }
 
+    if ( fileURL )
+    {
         /*
-         * We could not open the local font, so we have a problem.
+         * If we have the URL, then load the first part of the font to
+         * get the signature.
          */
-        if ( count == 0 )
-        {
+	font_data = (unsigned char *)malloc ( amount_to_checksum );
+
+	if ( font_data )
+	{
+	    int fd;
+
+	    if ((fd = open ( fileURL, O_RDONLY )) != NULL )
+	    {
+		read ( fd, (void *)font_data, amount_to_checksum );
+		close ( fd );
+	    }
+	}
+ 	else
 	    return 0;
-        }
-    
+    }
+    else if ( face )
+    {
         /*
-         * Get the signature of the local font so we can find it on the 
-         * display system
-         */
-        signature = XSTFontGetSignature ( NULL, xst_dpy->local_xst_env, 
-				          st_font_id[0] );
+         * Load the font into font_data to get the signature.
+         */ 
+        if ( face->stream )
+        {
+	    if ( face->stream->read )
+	    {
+                store_pos  = face->stream->pos;
+                store_data = face->stream->base;
+		store_size = face->stream->size;
+		font_data  = (unsigned char *)malloc ( face->stream->size );
 
-	if ( st_font_id )
-            free ( st_font_id );
+		if ( font_data )
+		{
+		    (face->stream->read) ( face->stream, 0, font_data, store_size );
+		}
+		else
+		    return 0;
+            }
+	    else
+		return 0;
+	}
+	else
+	    return 0;
+    }
+	
+    /*
+     * Get the signature of the font to use
+     */	
+    signature = XSTGetSignature ( font_data, amount_to_checksum );
 
-        /*
-         * Search the display system for the font with the matching 
-         * signature
-         */
-        tmp->xst_font = XSTTypeEnvFindFontBySignature ( xst_dpy->dpy, 
-						        xst_dpy->xst_env, 
-						        signature );
+    /*
+     * Search the display system for the font with the matching 
+     * signature
+     */
+    tmp->xst_font = XSTTypeEnvFindFontBySignature ( xst_dpy->dpy, xst_dpy->xst_env, 
+						    signature );
 
-        /*
-         * If the display system does not have the matching font, then we 
-         * need to send a copy of the font to that system
-         */
-        if ( tmp->xst_font == 0 )
-        {
-	    int file = open ( fileURL, O_RDONLY );
+    if ( signature )
+	free ( signature );
 
-	    if ( file == -1 )
-	    {
-	        tmp->xst_font = 0;
-	        return 0;
-	    }
+    /*
+     * If STSF cannot find the font by Signature, then download the font
+     * to it.
+     */
+    if ( !tmp->xst_font )
+    {
+	XSTFont *fonts;
+	int      count;
 
-            st_font_id = XSTTypeEnvCreateFontsFromStream ( xst_dpy->dpy, 
-						           xst_dpy->xst_env,
-						           file,
-						           &count );
-	    close ( file );	
+	if ( fileURL )
+	{
+	    /*
+	     * Since we may have only downloaded the start of the font,
+	     * we need to load the rest.
+	     */
+	    int         fd;
+	    struct stat buf;
 
-	    tmp->xst_font            = st_font_id[0];			    
-	    tmp->xst_font_downloaded = 1;
+	    stat ( fileURL, &buf );
+	    store_size = buf.st_size;
 
-	    if ( st_font_id )
-                free ( st_font_id );
-        }
+	    /*
+	     * Free up the old font header, and allocate enough space
+	     * for the entire font.
+	     */
+	    free ( font_data );
+	    font_data = (unsigned char *)malloc ( store_size );
 
-        free ( signature );
+	    if ( font_data )
+	    {
+	        if ((fd = open ( fileURL, O_RDONLY )) != NULL )
+	        {
+	            read ( fd, (void *)font_data, store_size );
+	            close ( fd );
+	        }
+	    }
+	    else
+	        return 0;
+	}
+	
+	fonts = XSTTypeEnvCreateFonts ( xst_dpy->dpy, xst_dpy->xst_env, 1, 
+					&font_data, &store_size, &count );
+
+	if ( count != 0 )
+	{
+	    tmp->xst_font = fonts[0];
+	    free ( fonts );
+	}
     }
-    else
-    {
-        /*
-         * Use the XSTTypeEnv object to get the XSTFont associated with 
-         * the URL.
-         */
-        st_font_id = XSTTypeEnvFindFontsByURL ( xst_dpy->dpy, 
-					        xst_dpy->xst_env, fileURL, 
-						&count );
 
-        if ( count == 1 )
-            tmp->xst_font = st_font_id[0];
+    if ( font_data )
+	free ( font_data );
 
-        if ( st_font_id )
-            free ( st_font_id );
+    if ( face )
+    {
+	/*
+	 * Restore the stream data back to how it was
+	 */
+	face->stream->base = store_data;
+	face->stream->size = store_size;
+	face->stream->pos  = store_pos;
+	(face->stream->read) ( face->stream, store_pos, store_data, 0 );
     }
 
     return tmp->xst_font;
@@ -964,7 +1025,8 @@
 
 XSTFont
 _XftGetXSTFont (Display *dpy,
-                char    *file)
+                char    *file,
+		FT_Face  face)
 {
     struct XSTdpy *tmp     = head;
     int            num;
@@ -998,7 +1060,7 @@
 	    return 0;
     }
 
-    xst_font = _XftLoadXSTFont ( tmp, file );
+    xst_font = _XftLoadXSTFont ( tmp, file, face );
 
     if ( xst_font == 0 )
 	xst_font = 1;
@@ -1019,6 +1081,7 @@
     XSTStyledGlyph *xst_glyphs = NULL;
 #endif
     int             clip       = 0;
+    REGION	    nr;
     REGION         *r;
     int             i;
     GC              gc;
@@ -1041,6 +1104,17 @@
         clip = 1;
         r = (REGION *)draw->clip.region;
     }
+    else if ( draw->clip_type == XftClipTypeRectangles )
+    {
+	clip = 1;
+	nr.numRects   = 0;
+	nr.rects      = 0;
+	nr.extents.x1 = ((REGION *)draw->clip.region)->extents.x1;
+	nr.extents.x2 = ((REGION *)draw->clip.region)->extents.y1;
+	nr.extents.y1 = ((REGION *)draw->clip.region)->extents.x2;
+	nr.extents.y2 = ((REGION *)draw->clip.region)->extents.y2;
+        r = &nr;
+    }
 
     if ( xst_glyphs == NULL || len > mxst_glyphs )
     {
@@ -1057,8 +1131,15 @@
     fp = fopen("/tmp/Xoutput", "a");
     if ( fp) fprintf(fp, "Glyphs: %d: %f ", len, font->info.xst_size);
     for ( i = 0; i < len; i++ )
-        if (fp) fprintf(fp, "%c", glyphs[i].glyph + 29);
+	if ( glyphs[i].glyph > 16000 )
+	{
+            if (fp) fprintf(fp, "%c", glyphs[i].glyph - 16805 + 32);
+	}
+	else
+            if (fp) fprintf(fp, "%c", glyphs[i].glyph + 29);
     fprintf(fp, "\n");
+    if ( draw->clip_type == XftClipTypeRectangles )
+	if (fp) fprintf(fp, "CLIP RECT!!!\n");
 #endif
     glyphs_loaded = FcFalse;
     max = 0;
@@ -1080,6 +1161,8 @@
     {
         int          xloc = glyphs[i].x;
         int          yloc = glyphs[i].y;
+	int          xo;
+        int          yo;
         int          wi;
         int          hi;
         unsigned int g;
@@ -1105,21 +1188,54 @@
         }
         else
 	{
+            xo = font->glyphs[g]->metrics.xOff;
+            yo = font->glyphs[g]->metrics.yOff;
             wi = font->glyphs[g]->metrics.width;
             hi = font->glyphs[g]->metrics.height;
 	}
 
         if ( clip )
         {
-            int ayloc = yloc - font->glyphs[g]->metrics.y + hi;
+            int ayloc;
 
-            if ( r->numRects == 1 && r->rects[0].x1 == 0 && r->rects[0].y1 == 0 /*&&
-                 r->rects[0].x2 - r->rects[0].x1 < wi */ )
+	    if ( xloc == 0 && yloc == 0 )
+	    {
+	        xloc = xpos;
+	        yloc = ypos;
+	    }
+
+	    ayloc = yloc - font->glyphs[g]->metrics.y + hi;
+
+	    if ( r->numRects == 0 )
+	    {
+                if ( draw->clip_type == XftClipTypeRectangles )
+		{
+#ifdef DEBUG_FILE
+                if ( g > 16000 )
+		{
+                if (fp) fprintf(fp, "RCLIP: 1: (%d %d) (%d %d): CH: %c (%d) (%d %d) (%d %d) ", r->extents.x1, r->extents.y1, r->extents.x2, r->extents.y2, g - 16805 + 32, g, xloc, yloc, xloc+wi, hi);
+		}
+		else
+                if (fp) fprintf(fp, "RCLIP: 1: (%d %d) (%d %d): CH: %c (%d) (%d %d) (%d %d) ", r->extents.x1, r->extents.y1, r->extents.x2, r->extents.y2, g + 29, g, xloc, yloc, xloc+wi, hi);
+#endif
+		    if ( xloc + wi >= r->extents.x1 && xloc <= r->extents.x1 + r->extents.x2 )
+		    {
+			in = 1;
+#ifdef DEBUG_FILE
+                    if (fp) fprintf(fp, "IN");
+#endif
+		    }
+#ifdef DEBUG_FILE
+                if ( fp) fprintf(fp, "\n");
+#endif
+		}
+	    }
+
+            else if ( r->numRects == 1 && r->rects[0].x1 == 0 && r->rects[0].y1 == 0 /*&&
+                      r->rects[0].x2 - r->rects[0].x1 < wi */ )
             {
 #ifdef DEBUG_FILE
-                if (fp) fprintf(fp, "CLIP: 1: (%d %d) (%d %d): CH: %c (%d %d) (%d %d) ", r-
->rects[0].x1, r->rects[0].y1, r->rects[0].x2, r->rects[0].y2, g + 29, xloc, yloc, xloc+wi,
-hi);
+                if (fp) fprintf(fp, "REG CLIP: 1: (%d %d) (%d %d): CH: %c (%d) (%d %d) (%d %d) ", r->rects[0].x1, r->rects[0].y1, r->rects[0].x2, r->rects[0].y2, g + 29, g, xloc, yloc, xloc+wi, hi);
 #endif
                 if ( xloc + wi >= r->rects[0].x1 && xloc       <= r->rects[0].x2 /*&&
                      ayloc     >= r->rects[0].y1 && ayloc - hi <= r->rects[0].y2 */)
@@ -1138,14 +1254,17 @@
                 int j;
 
 #ifdef DEBUG_FILE
-                if (fp) fprintf(fp, "CLIP: %d: CH: %c (%d %d) (%d %d) ", r->numRects, g + 2
-9, xloc, yloc, xloc+wi, hi);
+                if ( g > 16000 )
+		{
+                if (fp) fprintf(fp, "BLOCK CLIP: %d: CH: %c (%d) (%d %d) (%d %d) ", r->numRects, g -16805 + 32, g, xloc, yloc, xloc+wi, hi);
+		}
+		else
+                if (fp) fprintf(fp, "BLOCK CLIP: %d: CH: %c (%d) (%d %d) (%d %d) ", r->numRects, g + 29, g, xloc, yloc, xloc+wi, hi);
 #endif
                 for ( j = 0; j < r->numRects; j++ )
                 {
 #ifdef DEBUG_FILE
-                    if (fp) fprintf(fp, "R (%d %d) (%d %d) ", r->rects[j].x1, r->rects[j].y
-1, r->rects[j].x2, r->rects[j].y2);
+                    if (fp) fprintf(fp, "R (%d %d) (%d %d) ", r->rects[j].x1, r->rects[j].y1, r->rects[j].x2, r->rects[j].y2);
 #endif
                     if ( xloc + wi >= r->rects[j].x1 && xloc <= r->rects[j].x2 /* &&
                          yloc >= r->rects[j].y1 && yloc      <= r->rects[j].y2 */ )
@@ -1163,7 +1282,8 @@
             }
             clip_set = 1;
             gc = _XftGetXSTGC ( draw->dpy, draw->drawable );
-            XSTGCSetRegion ( draw->dpy, gc, r );
+	    if ( i == 0 )
+                XSTGCSetRegion ( draw->dpy, gc, r );
         }
         else
         {
@@ -1183,14 +1303,15 @@
 	    {
                 xst_glyphs[(*nglyphs)].pos.x = xloc;
                 xst_glyphs[(*nglyphs)++].pos.y = yloc;
-	        xpos = xloc + wi;
-	        ypos = yloc;
+	        xpos = xloc + xo;
+	        ypos = yloc + yo;
 	    }
 	    else
 	    {
 		xst_glyphs[(*nglyphs)].pos.x = xpos;
 		xst_glyphs[(*nglyphs)++].pos.y = ypos;
-	        xpos += wi;
+	        xpos += xo;
+		ypos += yo;
 	    }
         }
     }
@@ -1215,6 +1336,7 @@
     int             i;
     XSTStyledGlyph *xst_glyphs;
     int             xst_vector_len = 0;
+    XSTAlphaStruct  alpha;
 #ifdef DEBUG_FILE
     FILE           *fp             = NULL;
 #endif
@@ -1244,8 +1366,7 @@
             {
                 int new_gv = 0;
 #ifdef DEBUG_FILE
-                if(fp) fprintf(fp, "Found dpy: FNT: %d (%d), SIZE: %f (%f)\n", tmp->xst_fon
-t, font->info.xst_font, tmp->xst_font_size, font->info.xst_size);
+                if(fp) fprintf(fp, "Found dpy: FNT: %d (%d), SIZE: %f (%f)\n", tmp->xst_font, font->info.xst_font, tmp->xst_font_size, font->info.xst_size);
 #endif
                 /*
                  * If the color changed, then change the stored GCs foreground
@@ -1272,6 +1393,31 @@
                     new_gv = 1;
                 }
 
+		if ( tmp->xst_embolden != font->info.xst_embolden )
+                {
+		    XSTStyleSetEffects ( draw->dpy, tmp->xst_style, ST_SM_EFFECTS,
+                                         font->info.xst_embolden | font->info.xst_italicize, 0, 0 );
+                    tmp->xst_embolden = font->info.xst_embolden;
+                    tmp->xst_italicize = font->info.xst_italicize;
+                    new_gv = 1;
+                }
+
+		if ( tmp->xst_italicize != font->info.xst_italicize )
+                {
+		    XSTStyleSetEffects ( draw->dpy, tmp->xst_style, ST_SM_EFFECTS,
+                                         font->info.xst_italicize | font->info.xst_embolden, 0, 0 );
+                    tmp->xst_italicize = font->info.xst_italicize;
+                    new_gv = 1;
+                }
+
+		if ( tmp->xst_hinting != font->info.xst_hinting )
+		{
+                    XSTStyleSetScaler ( draw->dpy, tmp->xst_style, 
+					ST_SM_HINTINGMODE, 0, font->info.xst_hinting, 0 );
+		    tmp->xst_hinting = font->info.xst_hinting;
+                    new_gv = 1;
+		}
+
                 /*
                  * Fill in the glyph vector with the stored XST style
                  */
@@ -1283,6 +1429,38 @@
                 if ( new_gv )
                 {
 #endif
+
+                if ( !draw->depth )
+                    XftDrawDepth (draw);
+
+                if ( font->info.antialias && draw->depth >= 16 )
+		{
+		    if ( tmp->output_mode != ST_OM_RASTER_GRAYSCALE )
+		    {
+                        XSTGCSetOutputFormat ( draw->dpy, tmp->xst_gc, 
+					       XST_RASTER_OUTPUT, ST_OM_RASTER_GRAYSCALE );
+                        XSTStyleSetScaler ( draw->dpy, tmp->xst_style, 
+					    ST_SM_SBITSMODE, 0, 0, ST_IGNORE_SBITS );
+	                tmp->xst_embedding = ST_IGNORE_SBITS;
+		    }
+		    tmp->output_mode = ST_OM_RASTER_GRAYSCALE;
+		}
+                else
+		{
+		    if ( tmp->output_mode != ST_OM_RASTER_MONO )
+		    {
+                        XSTGCSetOutputFormat ( draw->dpy, tmp->xst_gc, 
+					       XST_RASTER_OUTPUT, ST_OM_RASTER_MONO );
+			if ( tmp->xst_embedding != font->info.xst_embedding )
+			{
+                            XSTStyleSetScaler ( draw->dpy, tmp->xst_style, 
+					        ST_SM_SBITSMODE, 0, 0, font->info.xst_embedding );
+			    tmp->xst_embedding = font->info.xst_embedding;
+			}
+		    }
+		    tmp->output_mode = ST_OM_RASTER_MONO;
+		}
+
                 /*
                  * Replace the glyphs with the new glyphs
                  */
@@ -1345,6 +1523,12 @@
                       font->info.xst_font, font->info.xst_size, (XSTLocale)NULL,
                       (XSTBaselineFlag)NULL );
 
+    XSTStyleSetEffects ( draw->dpy, tmp->xst_style, ST_SM_EFFECTS,
+                         font->info.xst_embolden | font->info.xst_italicize, 0, 0 );
+
+    XSTStyleSetScaler ( draw->dpy, tmp->xst_style, ST_SM_HINTINGMODE, 
+			0, font->info.xst_hinting, 0 );
+
     /*
      * Fill in the style value for the glyph vector
      */
@@ -1354,12 +1538,15 @@
     }
 
 #ifdef DEBUG_FILE
-    if(fp) fprintf(fp, "NOT Found dpy: FNT: %d (%d), SIZE: %f (%f)\n", tmp->xst_font, font-
->info.xst_font, tmp->xst_font_size, font->info.xst_size);
+    if(fp) fprintf(fp, "NOT Found dpy: FNT: %d (%d), SIZE: %f (%f)\n", tmp->xst_font, font->info.xst_font, tmp->xst_font_size, font->info.xst_size);
     if(fp) fclose(fp);
 #endif
     tmp->xst_font       = font->info.xst_font;
     tmp->xst_font_size  = font->info.xst_size;
+    tmp->xst_embolden   = font->info.xst_embolden;
+    tmp->xst_italicize  = font->info.xst_italicize;
+    tmp->xst_hinting    = font->info.xst_hinting;
+
     if ( tmp->xst_gc == 0 )
         tmp->xst_gc     = XCreateGC ( draw->dpy, draw->drawable, vmask, &vals );
     else
@@ -1372,6 +1559,38 @@
             XChangeGC ( draw->dpy, tmp->xst_gc, vmask, &vals );
         }
     }
+
+    if ( !draw->depth )
+        XftDrawDepth (draw);
+
+    /*
+     * Set the appropriate XST values for the output, and associate the font and
+     * size with the style
+     */
+    if ( font->info.antialias && draw->depth >= 16 )
+    {
+        XSTGCSetOutputFormat ( draw->dpy, tmp->xst_gc, XST_RASTER_OUTPUT, 
+			       ST_OM_RASTER_GRAYSCALE );
+        XSTStyleSetScaler ( draw->dpy, tmp->xst_style, ST_SM_SBITSMODE, 0, 
+			    0, ST_IGNORE_SBITS );
+
+	tmp->xst_embedding = ST_IGNORE_SBITS;
+        tmp->output_mode = ST_OM_RASTER_GRAYSCALE;
+    }
+    else
+    {
+        XSTGCSetOutputFormat ( draw->dpy, tmp->xst_gc, XST_RASTER_OUTPUT, 
+			       ST_OM_RASTER_MONO );
+        XSTStyleSetScaler ( draw->dpy, tmp->xst_style, ST_SM_SBITSMODE, 0, 
+			    0, font->info.xst_embedding );
+	tmp->xst_embedding = font->info.xst_embedding;
+        tmp->output_mode = ST_OM_RASTER_MONO;
+    }
+    alpha.min = 0.0;
+    alpha.max = 1.0;
+    XSTGCSetAlphaRange ( draw->dpy, tmp->xst_gc, XST_TEXT_ALPHA, &alpha, NULL, 
+			 NULL, NULL, NULL );
+
     tmp->xst_gc_color   = color;
     tmp->xst_vector     = XSTGlyphVectorNew ( draw->dpy, tmp->xst_env, xst_glyphs,
                                               xst_vector_len );
@@ -1381,16 +1600,6 @@
 #ifdef NO_MALLOC
     free ( xst_glyphs );
 #endif
-
-    /*
-     * Set the appropriate XST values for the output, and associate the font and
-     * size with the style
-     */
-    if ( font->info.antialias )
-        XSTGCSetOutputFormat ( draw->dpy, tmp->xst_gc, XST_RASTER_OUTPUT, ST_OM_RASTER_GRAYSCALE );
-    else
-        XSTGCSetOutputFormat ( draw->dpy, tmp->xst_gc, XST_RASTER_OUTPUT, ST_OM_RASTER_MONO );
-
     /*
      * Draw the glyph vector
      */
@@ -1452,7 +1661,6 @@
     if (font->format)
     {
 	Picture	    src;
-	
 	if (_XftDrawRenderPrepare (draw) &&
 	    (src = XftDrawSrcPicture (draw, color)))
 	    XftGlyphRender (draw->dpy, _XftDrawOp (draw, color),

Index: xftfreetype.c
===================================================================
RCS file: /cvs/stsf/xftbridge/xftfreetype.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- xftfreetype.c	5 Apr 2004 21:49:28 -0000	1.1
+++ xftfreetype.c	29 Jul 2004 17:54:35 -0000	1.2
@@ -22,55 +22,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/*
- * Copyright © 2004 Sun Microsystems, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of Sun Microsystems, Inc. nor the names of 
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind.
- *
- * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
- * SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR
- * LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE,
- * MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES.
- * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
- * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
- * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
- * THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE
- * SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or intended
- * for use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- */
-
-/* $Id$ */
-
-
-/**
- * @file xftfreetype.c
- * @brief Xft/STSF Bridge Library
- * @author Jay Hobson <jay.hobson at sun.com>
- * @version 0.8
- */
-
 #define NEED_EVENTS
 #define NEED_REPLIES
 
@@ -381,6 +332,7 @@
     FcChar32	    hash, *hashp;
     FT_Face	    face;
     int		    nhash;
+    FcBool          embed; /* Use embededbitmap switch */
 #ifdef XST
     extern int      use_xst;
 #endif
@@ -427,6 +379,12 @@
     if (FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &dsize) != FcResultMatch)
 	goto bail1;
 
+    /*
+     * Add By Firefly (firefly at firefly.idv.tw)
+     */
+    if (dsize != (long)dsize) /* for speed - avoid math compute */
+        dsize = ((dsize - (long)dsize) >= 0.5) ? (long)dsize + 1: (long)dsize;
+
     if (FcPatternGetDouble (pattern, FC_ASPECT, 0, &aspect) != FcResultMatch)
 	aspect = 1.0;
     
@@ -442,14 +400,17 @@
 
     if ( use_xst )
     {
-	XSTFont _XftGetXSTFont (Display *, char *);
+	XSTFont _XftGetXSTFont (Display *, char *, FT_Face );
 
         /*
          * Get the XSTFont XID for the font with the specified file name
          */
-        fi->xst_font = _XftGetXSTFont ( dpy, (char *)filename );
+        fi->xst_font = _XftGetXSTFont ( dpy, (char *)filename, fi->file->face );
         fi->xst_size = ( dsize * 72.0 ) / (((double) DisplayHeight (dpy, 0) * 25.4) /
                                             (double) DisplayHeightMM (dpy, 0));
+	fi->xst_size = (int)(fi->xst_size + .5);
+	if ( fi->xst_size <= 1 )
+	    fi->xst_size = 1;
     }
 #endif
 
@@ -526,10 +487,43 @@
      */
     fi->load_flags = FT_LOAD_DEFAULT;
 
+#if 0
     /* disable bitmaps when anti-aliasing or transforming glyphs */
-    if (fi->antialias || fi->transform)
+#endif
+    /*------------------------------------------------------------------
+     * Add by Firefly ( firefly at firefly.idv.tw)
+     * enable bitmaps first if requested
+     */
+    switch ( FcPatternGetBool (pattern, "embed", 0, &embed)) {
+    case FcResultNoMatch:
+        embed = FcTrue;
+	break;
+    case FcResultMatch:
+        break;
+    default:
+	goto bail1;
+    }
+
+    /*
+     * disable bitmaps when anti-aliasing and not set embed or 
+     * transforming glyphs
+     */
+    if ((fi->antialias && !embed ) || fi->transform)
 	fi->load_flags |= FT_LOAD_NO_BITMAP;
     
+    /*
+     * Check for weight
+     */
+    switch (FcPatternGetInteger(pattern, FC_WEIGHT, 0, &fi->weight)) {
+    case FcResultNoMatch:
+        fi->weight = FC_WEIGHT_MEDIUM;
+        break;
+    case FcResultMatch:
+        break;
+    default:
+        goto bail1;
+    }
+
     /* disable hinting if requested */
     switch (FcPatternGetBool (pattern, FC_HINTING, 0, &hinting)) {
     case FcResultNoMatch:
@@ -572,6 +566,30 @@
     if (autohint)
 	fi->load_flags |= FT_LOAD_FORCE_AUTOHINT;
 
+#ifdef USE_XST
+    if ( use_xst )
+    {
+	if ( embed )
+	    fi->xst_embedding = ST_USE_SBITS;
+	else
+	    fi->xst_embedding = ST_IGNORE_SBITS;
+
+	if ( fi->transform )
+	    fi->xst_italicize = ST_SE_ITALICIZE;
+	else
+	    fi->xst_italicize = 0;
+
+	if ( hinting && autohint )
+	    fi->xst_hinting = ST_APPLY_HINTS | ST_AUTOHINT;
+	else if ( hinting )
+	    fi->xst_hinting = ST_APPLY_HINTS;
+	else if ( autohint )
+	    fi->xst_hinting = ST_AUTOHINT;
+	else
+	    fi->xst_hinting = ST_IGNORE_HINTS;
+    }
+#endif
+
     /* disable global advance width (for broken DynaLab TT CJK fonts) */
     switch (FcPatternGetBool (pattern, FC_GLOBAL_ADVANCE, 0, &global_advance)) {
     case FcResultNoMatch:

Index: xftglyphs.c
===================================================================
RCS file: /cvs/stsf/xftbridge/xftglyphs.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- xftglyphs.c	5 Apr 2004 21:49:28 -0000	1.1
+++ xftglyphs.c	29 Jul 2004 17:54:35 -0000	1.2
@@ -103,6 +103,7 @@
     FT_Vector	    vector;
     Bool	    subpixel = False;
     FT_Face	    face;
+    int             bold_advance_width = 0;
 
     if (!info)
 	return;
@@ -112,6 +113,24 @@
     if (!face)
 	return;
 
+    /*-------------------------------------------------------
+     * Add by Firefly (firefly at firefly.idv.tw)
+     *------------------------------------------------------*/
+    if (font->info.weight >= FC_WEIGHT_BOLD &&
+       !(face->style_flags & FT_STYLE_FLAG_BOLD))
+    {
+       bold_advance_width = 64;
+#ifdef XST
+       font->info.xst_embolden = ST_SE_EMBOLDEN;
+#endif
+    }
+#ifdef XST
+    else
+    {
+       font->info.xst_embolden = 0;
+    }
+#endif
+
     matrix.xx = matrix.yy = 0x10000L;
     matrix.xy = matrix.yx = 0;
 
@@ -216,6 +235,7 @@
 	    bottom = FLOOR( glyphslot->metrics.horiBearingY - glyphslot->metrics.height );
 	}
 
+        right += CEIL(bold_advance_width);
 	width = TRUNC(right - left);
 	height = TRUNC( top - bottom );
 
@@ -223,34 +243,42 @@
 	 * Try to keep monospace fonts ink-inside
 	 * XXX transformed?
 	 */
+        /* Modified by Firefly (firefly at firefly.idv.tw)
+         *
+         * Don't use "font->public.max_advance_width", because CJK fonts
+         * have both half-width and full-width.
+         * So must use "glyphslot->metrics.vertAdvance" &
+         * "glyphslot->metrics.horiAdvance" in order to get correctly width.
+         *----------------------------------------------------------------*/
+        glyphslot->metrics.horiAdvance += bold_advance_width;
 	if (font->info.spacing != FC_PROPORTIONAL && !font->info.transform)
 	{
 	    if (font->info.load_flags & FT_LOAD_VERTICAL_LAYOUT)
 	    {
-		if (TRUNC(bottom) > font->public.max_advance_width)
+		if (bottom > glyphslot->metrics.vertAdvance)
 		{
 		    int adjust;
     
-		    adjust = bottom - (font->public.max_advance_width << 6);
+		    adjust = bottom - glyphslot->metrics.vertAdvance;
 		    if (adjust > top)
 			adjust = top;
 		    top -= adjust;
 		    bottom -= adjust;
-		    height = font->public.max_advance_width;
+                    height = TRUNC(glyphslot->metrics.vertAdvance);
 		}
 	    }
 	    else
 	    {
-		if (TRUNC(right) > font->public.max_advance_width)
+                if (right > glyphslot->metrics.horiAdvance)
 		{
 		    int adjust;
     
-		    adjust = right - (font->public.max_advance_width << 6);
+                    adjust = right - glyphslot->metrics.horiAdvance;
 		    if (adjust > left)
 			adjust = left;
 		    left -= adjust;
 		    right -= adjust;
-		    width = font->public.max_advance_width;
+                    width = TRUNC(glyphslot->metrics.horiAdvance);
 		}
 	    }
 	}
@@ -274,11 +302,11 @@
 		if (font->info.load_flags & FT_LOAD_VERTICAL_LAYOUT)
 		{
 		    vector.x = 0;
-		    vector.y = -face->size->metrics.max_advance;
+		    vector.y = -glyphslot->metrics.vertAdvance;
 		}
 		else
 		{
-		    vector.x = face->size->metrics.max_advance;
+                    vector.x = glyphslot->metrics.horiAdvance;
 		    vector.y = 0;
 		}
 		FT_Vector_Transform (&vector, &font->info.matrix);
@@ -290,18 +318,18 @@
 		if (font->info.load_flags & FT_LOAD_VERTICAL_LAYOUT)
 		{
 		    xftg->metrics.xOff = 0;
-		    xftg->metrics.yOff = -font->public.max_advance_width;
+                    xftg->metrics.yOff = -(glyphslot->metrics.vertAdvance >> 6);
 		}
 		else
 		{
-		    xftg->metrics.xOff = font->public.max_advance_width;
+                    xftg->metrics.xOff = glyphslot->metrics.horiAdvance >> 6;
 		    xftg->metrics.yOff = 0;
 		}
 	    }
 	}
 	else
 	{
-	    xftg->metrics.xOff = TRUNC(ROUND(glyphslot->advance.x));
+	    xftg->metrics.xOff = TRUNC(ROUND(glyphslot->advance.x + bold_advance_width));
 	    xftg->metrics.yOff = -TRUNC(ROUND(glyphslot->advance.y));
 	}
 	
@@ -403,6 +431,10 @@
 	    continue;
 	}
 	
+        /*-------------------------------------------------------
+         * Add by Firefly (firefly at firefly.idv.tw)
+         * some code from XFree86's X-TrueType module.
+         *------------------------------------------------------*/
 	if (XftDebug() & XFT_DBG_GLYPH)
 	{
 	    printf ("glyph %d:\n", (int) glyphindex);
@@ -607,6 +639,9 @@
     FT_UInt	    glyphindex;
     Glyph	    glyphBuf[1024];
     int		    nused;
+#ifdef XST
+    extern int      use_xst;
+#endif
     
     nused = 0;
     while (nglyph--)
@@ -624,7 +659,14 @@
 		    glyphBuf[nused++] = (Glyph) glyphindex;
 		    if (nused == sizeof (glyphBuf) / sizeof (glyphBuf[0]))
 		    {
+#ifdef USE_XST
+		        if ( !use_xst )
+			{
+			    XRenderFreeGlyphs (dpy, font->glyphset, glyphBuf, nused);
+			}
+#else
 			XRenderFreeGlyphs (dpy, font->glyphset, glyphBuf, nused);
+#endif
 			nused = 0;
 		    }
 		}
@@ -643,7 +685,14 @@
 	font->glyphs[glyphindex] = 0;
     }    
     if (font->glyphset && nused)
+#ifdef USE_XST
+	if ( !use_xst )
+	{
+	    XRenderFreeGlyphs (dpy, font->glyphset, glyphBuf, nused);
+	}
+#else
 	XRenderFreeGlyphs (dpy, font->glyphset, glyphBuf, nused);
+#endif
 }
 
 FcBool

Index: Xft.h
===================================================================
RCS file: /cvs/stsf/xftbridge/Xft.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Xft.h	5 Apr 2004 21:49:28 -0000	1.1
+++ Xft.h	29 Jul 2004 17:54:35 -0000	1.2
@@ -32,7 +32,8 @@
 #define XftVersion	XFT_VERSION
 
 #include <stdarg.h>
-#include <freetype/freetype.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
 #include <fontconfig/fontconfig.h>
 #include <X11/extensions/Xrender.h>
 

Index: xftint.h
===================================================================
RCS file: /cvs/stsf/xftbridge/xftint.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- xftint.h	5 Apr 2004 21:49:28 -0000	1.1
+++ xftint.h	29 Jul 2004 17:54:35 -0000	1.2
@@ -30,55 +30,6 @@
  * interfaces. keithp at xfree86.org
  */
 
-/*
- * Copyright © 2004 Sun Microsystems, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of Sun Microsystems, Inc. nor the names of 
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind.
- *
- * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
- * SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR
- * LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE,
- * MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES.
- * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
- * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
- * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
- * THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE
- * SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or intended
- * for use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- */
-
-/* $Id$ */
-
-
-/**
- * @file xftint.h
- * @brief Xft/STSF Bridge Library
- * @author Jay Hobson <jay.hobson at sun.com>
- * @version 0.8
- */
-
 #ifndef _XFTINT_H_
 #define _XFTINT_H_
 
@@ -169,9 +120,14 @@
     int			spacing;
     FcBool		minspace;
     int			char_width;
+    int                 weight;
 #ifdef USE_XST
     XSTFont             xst_font;
     double              xst_size;
+    uint32_t            xst_embolden;
+    uint32_t            xst_italicize;
+    uint32_t            xst_hinting;
+    uint32_t            xst_embedding;
 #endif
 };
 



More information about the stsf-commit mailing list