FreeType库试用

FreeType库试用




有关字体的一点参考:
TTC和TTF的解释:
     TTC:TrueType Collection file. A scheme where multiple TrueType fonts can be stored in a single file, typically used when only a subset of glyphs changes among different designs. They're used in Japanese fonts, where the Kana glyphs change but the Kanji remain the same.
     TTF:The recommended file extension for TrueType font files on the PC. On the Macintosh, exactly the same data is in an *'sfnt' resource. The recommended file extension for the TrueType flavour of *OpenType fonts is also TTF. (But Type 1 flavour OpenType fonts should have an OTF extension.)  
     
      所以我个人认为TTF才是一个将一种字体定义好的文件格式,它里面应该包括每个字的写法。而TTC是一个链接容器,可能只有部分字体的写法,其他的字体是从别的TTF中链接过来的。
      ttc 是TrueType的集合,可能会在一个ttc文件中包含多个type 接口。可以用FontLab, 或者 breakttc.exe 将一个ttc文件分离成多个ttf文件。

       因此,TTC是几个TTF合成的字库,安装后字体列表中会看到两个以上的字体。两个字体中大部分字都一样时,可以将两种字体做成一个TTC文件,现在常见的TTC中的不同字体,汉字一般没有差别,只是英文符号的宽度不一样,以便适应不同的版面要求。
     
       我想说的以后的TTC字库可能就是一个发展趋势,因为它很有优越行,任何字体可以合成TTC字库的

      

    生成字形位图后,我们要将字形位图转换为我们自己的图形数据,生成最接近位图大小的2的幂次方位图


/**/ ///This function gets the first power of 2 >= the
///int that we pass it.

inline  int  next_p2 (  int  a )
{
    
int rval=1;
    
while(rval<a) rval<<=1;
    
return rval;
}

      int width = next_p2( bitmap.width );
      int height = next_p2( bitmap.rows );

     char *  pBuf  =   new   char [width  *  height  *   4 ];
    
for ( int  j = 0 ; j   <  height ; j ++ )
    
{
        
for(int i=0; i < width; i++)
        
{
            unsigned 
char _vl =  (i>=bitmap.width || j>=bitmap.rows) ? 0 : bitmap.buffer[i + bitmap.width*j];
            pBuf[(
4*+ (height - j - 1* width * 4)  ] = 0xFF;
            pBuf[(
4*+ (height - j - 1* width * 4)+1= 0xFF;
            pBuf[(
4*+ (height - j - 1* width * 4)+2= 0xFF;
            pBuf[(
4*+ (height - j - 1* width * 4)+3= _vl;
        }

    }
    位图数据转换为RGBA格式,RGB分别给0xFF而不是别的颜色,因为这样的话就可以在外界传入字体颜色    任何传入字体颜色&0xFF = 字体颜色
   alpha数据,我们就传入字形位图的数据(里面包含着FreeType生成的反锯齿位图的alpha数据)



参考:   http://freetype.sourceforge.net/freetype2/docs/tutorial/step1.html      官方教学
              http://www.linuxforum.net/forum/showflat.php?Board=kylix&Number=592188       对应的中文翻译
             http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43

你可能感兴趣的:(FreeType库试用)