rbpdf 1.18.4 → 1.18.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 5329616012db52c1743a298afb11aa835126a284
4
- data.tar.gz: 6d92283c3fa55edaa59b68edab0b2db7f1311ae5
5
- SHA512:
6
- metadata.gz: 74738ca0557dbe52a46177277d58b92ce1dc4e590fea0cfb6c4711e94f657db4359fe455aab918aeb67d55353fd4044d6bea4de05eaa7c1189b22e7daa05d918
7
- data.tar.gz: f29d02d42ac883a7781314deed127c67216fc780b9df7d742cefeb8b839fc7e896fc2638a9459f6eb1010eb3a4b5e478450d523e6a55a9b55f045914efda2000
1
+ ---
2
+ SHA512:
3
+ data.tar.gz: 58ee6415442d443f581733352686a7ce871a2cfe04b5bf683544ba7e8202b934f7258d0c403942b07c52c2a56ad6288f02fb1bb210c1ca94401ca092729da139
4
+ metadata.gz: fca83b46f3d2abdc1efea548a5a7c7963b1fbbbbdde7e6dbf7a1b279a80cb25bb628a4eba853eb064cdef79ea4ad514928b6d243f3b4c01bf42f03046c2a122f
5
+ SHA1:
6
+ data.tar.gz: a973c8fae4a4b576b68cd8e5a7dc3b73211e26ab
7
+ metadata.gz: c27e1dfa12f3cbfbf8cee92658d17a99cff0a1e0
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 1.18.5 2015-01-24
2
+ - Rails 4.2 and Ruby 2.2 supported.
3
+ - Fix Rails 4.2 (new HTML sanitizer) compatible.
4
+ - Method getHTMLUnitToUnits() and SetDisplayMode() was fixed, and the problem when dividing, by an integer was fixed.
5
+ - Remove Rails 4.2 deprecated ::ActionView::Base.sanitized_allowed_css_properties=.
6
+ - Fixed no left padding problem on tables.
7
+ - Fixed thead tag position problem on page break.
8
+ - fix case of missing HTML image (without height attribute) file.
9
+
1
10
  1.18.4 2014-12-21
2
11
  - utf8Bidi() Persion 0x200C(8204) and endedletter bug fixed.
3
12
  - utf8Bidi() Bidirectional Algorithm X9/I1 rule BN(ZERO WIDTH NON-JOINER) bug fixed.
@@ -363,7 +363,6 @@ class RBPDF
363
363
  @radiobutton_groups ||= []
364
364
  @radio_groups ||= []
365
365
  @textindent ||= 0
366
- @nested_table = false
367
366
 
368
367
  @start_transaction_y ||= 0
369
368
  @in_thead ||= false
@@ -1340,7 +1339,7 @@ class RBPDF
1340
1339
  #
1341
1340
  def SetDisplayMode(zoom, layout='SinglePage', mode='UseNone')
1342
1341
  #Set display mode in viewer
1343
- if (zoom == 'fullpage' or zoom == 'fullwidth' or zoom == 'real' or zoom == 'default' or !zoom.is_a?(String))
1342
+ if (zoom == 'fullpage' or zoom == 'fullwidth' or zoom == 'real' or zoom == 'default' or zoom.is_a?(Numeric))
1344
1343
  @zoom_mode = zoom
1345
1344
  else
1346
1345
  Error('Incorrect zoom display mode: ' + zoom)
@@ -2001,8 +2000,8 @@ class RBPDF
2001
2000
  #barcode = getBarcode()
2002
2001
  #if !barcode.empty?
2003
2002
  # Ln(line_width)
2004
- # barcode_width = ((getPageWidth() - ormargins['left'] - ormargins['right']) / 3).round
2005
- # write1DBarcode(barcode, 'C128B', GetX(), cur_y + line_width, barcode_width, ((getFooterMargin() / 3) - line_width), 0.3, '', '')
2003
+ # barcode_width = ((getPageWidth() - ormargins['left'] - ormargins['right']) / 3.0).round
2004
+ # write1DBarcode(barcode, 'C128B', GetX(), cur_y + line_width, barcode_width, ((getFooterMargin() / 3.0) - line_width), 0.3, '', '')
2006
2005
  #end
2007
2006
  w_page = (@l.nil? or @l['w_page'].nil?) ? '' : @l['w_page']
2008
2007
  if @pagegroups.empty?
@@ -2126,8 +2125,9 @@ class RBPDF
2126
2125
  # set margins
2127
2126
  prev_lMargin = @l_margin
2128
2127
  prev_rMargin = @r_margin
2129
- @l_margin = @pagedim[@page]['olm']
2130
- @r_margin = @pagedim[@page]['orm']
2128
+ prev_cMargin = @c_margin
2129
+ @l_margin = @thead_margins['lmargin']
2130
+ @r_margin = @thead_margins['rmargin']
2131
2131
  @c_margin = @thead_margins['cmargin']
2132
2132
  if @rtl
