class TTFunk::Table::Cff::Encoding
def encode(charmap)
-
(String)
-
Parameters:
-
charmap
(Hash{Integer => Hash}
) -- keys are the charac codes,
def encode(charmap) # Any subset encoding is all but guaranteed to be different from the # standard encoding so we don't even attempt to see if it matches. We # assume it's different and just encode it anew. return encode_supplemental(charmap) if supplemental? codes = charmap .reject { |_code, mapping| mapping[:new].zero? } .sort_by { |_code, mapping| mapping[:new] } .map { |(code, _m)| code } ranges = TTFunk::BinUtils.rangify(codes) # calculate whether storing the charset as a series of ranges is # more efficient (i.e. takes up less space) vs storing it as an # array of SID values total_range_size = (2 * ranges.size) + (element_width(:range_format) * ranges.size) total_array_size = codes.size * element_width(:array_format) if total_array_size <= total_range_size ([format_int(:array_format), codes.size] + codes).pack('C*') else element_fmt = element_format(:range_format) result = [format_int(:range_format), ranges.size].pack('CC') ranges.each { |range| result << range.pack(element_fmt) } result end end