问题如图所示: 怎样让这些“□”替换成其他字体下的日文字呢?
$_PS0 = {} if $_PS0 == nil $_PS0["Draw_Text_DF"] = 20120127.2module 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!(/./) { "\\" + $& }}]/ endendclass 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 endend
$_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
折叠内容标题(非必须)
折叠内容
站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作
GMT+8, 2024-11-16 05:40
Powered by Discuz! X3.1
© 2001-2013 Comsenz Inc.