2133
2133
  @x = @w - @r_margin
@@ -2145,6 +2145,7 @@ class RBPDF
2145
2145
  @lasth = 0
2146
2146
  @l_margin = prev_lMargin
2147
2147
  @r_margin = prev_rMargin
2148
+ @c_margin = prev_cMargin
2148
2149
  end
2149
2150
  end
2150
2151
  protected :setTableHeader
@@ -2840,12 +2841,12 @@ class RBPDF
2840
2841
  @font_size_pt = size;
2841
2842
  @font_size = size.to_f / @k;
2842
2843
  if !@current_font['desc'].nil? and !@current_font['desc']['Ascent'].nil? and (@current_font['desc']['Ascent'] > 0)
2843
- @font_ascent = @current_font['desc']['Ascent'] * @font_size / 1000
2844
+ @font_ascent = @current_font['desc']['Ascent'] * @font_size / 1000.0
2844
2845
  else
2845
2846
  @font_ascent = 0.85 * @font_size
2846
2847
  end
2847
2848
  if !@current_font['desc'].nil? and !@current_font['desc']['Descent'].nil? and (@current_font['desc']['Descent'] <= 0)
2848
- @font_descent = - @current_font['desc']['Descent'] * @font_size / 1000
2849
+ @font_descent = - @current_font['desc']['Descent'] * @font_size / 1000.0
2849
2850
  else
2850
2851
  @font_descent = 0.15 * @font_size
2851
2852
  end
@@ -2870,7 +2871,7 @@ class RBPDF
2870
2871
  fontdata = AddFont(font, style)
2871
2872
  font = getFontBuffer(fontdata['fontkey'])
2872
2873
  if font['desc'] and font['desc']['Descent'] and (font['desc']['Descent'] <= 0)
2873
- descent = - font['desc']['Descent'] * sizek / 1000
2874
+ descent = - font['desc']['Descent'] * sizek / 1000.0
2874
2875
  else
2875
2876
  descent = 0.15 * sizek
2876
2877
  end
@@ -2893,7 +2894,7 @@ class RBPDF
2893
2894
  fontdata = AddFont(font, style)
2894
2895
  font = getFontBuffer(fontdata['fontkey'])
2895
2896
  if font['desc'] and font['desc']['Ascent'] and (font['desc']['Ascent'] > 0)
2896
- ascent = font['desc']['Ascent'] * sizek / 1000
2897
+ ascent = font['desc']['Ascent'] * sizek / 1000.0
2897
2898
  else
2898
2899
  ascent = 0.85 * sizek
2899
2900
  end
@@ -3401,46 +3402,46 @@ class RBPDF
3401
3402
  case valign
3402
3403
  when 'T'
3403
3404
  # top
3404
- y -= @line_width / 2
3405
+ y -= @line_width / 2.0
3405
3406
  when 'B'
3406
3407
  # bottom
3407
- y -= (h - @font_ascent - @font_descent - @line_width / 2)
3408
+ y -= (h - @font_ascent - @font_descent - @line_width / 2.0)
3408
3409
  else # 'M'
3409
3410
  # center
3410
- y -= (h - @font_ascent - @font_descent) / 2
3411
+ y -= (h - @font_ascent - @font_descent) / 2.0
3411
3412
  end
3412
3413
  when 'L'
3413
3414
  # font baseline
3414
3415
  case valign
3415
3416
  when 'T'
3416
3417
  # top
3417
- y -= (@font_ascent + @line_width / 2)
3418
+ y -= (@font_ascent + @line_width / 2.0)
3418
3419
  when 'B'
3419
3420
  # bottom
3420
- y -= (h - @font_descent - @line_width / 2)
3421
+ y -= (h - @font_descent - @line_width / 2.0)
3421
3422
  else # 'M'
3422
3423
  # center
3423
- y -= (h + @font_ascent - @font_descent) / 2
3424
+ y -= (h + @font_ascent - @font_descent) / 2.0
3424
3425
  end
3425
3426
  when 'D'
3426
3427
  # font bottom
3427
3428
  case valign
3428
3429
  when 'T'
3429
3430
  # top
3430
- y -= (@font_ascent + @font_descent + @line_width / 2)
3431
+ y -= (@font_ascent + @font_descent + @line_width / 2.0)
3431
3432
  when 'B'
3432
3433
  # bottom
3433
- y -= (h - @line_width / 2)
3434
+ y -= (h - @line_width / 2.0)
3434
3435
  else # 'M'
3435
3436
  # center
3436
- y -= (h + @font_ascent + @font_descent) / 2
3437
+ y -= (h + @font_ascent + @font_descent) / 2.0
3437
3438
  end
3438
3439
  when 'B'
3439
3440
  # cell bottom
3440
3441
  y -= h
3441
3442
  when 'C'
3442
3443
  # cell center
3443
- y -= h / 2
3444
+ y -= h / 2.0
3444
3445
  else # 'T'
3445
3446
  # cell top
