Browse files

[Ruby1.9] Compatibility that still allows 1.8.6 ruby too and not forc…

…e 1.8.7 transitional support.
  • Loading branch information...
1 parent cb725fb commit 738b1810e068f63f07077bed536ebce3ff21d904 @metaskills committed May 19, 2009
Showing with 15 additions and 3 deletions.
  1. +5 −1 lib/pdf/techbook.rb
  2. +5 −1 lib/pdf/writer.rb
  3. +5 −1 lib/pdf/writer/graphics.rb
View
6 lib/pdf/techbook.rb
@@ -854,7 +854,11 @@ def self.run(args)
# class program, then regenerate.
if (_tm_doc < _tm_cch) and (_tm_prg < _tm_cch)
$stderr.puts PDF::Writer::Lang[:techbook_using_cached_doc] % File.basename(files[:cache])
- pdf = File.open(files[:cache], "rb:binary") { |cf| Marshal.load(cf.read) }
+ if RUBY_VERSION >= '1.9'
+ pdf = File.open(files[:cache], "rb:binary") { |cf| Marshal.load(cf.read) }
+ else
+ pdf = File.open(files[:cache], "rb") { |cf| Marshal.load(cf.read) }
+ end
pdf.save_as(files[:pdf])
File.open(files[:pdf], "wb") { |pf| pf.write pdf.render }
exit(0)
View
6 lib/pdf/writer.rb
@@ -1467,7 +1467,11 @@ def add_text(x, y, text, size = nil, angle = 0, word_space_adjust = 0)
end
def char_width(font, char)
- char = char.bytes.to_a.first unless @fonts[font].c[char]
+ if RUBY_VERSION >= '1.9'
+ char = char.bytes.to_a.first unless @fonts[font].c[char]
+ else
+ char = char[0] unless @fonts[font].c[char]
+ end
if @fonts[font].differences and @fonts[font].c[char].nil?
name = @fonts[font].differences[char] || 'M'
View
6 lib/pdf/writer/graphics.rb
@@ -543,7 +543,11 @@ def add_image_from_file(image, x, y, width = nil, height = nil, link = nil)
if image.respond_to?(:read)
data = image.read
else
- open(image,'rb:binary') { |ff| data = ff.read }
+ if RUBY_VERSION >= '1.9'
+ open(image,'rb:binary') { |ff| data = ff.read }
+ else
+ open(image,'rb') { |ff| data = ff.read }
+ end
end
add_image(data, x, y, width, height, nil, link)

0 comments on commit 738b181

Please sign in to comment.