lib/epdfafm.rb in eideticpdf-0.9.9 vs lib/epdfafm.rb in eideticpdf-1.0.0
- old
+ new
@@ -13,15 +13,23 @@
# AfmChar = Struct.new(:code, :name, :w0x, :w1x, :w0y, :w1y, :w0, :w1, :vv, :b, :l)
AfmChar = Struct.new(:code, :name, :width)
FontPath = [File.join(File.dirname(__FILE__), '..', 'fonts')]
class Codepoints
- def self.for_encoding(encoding)
- require 'iconv'
- encoding = 'CP1252' if encoding == 'WinAnsiEncoding'
- @@codepoints_by_encoding ||= {}
- @@codepoints_by_encoding[encoding] ||= Iconv.open("UCS-2BE//IGNORE", encoding) do |ic|
- (0..255).map { |c| ic.iconv(c.chr) }.map { |s| s.unpack('n') }.map { |a| a.first }
+ if ''.respond_to?(:encoding) # Ruby 1.9+
+ def self.for_encoding(encoding)
+ encoding = 'CP1252' if encoding == 'WinAnsiEncoding'
+ @@codepoints_by_encoding ||= {}
+ @@codepoints_by_encoding[encoding] ||= (0..255).inject('') { |m, n| m << n.chr }.encode('UCS-2BE', encoding, :undef => :replace).unpack('n*')
+ end
+ else
+ def self.for_encoding(encoding)
+ require 'iconv'
+ encoding = 'CP1252' if encoding == 'WinAnsiEncoding'
+ @@codepoints_by_encoding ||= {}
+ @@codepoints_by_encoding[encoding] ||= Iconv.open("UCS-2BE//IGNORE", encoding) do |ic|
+ (0..255).map { |c| ic.iconv(c.chr) }.map { |s| s.unpack('n') }.map { |a| a.first }
+ end
end
end
end
class Glyphs