3446
3447
  end
@@ -3449,13 +3450,13 @@ class RBPDF
3449
3450
  case valign
3450
3451
  when 'T'
3451
3452
  # top
3452
- basefonty = y + @font_ascent + @line_width / 2
3453
+ basefonty = y + @font_ascent + @line_width / 2.0
3453
3454
  when 'B'
3454
3455
  # bottom
3455
- basefonty = y + h - @font_descent - @line_width / 2
3456
+ basefonty = y + h - @font_descent - @line_width / 2.0
3456
3457
  else # 'M'
3457
3458
  # center
3458
- basefonty = y + (h + @font_ascent - @font_descent) / 2
3459
+ basefonty = y + (h + @font_ascent - @font_descent) / 2.0
3459
3460
  end
3460
3461
 
3461
3462
  if empty_string(w) or (w <= 0)
@@ -3482,7 +3483,7 @@ class RBPDF
3482
3483
  s << sprintf('%.2f %.2f %.2f %.2f re %s ', xk, (@h - y) * k, w * k, -h * k, op)
3483
3484
  end
3484
3485
  if (border.is_a?(String))
3485
- lm = @line_width / 2
3486
+ lm = @line_width / 2.0
3486
3487
  if (border.include?('L'))
3487
3488
  if @rtl
3488
3489
  xk = (x - w) * k
@@ -3622,7 +3623,7 @@ class RBPDF
3622
3623
  txt2 = txt2.gsub("\r", ' ')
3623
3624
  case align
3624
3625
  when 'C'
3625
- dx = (w - width) / 2
3626
+ dx = (w - width) / 2.0
3626
3627
  when 'R'
3627
3628
  if @rtl
3628
3629
  dx = @c_margin
@@ -3684,7 +3685,7 @@ class RBPDF
3684
3685
  s<<' Q';
3685
3686
  end
3686
3687
  if link && ((link.is_a?(String) and !link.empty?) or (link.is_a?(Fixnum) and link != 0)) # Fixnum is PDF file Page No.
3687
- Link(xdx, y + ((h - @font_size) / 2), width, @font_size, link, ns)
3688
+ Link(xdx, y + ((h - @font_size) / 2.0), width, @font_size, link, ns)
3688
3689
  end
3689
3690
  end
3690
3691
 
@@ -3834,12 +3835,12 @@ class RBPDF
3834
3835
  starty = @y
3835
3836
  if autopadding
3836
3837
  # Adjust internal padding
3837
- if @c_margin < (@line_width / 2)
3838
- @c_margin = @line_width / 2
3838
+ if @c_margin < (@line_width / 2.0)
3839
+ @c_margin = @line_width / 2.0
3839
3840
  end
3840
3841
  # Add top space if needed
3841
3842
  if (@lasth - @font_size) < @line_width
3842
- @y += @line_width / 2
3843
+ @y += @line_width / 2.0
3843
3844
  end
3844
3845
  # add top padding
3845
3846
  @y += @c_margin
@@ -3859,7 +3860,7 @@ class RBPDF
3859
3860
  @y += @c_margin
3860
3861
  # Add bottom space if needed
3861
3862
  if (@lasth - @font_size) < @line_width
3862
- @y += @line_width / 2
3863
+ @y += @line_width / 2.0
3863
3864
  end
3864
3865
  end
3865
3866
 
@@ -4085,8 +4086,8 @@ class RBPDF
4085
4086
  end
4086
4087
  if autopadding
4087
4088
  # adjust internal padding
4088
- if cellMargin < (lineWidth / 2)
4089
- cellMargin = lineWidth / 2
4089
+ if cellMargin < (lineWidth / 2.0)
4090
+ cellMargin = lineWidth / 2.0
4090
4091
  end
4091
4092
  end
4092
4093
  wmax = w - (2 * cellMargin)
@@ -4187,8 +4188,8 @@ class RBPDF
4187
4188
  lineWidth = @line_width
4188
4189
  end
4189
4190
  # adjust internal padding
4190
- if cellMargin < (lineWidth / 2)
4191
- cellMargin = lineWidth / 2
4191
+ if cellMargin < (lineWidth / 2.0)
4192
+ cellMargin = lineWidth / 2.0
4192
4193
  end
4193
4194
  # add top and bottom space if needed
4194
4195
  if (@lasth - @font_size) < lineWidth
@@ -4817,6 +4818,7 @@ class RBPDF
4817
4818
  prev_x = @x
4818
4819
  if checkPageBreak(h, y)
4819
4820
  y = @y
4821
+ y += @c_margin if !empty_string(@thead) and !@in_thead ### fix ###
4820
4822
  if @rtl
4821
4823
  x += prev_x - @x
4822
4824
  else
@@ -4950,7 +4952,7 @@ class RBPDF
4950
4952
  if palign == 'L'
4951
4953
  ximg = @l_margin
4952
4954
  elsif palign == 'C'
