Back to index

texmacs  1.0.7.15
free_type.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : free_type.cpp
00004 * DESCRIPTION: Interface with Free Type II
00005 * COPYRIGHT  : (C) 2003  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "free_type.hpp"
00013 #include "dyn_link.hpp"
00014 
00015 #ifdef USE_FREETYPE
00016 
00017 static bool ft_initialized= false;
00018 static bool ft_error      = true;
00019 
00020 FT_Library ft_library;
00021 
00022 FT_Error (*ft_init_freetype)  (FT_Library     *alibrary);
00023 FT_Error (*ft_new_face)       (FT_Library     library,
00024                             const char*    filepathname,
00025                             FT_Long        face_index,
00026                             FT_Face*       aface);
00027 FT_Error (*ft_select_charmap) (FT_Face        face,
00028                             FT_Encoding    encoding);
00029 FT_Error (*ft_set_char_size)  (FT_Face        face,
00030                             FT_F26Dot6     char_width,
00031                             FT_F26Dot6     char_height,
00032                             FT_UInt        horz_resolution,
00033                             FT_UInt        vert_resolution);
00034 FT_UInt  (*ft_get_char_index) (FT_Face        face,
00035                             FT_ULong       charcode);
00036 FT_Error (*ft_load_glyph)     (FT_Face        face,
00037                             FT_UInt        glyph_index,
00038                             FT_Int         load_flags);
00039 FT_Error (*ft_render_glyph)   (FT_GlyphSlot   slot,
00040                             FT_Render_Mode render_mode);
00041 
00042 typedef FT_Error (*glyph_renderer) (FT_GlyphSlot, FT_Render_Mode);
00043 
00044 bool
00045 ft_initialize () {
00046   if (ft_initialized) return ft_error;
00047   ft_initialized= true;
00048 #ifdef LINKED_FREETYPE
00049   ft_init_freetype = FT_Init_FreeType;
00050   ft_new_face      = FT_New_Face;
00051   ft_select_charmap= FT_Select_Charmap;
00052   ft_set_char_size = FT_Set_Char_Size;
00053   ft_get_char_index= FT_Get_Char_Index;
00054   ft_load_glyph    = FT_Load_Glyph;
00055   ft_render_glyph  = (glyph_renderer) ((void*) FT_Render_Glyph);
00056   if (ft_init_freetype (&ft_library)) return true;
00057   if (DEBUG_AUTO) cout << "TeXmacs] With linked TrueType support\n";
00058 #else
00059   int status= debug_off ();
00060   (void) symbol_install ("/usr/lib/libfreetype.so", "FT_Init_FreeType" ,
00061                       (pointer&) ft_init_freetype);
00062   if (ft_init_freetype == NULL) return true;
00063   (void) symbol_install ("/usr/lib/libfreetype.so", "FT_New_Face"      ,
00064                       (pointer&) ft_new_face);
00065   if (ft_new_face == NULL) return true;
00066   (void) symbol_install ("/usr/lib/libfreetype.so", "FT_Select_Charmap",
00067                       (pointer&) ft_select_charmap);
00068   if (ft_select_charmap == NULL) return true;
00069   (void) symbol_install ("/usr/lib/libfreetype.so", "FT_Set_Char_Size" ,
00070                       (pointer&) ft_set_char_size);
00071   if (ft_set_char_size == NULL) return true;
00072   (void) symbol_install ("/usr/lib/libfreetype.so", "FT_Get_Char_Index",
00073                       (pointer&) ft_get_char_index);
00074   if (ft_get_char_index == NULL) return true;
00075   (void) symbol_install ("/usr/lib/libfreetype.so", "FT_Load_Glyph"    ,
00076                       (pointer&) ft_load_glyph);
00077   if (ft_load_glyph == NULL) return true;
00078   (void) symbol_install ("/usr/lib/libfreetype.so", "FT_Render_Glyph"  ,
00079                       (pointer&) ft_render_glyph);
00080   if (ft_render_glyph == NULL) return true;
00081   debug_on (status);
00082   if (ft_init_freetype (&ft_library)) return true;
00083   if (DEBUG_AUTO) cout << "TeXmacs] Installed TrueType support\n";
00084 #endif
00085   ft_error= false;
00086   return false;
00087 }
00088 
00089 bool
00090 ft_present () {
00091   return !ft_initialize ();
00092 }
00093 
00094 #else
00095 
00096 bool ft_initialize () { return true; }
00097 bool ft_present () { return false; }
00098 
00099 #endif