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

📄 freetypeintf.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:

void c_load_glyph(value face,value index,value load_kind)
{
    CAMLparam3(face,index,load_kind);

    FT_Error error;

    
    error=FT_Load_Glyph((FT_Face)face,Int_val(index),Int_val(load_kind));
    if (error)
      c_process_error(error);

    CAMLreturn0;
}

value c_get_glyph(value face)
{
    return((value)(((FT_Face)face)-> glyph));
}

value c_get_ascent(value face)
{
  return(Val_int(FT_MulFix((((FT_Face)face)-> ascender),(((FT_Face)face)-> size->metrics.y_scale))>>6));
}

value c_get_face_height(value face)
{
  return(Val_int(FT_MulFix((((FT_Face)face)-> height),(((FT_Face)face)-> size->metrics.y_scale))>>6));
}

value c_get_descent(value face)
{
  return(Val_int((-FT_MulFix((((FT_Face)face)-> descender),(((FT_Face)face)-> size->metrics.y_scale)))>>6));
}

value c_get_leading(value face)
{
  return(Val_int((FT_MulFix((((FT_Face)face)-> height),(((FT_Face)face)-> size->metrics.y_scale))>>6)));
}

value c_get_underline(value face)
{
  return(Val_int(-(FT_MulFix((((FT_Face)face)-> underline_position),(((FT_Face)face)->size->metrics.y_scale))>>6)));
}

value c_get_width(value glyph)
{
  return(Val_int(((FT_GlyphSlot)glyph)-> metrics.width>>6) );
}

value c_get_height(value glyph)
{
  return(Val_int(((FT_GlyphSlot)glyph)-> metrics.height>>6 ));
}

value c_get_x_advance(value glyph)
{
  return(Val_int(((FT_GlyphSlot)glyph)-> advance.x>>6) );
}

value c_get_y_advance(value glyph)
{
  return(Val_int(((FT_GlyphSlot)glyph)-> advance.y>>6) );
}

value c_get_left_origin(value glyph)
{
  return(Val_int(((FT_GlyphSlot)glyph)->bitmap_left));
}

value c_get_top_origin(value glyph)
{
  return(Val_int(((FT_GlyphSlot)glyph)->bitmap_top));
}

value c_get_bitmap(value glyph)
{
  return((value)(&((FT_GlyphSlot)glyph)->bitmap));
}


/* Just extract the font into a bitmap.
  The scanning is done depending on the mode vertical or horizontal */

/* From width and height create a bitmap whose height is aligned
to an integer number of long words.
The new size in pixel (after dilation of the height) is saved.
The size of the glyph image (in pixel is saved). The height of
the glyph image is varying from glyph to glyph contrary to
bitmap height.*/
value c_expand_bitmap(value glyph,value bitmap_size,value reversex,value reversey,value vertical)
{
    CAMLparam5(glyph,bitmap_size,reversex,reversey,vertical);
    CAMLlocal2(matrix,datas);
    int bytes,pitch,height,width;
    int down_direction;
    int x,y,i,j,k,row,a,nx,ny;
    unsigned char *start,*p;
    int pos;
    FT_Bitmap *bitmap;
    /* Aligned size according to the mode : horizontal or vertical*/
    int aligned_size;

    aligned_size=(Int_val(bitmap_size) >> 5) + 1;

    /*printf("Aligned=%d\n",aligned_size);*/
  

    bitmap=&((FT_GlyphSlot)glyph)->bitmap;

    pitch=bitmap->pitch;

    row=bitmap->rows;
    start=bitmap->buffer;

    height=((FT_GlyphSlot)glyph)-> metrics.height>>6 ;
    width=((FT_GlyphSlot)glyph)-> metrics.width>>6 ;

    bytes=pitch;
    if (bytes<0)
    {
      bytes=-bytes;
      down_direction=0;
    }
    else
     down_direction=1;

    
   

    //printf("bytes=%d,row=%d,width=%d\n",bytes,row,((FT_Bitmap*)bitmap)->width);
   if (Bool_val(vertical))
   {
        if (bytes==0)
          bytes=1;
        matrix=alloc_tuple(7);
        datas=alloc_tuple(((aligned_size)*32)*bytes*8);

       for(x=0;x<bytes*8;x++)
         for(y=0;y<(aligned_size);y++)
         {
             pos=y*32+x*((aligned_size)*32);
             for(k=0;k<32;k++)
             {
                Store_field(datas,pos,Val_int(0));
                pos++;
             }
         }

        y=0;
        while(row!= 0)
        {
            i=bytes;
            p=start;
            x=0;
            while(i != 0)
            {
                if (down_direction)
                  a=*p++;
                else
                  a=*p--;

                //printf("a=%08X\n",a);
                for(j=0;j<8;j++)
                {
                   if (Bool_val(reversex))
                      nx=width-1-x;
                   else
                      nx=x;

                   if (Bool_val(reversey))
                      ny=height-1-y;
                   else
                      ny=y;

                   pos=(ny+nx*((aligned_size)*32));
                   


                   if (a & 0x80)
                   {
                     //printf("Store : %d -> 1\n",pos);
                     Store_field(datas,pos,Val_int(1));
                   }


                   a=a<<1;
                   x++;

                }
                i--;
            }
            row--;
            y++;
            start+=pitch;
        }

        /* THE MATRIX WIDTH MUST BE THE ONE WRITTEN AT THE END
           IN THE ARRAY FOR THE R2D GLYPH */
//printf("bytes=%d,aligned=%d\n",bytes,aligned_size);
        Store_field(matrix,0,Val_int(0));
        Store_field(matrix,1,Val_int(bytes*8));
        Store_field(matrix,2,Val_int(aligned_size*32));
        Store_field(matrix,3,bitmap_size);
        Store_field(matrix,4,Val_int(width));
        Store_field(matrix,5,Val_int(height));
        Store_field(matrix,6,datas);
    }
    else
    {
       
        if (bytes==0)
          bytes=1;

        aligned_size=((bytes*8) >> 5) + 1;

        matrix=alloc_tuple(7);
        datas=alloc_tuple(((aligned_size)*32)*height);


       for(y=0;y<height;y++)
         for(x=0;x<aligned_size;x++)
         {
             pos=y*32*aligned_size+x*32;
             for(k=0;k<32;k++)
             {
                Store_field(datas,pos,Val_int(0));
                pos++;
             }
         }

        y=0;
        while(row!= 0)
        {
            i=bytes;
            p=start;
            x=0;
            while(i != 0)
            {
                if (down_direction)
                  a=*p++;
                else
                  a=*p--;

                //printf("a=%08X\n",a);
                for(j=0;j<8;j++)
                {

                   if (Bool_val(reversex))
                      nx=width-1-x;
                   else
                      nx=x;

                   if (Bool_val(reversey))
                      ny=height-1-y;
                   else
                      ny=y;

                   pos=ny*((aligned_size)*32)+nx;
                   

                   if (a & 0x80)
                   {
                     //printf("Store : %d -> 1\n",pos);
                     Store_field(datas,pos,Val_int(1));
                   }


                   a=a<<1;
                   x++;

                }
                i--;
            }
            row--;
            y++;
            start+=pitch;
        }

        Store_field(matrix,0,Val_int(1));
        Store_field(matrix,1,Val_int(height));
        Store_field(matrix,2,Val_int(aligned_size*32));
        Store_field(matrix,3,bitmap_size);
        Store_field(matrix,4,Val_int(width));
        Store_field(matrix,5,Val_int(height));
        Store_field(matrix,6,datas);

    }
    

    CAMLreturn(matrix);
}




⌨️ 快捷键说明

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