4953
- ximg = (@w + @l_margin - @r_margin - w) / 2
4955
+ ximg = (@w + @l_margin - @r_margin - w) / 2.0
4954
4956
  elsif palign == 'R'
4955
4957
  ximg = @w - @r_margin - w
4956
4958
  else
@@ -4961,7 +4963,7 @@ class RBPDF
4961
4963
  if palign == 'L'
4962
4964
  ximg = @l_margin
4963
4965
  elsif palign == 'C'
4964
- ximg = (@w + @l_margin - @r_margin - w) / 2
4966
+ ximg = (@w + @l_margin - @r_margin - w) / 2.0
4965
4967
  elsif palign == 'R'
4966
4968
  ximg = @w - @r_margin - w
4967
4969
  else
@@ -4999,7 +5001,7 @@ class RBPDF
4999
5001
  @y = y
5000
5002
  @x = @img_rb_x
5001
5003
  when 'M'
5002
- @y = y + (h/2).round
5004
+ @y = y + (h/2.0).round
5003
5005
  @x = @img_rb_x
5004
5006
  when 'B'
5005
5007
  @y = @img_rb_y
@@ -5721,7 +5723,7 @@ protected
5721
5723
  if @pagedim[n]['BoxColorInfo'][box]['C']
5722
5724
  color = @pagedim[n]['BoxColorInfo'][box]['C']
5723
5725
  out <<= ' /C ['
5724
- out << sprintf(' %.3f %.3f %.3f', color[0]/255, color[1]/255, color[2]/255)
5726
+ out << sprintf(' %.3f %.3f %.3f', color[0]/255.0, color[1]/255.0, color[2]/255.0)
5725
5727
  out << ' ]'
5726
5728
  end
5727
5729
  if @pagedim[n]['BoxColorInfo'][box]['W']
@@ -6028,7 +6030,7 @@ protected
6028
6030
  annots << ' /C ['
6029
6031
  pl['opt']['c'].each {|col|
6030
6032
  col = col.to_i
6031
- color = col <= 0 ? 0 : (col >= 255 ? 1 : col / 255)
6033
+ color = col <= 0 ? 0 : (col >= 255 ? 1 : col / 255.0)
6032
6034
  annots << sprintf(" %.4f", color)
6033
6035
  }
6034
6036
  annots << ']'
@@ -6188,7 +6190,7 @@ protected
6188
6190
  annots << ' /BC ['
6189
6191
  pl['opt']['mk']['bc'].each {|col|
6190
6192
  col = col.to_i
6191
- color = col <= 0 ? 0 : (col >= 255 ? 1 : col / 255)
6193
+ color = col <= 0 ? 0 : (col >= 255 ? 1 : col / 255.0)
6192
6194
  annots << sprintf(' %.2f', color)
6193
6195
  }
6194
6196
  annots << ']'
@@ -6197,7 +6199,7 @@ protected
6197
6199
  annots << ' /BG ['
6198
6200
  pl['opt']['mk']['bg'].each {|col|
6199
6201
  col = col.to_i
6200
- color = col <= 0 ? 0 : (col >= 255 ? 1 : col / 255)
6202
+ color = col <= 0 ? 0 : (col >= 255 ? 1 : col / 255.0)
6201
6203
  annots << sprintf(' %.2f', color)
6202
6204
  }
6203
6205
  annots << ']'
@@ -6923,7 +6925,7 @@ protected
6923
6925
  out = '[/Separation /' + name.gsub(' ', '#20')
6924
6926
  out << ' /DeviceCMYK <<'
6925
6927
  out << ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]'
6926
- out << ' ' + sprintf('/C1 [%.4f %.4f %.4f %.4f] ', color['c']/100, color['m']/100, color['y']/100, color['k']/100)
6928
+ out << ' ' + sprintf('/C1 [%.4f %.4f %.4f %.4f] ', color['c']/100.0, color['m']/100.0, color['y']/100.0, color['k']/100.0)
6927
6929
  out << ' /FunctionType 2 /Domain [0 1] /N 1>>]'
6928
6930
  out << ' endobj'
6929
6931
  out(out)
@@ -7074,8 +7076,8 @@ protected
7074
7076
  out << ' /OpenAction [3 0 R /FitH null]'
7075
7077
  elsif (@zoom_mode=='real')
7076
7078
  out << ' /OpenAction [3 0 R /XYZ null null 1]'
7077
- elsif (!@zoom_mode.is_a?(String))
7078
- out << ' /OpenAction [3 0 R /XYZ null null ' + (@zoom_mode/100) + ']'
7079
+ elsif @zoom_mode.is_a?(Numeric)
7080
+ out << ' /OpenAction [3 0 R /XYZ null null ' + (@zoom_mode/100.0).to_s + ']'
7079
7081
  end
7080
7082
  if @layout_mode and !empty_string(@layout_mode)
7081
7083
  out << ' /PageLayout /' + @layout_mode
@@ -7393,7 +7395,7 @@ protected
7393
7395
  #
