Class: HexaPDF::Font::CMap

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/font/cmap.rb,
lib/hexapdf/font/cmap/parser.rb,
lib/hexapdf/font/cmap/writer.rb

Overview

Represents a CMap, a mapping from character codes to CIDs (character IDs) or to their Unicode value.

Currently, only the mapping to the Unicode values is supported.

See: PDF1.7 s9.7.5, s9.10.3; Adobe Technical Note #5411

Defined Under Namespace

Classes: Parser, Writer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCMap

Creates a new CMap object.



77
78
79
# File 'lib/hexapdf/font/cmap.rb', line 77

def initialize
  @unicode_mapping = Hash.new("".freeze)
end

Instance Attribute Details

#nameObject

The name of the CMap.



71
72
73
# File 'lib/hexapdf/font/cmap.rb', line 71

def name
  @name
end

#orderingObject

The ordering part of the CMap version.



65
66
67
# File 'lib/hexapdf/font/cmap.rb', line 65

def ordering
  @ordering
end

#registryObject

The registry part of the CMap version.



62
63
64
# File 'lib/hexapdf/font/cmap.rb', line 62

def registry
  @registry
end

#supplementObject

The supplement part of the CMap version.



68
69
70
# File 'lib/hexapdf/font/cmap.rb', line 68

def supplement
  @supplement
end

#unicode_mappingObject

The mapping from character codes to Unicode values.



74
75
76
# File 'lib/hexapdf/font/cmap.rb', line 74

def unicode_mapping
  @unicode_mapping
end

Class Method Details

.create_to_unicode_cmap(mapping) ⇒ Object

Returns a string containing a ToUnicode CMap that represents the given code to Unicode codepoint mapping.

See: Writer#create_to_unicode_cmap



57
58
59
# File 'lib/hexapdf/font/cmap.rb', line 57

def self.create_to_unicode_cmap(mapping)
  Writer.new.create_to_unicode_cmap(mapping)
end

.parse(string) ⇒ Object

Creates a new CMap object from the given string which needs to contain a valid CMap file.



49
50
51
# File 'lib/hexapdf/font/cmap.rb', line 49

def self.parse(string)
  Parser.new.parse(string)
end

Instance Method Details

#to_unicode(code) ⇒ Object

Returns the Unicode string in UTF-8 encoding for the given character code, or an empty string if no mapping was found.



83
84
85
# File 'lib/hexapdf/font/cmap.rb', line 83

def to_unicode(code)
  unicode_mapping[code]
end