Project

General

Profile

Patch #8312 ยป switch_from_fpdf_to_tcpdf_r5670.patch

Jun NAITOH, 2011-05-06 16:06

View differences:

vendor/plugins/rfpdf/lib/fpdf/chinese.rb (working copy)
116 116
  end
117 117

  
118 118
  def GetStringWidth(s)
119
  	if(@CurrentFont['type']=='Type0')
119
  	if(@current_font['type']=='Type0')
120 120
  		return GetMBStringWidth(s)
121 121
  	else
122 122
  		return super(s)
......
126 126
  def GetMBStringWidth(s)
127 127
  	#Multi-byte version of GetStringWidth()
128 128
  	l=0
129
  	cw=@CurrentFont['cw']
129
  	cw=@current_font['cw']
130 130
  	nb=s.length
131 131
  	i=0
132 132
  	while(i<nb)
......
139 139
  			i+=2
140 140
  		end
141 141
  	end
142
  	return l*@FontSize/1000
142
  	return l*@font_size/1000
143 143
  end
144 144

  
145 145
  def MultiCell(w,h,txt,border=0,align='L',fill=0)
146
  	if(@CurrentFont['type']=='Type0')
146
  	if(@current_font['type']=='Type0')
147 147
  		MBMultiCell(w,h,txt,border,align,fill)
148 148
  	else
149 149
  		super(w,h,txt,border,align,fill)
......
152 152

  
153 153
  def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
154 154
  	#Multi-byte version of MultiCell()
155
  	cw=@CurrentFont['cw']
155
  	cw=@current_font['cw']
156 156
  	if(w==0)
157
  		w=@w-@rMargin-@x
157
  		w=@w-@r_margin-@x
158 158
		end
159
  	wmax=(w-2*@cMargin)*1000/@FontSize
159
  	wmax=(w-2*@c_margin)*1000/@font_size
160 160
  	s=txt.gsub("\r",'')
161 161
  	nb=s.length
162 162
  	if(nb>0 and s[nb-1]=="\n")
......
233 233
  		b+='B'
234 234
		end
235 235
  	Cell(w,h,s[j,i-j],b,2,align,fill)
236
  	@x=@lMargin
236
  	@x=@l_margin
237 237
  end
238 238

  
239 239
  def Write(h,txt,link='')
240
  	if(@CurrentFont['type']=='Type0')
240
  	if(@current_font['type']=='Type0')
241 241
  		MBWrite(h,txt,link)
242 242
  	else
243 243
  		super(h,txt,link)
......
246 246

  
247 247
  def MBWrite(h,txt,link)
248 248
  	#Multi-byte version of Write()
249
  	cw=@CurrentFont['cw']
250
  	w=@w-@rMargin-@x
251
  	wmax=(w-2*@cMargin)*1000/@FontSize
249
  	cw=@current_font['cw']
250
  	w=@w-@r_margin-@x
251
  	wmax=(w-2*@c_margin)*1000/@font_size
252 252
  	s=txt.gsub("\r",'')
253 253
  	nb=s.length
254 254
  	sep=-1
......
269 269
  			j=i
270 270
  			l=0
271 271
  			if(nl==1)
272
  				@x=@lMargin
273
  				w=@w-@rMargin-@x
274
  				wmax=(w-2*@cMargin)*1000/@FontSize
272
  				@x=@l_margin
273
  				w=@w-@r_margin-@x
274
  				wmax=(w-2*@c_margin)*1000/@font_size
275 275
  			end
276 276
  			nl+=1
277 277
  			next
......
283 283
  		if(l>wmax)
284 284
  			#Automatic line break
285 285
  			if(sep==-1 or i==j)
286
  				if(@x>@lMargin)
286
  				if(@x>@l_margin)
287 287
  					#Move to next line
288
  					@x=@lMargin
288
  					@x=@l_margin
289 289
  					@y+=h
290
  					w=@w-@rMargin-@x
