Commit 2c830770 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

ruby1.9 compatibility

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4602 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 97485674
...@@ -379,12 +379,20 @@ class FPDF ...@@ -379,12 +379,20 @@ class FPDF
@ColorFlag=(@FillColor!=@TextColor) @ColorFlag=(@FillColor!=@TextColor)
end end
def GetCharWidth(widths, index)
if index.is_a?(String)
widths[index.ord]
else
widths[index]
end
end
def GetStringWidth(s) def GetStringWidth(s)
# Get width of a string in the current font # Get width of a string in the current font
cw=@CurrentFont['cw'] cw=@CurrentFont['cw']
w=0 w=0
s.each_byte do |c| s.each_byte do |c|
w=w+cw[c] w=w+GetCharWidth(cw, c)
end end
w*@FontSize/1000.0 w*@FontSize/1000.0
end end
...@@ -707,7 +715,7 @@ class FPDF ...@@ -707,7 +715,7 @@ class FPDF
ls=l ls=l
ns=ns+1 ns=ns+1
end end
l=l+cw[c[0]] l=l+GetCharWidth(cw, c[0])
if l>wmax if l>wmax
# Automatic line break # Automatic line break
if sep==-1 if sep==-1
...@@ -786,7 +794,7 @@ class FPDF ...@@ -786,7 +794,7 @@ class FPDF
sep=i sep=i
ls=l ls=l
end end
l=l+cw[c]; l=l+GetCharWidth(cw, c);
if l>wmax if l>wmax
# Automatic line break # Automatic line break
if sep==-1 if sep==-1
...@@ -1079,7 +1087,7 @@ class FPDF ...@@ -1079,7 +1087,7 @@ class FPDF
cw=font['cw'] cw=font['cw']
s='[' s='['
32.upto(255) do |i| 32.upto(255) do |i|
s << cw[i].to_s+' ' s << GetCharWidth(cw, i).to_s + ' '
end end
out(s+']') out(s+']')
out('endobj') out('endobj')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment