tcpdf.rb_r6129.patch

Jun NAITOH, 2011-06-29 16:43

Download (25 KB)

View differences:

vendor/plugins/rfpdf/lib/tcpdf.rb (working copy)
98 98
	attr_accessor :color_flag
99 99
	
100 100
	attr_accessor :default_table_columns
101

  
102
	attr_accessor :max_table_columns
101 103
	
102 104
	attr_accessor :default_font
103 105

  
......
141 143
	
142 144
	attr_accessor :links
143 145
	
144
	attr_accessor :listordered
146
	attr_accessor :list_ordered
145 147
	
146
	attr_accessor :listcount
148
	attr_accessor :list_count
147 149
	
148
	attr_accessor :lispacer
150
	attr_accessor :li_spacer
149 151
	
150 152
	attr_accessor :n
151 153
	
......
226 228
		@diffs ||= []
227 229
		@color_flag ||= false
228 230
  	@default_table_columns ||= 4
231
  	@table_columns ||= 0
232
  	@max_table_columns ||= []
233
  	@tr_id ||= 0
234
  	@max_td_page ||= []
235
  	@max_td_y ||= []
236
  	@t_columns ||= 0
229 237
  	@default_font ||= "FreeSans" if unicode
230 238
  	@default_font ||= "Helvetica"
231 239
		@draw_color ||= '0 G'
......
248 256
		@is_unicode = unicode
249 257
		@lasth ||= 0
250 258
		@links ||= []
251
  	@listordered ||= false
252
  	@listcount ||= 0
253
  	@lispacer ||= ""
259
  	@list_ordered ||= []
260
  	@list_count ||= []
261
  	@li_spacer ||= ""
262
  	@li_count ||= 0
263
  	@spacer ||= ""
264
  	@quote_count ||= 0
265
  	@prevquote_count ||= 0
266
  	@quote_top ||= []
267
  	@quote_page ||= []
254 268
		@n ||= 2
255 269
		@offsets ||= []
256 270
		@orientation_changes ||= []
......
272 286
  	@tempfontsize ||= 10
273 287
		@text_color ||= '0 g'
274 288
		@underline ||= false
289
		@deleted ||= false
275 290
		@ws ||= 0
276 291
		
277 292
		#Standard Unicode fonts
......
737 752
			Open();
738 753
		end
739 754
		family=@font_family;
740
		style=@font_style + (@underline ? 'U' : '');
755
		style=@font_style + (@underline ? 'U' : '') + (@deleted ? 'D' : '');
741 756
		size=@font_size_pt;
742 757
		lw=@line_width;
743 758
		dc=@draw_color;
......
1312 1327

  
1313 1328
		style=style.upcase
1314 1329
		style=style.gsub('U','');
1330
		style=style.gsub('D','');
1315 1331
		if (style == 'IB')
1316 1332
			style = 'BI';
1317 1333
		end
......
1394 1410
	# #Removes bold
1395 1411
	# :pdf->SetFont('');
1396 1412
	# #Times bold, italic and underlined 14
1397
	# :pdf->SetFont('Times','BIU');
1413
	# :pdf->SetFont('Times','BIUD');
1398 1414
	# </pre><br />
1399 1415
	# If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated.
1400 1416
	# @param string :family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained.
......
1426 1442
		else
1427 1443
			@underline=false;
1428 1444
		end
1445
		if (style.include?('D'))
1446
			@deleted=true;
1447
			style= style.gsub('D','');
1448
		else
1449
			@deleted=false;
1450
		end
1429 1451
		if (style=='IB')
1430 1452
			style='BI';
1431 1453
		end
......
1573 1595
		#Output a string
1574 1596
		s=sprintf('BT %.2f %.2f Td (%s) Tj ET', x * @k, (@h-y) * @k, escapetext(txt));
1575 1597
		if (@underline and (txt!=''))
1576
			s += ' ' + dounderline(x, y, txt);
1598
			s += ' ' + dolinetxt(x, y, txt);
1577 1599
		end
1578 1600
		if (@color_flag)
1579 1601
			s='q ' + @text_color + ' ' + s + ' Q';
......
1661 1683
		k=@k;
1662 1684
		if ((@y + h) > @page_break_trigger and !@in_footer and AcceptPageBreak())
1663 1685
			#Automatic page break
1664
			x = @x;
1665
			ws = @ws;
1666
			if (ws > 0)
1667
				@ws = 0;
1668
				out('0 Tw');
1686
			if @pages[@page+1].nil?
1687
				x = @x;
1688
				ws = @ws;
1689
				if (ws > 0)
1690
					@ws = 0;
1691
					out('0 Tw');
1692
				end
1693
				AddPage(@cur_orientation);
1694
				@x = x;
1695
				if (ws > 0)
1696
					@ws = ws;
1697
					out(sprintf('%.3f Tw', ws * k));
