zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
test_afm.c
Go to the documentation of this file.
1 /*
2  * gcc -DFT2_BUILD_LIBRARY -I../../include -o test_afm test_afm.c \
3  * -L../../objs/.libs -lfreetype -lz -static
4  */
5 #include <ft2build.h>
6 #include FT_FREETYPE_H
7 #include FT_INTERNAL_STREAM_H
8 #include FT_INTERNAL_POSTSCRIPT_AUX_H
9 
11  {
12  FT_Int i;
13 
14 
15  printf( "This AFM is for %sCID font.\n\n",
16  ( fi->IsCIDFont ) ? "" : "non-" );
17 
18  printf( "FontBBox: %.2f %.2f %.2f %.2f\n", fi->FontBBox.xMin / 65536.,
19  fi->FontBBox.yMin / 65536.,
20  fi->FontBBox.xMax / 65536.,
21  fi->FontBBox.yMax / 65536. );
22  printf( "Ascender: %.2f\n", fi->Ascender / 65536. );
23  printf( "Descender: %.2f\n\n", fi->Descender / 65536. );
24 
25  if ( fi->NumTrackKern )
26  printf( "There are %d sets of track kernings:\n",
27  fi->NumTrackKern );
28  else
29  printf( "There is no track kerning.\n" );
30 
31  for ( i = 0; i < fi->NumTrackKern; i++ )
32  {
33  AFM_TrackKern tk = fi->TrackKerns + i;
34 
35 
36  printf( "\t%2d: %5.2f %5.2f %5.2f %5.2f\n", tk->degree,
37  tk->min_ptsize / 65536.,
38  tk->min_kern / 65536.,
39  tk->max_ptsize / 65536.,
40  tk->max_kern / 65536. );
41  }
42 
43  printf( "\n" );
44 
45  if ( fi->NumKernPair )
46  printf( "There are %d kerning pairs:\n",
47  fi->NumKernPair );
48  else
49  printf( "There is no kerning pair.\n" );
50 
51  for ( i = 0; i < fi->NumKernPair; i++ )
52  {
53  AFM_KernPair kp = fi->KernPairs + i;
54 
55 
56  printf( "\t%3d + %3d => (%4d, %4d)\n", kp->index1,
57  kp->index2,
58  kp->x,
59  kp->y );
60  }
61 
62  }
63 
64  int
65  dummy_get_index( const char* name,
66  FT_Offset len,
67  void* user_data )
68  {
69  if ( len )
70  return name[0];
71  else
72  return 0;
73  }
74 
75  FT_Error
78  AFM_FontInfo fi )
79  {
80  PSAux_Service psaux;
81  AFM_ParserRec parser;
83 
84 
85  psaux = (PSAux_Service)FT_Get_Module_Interface( library, "psaux" );
86  if ( !psaux || !psaux->afm_parser_funcs )
87  return -1;
88 
89  error = FT_Stream_EnterFrame( stream, stream->size );
90  if ( error )
91  return error;
92 
93  error = psaux->afm_parser_funcs->init( &parser,
94  library->memory,
95  stream->cursor,
96  stream->limit );
97  if ( error )
98  return error;
99 
100  parser.FontInfo = fi;
101  parser.get_index = dummy_get_index;
102 
103  error = psaux->afm_parser_funcs->parse( &parser );
104 
105  psaux->afm_parser_funcs->done( &parser );
106 
107  return error;
108  }
109 
110 
111  int main( int argc,
112  char** argv )
113  {
117  AFM_FontInfoRec fi;
118 
119 
120  if ( argc < 2 )
122 
123  error = FT_Init_FreeType( &library );
124  if ( error )
125  return error;
126 
127  FT_ZERO( &stream );
128  error = FT_Stream_Open( &stream, argv[1] );
129  if ( error )
130  goto Exit;
131  stream.memory = library->memory;
132 
133  FT_ZERO( &fi );
134  error = parse_afm( library, &stream, &fi );
135 
136  if ( !error )
137  {
138  FT_Memory memory = library->memory;
139 
140 
141  dump_fontinfo( &fi );
142 
143  if ( fi.KernPairs )
144  FT_FREE( fi.KernPairs );
145  if ( fi.TrackKerns )
146  FT_FREE( fi.TrackKerns );
147  }
148  else
149  printf( "parse error\n" );
150 
151  FT_Stream_Close( &stream );
152 
153  Exit:
154  FT_Done_FreeType( library );
155 
156  return error;
157  }
int FT_Error
Definition: fttypes.h:296
FT_Bool IsCIDFont
Definition: t1types.h:169
FT_Stream_EnterFrame(FT_Stream stream, FT_ULong count)
Definition: ftstream.c:234
unsigned long size
Definition: ftsystem.h:324
const AFM_Parser_FuncsRec * afm_parser_funcs
Definition: psaux.h:810
FT_Fixed max_ptsize
Definition: t1types.h:153
int main(int argc, char **argv)
Definition: bootstrap.cpp:102
signed int FT_Int
Definition: fttypes.h:216
return FT_Err_Invalid_Argument
Definition: ftbbox.c:584
unsigned char * cursor
Definition: ftsystem.h:333
GLuint GLuint stream
Definition: glew.h:6573
int dummy_get_index(const char *name, FT_Offset len, void *user_data)
Definition: test_afm.c:65
FT_Error(* init)(AFM_Parser parser, FT_Memory memory, FT_Byte *base, FT_Byte *limit)
Definition: psaux.h:713
void dump_fontinfo(AFM_FontInfo fi)
Definition: test_afm.c:10
FT_Library library
Definition: cffdrivr.c:409
EGLImageKHR EGLint * name
Definition: eglext.h:284
return FT_Err_Ok
Definition: ftbbox.c:658
FT_Int NumTrackKern
Definition: t1types.h:174
FT_Stream_Close(FT_Stream stream)
Definition: ftstream.c:49
FT_Done_FreeType(FT_Library library)
Definition: ftinit.c:264
GLenum GLsizei len
Definition: glew.h:7035
FT_Fixed min_kern
Definition: t1types.h:152
FT_Init_FreeType(FT_Library *alibrary)
Definition: ftinit.c:232
FT_Error parse_afm(FT_Library library, FT_Stream stream, AFM_FontInfo fi)
Definition: test_afm.c:76
FT_Int index2
Definition: t1types.h:161
FT_Memory memory
Definition: ftobjs.h:826
FT_Memory memory
Definition: ftsystem.h:332
#define FT_FREE(ptr)
Definition: ftmemory.h:286
FT_Fixed Descender
Definition: t1types.h:172
FT_Pos yMax
Definition: ftimage.h:119
FT_Pos xMin
Definition: ftimage.h:118
FT_Fixed min_ptsize
Definition: t1types.h:151
FT_Error error
Definition: cffdrivr.c:407
#define FT_ZERO(p)
Definition: ftmemory.h:210
struct PSAux_ServiceRec_ * PSAux_Service
AFM_KernPair KernPairs
Definition: t1types.h:175
FT_Pos xMax
Definition: ftimage.h:119
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
FT_Fixed max_kern
Definition: t1types.h:154
FT_Error(* parse)(AFM_Parser parser)
Definition: psaux.h:722
AFM_TrackKern TrackKerns
Definition: t1types.h:173
void(* done)(AFM_Parser parser)
Definition: psaux.h:719
unsigned char * limit
Definition: ftsystem.h:334
FT_Int index1
Definition: t1types.h:160
FT_Fixed Ascender
Definition: t1types.h:171
FT_Stream_Open(FT_Stream stream, const char *filepathname)
Definition: ftsystem.c:224
FT_Get_Module_Interface(FT_Library library, const char *mod_name)
Definition: ftobjs.c:4284
FT_BBox FontBBox
Definition: t1types.h:170
int i
Definition: pngrutil.c:1377
AFM_FontInfo FontInfo
Definition: psaux.h:754
FT_Int(* get_index)(const char *name, FT_Offset len, void *user_data)
Definition: psaux.h:757
FT_Pos yMin
Definition: ftimage.h:118
FT_Int NumKernPair
Definition: t1types.h:176
size_t FT_Offset
Definition: fttypes.h:320