7394
7396
  def dolinethroughw(x, y, w)
7395
7397
  linew = - @current_font['ut'] / 1000.0 * @font_size_pt
7396
- return sprintf('%.2f %.2f %.2f %.2f re f', x * @k, (@h - y) * @k + linew + (@font_size_pt / 3), w * @k, linew)
7398
+ return sprintf('%.2f %.2f %.2f %.2f re f', x * @k, (@h - y) * @k + linew + (@font_size_pt / 3.0), w * @k, linew)
7397
7399
  end
7398
7400
 
7399
7401
  #
@@ -8890,7 +8892,7 @@ public
8890
8892
  if border_style
8891
8893
  SetLineStyle(border_style)
8892
8894
  end
8893
- myArc = 4 / 3 * (::Math.sqrt(2) - 1)
8895
+ myArc = 4 / 3.0 * (::Math.sqrt(2) - 1)
8894
8896
  outPoint(x + rx, y)
8895
8897
  xc = x + w - rx
8896
8898
  yc = y + ry
@@ -10685,8 +10687,7 @@ protected
10685
10687
  blocktags = ['blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','table','tr','td']
10686
10688
 
10687
10689
  # remove all unsupported tags (the line below lists all supported tags)
10688
- ::ActionView::Base.sanitized_allowed_css_properties = ["page-break-before", "page-break-after", "page-break-inside"]
10689
- html = "%s" % sanitize(html, :tags=> %w(a b blockquote body br dd del div dl dt em font h1 h2 h3 h4 h5 h6 hr i img li ol p pre small span strong sub sup table tablehead td th thead tr tt u ins ul), :attributes => %w(cellspacing cellpadding bgcolor color value width height src size colspan rowspan style align border face href dir class id nobr stroke strokecolor fill nested))
10690
+ html = sanitize_html(html)
10690
10691
 
10691
10692
  # replace some blank characters
10692
10693
  html.gsub!(/<pre/, '<xre') # preserve pre tag
@@ -10840,8 +10841,8 @@ protected
10840
10841
  end
10841
10842
  if (dom[key]['value'] == 'table') and !empty_string(dom[(dom[key]['parent'])]['thead'])
10842
10843
  # remove the nobr attributes from the table header
10843
- dom[(dom[key]['parent'])]['thead'] = dom[(dom[key]['parent'])]['thead'].gsub(' nobr="true"', '')
10844
- dom[(dom[key]['parent'])]['thead'] << '</tablehead>'
10844
+ dom[(dom[key]['parent'])]['thead'] = dom[(dom[key]['parent'])]['thead'].gsub(' nobr="true"', '').sub(/<table([ >])/, '<table tablehead="1"\1')
10845
+ dom[(dom[key]['parent'])]['thead'] << '</table>'
10845
10846
  end
10846
10847
  else
10847
10848
  # *** opening html tag
@@ -11278,13 +11279,16 @@ public
11278
11279
  # [@see] Multicell(), writeHTML(), Cell()
11279
11280
  #
11280
11281
  def writeHTMLCell(w, h, x, y, html='', border=0, ln=0, fill=0, reseth=true, align='', autopadding=true)
11281
- @nested_table = true
11282
11282
  rtn = MultiCell(w, h, html, border, align, fill, ln, x, y, reseth, 0, true, autopadding, 0)
11283
- @nested_table = false
11284
11283
  return rtn
11285
11284
  end
11286
11285
  alias_method :write_html_cell, :writeHTMLCell
11287
11286
 
11287
+ def sanitize_html(html)
11288
+ html = "%s" % sanitize(html, :tags=> %w(a b blockquote body br dd del div dl dt em font h1 h2 h3 h4 h5 h6 hr i img li ol p pre small span strong sub sup table td th thead tr tt u ins ul), :attributes => %w(cellspacing cellpadding bgcolor color value width height src size colspan rowspan style align border face href dir class id nobr stroke strokecolor fill nested tablehead))
11289
+ end
11290
+ protected :sanitize_html
11291
+
11288
11292
  #
11289
11293
  # Allows to preserve some HTML formatting (limited support).
11290
11294
  # IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
@@ -11454,8 +11458,18 @@ public
11454
11458
  if (dom[key]['value'] == 'tr') and dom[key]['thead'] and dom[key]['thead']
11455
11459
  if dom[key]['parent'] and dom[(dom[key]['parent'])]['thead'] and !empty_string(dom[(dom[key]['parent'])]['thead'])
11456
11460
  @in_thead = true
11461
+
11462
+ prev_lMargin = @l_margin
11463
+ prev_rMargin = @r_margin
11464
+ @l_margin = @thead_margins['lmargin']
11465
+ @r_margin = @thead_margins['rmargin']
11466
+
11457
11467
  # print table header (thead)
11458
11468
  writeHTML(@thead, false, false, false, false, '')