291
  					wmax=(w-2*@cMargin)*1000/@FontSize
290
  					w=@w-@r_margin-@x
291
  					wmax=(w-2*@c_margin)*1000/@font_size
292 292
  					i+=1
293 293
  					nl+=1
294 294
  					next
......
305 305
  			j=i
306 306
  			l=0
307 307
  			if(nl==1)
308
  				@x=@lMargin
309
  				w=@w-@rMargin-@x
310
  				wmax=(w-2*@cMargin)*1000/@FontSize
308
  				@x=@l_margin
309
  				w=@w-@r_margin-@x
310
  				wmax=(w-2*@c_margin)*1000/@font_size
311 311
  			end
312 312
  			nl+=1
313 313
  		else
......
316 316
  	end
317 317
  	#Last chunk
318 318
  	if(i!=j)
319
  		Cell(l/1000*@FontSize,h,s[j,i-j],0,0,'',0,link)
319
  		Cell(l/1000*@font_size,h,s[j,i-j],0,0,'',0,link)
320 320
		end
321 321
  end
322 322

  
......
332 332
  	end
333 333
  	# mqr=get_magic_quotes_runtime()
334 334
  	# set_magic_quotes_runtime(0)
335
    @FontFiles.each_pair do |file, info|
335
    @font_files.each_pair do |file, info|
336 336
  		#Font file embedding
337 337
  		newobj()
338
  		@FontFiles[file]['n']=@n
338
  		@font_files[file]['n']=@n
339 339
  		if(defined('FPDF_FONTPATH'))
340 340
  			file=FPDF_FONTPATH+file
341 341
			end
......
411 411
  				end
412 412
  				file=font['file']
413 413
  				if(file)
414
  					s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@FontFiles[file]['n']+' 0 R'
414
  					s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@font_files[file]['n']+' 0 R'
415 415
  				end
416 416
  				out(s+'>>')
417 417
  				out('endobj')
vendor/plugins/rfpdf/lib/fpdf/korean.rb (working copy)
85 85
  end
86 86

  
87 87
  def GetStringWidth(s)
88
  	if(@CurrentFont['type']=='Type0')
88
  	if(@current_font['type']=='Type0')
89 89
  		return GetMBStringWidth(s)
90 90
  	else
91 91
  		return super(s)
......
95 95
  def GetMBStringWidth(s)
96 96
  	#Multi-byte version of GetStringWidth()
97 97
  	l=0
98
  	cw=@CurrentFont['cw']
98
  	cw=@current_font['cw']
99 99
  	nb=s.length
100 100
  	i=0
101 101
  	while(i<nb)
......
108 108
  			i+=2
109 109
  		end
110 110
  	end
111
  	return l*@FontSize/1000
111
  	return l*@font_size/1000
112 112
  end
113 113

  
114 114
  def MultiCell(w,h,txt,border=0,align='L',fill=0)
115
  	if(@CurrentFont['type']=='Type0')
115
  	if(@current_font['type']=='Type0')
116 116
  		MBMultiCell(w,h,txt,border,align,fill)
117 117
  	else
118 118
  		super(w,h,txt,border,align,fill)
......
121 121

  
122 122
  def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
123 123
  	#Multi-byte version of MultiCell()
124
  	cw=@CurrentFont['cw']
124
  	cw=@current_font['cw']
125 125
  	if(w==0)
126
  		w=@w-@rMargin-@x
126
  		w=@w-@r_margin-@x
127 127
    end
128
  	wmax=(w-2*@cMargin)*1000/@FontSize
128
  	wmax=(w-2*@c_margin)*1000/@font_size
129 129
  	s=txt.gsub("\r",'')
130 130
  	nb=s.length
131 131
  	if(nb>0 and s[nb-1]=="\n")
......
202 202
  		b+='B'
203 203
    end
204 204
  	Cell(w,h,s[j,i-j],b,2,align,fill)
