diff --git a/.rubocop.yml b/.rubocop.yml index 45b62dd..7173033 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,6 @@ inherit_gem: prawn-dev: rubocop.yml -RSpec/FilePath: - Enabled: false - RSpec/MultipleMemoizedHelpers: Max: 7 Exclude: @@ -20,7 +17,6 @@ Style/FormatStringToken: Exclude: - examples/metrics.rb - Style/Documentation: Exclude: - examples/**/*.rb diff --git a/lib/ttfunk.rb b/lib/ttfunk.rb index c0420f2..8a8a078 100644 --- a/lib/ttfunk.rb +++ b/lib/ttfunk.rb @@ -154,7 +154,7 @@ def initialize(contents, offset = 0) # # @return [Integer] def ascent - @ascent ||= (os2.exists? && os2.ascent && os2.ascent.nonzero?) || + @ascent ||= (os2.exists? && os2&.ascent&.nonzero?) || horizontal_header.ascent end @@ -162,7 +162,7 @@ def ascent # # @return [Integer] def descent - @descent ||= (os2.exists? && os2.descent && os2.descent.nonzero?) || + @descent ||= (os2.exists? && os2&.descent&.nonzero?) || horizontal_header.descent end @@ -170,7 +170,7 @@ def descent # # @return [Integer] def line_gap - @line_gap ||= (os2.exists? && os2.line_gap && os2.line_gap.nonzero?) || + @line_gap ||= (os2.exists? && os2&.line_gap&.nonzero?) || horizontal_header.line_gap end diff --git a/lib/ttfunk/bin_utils.rb b/lib/ttfunk/bin_utils.rb index 2552c47..9035dd8 100644 --- a/lib/ttfunk/bin_utils.rb +++ b/lib/ttfunk/bin_utils.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module TTFunk # rubocop: disable Style/Documentation # false positive +module TTFunk # Bit crunching utility methods. module BinUtils # Turn a bunch of small integers into one big integer. Assumes big-endian. @@ -17,6 +17,7 @@ def stitch_int(arr, bit_width:) value end + module_function :stitch_int # Slice a big integer into a bunch of small integers. Assumes big-endian. # @@ -32,6 +33,7 @@ def slice_int(value, bit_width:, slice_count:) (value >> (bit_width * i)) & mask end end + module_function :slice_int # Two's compliment to an integer. # @@ -49,6 +51,7 @@ def twos_comp_to_int(num, bit_width:) num end end + module_function :twos_comp_to_int # Turns a (sorted) sequence of values into a series of two-element arrays # where the first element is the start and the second is the length. @@ -60,7 +63,6 @@ def rangify(values) .slice_when { |a, b| b - a > 1 } .map { |span| [span.first, span.length - 1] } end + module_function :rangify end - - BinUtils.extend(BinUtils) end diff --git a/lib/ttfunk/bit_field.rb b/lib/ttfunk/bit_field.rb index af20168..1dd04c7 100644 --- a/lib/ttfunk/bit_field.rb +++ b/lib/ttfunk/bit_field.rb @@ -25,7 +25,7 @@ def on(pos) # @param pos [Integer] # @return [Boolean] def on?(pos) - (value & (2**pos)).positive? + value.allbits?(2**pos) end # Set bit off. diff --git a/lib/ttfunk/subset/base.rb b/lib/ttfunk/subset/base.rb index 5a2e4e7..18e7c5c 100644 --- a/lib/ttfunk/subset/base.rb +++ b/lib/ttfunk/subset/base.rb @@ -102,7 +102,7 @@ def collect_glyphs(glyph_ids) end additional_ids = collected.values - .select { |g| g && g.compound? } + .select { |g| g&.compound? } .map(&:glyph_ids) .flatten diff --git a/lib/ttfunk/table/cff/charstring.rb b/lib/ttfunk/table/cff/charstring.rb index fd3f947..0a5e898 100644 --- a/lib/ttfunk/table/cff/charstring.rb +++ b/lib/ttfunk/table/cff/charstring.rb @@ -126,16 +126,16 @@ def parse! # return from callgsubr - do nothing since we inline subrs next if code == 11 - if code >= 32 && code <= 246 + if code.between?(32, 246) @stack << (code - 139) elsif (m = CODE_MAP[code]) __send__(m) - elsif code >= 247 && code <= 250 + elsif code.between?(247, 250) b0 = code b1 = @data[@index] @index += 1 @stack << (((b0 - 247) * 256) + b1 + 108) - elsif code >= 251 && code <= 254 + elsif code.between?(251, 254) b0 = code b1 = @data[@index] @index += 1 diff --git a/lib/ttfunk/table/cmap/format04.rb b/lib/ttfunk/table/cmap/format04.rb index ab9001e..d586bec 100644 --- a/lib/ttfunk/table/cmap/format04.rb +++ b/lib/ttfunk/table/cmap/format04.rb @@ -141,7 +141,7 @@ def parse_cmap! end_code.each_with_index do |tail, i| start_code[i].upto(tail) do |code| - if (id_range_offset[i]).zero? + if id_range_offset[i].zero? glyph_id = code + id_delta[i] else index = (id_range_offset[i] / 2) + (code - start_code[i]) - (segcount - i) diff --git a/lib/ttfunk/table/cmap/subtable.rb b/lib/ttfunk/table/cmap/subtable.rb index 230cdb3..4d8cb0c 100644 --- a/lib/ttfunk/table/cmap/subtable.rb +++ b/lib/ttfunk/table/cmap/subtable.rb @@ -107,7 +107,7 @@ def initialize(file, table_start) # # @return [Boolean] def unicode? - (platform_id == 3 && (encoding_id == 1 || encoding_id == 10) && format != 0) || + (platform_id == 3 && [1, 10].include?(encoding_id) && format != 0) || (platform_id.zero? && format != 0) end diff --git a/lib/ttfunk/table/glyf/compound.rb b/lib/ttfunk/table/glyf/compound.rb index 0f8fe15..fd2ff83 100644 --- a/lib/ttfunk/table/glyf/compound.rb +++ b/lib/ttfunk/table/glyf/compound.rb @@ -110,22 +110,22 @@ def initialize(id, raw) @glyph_ids << glyph_id @glyph_id_offsets << (offset + 2) - break if (flags & MORE_COMPONENTS).zero? + break if flags.nobits?(MORE_COMPONENTS) offset += 4 offset += - if (flags & ARG_1_AND_2_ARE_WORDS).zero? + if flags.nobits?(ARG_1_AND_2_ARE_WORDS) 2 else 4 end - if flags & WE_HAVE_A_TWO_BY_TWO != 0 + if flags.allbits?(WE_HAVE_A_TWO_BY_TWO) offset += 8 - elsif flags & WE_HAVE_AN_X_AND_Y_SCALE != 0 + elsif flags.allbits?(WE_HAVE_AN_X_AND_Y_SCALE) offset += 4 - elsif flags & WE_HAVE_A_SCALE != 0 + elsif flags.allbits?(WE_HAVE_A_SCALE) offset += 2 end end diff --git a/lib/ttfunk/table/kern.rb b/lib/ttfunk/table/kern.rb index 676cdad..a1f50c5 100644 --- a/lib/ttfunk/table/kern.rb +++ b/lib/ttfunk/table/kern.rb @@ -65,10 +65,10 @@ def parse_version_0_tables(_num_tables) length: length, coverage: coverage, data: raw[10..], - vertical: (coverage & 0x1).zero?, - minimum: (coverage & 0x2 != 0), - cross: (coverage & 0x4 != 0), - override: (coverage & 0x8 != 0), + vertical: coverage.nobits?(0x1), + minimum: coverage.allbits?(0x2), + cross: coverage.allbits?(0x4), + override: coverage.allbits?(0x8), ) end @@ -83,9 +83,9 @@ def parse_version_1_tables(num_tables) coverage: coverage, tuple_index: tuple_index, data: io.read(length - 8), - vertical: (coverage & 0x8000 != 0), - cross: (coverage & 0x4000 != 0), - variation: (coverage & 0x2000 != 0), + vertical: coverage.nobits?(0x8000), + cross: coverage.allbits?(0x4000), + variation: coverage.allbits?(0x2000), ) end end diff --git a/lib/ttfunk/table/os2.rb b/lib/ttfunk/table/os2.rb index 1988eed..69f8034 100644 --- a/lib/ttfunk/table/os2.rb +++ b/lib/ttfunk/table/os2.rb @@ -436,7 +436,7 @@ def encode(os2, subset) new_cmap_table = subset.new_cmap_table[:charmap] code_points = new_cmap_table .keys - .select { |k| (new_cmap_table[k][:new]).positive? } + .select { |k| new_cmap_table[k][:new].positive? } .sort # "This value depends on which character sets the font supports. diff --git a/spec/integration/subset_spec.rb b/spec/integration/subset_spec.rb index e4f223b..5636d12 100644 --- a/spec/integration/subset_spec.rb +++ b/spec/integration/subset_spec.rb @@ -145,15 +145,10 @@ subset.use(97) name = TTFunk::File.new(subset.encode).name - records = [] - name.entries.each do |entry| - records << [ - entry[:platform_id], - entry[:encoding_id], - entry[:language_id], - entry[:name_id], - ] - end + records = + name.entries.map { |entry| + entry.values_at(:platform_id, :encoding_id, :language_id, :name_id) + } expect(records).to eq(records.sort) end diff --git a/ttfunk.gemspec b/ttfunk.gemspec index 9ee442c..ff758a8 100644 --- a/ttfunk.gemspec +++ b/ttfunk.gemspec @@ -50,6 +50,6 @@ Gem::Specification.new do |spec| } spec.required_ruby_version = '>= 2.7' - spec.add_runtime_dependency('bigdecimal', '~> 3.1') - spec.add_development_dependency('prawn-dev', '~> 0.4.0') + spec.add_dependency('bigdecimal', '~> 3.1') + spec.add_development_dependency('prawn-dev', '~> 0.6.0') end