11469
+
11470
+ @l_margin = prev_lMargin
11471
+ @r_margin = prev_rMargin
11472
+
11459
11473
  if (@start_transaction_page == (@numpages - 1)) or (@y < @start_transaction_y) or checkPageBreak(@lasth, '', false)
11460
11474
  # restore previous object
11461
11475
  rollbackTransaction(true)
@@ -11555,7 +11569,7 @@ public
11555
11569
  startlinepage = @page
11556
11570
  startliney = @y
11557
11571
  end
11558
- @y += ((curfontsize * @cell_height_ratio / @k) + curfontascent - curfontdescent) / 2 - imgh
11572
+ @y += ((curfontsize * @cell_height_ratio / @k) + curfontascent - curfontdescent) / 2.0 - imgh
11559
11573
  minstartliney = [@y, minstartliney].min
11560
11574
  maxbottomliney = startliney + @font_size * @cell_height_ratio
11561
11575
  end
@@ -11612,7 +11626,7 @@ public
11612
11626
  startliney = @y
11613
11627
  end
11614
11628
  if !dom[key]['block']
11615
- @y += (((curfontsize - fontsize) * @cell_height_ratio / @k) + curfontascent - fontascent - curfontdescent + fontdescent) / 2
11629
+ @y += (((curfontsize - fontsize) * @cell_height_ratio / @k) + curfontascent - fontascent - curfontdescent + fontdescent) / 2.0
11616
11630
  if (dom[key]['value'] != 'sup') and (dom[key]['value'] != 'sub')
11617
11631
  minstartliney = [@y, minstartliney].min
11618
11632
  maxbottomliney = [@y + ((fontsize * @cell_height_ratio) / @k), maxbottomliney].max
@@ -11706,9 +11720,9 @@ public
11706
11720
  mdiff = (tw - linew).abs
11707
11721
  if plalign == 'C'
11708
11722
  if @rtl
11709
- t_x = -(mdiff / 2)
11723
+ t_x = -(mdiff / 2.0)
11710
11724
  else
11711
- t_x = (mdiff / 2)
11725
+ t_x = (mdiff / 2.0)
11712
11726
  end
11713
11727
  elsif (plalign == 'R') and !@rtl
11714
11728
  # right alignment on LTR document
@@ -11955,6 +11969,7 @@ public
11955
11969
  end
11956
11970
  end
11957
11971
  pbrk = checkPageBreak(@lasth)
11972
+ @y += @c_margin if pbrk and !dom[key]['tag'] and !empty_string(@thead) and !@in_thead ### fix ###
11958
11973
  @newline = false
11959
11974
  startlinex = @x
11960
11975
  startliney = @y
@@ -12010,7 +12025,7 @@ public
12010
12025
  else
12011
12026
  wtmp = @w - @r_margin - @x
12012
12027
  end
12013
- if (@nested_table == true) or (dom[key]['attribute']['nested'] and (dom[key]['attribute']['nested'] == 'true'))
12028
+ if cell or (dom[key]['attribute']['nested'] and (dom[key]['attribute']['nested'] == 'true'))
12014
12029
  # add margin for nested tables
12015
12030
  wtmp -= @c_margin
12016
12031
  end
@@ -12028,10 +12043,12 @@ public
12028
12043
  dom[table_el]['cols'] = dom[trid]['cols']
12029
12044
  end
12030
12045
  oldmargin = @c_margin
12046
+ currentcmargin = @c_margin
12031
12047
  if !dom[(dom[trid]['parent'])]['attribute']['cellpadding'].nil?
12032
12048
  currentcmargin = getHTMLUnitToUnits(dom[(dom[trid]['parent'])]['attribute']['cellpadding'], 1, 'px')
12033
- else
12034
- currentcmargin = 0
12049
+ end
12050
+ if currentcmargin < (@line_width / 2.0)
12051
+ currentcmargin = @line_width / 2.0
12035
12052
  end
12036
12053
  @c_margin = currentcmargin
12037
12054
  if !dom[(dom[trid]['parent'])]['attribute']['cellspacing'].nil?
@@ -12082,7 +12099,7 @@ public
12082
12099
  if dom[trid]['startx'].nil?
12083
12100
  dom[trid]['startx'] = @x
12084
12101
  else
12085
- @x += (cellspacingx / 2)
12102
+ @x += (cellspacingx / 2.0)
12086
12103
  end
12087
12104
  if !dom[parentid]['attribute']['rowspan'].nil?
12088
12105
  rowspan = dom[parentid]['attribute']['rowspan'].to_i
@@ -12182,7 +12199,7 @@ public
12182
12199
  end
12183
12200
  }
12184
12201
  end
12185
- @x += (cellspacingx / 2)
12202
+ @x += (cellspacingx / 2.0)
12186
12203
  else
12187
12204
  # opening tag (or self-closing tag)
12188
12205
  if opentagpos.nil?
@@ -12218,7 +12235,7 @@ public
12218
12235
  if pfontsize.is_a?(Numeric) and (pfontsize > 0) and curfontsize.is_a?(Numeric) and (curfontsize > 0) and (pfontsize != curfontsize)
