Class: HexaPDF::Font::CMap::Writer
- Inherits:
-
Object
- Object
- HexaPDF::Font::CMap::Writer
- Defined in:
- lib/hexapdf/font/cmap/writer.rb
Overview
Creates a CMap file.
Currently only ToUnicode CMaps are supported.
Constant Summary collapse
- MAX_ENTRIES_IN_SECTION =
Maximum number of entries in one section.
100
Instance Method Summary collapse
-
#create_to_unicode_cmap(mapping) ⇒ Object
Returns a ToUnicode CMap for the given input code to Unicode codepoint mapping which needs to be sorted by input codes.
Instance Method Details
#create_to_unicode_cmap(mapping) ⇒ Object
Returns a ToUnicode CMap for the given input code to Unicode codepoint mapping which needs to be sorted by input codes.
Note that the returned CMap always uses a 16-bit input code space!
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hexapdf/font/cmap/writer.rb', line 52 def create_to_unicode_cmap(mapping) return to_unicode_template % '' if mapping.empty? chars, ranges = compute_section_entries(mapping) result = create_sections("bfchar", chars.size / 2) do |index| index *= 2 sprintf("<%04X>", chars[index]) << "<" << (''.force_encoding(::Encoding::UTF_16BE) << chars[index + 1]).unpack('H*').first << ">\n" end result << create_sections("bfrange", ranges.size / 3) do |index| index *= 3 sprintf("<%04X><%04X>", ranges[index], ranges[index + 1]) << "<" << (''.force_encoding(::Encoding::UTF_16BE) << ranges[index + 2]).unpack('H*').first << ">\n" end to_unicode_template % result.chop! end |