1 /***************************************************************************/ 2 /* */ 3 /* ftspic.c */ 4 /* */ 5 /* The FreeType position independent code services for smooth module. */ 6 /* */ 7 /* Copyright 2009, 2010 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 "ftspic.h" 23 #include "ftsmerrs.h" 24 25 #ifdef FT_CONFIG_OPTION_PIC 26 27 /* forward declaration of PIC init functions from ftgrays.c */ 28 void 29 FT_Init_Class_ft_grays_raster( FT_Raster_Funcs* funcs ); 30 31 void 32 ft_smooth_renderer_class_pic_free( FT_Library library ) 33 { 34 FT_PIC_Container* pic_container = &library->pic_container; 35 FT_Memory memory = library->memory; 36 37 38 if ( pic_container->smooth ) 39 { 40 SmoothPIC* container = (SmoothPIC*)pic_container->smooth; 41 42 43 if ( --container->ref_count ) 44 return; 45 FT_FREE( container ); 46 pic_container->smooth = NULL; 47 } 48 } 49 50 51 FT_Error 52 ft_smooth_renderer_class_pic_init( FT_Library library ) 53 { 54 FT_PIC_Container* pic_container = &library->pic_container; 55 FT_Error error = Smooth_Err_Ok; 56 SmoothPIC* container; 57 FT_Memory memory = library->memory; 58 59 60 /* since this function also serve smooth_lcd and smooth_lcdv renderers, 61 it implements reference counting */ 62 if ( pic_container->smooth ) 63 { 64 ((SmoothPIC*)pic_container->smooth)->ref_count++; 65 return error; 66 } 67 68 /* allocate pointer, clear and set global container pointer */ 69 if ( FT_ALLOC ( container, sizeof ( *container ) ) ) 70 return error; 71 FT_MEM_SET( container, 0, sizeof ( *container ) ); 72 pic_container->smooth = container; 73 container->ref_count = 1; 74 75 /* initialize pointer table - this is how the module usually expects this data */ 76 FT_Init_Class_ft_grays_raster( &container->ft_grays_raster ); 77 /*Exit:*/ 78 if ( error ) 79 ft_smooth_renderer_class_pic_free( library ); 80 return error; 81 } 82 83 /* re-route these init and free functions to the above functions */ 84 FT_Error ft_smooth_lcd_renderer_class_pic_init( FT_Library library ) 85 { 86 return ft_smooth_renderer_class_pic_init( library ); 87 } 88 89 void ft_smooth_lcd_renderer_class_pic_free( FT_Library library ) 90 { 91 ft_smooth_renderer_class_pic_free( library ); 92 } 93 94 FT_Error ft_smooth_lcdv_renderer_class_pic_init( FT_Library library ) 95 { 96 return ft_smooth_renderer_class_pic_init( library ); 97 } 98 99 void ft_smooth_lcdv_renderer_class_pic_free( FT_Library library ) 100 { 101 ft_smooth_renderer_class_pic_free( library ); 102 } 103 104 #endif /* FT_CONFIG_OPTION_PIC */ 105 106 107 /* END */ 108