205
  	@x=@lMargin
205
  	@x=@l_margin
206 206
  end
207 207

  
208 208
  def Write(h,txt,link='')
209
  	if(@CurrentFont['type']=='Type0')
209
  	if(@current_font['type']=='Type0')
210 210
  		MBWrite(h,txt,link)
211 211
  	else
212 212
  		super(h,txt,link)
......
215 215

  
216 216
  def MBWrite(h,txt,link)
217 217
  	#Multi-byte version of Write()
218
  	cw=@CurrentFont['cw']
219
  	w=@w-@rMargin-@x
220
  	wmax=(w-2*@cMargin)*1000/@FontSize
218
  	cw=@current_font['cw']
219
  	w=@w-@r_margin-@x
220
  	wmax=(w-2*@c_margin)*1000/@font_size
221 221
  	s=txt.gsub("\r",'')
222 222
  	nb=s.length
223 223
  	sep=-1
......
238 238
  			j=i
239 239
  			l=0
240 240
  			if(nl==1)
241
  				@x=@lMargin
242
  				w=@w-@rMargin-@x
243
  				wmax=(w-2*@cMargin)*1000/@FontSize
241
  				@x=@l_margin
242
  				w=@w-@r_margin-@x
243
  				wmax=(w-2*@c_margin)*1000/@font_size
244 244
  			end
245 245
  			nl+=1
246 246
  			next
......
252 252
  		if(l>wmax)
253 253
  			#Automatic line break
254 254
  			if(sep==-1 or i==j)
255
  				if(@x>@lMargin)
255
  				if(@x>@l_margin)
256 256
  					#Move to next line
257
  					@x=@lMargin
257
  					@x=@l_margin
258 258
  					@y+=h
259
  					w=@w-@rMargin-@x
260
  					wmax=(w-2*@cMargin)*1000/@FontSize
259
  					w=@w-@r_margin-@x
260
  					wmax=(w-2*@c_margin)*1000/@font_size
261 261
  					i+=1
262 262
  					nl+=1
263 263
  					next
......
274 274
  			j=i
275 275
  			l=0
276 276
  			if(nl==1)
277
  				@x=@lMargin
278
  				w=@w-@rMargin-@x
279
  				wmax=(w-2*@cMargin)*1000/@FontSize
277
  				@x=@l_margin
278
  				w=@w-@r_margin-@x
279
  				wmax=(w-2*@c_margin)*1000/@font_size
280 280
  			end
281 281
  			nl+=1
282 282
  		else
......
285 285
  	end
286 286
  	#Last chunk
287 287
  	if(i!=j)
288
  		Cell(l/1000*@FontSize,h,s[j,i-j],0,0,'',0,link)
288
  		Cell(l/1000*@font_size,h,s[j,i-j],0,0,'',0,link)
289 289
    end
290 290
  end
291 291

  
......
301 301
  	end
302 302
  	# mqr=get_magic_quotes_runtime()
303 303
  	# set_magic_quotes_runtime(0)
304
    @FontFiles.each_pair do |file, info|
304
    @font_files.each_pair do |file, info|
305 305
  		#Font file embedding
306 306
  		newobj()
307
  		@FontFiles[file]['n']=@n
307
  		@font_files[file]['n']=@n
308 308
  		if(defined('FPDF_FONTPATH'))
309 309
  			file=FPDF_FONTPATH+file
310 310
      end
......
378 378
          end
379 379
  				file=font['file']
380 380
  				if(file)
381
  					s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@FontFiles[file]['n']+' 0 R'
381
  					s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@font_files[file]['n']+' 0 R'
382 382
          end
383 383
  				out(s+'>>')
384 384
  				out('endobj')
vendor/plugins/rfpdf/lib/fpdf/japanese.rb (working copy)
86 86
  end
87 87

  
88 88
  def GetStringWidth(s)
89
  	if(@CurrentFont['type']=='Type0')
