ftglue.h revision 2c393a42
12c393a42Smrg/* ftglue.c: Glue code for compiling the OpenType code from 22c393a42Smrg * FreeType 1 using only the public API of FreeType 2 32c393a42Smrg * 42c393a42Smrg * By David Turner, The FreeType Project (www.freetype.org) 52c393a42Smrg * 62c393a42Smrg * This code is explicitely put in the public domain 72c393a42Smrg * 82c393a42Smrg * ========================================================================== 92c393a42Smrg * 102c393a42Smrg * the OpenType parser codes was originally written as an extension to 112c393a42Smrg * FreeType 1.x. As such, its source code was embedded within the library, 122c393a42Smrg * and used many internal FreeType functions to deal with memory and 132c393a42Smrg * stream i/o. 142c393a42Smrg * 152c393a42Smrg * When it was 'salvaged' for Pango and Qt, the code was "ported" to FreeType 2, 162c393a42Smrg * which basically means that some macro tricks were performed in order to 172c393a42Smrg * directly access FT2 _internal_ functions. 182c393a42Smrg * 192c393a42Smrg * these functions were never part of FT2 public API, and _did_ change between 202c393a42Smrg * various releases. This created chaos for many users: when they upgraded the 212c393a42Smrg * FreeType library on their system, they couldn't run Gnome anymore since 222c393a42Smrg * Pango refused to link. 232c393a42Smrg * 242c393a42Smrg * Very fortunately, it's possible to completely avoid this problem because 252c393a42Smrg * the FT_StreamRec and FT_MemoryRec structure types, which describe how 262c393a42Smrg * memory and stream implementations interface with the rest of the font 272c393a42Smrg * library, have always been part of the public API, and never changed. 282c393a42Smrg * 292c393a42Smrg * What we do thus is re-implement, within the OpenType parser, the few 302c393a42Smrg * functions that depend on them. This only adds one or two kilobytes of 312c393a42Smrg * code, and ensures that the parser can work with _any_ version 322c393a42Smrg * of FreeType installed on your system. How sweet... ! 332c393a42Smrg * 342c393a42Smrg * Note that we assume that Pango doesn't use any other internal functions 352c393a42Smrg * from FreeType. It used to in old versions, but this should no longer 362c393a42Smrg * be the case. (crossing my fingers). 372c393a42Smrg * 382c393a42Smrg * - David Turner 392c393a42Smrg * - The FreeType Project (www.freetype.org) 402c393a42Smrg * 412c393a42Smrg * PS: This "glue" code is explicitely put in the public domain 422c393a42Smrg */ 432c393a42Smrg#ifndef __OPENTYPE_FTGLUE_H__ 442c393a42Smrg#define __OPENTYPE_FTGLUE_H__ 452c393a42Smrg 462c393a42Smrg#include "fcint.h" 472c393a42Smrg 482c393a42Smrg#include <ft2build.h> 492c393a42Smrg#include FT_FREETYPE_H 502c393a42Smrg 512c393a42SmrgFT_BEGIN_HEADER 522c393a42Smrg 532c393a42Smrg 542c393a42Smrg/* utility macros */ 552c393a42Smrg#define TT_Err_Ok FT_Err_Ok 562c393a42Smrg#define TT_Err_Invalid_Argument FT_Err_Invalid_Argument 572c393a42Smrg#define TT_Err_Invalid_Face_Handle FT_Err_Invalid_Face_Handle 582c393a42Smrg#define TT_Err_Table_Missing FT_Err_Table_Missing 592c393a42Smrg 602c393a42Smrg#define SET_ERR(c) ( (error = (c)) != 0 ) 612c393a42Smrg 622c393a42Smrg#ifndef FTGLUE_API 632c393a42Smrg#define FTGLUE_API(x) extern FcPrivate x 642c393a42Smrg#endif 652c393a42Smrg 662c393a42Smrg#ifndef FTGLUE_APIDEF 672c393a42Smrg#define FTGLUE_APIDEF(x) x 682c393a42Smrg#endif 692c393a42Smrg 702c393a42Smrg/* stream macros used by the OpenType parser */ 712c393a42Smrg#define FILE_Pos() ftglue_stream_pos( stream ) 722c393a42Smrg#define FILE_Seek(pos) SET_ERR( ftglue_stream_seek( stream, pos ) ) 732c393a42Smrg#define ACCESS_Frame(size) SET_ERR( ftglue_stream_frame_enter( stream, size ) ) 742c393a42Smrg#define FORGET_Frame() ftglue_stream_frame_exit( stream ) 752c393a42Smrg 762c393a42Smrg#define GET_Byte() (*stream->cursor++) 772c393a42Smrg#define GET_Short() (stream->cursor += 2, (FT_Short)( \ 782c393a42Smrg (*(((FT_Byte*)stream->cursor)-2) << 8) | \ 792c393a42Smrg *(((FT_Byte*)stream->cursor)-1) \ 802c393a42Smrg )) 812c393a42Smrg#define GET_Long() (stream->cursor += 4, (FT_Long)( \ 822c393a42Smrg (*(((FT_Byte*)stream->cursor)-4) << 24) | \ 832c393a42Smrg (*(((FT_Byte*)stream->cursor)-3) << 16) | \ 842c393a42Smrg (*(((FT_Byte*)stream->cursor)-2) << 8) | \ 852c393a42Smrg *(((FT_Byte*)stream->cursor)-1) \ 862c393a42Smrg )) 872c393a42Smrg 882c393a42Smrg#define GET_Char() ((FT_Char)GET_Byte()) 892c393a42Smrg#define GET_UShort() ((FT_UShort)GET_Short()) 902c393a42Smrg#define GET_ULong() ((FT_ULong)GET_Long()) 912c393a42Smrg#define GET_Tag4() GET_ULong() 922c393a42Smrg 932c393a42Smrg#define FT_SET_ERROR( expression ) \ 942c393a42Smrg ( ( error = (expression) ) != 0 ) 952c393a42Smrg 962c393a42SmrgFTGLUE_API( FT_Long ) 972c393a42Smrgftglue_stream_pos( FT_Stream stream ); 982c393a42Smrg 992c393a42SmrgFTGLUE_API( FT_Error ) 1002c393a42Smrgftglue_stream_seek( FT_Stream stream, 1012c393a42Smrg FT_Long pos ); 1022c393a42Smrg 1032c393a42SmrgFTGLUE_API( FT_Error ) 1042c393a42Smrgftglue_stream_frame_enter( FT_Stream stream, 1052c393a42Smrg FT_ULong size ); 1062c393a42Smrg 1072c393a42SmrgFTGLUE_API( void ) 1082c393a42Smrgftglue_stream_frame_exit( FT_Stream stream ); 1092c393a42Smrg 1102c393a42SmrgFTGLUE_API( FT_Byte ) 1112c393a42Smrgftglue_stream_get_byte( FT_Stream stream ); 1122c393a42Smrg 1132c393a42SmrgFTGLUE_API( FT_Short ) 1142c393a42Smrgftglue_stream_get_short( FT_Stream stream ); 1152c393a42Smrg 1162c393a42SmrgFTGLUE_API( FT_Long ) 1172c393a42Smrgftglue_stream_get_long( FT_Stream stream ); 1182c393a42Smrg 1192c393a42SmrgFTGLUE_API( FT_Error ) 1202c393a42Smrgftglue_face_goto_table( FT_Face face, 1212c393a42Smrg FT_ULong tag, 1222c393a42Smrg FT_Stream stream ); 1232c393a42Smrg 1242c393a42SmrgFTGLUE_API( FT_Pointer ) 1252c393a42Smrgftglue_alloc( FT_Memory memory, 1262c393a42Smrg FT_ULong size, 1272c393a42Smrg FT_Error *perror_ ); 1282c393a42Smrg 1292c393a42SmrgFTGLUE_API( FT_Pointer ) 1302c393a42Smrgftglue_realloc( FT_Memory memory, 1312c393a42Smrg FT_Pointer block, 1322c393a42Smrg FT_ULong old_size, 1332c393a42Smrg FT_ULong new_size, 1342c393a42Smrg FT_Error *perror_ ); 1352c393a42Smrg 1362c393a42SmrgFTGLUE_API( void ) 1372c393a42Smrgftglue_free( FT_Memory memory, 1382c393a42Smrg FT_Pointer block ); 1392c393a42Smrg 1402c393a42Smrg/* */ 1412c393a42Smrg 1422c393a42SmrgFT_END_HEADER 1432c393a42Smrg 1442c393a42Smrg#endif /* __OPENTYPE_FTGLUE_H__ */ 145