--- xc.orig/extras/freetype2/include/freetype/internal/sfnt.h	2004-03-06 03:48:03.000000000 +0900
+++ xc/extras/freetype2/include/freetype/internal/sfnt.h	2004-04-14 13:53:04.000000000 +0900
@@ -239,6 +239,73 @@
                        FT_Byte   *buffer,
                        FT_ULong*  length );
 
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Find_SBit_Image_Func                                            */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Checks whether an embedded bitmap (an `sbit') exists for a given   */
+  /*    glyph, at a given strike.                                          */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face          :: The target face object.                           */
+  /*                                                                       */
+  /*    glyph_index   :: The glyph index.                                  */
+  /*                                                                       */
+  /*    strike_index  :: The current strike index.                         */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    arange        :: The SBit range containing the glyph index.        */
+  /*                                                                       */
+  /*    astrike       :: The SBit strike containing the glyph index.       */
+  /*                                                                       */
+  /*    aglyph_offset :: The offset of the glyph data in `EBDT' table.     */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.  Returns                    */
+  /*    SFNT_Err_Invalid_Argument if no sbit exists for the requested      */
+  /*    glyph.                                                             */
+  /*                                                                       */
+  typedef FT_Error
+  (*TT_Find_SBit_Image_Func)( TT_Face          face,
+                              FT_UInt          glyph_index,
+                              FT_ULong         strike_index,
+                              TT_SBit_Range   *arange,
+                              TT_SBit_Strike  *astrike,
+                              FT_ULong        *aglyph_offset );
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Load_SBit_Metrics_Func                                          */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Gets the big metrics for a given SBit.                             */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream      :: The input stream.                                   */
+  /*                                                                       */
+  /*    range       :: The SBit range containing the glyph.                */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    big_metrics :: A big SBit metrics structure for the glyph.         */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The stream cursor must be positioned at the glyph's offset within  */
+  /*    the `EBDT' table before the call.                                  */
+  /*                                                                       */
+  /*    If the image format uses variable metrics, the stream cursor is    */
+  /*    positioned just after the metrics header in the `EBDT' table on    */
+  /*    function exit.                                                     */
+  /*                                                                       */
+  typedef FT_Error
+  (*TT_Load_SBit_Metrics_Func)( FT_Stream        stream,
+                                TT_SBit_Range    range,
+                                TT_SBit_Metrics  metrics );
 
   /*************************************************************************/
   /*                                                                       */
@@ -503,6 +570,8 @@
     /* see `ttsbit.h' */
     TT_Set_SBit_Strike_Func      set_sbit_strike;
     TT_Load_Table_Func           load_sbits;
+    TT_Find_SBit_Image_Func      find_sbit_image;
+    TT_Load_SBit_Metrics_Func    load_sbit_metrics;
     TT_Load_SBit_Image_Func      load_sbit_image;
     TT_Free_Table_Func           free_sbits;
 
--- xc.orig/extras/freetype2/src/sfnt/sfdriver.c	2004-03-06 03:48:06.000000000 +0900
+++ xc/extras/freetype2/src/sfnt/sfdriver.c	2004-04-14 13:53:04.000000000 +0900
@@ -334,6 +334,8 @@
     /* see `ttsbit.h' */
     tt_face_set_sbit_strike,
     tt_face_load_sbit_strikes,
+    tt_find_sbit_image,
+    tt_load_sbit_metrics,
     tt_face_load_sbit_image,
     tt_face_free_sbit_strikes,
 
@@ -342,6 +344,8 @@
     0,
     0,
     0,
+    0, 
+    0, 
     0,
     0,
 
--- xc.orig/extras/freetype2/src/sfnt/ttsbit.h	2003-11-27 07:48:28.000000000 +0900
+++ xc/extras/freetype2/src/sfnt/ttsbit.h	2004-04-14 13:53:04.000000000 +0900
@@ -42,6 +42,19 @@
                            FT_ULong  *astrike_index );
 
   FT_LOCAL( FT_Error )
