pfrcmap.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  pfrcmap.c                                                              */
00004 /*                                                                         */
00005 /*    FreeType PFR cmap handling (body).                                   */
00006 /*                                                                         */
00007 /*  Copyright 2002, 2007, 2009 by                                          */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #include "pfrcmap.h"
00020 #include "pfrobjs.h"
00021 
00022 #include "pfrerror.h"
00023 
00024 
00025   FT_CALLBACK_DEF( FT_Error )
00026   pfr_cmap_init( PFR_CMap  cmap )
00027   {
00028     FT_Error  error = PFR_Err_Ok;
00029     PFR_Face  face  = (PFR_Face)FT_CMAP_FACE( cmap );
00030 
00031 
00032     cmap->num_chars = face->phy_font.num_chars;
00033     cmap->chars     = face->phy_font.chars;
00034 
00035     /* just for safety, check that the character entries are correctly */
00036     /* sorted in increasing character code order                       */
00037     {
00038       FT_UInt  n;
00039 
00040 
00041       for ( n = 1; n < cmap->num_chars; n++ )
00042       {
00043         if ( cmap->chars[n - 1].char_code >= cmap->chars[n].char_code )
00044         {
00045           error = PFR_Err_Invalid_Table;
00046           goto Exit;
00047         }
00048       }
00049     }
00050 
00051   Exit:
00052     return error;
00053   }
00054 
00055 
00056   FT_CALLBACK_DEF( void )
00057   pfr_cmap_done( PFR_CMap  cmap )
00058   {
00059     cmap->chars     = NULL;
00060     cmap->num_chars = 0;
00061   }
00062 
00063 
00064   FT_CALLBACK_DEF( FT_UInt )
00065   pfr_cmap_char_index( PFR_CMap   cmap,
00066                        FT_UInt32  char_code )
00067   {
00068     FT_UInt   min = 0;
00069     FT_UInt   max = cmap->num_chars;
00070     FT_UInt   mid;
00071     PFR_Char  gchar;
00072 
00073 
00074     while ( min < max )
00075     {
00076       mid   = min + ( max - min ) / 2;
00077       gchar = cmap->chars + mid;
00078 
00079       if ( gchar->char_code == char_code )
00080         return mid + 1;
00081 
00082       if ( gchar->char_code < char_code )
00083         min = mid + 1;
00084       else
00085         max = mid;
00086     }
00087     return 0;
00088   }
00089 
00090 
00091   FT_CALLBACK_DEF( FT_UInt32 )
00092   pfr_cmap_char_next( PFR_CMap    cmap,
00093                       FT_UInt32  *pchar_code )
00094   {
00095     FT_UInt    result    = 0;
00096     FT_UInt32  char_code = *pchar_code + 1;
00097 
00098 
00099   Restart:
00100     {
00101       FT_UInt   min = 0;
00102       FT_UInt   max = cmap->num_chars;
00103       FT_UInt   mid;
00104       PFR_Char  gchar;
00105 
00106 
00107       while ( min < max )
00108       {
00109         mid   = min + ( ( max - min ) >> 1 );
00110         gchar = cmap->chars + mid;
00111 
00112         if ( gchar->char_code == char_code )
00113         {
00114           result = mid;
00115           if ( result != 0 )
00116           {
00117             result++;
00118             goto Exit;
00119           }
00120 
00121           char_code++;
00122           goto Restart;
00123         }
00124 
00125         if ( gchar->char_code < char_code )
00126           min = mid+1;
00127         else
00128           max = mid;
00129       }
00130 
00131       /* we didn't find it, but we have a pair just above it */
00132       char_code = 0;
00133 
00134       if ( min < cmap->num_chars )
00135       {
00136         gchar  = cmap->chars + min;
00137         result = min;
00138         if ( result != 0 )
00139         {
00140           result++;
00141           char_code = gchar->char_code;
00142         }
00143       }
00144     }
00145 
00146   Exit:
00147     *pchar_code = char_code;
00148     return result;
00149   }
00150 
00151 
00152   FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
00153   pfr_cmap_class_rec =
00154   {
00155     sizeof ( PFR_CMapRec ),
00156 
00157     (FT_CMap_InitFunc)     pfr_cmap_init,
00158     (FT_CMap_DoneFunc)     pfr_cmap_done,
00159     (FT_CMap_CharIndexFunc)pfr_cmap_char_index,
00160     (FT_CMap_CharNextFunc) pfr_cmap_char_next,
00161 
00162     NULL, NULL, NULL, NULL, NULL
00163   };
00164 
00165 
00166 /* END */

Generated on Tue Jul 5 14:13:49 2011 for ROOT_528-00b_version by  doxygen 1.5.1