--- a/vendor/plugins/rfpdf/lib/rfpdf/japanese.rb 2011-03-07 14:44:39.000000000 -0500 +++ b/vendor/plugins/rfpdf/lib/rfpdf/japanese.rb 2011-03-19 01:46:10.000000000 -0400 @@ -120,13 +120,14 @@ 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) @@ -148,24 +149,28 @@ 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=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) @@ -212,10 +231,10 @@ nl+=1 if(border and nl==2) b=b2 - end + end else i+=n - if(o>=128) + if(!ascii) sep=i end end