Skip to content

Commit f55c10f

Browse files
committed
Update code style
1 parent 5f64ca9 commit f55c10f

File tree

13 files changed

+34
-41
lines changed

13 files changed

+34
-41
lines changed

.rubocop.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
inherit_gem:
22
prawn-dev: rubocop.yml
33

4-
RSpec/FilePath:
5-
Enabled: false
6-
74
RSpec/MultipleMemoizedHelpers:
85
Max: 7
96
Exclude:
@@ -20,7 +17,6 @@ Style/FormatStringToken:
2017
Exclude:
2118
- examples/metrics.rb
2219

23-
2420
Style/Documentation:
2521
Exclude:
2622
- examples/**/*.rb

lib/ttfunk.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,23 @@ def initialize(contents, offset = 0)
154154
#
155155
# @return [Integer]
156156
def ascent
157-
@ascent ||= (os2.exists? && os2.ascent && os2.ascent.nonzero?) ||
157+
@ascent ||= (os2.exists? && os2&.ascent&.nonzero?) ||
158158
horizontal_header.ascent
159159
end
160160

161161
# Glyphs descent as defined in the font.
162162
#
163163
# @return [Integer]
164164
def descent
165-
@descent ||= (os2.exists? && os2.descent && os2.descent.nonzero?) ||
165+
@descent ||= (os2.exists? && os2&.descent&.nonzero?) ||
166166
horizontal_header.descent
167167
end
168168

169169
# Line gap as defined in the font.
170170
#
171171
# @return [Integer]
172172
def line_gap
173-
@line_gap ||= (os2.exists? && os2.line_gap && os2.line_gap.nonzero?) ||
173+
@line_gap ||= (os2.exists? && os2&.line_gap&.nonzero?) ||
174174
horizontal_header.line_gap
175175
end
176176

lib/ttfunk/bin_utils.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module TTFunk # rubocop: disable Style/Documentation # false positive
3+
module TTFunk
44
# Bit crunching utility methods.
55
module BinUtils
66
# Turn a bunch of small integers into one big integer. Assumes big-endian.
@@ -17,6 +17,7 @@ def stitch_int(arr, bit_width:)
1717

1818
value
1919
end
20+
module_function :stitch_int
2021

2122
# Slice a big integer into a bunch of small integers. Assumes big-endian.
2223
#
@@ -32,6 +33,7 @@ def slice_int(value, bit_width:, slice_count:)
3233
(value >> (bit_width * i)) & mask
3334
end
3435
end
36+
module_function :slice_int
3537

3638
# Two's compliment to an integer.
3739
#
@@ -49,6 +51,7 @@ def twos_comp_to_int(num, bit_width:)
4951
num
5052
end
5153
end
54+
module_function :twos_comp_to_int
5255

5356
# Turns a (sorted) sequence of values into a series of two-element arrays
5457
# where the first element is the start and the second is the length.
@@ -60,7 +63,6 @@ def rangify(values)
6063
.slice_when { |a, b| b - a > 1 }
6164
.map { |span| [span.first, span.length - 1] }
6265
end
66+
module_function :rangify
6367
end
64-
65-
BinUtils.extend(BinUtils)
6668
end

lib/ttfunk/bit_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def on(pos)
2525
# @param pos [Integer]
2626
# @return [Boolean]
2727
def on?(pos)
28-
(value & (2**pos)).positive?
28+
value.allbits?(2**pos)
2929
end
3030

3131
# Set bit off.

lib/ttfunk/subset/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def collect_glyphs(glyph_ids)
102102
end
103103

104104
additional_ids = collected.values
105-
.select { |g| g && g.compound? }
105+
.select { |g| g&.compound? }
106106
.map(&:glyph_ids)
107107
.flatten
108108

lib/ttfunk/table/cff/charstring.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ def parse!
126126
# return from callgsubr - do nothing since we inline subrs
127127
next if code == 11
128128

