ftglue.h revision 2c393a42
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 "fcint.h" 47 48#include <ft2build.h> 49#include FT_FREETYPE_H 50 51FT_BEGIN_HEADER 52 53 54/* utility macros */ 55#define TT_Err_Ok FT_Err_Ok 56#define TT_Err_Invalid_Argument FT_Err_Invalid_Argument 57#define TT_Err_Invalid_Face_Handle FT_Err_Invalid_Face_Handle 58#define TT_Err_Table_Missing FT_Err_Table_Missing 59 60#define SET_ERR(c) ( (error = (c)) != 0 ) 61 62#ifndef FTGLUE_API 63#define FTGLUE_API(x) extern FcPrivate x 64#endif 65 66#ifndef FTGLUE_APIDEF 67#define FTGLUE_APIDEF(x) x 68#endif 69 70/* stream macros used by the OpenType parser */ 71#define FILE_Pos() ftglue_stream_pos( stream ) 72#define FILE_Seek(pos) SET_ERR( ftglue_stream_seek( stream, pos ) ) 73#define ACCESS_Frame(size) SET_ERR( ftglue_stream_frame_enter( stream, size ) ) 74#define FORGET_Frame() ftglue_stream_frame_exit( stream ) 75 76#define GET_Byte() (*stream->cursor++) 77#define GET_Short() (stream->cursor += 2, (FT_Short)( \ 78 (*(((FT_Byte*)stream->cursor)-2) << 8) | \ 79 *(((FT_Byte*)stream->cursor)-1) \ 80 )) 81#define GET_Long() (stream->cursor += 4, (FT_Long)( \ 82 (*(((FT_Byte*)stream->cursor)-4) << 24) | \ 83 (*(((FT_Byte*)stream->cursor)-3) << 16) | \ 84 (*(((FT_Byte*)stream->cursor)-2) << 8) | \ 85 *(((FT_Byte*)stream->cursor)-1) \ 86 )) 87 88#define GET_Char() ((FT_Char)GET_Byte()) 89#define GET_UShort() ((FT_UShort)GET_Short()) 90#define GET_ULong() ((FT_ULong)GET_Long()) 91#define GET_Tag4() GET_ULong() 92 93#define FT_SET_ERROR( expression ) \ 94 ( ( error = (expression) ) != 0 ) 95 96FTGLUE_API( FT_Long ) 97ftglue_stream_pos( FT_Stream stream ); 98 99FTGLUE_API( FT_Error ) 100ftglue_stream_seek( FT_Stream stream, 101 FT_Long pos ); 102 103FTGLUE_API( FT_Error ) 104ftglue_stream_frame_enter( FT_Stream stream, 105 FT_ULong size ); 106 107FTGLUE_API( void ) 108ftglue_stream_frame_exit( FT_Stream stream ); 109 110FTGLUE_API( FT_Byte ) 111ftglue_stream_get_byte( FT_Stream stream ); 112 113FTGLUE_API( FT_Short ) 114ftglue_stream_get_short( FT_Stream stream ); 115 116FTGLUE_API( FT_Long ) 117ftglue_stream_get_long( FT_Stream stream ); 118 119FTGLUE_API( FT_Error ) 120ftglue_face_goto_table( FT_Face face, 121 FT_ULong tag, 122 FT_Stream stream ); 123 124FTGLUE_API( FT_Pointer ) 125ftglue_alloc( FT_Memory memory, 126 FT_ULong size, 127 FT_Error *perror_ ); 128 129FTGLUE_API( FT_Pointer ) 130ftglue_realloc( FT_Memory memory, 131 FT_Pointer block, 132 FT_ULong old_size, 133 FT_ULong new_size, 134 FT_Error *perror_ ); 135 136FTGLUE_API( void ) 137ftglue_free( FT_Memory memory, 138 FT_Pointer block ); 139 140/* */ 141 142FT_END_HEADER 143 144#endif /* __OPENTYPE_FTGLUE_H__ */ 145