Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
inherit_gem:
prawn-dev: rubocop.yml

RSpec/FilePath:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Max: 7
Exclude:
Expand All @@ -20,7 +17,6 @@ Style/FormatStringToken:
Exclude:
- examples/metrics.rb


Style/Documentation:
Exclude:
- examples/**/*.rb
Expand Down
6 changes: 3 additions & 3 deletions lib/ttfunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,23 @@ 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

# Glyphs descent as defined in the font.
#
# @return [Integer]
def descent
@descent ||= (os2.exists? && os2.descent && os2.descent.nonzero?) ||
@descent ||= (os2.exists? && os2&.descent&.nonzero?) ||
horizontal_header.descent
end

# Line gap as defined in the font.
#
# @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

Expand Down
8 changes: 5 additions & 3 deletions lib/ttfunk/bin_utils.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
#
Expand All @@ -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.
#
Expand All @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/ttfunk/bit_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/ttfunk/subset/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/ttfunk/table/cff/charstring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ttfunk/table/cmap/format04.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/ttfunk/table/cmap/subtable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions lib/ttfunk/table/glyf/compound.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/ttfunk/table/kern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ttfunk/table/os2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 4 additions & 9 deletions spec/integration/subset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ttfunk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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