lib/pdf/reader/cmap.rb in pdf-reader-1.2.0 vs lib/pdf/reader/cmap.rb in pdf-reader-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# coding: utf-8
+
################################################################################
#
# Copyright (C) 2008 James Healy (jimmy@deefa.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -22,10 +24,14 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################
class PDF::Reader
+
+ # wraps a string containing a PDF CMap and provides convenience methods for
+ # extracting various useful information.
+ #
class CMap # :nodoc:
attr_reader :map
def initialize(data)
@@ -82,12 +88,12 @@
unpacked_string = if str.size == 1 # UTF-8
str.unpack("C*")
else # UTF-16
str.unpack("n*")
end
- if unpacked_string.length == 1
+ if unpacked_string.size == 1
unpacked_string
- elsif unpacked_string.length == 2 && (unpacked_string[0] > 0xD800 && unpacked_string[0] < 0xDBFF)
+ elsif unpacked_string.size == 2 && unpacked_string[0] > 0xD800 && unpacked_string[0] < 0xDBFF
# this is a Unicode UTF-16 "Surrogate Pair" see Unicode Spec. Chapter 3.7
# lets convert to a UTF-32. (the high bit is between 0xD800-0xDBFF, the
# low bit is between 0xDC00-0xDFFF) for example: U+1D44E (U+D835 U+DC4E)
[(unpacked_string[0] - 0xD800) * 0x400 + (unpacked_string[1] - 0xDC00) + 0x10000]
else