Home | History | Annotate | Download | only in autofit
      1 /***************************************************************************/
      2 /*                                                                         */
      3 /*  afpic.c                                                                */
      4 /*                                                                         */
      5 /*    The FreeType position independent code services for autofit module.  */
      6 /*                                                                         */
      7 /*  Copyright 2009-2013 by                                                 */
      8 /*  Oran Agra and Mickey Gabel.                                            */
      9 /*                                                                         */
     10 /*  This file is part of the FreeType project, and may only be used,       */
     11 /*  modified, and distributed under the terms of the FreeType project      */
     12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
     13 /*  this file you indicate that you have read the license and              */
     14 /*  understand and accept it fully.                                        */
     15 /*                                                                         */
     16 /***************************************************************************/
     17 
     18 
     19 #include <ft2build.h>
     20 #include FT_FREETYPE_H
     21 #include FT_INTERNAL_OBJECTS_H
     22 #include "afpic.h"
     23 #include "aferrors.h"
     24 
     25 
     26 #ifdef FT_CONFIG_OPTION_PIC
     27 
     28   /* forward declaration of PIC init functions from afmodule.c */
     29   FT_Error
     30   FT_Create_Class_af_services( FT_Library           library,
     31                                FT_ServiceDescRec**  output_class );
     32 
     33   void
     34   FT_Destroy_Class_af_services( FT_Library          library,
     35                                 FT_ServiceDescRec*  clazz );
     36 
     37   void
     38   FT_Init_Class_af_service_properties( FT_Service_PropertiesRec*  clazz );
     39 
     40   void FT_Init_Class_af_autofitter_interface(
     41     FT_Library                   library,
     42     FT_AutoHinter_InterfaceRec*  clazz );
     43 
     44 
     45   /* forward declaration of PIC init functions from script classes */
     46 #include "aflatin.h"
     47 #ifdef FT_OPTION_AUTOFIT2
     48 #include "aflatin2.h"
     49 #endif
     50 #include "afcjk.h"
     51 #include "afdummy.h"
     52 #include "afindic.h"
     53 
     54 
     55   void
     56   autofit_module_class_pic_free( FT_Library  library )
     57   {
     58     FT_PIC_Container*  pic_container = &library->pic_container;
     59     FT_Memory          memory        = library->memory;
     60 
     61 
     62     if ( pic_container->autofit )
     63     {
     64       AFModulePIC*  container = (AFModulePIC*)pic_container->autofit;
     65 
     66 
     67       if ( container->af_services )
     68         FT_Destroy_Class_af_services( library,
     69                                       container->af_services );
     70       container->af_services = NULL;
     71 
     72       FT_FREE( container );
     73       pic_container->autofit = NULL;
     74     }
     75   }
     76 
     77 
     78   FT_Error
     79   autofit_module_class_pic_init( FT_Library  library )
     80   {
     81     FT_PIC_Container*  pic_container = &library->pic_container;
     82     FT_UInt            ss;
     83     FT_Error           error         = FT_Err_Ok;
     84     AFModulePIC*       container     = NULL;
     85     FT_Memory          memory        = library->memory;
     86 
     87 
     88     /* allocate pointer, clear and set global container pointer */
     89     if ( FT_ALLOC ( container, sizeof ( *container ) ) )
     90       return error;
     91     FT_MEM_SET( container, 0, sizeof ( *container ) );
     92     pic_container->autofit = container;
     93 
     94     /* initialize pointer table -                       */
     95     /* this is how the module usually expects this data */
     96     error = FT_Create_Class_af_services( library,
     97                                          &container->af_services );
     98     if ( error )
     99       goto Exit;
    100 
    101     FT_Init_Class_af_service_properties( &container->af_service_properties );
    102 
    103     for ( ss = 0 ; ss < AF_SCRIPT_CLASSES_REC_COUNT ; ss++ )
    104     {
    105       container->af_script_classes[ss] =
    106         &container->af_script_classes_rec[ss];
    107     }
    108     container->af_script_classes[AF_SCRIPT_CLASSES_COUNT - 1] = NULL;
    109 
    110     /* add call to initialization function when you add new scripts */
    111     ss = 0;
    112     FT_Init_Class_af_dummy_script_class(
    113       &container->af_script_classes_rec[ss++] );
    114 #ifdef FT_OPTION_AUTOFIT2
    115     FT_Init_Class_af_latin2_script_class(
    116       &container->af_script_classes_rec[ss++] );
    117 #endif
    118     FT_Init_Class_af_latin_script_class(
    119       &container->af_script_classes_rec[ss++] );
    120     FT_Init_Class_af_cjk_script_class(
    121       &container->af_script_classes_rec[ss++] );
    122     FT_Init_Class_af_indic_script_class(
    123       &container->af_script_classes_rec[ss++] );
    124 
    125     FT_Init_Class_af_autofitter_interface(
    126       library, &container->af_autofitter_interface );
    127 
    128   Exit:
    129     if ( error )
    130       autofit_module_class_pic_free( library );
    131     return error;
    132   }
    133 
    134 #endif /* FT_CONFIG_OPTION_PIC */
    135 
    136 
    137 /* END */
    138