Project

General

Profile

Defect #61 » chinese.rb_rfpdf115.patch

Jun NAITOH, 2011-03-27 09:34

View differences:

rfpdf/lib/fpdf/chinese.rb 2011-01-25 17:50:48.000000000 -0500 → rfpdf/lib/fpdf/chinese.rb 2011-03-23 17:48:05.000000000 -0400
37 37

  
38 38
module PDF_Chinese
39 39

  
40
  Big5_widths={' '=>250,'!'=>250,'"'=>408,'#'=>668,''=>490,'%'=>875,'&'=>698,'\''=>250,
40
  Big5_widths={' '=>250,'!'=>250,'"'=>408,'#'=>668,'$'=>490,'%'=>875,'&'=>698,'\''=>250,
41 41
  	'('=>240,')'=>240,'*'=>417,'+'=>667,','=>250,'-'=>313,'.'=>250,'/'=>520,'0'=>500,'1'=>500,
42
  	'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,''=>250,
42
  	'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,';'=>250,
43 43
  	'<'=>667,'='=>667,'>'=>667,'?'=>396,'@'=>921,'A'=>677,'B'=>615,'C'=>719,'D'=>760,'E'=>625,
44 44
  	'F'=>552,'G'=>771,'H'=>802,'I'=>354,'J'=>354,'K'=>781,'L'=>604,'M'=>927,'N'=>750,'O'=>823,
45 45
  	'P'=>563,'Q'=>823,'R'=>729,'S'=>542,'T'=>698,'U'=>771,'V'=>729,'W'=>948,'X'=>771,'Y'=>677,
46 46
  	'Z'=>635,'['=>344,'\\'=>520,']'=>344,'^'=>469,'_'=>500,'`'=>250,'a'=>469,'b'=>521,'c'=>427,
47 47
  	'd'=>521,'e'=>438,'f'=>271,'g'=>469,'h'=>531,'i'=>250,'j'=>250,'k'=>458,'l'=>240,'m'=>802,
48 48
  	'n'=>531,'o'=>500,'p'=>521,'q'=>521,'r'=>365,'s'=>333,'t'=>292,'u'=>521,'v'=>458,'w'=>677,
49
  	'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'end'=>480,'~'=>667}
49
  	'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'}'=>480,'~'=>667}
50 50

  
51
  GB_widths={' '=>207,'!'=>270,'"'=>342,'#'=>467,''=>462,'%'=>797,'&'=>710,'\''=>239,
51
  GB_widths={' '=>207,'!'=>270,'"'=>342,'#'=>467,'$'=>462,'%'=>797,'&'=>710,'\''=>239,
52 52
  	'('=>374,')'=>374,'*'=>423,'+'=>605,','=>238,'-'=>375,'.'=>238,'/'=>334,'0'=>462,'1'=>462,
53
  	'2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,''=>238,
53
  	'2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,';'=>238,
54 54
  	'<'=>605,'='=>605,'>'=>605,'?'=>344,'@'=>748,'A'=>684,'B'=>560,'C'=>695,'D'=>739,'E'=>563,
55 55
  	'F'=>511,'G'=>729,'H'=>793,'I'=>318,'J'=>312,'K'=>666,'L'=>526,'M'=>896,'N'=>758,'O'=>772,
56 56
  	'P'=>544,'Q'=>772,'R'=>628,'S'=>465,'T'=>607,'U'=>753,'V'=>711,'W'=>972,'X'=>647,'Y'=>620,
57 57
  	'Z'=>607,'['=>374,'\\'=>333,']'=>374,'^'=>606,'_'=>500,'`'=>239,'a'=>417,'b'=>503,'c'=>427,
58 58
  	'd'=>529,'e'=>415,'f'=>264,'g'=>444,'h'=>518,'i'=>241,'j'=>230,'k'=>495,'l'=>228,'m'=>793,
59 59
  	'n'=>527,'o'=>524,'p'=>524,'q'=>504,'r'=>338,'s'=>336,'t'=>277,'u'=>517,'v'=>450,'w'=>652,
60
  	'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'end'=>370,'~'=>605}
60
  	'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'}'=>370,'~'=>605}
61 61

  
62 62
  def AddCIDFont(family,style,name,cw,cMap,registry)
63 63
#ActionController::Base::logger.debug registry.to_a.join(":").to_s
......
132 132
  	while(i<nb)
133 133
  		c=s[i]
134 134
  		if(c<128)
135
  			l+=cw[c.chr]
135
  			l+=cw[c.chr] if cw[c.chr]
136 136
  			i+=1
137 137
  		else
138 138
  			l+=1000
......
170 170
  			b2='LR'
171 171
  		else
172 172
  			b2=''
173
  			if(border.index('L').nil?)
174
  				b2+='L'
175
				end
176
  			if(border.index('R').nil?)
177
  				b2+='R'
178
				end
179
  			b=border.index('T').nil? ? b2+'T' : b2
173
			b2='L' unless border.to_s.index('L').nil?
174
			b2=b2+'R' unless border.to_s.index('R').nil?
175
  			b=(border.to_s.index('T')) ? (b2+'T') : b2
180 176
  		end
181 177
  	end
182 178
  	sep=-1
......
189 185
  		c=s[i]
190 186
  		#Check if ASCII or MB
191 187
  		ascii=(c<128)
192
  		if(c=="\n")
188
  		if(c.chr=="\n")
193 189
  			#Explicit line break
194 190
  			Cell(w,h,s[j,i-j],b,2,align,fill)
195 191
  			i+=1
......
205 201
  		if(!ascii)
206 202
  			sep=i
207 203
  			ls=l
208
  		elsif(c==' ')
204
  		elsif(c.chr==' ')
209 205
  			sep=i
210 206
  			ls=l
211 207
  		end
212
  		l+=ascii ? cw[c.chr] : 1000
208
  		l+=(ascii ? cw[c.chr] : 1000) || 0
213 209
  		if(l>wmax)
214 210
  			#Automatic line break
215 211
  			if(sep==-1 or i==j)
......
219 215
  				Cell(w,h,s[j,i-j],b,2,align,fill)
220 216
  			else
221 217
  				Cell(w,h,s[j,sep-j],b,2,align,fill)
222
  				i=(s[sep]==' ') ? sep+1 : sep
218
  				i=(s[sep].chr==' ') ? sep+1 : sep
223 219
  			end
224 220
  			sep=-1
225 221
  			j=i
......
233 229
  		end
234 230
  	end
235 231
  	#Last chunk
236
  	if(border and not border.index('B').nil?)
232
  	if(border and not border.to_s.index('B').nil?)
237 233
  		b+='B'
238 234
		end
239 235
  	Cell(w,h,s[j,i-j],b,2,align,fill)
......
265 261
  		c=s[i]
266 262
  		#Check if ASCII or MB
267 263
  		ascii=(c<128)
268
  		if(c=="\n")
264
  		if(c.chr=="\n")
269 265
  			#Explicit line break
270 266
  			Cell(w,h,s[j,i-j],0,2,'',0,link)
271 267
  			i+=1
......
280 276
  			nl+=1
281 277
  			next
282 278
  		end
283
  		if(!ascii or c==' ')
279
  		if(!ascii or c.chr==' ')
284 280
  			sep=i
285 281
			end
286
  		l+=ascii ? cw[c.chr] : 1000
282
  		l+=(ascii ? cw[c.chr] : 1000) || 0
287 283
  		if(l>wmax)
288 284
  			#Automatic line break
289 285
  			if(sep==-1 or i==j)
......
303 299
  				Cell(w,h,s[j,i-j],0,2,'',0,link)
304 300
  			else
305 301
  				Cell(w,h,s[j,sep-j],0,2,'',0,link)
306
  				i=(s[sep]==' ') ? sep+1 : sep
302
  				i=(s[sep].chr==' ') ? sep+1 : sep
307 303
  			end
308 304
  			sep=-1
309 305
  			j=i
(24-24/46)