Commit e33dc2ebeef85f78805a422f089307606925e062

Wu, Chia-I (吳佳一) 2006-01-14T05:09:30

* docs/CHANGES: Mention the size selection change. * src/bdf/bdfdrivr.c (BDF_Size_Request, BDF_Size_Select), src/pcf/pcfdrivr.c (PCF_Size_Request, PCF_Size_Select), src/winfonts/winfnt.c (FNT_Size_Request, FNT_Size_Select): Do size matching for request of type NOMINAL and REAL_DIM. * src/winfonts/winfnt.c (FNT_Face_Init): Print trace message when `pixel_height' is used for nominal height. * src/base/ftobjs.c (FT_Request_Size): Call `FT_Match_Size' if the face is bitmap only and driver doesn't provide `request_size'. This is added merely for completion as no driver satisfies the conditions.

diff --git a/ChangeLog b/ChangeLog
index 833b427..c6210ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2006-01-14  Chia-I Wu  <b90201047@ntu.edu.tw>
+
+	* docs/CHANGES: Mention the size selection change.
+
+	* src/bdf/bdfdrivr.c (BDF_Size_Request, BDF_Size_Select),
+	src/pcf/pcfdrivr.c (PCF_Size_Request, PCF_Size_Select),
+	src/winfonts/winfnt.c (FNT_Size_Request, FNT_Size_Select): Do size
+	matching for request of type NOMINAL and REAL_DIM.
+
+	* src/winfonts/winfnt.c (FNT_Face_Init): Print trace message when
+	`pixel_height' is used for nominal height.
+
+	* src/base/ftobjs.c (FT_Request_Size): Call `FT_Match_Size' if the
+	face is bitmap only and driver doesn't provide `request_size'.  This
+	is added merely for completion as no driver satisfies the conditions.
+
 2006-01-13  Chia-I Wu  <b90201047@ntu.edu.tw>
 
 	Introduce new size selection interface.
diff --git a/docs/CHANGES b/docs/CHANGES
index fd63451..5bfdf7d 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -52,6 +52,16 @@ LATEST CHANGES BETWEEN 2.2.0 and 2.1.10
       `FT_GetFile_From_Mac_Name'.  Legacy APIs are still available, if
       FreeType is built without disabling them.
 
+    - A new API `FT_Select_Size' is added to select a bitmap strike by
+      its index.  Code  using other functions to select bitmap strikes
+      should be updated to use this function.
+
+    - In 2.1.10,  the behavior of `FT_Set_Pixel_Sizes'  is changed for
+      BDF/PCF  fonts,  and only for  them.  This causes inconsistency.
+      In this release,  we undo the change.  The intent  of the change
+      in 2.1.10  is to allow  size selection through  real dimensions,
+      which can now be done through `FT_Request_Size'.
+
 
   III. MISCELLANEOUS
 
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index a19092c..c2efbe0 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -2093,6 +2093,7 @@
     FT_Driver_Class   clazz;
     FT_Size_Metrics*  metrics;
     FT_Error          error;
+    FT_Bool           bitmap_only = 0;
 
 
     if ( !face )
@@ -2190,13 +2191,36 @@
     else
     {
       FT_ZERO( metrics );
+
+      if ( FT_HAS_FIXED_SIZES( face ) )
+        bitmap_only = 1;
+
       error = FT_Err_Invalid_Pixel_Size;
     }
 
     if ( clazz->request_size )
-      return clazz->request_size( face->size, req );
-    else
-      return error;
+      error = clazz->request_size( face->size, req );
+    /*
+     * The reason that a driver not having `request_size' defined is
+     * either the scaling here suffices or the supported formats
+     * are bitmap-only and size matching is not implmented.
+     *
+     * In the latter case, a simple size matching is done.
+     */
+    else if ( bitmap_only )
+    {
+      FT_ULong  index;
+
+
+      if ( !FT_Match_Size( face, req, 0, &index ) )
+      {
+        FT_TRACE3(( "FT_Request_Size: bitmap strike %lu matched\n", index ));
+
+        error = FT_Select_Size( face, index );
+      }
+    }
+
+    return error;
   }
 
 
diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c
index 445fb9f..213abcb 100644
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -592,6 +592,8 @@ THE SOFTWARE.
 
     size->metrics.ascender    = bdffont->font_ascent << 6;
     size->metrics.descender   = -bdffont->font_descent << 6;
+    size->metrics.height      = ( bdffont->font_ascent +
+                                  bdffont->font_descent ) << 6;
     size->metrics.max_advance = bdffont->bbx.width << 6;
 
     return BDF_Err_Ok;
