怎样让字体能够自动替换?

查看数: 1751 | 评论数: 3 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2015-5-25 18:42

正文摘要:

问题如图所示: 怎样让这些“□”替换成其他字体下的日文字呢?

回复

长弓巡洋集团 发表于 2015-5-25 19:50:32
本帖最后由 长弓巡洋集团 于 2015-5-25 19:53 编辑

[pre lang="ruby"]$_PS0 = {} if $_PS0 == nil  
$_PS0["Draw_Text_DF"] = 20120127.2
module PS0
  module Draw_Text_DF
    DO_PRE_CHECK = true
    Font.default_name = "simhei"
    ENG_FONT = "calibri"#(变为日文字体)
    DO_CHANGE = 0
    DRAW_TYPE = 0
    REG1 = "0-9A-Za-z "  #(在这行写入需要的片假名)               
    REG2 = ";:?!@#%^&*(){}[]=-+_/|,.<>" #(在这行写入需要的平假名)   
    REG3 = "\"\'\$\\"  #(在这行写入需要的特殊符号)   
    REG = /[#{REG1 + (REG2+REG3).gsub!(/./) { "\\" + $& }}]/
  end
end
class Bitmap
  alias old_draw_text draw_text
  def draw_text(*args)
   if self.font.name != Font.default_name && PS0::Draw_Text_DF::DO_CHANGE == 1
    old_draw_text(*args)
  else
     last_font_name = self.font.name
     if args[0].is_a?(Rect)
     rect, str, align = args[0..2]
     x, y, width, height = rect.x, rect.y, rect.width, rect.height
    else
      x, y, width, height, str, align = args[0..5]
    end
    str = str.to_s
    align = 0 if align.nil?
    if PS0::Draw_Text_DF::DO_PRE_CHECK == true
      if str.scan(PS0::Draw_Text_DF::REG).size == 0
        old_draw_text(*args)
      elsif str.scan(PS0::Draw_Text_DF::REG).size == str.size
        change_to_eng_font
        old_draw_text(*args)
      else
        case PS0::Draw_Text_DF::DRAW_TYPE
        when 0 ; draw_text_1by1(x, y, width, height, str, align)
        when 1 ; draw_text_npass(x, y, width, height, str, align)
        end
      end
    else
      case PS0::Draw_Text_DF::DRAW_TYPE
      when 0 ; draw_text_1by1(x, y, width, height, str, align)
      when 1 ; draw_text_npass(x, y, width, height, str, align)
      end
    end

    self.font.name = last_font_name
  end
  end
  def draw_text_1by1(x, y, width, height, str, align)
    last_font_name = self.font.name
    ox = 0
    if align == 0
      bx = x
    else
      str1 = str.clone.gsub!(PS0::Draw_Text_DF::REG)            { "" }
      str2 = str.clone.gsub!(/(?!#{PS0::Draw_Text_DF::REG})./)  { "" }
      str_width = text_size(str1).width
      change_to_eng_font
      str_width += text_size(str2).width
      case align
      when 0
        bx = x
      when 1
        bx = x + (width - str_width) / 2
      when 2
        bx = x + (width - str_width)
      end
    end
    str += "\P"
    while (!(c = str.slice!(/./m)).nil?)
      self.font.name = last_font_name
      change_to_eng_font if c.slice(PS0::Draw_Text_DF::REG)
       if c == "\P"
        c = ""
      else
        old_draw_text((bx + ox), y, width, height, c, 0)
        ox += text_size(c).width
      end
    end
  end
  def change_to_eng_font
    self.font.name = PS0::Draw_Text_DF::ENG_FONT
  end
end[/pre]

看括号里的注释
长弓巡洋集团 发表于 2015-5-25 19:27:38
找一个日文字体粘贴进去(但是中文还有木有就不清楚了)

点评

但是这个要怎么操作呢?我不懂脚本。  发表于 2015-5-25 19:47
请参考中英双字体脚本,把英文字符替换为所有片假字  发表于 2015-5-25 19:45
不是这个意思……我是希望中文能够用一种字体,日文能够自动替换成另一种……  发表于 2015-5-25 19:40

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

在本版发帖返回顶部