查看: 3061|回复: 5

[已经解决] 关于一个诡异的字体定义方法

[复制链接]
梦石
0
星屑
50
在线时间
476 小时
注册时间
2011-3-22
回帖
33
发表于 2013-1-28 00:41:21 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 muyumuyulnny 于 2013-1-28 14:52 编辑

有一个英文脚本,它不适用正常的字体而是用以下脚本来定义字体  
[pre lang="ruby" line="1"]class Bitmap
  #--------------------------------------------------------------------------
  # * Bitmap Font
  #  x    :  the x of the starting letter
  #  y    :  the y of the starting letter
  #  text :  the text to display
  #  font :  the font to render (optional)
  #--------------------------------------------------------------------------
  def bitmap_font(x, y, text, font = 'FE7_Text', color = 'White', dash = false)
    text = text.to_s
    if font == 'Verdana'
      # Create the font
      font_image = RPG::Cache.picture(font)
      # Determine sizing.
      char_width  = font_image.width  / 26
      char_height = font_image.height / 3
      # Loop through each letter.
      text.length.times do |index|
        # Get the Byte.
        byte = text[index]
        # Get Letter
        letter = byte.chr
        # If it is a letter
        if letter =~ /[A-Z]/
          iX = (byte - 65) * char_width
          iY = char_height
        elsif letter =~ /[a-z]/
          iX =(byte - 97) * char_width
          iY = 0
        # If it is a number
        elsif letter =~ /[0-9]/
          iX = letter.to_i * char_width
          iY = 2 * char_height
        # Otherwise it's a symbol
        else
          unless letter == ' ' or letter == ''
            # Define the order
            order = ['.', ',', '$', '!', '(', ')', '-', '/', '\\', '?', ';',
                ':', '#', '&', '"', "'"]
            iX = (order.index(letter) + 10) * char_width
            iY = 2 * char_height
          end
        end
        # If it's not a space, draw it
        if letter != ' ' and letter != ""
          rect = Rect.new(iX, iY, char_width, char_height)
          # Blit it to the screen
          self.blt((index * char_width) + x, y, font_image, rect)
        end
      end
    end
    if font == 'AWOS'
      # Create the font
      font_image = RPG::Cache.picture(font)
      $placement = 0
      # Loop through each letter.
      text.length.times do |index|
        # Determine sizing.
        char_width  = 8 #font_image.width  / 26
        char_height = 12 #font_image.height / 3
        # Get the Byte.
        byte = text[index]
        # Get Letter
        letter = byte.chr
        # If it is a letter
        if letter =~ /[A-Z]/
          iX = (byte - 65) * char_width
          iY = char_height
          if letter == 'W' or letter == 'M'
            char_width = 8
          elsif letter == 'I'
            char_width = 2
          else
            char_width = 6
          end
        elsif letter =~ /[a-z]/
          iX =(byte - 97) * char_width
          iY = 0
          if letter == 'a' or letter == 'd' or letter == 'm' or letter == 'v'
            char_width = 6
          elsif letter == 'w' or letter == 'x' or letter == 'z'
            char_width = 6
          elsif letter == 'j' or letter == 't'
            char_width = 4
          elsif letter == 'i' or letter == 'l'
            char_width = 2
          else
            char_width = 5
          end
        # If it is a number
        elsif letter =~ /[0-9]/
          iX = letter.to_i * char_width
          iY = 2 * char_height
          if letter == '1'
            char_width = 4
          else
            char_width = 7
          end
        # Otherwise it's a symbol
        else
          unless letter == ' ' or letter == ''
            # Define the order
            order = ['.', ',', '$', '!', '(', ')', '-', '/', '\\', '?', ';',
                ':', '#', '&', '"', "'", '+']
            iX = (order.index(letter) + 10) * char_width
            iY = 2 * char_height
          end
          if letter == '.' or letter == ':' or letter == "'"
            char_width = 2
          elsif letter == ',' or letter == '!' or letter == ';'
            char_width = 3
          elsif letter == '(' or letter == ')' or letter == '-' or letter == '"'
            char_width = 4
          elsif letter == '#'
            char_width = 7
          elsif letter == '&'
            char_width = 8
          else
            char_width = 6
          end
        end
        letter == ' ' or letter == "" ? char_width = 3 : nil
        # If it's not a space, draw it
        if letter != ' ' and letter != ""
          rect = Rect.new(iX, iY, char_width, char_height)
          # Blit it to the screen
          self.blt($placement + x, y, font_image, rect)
        end
        $placement += char_width
      end
    end
    if font == 'FE7_Text' or font == 'FE7_TextL'
      large_text = (font == 'FE7_TextL')
      # Create the font
      font = 'FE7_Text' + '_' + (color == 'Info2' ? 'Info' : color)
      font_image = RPG::Cache.picture(font)
      $placement = 0
      # Loop through each letter.
      text.length.times do |index|
        # Determine sizing.
        char_width  = 8 #font_image.width  / 26
        char_height = 14 #font_image.height / 3
        # Get the Byte.
        byte = text[index]
        # Get Letter
        letter = byte.chr
        # If it is a letter
        if letter =~ /[A-Z]/
          iX = (byte - 65) * char_width
          iY = char_height * (large_text ? 3 : 1)
          if large_text
            char_width = 8
          else
            if letter == 'W' or letter == 'M' or letter == 'V' or
                letter == 'Q' or letter == 'X' or letter == 'Y' or letter == 'T'
              char_width = 7
            elsif letter == 'I' or letter == 'L'
              char_width = 5
            else
              char_width = 6
            end
          end
        elsif letter =~ /[a-z]/
          iX =(byte - 97) * char_width
          iY = 0
          if letter == 'a' or letter == 'm' or letter == 'v' or
              letter == 'w' or letter == 'x'
            char_width = 7
          elsif letter == 'f' or letter == 'j' or letter == 'r' or letter == 't'
            char_width = 5
          elsif letter == 'i' or letter == 'l'
            char_width = 3
          else
            char_width = 6
          end
        # If it is a number
        elsif letter =~ /[0-9]/
          iX = letter.to_i * char_width
          iY = 2 * char_height
          if color == 'Info'
            char_width = 7
          else
            char_width = 8
          end
        # Otherwise it's a symbol
        else
          unless letter == ' ' or letter == ''
            # Define the order
            order = ['.', ',', '$', '!', '(', ')', '-', '/', '\\', '?', ';',
                ':', '#', '&', '"', "'", '+']
            iX = (order.index(letter) + 10) * char_width
            iY = 2 * char_height
          end
          if letter == '.' or letter == ':' or letter == "'" or
              letter == ',' or letter == ';'
            char_width = 3
          elsif letter == '(' or letter == ')'
            char_width = 5
          elsif letter == '"' or letter == '!'
            char_width = 5
          elsif letter == '#'
            char_width = 6
          elsif letter == '-'
            if color == 'Combat'
              char_width = 8
            else
              char_width = 7
            end
            #$placement += 1
          elsif letter == '$' # Equipped/Experience 'E'
            char_width = 8
          else
            char_width = 7
          end
        end
        (letter == ' ' or letter == "") ? (char_width = 4) : nil
        # If it's not a space, draw it
        if letter != ' ' and letter != ""
          rect = Rect.new(iX, iY, char_width, char_height)
          # Blit it to the screen
          self.blt($placement + x, y, font_image, rect)
        end
        $placement += char_width - 1
        $placement += 1 if (letter =~ /[A-Z]/ and large_text)
        $placement += 1 if (letter =~ /[0-9]/)
        $placement += 1 if (letter == '-' and (dash or color == 'Combat'))
        $placement += 2 if (letter == '-' and !(dash or (color == 'Combat')))
      end
    end
    if font == 'FE7_Convo'
      # Create the font
      font = 'FE7_Convo' + '_' + color
      font_image = RPG::Cache.picture(font)
      $placement = 0
      # Loop through each letter.
      text.length.times do |index|
        # Determine sizing.
        char_width  = 8 #font_image.width  / 26
        char_height = 16 #font_image.height / 3
        # Get the Byte.
        byte = text[index]
        # Get Letter
        letter = byte.chr
        # If it is a letter
        if letter =~ /[A-Z]/
          iX = (byte - 65) * char_width
          iY = char_height
          if ['M', 'W', 'X'].include?(letter)
            char_width = 8
          elsif ['Q', 'S'].include?(letter)
            char_width = 7
          elsif letter == 'I'
            char_width = 4
          else
            char_width = 6
          end
        elsif letter =~ /[a-z]/
          iX =(byte - 97) * char_width
          iY = 0
          if letter == 'g'
            char_width = 7
          elsif ['a', 'm', 'v', 'w', 'x'].include?(letter)
            char_width = 6
          elsif letter == 'r' or letter == 't'
            char_width = 4
          elsif letter == 'j'
            char_width = 3
          elsif letter == 'i' or letter == 'l'
            char_width = 2
          else
            char_width = 5
          end
        # If it is a number
        elsif letter =~ /[0-9]/
          iX = letter.to_i * char_width
          iY = 2 * char_height
          if letter == '1'
            char_width = 4
          elsif letter == '4'
            char_width = 7
          else
            char_width = 6
          end
        # Otherwise it's a symbol
        else
          unless letter == ' ' or letter == ''
            # Define the order
            order = ['.', ',', '$', '!', '(', ')', '-', '/', '\\', '?', ';',
                ':', '#', '&', '"', "'", '+', '%']
            if !order.include?(letter)
              next
            end
            iX = (order.index(letter) + 10) * char_width
            iY = 2 * char_height
          end
          if ['.', ',', ';', ':', "'"].include?(letter)
            char_width = 2
          elsif ['!', '(', ')'].include?(letter)
            char_width = 3
          elsif letter == '-'
            char_width = 4
          elsif letter == '"' or letter == '+'
            char_width = 5
          elsif letter == '#'
            char_width = 6
          elsif letter == '%' or letter == '$' # Equipped/Experience 'E'
            char_width = 8
          else
            char_width = 7
          end
        end
        (letter == ' ' or letter == "") ? (char_width = 4) : nil
        # If it's not a space, draw it
        if letter != ' ' and letter != ""
          rect = Rect.new(iX, iY, char_width, char_height)
          # Blit it to the screen
          self.blt($placement + x, y, font_image, rect)
        end
        $placement += char_width
        #$placement += 1 if (letter =~ /[A-Z]/ and large_text)
        #$placement += 1 if (letter =~ /[0-9]/)
        #$placement += 1 if (letter == '-' and (dash or color == 'Combat'))
        #$placement += 2 if (letter == '-' and !(dash or (color == 'Combat')))
      end
    end
  end
