zenilib: zenilib/jni/external/freetype2/src/tools/test_afm.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
10 void dump_fontinfo( AFM_FontInfo fi )
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
76 parse_afm( FT_Library library,
77 FT_Stream stream,
78 AFM_FontInfo fi )
79 {
80 PSAux_Service psaux;
81 AFM_ParserRec parser;
82 FT_Error error = FT_Err_Ok;
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 {
114 FT_Library library;
115 FT_StreamRec stream;
116 FT_Error error = FT_Err_Ok;
117 AFM_FontInfoRec fi;
118
119
120 if ( argc < 2 )
121 return FT_Err_Invalid_Argument;
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 }
AFM_ParserRec_
Definition: psaux.h:749
AFM_TrackKernRec_
Definition: t1types.h:148
FT_Error
int FT_Error
Definition: fttypes.h:296
AFM_FontInfoRec_::IsCIDFont
FT_Bool IsCIDFont
Definition: t1types.h:169
FT_Stream_EnterFrame
FT_Stream_EnterFrame(FT_Stream stream, FT_ULong count)
Definition: ftstream.c:234
FT_StreamRec_::size
unsigned long size
Definition: ftsystem.h:324
PSAux_ServiceRec_::afm_parser_funcs
const AFM_Parser_FuncsRec * afm_parser_funcs
Definition: psaux.h:810
AFM_TrackKernRec_::max_ptsize
FT_Fixed max_ptsize
Definition: t1types.h:153
main
int main(int argc, char **argv)
Definition: bootstrap.cpp:102
AFM_TrackKernRec_::degree
FT_Int degree
Definition: t1types.h:150
FT_Int
signed int FT_Int
Definition: fttypes.h:216
FT_Err_Invalid_Argument
return FT_Err_Invalid_Argument
Definition: ftbbox.c:584
FT_StreamRec_::cursor
unsigned char * cursor
Definition: ftsystem.h:333
stream
GLuint GLuint stream
Definition: glew.h:6573
dummy_get_index
int dummy_get_index(const char *name, FT_Offset len, void *user_data)
Definition: test_afm.c:65
AFM_Parser_FuncsRec_::init
FT_Error(* init)(AFM_Parser parser, FT_Memory memory, FT_Byte *base, FT_Byte *limit)
Definition: psaux.h:713
dump_fontinfo
void dump_fontinfo(AFM_FontInfo fi)
Definition: test_afm.c:10
library
FT_Library library
Definition: cffdrivr.c:409
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
FT_Err_Ok
return FT_Err_Ok
Definition: ftbbox.c:658
AFM_FontInfoRec_::NumTrackKern
FT_Int NumTrackKern
Definition: t1types.h:174
FT_Stream_Close
FT_Stream_Close(FT_Stream stream)
Definition: ftstream.c:49
FT_Done_FreeType
FT_Done_FreeType(FT_Library library)
Definition: ftinit.c:264
len
GLenum GLsizei len
Definition: glew.h:7035
AFM_TrackKernRec_::min_kern
FT_Fixed min_kern
Definition: t1types.h:152
FT_Init_FreeType
FT_Init_FreeType(FT_Library *alibrary)
Definition: ftinit.c:232
parse_afm
FT_Error parse_afm(FT_Library library, FT_Stream stream, AFM_FontInfo fi)
Definition: test_afm.c:76
AFM_KernPairRec_::index2
FT_Int index2
Definition: t1types.h:161
FT_LibraryRec_::memory
FT_Memory memory
Definition: ftobjs.h:826
FT_StreamRec_::memory
FT_Memory memory
Definition: ftsystem.h:332
FT_FREE
#define FT_FREE(ptr)
Definition: ftmemory.h:286
AFM_FontInfoRec_::Descender
FT_Fixed Descender
Definition: t1types.h:172
FT_BBox_::yMax
FT_Pos yMax
Definition: ftimage.h:119
FT_BBox_::xMin
FT_Pos xMin
Definition: ftimage.h:118
AFM_TrackKernRec_::min_ptsize
FT_Fixed min_ptsize
Definition: t1types.h:151
AFM_FontInfoRec_
Definition: t1types.h:167
error
FT_Error error
Definition: cffdrivr.c:407
FT_ZERO
#define FT_ZERO(p)
Definition: ftmemory.h:210
AFM_KernPairRec_
Definition: t1types.h:158
PSAux_Service
struct PSAux_ServiceRec_ * PSAux_Service
AFM_KernPairRec_::x
FT_Int x
Definition: t1types.h:162
AFM_FontInfoRec_::KernPairs
AFM_KernPair KernPairs
Definition: t1types.h:175
FT_BBox_::xMax
FT_Pos xMax
Definition: ftimage.h:119
FT_LibraryRec_
Definition: ftobjs.h:824
FT_Memory
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
AFM_TrackKernRec_::max_kern
FT_Fixed max_kern
Definition: t1types.h:154
AFM_KernPairRec_::y
FT_Int y
Definition: t1types.h:163
AFM_Parser_FuncsRec_::parse
FT_Error(* parse)(AFM_Parser parser)
Definition: psaux.h:722
ft2build.h
AFM_FontInfoRec_::TrackKerns
AFM_TrackKern TrackKerns
Definition: t1types.h:173
AFM_Parser_FuncsRec_::done
void(* done)(AFM_Parser parser)
Definition: psaux.h:719
FT_StreamRec_::limit
unsigned char * limit
Definition: ftsystem.h:334
AFM_KernPairRec_::index1
FT_Int index1
Definition: t1types.h:160
AFM_FontInfoRec_::Ascender
FT_Fixed Ascender
Definition: t1types.h:171
FT_Stream_Open
FT_Stream_Open(FT_Stream stream, const char *filepathname)
Definition: ftsystem.c:224
FT_Get_Module_Interface
FT_Get_Module_Interface(FT_Library library, const char *mod_name)
Definition: ftobjs.c:4284
AFM_FontInfoRec_::FontBBox
FT_BBox FontBBox
Definition: t1types.h:170
i
int i
Definition: pngrutil.c:1377
AFM_ParserRec_::FontInfo
AFM_FontInfo FontInfo
Definition: psaux.h:754
AFM_ParserRec_::get_index
FT_Int(* get_index)(const char *name, FT_Offset len, void *user_data)
Definition: psaux.h:757
FT_StreamRec_
Definition: ftsystem.h:321
FT_BBox_::yMin
FT_Pos yMin
Definition: ftimage.h:118
PSAux_ServiceRec_
Definition: psaux.h:794
AFM_FontInfoRec_::NumKernPair
FT_Int NumKernPair
Definition: t1types.h:176
FT_Offset
size_t FT_Offset
Definition: fttypes.h:320