Class: PDF::Reader::CMap

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/cmap.rb

Overview

wraps a string containing a PDF CMap and provides convenience methods for extracting various useful information.

Constant Summary collapse

CMAP_KEYWORDS =

:nodoc:

{
  "begincodespacerange" => :noop,
  "endcodespacerange" => :noop,
  "beginbfchar" => :noop,
  "endbfchar" => :noop,
  "beginbfrange" => :noop,
  "endbfrange" => :noop,
  "begin" => :noop,
  "begincmap" => :noop,
  "def" => :noop
}
HIGH_SURROGATE_RANGE =

Indicates the start of a UTF-16 surrogate pair, see https://en.wikipedia.org/wiki/Universal_Character_Set_characters

(0xD800..0xDBFF)
EMPTY_CODEPOINTS =

Signature:

  • Array[Integer]

[].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CMap

Returns a new instance of CMap.

Signature:

  • (String) -> void



59
60
61
62
# File 'lib/pdf/reader/cmap.rb', line 59

def initialize(data)
  @map = {} #: Hash[Integer, Array[Integer]]
  process_data(data)
end

Instance Attribute Details

#mapObject (readonly)

Signature:

  • Hash[Integer, Array[Integer]]



56
57
58
# File 'lib/pdf/reader/cmap.rb', line 56

def map
  @map
end

Instance Method Details

#decode(c) ⇒ Object

Convert a glyph code into one or more Codepoints.

Returns an array of Integers.

Signature:

  • (Integer) -> Array[Integer]



74
75
76
# File 'lib/pdf/reader/cmap.rb', line 74

def decode(c)
  @map.fetch(c, EMPTY_CODEPOINTS)
end

#sizeObject

Signature:

  • () -> Integer



65
66
67
# File 'lib/pdf/reader/cmap.rb', line 65

def size
  @map.size
end