/* vi: set sw=4 ts=4: */
/*
 * CCE - Console Chinese Environment -
 * Copyright (C) 1998-2003 Rui He (rhe@3eti.com)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * 
 */

#ifndef __CCE_FTFONT_H__
#define __CCE_FTFONT_H__

#include "config.h"

#ifdef SUPPORT_FREETYPE_FONT

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H

#define DEFAULT_TTFONT_SIZE 20  /* 20 * 20 */
#define MIN_TTFONT_SIZE		12  
#define MAX_TTFONT_SIZE		128  /* bigger than max, use default */

extern int UseTTFont, TTFontSize; /* are we using Unicode TTY font? */
extern char *TTFontPathName;

extern int DoAntiAlias;  /* do we do antialias ? */
extern int ftXOrig, ftYOrig;  /* X and Y Origin offset */

extern int  FreetypeInit (char *fontfile, int fontsize);
extern void FreetypeCleanup(void);
extern int  FreetypeGetGlyph(int encoding, int ch1, int ch2, FT_GlyphSlot *glyph);

#ifdef USE_DYNAMIC_FREETYPELIB

#include    <dlfcn.h>  /* for dlopen etc */

extern FT_Error (*p_FT_Init_FreeType)( FT_Library  *alibrary );
extern FT_Error (*p_FT_New_Face)( FT_Library library, const char*  filepathname,
	                 FT_Long      face_index, FT_Face     *aface );
extern FT_Error (*p_FT_Done_FreeType)( FT_Library  library );
extern FT_Error (*p_FT_Set_Pixel_Sizes)( FT_Face  face,
                     FT_UInt  pixel_width, FT_UInt  pixel_height );
extern FT_Error (*p_FT_Select_Charmap)( FT_Face face, FT_Encoding  encoding );
extern FT_UInt  (*p_FT_Get_Char_Index)( FT_Face face, FT_ULong charcode);
extern FT_Error (*p_FT_Load_Glyph)( FT_Face face, FT_UInt  glyph_index, FT_Int32 load_flags);
extern FT_Error (*p_FT_Render_Glyph)( FT_GlyphSlot    slot, FT_Render_Mode  render_mode );

#define FT_INIT_FREETYPE   (*p_FT_Init_FreeType)
#define FT_NEW_FACE        (*p_FT_New_Face)
#define FT_DONE_FREETYPE   (*p_FT_Done_FreeType)
#define FT_SET_PIXEL_SIZES (*p_FT_Set_Pixel_Sizes)
#define FT_SELECT_CHARMAP  (*p_FT_Select_Charmap)
#define FT_GET_CHAR_INDEX  (*p_FT_Get_Char_Index)
#define FT_LOAD_GLYPH	   (*p_FT_Load_Glyph)
#define FT_RENDER_GLYPH    (*p_FT_Render_Glyph)

#if defined(__OpenBSD__)
#define SYMBOL_PREFIX "_"  /* strange for OpenBSD */
#else
#define SYMBOL_PREFIX ""
#endif

#define SYMBOL_FT_INIT_FREETYPE          SYMBOL_PREFIX "FT_Init_FreeType"
#define SYMBOL_FT_NEW_FACE               SYMBOL_PREFIX "FT_New_Face"
#define SYMBOL_FT_DONE_FREETYPE          SYMBOL_PREFIX "FT_Done_FreeType"
#define SYMBOL_FT_SET_PIXEL_SIZES        SYMBOL_PREFIX "FT_Set_Pixel_Sizes"
#define SYMBOL_FT_SELECT_CHARMAP         SYMBOL_PREFIX "FT_Select_Charmap"
#define SYMBOL_FT_GET_CHAR_INDEX         SYMBOL_PREFIX "FT_Get_Char_Index"
#define SYMBOL_FT_LOAD_GLYPH             SYMBOL_PREFIX "FT_Load_Glyph"
#define SYMBOL_FT_RENDER_GLYPH           SYMBOL_PREFIX "FT_Render_Glyph"

#else /* USE_DYNAMIC_FREETYPELIB */

#define FT_INIT_FREETYPE     FT_Init_FreeType
#define FT_NEW_FACE          FT_New_Face
#define FT_DONE_FREETYPE     FT_Done_FreeType
#define FT_SET_PIXEL_SIZES   FT_Set_Pixel_Sizes
#define FT_SELECT_CHARMAP    FT_Select_Charmap
#define FT_GET_CHAR_INDEX    FT_Get_Char_Index
#define FT_LOAD_GLYPH	     FT_Load_Glyph
#define FT_RENDER_GLYPH      FT_Render_Glyph

#endif /* USE_DYNAMIC_FREETYPELIB */

#endif /* SUPPORT_FREETYPE_FONT */

#endif /* __CCE_FTFONT_H__ */