end[/pre]


能否在其中加入一个可使用中文的字体?因为这是一个系列的脚本,它的窗口里都是用的
@content[index].bitmap.bitmap_font(4,6,@commands[index], 'FE7_Text','White')
  @lv_hp.bitmap.bitmap_font(0, 16, 'HP', 'FE7_TextL', 'Yellow')
之类的语句来写的,一旦把'HP'改成'生命'它就完全不能显示了。
其实我以前有问过的,可是一直到过期都没人理我... ...所以本着锲而不舍的精神再问一次。

风行者

梦石
0
星屑
2540
在线时间
6938 小时
注册时间
2011-10-2
回帖
2373

开拓者

发表于 2013-1-28 08:40:02 来自手机 | 显示全部楼层
这上面只能输出英文字符,你写中文当然就显示不能了。改字体在你的脚本里全局搜索font.name。然后改成你想要的字体。
回复

使用道具 举报

梦石
0
星屑
3905
在线时间
1972 小时
注册时间
2013-1-3
回帖
9146
发表于 2013-1-28 09:03:55 | 显示全部楼层
您全局搜索font.name,然后把括号里的字体名称改为您想要的,一定要写全称(可在我的电脑\window\Font中查找)。
《宿愿·寻剑篇》正式版已经发布!快去看看!点击进入论坛发布贴
回复

