RUBY 代码 
[code]=begin 
 
使用FreeType进行中文的文本描绘,脚本编辑器置顶即可 
支持文字粗体、斜体、旋转、描边、阴影 
使用内存字体文件,仅支持矢量字体,不支持字体的kern设置 
CPU支持SSE 
 
FontEx用13个元素的数组来表示字体 
 [0] 内存字体文件 String 
 [1] 字体大小     Fixnum  须大于0 
 [2] 字体颜色     Fixnum/BigNum  单色填充  0xAaRrGgBb 
                  String  沿文字方向线性渐变填充 
                            渐变由节点描述,节点结构 float pos, int argb 
                            至少2个节点,首节点pos须0.0f,尾节点pos须1.0f 
                            后节点比前节点pos大0.001 
 [3] 水平方向斜体 Fixnum/Float  与Y正半轴的顺时针夹角 取值范围 [-65, 65] 
 [4] 垂直方向斜体 Fixnum/Float  与X正半轴的顺时针夹角 取值范围 [-65, 65] 
                                  当水平方向斜体为0时,才有效 
 [5] 文本旋转角度 Fixnum/Float  与文字方向的逆时针夹角 
 [6] 水平方向粗体 Fixnum  可以负值 
 [7] 垂直方向粗体 Fixnum  可以负值 
 [8] 描边大小     Fixnum  须大于等于0 
 [9] 描边颜色     Fixnum/BigNum  单色填充  0xAaRrGgBb 
 [10]阴影         0/nil   表示无阴影 
                  String  阴影描述,由节点组成,可多个节点 
                          阴影节点 char offset_hori 相对于主体的水平偏移 
                                   char offset_vert 相对于主体的垂直偏移 
                                   char blur_size   模糊大小 建议 -16..16 
                                                    负值类似空心效果 
                                   char blend_times 阴影加强,类似PS ctrl+j 
                                    int argb        阴影颜色                                              
 [11]字体间距     Fixnum  字体间距调整值 
 [12]标志参数     Fixnum   
                          0..1bit 描绘方式 0: 正常;1: 加法;2: 减法 
                                           加减法只影响alpha通道,3修正为0 
                             2bit 布局方式 0:水平;1: 垂直 
                             3bit [11]字体间距计算方式 
                                  0: 额外附加值;1: 绝对值作为总间距 
                             4bit 中文水平标点符号修正为垂直符号(垂直布局时) 
                                  0: 不修正;1: 修正 
 
颜色直接使用数值表示,并不使用RMXP的Color对象 
  单色描绘时,颜色设置为0时,不进行描绘 
 
文字描绘由单个字符分3层(先后依次为 阴影、描边、主体)描绘,字符可能相互影响 
  描边是字体轮廓,类似空心字体的效果 
  阴影以主体为基础,不包括描边 
 
不进行主体描绘,[2] = 0 
不进行描边描绘,[8] = 0 
不进行阴影描绘,[10] = 0 或 nil 
 
文本的要求,仅支持符合Utf8编码的部分(字符的首字节与后续字节都必须符合) 
 
int, char, float,short 为C语言的类型 
=end 
 
