⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freetypeintf.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "ft2build.h"
#include <freetype/freetype.h>

#include "caml/mlvalues.h"
#include "caml/memory.h"
#include "caml/alloc.h"
#include "caml/callback.h"

void c_process_error(FT_Error error)
{
   switch(error)
   {
    
      case 1:
         raise_with_string(*caml_named_value("freetype exception"), "cannot open resource");
      break;
      case 2:
         raise_with_string(*caml_named_value("freetype exception"), "unknown file format");
      break;
      case 3:
         raise_with_string(*caml_named_value("freetype exception"), "broken file");
      break;
      case 4:
         raise_with_string(*caml_named_value("freetype exception"), "invalid FreeType version");
      break;
      case 5:
         raise_with_string(*caml_named_value("freetype exception"), "module version is too low");
      break;
      case 6:
         raise_with_string(*caml_named_value("freetype exception"), "invalid argument");
      break;
      case 7:
         raise_with_string(*caml_named_value("freetype exception"), "unimplemented feature");
      break;
      case 0x10:
         raise_with_string(*caml_named_value("freetype glyph exception"), "invalid glyph index");
      break;
      case 0x11:
         raise_with_string(*caml_named_value("freetype glyph exception"), "invalid character code");
      break;
      case 0x12:
         raise_with_string(*caml_named_value("freetype glyph exception"), "unsupported glyph image format");
      break;
      case 0x13:
         raise_with_string(*caml_named_value("freetype glyph exception"), "cannot render this glyph format");
      break;
      case 0x14:
         raise_with_string(*caml_named_value("freetype glyph exception"), "invalid outline");
      break;
      case 0x15:
         raise_with_string(*caml_named_value("freetype glyph exception"), "invalid composite glyph");
      break;
      case 0x16:
         raise_with_string(*caml_named_value("freetype glyph exception"), "too many hints");
      break;
      case 0x17:
         raise_with_string(*caml_named_value("freetype glyph exception"), "invalid pixel size");
      break;
      case 0x20:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid object handle");
      break;
      case 0x21:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid library handle");
      break;
      case 0x22:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid module handle");
      break;
      case 0x23:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid face handle");
      break;
      case 0x24:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid size handle");
      break;
      case 0x25:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid glyph slot handle");
      break;
      case 0x26:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid charmap handle");
      break;
      case 0x27:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid cache manager handle");
      break;
      case 0x28:
         raise_with_string(*caml_named_value("freetype handle exception"), "invalid stream handle");
      break;
      case 0x30:
         raise_with_string(*caml_named_value("freetype driver exception"), "too many modules");
      break;
      case 0x31:
         raise_with_string(*caml_named_value("freetype driver exception"), "too many extensions");
      break;
      case 0x40:
         raise_with_string(*caml_named_value("freetype memory exception"), "out of memory");
      break;
      case 0x41:
         raise_with_string(*caml_named_value("freetype memory exception"), "unlisted object");
      break;
      case 0x51:
         raise_with_string(*caml_named_value("freetype stream exception"), "cannot open stream");
      break;
      case 0x52:
         raise_with_string(*caml_named_value("freetype stream exception"), "invalid stream seek");
      break;
      case 0x53:
         raise_with_string(*caml_named_value("freetype stream exception"), "invalid stream skip");
      break;
      case 0x54:
         raise_with_string(*caml_named_value("freetype stream exception"), "invalid stream read");
      break;
      case 0x55:
         raise_with_string(*caml_named_value("freetype stream exception"), "invalid stream operation");
      break;
      case 0x56:
         raise_with_string(*caml_named_value("freetype stream exception"), "invalid frame operation");
      break;
      case 0x57:
         raise_with_string(*caml_named_value("freetype stream exception"), "nested frame access");
      break;
      case 0x58:
         raise_with_string(*caml_named_value("freetype stream exception"), "invalid frame read");
      break;
      case 0x60:
         raise_with_string(*caml_named_value("freetype raster exception"), "raster uninitialized");
      break;
      case 0x61:
         raise_with_string(*caml_named_value("freetype raster exception"), "raster corrupted");
      break;
      case 0x62:
         raise_with_string(*caml_named_value("freetype raster exception"), "raster overflow");
      break;
      case 0x63:
         raise_with_string(*caml_named_value("freetype truetype exception"), "negative height while rastering");
      break;
      case 0x70:
         raise_with_string(*caml_named_value("freetype truetype exception"), "too many registered caches");
      break;
      case 0x80:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid opcode");
      break;
      case 0x81:
         raise_with_string(*caml_named_value("freetype truetype exception"), "too few arguments");
      break;
      case 0x82:
         raise_with_string(*caml_named_value("freetype truetype exception"), "stack overflow");
      break;
      case 0x83:
         raise_with_string(*caml_named_value("freetype truetype exception"), "code overflow");
      break;
      case 0x84:
         raise_with_string(*caml_named_value("freetype truetype exception"), "bad argument");
      break;
      case 0x85:
         raise_with_string(*caml_named_value("freetype truetype exception"), "division by zero");
      break;
      case 0x86:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid reference");
      break;
      case 0x87:
         raise_with_string(*caml_named_value("freetype truetype exception"), "found debug opcode");
      break;
      case 0x88:
         raise_with_string(*caml_named_value("freetype truetype exception"), "found ENDF opcode in execution stream");
      break;
      case 0x89:
         raise_with_string(*caml_named_value("freetype truetype exception"), "nested DEFS");
      break;
      case 0x8A:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid code range");
      break;
      case 0x8B:
         raise_with_string(*caml_named_value("freetype truetype exception"), "execution context too long");
      break;
      case 0x8c:
         raise_with_string(*caml_named_value("freetype truetype exception"), "too many function definitions");
      break;
      case 0x8d:
         raise_with_string(*caml_named_value("freetype truetype exception"), "too many instruction definitions");
      break;
      case 0x8e:
         raise_with_string(*caml_named_value("freetype truetype exception"), "SFNT font table missing");
      break;
      case 0x8f:
         raise_with_string(*caml_named_value("freetype truetype exception"), "horizontal header (hhea) table missing");
      break;
      case 0x90:
         raise_with_string(*caml_named_value("freetype truetype exception"), "locations (loca) table missing");
      break;
      case 0x91:
         raise_with_string(*caml_named_value("freetype truetype exception"), "name table missing");
      break;
      case 0x92:
         raise_with_string(*caml_named_value("freetype truetype exception"), "character map (cmap) table missing");
      break;
      case 0x93:
         raise_with_string(*caml_named_value("freetype truetype exception"), "horizontal metrics (hmtx) table missing");
      break;
      case 0x94:
         raise_with_string(*caml_named_value("freetype truetype exception"), "PostScript (post) table missing");
      break;
      case 0x95:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid horizontal metrics");
      break;
      case 0x96:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid character map (cmap) format");
      break;
      case 0x97:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid ppem value");
      break;
      case 0x98:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid vertical metrics");
      break;
      case 0x99:
         raise_with_string(*caml_named_value("freetype truetype exception"), "could not find context");
      break;
      case 0x9a:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid PostScript (post) table format");
      break;
      case 0x9b:
         raise_with_string(*caml_named_value("freetype truetype exception"), "invalid PostScript (post) table");
      break;
      case 0xa0:
         raise_with_string(*caml_named_value("freetype truetype exception"), "opcode syntax error");
      break;
      case 0xa1:
         raise_with_string(*caml_named_value("freetype truetype exception"), "argument stack underflow");
      break;
      default:
         raise_with_string(*caml_named_value("freetype truetype exception"), "Unknown error");
      break;
   }
}