+  tt_find_sbit_image( TT_Face          face,
+                      FT_UInt          glyph_index,
+                      FT_ULong         strike_index,
+                      TT_SBit_Range   *arange,
+                      TT_SBit_Strike  *astrike,
+                      FT_ULong        *aglyph_offset );
+
+  FT_LOCAL( FT_Error )
+  tt_load_sbit_metrics( FT_Stream        stream,
+                        TT_SBit_Range    range,
+                        TT_SBit_Metrics  metrics );
+
+  FT_LOCAL( FT_Error )
   tt_face_load_sbit_image( TT_Face              face,
                            FT_ULong             strike_index,
                            FT_UInt              glyph_index,
--- xc.orig/extras/freetype2/src/sfnt/ttsbit.c	2004-03-06 03:48:06.000000000 +0900
+++ xc/extras/freetype2/src/sfnt/ttsbit.c	2004-04-14 13:53:04.000000000 +0900
@@ -754,7 +754,7 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    find_sbit_image                                                    */
+  /*    tt_find_sbit_image                                                 */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Checks whether an embedded bitmap (an `sbit') exists for a given   */
@@ -779,13 +779,13 @@
   /*    SFNT_Err_Invalid_Argument if no sbit exists for the requested      */
   /*    glyph.                                                             */
   /*                                                                       */
-  static FT_Error
-  find_sbit_image( TT_Face          face,
-                   FT_UInt          glyph_index,
-                   FT_ULong         strike_index,
-                   TT_SBit_Range   *arange,
-                   TT_SBit_Strike  *astrike,
-                   FT_ULong        *aglyph_offset )
+  FT_LOCAL( FT_Error )
+  tt_find_sbit_image( TT_Face          face,
+                      FT_UInt          glyph_index,
+                      FT_ULong         strike_index,
+                      TT_SBit_Range   *arange,
+                      TT_SBit_Strike  *astrike,
+                      FT_ULong        *aglyph_offset )
   {
     FT_Error        error;
     TT_SBit_Strike  strike;
@@ -819,7 +819,7 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    load_sbit_metrics                                                  */
+  /*    tt_load_sbit_metrics                                               */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Gets the big metrics for a given SBit.                             */
@@ -843,10 +843,10 @@
   /*    positioned just after the metrics header in the `EBDT' table on    */
   /*    function exit.                                                     */
   /*                                                                       */
-  static FT_Error
-  load_sbit_metrics( FT_Stream        stream,
-                     TT_SBit_Range    range,
-                     TT_SBit_Metrics  metrics )
+  FT_LOCAL( FT_Error )
+  tt_load_sbit_metrics( FT_Stream        stream,
+                        TT_SBit_Range    range,
+                        TT_SBit_Metrics  metrics )
   {
     FT_Error  error = SFNT_Err_Ok;
 
@@ -1228,7 +1228,7 @@
     if ( FT_STREAM_SEEK( ebdt_pos + glyph_offset ) )
       goto Exit;
 
-    error = load_sbit_metrics( stream, range, metrics );
+    error = tt_load_sbit_metrics( stream, range, metrics );
     if ( error )
       goto Exit;
 
@@ -1419,8 +1419,8 @@
 
 
     /* Check whether there is a glyph sbit for the current index */
-    error = find_sbit_image( face, glyph_index, strike_index,
-                             &range, &strike, &glyph_offset );
+    error = tt_find_sbit_image( face, glyph_index, strike_index,
+                                &range, &strike, &glyph_offset );
     if ( error )
       goto Exit;
 
--- xc.orig/lib/font/FreeType/ftfuncs.h	2004-03-05 02:47:03.000000000 +0900
+++ xc/lib/font/FreeType/ftfuncs.h	2004-04-14 13:53:04.000000000 +0900
@@ -121,6 +121,7 @@
     FT_Size size;
     FTNormalisedTransformationRec transformation;
     FT_Int32 load_flags;
+    FT_ULong strike_index;
     int spacing;		/* actual spacing */
     double pixel_size;          /* to calc attributes (actual height) */
     double pixel_width_unit_x;  /* to calc horiz. width (cosine) */
--- xc.orig/lib/font/FreeType/ftfuncs.c	2004-03-27 05:09:05.000000000 +0900
+++ xc/lib/font/FreeType/ftfuncs.c	2004-04-14 13:53:04.000000000 +0900
@@ -5,7 +5,7 @@
 Copyright (c) 1998 Kazushi (Jam) Marukawa, All rights reserved.
 Copyright (c) 1998 Takuya SHIOZAKI, All rights reserved.
 Copyright (c) 1998 X-TrueType Server Project, All rights reserved.
-Copyright (c) 2003 After X-TT Project, All rights reserved.
+Copyright (c) 2003-2004 After X-TT Project, All rights reserved.
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -52,10 +52,9 @@
 #include FT_XFREE86_H
 #include FT_BBOX_H
 #include FT_INTERNAL_TRUETYPE_TYPES_H
-#ifdef USE_INTERNAL_FREETYPE
-# include "ttobjs.h"
-#endif
-
+#include FT_TRUETYPE_TAGS_H
+#include FT_INTERNAL_SFNT_H
+#include FT_INTERNAL_STREAM_H
 /*
  *  If you want to use FT_Outline_Get_CBox instead of 
  *  FT_Outline_Get_BBox, define here.
@@ -459,6 +458,33 @@
         return FTtoXReturnCode(ftrc);
     }
 
+    if( FT_IS_SFNT( face->face ) ) {
+	/* See Set_Char_Sizes() in ttdriver.c */
+	FT_Error err;
+	TT_Face tt_face;
+	FT_Long tt_dim_x, tt_dim_y;
+	FT_UShort tt_x_ppem, tt_y_ppem;
+	FT_F26Dot6  tt_char_width, tt_char_height;
+	SFNT_Service sfnt;
+	tt_face=(TT_Face)face->face;
+	tt_char_width  = (int)(trans->scale*(1<<6) + 0.5);
+	tt_char_height = (int)(trans->scale*(1<<6) + 0.5);
+	if ( ( tt_face->header.Flags & 8 ) != 0 ) {
+	    tt_dim_x = ( ( tt_char_width  * trans->xres + (36+32*72) ) / 72 ) & -64;
+	    tt_dim_y = ( ( tt_char_height * trans->yres + (36+32*72) ) / 72 ) & -64;
+	}
+	else{
+	    tt_dim_x = ( ( tt_char_width  * trans->xres + 36 ) / 72 );
+	    tt_dim_y = ( ( tt_char_height * trans->yres + 36 ) / 72 );
+	}
+	tt_x_ppem  = (FT_UShort)( tt_dim_x >> 6 );
+	tt_y_ppem  = (FT_UShort)( tt_dim_y >> 6 );
+	/* See Reset_SBit_Size() in ttobjs.c */
+	sfnt   = (SFNT_Service)tt_face->sfnt;
+	err = sfnt->set_sbit_strike(tt_face,tt_x_ppem,tt_y_ppem,&instance->strike_index);
+	if ( err ) instance->strike_index=0xFFFFU;
+    }
+
     /* maintain a linked list of instances */
     instance->next = instance->face->instances;
     instance->face->instances = instance;
@@ -876,20 +902,88 @@
     return -1;
 }
 
+static FT_Error
+FT_Do_SBit_Metrics( FT_Face ft_face, FT_Size ft_size, FT_ULong strike_index,
+		    FT_UShort glyph_index, FT_Glyph_Metrics *metrics_return )
+{
+    SFNT_Service       sfnt;
+    TT_Face            face;
+    FT_Error           error;
+    FT_Stream          stream;
+    TT_SBit_Strike     strike;
+    TT_SBit_Range      range;
+    TT_SBit_MetricsRec elem_metrics;
+    FT_ULong           ebdt_pos;
+    FT_ULong           glyph_offset;
+    ;
+
+    if ( ! FT_IS_SFNT( ft_face ) )
+    {
+        error=-1;
+        goto Exit;
+    }
+
+    face = (TT_Face)ft_face;
+    sfnt   = (SFNT_Service)face->sfnt;
+
+    if ( strike_index != 0xFFFFU && sfnt->load_sbits ) {
+        /* Check whether there is a glyph sbit for the current index */
+        error = sfnt->find_sbit_image( face, glyph_index, strike_index,
+                                       &range, &strike, &glyph_offset );
+    }
+    else error=-1;
+    if ( error ) goto Exit;
+
+    if ( metrics_return == NULL ) goto Exit;
+
+    stream = face->root.stream;
+
+    /* now, find the location of the `EBDT' table in */
+    /* the font file                                 */
+    error = face->goto_table( face, TTAG_EBDT, stream, 0 );
+    if ( error )
+      error = face->goto_table( face, TTAG_bdat, stream, 0 );
+    if (error)
+      goto Exit;
+
+    ebdt_pos = FT_STREAM_POS();
+
+    /* place stream at beginning of glyph data and read metrics */
+    if ( FT_STREAM_SEEK( ebdt_pos + glyph_offset ) )
+      goto Exit;
+
+    error = sfnt->load_sbit_metrics( stream, range, &elem_metrics );
+    if ( error )
+      goto Exit;
+
+    metrics_return->width  = (FT_Pos)elem_metrics.width  << 6;
+    metrics_return->height = (FT_Pos)elem_metrics.height << 6;
+
+    metrics_return->horiBearingX = (FT_Pos)elem_metrics.horiBearingX << 6;
+    metrics_return->horiBearingY = (FT_Pos)elem_metrics.horiBearingY << 6;
+    metrics_return->horiAdvance  = (FT_Pos)elem_metrics.horiAdvance  << 6;
+    
+    metrics_return->vertBearingX = (FT_Pos)elem_metrics.vertBearingX << 6;
+    metrics_return->vertBearingY = (FT_Pos)elem_metrics.vertBearingY << 6;
+    metrics_return->vertAdvance  = (FT_Pos)elem_metrics.vertAdvance  << 6;
+
+  Exit:
+      return error;
+}
+
 int
 FreeTypeRasteriseGlyph(unsigned idx, int flags, CharInfoPtr tgp,
 		       FTInstancePtr instance, int hasMetrics)
 {
     FTFacePtr face;
-    FT_Bitmap *bitmap;
     FT_BBox bbox;
-    FT_Long outline_hori_advance;
-    FT_Long outline_vert_advance;
-    char *raster = NULL;
-    FT_Glyph_Metrics *metrics = NULL;
+    FT_Long outline_hori_advance, outline_vert_advance;
+    FT_Glyph_Metrics sbit_metrics;
+    FT_Glyph_Metrics *bitmap_metrics=NULL, *metrics = NULL;
+    char *raster;
     int wd, ht, bpr;            /* width, height, bytes per row */
     int wd_actual, ht_actual;
-    int ftrc, is_outline, b_shift=0, correct=0;
+    int ftrc, is_outline, correct, b_shift=0;
     int dx, dy;
     int leftSideBearing, rightSideBearing, characterWidth, rawCharacterWidth,
         ascent, descent;
@@ -899,30 +993,8 @@
 
     FreeTypeActivateInstance(instance);
 
-    bitmap = &face->face->glyph->bitmap;
-
     if(!tgp) return AllocError;
 
-    if( instance->spacing == FT_CHARCELL ) correct=1;
-    else if( flags & FT_FORCE_CONSTANT_SPACING ) correct=1;
-    else if( instance->ttcap.flags & TTCAP_IS_VERY_LAZY ){
-	if( hasMetrics || (!hasMetrics && (flags & FT_GET_GLYPH_METRICS_ONLY)) ){
-	    /* If sbit is available, we don't use very lazy method. */
-	    /* See TT_Load_Glyph */
-	    if( FT_IS_SFNT( face->face ) ) {
-#ifdef USE_INTERNAL_FREETYPE
-		TT_Size tt_size = (TT_Size)instance->size;
-		if( !( !(instance->load_flags & FT_LOAD_NO_BITMAP)
-		       && tt_size->strike_index != 0xFFFFU ) )
-#else
-		if((instance->load_flags & FT_LOAD_NO_BITMAP)
-		   || (face->face->face_flags & FT_FACE_FLAG_FIXED_SIZES) == 0)
-#endif
-		    correct=1;
-	    }
-	}
-    }
-
     /*
      * PREPARE METRICS
      */
@@ -940,34 +1012,42 @@
 	}
 	/* mono or prop. */
 	else{
-	    int new_width, try_very_lazy=correct;
+	    int new_width;
 	    double ratio;
 
-	    if( try_very_lazy ) {
-		if( ft_get_very_lazy_bbox( idx, face->face, instance->size, 
-					   instance->ttcap.vl_slant,
-					   &instance->transformation.matrix,
-					   &bbox, &outline_hori_advance, 
-					   &outline_vert_advance ) == 0 ) {
-		    goto bbox_ok;	/* skip exact calculation */
+	    if( ! (instance->load_flags & FT_LOAD_NO_BITMAP) ) {
+		if( FT_Do_SBit_Metrics(face->face,instance->size,instance->strike_index,
+				       idx,&sbit_metrics)==0 ) {
+		    bitmap_metrics = &sbit_metrics;
+		}
+	    }
+	    if( bitmap_metrics == NULL ) {
+		if ( instance->ttcap.flags & TTCAP_IS_VERY_LAZY ) {
+		    if( ft_get_very_lazy_bbox( idx, face->face, instance->size, 
+					       instance->ttcap.vl_slant,
+					       &instance->transformation.matrix,
+					       &bbox, &outline_hori_advance, 
+					       &outline_vert_advance ) == 0 ) {
+			goto bbox_ok;	/* skip exact calculation */
+		    }
+		}
+		ftrc = FT_Load_Glyph(instance->face->face, idx, 
+				     instance->load_flags);
+		if(ftrc != 0) return FTtoXReturnCode(ftrc);
+		metrics = &face->face->glyph->metrics;
+		if( face->face->glyph->format == FT_GLYPH_FORMAT_BITMAP ) {
+		    bitmap_metrics = metrics;
 		}
 	    }
 
-	    ftrc = FT_Load_Glyph(instance->face->face, idx, 
-				 instance->load_flags);
-	    metrics = &face->face->glyph->metrics;
-
-	    if(ftrc != 0) return FTtoXReturnCode(ftrc);
-
-	    if( face->face->glyph->format == FT_GLYPH_FORMAT_BITMAP ) {
-		/* bitmap, embedded bitmap */
-		leftSideBearing = metrics->horiBearingX / 64;
-		rightSideBearing = (metrics->width + metrics->horiBearingX) / 64;
-		bbox_center_raw = (2.0 * metrics->horiBearingX + metrics->width)/2.0/64.0;
-		characterWidth = (int)floor(metrics->horiAdvance 
+	    if( bitmap_metrics ) {
+		leftSideBearing = bitmap_metrics->horiBearingX / 64;
+		rightSideBearing = (bitmap_metrics->width + bitmap_metrics->horiBearingX) / 64;
+		bbox_center_raw = (2.0 * bitmap_metrics->horiBearingX + bitmap_metrics->width)/2.0/64.0;
+		characterWidth = (int)floor(bitmap_metrics->horiAdvance 
 					    * instance->ttcap.scaleBBoxWidth / 64.0 + .5);
-		ascent = metrics->horiBearingY / 64;
-		descent = (metrics->height - metrics->horiBearingY) / 64 ;
+		ascent = bitmap_metrics->horiBearingY / 64;
+		descent = (bitmap_metrics->height - bitmap_metrics->horiBearingY) / 64 ;
 		/* */
 		new_width = characterWidth;
 		if( instance->ttcap.flags & TTCAP_DOUBLE_STRIKE_CORRECT_B_BOX_WIDTH )
@@ -984,7 +1064,7 @@
 		leftSideBearing  += instance->ttcap.lsbShiftOfBitmapAutoItalic;
 		/* */
 		rawCharacterWidth =
-		    (unsigned short)(short)(floor(1000 * metrics->horiAdvance 
+		    (unsigned short)(short)(floor(1000 * bitmap_metrics->horiAdvance 
 						  * instance->ttcap.scaleBBoxWidth * ratio / 64.
 						  / instance->pixel_size));
 	    }
@@ -1068,6 +1148,28 @@
     if( flags & FT_GET_GLYPH_METRICS_ONLY ) return Successful;
 
     /*
+     * CHECK THE NECESSITY OF BITMAP POSITION'S CORRECTION
+     */
+
+    correct=0;
+    if( instance->spacing == FT_CHARCELL ) correct=1;
+    else if( flags & FT_FORCE_CONSTANT_SPACING ) correct=1;
+    else{
+	int sbit_available=0;
+	if( !(instance->load_flags & FT_LOAD_NO_BITMAP) ) {
+	    if( FT_Do_SBit_Metrics(face->face,instance->size,
+				   instance->strike_index,idx,NULL)==0 ) {
+		sbit_available=1;
+	    }
+	}
+	if( sbit_available == 0 ) {
+	    if ( instance->ttcap.flags & TTCAP_IS_VERY_LAZY ) {
+		if( FT_IS_SFNT(face->face) ) correct=1;
+	    }
+	}
+    }
+
+    /*
      * RENDER AND ALLOCATE BUFFER
      */
 
@@ -1209,11 +1311,13 @@
      */
 
     {
+	FT_Bitmap *bitmap;
 	int i, j;
 	unsigned char *current_raster;
 	unsigned char *current_buffer;
 	int mod_dx0,mod_dx1;
 	int div_dx;
+	bitmap = &face->face->glyph->bitmap;
 	if( 0 <= dx ){
 	    div_dx = dx / 8;
 	    mod_dx0 = dx % 8;