89
  	if(@current_font['type']=='Type0')
90 90
  		return GetSJISStringWidth(s)
91 91
  	else
92 92
  		return super(s)
......
96 96
  def GetSJISStringWidth(s)
97 97
  	#SJIS version of GetStringWidth()
98 98
  	l=0
99
  	cw=@CurrentFont['cw']
99
  	cw=@current_font['cw']
100 100
  	nb=s.length
101 101
  	i=0
102 102
  	while(i<nb)
......
115 115
  			i+=2
116 116
  		end
117 117
  	end
118
  	return l*@FontSize/1000
118
  	return l*@font_size/1000
119 119
  end
120 120

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

  
129 129
  def SJISMultiCell(w,h,txt,border=0,align='L',fill=0)
130 130
  	#Output text with automatic or explicit line breaks
131
  	cw=@CurrentFont['cw']
131
  	cw=@current_font['cw']
132 132
  	if(w==0)
133
  		w=@w-@rMargin-@x
133
  		w=@w-@r_margin-@x
134 134
  	end  
135
  	wmax=(w-2*@cMargin)*1000/@FontSize
135
  	wmax=(w-2*@c_margin)*1000/@font_size
136 136
  	s=txt.gsub("\r",'')
137 137
  	nb=s.length
138 138
  	if(nb>0 and s[nb-1]=="\n")
......
221 221
  		b+='B'
222 222
  	end  
223 223
  	Cell(w,h,s[j,i-j],b,2,align,fill)
224
  	@x=@lMargin
224
  	@x=@l_margin
225 225
  end
226 226

  
227 227
  def Write(h,txt,link='')
228
  	if(@CurrentFont['type']=='Type0')
228
  	if(@current_font['type']=='Type0')
229 229
 		SJISWrite(h,txt,link)
230 230
 	else
231 231
 		super(h,txt,link)
......
234 234

  
235 235
  def SJISWrite(h,txt,link)
236 236
  	#SJIS version of Write()
237
  	cw=@CurrentFont['cw']
238
  	w=@w-@rMargin-@x
239
  	wmax=(w-2*@cMargin)*1000/@FontSize
237
  	cw=@current_font['cw']
238
  	w=@w-@r_margin-@x
239
  	wmax=(w-2*@c_margin)*1000/@font_size
240 240
  	s=txt.gsub("\r",'')
241 241
  	nb=s.length
242 242
  	sep=-1
......
257 257
  			l=0
258 258
  			if(nl==1)
259 259
  				#Go to left margin
260
  				@x=@lMargin
261
  				w=@w-@rMargin-@x
262
  				wmax=(w-2*@cMargin)*1000/@FontSize
260
  				@x=@l_margin
261
  				w=@w-@r_margin-@x
262
  				wmax=(w-2*@c_margin)*1000/@font_size
263 263
  			end
264 264
  			nl+=1
265 265
  			next
......
285 285
  		if(l>wmax)
286 286
  			#Automatic line break
287 287
  			if(sep==-1 or i==j)
288
  				if(@x>@lMargin)
288
  				if(@x>@l_margin)
289 289
  					#Move to next line
290
  					@x=@lMargin
290
  					@x=@l_margin
291 291
  					@y+=h
292
  					w=@w-@rMargin-@x
293
  					wmax=(w-2*@cMargin)*1000/@FontSize
292
  					w=@w-@r_margin-@x
293
  					wmax=(w-2*@c_margin)*1000/@font_size
294 294
  					i+=n
295 295
  					nl+=1
296 296
  					next
......
307 307
  			j=i
308 308
  			l=0
309 309
  			if(nl==1)
310
  				@x=@lMargin
311
  				w=@w-@rMargin-@x
312
  				wmax=(w-2*@cMargin)*1000/@FontSize
310
  				@x=@l_margin
311
  				w=@w-@r_margin-@x
312
  				wmax=(w-2*@c_margin)*1000/@font_size
