lib/ttfunk/table/cff/fd_selector.rb in ttfunk-1.6.2.1 vs lib/ttfunk/table/cff/fd_selector.rb in ttfunk-1.7.0
- old
+ new
@@ -27,11 +27,12 @@
when :range_format
if (entry = range_cache[glyph_id])
return entry
end
- range, entry = entries.bsearch do |rng, _|
+ range, entry =
+ entries.bsearch do |rng, _|
if rng.cover?(glyph_id)
0
elsif glyph_id < rng.first
-1
else
@@ -51,13 +52,14 @@
end
# mapping is new -> old glyph ids
def encode(mapping)
# get list of [new_gid, fd_index] pairs
- new_indices = mapping.keys.sort.map do |new_gid|
- [new_gid, self[mapping[new_gid]]]
- end
+ new_indices =
+ mapping.keys.sort.map do |new_gid|
+ [new_gid, self[mapping[new_gid]]]
+ end
ranges = rangify_gids(new_indices)
total_range_size = ranges.size * RANGE_ENTRY_SIZE
total_array_size = new_indices.size * ARRAY_ENTRY_SIZE
@@ -117,32 +119,33 @@
num_ranges = read(2, 'n').first
@length += (num_ranges * RANGE_ENTRY_SIZE) + 4
ranges = Array.new(num_ranges) { read(RANGE_ENTRY_SIZE, 'nC') }
- @entries = ranges.each_cons(2).map do |first, second|
- first_gid, fd_index = first
- second_gid, = second
- [(first_gid...second_gid), fd_index]
- end
+ @entries =
+ ranges.each_cons(2).map do |first, second|
+ first_gid, fd_index = first
+ second_gid, = second
+ [(first_gid...second_gid), fd_index]
+ end
# read the sentinel GID, otherwise known as the number of glyphs
# in the font
@n_glyphs = read(2, 'n').first
last_start_gid, last_fd_index = ranges.last
@entries << [(last_start_gid...(n_glyphs + 1)), last_fd_index]
- @count = entries.inject(0) { |sum, entry| sum + entry.first.size }
+ @count = entries.reduce(0) { |sum, entry| sum + entry.first.size }
end
end
def format_sym
case @format
when ARRAY_FORMAT then :array_format
when RANGE_FORMAT then :range_format
else
- raise "unsupported fd select format '#{@format}'"
+ raise Error, "unsupported fd select format '#{@format}'"
end
end
end
end
end