@@ -602,20 +604,40 @@ THE SOFTWARE.
   BDF_Size_Request( FT_Size          size,
                     FT_Size_Request  req )
   {
-    FT_Face   face = size->face;
-    FT_Error  error;
+    FT_Face          face    = size->face;
+    FT_Bitmap_Size*  bsize   = face->available_sizes;
+    bdf_font_t*      bdffont = ( (BDF_Face)face )->bdffont;
+    FT_Error         error   = BDF_Err_Invalid_Pixel_Size;
+    FT_Long          height;
 
 
-    error = FT_Match_Size( face, req, 1, NULL );
+    if ( req->vertResolution )
+      height = ( req->height * req->vertResolution + 36 ) / 72;
+    else
+      height = req->height;
+
+    height = ( height + 32 ) >> 6;
+
+    switch ( req->type )
+    {
+    case FT_SIZE_REQUEST_TYPE_NOMINAL:
+      if ( height == ( bsize->y_ppem + 32 ) >> 6 )
+        error = BDF_Err_Ok;
+      break;
+    case FT_SIZE_REQUEST_TYPE_REAL_DIM:
+      if ( height == ( bdffont->font_ascent +
+                       bdffont->font_descent ) )
+        error = BDF_Err_Ok;
+      break;
+    default:
+      error = BDF_Err_Unimplemented_Feature;
+      break;
+    }
 
     if ( error )
       return error;
     else
-    {
-      size->metrics.height = face->available_sizes->height << 6;
-
       return BDF_Size_Select( size, 0 );
-    }
   }
 
 
diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c
index 011b45d..f3d56d9 100644
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -375,6 +375,9 @@ THE SOFTWARE.
     size->metrics.descender   = -face->accel.fontDescent << 6;
 #if 0
     size->metrics.height      = face->accel.maxbounds.ascent << 6;
+#else
+    size->metrics.height      = size->metrics.ascender -
+                                size->metrics.descender;
 #endif
     size->metrics.max_advance = face->accel.maxbounds.characterWidth << 6;
 
@@ -386,20 +389,39 @@ THE SOFTWARE.
   PCF_Size_Request( FT_Size          size,
                     FT_Size_Request  req )
   {
-    FT_Face   face = size->face;
-    FT_Error  error;
+    PCF_Face         face    = (PCF_Face)size->face;
+    FT_Bitmap_Size*  bsize   = size->face->available_sizes;
+    FT_Error         error   = PCF_Err_Invalid_Pixel_Size;
+    FT_Long          height;
 
 
-    error = FT_Match_Size( face, req, 1, NULL );
+    if ( req->vertResolution )
+      height = ( req->height * req->vertResolution + 36 ) / 72;
+    else
+      height = req->height;
+
+    height = ( height + 32 ) >> 6;
+
+    switch ( req->type )
+    {
+    case FT_SIZE_REQUEST_TYPE_NOMINAL:
+      if ( height == ( bsize->y_ppem + 32 ) >> 6 )
+        error = PCF_Err_Ok;
+      break;
+    case FT_SIZE_REQUEST_TYPE_REAL_DIM:
+      if ( height == ( face->accel.fontAscent +
+                       face->accel.fontDescent ) )
+        error = PCF_Err_Ok;
+      break;
+    default:
+      error = PCF_Err_Unimplemented_Feature;
+      break;
+    }
 
     if ( error )
       return error;
     else
-    {
-      size->metrics.height = face->available_sizes->height << 6;
-
       return PCF_Size_Select( size, 0 );
-    }
   }
 
 
diff --git a/src/winfonts/winfnt.c b/src/winfonts/winfnt.c
index a24ea1b..66ae9f1 100644
--- a/src/winfonts/winfnt.c
+++ b/src/winfonts/winfnt.c
@@ -489,6 +489,8 @@
          */
         if ( bsize->y_ppem > font->header.pixel_height << 6 )
         {
+          FT_TRACE2(( "use pixel_height as the nominal height\n" ));
+
           bsize->y_ppem = font->header.pixel_height << 6;
           bsize->size   = FT_MulDiv( bsize->y_ppem, 72, y_res );
         }
@@ -579,6 +581,8 @@
     size->metrics.ascender    = header->ascent * 64;
     size->metrics.descender   = -( header->pixel_height -
                                    header->ascent ) * 64;
+    size->metrics.height      = ( header->pixel_height +
+                                  header->external_leading ) * 64;
     size->metrics.max_advance = header->max_width * 64;
 
     return FNT_Err_Ok;
@@ -589,20 +593,39 @@
   FNT_Size_Request( FT_Size          size,
                     FT_Size_Request  req )
   {
-    FT_Face   face = size->face;
-    FT_Error  error;
-    
+    FNT_Face          face    = (FNT_Face)size->face;
+    FT_WinFNT_Header  header  = &face->font->header;
+    FT_Bitmap_Size*   bsize   = size->face->available_sizes;
+    FT_Error          error   = FNT_Err_Invalid_Pixel_Size;
+    FT_Long           height;
 
-    error = FT_Match_Size( face, req, 1, NULL );
 
-    if ( error )
-      return error;
+    if ( req->vertResolution )
+      height = ( req->height * req->vertResolution + 36 ) / 72;
     else
+      height = req->height;
+
+    height = ( height + 32 ) >> 6;
+
+    switch ( req->type )
     {
-      size->metrics.height = face->available_sizes->height << 6;
+    case FT_SIZE_REQUEST_TYPE_NOMINAL:
+      if ( height == ( bsize->y_ppem + 32 ) >> 6 )
+        error = FNT_Err_Ok;
+      break;
+    case FT_SIZE_REQUEST_TYPE_REAL_DIM:
+      if ( height == header->pixel_height )
+        error = FNT_Err_Ok;
+      break;
+    default:
+      error = FNT_Err_Unimplemented_Feature;
+      break;
+    }
 
+    if ( error )
+      return error;
+    else
       return FNT_Size_Select( size );
-    }
   }