313 313
  			end
314 314
  			nl+=1
315 315
  		else
......
321 321
  	end
322 322
  	#Last chunk
323 323
  	if(i!=j)
324
  		Cell(l/1000*@FontSize,h,s[j,i-j],0,0,'',0,link)
324
  		Cell(l/1000*@font_size,h,s[j,i-j],0,0,'',0,link)
325 325
  	end  
326 326
  end
327 327
  
......
337 337
  	end
338 338
  	# mqr=get_magic_quotes_runtime()
339 339
  	# set_magic_quotes_runtime(0)
340
    @FontFiles.each_pair do |file, info|
340
    @font_files.each_pair do |file, info|
341 341
  		#Font file embedding
342 342
  		newobj()
343
  		@FontFiles[file]['n']=@n
343
  		@font_files[file]['n']=@n
344 344
  		if(defined('FPDF_FONTPATH'))
345 345
  			file=FPDF_FONTPATH+file
346 346
    	end  
......
414 414
        	end  
415 415
  				file=font['file']
416 416
  				if(file)
417
  					s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@FontFiles[file]['n']+' 0 R'
417
  					s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@font_files[file]['n']+' 0 R'
418 418
        	end  
419 419
  				out(s+'>>')
420 420
  				out('endobj')
vendor/plugins/rfpdf/lib/tcpdf.rb (working copy)
669 669
	# @since 1.4
670 670
	# @see PageNo(), Footer()
671 671
	#
672
	def alias_nb_pages(alias_nb ='{nb}')
672
	def AliasNbPages(alias_nb ='{nb}')
673 673
		#Define an alias for total number of pages
674 674
		@alias_nb_pages = escapetext(alias_nb)
675 675
	end
676
  alias_method :alias_nb_pages, :AliasNbPages
676 677

  
677 678
	#
678 679
	# This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
......
1154 1155
			end
1155 1156
		else
1156 1157
		  s.each_byte do |c|
1157
				if cw[c]
1158
					w += cw[c];
1159
				elsif cw[?c]
1160
					w += cw[?c]
1158
				if cw[c.chr]
1159
					w += cw[c.chr];
1160
				elsif cw[?c.chr]
1161
					w += cw[?c.chr]
1161 1162
				end
1162 1163
			end
1163 1164
		end
......
1433 1434
		end
1434 1435

  
1435 1436
		# try to add font (if not already added)
1436
		if (@is_unicode)
1437
			AddFont(family, style);
1438
		end
1437
		AddFont(family, style);
1439 1438
		
1440 1439
		#Test if font is already selected
1441 1440
		if ((@font_family == family) and (@font_style == style) and (@font_size_pt == size))
......
2293 2292
	def putpages()
2294 2293
		nb = @page;
2295 2294
		if (@alias_nb_pages)
2296
			nbstr = UTF8ToUTF16BE(nb, false);
2295
			nbstr = UTF8ToUTF16BE(nb.to_s, false);
2297 2296
			#Replace number of pages
2298 2297
			1.upto(nb) do |n|
2299 2298
				@pages[n].gsub!(@alias_nb_pages, nbstr)
lib/redmine/export/pdf.rb (working copy)
29 29
      include ActionView::Helpers::TextHelper
30 30
      include ActionView::Helpers::NumberHelper
31 31

  
32
      class ITCPDF < TCPDF
32
      class IFPDF < TCPDF
33 33
        include Redmine::I18n
34 34
        attr_accessor :footer_date
35 35

  
36 36
        def initialize(lang)
37
          super()
38
          set_language_if_valid lang
39
          @font_for_content = 'FreeSans'
40
          @font_for_footer  = 'FreeSans'
41
          SetCreator(Redmine::Info.app_name)
42
          SetFont(@font_for_content)
43
        end
44

  
45
        def SetFontStyle(style, size)
46
          SetFont(@font_for_content, style, size)
