[CMAKE]
[reactos.git] / lib / 3rdparty / freetype / src / type1 / t1objs.c
index 3d08336..5863210 100644 (file)
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Type 1 objects manager (body).                                       */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by             */
+/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -17,6 +17,7 @@
 
 
 #include <ft2build.h>
+#include FT_INTERNAL_CALC_H
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_STREAM_H
 #include FT_TRUETYPE_IDS_H
@@ -90,7 +91,7 @@
   FT_LOCAL_DEF( FT_Error )
   T1_Size_Init( T1_Size  size )
   {
-    FT_Error           error = 0;
+    FT_Error           error = T1_Err_Ok;
     PSH_Globals_Funcs  funcs = T1_Size_Get_Globals_Funcs( size );
 
 
   FT_LOCAL_DEF( void )
   T1_Face_Done( T1_Face  face )
   {
-    if ( face )
-    {
-      FT_Memory  memory = face->root.memory;
-      T1_Font    type1  = &face->type1;
+    FT_Memory  memory;
+    T1_Font    type1;
+
+
+    if ( !face )
+      return;
 
+    memory = face->root.memory;
+    type1  = &face->type1;
 
 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
-      /* release multiple masters information */
-      FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
+    /* release multiple masters information */
+    FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
 
-      if ( face->buildchar )
-      {
-        FT_FREE( face->buildchar );
+    if ( face->buildchar )
+    {
+      FT_FREE( face->buildchar );
 
-        face->buildchar     = NULL;
-        face->len_buildchar = 0;
-      }
+      face->buildchar     = NULL;
+      face->len_buildchar = 0;
+    }
 
-      T1_Done_Blend( face );
-      face->blend = 0;
+    T1_Done_Blend( face );
+    face->blend = 0;
 #endif
 
-      /* release font info strings */
-      {
-        PS_FontInfo  info = &type1->font_info;
+    /* release font info strings */
+    {
+      PS_FontInfo  info = &type1->font_info;
 
 
-        FT_FREE( info->version );
-        FT_FREE( info->notice );
-        FT_FREE( info->full_name );
-        FT_FREE( info->family_name );
-        FT_FREE( info->weight );
-      }
+      FT_FREE( info->version );
+      FT_FREE( info->notice );
+      FT_FREE( info->full_name );
+      FT_FREE( info->family_name );
+      FT_FREE( info->weight );
+    }
 
-      /* release top dictionary */
-      FT_FREE( type1->charstrings_len );
-      FT_FREE( type1->charstrings );
-      FT_FREE( type1->glyph_names );
+    /* release top dictionary */
+    FT_FREE( type1->charstrings_len );
+    FT_FREE( type1->charstrings );
+    FT_FREE( type1->glyph_names );
 
-      FT_FREE( type1->subrs );
-      FT_FREE( type1->subrs_len );
+    FT_FREE( type1->subrs );
+    FT_FREE( type1->subrs_len );
 
-      FT_FREE( type1->subrs_block );
-      FT_FREE( type1->charstrings_block );
-      FT_FREE( type1->glyph_names_block );
+    FT_FREE( type1->subrs_block );
+    FT_FREE( type1->charstrings_block );
+    FT_FREE( type1->glyph_names_block );
 
-      FT_FREE( type1->encoding.char_index );
-      FT_FREE( type1->encoding.char_name );
-      FT_FREE( type1->font_name );
+    FT_FREE( type1->encoding.char_index );
+    FT_FREE( type1->encoding.char_name );
+    FT_FREE( type1->font_name );
 
 #ifndef T1_CONFIG_OPTION_NO_AFM
-      /* release afm data if present */
-      if ( face->afm_data )
-        T1_Done_Metrics( memory, (AFM_FontInfo)face->afm_data );
+    /* release afm data if present */
+    if ( face->afm_data )
+      T1_Done_Metrics( memory, (AFM_FontInfo)face->afm_data );
 #endif
 
-      /* release unicode map, if any */
+    /* release unicode map, if any */
 #if 0
-      FT_FREE( face->unicode_map_rec.maps );
-      face->unicode_map_rec.num_maps = 0;
-      face->unicode_map              = NULL;
+    FT_FREE( face->unicode_map_rec.maps );
+    face->unicode_map_rec.num_maps = 0;
+    face->unicode_map              = NULL;
 #endif
 
-      face->root.family_name = 0;
-      face->root.style_name  = 0;
-    }
+    face->root.family_name = NULL;
+    face->root.style_name  = NULL;
   }
 
 
 
     FT_UNUSED( num_params );
     FT_UNUSED( params );
-    FT_UNUSED( face_index );
     FT_UNUSED( stream );
 
 
       goto Exit;
 
     /* check the face index */
-    if ( face_index != 0 )
+    if ( face_index > 0 )
     {
       FT_ERROR(( "T1_Face_Init: invalid face index\n" ));
       error = T1_Err_Invalid_Argument;
 
 
       root->num_glyphs = type1->num_glyphs;
-      root->face_index = face_index;
+      root->face_index = 0;
 
       root->face_flags = FT_FACE_FLAG_SCALABLE    |
                          FT_FACE_FLAG_HORIZONTAL  |
 
       /* XXX: TODO -- add kerning with .afm support */
 
+
+      /* The following code to extract the family and the style is very   */
+      /* simplistic and might get some things wrong.  For a full-featured */
+      /* algorithm you might have a look at the whitepaper given at       */
+      /*                                                                  */
+      /*   http://blogs.msdn.com/text/archive/2007/04/23/wpf-font-selection-model.aspx */
+
       /* get style name -- be careful, some broken fonts only */
       /* have a `/FontName' dictionary entry!                 */
       root->family_name = info->family_name;
-      /* assume "Regular" style if we don't know better */
-      root->style_name = (char *)"Regular";
+      root->style_name  = NULL;
+
       if ( root->family_name )
       {
         char*  full   = info->full_name;
 
         if ( full )
         {
+          FT_Bool  the_same = TRUE;
+
+
           while ( *full )
           {
             if ( *full == *family )
                 family++;
               else
               {
+                the_same = FALSE;
+
                 if ( !*family )
                   root->style_name = full;
                 break;
               }
             }
           }
+
+          if ( the_same )
+            root->style_name = (char *)"Regular";
         }
       }
       else
           root->family_name = type1->font_name;
       }
 
