ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cidobjs.c
Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  cidobjs.c                                                              */
00004 /*                                                                         */
00005 /*    CID objects manager (body).                                          */
00006 /*                                                                         */
00007 /*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008, 2010 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 <ft2build.h>
00020 #include FT_INTERNAL_DEBUG_H
00021 #include FT_INTERNAL_STREAM_H
00022 
00023 #include "cidgload.h"
00024 #include "cidload.h"
00025 
00026 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
00027 #include FT_INTERNAL_POSTSCRIPT_AUX_H
00028 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
00029 
00030 #include "ciderrs.h"
00031 
00032 
00033   /*************************************************************************/
00034   /*                                                                       */
00035   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
00036   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
00037   /* messages during execution.                                            */
00038   /*                                                                       */
00039 #undef  FT_COMPONENT
00040 #define FT_COMPONENT  trace_cidobjs
00041 
00042 
00043   /*************************************************************************/
00044   /*                                                                       */
00045   /*                            SLOT  FUNCTIONS                            */
00046   /*                                                                       */
00047   /*************************************************************************/
00048 
00049   FT_LOCAL_DEF( void )
00050   cid_slot_done( FT_GlyphSlot  slot )
00051   {
00052     slot->internal->glyph_hints = 0;
00053   }
00054 
00055 
00056   FT_LOCAL_DEF( FT_Error )
00057   cid_slot_init( FT_GlyphSlot  slot )
00058   {
00059     CID_Face          face;
00060     PSHinter_Service  pshinter;
00061 
00062 
00063     face     = (CID_Face)slot->face;
00064     pshinter = (PSHinter_Service)face->pshinter;
00065 
00066     if ( pshinter )
00067     {
00068       FT_Module  module;
00069 
00070 
00071       module = FT_Get_Module( slot->face->driver->root.library,
00072                               "pshinter" );
00073       if ( module )
00074       {
00075         T1_Hints_Funcs  funcs;
00076 
00077 
00078         funcs = pshinter->get_t1_funcs( module );
00079         slot->internal->glyph_hints = (void*)funcs;
00080       }
00081     }
00082 
00083     return 0;
00084   }
00085 
00086 
00087   /*************************************************************************/
00088   /*                                                                       */
00089   /*                           SIZE  FUNCTIONS                             */
00090   /*                                                                       */
00091   /*************************************************************************/
00092 
00093 
00094   static PSH_Globals_Funcs
00095   cid_size_get_globals_funcs( CID_Size  size )
00096   {
00097     CID_Face          face     = (CID_Face)size->root.face;
00098     PSHinter_Service  pshinter = (PSHinter_Service)face->pshinter;
00099     FT_Module         module;
00100 
00101 
00102     module = FT_Get_Module( size->root.face->driver->root.library,
00103                             "pshinter" );
00104     return ( module && pshinter && pshinter->get_globals_funcs )
00105            ? pshinter->get_globals_funcs( module )
00106            : 0;
00107   }
00108 
00109 
00110   FT_LOCAL_DEF( void )
00111   cid_size_done( FT_Size  cidsize )         /* CID_Size */
00112   {
00113     CID_Size  size = (CID_Size)cidsize;
00114 
00115 
00116     if ( cidsize->internal )
00117     {
00118       PSH_Globals_Funcs  funcs;
00119 
00120 
00121       funcs = cid_size_get_globals_funcs( size );
00122       if ( funcs )
00123         funcs->destroy( (PSH_Globals)cidsize->internal );
00124 
00125       cidsize->internal = 0;
00126     }
00127   }
00128 
00129 
00130   FT_LOCAL_DEF( FT_Error )
00131   cid_size_init( FT_Size  cidsize )     /* CID_Size */
00132   {
00133     CID_Size           size  = (CID_Size)cidsize;
00134     FT_Error           error = CID_Err_Ok;
00135     PSH_Globals_Funcs  funcs = cid_size_get_globals_funcs( size );
00136 
00137 
00138     if ( funcs )
00139     {
00140       PSH_Globals   globals;
00141       CID_Face      face = (CID_Face)cidsize->face;
00142       CID_FaceDict  dict = face->cid.font_dicts + face->root.face_index;
00143       PS_Private    priv = &dict->private_dict;
00144 
00145 
00146       error = funcs->create( cidsize->face->memory, priv, &globals );
00147       if ( !error )
00148         cidsize->internal = (FT_Size_Internal)(void*)globals;
00149     }
00150 
00151     return error;
00152   }
00153 
00154 
00155   FT_LOCAL( FT_Error )
00156   cid_size_request( FT_Size          size,
00157                     FT_Size_Request  req )
00158   {
00159     PSH_Globals_Funcs  funcs;
00160 
00161 
00162     FT_Request_Metrics( size->face, req );
00163 
00164     funcs = cid_size_get_globals_funcs( (CID_Size)size );
00165 
00166     if ( funcs )
00167       funcs->set_scale( (PSH_Globals)size->internal,
00168                         size->metrics.x_scale,
00169                         size->metrics.y_scale,
00170                         0, 0 );
00171 
00172     return CID_Err_Ok;
00173   }
00174 
00175 
00176   /*************************************************************************/
00177   /*                                                                       */
00178   /*                           FACE  FUNCTIONS                             */
00179   /*                                                                       */
00180   /*************************************************************************/
00181 
00182   /*************************************************************************/
00183   /*                                                                       */
00184   /* <Function>                                                            */
00185   /*    cid_face_done                                                      */
00186   /*                                                                       */
00187   /* <Description>                                                         */
00188   /*    Finalizes a given face object.                                     */
00189   /*                                                                       */
00190   /* <Input>                                                               */
00191   /*    face :: A pointer to the face object to destroy.                   */
00192   /*                                                                       */
00193   FT_LOCAL_DEF( void )
00194   cid_face_done( FT_Face  cidface )         /* CID_Face */
00195   {
00196     CID_Face      face = (CID_Face)cidface;
00197     FT_Memory     memory;
00198     CID_FaceInfo  cid;
00199     PS_FontInfo   info;
00200 
00201 
00202     if ( !face )
00203       return;
00204 
00205     cid    = &face->cid;
00206     info   = &cid->font_info;
00207     memory = cidface->memory;
00208 
00209     /* release subrs */
00210     if ( face->subrs )
00211     {
00212       FT_Int  n;
00213 
00214 
00215       for ( n = 0; n < cid->num_dicts; n++ )
00216       {
00217         CID_Subrs  subr = face->subrs + n;
00218 
00219 
00220         if ( subr->code )
00221         {
00222           FT_FREE( subr->code[0] );
00223           FT_FREE( subr->code );
00224         }
00225       }
00226 
00227       FT_FREE( face->subrs );
00228     }
00229 
00230     /* release FontInfo strings */
00231     FT_FREE( info->version );
00232     FT_FREE( info->notice );
00233     FT_FREE( info->full_name );
00234     FT_FREE( info->family_name );
00235     FT_FREE( info->weight );
00236 
00237     /* release font dictionaries */
00238     FT_FREE( cid->font_dicts );
00239     cid->num_dicts = 0;
00240 
00241     /* release other strings */
00242     FT_FREE( cid->cid_font_name );
00243     FT_FREE( cid->registry );
00244     FT_FREE( cid->ordering );
00245 
00246     cidface->family_name = 0;
00247     cidface->style_name  = 0;
00248 
00249     FT_FREE( face->binary_data );
00250     FT_FREE( face->cid_stream );
00251   }
00252 
00253 
00254   /*************************************************************************/
00255   /*                                                                       */
00256   /* <Function>                                                            */
00257   /*    cid_face_init                                                      */
00258   /*                                                                       */
00259   /* <Description>                                                         */
00260   /*    Initializes a given CID face object.                               */
00261   /*                                                                       */
00262   /* <Input>                                                               */
00263   /*    stream     :: The source font stream.                              */
00264   /*                                                                       */
00265   /*    face_index :: The index of the font face in the resource.          */
00266   /*                                                                       */
00267   /*    num_params :: Number of additional generic parameters.  Ignored.   */
00268   /*                                                                       */
00269   /*    params     :: Additional generic parameters.  Ignored.             */
00270   /*                                                                       */
00271   /* <InOut>                                                               */
00272   /*    face       :: The newly built face object.                         */
00273   /*                                                                       */
00274   /* <Return>                                                              */
00275   /*    FreeType error code.  0 means success.                             */
00276   /*                                                                       */
00277   FT_LOCAL_DEF( FT_Error )
00278   cid_face_init( FT_Stream      stream,
00279                  FT_Face        cidface,        /* CID_Face */
00280                  FT_Int         face_index,
00281                  FT_Int         num_params,
00282                  FT_Parameter*  params )
00283   {
00284     CID_Face          face = (CID_Face)cidface;
00285     FT_Error          error;
00286     PSAux_Service     psaux;
00287     PSHinter_Service  pshinter;
00288 
00289     FT_UNUSED( num_params );
00290     FT_UNUSED( params );
00291     FT_UNUSED( stream );
00292 
00293 
00294     cidface->num_faces = 1;
00295 
00296     psaux = (PSAux_Service)face->psaux;
00297     if ( !psaux )
00298     {
00299       psaux = (PSAux_Service)FT_Get_Module_Interface(
00300                 FT_FACE_LIBRARY( face ), "psaux" );
00301 
00302       face->psaux = psaux;
00303     }
00304 
00305     pshinter = (PSHinter_Service)face->pshinter;
00306     if ( !pshinter )
00307     {
00308       pshinter = (PSHinter_Service)FT_Get_Module_Interface(
00309                    FT_FACE_LIBRARY( face ), "pshinter" );
00310 
00311       face->pshinter = pshinter;
00312     }
00313 
00314     /* open the tokenizer; this will also check the font format */
00315     if ( FT_STREAM_SEEK( 0 ) )
00316       goto Exit;
00317 
00318     error = cid_face_open( face, face_index );
00319     if ( error )
00320       goto Exit;
00321 
00322     /* if we just wanted to check the format, leave successfully now */
00323     if ( face_index < 0 )
00324       goto Exit;
00325 
00326     /* check the face index */
00327     /* XXX: handle CID fonts with more than a single face */
00328     if ( face_index != 0 )
00329     {
00330       FT_ERROR(( "cid_face_init: invalid face index\n" ));
00331       error = CID_Err_Invalid_Argument;
00332       goto Exit;
00333     }
00334 
00335     /* now load the font program into the face object */
00336 
00337     /* initialize the face object fields */
00338 
00339     /* set up root face fields */
00340     {
00341       CID_FaceInfo  cid  = &face->cid;
00342       PS_FontInfo   info = &cid->font_info;
00343 
00344 
00345       cidface->num_glyphs   = cid->cid_count;
00346       cidface->num_charmaps = 0;
00347 
00348       cidface->face_index = face_index;
00349       cidface->face_flags = FT_FACE_FLAG_SCALABLE   | /* scalable outlines */
00350                             FT_FACE_FLAG_HORIZONTAL | /* horizontal data   */
00351                             FT_FACE_FLAG_HINTER;      /* has native hinter */
00352 
00353       if ( info->is_fixed_pitch )
00354         cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
00355 
00356       /* XXX: TODO: add kerning with .afm support */
00357 
00358       /* get style name -- be careful, some broken fonts only */
00359       /* have a /FontName dictionary entry!                   */
00360       cidface->family_name = info->family_name;
00361       /* assume "Regular" style if we don't know better */
00362       cidface->style_name = (char *)"Regular";
00363       if ( cidface->family_name )
00364       {
00365         char*  full   = info->full_name;
00366         char*  family = cidface->family_name;
00367 
00368 
00369         if ( full )
00370         {
00371           while ( *full )
00372           {
00373             if ( *full == *family )
00374             {
00375               family++;
00376               full++;
00377             }
00378             else
00379             {
00380               if ( *full == ' ' || *full == '-' )
00381                 full++;
00382               else if ( *family == ' ' || *family == '-' )
00383                 family++;
00384               else
00385               {
00386                 if ( !*family )
00387                   cidface->style_name = full;
00388                 break;
00389               }
00390             }
00391           }
00392         }
00393       }
00394       else
00395       {
00396         /* do we have a `/FontName'? */
00397         if ( cid->cid_font_name )
00398           cidface->family_name = cid->cid_font_name;
00399       }
00400 
00401       /* compute style flags */
00402       cidface->style_flags = 0;
00403       if ( info->italic_angle )
00404         cidface->style_flags |= FT_STYLE_FLAG_ITALIC;
00405       if ( info->weight )
00406       {
00407         if ( !ft_strcmp( info->weight, "Bold"  ) ||
00408              !ft_strcmp( info->weight, "Black" ) )
00409           cidface->style_flags |= FT_STYLE_FLAG_BOLD;
00410       }
00411 
00412       /* no embedded bitmap support */
00413       cidface->num_fixed_sizes = 0;
00414       cidface->available_sizes = 0;
00415 
00416       cidface->bbox.xMin =   cid->font_bbox.xMin            >> 16;
00417       cidface->bbox.yMin =   cid->font_bbox.yMin            >> 16;
00418       /* no `U' suffix here to 0xFFFF! */
00419       cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFF ) >> 16;
00420       cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFF ) >> 16;
00421 
00422       if ( !cidface->units_per_EM )
00423         cidface->units_per_EM = 1000;
00424 
00425       cidface->ascender  = (FT_Short)( cidface->bbox.yMax );
00426       cidface->descender = (FT_Short)( cidface->bbox.yMin );
00427 
00428       cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 );
00429       if ( cidface->height < cidface->ascender - cidface->descender )
00430         cidface->height = (FT_Short)( cidface->ascender - cidface->descender );
00431 
00432       cidface->underline_position  = (FT_Short)info->underline_position;
00433       cidface->underline_thickness = (FT_Short)info->underline_thickness;
00434     }
00435 
00436   Exit:
00437     return error;
00438   }
00439 
00440 
00441   /*************************************************************************/
00442   /*                                                                       */
00443   /* <Function>                                                            */
00444   /*    cid_driver_init                                                    */
00445   /*                                                                       */
00446   /* <Description>                                                         */
00447   /*    Initializes a given CID driver object.                             */
00448   /*                                                                       */
00449   /* <Input>                                                               */
00450   /*    driver :: A handle to the target driver object.                    */
00451   /*                                                                       */
00452   /* <Return>                                                              */
00453   /*    FreeType error code.  0 means success.                             */
00454   /*                                                                       */
00455   FT_LOCAL_DEF( FT_Error )
00456   cid_driver_init( FT_Module  driver )
00457   {
00458     FT_UNUSED( driver );
00459 
00460     return CID_Err_Ok;
00461   }
00462 
00463 
00464   /*************************************************************************/
00465   /*                                                                       */
00466   /* <Function>                                                            */
00467   /*    cid_driver_done                                                    */
00468   /*                                                                       */
00469   /* <Description>                                                         */
00470   /*    Finalizes a given CID driver.                                      */
00471   /*                                                                       */
00472   /* <Input>                                                               */
00473   /*    driver :: A handle to the target CID driver.                       */
00474   /*                                                                       */
00475   FT_LOCAL_DEF( void )
00476   cid_driver_done( FT_Module  driver )
00477   {
00478     FT_UNUSED( driver );
00479   }
00480 
00481 
00482 /* END */

Generated on Sun May 27 2012 04:33:50 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.