47
        end
48

  
49
        def SetTitle(txt)
50
          txt = begin
51
            utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
52
            hextxt = "<FEFF"  # FEFF is BOM
53
            hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
54
            hextxt << ">"
55
          rescue
56
            txt
57
          end || ''
58
          super(txt)
59
        end
60

  
61
        def textstring(s)
62
          # Format a text string
63
          if s =~ /^</  # This means the string is hex-dumped.
64
            return s
37
          pdf_encoding = l(:general_pdf_encoding).upcase
38
          if pdf_encoding == 'UTF-8'
39
            @unicode = true
65 40
          else
66
            return '('+escape(s)+')'
41
            @unicode = false
67 42
          end
68
        end
69

  
70
        alias RDMCell Cell
71
        alias RDMMultiCell MultiCell
72

  
73
        def Footer
74
          SetFont(@font_for_footer, 'I', 8)
75
          SetY(-15)
76
          SetX(15)
77
          RDMCell(0, 5, @footer_date, 0, 0, 'L')
78
          SetY(-15)
79
          SetX(-30)
80
          RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
81
        end
82
      end
83

  
84
      class IFPDF < FPDF
85
        include Redmine::I18n
86
        attr_accessor :footer_date
87

  
88
        def initialize(lang)
89
          super()
43
          super('P', 'mm', 'A4', @unicode, pdf_encoding )
90 44
          set_language_if_valid lang
91
          case l(:general_pdf_encoding).upcase
45
          case pdf_encoding
46
          when 'UTF-8'
47
            @font_for_content = 'FreeSans'
48
            @font_for_footer  = 'FreeSans'
92 49
          when 'CP949'
93 50
            extend(PDF_Korean)
94 51
            AddUHCFont()
......
143 100
        end
144 101

  
145 102
        def fix_text_encoding(txt)
103
          if (@unicode)
104
            return txt
105
          end
106

  
146 107
          txt ||= ''
147 108
          if txt.respond_to?(:force_encoding)
148 109
            txt.force_encoding('UTF-8')
......
183 144
          SetX(-30)
184 145
          RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
185 146
        end
186
        alias alias_nb_pages AliasNbPages
187 147
      end
188 148

  
189 149
      # Returns a PDF string of a list of issues
190 150
      def issues_to_pdf(issues, project, query)
191
        if l(:general_pdf_encoding).upcase != 'UTF-8'
192
          pdf = IFPDF.new(current_language)
193
        else
194
          pdf = ITCPDF.new(current_language)
195
        end
151
        pdf = IFPDF.new(current_language)
196 152
        title = query.new_record? ? l(:label_issue_plural) : query.name
197 153
        title = "#{project} - #{title}" if project
198 154
        pdf.SetTitle(title)
......
334 290

  
335 291
      # Returns a PDF string of a single issue
336 292
      def issue_to_pdf(issue)
337
        if l(:general_pdf_encoding).upcase != 'UTF-8'
338
          pdf = IFPDF.new(current_language)
339
        else
340
          pdf = ITCPDF.new(current_language)
341
        end
293
        pdf = IFPDF.new(current_language)
342 294
        pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
343 295
        pdf.alias_nb_pages
344 296
        pdf.footer_date = format_date(Date.today)
lib/redmine/helpers/gantt.rb (working copy)
507 507
      end if Object.const_defined?(:Magick)
508 508

  
509 509
      def to_pdf
510
        if l(:general_pdf_encoding).upcase != 'UTF-8'
511
          pdf = ::Redmine::Export::PDF::IFPDF.new(current_language)
512
        else
513
          pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
514
        end
510
        pdf = ::Redmine::Export::PDF::IFPDF.new(current_language)
515 511
        pdf.SetTitle("#{l(:label_gantt)} #{project}")
516 512
        pdf.alias_nb_pages
517 513
        pdf.footer_date = format_date(Date.today)
    (1-1/1)