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, either a ToUnicode CMap or a CID CMap.
Constant Summary collapse
- MAX_ENTRIES_IN_SECTION =
Maximum number of entries in one section.
100
Instance Method Summary collapse
-
#create_cid_cmap(mapping) ⇒ Object
Returns a CID CMap for the given input code to CID mapping which needs to be sorted by input codes.
-
#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_cid_cmap(mapping) ⇒ Object
Returns a CID CMap for the given input code to CID mapping which needs to be sorted by input codes.
Note that the returned CMap always uses a 16-bit input code space!
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/hexapdf/font/cmap/writer.rb', line 79 def create_cid_cmap(mapping) return cid_template % '' if mapping.empty? chars, ranges = compute_section_entries(mapping) result = create_sections("cidchar", chars.size / 2) do |index| index *= 2 sprintf("<%04X>", chars[index]) << " #{chars[index + 1]}\n" end result << create_sections("cidrange", ranges.size / 3) do |index| index *= 3 sprintf("<%04X><%04X>", ranges[index], ranges[index + 1]) << " #{ranges[index + 2]}\n" end cid_template % result.chop! end |
#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!
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/hexapdf/font/cmap/writer.rb', line 53 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]).unpack1('H*') << ">\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]).unpack1('H*') << ">\n" end to_unicode_template % result.chop! end |