ftglue.h revision a32e9e42
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#define  SET_ERR(c)   ( (error = (c)) != 0 )
552c393a42Smrg
562c393a42Smrg#ifndef FTGLUE_API
572c393a42Smrg#define FTGLUE_API(x)  extern FcPrivate x
582c393a42Smrg#endif
592c393a42Smrg
602c393a42Smrg#ifndef FTGLUE_APIDEF
612c393a42Smrg#define FTGLUE_APIDEF(x)  x
622c393a42Smrg#endif
632c393a42Smrg
642c393a42Smrg/* stream macros used by the OpenType parser */
652c393a42Smrg#define  FILE_Pos()      ftglue_stream_pos( stream )
662c393a42Smrg#define  FILE_Seek(pos)  SET_ERR( ftglue_stream_seek( stream, pos ) )
672c393a42Smrg#define  ACCESS_Frame(size)  SET_ERR( ftglue_stream_frame_enter( stream, size ) )
682c393a42Smrg#define  FORGET_Frame()      ftglue_stream_frame_exit( stream )
692c393a42Smrg
702c393a42Smrg#define  GET_Byte()      (*stream->cursor++)
712c393a42Smrg#define  GET_Short()     (stream->cursor += 2, (FT_Short)( \
72a32e9e42Smrg				((FT_ULong)*(((FT_Byte*)stream->cursor)-2) << 8) | \
73a32e9e42Smrg				 (FT_ULong)*(((FT_Byte*)stream->cursor)-1) \
742c393a42Smrg			 ))
752c393a42Smrg#define  GET_Long()      (stream->cursor += 4, (FT_Long)( \
76a32e9e42Smrg				((FT_ULong)*(((FT_Byte*)stream->cursor)-4) << 24) | \
77a32e9e42Smrg				((FT_ULong)*(((FT_Byte*)stream->cursor)-3) << 16) | \
78a32e9e42Smrg				((FT_ULong)*(((FT_Byte*)stream->cursor)-2) << 8) | \
79a32e9e42Smrg				 (FT_ULong)*(((FT_Byte*)stream->cursor)-1) \
802c393a42Smrg			 ))
812c393a42Smrg
822c393a42Smrg#define  GET_Char()      ((FT_Char)GET_Byte())
832c393a42Smrg#define  GET_UShort()    ((FT_UShort)GET_Short())
842c393a42Smrg#define  GET_ULong()     ((FT_ULong)GET_Long())
852c393a42Smrg#define  GET_Tag4()      GET_ULong()
862c393a42Smrg
872c393a42Smrg#define FT_SET_ERROR( expression ) \
882c393a42Smrg          ( ( error = (expression) ) != 0 )
892c393a42Smrg
902c393a42SmrgFTGLUE_API( FT_Long )
912c393a42Smrgftglue_stream_pos( FT_Stream   stream );
922c393a42Smrg
932c393a42SmrgFTGLUE_API( FT_Error )
942c393a42Smrgftglue_stream_seek( FT_Stream   stream,
952c393a42Smrg                    FT_Long     pos );
962c393a42Smrg
972c393a42SmrgFTGLUE_API( FT_Error )
982c393a42Smrgftglue_stream_frame_enter( FT_Stream   stream,
992c393a42Smrg                           FT_ULong    size );
1002c393a42Smrg
1012c393a42SmrgFTGLUE_API( void )
1022c393a42Smrgftglue_stream_frame_exit( FT_Stream  stream );
1032c393a42Smrg
1042c393a42SmrgFTGLUE_API( FT_Error )
1052c393a42Smrgftglue_face_goto_table( FT_Face    face,
1062c393a42Smrg                        FT_ULong   tag,
1072c393a42Smrg                        FT_Stream  stream );
1082c393a42Smrg
1092c393a42SmrgFT_END_HEADER
1102c393a42Smrg
1112c393a42Smrg#endif /* __OPENTYPE_FTGLUE_H__ */
112