使用道具 举报

梦石
0
星屑
50
在线时间
270 小时
注册时间
2010-2-4
回帖
1296
发表于 2013-1-28 10:59:04 | 显示全部楼层
替换成如下脚本- -b
  1. class Bitmap
  2.   #--------------------------------------------------------------------------
  3.   # * Bitmap Font
  4.   #  x    :  the x of the starting letter
  5.   #  y    :  the y of the starting letter
  6.   #  text :  the text to display
  7.   #  font :  the font to render (optional)
  8.   #--------------------------------------------------------------------------
  9.   def bitmap_font(x, y, text, font = '黑体', color = "", dash = false)
  10.     self.font.name = font
  11.     draw_text(x, y, text.size * 32, 32, text)
  12.   end
  13. end
复制代码

点评

非常感谢,可以使用中文字了!  发表于 2013-1-28 13:18
好歹当年也当过大魔王过,orz
回复

使用道具 举报

梦石
0
星屑
50
在线时间
476 小时
注册时间
2011-3-22
回帖
33
 楼主| 发表于 2013-1-28 13:14:29 | 显示全部楼层
幻风 发表于 2013-1-28 08:40
这上面只能输出英文字符,你写中文当然就显示不能了。改字体在你的脚本里全局搜索font.name。然后改成你想 ...

问题是这个人在描绘文字的时候就不是用的
self.font.name = ""
这种方法,而是自己定义的bitmap_font(x, y, text, font = 'FE7_Text', color = 'Yellow', dash = false)
如果搜font.name 的话只能搜到XP自带脚本而不能搜到这个作者自己写的脚本里的文字。
仍然非常感谢您的回答。
回复

使用道具 举报

梦石
0
星屑
47
在线时间
976 小时
注册时间
2011-4-30
回帖
846
发表于 2013-1-28 13:30:32 | 显示全部楼层
muyumuyulnny 发表于 2013-1-28 13:14
问题是这个人在描绘文字的时候就不是用的
self.font.name = ""
这种方法,而是自己定义的bitmap_font(x,  ...

LZ难道没看到这段脚本吗?

      char_width  = font_image.width  / 26
      char_height = font_image.height / 3

很明显这是个使用图片显示文字的脚本,也就是你脚本里输入文字,它给你从一张图片里找出对应的图片文字,然后显示,

英文26个字母才好这么弄,你中文要用先得准备一张几千字的图?你有么??再说读取方式和英文的也不一样吧??

它里面改字体颜色都是用的另一张图,你还想改字号??

楼下一群人看都没看就瞎解释。
湿滑落式骑!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部