1698
				end
1699
			else
1700
				@page += 1;
1701
				@y=@t_margin;
1669 1702
			end
1670
			AddPage(@cur_orientation);
1671
			@x = x;
1672
			if (ws > 0)
1673
				@ws = ws;
1674
				out(sprintf('%.3f Tw', ws * k));
1675
			end
1676 1703
		end
1704

  
1677 1705
		if (w == 0)
1678 1706
			w = @w - @r_margin - @x;
1679 1707
		end
......
1717 1745
			txt2 = escapetext(txt);
1718 1746
			s<<sprintf('BT %.2f %.2f Td (%s) Tj ET', (@x + dx) * k, (@h - (@y + 0.5 * h + 0.3 * @font_size)) * k, txt2);
1719 1747
			if (@underline)
1720
				s<<' ' + dounderline(@x + dx, @y + 0.5 * h + 0.3 * @font_size, txt);
1748
				s<<' ' + dolinetxt(@x + dx, @y + 0.5 * h + 0.3 * @font_size, txt);
1721 1749
			end
1750
			if (@deleted)
1751
				s<<' ' + dolinetxt(@x + dx, @y + 0.3 * h + 0.2 * @font_size, txt);
1752
			end
1722 1753
			if (@color_flag)
1723 1754
				s<<' Q';
1724 1755
			end
......
1760 1791
		# save current position
1761 1792
		prevx = @x;
1762 1793
		prevy = @y;
1794
		prevpage = @page;
1763 1795
		 
1764 1796
		#Output text with automatic or explicit line breaks
1765 1797

  
......
1876 1908
			@x = @l_margin;
1877 1909
		elsif (ln == 0)
1878 1910
			# go to the top-right of the cell
1911
			@page = prevpage;
1879 1912
			@y = prevy;
1880 1913
			@x = prevx + w;
1881 1914
		elsif (ln == 2)
......
2075 2108
		else
2076 2109
			@y += h;
2077 2110
		end
2111

  
2112
		k=@k;
2113
		if (@y > @page_break_trigger and !@in_footer and AcceptPageBreak())
2114
			#Automatic page break
2115
			if @pages[@page+1].nil?
2116
				x = @x;
2117
				ws = @ws;
2118
				if (ws > 0)
2119
					@ws = 0;
2120
					out('0 Tw');
2121
				end
2122
				AddPage(@cur_orientation);
2123
				@x = x;
2124
				if (ws > 0)
2125
					@ws = ws;
2126
					out(sprintf('%.3f Tw', ws * k));
2127
				end
2128
			else
2129
				@page += 1;
2130
				@y=@t_margin;
2131
			end
2132
		end
2133

  
2078 2134
	end
2079 2135
  alias_method :ln, :Ln
2080 2136

  
......
2473 2529

  
2474 2530
  def putType0(font)
2475 2531
  	#Type0
2532
		newobj();
2476 2533
		out('<</Type /Font')
2477 2534
  	out('/Subtype /Type0')
2478 2535
  	out('/BaseFont /'+font['name']+'-'+font['cMap'])
......
2525 2582
			out('/Width ' + info['w'].to_s);
2526 2583
			out('/Height ' + info['h'].to_s);
2527 2584
			if (info['cs']=='Indexed')
2528
				out('/ColorSpace [/Indexed /DeviceRGB ' + (info['pal'].length/3-1) + ' ' + (@n+1) + ' 0 R]');
2585
				out('/ColorSpace [/Indexed /DeviceRGB ' + (info['pal'].length/3-1).to_s + ' ' + (@n+1).to_s + ' 0 R]');
2529 2586
			else
2530 2587
				out('/ColorSpace /' + info['cs']);
2531 2588
				if (info['cs']=='DeviceCMYK')
......
2553 2610
			#Palette
2554 2611
			if (info['cs']=='Indexed')
2555 2612
				newobj();
2556
				pal=(@compress) ? gzcompress(info['pal']) : :info['pal'];
2613
				pal=(@compress) ? gzcompress(info['pal']) : info['pal'];
2557 2614
				out('<<' + filter + '/Length ' + pal.length.to_s + '>>');
2558 2615
				putstream(pal);
2559 2616
				out('endobj');
......
2766 2823
	end
2767 2824

  
2768 2825
	#
2769
	# Underline text
2826
	# Underline and Deleted text
2770 2827
	# @access protected
2771 2828
	#
2772
	def dounderline(x, y, txt)
2829
	def dolinetxt(x, y, txt)
2773 2830
		up = @current_font['up'];
2774 2831
		ut = @current_font['ut'];
2775 2832
		w = GetStringWidth(txt) + @ws * txt.count(' ');
......
3350 3407
	
3351 3408
	#
3352 3409
	# Allows to preserve some HTML formatting.<br />
3353
	# Supports: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small