class FontEx < Array 
 
  def initialize(name = @@default_name, *args) 
    super(13, 0) 
    t = args.size 
    t = 12if t > 12 
    t.times{|i| self[i + 1] = args} 
    self.name = name 
    self[1] = @@default_size  if t == 0 
    self[2] = @@default_color if t == 1 
  end 
 
 
  ["file_buffer", "size", "color", "oblique_x", "oblique_y", 
   "rotate_angle", "bold_x", "bold_y", "stroke_size", "stroke_color", 
   "shadow", "kerning", "flags"].each_with_indexdo |attr, i| 
 
    define_method(attr){self} 
    define_method(attr + "="){|value| self = value}      
  end 
 
  def name 
    @font_name 
  end 
 
  def name=(font_name) 
    @font_name = @@font_cache.include?(font_name) ? font_name : @@default_name 
    self[0] = @@font_cache[@font_name] 
  end 
 
  def blend_type 
    self[12] & 3 
  end 
 
  def blend_type=(type) 
    type = 0if type < 0 || type > 2 
    self[12] = (self[12] & -4) | type 
  end 
 
  def layout 
    self[12][2] 
  end 
 
  def layout_hori 
    self[12] &= -5 
  end 
 
  def layout_vert(bPunctAmend = false) 
    self[12] |= 4 
    self[12] |= 16  if bPunctAmend == true 
    self[12] &= -17if bPunctAmend == false 
  end 
 
  def kerning_fixed=(bool) 
    self[12] |= 8  if bool == true 
    self[12] &= -9if bool == false 
  end 
 
  def clampByte(value) 
    value = 0   if value < 0 
    value = 255if value > 255 
    return value.to_i 
  end 
 
  def make_color(r, g, b, a) 
    r = self.clampByte(r) 
    g = self.clampByte(g) 
    b = self.clampByte(b) 
    a = self.clampByte(a) 
    return a 水平基准线;2=>字符框底端 
  #               垂直布局时,0=>字符框左端;1=>垂直基准线;2=>字符框右端 
  # alignPoint: 点(dx, dy)在文本描绘基准线上的位置( < 0 或 > 2 修正为0 ) 
  #               0=>起始点;1=>中间点;2=>终止点 
  # 
  # 备注:对齐方式,不含阴影部分 
  #———————————————————————————— 
  def text_out(bitmap, dx, dy, text, cTerminate = -1, alignBsln = 0, 
    alignPoint = 0) 
 
    alignBsln = 0if alignBsln < 0 || alignBsln > 2 
    alignPoint = 0if alignPoint < 0 || alignPoint > 2 
 
    Text_Out.call(bitmap.__id__, dx, dy, text.__id__, cTerminate, 
      self.__id__, alignBsln | alignPoint  3 修正为0 ) 
  #               水平布局时,0=>水平基准线;1=>字符框顶端 
  #                           2=>字符框上下中端;3=>字符框底端 
  #               垂直布局时,0=>垂直基准线;1=>字符框左端 
  #                           2=>字符框左右中端;3=>字符框右端 
  #    bSmooth: 多个二阶贝塞尔曲线之间是否平滑过渡 
  #               p0, p1, p1.5 
  #                       p1.5, p2, p2.5 
  #                                 p2.5, p3, p4 
  # bCurveLine: 贝塞尔曲线是否直接写入位图( 不推荐使用 ) 
  #curve_color: 贝塞尔曲线的颜色,0xAaRrGgBb 
  # 
  # 备注:不支持 kerning_fixed = true 
  #———————————————————————————— 
  def text_out_path(bitmap, text, cTerminate, points, step, 
    alignBsln = 0, bSmooth = false, bCurveLine = false, curve_color = -1) 
 
    mode = alignBsln 
    mode = 0if alignBsln < 0 || alignBsln > 3 
    mode |= 0x10 if bSmooth == true 
    mode |= 0x100 if bCurveLine == true 
 
    Text_Out_Bzr.call(bitmap.__id__, text.__id__, cTerminate, self.__id__, 
      points.__id__, step, mode, curve_color) 
  end 
 
  # 搭配draw_text使用,计算的文本大小含阴影部分 
  def text_size(text, cTerminate = -1) 
    rect = Rect.new(0, 0, 0, 0) 
    Text_Size.call(self.__id__, text.__id__, cTerminate, rect.__id__) 
    return rect 
  end 
 
  #———————————————————————————— 
  # 类似GDI的draw_text 
  #     bitmap: 位图对象 
  #       rect: 文本描绘的位置区域,RMXP Rect对象 
  #       text: 文本描绘的字符串 
  # cTerminate: 字符串的终止符(仅最低位字节有效) 
  #      align: 文本描绘的对齐方式( < 0 或 > 9 修正为4 ) 
  #               对齐方式参考小键盘的1-9 
  #———————————————————————————— 
  def draw_text(bitmap, rect, text, cTerminate = -1, align = 4) 
    align = 4if align < 1 || align > 9 
    Draw_Text.call(bitmap.__id__, rect.__id__, text.__id__, cTerminate, 
      self.__id__, align) 
  end 
 
  class