12219
12236
  pfontascent = getFontAscent(pfontname, pfontstyle, pfontsize)
12220
12237
  pfontdescent = getFontDescent(pfontname, pfontstyle, pfontsize)
12221
- @y += ((pfontsize - curfontsize) * @cell_height_ratio / @k + pfontascent - curfontascent - pfontdescent + curfontdescent) / 2
12238
+ @y += ((pfontsize - curfontsize) * @cell_height_ratio / @k + pfontascent - curfontascent - pfontdescent + curfontdescent) / 2.0
12222
12239
  minstartliney = [@y, minstartliney].min
12223
12240
  maxbottomliney = [@y + pfontsize * @cell_height_ratio / @k, maxbottomliney].max
12224
12241
  end
@@ -12374,9 +12391,9 @@ public
12374
12391
  mdiff = (tw - linew).abs
12375
12392
  if plalign == 'C'
12376
12393
  if @rtl
12377
- t_x = -(mdiff / 2)
12394
+ t_x = -(mdiff / 2.0)
12378
12395
  else
12379
- t_x = (mdiff / 2)
12396
+ t_x = (mdiff / 2.0)
12380
12397
  end
12381
12398
  elsif (plalign == 'R') and !@rtl
12382
12399
  # right alignment on LTR document
@@ -12500,12 +12517,30 @@ public
12500
12517
  @thead = dom[key]['thead']
12501
12518
  if @thead_margins.nil? or @thead_margins.empty?
12502
12519
  @thead_margins ||= {}
12503
- @thead_margins['cmargin'] = @c_margin
12520
+
12521
+ if dom[key]['attribute']['cellpadding']
12522
+ @thead_margins['cmargin'] = getHTMLUnitToUnits(dom[key]['attribute']['cellpadding'], 1, 'px')
12523
+ else
12524
+ @thead_margins['cmargin'] = @c_margin
12525
+ end
12526
+ if @thead_margins['cmargin'] < (@line_width / 2.0)
12527
+ @thead_margins['cmargin'] = @line_width / 2.0
12528
+ end
12529
+ if cell
12530
+ @thead_margins['lmargin'] = @l_margin + @c_margin
12531
+ @thead_margins['rmargin'] = @r_margin + @c_margin
12532
+ else
12533
+ @thead_margins['lmargin'] = @l_margin
12534
+ @thead_margins['rmargin'] = @r_margin
12535
+ end
12504
12536
  end
12505
12537
  end
12506
12538
  end
12507
12539
  if !tag['attribute']['cellpadding'].nil?
12508
12540
  cp = getHTMLUnitToUnits(tag['attribute']['cellpadding'], 1, 'px')
12541
+ if cp < (@line_width / 2.0)
12542
+ cp = @line_width / 2.0
12543
+ end
12509
12544
  @old_c_margin = @c_margin
12510
12545
  @c_margin = cp
12511
12546
  end
@@ -12526,7 +12561,7 @@ public
12526
12561
  else
12527
12562
  hrHeight = GetLineWidth()
12528
12563
  end
12529
- addHTMLVertSpace(hbz, (hrHeight / 2), cell, firstorlast)
12564
+ addHTMLVertSpace(hbz, (hrHeight / 2.0), cell, firstorlast)
12530
12565
  x = GetX()
12531
12566
  y = GetY()
12532
12567
  wtmp = @w - @l_margin - @r_margin
@@ -12543,7 +12578,7 @@ public
12543
12578
  Line(x, y, x + hrWidth, y)
12544
12579
  SetLineWidth(prevlinewidth)
12545
12580
  Ln('', cell)
12546
- addHTMLVertSpace(hrHeight / 2, 0, cell, dom[key + 1].nil?)
12581
+ addHTMLVertSpace(hrHeight / 2.0, 0, cell, dom[key + 1].nil?)
12547
12582
  when 'a'
12548
12583
  if tag['attribute'].key?('href')
12549
12584
  @href['url'] = get_sever_url(tag['attribute']['href'])
@@ -12594,11 +12629,6 @@ public
12594
12629
  xpos += 2 * GetStringWidth(32.chr)
12595
12630
  end
12596
12631
  end
12597
- if @rtl
12598
- xpos -= @line_width * 1.5
12599
- else
12600
- xpos += @line_width * 1.5
12601
- end
12602
12632
 
12603
12633
  imglink = ''
12604
12634
  if !@href['url'].nil? and !empty_string(@href['url'])
@@ -12636,8 +12666,8 @@ public
12636
12666
  l_margin = @l_margin
12637
12667
  r_margin = @r_margin
12638
12668
 
12639
- SetLeftMargin(@l_margin + @line_width * 1.5)
12640
- SetRightMargin(@r_margin + @line_width * 1.5)
12669
+ SetLeftMargin(@l_margin + @c_margin)
12670
+ SetRightMargin(@r_margin + @c_margin)
12641
12671
 