3410
	# Supports: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, ins, del, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small
3354 3411
	# @param string :html text to display
3355 3412
	# @param boolean :ln if true add a new line after text (default = true)
3356 3413
	# @param int :fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
......
3364 3421
		end
3365 3422
		
3366 3423
    @href = nil
3367
    @style = {}
3368
    html.gsub!(/[\t\r\n\f]/, "")#\0\x0B
3424
    @style = "";
3425
    @t_cells =  [[]];
3426
    @table_id = 0;
3427

  
3428
    # pre calculate
3369 3429
    html.split(/(<[^>]+>)/).each do |element|
3370 3430
      if "<" == element[0,1]
3371 3431
        #Tag
3372 3432
        if (element[1, 1] == '/')
3433
					closedHTMLTagCalc(element[2..-2].downcase);
3434
        else
3435
					#Extract attributes
3436
					# get tag name
3437
					tag = element.scan(/([a-zA-Z0-9]*)/).flatten.delete_if {|x| x.length == 0}
3438
					tag = tag[0].downcase;
3439
					
3440
					# get attributes
3441
					attr_array = element.scan(/([^=\s]*)=["\']?([^"\']*)["\']?/)
3442
          attrs = {}
3443
          attr_array.each do |name, value|
3444
    			  attrs[name.downcase] = value;
3445
    		  end
3446
					openHTMLTagCalc(tag, attrs);
3447
				end
3448
			end
3449
		end
3450
		@table_id = 0;
3451
				
3452
    html.split(/(<[A-Za-z!?\/][^>]*?>)/).each do |element|
3453
      if "<" == element[0,1]
3454
        #Tag
3455
        if (element[1, 1] == '/')
3373 3456
					closedHTMLTagHandler(element[2..-2].downcase);
3374 3457
        else
3375 3458
					#Extract attributes
......
3389 3472
      else
3390 3473
        #Text
3391 3474
				if (@href)
3475
					element.gsub!(/[\t\r\n\f]/, "");
3392 3476
					addHtmlLink(@href, element, fill);
3393 3477
				elsif (@tdbegin)
3394
					if ((element.strip.length > 0) and (element != "&nbsp;"))
3395
						Cell(@tdwidth, @tdheight, unhtmlentities(element.strip), @tableborder, 0, @tdalign, @tdfill);
3396
					elsif (element == "&nbsp;")
3397
						Cell(@tdwidth, @tdheight, '', @tableborder, 0, @tdalign, @tdfill);
3478
					element.gsub!(/[\t\r\n\f]/, "");
3479
					element.gsub!(/&nbsp;/, " ");
3480
					base_page = @page;
3481
					base_x = @x;
3482
					base_y = @y;
3483

  
3484
					MultiCell(@tdwidth, @tdheight, unhtmlentities(element.strip), @tableborder, @tdalign, @tdfill, 1);
3485
					tr_end = @t_cells[@table_id][@tr_id][@td_id]['j1'] + 1;
3486
					if @max_td_page[tr_end].nil?  or (@max_td_page[tr_end] < @page)
3487
						@max_td_page[tr_end] = @page
3488
						@max_td_y[tr_end] = @y
3489
					elsif (@max_td_page[tr_end] == @page)
3490
						@max_td_y[tr_end] = @y if @max_td_y[tr_end].nil? or (@max_td_y[tr_end] < @y) 
3398 3491
					end
3399
				elsif ((element.strip.length > 0) and (element != "&nbsp;"))
3492

  
3493
					@page = base_page;
3494
					@x = base_x + @tdwidth;
3495
					@y = base_y;
3496
				elsif (element.strip.length > 0)
3497
					if @pre_state != true
3498
						element.gsub!(/[\t\r\n\f]/, "");
3499
						element.gsub!(/&nbsp;/, " ");
3500
					end
3400 3501
					Write(@lasth, unhtmlentities(element), '', fill);
3401 3502
				end
3402 3503
      end
......
3422 3523
	# @param int :fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
3423 3524
	# @see Cell()
3424 3525
	#
3425
	def writeHTMLCell(w, h, x, y, html='', border=0, ln=0, fill=0)
3526
	def writeHTMLCell(w, h, x, y, html='', border=0, ln=1, fill=0)
3426 3527
		
3427 3528
		if (@lasth == 0)
3428 3529
			#set row height
......
3446 3547
			w = @fw - x - @r_margin;
3447 3548
		end
3448 3549
		
3550
		b=0;
3551
		if (border)
3552
			if (border==1)
3553
				border='LTRB';
3554
				b='LRT';
3555
				b2='LR';
3556
			elsif border.is_a?(String)
3557
				b2='';
3558
				if (border.include?('L'))
3559
					b2<<'L';
3560
				end
3561
				if (border.include?('R'))
3562
					b2<<'R';
3563
				end
3564
				b=(border.include?('T')) ? b2 + 'T' : b2;
3565
			end
3566
		end
3567
		
3449 3568
		# store original margin values
3450 3569
		l_margin = @l_margin;
3451 3570
		r_margin = @r_margin;
......
3461 3580
		
3462 3581
		currentY =  GetY();
3463 3582
		
3583
		@auto_page_break = false;
3464 3584
		# check if a new page has been created
3465 3585
		if (@page > pagenum)
3466 3586
			# design a cell around the text on first page
3467 3587
			currentpage = @page;
3468 3588
			@page = pagenum;
3469 3589
			SetY(GetPageHeight() - restspace - GetBreakMargin());
3470
			h = restspace - 1;
3471
			Cell(w, h, "", border, ln, 'L', 0);
3590
			Cell(w, restspace - 1, "", b, 0, 'L', 0);
3591
			b = b2;
3592
			@page += 1;
3593
			while @page < currentpage
3594
				SetY(@t_margin); # put cursor at the beginning of text
3595
				Cell(w, @page_break_trigger - @t_margin, "", b, 0, 'L', 0);
3596
				@page += 1;
3597
			end
3598
			if (border.is_a?(String) and border.include?('B'))
3599
				b<<'B';
3600
			end
3472 3601
			# design a cell around the text on last page
3473
			@page = currentpage;
3474
			h = currentY - @t_margin;
3475 3602
			SetY(@t_margin); # put cursor at the beginning of text
3476
			Cell(w, h, "", border, ln, 'L', 0);
3603
			Cell(w, currentY - @t_margin, "", b, 0, 'L', 0);
3477 3604
		else
3478
			h = [h, (currentY - y)].max;
3479 3605
			SetY(y); # put cursor at the beginning of text
3480 3606
			# design a cell around the text
3481
			Cell(w, h, "", border, ln, 'L', 0);
3607
			Cell(w, [h, (currentY - y)].max, "", border, 0, 'L', 0);
3482 3608
		end
3609
		@auto_page_break = true;
3483 3610
		
3484 3611
		# restore original margin values
3485 3612
		SetLeftMargin(l_margin);
3486 3613
		SetRightMargin(r_margin);
3487 3614
		
3488
		if (ln)
3489
			Ln(0);
3615
		@lasth = h
3616

  
3617
		# move cursor to specified position
3618
		if (ln == 0)
3619
			# go to the top-right of the cell
3620
			@x = x + w;
3621
			@y = y;
3622
		elsif (ln == 1)
3623
			# go to the beginning of the next line
3624
			@x = @l_margin;
3625
			@y = currentY;
3626
		elsif (ln == 2)
3627
			# go to the bottom-left of the cell (below)
3628
			@x = x;
3629
			@y = currentY;
3490 3630
		end
3491 3631
	end
3492 3632
  alias_method :write_html_cell, :writeHTMLCell
3493 3633

  
3494 3634
	#
3635
	# Check html table tag position.
3636
	#
3637
	# @param array :table potision array
3638
	# @param int :current tr tag id number
3639
	# @param int :current td tag id number
3640
	# @access private
3641
	# @return int : next td_id position.
3642
	#               value 0 mean that can use position.
3643
	#
3644
	def checkTableBlockingCellPosition(table, tr_id, td_id )
3645
		0.upto(tr_id) do |j|
3646
			0.upto(@t_cells[table][j].size - 1) do |i|
3647
				if @t_cells[table][j][i]['i0'] <= td_id and td_id <= @t_cells[table][j][i]['i1']
3648
					if @t_cells[table][j][i]['j0'] <= tr_id and tr_id <= @t_cells[table][j][i]['j1']
3649
						return @t_cells[table][j][i]['i1'] - td_id + 1;
3650
					end
3651
				end
3652
			end
3653
		end
3654
		return 0;
3655
	end
3656

  
3657
	#
3658
	# Calculate opening tags.
3659
	#
3660
	# html table cell array : @t_cells
3661
	#
3662
	#  i0: table cell start position
3663
	#  i1: table cell end position
3664
	#  j0: table row start position
3665
	#  j1: table row end position
3666
	#
3667
	#  +------+
3668
	#  |i0,j0 |
3669
	#  | i1,j1|
3670
	#  +------+
3671
	#
3672
	#  example html:
3673
	#  <table>
3674
	#    <tr><td></td><td></td><td></td></tr>
3675
	#    <tr><td colspan=2></td><td></td></tr>
3676
	#    <tr><td rowspan=2></td><td></td><td></td></tr>
3677
	#    <tr><td></td><td></td></tr>
3678
	#  </table>
3679
	#
3680
	#   i: 0    1    2
3681
	#  j+----+----+----+
3682
	#  :|0,0 |1,0 |2,0 |
3683
	#  0| 0,0| 1,0| 2,0|
3684
	#   +----+----+----+
3685
	#   |0,1      |2,1 |
3686
	#  1|      1,1| 2,1|
3687
	#   +----+----+----+
3688
	#   |0,2 |1,2 |2,2 |
3689
	#  2|    | 1,2| 2,2|
3690
	#   +    +----+----+
3691
	#   |    |1,3 |2,3 |
3692
	#  3| 0,3| 1,3| 2,3|
3693
	#   +----+----+----+
3694
	#
3695
	#  html table cell array :
3696
	#  [[[i0=>0,j0=>0,i1=>0,j1=>0],[i0=>1,j0=>0,i1=>1,j1=>0],[i0=>2,j0=>0,i1=>2,j1=>0]],
3697
	#   [[i0=>0,j0=>1,i1=>1,j1=>1],[i0=>2,j0=>1,i1=>2,j1=>1]],
3698
	#   [[i0=>0,j0=>2,i1=>0,j1=>3],[i0=>1,j0=>2,i1=>1,j1=>2],[i0=>2,j0=>2,i1=>2,j1=>2]]
3699
	#   [[i0=>1,j0=>3,i1=>1,j1=>3],[i0=>2,j0=>3,i1=>2,j1=>3]]]
3700
	#
3701
	# @param string :tag tag name (in upcase)
3702
	# @param string :attr tag attribute (in upcase)
3703
	# @access private
3704
	#
3705
	def openHTMLTagCalc(tag, attrs)
3706
		#Opening tag
3707
		case (tag)
3708
			when 'table'
3709
				@max_table_columns[@table_id] = 0;
3710
				@t_columns = 0;
3711
				@tr_id = -1;
3712
			when 'tr'
3713
				if @max_table_columns[@table_id] < @t_columns
3714
					@max_table_columns[@table_id] = @t_columns;
3715
				end
3716
				@t_columns = 0;
3717
				@tr_id +=  1;
3718
				@td_id =  -1;
3719
				@t_cells[@table_id].push []
3720
			when 'td', 'th'
3721
				@td_id +=  1;
3722
				if attrs['colspan'].nil? or attrs['colspan'] == ''
3723
					colspan = 1;
3724
				else
3725
					colspan = attrs['colspan'].to_i;
3726
				end
3727
				if attrs['rowspan'].nil? or attrs['rowspan'] == ''
3728
					rowspan = 1;
3729
				else
3730
					rowspan = attrs['rowspan'].to_i;
3731
				end
3732

  
3733
				i = 0;
3734
				while true
3735
					next_i_distance = checkTableBlockingCellPosition(@table_id, @tr_id, @td_id + i);
3736
					if next_i_distance == 0
3737
						@t_cells[@table_id][@tr_id].push "i0"=>@td_id + i, "j0"=>@tr_id, "i1"=>(@td_id + i + colspan - 1), "j1"=>@tr_id + rowspan - 1
3738
						break;
3739
					end
3740
					i += next_i_distance;
3741
				end
3742

  
3743
				@t_columns += colspan;
3744
		end
3745
	end
3746

  
3747
	#
3748
	# Calculate closing tags.
3749
	# @param string :tag tag name (in upcase)
3750
	# @access private
3751
	#
3752
	def closedHTMLTagCalc(tag)
3753
		#Closing tag
3754
		case (tag)
3755
			when 'table'
3756
				if @max_table_columns[@table_id] < @t_columns
3757
					@max_table_columns[@table_id] = @t_columns;
3758
				end
3759
				@table_id += 1;
3760
				@t_cells.push []
3761
		end
3762
	end
3763

  
3764
	#
3495 3765
	# Process opening tags.
3496 3766
	# @param string :tag tag name (in upcase)
3497 3767
	# @param string :attr tag attribute (in upcase)
......
3501 3771
	def openHTMLTagHandler(tag, attrs, fill=0)
3502 3772
		#Opening tag
3503 3773
		case (tag)
3774
			when 'pre'
3775
				@pre_state = true;
3776
				@l_margin += 5;	
3777
				@r_margin += 5;	
3778
				@x += 5;	
3779

  
3504 3780
			when 'table'
3781
				if @default_table_columns < @max_table_columns[@table_id]
3782
					@table_columns = @max_table_columns[@table_id];
3783
				else
3784
					@table_columns = @default_table_columns;
3785
				end
3786
				@l_margin += 5;	
3787
				@r_margin += 5;	
3788
				@x += 5;	
3789

  
3505 3790
				if attrs['border'].nil? or attrs['border'] == ''
3506 3791
					@tableborder = 0;
3507 3792
				else
3508 3793
					@tableborder = attrs['border'];
3509 3794
				end
3795
				@tr_id        = -1;
3796
				@max_td_page[0] = @page;
3797
				@max_td_y[0]    = @y;
3798

  
3510 3799
			when 'tr', 'td', 'th'
3511
        # SetStyle('b', true) if tag == 'th'
3512
				
3800
				if tag == 'th'
3801
					SetStyle('b', true);
3802
					@tdalign = "C";
3803
				end
3513 3804
				if ((!attrs['width'].nil?) and (attrs['width'] != ''))
3514 3805
					@tdwidth = (attrs['width'].to_i/4);
3515 3806
				else
3516
					@tdwidth = ((@w - @l_margin - @r_margin) / @default_table_columns);
3807
					@tdwidth = ((@w - @l_margin - @r_margin) / @table_columns);
3517 3808
				end
3809

  
3810
				if tag == 'tr'
3811
					@tr_id +=  1;
3812
					@td_id  = -1;
3813
				else
3814
					@td_id +=  1;
3815
					@x =  @l_margin + @tdwidth * @t_cells[@table_id][@tr_id][@td_id]['i0'];
3816
				end
3817

  
3818
				if attrs['colspan'].nil? or attrs['border'] == ''
3819
					@colspan = 1;
3820
				else
3821
					@colspan = attrs['colspan'].to_i;
3822
				end
3823
				@tdwidth *= @colspan;
3518 3824
				if ((!attrs['height'].nil?) and (attrs['height'] != ''))
3519 3825
					@tdheight=(attrs['height'].to_i / @k);
3520 3826
				else
......
3538 3844
				@tdbegin=true;
3539 3845
				
3540 3846
			when 'hr'
3541
				Ln();
3847
				margin = 1;
3542 3848
				if ((!attrs['width'].nil?) and (attrs['width'] != ''))
3543 3849
					hrWidth = attrs['width'];
3544 3850
				else
3545
					hrWidth = @w - @l_margin - @r_margin;
3851
					hrWidth = @w - @l_margin - @r_margin - margin;
3546 3852
				end
3547
				x = GetX();
3548
				y = GetY();
3549 3853
				SetLineWidth(0.2);
3550
				Line(x, y, x + hrWidth, y);
3551
				SetLineWidth(0.2);
3854
				Line(@x + margin, @y, @x + hrWidth, @y);
3552 3855
				Ln();
3553 3856
				
3554 3857
			when 'strong'
......
3557 3860
			when 'em'
3558 3861
				SetStyle('i', true);
3559 3862
				
3863
			when 'ins'
3864
				SetStyle('u', true);
3865
				
3866
			when 'del'
3867
				SetStyle('d', true);
3868
				
3560 3869
			when 'b', 'i', 'u'
3561 3870
				SetStyle(tag, true);
3562 3871
				
......
3565 3874
				
3566 3875
			when 'img'
3567 3876
				if (!attrs['src'].nil?)
3877
				Write(@lasth, '!' + attrs['src'] + '!', '', fill);
3878
=begin Comment out. Because not implement image output yet.
3568 3879
					# replace relative path with real server path
3569 3880
					attrs['src'] = attrs['src'].gsub(@@k_path_url_cache, @@k_path_cache);
3570 3881
					if (attrs['width'].nil?)
......
3577 3888
					Image(attrs['src'], GetX(),GetY(), pixelsToMillimeters(attrs['width']), pixelsToMillimeters(attrs['height']));
3578 3889
					#SetX(@img_rb_x);
3579 3890
					SetY(@img_rb_y);
3580
					
3891
=end
3581 3892
				end
3582 3893
				
3583
			when 'ul'
3584
				@listordered = false;
3585
				@listcount = 0;
3894
			when 'ul', 'ol'
3895
				if @li_count == 0
3896
					Ln() if @prevquote_count == @quote_count; # insert Ln for keeping quote lines
3897
					@prevquote_count = @quote_count;
3898
				end
3899
				if @li_state == true
3900
					Ln();
3901
			  	@li_state = false;
3902
				end
3903
				if tag == 'ul'
3904
					@list_ordered[@li_count] = false;
3905
				else
3906
					@list_ordered[@li_count] = true;
3907
				end
3908
				@list_count[@li_count] = 0;
3909
				@li_count += 1
3586 3910
				
3587
			when 'ol'
3588
				@listordered = true;
3589
				@listcount = 0;
3590
				
3591 3911
			when 'li'
3592
				Ln();
3593
				if (@listordered)
3594
				  @listcount += 1
3595
					@lispacer = "    " + (@listcount).to_s + ". ";
3912
				Ln() if @li_state == true
3913
				if (@list_ordered[@li_count - 1])
3914
					@list_count[@li_count - 1] += 1;
3915
					@li_spacer = "    " * @li_count + (@list_count[@li_count - 1]).to_s + ". ";
3596 3916
				else
3597 3917
					#unordered list simbol
3598
					@lispacer = "    -  ";
3918
					@li_spacer = "    " * @li_count + "-  ";
3599 3919
				end
3600
				Write(@lasth, @lispacer, '', fill);
3920
				Write(@lasth, @spacer + @li_spacer, '', fill);
3921
				@li_state = true;
3601 3922

  
3602
			when 'blockquote', 'br'
3923
			when 'blockquote'
3924
				if (@quote_count == 0)
3925
					SetStyle('i', true);
3926
					@l_margin += 5;	
3927
				else
3928
					@l_margin += 5 / 2;	
3929
				end
3930
				@x = @l_margin;	
3931
				@quote_top[@quote_count]  = @y;
3932
				@quote_page[@quote_count] = @page;
3933
				@quote_count += 1
3934
			when 'br'
3603 3935
				Ln();
3604
				if (@lispacer.length > 0)
3605
					@x += GetStringWidth(@lispacer);
3936

  
3937
				if (@li_spacer.length > 0)
3938
					@x += GetStringWidth(@li_spacer);
3606 3939
				end
3607 3940
				
3608 3941
			when 'p'
3609 3942
				Ln();
3610
				Ln();
3943
				0.upto(@quote_count - 1) do |i|
3944
			  	if @quote_page[i] == @page;
3945
			  		if @quote_top[i] == @y - @lasth; # fix start line
3946
			  			@quote_top[i] = @y;
3947
						end
3948
					else
3949
			  		if @quote_page[i] == @page - 1;
3950
			  			@quote_page[i] = @page; # fix start line
3951
			  			@quote_top[i] = @t_margin;
3952
						end
3953
					end
3954
				end
3611 3955
				
3612 3956
			when 'sup'
3613 3957
				currentfont_size = @font_size;
......
3648 3992
				@lasth = @font_size * @@k_cell_height_ratio;
3649 3993
				
3650 3994
			when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
3995
				Ln();
3651 3996
				headsize = (4 - tag[1,1].to_f) * 2
3652 3997
				@tempfontsize = @font_size_pt;
3653 3998
				SetFontSize(@font_size_pt + headsize);
......
3665 4010
	def closedHTMLTagHandler(tag)
3666 4011
		#Closing tag
3667 4012
		case (tag)
4013
			when 'pre'
4014
				@pre_state = false;
4015
				@l_margin -= 5;
4016
				@r_margin -= 5;
4017
				@x = @l_margin;
4018
				Ln();
4019

  
3668 4020
			when 'td','th'
3669 4021
				@tdbegin = false;
3670 4022
				@tdwidth = 0;
3671 4023
				@tdheight = 0;
3672 4024
				@tdalign = "L";
4025
				SetStyle('b', false);
3673 4026
				@tdfill = 0;
3674 4027
				SetFillColor(@prevfill_color[0], @prevfill_color[1], @prevfill_color[2]);
3675 4028
				
3676 4029
			when 'tr'
3677
				Ln();
4030
				@y = @max_td_y[@tr_id + 1];
4031
				@x = @l_margin;
4032
				@page = @max_td_page[@tr_id + 1];
3678 4033
				
3679 4034
			when 'table'
4035
				# Write Table Line
4036
				width = (@w - @l_margin - @r_margin) / @table_columns;
4037
				0.upto(@t_cells[@table_id].size - 1) do |j|
4038
					0.upto(@t_cells[@table_id][j].size - 1) do |i|
4039
						@page = @max_td_page[j]
4040
						i0=@t_cells[@table_id][j][i]['i0'];
4041
						j0=@t_cells[@table_id][j][i]['j0'];
4042
						i1=@t_cells[@table_id][j][i]['i1'];
4043
						j1=@t_cells[@table_id][j][i]['j1'];
4044

  
4045
						Line(@l_margin + width * i0,     @max_td_y[j0],   @l_margin + width * (i1+1), @max_td_y[j0])   # top
4046
						if ( @page == @max_td_page[j1 + 1])
4047
							Line(@l_margin + width * i0,     @max_td_y[j0],   @l_margin + width * i0,     @max_td_y[j1+1]) # left
4048
							Line(@l_margin + width * (i1+1), @max_td_y[j0],   @l_margin + width * (i1+1), @max_td_y[j1+1]) # right
4049
						else
4050
							Line(@l_margin + width * i0,     @max_td_y[j0],   @l_margin + width * i0,     @page_break_trigger) # left
4051
							Line(@l_margin + width * (i1+1), @max_td_y[j0],   @l_margin + width * (i1+1), @page_break_trigger) # right
4052
							@page += 1;
4053
							while @page < @max_td_page[j1 + 1]
4054
								Line(@l_margin + width * i0,     @t_margin,   @l_margin + width * i0,     @page_break_trigger) # left
4055
								Line(@l_margin + width * (i1+1), @t_margin,   @l_margin + width * (i1+1), @page_break_trigger) # right
4056
								@page += 1;
4057
							end
4058
							Line(@l_margin + width * i0,     @t_margin,   @l_margin + width * i0,     @max_td_y[j1+1]) # left
4059
							Line(@l_margin + width * (i1+1), @t_margin,   @l_margin + width * (i1+1), @max_td_y[j1+1]) # right
4060
						end
4061
						Line(@l_margin + width * i0,     @max_td_y[j1+1], @l_margin + width * (i1+1), @max_td_y[j1+1]) # bottom
4062
					end
4063
				end
4064

  
4065
				@l_margin -= 5;
4066
				@r_margin -= 5;
3680 4067
				@tableborder=0;
4068
				Ln();
4069
				@table_id += 1;
3681 4070
				
3682 4071
			when 'strong'
3683 4072
				SetStyle('b', false);
......
3685 4074
			when 'em'
3686 4075
				SetStyle('i', false);
3687 4076
				
4077
			when 'ins'
4078
				SetStyle('u', false);
4079
				
4080
			when 'del'
4081
				SetStyle('d', false);
4082
				
3688 4083
			when 'b', 'i', 'u'
3689 4084
				SetStyle(tag, false);
3690 4085
				
3691 4086
			when 'a'
3692 4087
				@href = nil;
3693 4088
				
4089
			when 'p'
4090
				Ln();
4091
				
3694 4092
			when 'sup'
3695 4093
				currentfont_size = @font_size;
3696 4094
				SetFontSize(@tempfontsize);
......
3725 4123
				#@text_color = @prevtext_color;
3726 4124
				@lasth = @font_size * @@k_cell_height_ratio;
3727 4125
				
3728
			when 'ul'
3729
				Ln();
4126
			when 'blockquote'
4127
			  @quote_count -= 1
4128
				if (@quote_page[@quote_count] == @page)
4129
					Line(@l_margin - 1, @quote_top[@quote_count], @l_margin - 1, @y)  # quoto line
4130
				else
4131
					cur_page = @page;
4132
					cur_y = @y;
4133
					@page = @quote_page[@quote_count];
4134
					if (@quote_top[@quote_count] < @page_break_trigger)
4135
						Line(@l_margin - 1, @quote_top[@quote_count], @l_margin - 1, @page_break_trigger)  # quoto line
4136
					end
4137
					@page += 1;
4138
					while @page < cur_page
4139
						Line(@l_margin - 1, @t_margin, @l_margin - 1, @page_break_trigger)  # quoto line
4140
						@page += 1;
4141
					end
4142
					@y = cur_y;
4143
					Line(@l_margin - 1, @t_margin, @l_margin - 1, @y)  # quoto line
4144
				end
4145
				if (@quote_count <= 0)
4146
					SetStyle('i', false);
4147
					@l_margin -= 5;
4148
				else
4149
					@l_margin -= 5 / 2;
4150
				end
4151
				@x = @l_margin;
4152
				Ln() if @quote_count == 0
4153

  
4154
			when 'ul', 'ol'
4155
			  @li_count -= 1
4156
				if @li_state == true
4157
					Ln();
4158
			  	@li_state = false;
4159
				end
3730 4160
				
3731
			when 'ol'
3732
				Ln();
3733
				
3734 4161
			when 'li'
3735
				@lispacer = "";
4162
				@li_spacer = "";
4163
				if @li_state == true
4164
					Ln();
4165
			  	@li_state = false;
4166
				end
3736 4167
				
3737 4168
			when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
3738 4169
				SetFontSize(@tempfontsize);
......
3740 4171
				SetStyle('b', false);
3741 4172
				Ln();
3742 4173
				@lasth = @font_size * @@k_cell_height_ratio;
3743
								
4174
				
4175
				if tag == 'h1' or tag == 'h2' or tag == 'h3' or tag == 'h4'
4176
					margin = 1;
4177
					hrWidth = @w - @l_margin - @r_margin - margin;
4178
					if tag == 'h1' or tag == 'h2'
4179
						SetLineWidth(0.2);
4180
					else
4181
						SetLineWidth(0.1);
4182
					end
4183
					Line(@x + margin, @y, @x + hrWidth, @y);
4184
				end
3744 4185
		end
3745 4186
	end
3746 4187
	
......
3752 4193
	#
3753 4194
	def SetStyle(tag, enable)
3754 4195
		#Modify style and select corresponding font
3755
		style='';
3756
		['b', 'i', 'u'].each do |s|
3757
				style << s if tag.downcase == s and enable
4196
		['b', 'i', 'u', 'd'].each do |s|
4197
			if tag.downcase == s
4198
				if enable
4199
					@style << s if ! @style.include?(s)
4200
				else
4201
					@style = @style.gsub(s,'')
4202
				end
4203
			end
3758 4204
		end
3759
		SetFont('', style);
4205
		SetFont('', @style);
3760 4206
	end
3761 4207
	
3762 4208
	#