129-
if code >= 32 && code <= 246
129+
if code.between?(32, 246)
130130
@stack << (code - 139)
131131
elsif (m = CODE_MAP[code])
132132
__send__(m)
133-
elsif code >= 247 && code <= 250
133+
elsif code.between?(247, 250)
134134
b0 = code
135135
b1 = @data[@index]
136136
@index += 1
137137
@stack << (((b0 - 247) * 256) + b1 + 108)
138-
elsif code >= 251 && code <= 254
138+
elsif code.between?(251, 254)
139139
b0 = code
140140
b1 = @data[@index]
141141
@index += 1

lib/ttfunk/table/cmap/format04.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def parse_cmap!
141141

142142
end_code.each_with_index do |tail, i|
143143
start_code[i].upto(tail) do |code|
144-
if (id_range_offset[i]).zero?
144+
if id_range_offset[i].zero?
145145
glyph_id = code + id_delta[i]
146146
else
147147
index = (id_range_offset[i] / 2) + (code - start_code[i]) - (segcount - i)

lib/ttfunk/table/cmap/subtable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def initialize(file, table_start)
107107
#
108108
# @return [Boolean]
109109
def unicode?
110-
(platform_id == 3 && (encoding_id == 1 || encoding_id == 10) && format != 0) ||
110+
(platform_id == 3 && [1, 10].include?(encoding_id) && format != 0) ||
111111
(platform_id.zero? && format != 0)
112112
end
113113

lib/ttfunk/table/glyf/compound.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,22 @@ def initialize(id, raw)
110110
@glyph_ids << glyph_id
111111
@glyph_id_offsets << (offset + 2)
112112

113-
break if (flags & MORE_COMPONENTS).zero?
113+
break if flags.nobits?(MORE_COMPONENTS)
114114

115115
offset += 4
116116

117117
offset +=
118-
if (flags & ARG_1_AND_2_ARE_WORDS).zero?
118+
if flags.nobits?(ARG_1_AND_2_ARE_WORDS)
119119
2
120120
else
121121
4
122122
end
123123

124-
if flags & WE_HAVE_A_TWO_BY_TWO != 0
124+
if flags.allbits?(WE_HAVE_A_TWO_BY_TWO)
125125
offset += 8
126-
elsif flags & WE_HAVE_AN_X_AND_Y_SCALE != 0
126+
elsif flags.allbits?(WE_HAVE_AN_X_AND_Y_SCALE)
127127
offset += 4
128-
elsif flags & WE_HAVE_A_SCALE != 0
128+
elsif flags.allbits?(WE_HAVE_A_SCALE)
129129
offset += 2
130130
end
131131
end

lib/ttfunk/table/kern.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def parse_version_0_tables(_num_tables)
6565
length: length,
6666
coverage: coverage,
6767
data: raw[10..],
68-
vertical: (coverage & 0x1).zero?,
69-
minimum: (coverage & 0x2 != 0),
70-
cross: (coverage & 0x4 != 0),
71-
override: (coverage & 0x8 != 0),
68+
vertical: coverage.nobits?(0x1),
69+
minimum: coverage.allbits?(0x2),
70+
cross: coverage.allbits?(0x4),
71+
override: coverage.allbits?(0x8),
7272
)
7373
end
7474

@@ -83,9 +83,9 @@ def parse_version_1_tables(num_tables)
8383
coverage: coverage,
8484
tuple_index: tuple_index,
8585
data: io.read(length - 8),
86-
vertical: (coverage & 0x8000 != 0),
87-
cross: (coverage & 0x4000 != 0),
88-
variation: (coverage & 0x2000 != 0),
86+
vertical: coverage.nobits?(0x8000),
87+
cross: coverage.allbits?(0x4000),
88+
variation: coverage.allbits?(0x2000),
8989
)
9090
end
9191
end

0 commit comments

Comments
 (0)