12642
12672
  begin
12643
12673
  # if (type == 'eps') or (type == 'ai')
@@ -12645,19 +12675,24 @@ public
12645
12675
  # elsif type == 'svg'
12646
12676
  # ImageSVG(tag['attribute']['src'], xpos, @y, iw, ih, imglink, align, '', border, true)
12647
12677
  # else
12648
- result_img = Image(tag['attribute']['src'], xpos, @y + @line_width * 1.5, iw, ih, '', imglink, align, false, 300, '', false, false, border, false, false, true)
12678
+ result_img = Image(tag['attribute']['src'], xpos, @y, iw, ih, '', imglink, align, false, 300, '', false, false, border, false, false, true)
12649
12679
  # end
12650
12680
  rescue => err
12651
12681
  logger.error "pdf: Image: error: #{err.message}"
12652
12682
  result_img = false
12653
12683
  end
12654
- case align
12655
- when 'T'
12684
+
12685
+ if result_img or ih != 0
12686
+ case align
12687
+ when 'T'
12688
+ @y = prevy
12689
+ when 'M'
12690
+ @y = (@img_rb_y + prevy - (tag['fontsize'] / @k)) / 2
12691
+ when 'B'
12692
+ @y = @img_rb_y - (tag['fontsize'] / @k)
12693
+ end
12694
+ else
12656
12695
  @y = prevy
12657
- when 'M'
12658
- @y = (@img_rb_y + prevy - (tag['fontsize'] / @k)) / 2
12659
- when 'B'
12660
- @y = @img_rb_y - (tag['fontsize'] / @k)
12661
12696
  end
12662
12697
 
12663
12698
  # restore original margin values
@@ -12879,8 +12914,8 @@ public
12879
12914
  end
12880
12915
  end
12881
12916
  end
12882
- when 'table', 'tablehead'
12883
- if tag['value'] == 'tablehead'
12917
+ when 'table'
12918
+ if dom[(dom[key]['parent'])]['attribute']['tablehead'] and dom[(dom[key]['parent'])]['attribute']['tablehead'] == "1"
12884
12919
  # closing tag used for the thead part
12885
12920
  in_table_head = true
12886
12921
  @in_thead = false
@@ -13051,8 +13086,10 @@ public
13051
13086
  @thead_margins = {}
13052
13087
  end
13053
13088
  end
13054
- if tag['block'] ### fix ###
13055
- addHTMLVertSpace(hbz / 2, 0, cell, (dom[key+1].nil? or (dom[key+1]['value'] != 'table')))
13089
+ if tag['block']
13090
+ unless dom[(dom[key]['parent'])]['attribute']['tablehead'] and dom[(dom[key]['parent'])]['attribute']['tablehead'] == "1" ### fix ###
13091
+ addHTMLVertSpace(hbz / 2, 0, cell, (dom[key+1].nil? or (dom[key+1]['value'] != 'table'))) ### fix ###
13092
+ end
13056
13093
  end
13057
13094
  when 'a'
13058
13095
  @href = {}
@@ -13253,11 +13290,11 @@ public
13253
13290
  end
13254
13291
  case unit
13255
13292
  when '%' # percentage
13256
- retval = (value * refsize) / 100
13293
+ retval = (value * refsize) / 100.0
13257
13294
  when 'em' # relative-size
13258
13295
  retval = value * refsize
13259
13296
  when 'ex' # height of lower case 'x' (about half the font-size)
13260
- retval = value * (refsize / 2)
13297
+ retval = value * (refsize / 2.0)
13261
13298
  when 'in' # absolute-size
13262
13299
  retval = (value * @dpi) / k
13263
13300
  when 'cm' # centimeters
@@ -13372,23 +13409,23 @@ protected
13372
13409
  when 'disc', 'circle'
13373
13410
  fill = 'F' if listtype == 'disc'
13374
13411
  fill << 'D'
13375
- r = size / 6
13412
+ r = size / 6.0
13376
13413
  lspace += 2 * r
13377
13414
  if @rtl
13378
13415
  @x += lspace
13379
13416
  else
13380
13417
  @x -= lspace
13381
13418
  end
13382
- Circle(@x + r, @y + @lasth / 2, r, 0, 360, fill, {'color'=>color}, color, 8)
13419
+ Circle(@x + r, @y + @lasth / 2.0, r, 0, 360, fill, {'color'=>color}, color, 8)
13383
13420
  when 'square'
13384
- l = size / 3
13421
+ l = size / 3.0
13385
13422
  lspace += l
13386
13423
  if @rtl
13387
13424
  @x += lspace
13388
13425
  else
13389
13426
  @x -= lspace
13390
13427
  end
13391
- Rect(@x, @y + (@lasth - l)/ 2, l, l, 'F', {}, color)
13428
+ Rect(@x, @y + (@lasth - l)/ 2.0, l, l, 'F', {}, color)
13392
13429
 
13393
13430
  # ordered types
13394
13431
  # listcount[@listnum]