Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix deprecation warnings in Ruby 1.9+ #11

Merged
merged 2 commits into from

2 participants

@rolftimmermans

This fixes the following deprecation warning in later Ruby 1.9 versions:

prawn-svg/lib/prawn/svg/font.rb:1:in `<top (required)>': iconv will be deprecated in the future, use String#encode instead.

Additionally, a small incompatibility with Ruby 1.9 was fixed.

@mogest
Owner

Thanks for the patch - this won't be backwards compatible with 1.8 unfortunately.

Can I suggest something like if field.respond_to?(:encode) field.encode(...) else Iconv.iconv(...)

I'm not sure that calling ord on a string is going to work in 1.8 or 1.9 either. Maybe replace it with

x = f.read(12).each_byte.to_a

which will work in both 1.8 and 1.9, or otherwise change x[4] to x[4].ord and so on

@rolftimmermans

Excellent suggestions, see the updated commit for improvements. Silly of me to forget backward compatibility, I've been living in a Ruby 1.9 world too long. :-)

@mogest mogest merged commit bef6768 into from
@mogest
Owner

Thanks, perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 12, 2012
  1. @rolftimmermans
Commits on Apr 13, 2012
  1. @rolftimmermans
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 4 deletions.
  1. +7 −4 lib/prawn/svg/font.rb
View
11 lib/prawn/svg/font.rb
@@ -1,5 +1,3 @@
-require 'iconv'
-
class Prawn::Svg::Font
BUILT_IN_FONTS = ["Courier", "Helvetica", "Times-Roman", "Symbol", "ZapfDingbats"]
@@ -59,7 +57,7 @@ def self.installed_fonts
def self.font_information(filename)
File.open(filename, "r") do |f|
x = f.read(12)
- table_count = x[4] * 256 + x[5]
+ table_count = x[4].ord * 256 + x[5].ord
tables = f.read(table_count * 16)
offset, length = table_count.times do |index|
@@ -86,7 +84,12 @@ def self.font_information(filename)
field = data[offset..offset+length-1]
names[name_id] = if platform_id == 0
begin
- Iconv.iconv('UTF-8', 'UTF-16', field)
+ if field.respond_to?(:encode)
+ field.encode(Encoding::UTF16)
+ else
+ require "iconv"
+ Iconv.iconv('UTF-8', 'UTF-16', field)
+ end
rescue
field
end
Something went wrong with that request. Please try again.