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
120 120

  
121 121
  def MultiCell(w,h,txt,border=0,align='L',fill=0)
122 122
  	if(@CurrentFont['type']=='Type0')
123
  		SJISMultiCell(w,h,txt,border,align,fill)
123
  		MBMultiCell(w,h,txt,border,align,fill)
124 124
  	else
125 125
  		super(w,h,txt,border,align,fill)
126 126
  	end  
127 127
  end
128 128

  
129
  def SJISMultiCell(w,h,txt,border=0,align='L',fill=0)
129
  def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
130
  	#Multi-byte version of MultiCell() for UTF-8
130 131
  	#Output text with automatic or explicit line breaks
131 132
  	cw=@CurrentFont['cw']
132 133
  	if(w==0)
......
148 149
  			b2=''
149 150
  			if(border.to_s.index('L'))
150 151
  				b2+='L'
151
      	end  
152
  			end
152 153
  			if(border.to_s.index('R'))
153 154
  				b2+='R'
154
      	end  
155
  			end
155 156
  			b=border.to_s.index('T') ? b2+'T' : b2
156 157
  		end
157 158
  	end
158 159
  	sep=-1
159 160
  	i=0
160 161
  	j=0
161
  	l=0
162
  	l=0    # Automatic line break counter
162 163
  	nl=1
163 164
  	while(i<nb)
164
  		#Get next character
165
  		c=s[i]
166
  		o=c #o=ord(c)
167
  		if(o==10)
168
  			#Explicit line break
165
  		case s[i]
166
  		when 0x00 .. 0x09, 0x0b .. 0x7f	# UTF-8 1byte ASCII
167
  			ascii=true
168
	  		n=1
169
  			l+=cw[s[i].chr] || 0
170
  			if(s[i].chr==' ')
171
  				sep=i
172
  			end
173
  		when 0x0a	# Explicit line break "\n"
169 174
  			Cell(w,h,s[j,i-j],b,2,align,fill)
170 175
  			i+=1
171 176
  			sep=-1
......
174 179
  			nl+=1
175 180
  			if(border and nl==2)
176 181
  				b=b2
177
      	end  
182
  			end
178 183
  			next
179
  		end
180
  		if(o<128)
181
  			#ASCII
182
  			l+=cw[c.chr]
183
  			n=1
184
  			if(o==32)
185
  				sep=i
186
      	end  
187
  		elsif(o>=161 and o<=223)
188
  			#Half-width katakana
184
  		when 0xc0 .. 0xdf	# UTF-8 2byte
185
  			n=2
189 186
  			l+=500
190
  			n=1
191 187
  			sep=i
192
  		else
193
  			#Full-width character
188
  		when 0xe0 .. 0xee	# UTF-8 3byte
189
  			n=3
190
  			l+=1000		# Full-width character
191
  			sep=i
192
  		when 0xef		# UTF-8 3byte
193
  			n=3
194
  			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)))
195
  				l+=500	# Half-width katakana (UTF-8: EFBDA1 - EFBDBF, EFBE80 - EFBE9F)
196
  			else
197
  				l+=1000	# Full-width character
198
  			end
199
  			sep=i
200
  		when 0xf0 .. 0xf7	# UTF-8 4byte
201
  			n=4
202
  			l+=1000
203
  			sep=i
204
  		when 0xf8 .. 0xfb	# UTF-8 5byte
205
  			n=5
206
  			l+=1000
207
  			sep=i
208
  		when 0xfc .. 0xfd	# UTF-8 6byte
209
  			n=6
194 210
  			l+=1000
195
  			n=2
196 211
  			sep=i
212
  		else
213
	  		i+=1
214
  			next
197 215
  		end
216

  
198 217
  		if(l>wmax)
199 218
  			#Automatic line break
200 219
  			if(sep==-1 or i==j)
201 220
  				if(i==j)
202 221
  					i+=n
203
        	end  
222
  				end
204 223
  				Cell(w,h,s[j,i-j],b,2,align,fill)
205 224
  			else
206 225
  				Cell(w,h,s[j,sep-j],b,2,align,fill)
......
212 231
  			nl+=1
213 232
  			if(border and nl==2)
214 233
  				b=b2
215
      	end  
234
  			end
216 235
  		else
217 236
  			i+=n
218
  			if(o>=128)
237
  			if(!ascii)
219 238
  				sep=i
220 239
  			end
221 240
  		end
(2-2/9)