Project

General

Profile

Defect #6505 » japanese.rb.patch

Jun NAITOH, 2011-03-21 04:12

View differences:

vendor/plugins/rfpdf/lib/rfpdf/japanese.rb 2011-03-07 14:44:39.000000000 -0500 → vendor/plugins/rfpdf/lib/rfpdf/japanese.rb 2011-03-19 01:46:10.000000000 -0400
def MultiCell(w,h,txt,border=0,align='L',fill=0)
if(@CurrentFont['type']=='Type0')
SJISMultiCell(w,h,txt,border,align,fill)
MBMultiCell(w,h,txt,border,align,fill)
else
super(w,h,txt,border,align,fill)
end
end
def SJISMultiCell(w,h,txt,border=0,align='L',fill=0)
def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
#Multi-byte version of MultiCell() for UTF-8
#Output text with automatic or explicit line breaks
cw=@CurrentFont['cw']
if(w==0)
......
b2=''
if(border.to_s.index('L'))
b2+='L'
end
end
if(border.to_s.index('R'))
b2+='R'
end
end
b=border.to_s.index('T') ? b2+'T' : b2
end
end
sep=-1
i=0
j=0
l=0
l=0 # Automatic line break counter
nl=1
while(i<nb)
#Get next character
c=s[i]
o=c #o=ord(c)
if(o==10)
#Explicit line break
case s[i]
when 0x00 .. 0x09, 0x0b .. 0x7f # UTF-8 1byte ASCII
ascii=true
n=1
l+=cw[s[i].chr] || 0
if(s[i].chr==' ')
sep=i
end
when 0x0a # Explicit line break "\n"
Cell(w,h,s[j,i-j],b,2,align,fill)
i+=1
sep=-1
......
nl+=1
if(border and nl==2)
b=b2
end
end
next
end
if(o<128)
#ASCII
l+=cw[c.chr]
n=1
if(o==32)
sep=i
end
elsif(o>=161 and o<=223)
#Half-width katakana
when 0xc0 .. 0xdf # UTF-8 2byte
n=2
l+=500
n=1
sep=i
else
#Full-width character
when 0xe0 .. 0xee # UTF-8 3byte
n=3
l+=1000 # Full-width character
sep=i
when 0xef # UTF-8 3byte
n=3
if((s[i+1]==0xbd and (s[i+2]>=0xa1 and s[i+2]<=0xbf)) or (s[i+1]==0xbe and(s[i+2]>=0x80 and s[i+2]<=0x9f)))
l+=500 # Half-width katakana (UTF-8: EFBDA1 - EFBDBF, EFBE80 - EFBE9F)
else
l+=1000 # Full-width character
end
sep=i
when 0xf0 .. 0xf7 # UTF-8 4byte
n=4
l+=1000
sep=i
when 0xf8 .. 0xfb # UTF-8 5byte
n=5
l+=1000
sep=i
when 0xfc .. 0xfd # UTF-8 6byte
n=6
l+=1000
n=2
sep=i
else
i+=1
next
end
if(l>wmax)
#Automatic line break
if(sep==-1 or i==j)
if(i==j)
i+=n
end
end
Cell(w,h,s[j,i-j],b,2,align,fill)
else
Cell(w,h,s[j,sep-j],b,2,align,fill)
......
nl+=1
if(border and nl==2)
b=b2
end
end
else
i+=n
if(o>=128)
if(!ascii)
sep=i
end
end
(2-2/9)