Project

General

Profile

Defect #6505 » chinese.rb.patch

Jun NAITOH, 2011-03-21 04:12

View differences:

vendor/plugins/rfpdf/lib/rfpdf/chinese.rb 2011-03-07 14:44:39.000000000 -0500 → vendor/plugins/rfpdf/lib/rfpdf/chinese.rb 2011-03-19 01:44:43.000000000 -0400
MBMultiCell(w,h,txt,border,align,fill)
else
super(w,h,txt,border,align,fill)
end
end
end
def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
#Multi-byte version of MultiCell()
#Multi-byte version of MultiCell() for UTF-8
#Output text with automatic or explicit line breaks
cw=@CurrentFont['cw']
if(w==0)
w=@w-@rMargin-@x
end
end
wmax=(w-2*@cMargin)*1000/@FontSize
s=txt.gsub("\r",'')
nb=s.length
if(nb>0 and s[nb-1]=="\n")
nb-=1
end
end
b=0
if(border)
if(border==1)
......
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]
#Check if ASCII or MB
ascii=(c<128)
if(c.chr=="\n")
#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(!ascii)
when 0xc0 .. 0xdf # UTF-8 2byte
n=2
l+=500
sep=i
ls=l
elsif(c==' ')
when 0xe0 .. 0xee # UTF-8 3byte
n=3
l+=1000 # Full-width character
sep=i
ls=l
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
sep=i
else
i+=1
next
end
l+=ascii ? (cw[c.chr] || 0) : 1100
if(l>wmax)
#Automatic line break
if(sep==-1 or i==j)
if(i==j)
i+=ascii ? 1 : 3
end
i+=n
end
Cell(w,h,s[j,i-j],b,2,align,fill)
else
Cell(w,h,s[j,sep-j],b,2,align,fill)
......
sep=-1
j=i
l=0
# nl+=1
nl+=1
if(border and nl==2)
b=b2
end
else
i+=ascii ? 1 : 3
i+=n
if(!ascii)
sep=i
end
end
end
#Last chunk
if(border and not border.to_s.index('B').nil?)
b+='B'
end
end
Cell(w,h,s[j,i-j],b,2,align,fill)
@x=@lMargin
end
(4-4/9)