+      if ( !root->style_name )
+      {
+        if ( info->weight )
+          root->style_name = info->weight;
+        else
+          /* assume `Regular' style because we don't know better */
+          root->style_name = (char *)"Regular";
+      }
+
       /* compute style flags */
       root->style_flags = 0;
       if ( info->italic_angle )
       root->num_fixed_sizes = 0;
       root->available_sizes = 0;
 
-      root->bbox.xMin =   type1->font_bbox.xMin             >> 16;
-      root->bbox.yMin =   type1->font_bbox.yMin             >> 16;
-      root->bbox.xMax = ( type1->font_bbox.xMax + 0xFFFFU ) >> 16;
-      root->bbox.yMax = ( type1->font_bbox.yMax + 0xFFFFU ) >> 16;
+      root->bbox.xMin =   type1->font_bbox.xMin            >> 16;
+      root->bbox.yMin =   type1->font_bbox.yMin            >> 16;
+      /* no `U' suffix here to 0xFFFF! */
+      root->bbox.xMax = ( type1->font_bbox.xMax + 0xFFFF ) >> 16;
+      root->bbox.yMax = ( type1->font_bbox.yMax + 0xFFFF ) >> 16;
 
       /* Set units_per_EM if we didn't set it in parse_font_matrix. */
       if ( !root->units_per_EM )
 
         /* in case of error, keep the standard width */
         if ( !error )
-          root->max_advance_width = (FT_Short)max_advance;
+          root->max_advance_width = (FT_Short)FIXED_TO_INT( max_advance );
         else
-          error = 0;   /* clear error */
+          error = T1_Err_Ok;   /* clear error */
       }
 
       root->max_advance_height = root->height;
 
         charmap.face = root;
 
-        /* first of all, try to synthetize a Unicode charmap */
-        charmap.platform_id = 3;
-        charmap.encoding_id = 1;
+        /* first of all, try to synthesize a Unicode charmap */
+        charmap.platform_id = TT_PLATFORM_MICROSOFT;
+        charmap.encoding_id = TT_MS_ID_UNICODE_CS;
         charmap.encoding    = FT_ENCODING_UNICODE;
 
-        FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );
+        error = FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );
+        if ( error && FT_Err_No_Unicode_Glyph_Name != error )
+          goto Exit;
+        error = FT_Err_Ok;
 
         /* now, generate an Adobe Standard encoding when appropriate */
-        charmap.platform_id = 7;
+        charmap.platform_id = TT_PLATFORM_ADOBE;
         clazz               = NULL;
 
         switch ( type1->encoding_type )
         }
 
         if ( clazz )
-          FT_CMap_New( clazz, NULL, &charmap, NULL );
+          error = FT_CMap_New( clazz, NULL, &charmap, NULL );
 
 #if 0
         /* Select default charmap */