lib/ttfunk/table/cff/encoding.rb in ttfunk-1.6.2.1 vs lib/ttfunk/table/cff/encoding.rb in ttfunk-1.7.0
- old
+ new
@@ -41,11 +41,11 @@
# +1 adjusts for the implicit .notdef glyph
(count + 1).times { |i| yield self[i] }
end
def [](glyph_id)
- return 0 if glyph_id == 0
+ return 0 if glyph_id.zero?
return code_for(glyph_id) if offset
self.class.codes_for_encoding_id(offset_or_id)[glyph_id]
end
@@ -66,13 +66,14 @@
# no offset means no encoding was specified (i.e. we're supposed to
# use a predefined encoding) so there's nothing to encode
return '' unless offset
return encode_supplemental(new_to_old, old_to_new) if supplemental?
- codes = new_to_old.keys.sort.map do |new_gid|
- code_for(new_to_old[new_gid])
- end
+ codes =
+ new_to_old.keys.sort.map do |new_gid|
+ code_for(new_to_old[new_gid])
+ end
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
@@ -98,15 +99,16 @@
end
private
def encode_supplemental(_new_to_old, old_to_new)
- new_entries = @entries.each_with_object({}) do |(code, old_gid), ret|
- if (new_gid = old_to_new[old_gid])
- ret[code] = new_gid
+ new_entries =
+ @entries.each_with_object({}) do |(code, old_gid), ret|
+ if (new_gid = old_to_new[old_gid])
+ ret[code] = new_gid
+ end
end
- end
result = [format_int(:supplemental), new_entries.size].pack('CC')
fmt = element_format(:supplemental)
new_entries.each do |code, new_gid|
@@ -115,18 +117,18 @@
result
end
def code_for(glyph_id)
- return 0 if glyph_id == 0
+ return 0 if glyph_id.zero?
# rather than validating the glyph as part of one of the predefined
# encodings, just pass it through
return glyph_id unless offset
case format_sym
- when :array_format
+ when :array_format, :supplemental
@entries[glyph_id]
when :range_format
remaining = glyph_id
@@ -137,13 +139,10 @@
remaining -= range.size
end
0
-
- when :supplemental
- @entries[glyph_id]
end
end
def parse!
@format, entry_count = read(2, 'C*')
@@ -174,45 +173,45 @@
end
end
end
def element_format(fmt = format_sym)
- case fmt
- when :array_format then 'C'
- when :range_format then 'CC'
- when :supplemental then 'Cn'
- end
+ {
+ array_format: 'C',
+ range_format: 'CC',
+ supplemental: 'Cn'
+ }[fmt]
end
# @TODO: handle supplemental encoding (necessary?)
def element_width(fmt = format_sym)
case fmt
when :array_format then 1
when :range_format then 2
when :supplemental then 3
else
- raise "'#{fmt}' is an unsupported encoding format"
+ raise Error, "'#{fmt}' is an unsupported encoding format"
end
end
def format_sym
return :supplemental if supplemental?
case @format
when 0 then :array_format
when 1 then :range_format
else
- raise "unsupported charset format '#{fmt}'"
+ raise Error, "unsupported charset format '#{fmt}'"
end
end
def format_int(sym = format_sym)
case sym
when :array_format then 0
when :range_format then 1
when :supplemental then 129
else
- raise "unsupported charset format '#{sym}'"
+ raise Error, "unsupported charset format '#{sym}'"
end
end
end
end
end