]>
Commit | Line | Data |
---|---|---|
824c7bf0 PL |
1 | /* ftglue.c: Glue code for compiling the OpenType code from |
2 | * FreeType 1 using only the public API of FreeType 2 | |
3 | * | |
4 | * By David Turner, The FreeType Project (www.freetype.org) | |
5 | * | |
6 | * This code is explicitely put in the public domain | |
7 | * | |
8 | * ========================================================================== | |
9 | * | |
10 | * the OpenType parser codes was originally written as an extension to | |
11 | * FreeType 1.x. As such, its source code was embedded within the library, | |
12 | * and used many internal FreeType functions to deal with memory and | |
13 | * stream i/o. | |
14 | * | |
15 | * When it was 'salvaged' for Pango and Qt, the code was "ported" to FreeType 2, | |
16 | * which basically means that some macro tricks were performed in order to | |
17 | * directly access FT2 _internal_ functions. | |
18 | * | |
19 | * these functions were never part of FT2 public API, and _did_ change between | |
20 | * various releases. This created chaos for many users: when they upgraded the | |
21 | * FreeType library on their system, they couldn't run Gnome anymore since | |
22 | * Pango refused to link. | |
23 | * | |
24 | * Very fortunately, it's possible to completely avoid this problem because | |
25 | * the FT_StreamRec and FT_MemoryRec structure types, which describe how | |
26 | * memory and stream implementations interface with the rest of the font | |
27 | * library, have always been part of the public API, and never changed. | |
28 | * | |
29 | * What we do thus is re-implement, within the OpenType parser, the few | |
30 | * functions that depend on them. This only adds one or two kilobytes of | |
31 | * code, and ensures that the parser can work with _any_ version | |
32 | * of FreeType installed on your system. How sweet... ! | |
33 | * | |
34 | * Note that we assume that Pango doesn't use any other internal functions | |
35 | * from FreeType. It used to in old versions, but this should no longer | |
36 | * be the case. (crossing my fingers). | |
37 | * | |
38 | * - David Turner | |
39 | * - The FreeType Project (www.freetype.org) | |
40 | * | |
41 | * PS: This "glue" code is explicitely put in the public domain | |
42 | */ | |
43 | #ifndef __OPENTYPE_FTGLUE_H__ | |
44 | #define __OPENTYPE_FTGLUE_H__ | |
45 | ||
46 | #include <ft2build.h> | |
47 | #include FT_FREETYPE_H | |
48 | ||
49 | FT_BEGIN_HEADER | |
50 | ||
51 | ||
52 | /* utility macros */ | |
53 | #define TT_Err_Ok FT_Err_Ok | |
54 | #define TT_Err_Invalid_Argument FT_Err_Invalid_Argument | |
55 | #define TT_Err_Invalid_Face_Handle FT_Err_Invalid_Face_Handle | |
56 | #define TT_Err_Table_Missing FT_Err_Table_Missing | |
57 | ||
58 | #define SET_ERR(c) ( (error = (c)) != 0 ) | |
59 | ||
60 | #ifndef FTGLUE_API | |
61 | #define FTGLUE_API(x) extern x | |
62 | #endif | |
63 | ||
64 | #ifndef FTGLUE_APIDEF | |
65 | #define FTGLUE_APIDEF(x) x | |
66 | #endif | |
67 | ||
68 | /* stream macros used by the OpenType parser */ | |
69 | #define FILE_Pos() ftglue_stream_pos( stream ) | |
70 | #define FILE_Seek(pos) SET_ERR( ftglue_stream_seek( stream, pos ) ) | |
71 | #define ACCESS_Frame(size) SET_ERR( ftglue_stream_frame_enter( stream, size ) ) | |
72 | #define FORGET_Frame() ftglue_stream_frame_exit( stream ) | |
73 | ||
74 | #define GET_Byte() ftglue_stream_get_byte( stream ) | |
75 | #define GET_Short() ftglue_stream_get_short( stream ) | |
76 | #define GET_Long() ftglue_stream_get_long( stream ) | |
77 | ||
78 | #define GET_Char() ((FT_Char)GET_Byte()) | |
79 | #define GET_UShort() ((FT_UShort)GET_Short()) | |
80 | #define GET_ULong() ((FT_ULong)GET_Long()) | |
81 | #define GET_Tag4() GET_ULong() | |
82 | ||
83 | #define FT_SET_ERROR( expression ) \ | |
84 | ( ( error = (expression) ) != 0 ) | |
85 | ||
86 | FTGLUE_API( FT_Long ) | |
87 | ftglue_stream_pos( FT_Stream stream ); | |
88 | ||
89 | FTGLUE_API( FT_Error ) | |
90 | ftglue_stream_seek( FT_Stream stream, | |
91 | FT_Long pos ); | |
92 | ||
93 | FTGLUE_API( FT_Error ) | |
94 | ftglue_stream_frame_enter( FT_Stream stream, | |
95 | FT_ULong size ); | |
96 | ||
97 | FTGLUE_API( void ) | |
98 | ftglue_stream_frame_exit( FT_Stream stream ); | |
99 | ||
100 | FTGLUE_API( FT_Byte ) | |
101 | ftglue_stream_get_byte( FT_Stream stream ); | |
102 | ||
103 | FTGLUE_API( FT_Short ) | |
104 | ftglue_stream_get_short( FT_Stream stream ); | |
105 | ||
106 | FTGLUE_API( FT_Long ) | |
107 | ftglue_stream_get_long( FT_Stream stream ); | |
108 | ||
109 | FTGLUE_API( FT_Error ) | |
110 | ftglue_face_goto_table( FT_Face face, | |
111 | FT_ULong tag, | |
112 | FT_Stream stream ); | |
113 | ||
114 | /* memory macros used by the OpenType parser */ | |
115 | #define ALLOC(_ptr,_size) \ | |
116 | ( (_ptr) = ftglue_alloc( memory, _size, &error ), error != 0 ) | |
117 | ||
118 | #define REALLOC(_ptr,_oldsz,_newsz) \ | |
119 | ( (_ptr) = ftglue_realloc( memory, (_ptr), (_oldsz), (_newsz), &error ), error != 0 ) | |
120 | ||
121 | #define FREE(_ptr) \ | |
122 | do { \ | |
123 | if ( (_ptr) ) \ | |
124 | { \ | |
125 | ftglue_free( memory, _ptr ); \ | |
126 | _ptr = NULL; \ | |
127 | } \ | |
128 | } while (0) | |
129 | ||
130 | #define ALLOC_ARRAY(_ptr,_count,_type) \ | |
131 | ALLOC(_ptr,(_count)*sizeof(_type)) | |
132 | ||
133 | #define REALLOC_ARRAY(_ptr,_oldcnt,_newcnt,_type) \ | |
134 | REALLOC(_ptr,(_oldcnt)*sizeof(_type),(_newcnt)*sizeof(_type)) | |
135 | ||
136 | #define MEM_Copy(dest,source,count) memcpy( (char*)(dest), (const char*)(source), (size_t)(count) ) | |
137 | ||
138 | ||
139 | FTGLUE_API( FT_Pointer ) | |
140 | ftglue_alloc( FT_Memory memory, | |
141 | FT_ULong size, | |
142 | FT_Error *perror_ ); | |
143 | ||
144 | FTGLUE_API( FT_Pointer ) | |
145 | ftglue_realloc( FT_Memory memory, | |
146 | FT_Pointer block, | |
147 | FT_ULong old_size, | |
148 | FT_ULong new_size, | |
149 | FT_Error *perror_ ); | |
150 | ||
151 | FTGLUE_API( void ) | |
152 | ftglue_free( FT_Memory memory, | |
153 | FT_Pointer block ); | |
154 | ||
155 | /* */ | |
156 | ||
157 | FT_END_HEADER | |
158 | ||
159 | #endif /* __OPENTYPE_FTGLUE_H__ */ |