Im trying to determine the physical pixel width of a string.
for example:
FONT_SIZE = 10
str="123456789"
width = str.length * FONT_SIZE # which will be 9 * 10 = 90px
PROBLEM: But for chinese, japanese or korean:
FONT_SIZE = 10
str="一二三四五六七八九"
width = str.length * FONT_SIZE # this still result in 90 (9*10)
But it really should be 180 as they are 2 chars with for each char.
How do I make this function (returns true/false)?
def is_wide_char char
#how to?
end
class String
def wlength
l = 0
self.each{|c| is_wide_char(c)? l+=2: l+=1}
l
end
end