class HexaPDF::Font::TrueType::Table::CmapSubtable
-
developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html<br>* Cmap
See:
and memory efficient code-to-gid as well as gid-to-code mappings.
The preferred cmap format is 12.0 because it supports all of Unicode and allows for fast
the specification and no font with a format 8.0 cmap subtable was available for testing.
cmap format 8.0 is currently not implemented because use of the format is discouraged in
Generic base class for all cmap subtables.
def [](code)
Returns the glyph index for the given character code or +nil+ if the character code is
def [](code) @code_map[code] end
def gid_to_code(gid)
minus), i.e. the code-to-glyph mapping is surjective but not injective! In such a case
Note that some fonts map multiple character codes to the same glyph (e.g. hyphen and
does not exist or is not mapped to a character code.
Returns a character code for the given glyph index or +nil+ if the given glyph index
def gid_to_code(gid) @gid_map[gid] end
def initialize(platform_id, encoding_id)
def initialize(platform_id, encoding_id) @platform_id = platform_id @encoding_id = encoding_id @supported = true @code_map = {} @gid_map = {} @format = nil @language = 0 end
def inspect #:nodoc:
def inspect #:nodoc: "#<#{self.class.name} (#{platform_id}, #{encoding_id}, #{language}, " \ "#{format.inspect})>" end
def parse(io, offset)
If the subtable format is supported, the information is used to populate this object and
Parses the cmap subtable from the IO at the given offset.
subtable.parse!(io, offset) => true or false
:call-seq:
def parse(io, offset) io.pos = offset @format = io.read(2).unpack1('n') if [8, 10, 12].include?(@format) io.pos += 2 length, @language = io.read(8).unpack('N2') elsif [0, 2, 4, 6].include?(@format) length, @language = io.read(4).unpack('n2') end return false unless [0, 2, 4, 6, 10, 12].include?(@format) offset = io.pos @code_map = lambda do |code| parse_mapping(io, offset, length) @code_map[code] end @gid_map = lambda do |gid| parse_mapping(io, offset, length) @gid_map[gid] end true end
def parse_mapping(io, offset, length)
def parse_mapping(io, offset, length) io.pos = offset @code_map, @gid_map = case @format when 0 then Format0.parse(io, length) when 2 then Format2.parse(io, length) when 4 then Format4.parse(io, length) when 6 then Format6.parse(io, length) when 10 then Format10.parse(io, length) when 12 then Format12.parse(io, length) end end
def unicode?
def unicode? (platform_id == PLATFORM_MICROSOFT && (encoding_id == 1 || encoding_id == 10)) || platform_id == PLATFORM_UNICODE end