value c_init_freetype(void)
{
    CAMLparam0();

    FT_Library library;
    FT_Error error;
    
    error=FT_Init_FreeType(&library);
    if (error)
      c_process_error(error);

    CAMLreturn((value)library);
}

value c_new_face(value lib,value path,value index)
{
    CAMLparam3(lib,path,index);

    FT_Face the_face;
    FT_Error error;
    
    error=FT_New_Face((FT_Library)lib,String_val(path),Int_val(index),&the_face);
    if (error)
      c_process_error(error);

    CAMLreturn((value)the_face);
}

void c_done_face(value face)
{
    CAMLparam1(face);
    FT_Error error;
    
    error=FT_Done_Face((FT_Face)face);
    if (error)
      c_process_error(error);

    CAMLreturn0;
}
void c_set_pixel_sizes(value face,value width,value height)
{
    CAMLparam3(face,width,height);

    FT_Error error;

    
    error=FT_Set_Pixel_Sizes((FT_Face)face,Int_val(width),Int_val(height));
    if (error)
      c_process_error(error);

    CAMLreturn0;
}

value c_get_char_index(value face,value index)
{
    CAMLparam2(face,index);

    FT_Error error;
    short glyph_index;

    
    glyph_index=FT_Get_Char_Index((FT_Face)face,Int_val(index));
    

    CAMLreturn(Val_int(glyph_index));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -