--- a/vendor/plugins/rfpdf/lib/rfpdf/korean.rb 2011-03-07 14:44:39.000000000 -0500 +++ b/vendor/plugins/rfpdf/lib/rfpdf/korean.rb 2011-03-19 01:45:17.000000000 -0400 @@ -116,21 +116,22 @@ 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) @@ -139,27 +140,30 @@ b2='LR' else b2='' - if(border.to_s.index('L').nil?) + if(border.to_s.index('L')) b2+='L' - end - if(border.to_s.index('R').nil?) + end + if(border.to_s.index('R')) b2+='R' - end - b=border.to_s.index('T').nil? ? b2+'T' : b2 + 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=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] : 1000) || 0 + if(l>wmax) #Automatic line break if(sep==-1 or i==j) if(i==j) - i+=ascii ? 1 : 2 - 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) @@ -196,15 +224,18 @@ nl+=1 if(border and nl==2) b=b2 - end + end else - i+=ascii ? 1 : 2 - end + 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