赞 | 0 |
VIP | 20 |
好人卡 | 50 |
积分 | 66 |
经验 | 109503 |
最后登录 | 2023-5-23 |
在线时间 | 2492 小时 |
Lv4.逐梦者
- 梦石
- 3
- 星屑
- 3605
- 在线时间
- 2492 小时
- 注册时间
- 2014-10-5
- 帖子
- 1768
|
本帖最后由 长弓巡洋集团 于 2015-5-25 19:53 编辑
$_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
$_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
看括号里的注释 |
|