Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentest_afm.c
Go to the documentation of this file.
00001 /* 00002 * gcc -DFT2_BUILD_LIBRARY -I../../include -o test_afm test_afm.c \ 00003 * -L../../objs/.libs -lfreetype -lz -static 00004 */ 00005 #include <ft2build.h> 00006 #include FT_FREETYPE_H 00007 #include FT_INTERNAL_STREAM_H 00008 #include FT_INTERNAL_POSTSCRIPT_AUX_H 00009 00010 void dump_fontinfo( AFM_FontInfo fi ) 00011 { 00012 FT_Int i; 00013 00014 00015 printf( "This AFM is for %sCID font.\n\n", 00016 ( fi->IsCIDFont ) ? "" : "non-" ); 00017 00018 printf( "FontBBox: %.2f %.2f %.2f %.2f\n", fi->FontBBox.xMin / 65536., 00019 fi->FontBBox.yMin / 65536., 00020 fi->FontBBox.xMax / 65536., 00021 fi->FontBBox.yMax / 65536. ); 00022 printf( "Ascender: %.2f\n", fi->Ascender / 65536. ); 00023 printf( "Descender: %.2f\n\n", fi->Descender / 65536. ); 00024 00025 if ( fi->NumTrackKern ) 00026 printf( "There are %d sets of track kernings:\n", 00027 fi->NumTrackKern ); 00028 else 00029 printf( "There is no track kerning.\n" ); 00030 00031 for ( i = 0; i < fi->NumTrackKern; i++ ) 00032 { 00033 AFM_TrackKern tk = fi->TrackKerns + i; 00034 00035 00036 printf( "\t%2d: %5.2f %5.2f %5.2f %5.2f\n", tk->degree, 00037 tk->min_ptsize / 65536., 00038 tk->min_kern / 65536., 00039 tk->max_ptsize / 65536., 00040 tk->max_kern / 65536. ); 00041 } 00042 00043 printf( "\n" ); 00044 00045 if ( fi->NumKernPair ) 00046 printf( "There are %d kerning pairs:\n", 00047 fi->NumKernPair ); 00048 else 00049 printf( "There is no kerning pair.\n" ); 00050 00051 for ( i = 0; i < fi->NumKernPair; i++ ) 00052 { 00053 AFM_KernPair kp = fi->KernPairs + i; 00054 00055 00056 printf( "\t%3d + %3d => (%4d, %4d)\n", kp->index1, 00057 kp->index2, 00058 kp->x, 00059 kp->y ); 00060 } 00061 00062 } 00063 00064 int 00065 dummy_get_index( const char* name, 00066 FT_Offset len, 00067 void* user_data ) 00068 { 00069 if ( len ) 00070 return name[0]; 00071 else 00072 return 0; 00073 } 00074 00075 FT_Error 00076 parse_afm( FT_Library library, 00077 FT_Stream stream, 00078 AFM_FontInfo fi ) 00079 { 00080 PSAux_Service psaux; 00081 AFM_ParserRec parser; 00082 FT_Error error = FT_Err_Ok; 00083 00084 00085 psaux = (PSAux_Service)FT_Get_Module_Interface( library, "psaux" ); 00086 if ( !psaux || !psaux->afm_parser_funcs ) 00087 return -1; 00088 00089 error = FT_Stream_EnterFrame( stream, stream->size ); 00090 if ( error ) 00091 return error; 00092 00093 error = psaux->afm_parser_funcs->init( &parser, 00094 library->memory, 00095 stream->cursor, 00096 stream->limit ); 00097 if ( error ) 00098 return error; 00099 00100 parser.FontInfo = fi; 00101 parser.get_index = dummy_get_index; 00102 00103 error = psaux->afm_parser_funcs->parse( &parser ); 00104 00105 psaux->afm_parser_funcs->done( &parser ); 00106 00107 return error; 00108 } 00109 00110 00111 int main( int argc, 00112 char** argv ) 00113 { 00114 FT_Library library; 00115 FT_StreamRec stream; 00116 FT_Error error = FT_Err_Ok; 00117 AFM_FontInfoRec fi; 00118 00119 00120 if ( argc < 2 ) 00121 return FT_Err_Invalid_Argument; 00122 00123 error = FT_Init_FreeType( &library ); 00124 if ( error ) 00125 return error; 00126 00127 FT_ZERO( &stream ); 00128 error = FT_Stream_Open( &stream, argv[1] ); 00129 if ( error ) 00130 goto Exit; 00131 stream.memory = library->memory; 00132 00133 FT_ZERO( &fi ); 00134 error = parse_afm( library, &stream, &fi ); 00135 00136 if ( !error ) 00137 { 00138 FT_Memory memory = library->memory; 00139 00140 00141 dump_fontinfo( &fi ); 00142 00143 if ( fi.KernPairs ) 00144 FT_FREE( fi.KernPairs ); 00145 if ( fi.TrackKerns ) 00146 FT_FREE( fi.TrackKerns ); 00147 } 00148 else 00149 printf( "parse error\n" ); 00150 00151 FT_Stream_Close( &stream ); 00152 00153 Exit: 00154 FT_Done_FreeType( library ); 00155 00156 return error; 00157 } Generated on Sat May 26 2012 04:32:57 for ReactOS by
1.7.6.1
|