ttfunk 1.6.2.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -1
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +15 -1
  5. data/lib/ttfunk.rb +3 -2
  6. data/lib/ttfunk/bit_field.rb +1 -1
  7. data/lib/ttfunk/collection.rb +8 -2
  8. data/lib/ttfunk/encoded_string.rb +3 -3
  9. data/lib/ttfunk/max.rb +1 -0
  10. data/lib/ttfunk/min.rb +1 -0
  11. data/lib/ttfunk/one_based_array.rb +1 -1
  12. data/lib/ttfunk/otf_encoder.rb +1 -1
  13. data/lib/ttfunk/reader.rb +3 -3
  14. data/lib/ttfunk/sci_form.rb +1 -1
  15. data/lib/ttfunk/subset.rb +3 -3
  16. data/lib/ttfunk/subset/base.rb +24 -21
  17. data/lib/ttfunk/subset/code_page.rb +16 -19
  18. data/lib/ttfunk/subset/unicode.rb +8 -6
  19. data/lib/ttfunk/subset/unicode_8bit.rb +14 -12
  20. data/lib/ttfunk/sum.rb +1 -0
  21. data/lib/ttfunk/table/cff.rb +17 -17
  22. data/lib/ttfunk/table/cff/charset.rb +31 -30
  23. data/lib/ttfunk/table/cff/charsets.rb +3 -3
  24. data/lib/ttfunk/table/cff/charstring.rb +54 -55
  25. data/lib/ttfunk/table/cff/dict.rb +6 -4
  26. data/lib/ttfunk/table/cff/encoding.rb +20 -21
  27. data/lib/ttfunk/table/cff/encodings.rb +1 -1
  28. data/lib/ttfunk/table/cff/fd_selector.rb +14 -11
  29. data/lib/ttfunk/table/cff/font_index.rb +7 -6
  30. data/lib/ttfunk/table/cff/index.rb +6 -5
  31. data/lib/ttfunk/table/cff/one_based_index.rb +7 -3
  32. data/lib/ttfunk/table/cff/path.rb +5 -3
  33. data/lib/ttfunk/table/cff/top_dict.rb +7 -6
  34. data/lib/ttfunk/table/cff/top_index.rb +5 -4
  35. data/lib/ttfunk/table/cmap.rb +8 -6
  36. data/lib/ttfunk/table/cmap/format00.rb +7 -6
  37. data/lib/ttfunk/table/cmap/format04.rb +16 -15
  38. data/lib/ttfunk/table/cmap/format06.rb +6 -5
  39. data/lib/ttfunk/table/cmap/format10.rb +6 -5
  40. data/lib/ttfunk/table/cmap/format12.rb +13 -12
  41. data/lib/ttfunk/table/cmap/subtable.rb +4 -4
  42. data/lib/ttfunk/table/dsig.rb +11 -9
  43. data/lib/ttfunk/table/glyf.rb +3 -3
  44. data/lib/ttfunk/table/glyf/compound.rb +8 -8
  45. data/lib/ttfunk/table/hmtx.rb +6 -5
  46. data/lib/ttfunk/table/kern.rb +4 -4
  47. data/lib/ttfunk/table/kern/format0.rb +1 -1
  48. data/lib/ttfunk/table/loca.rb +7 -6
  49. data/lib/ttfunk/table/name.rb +6 -5
  50. data/lib/ttfunk/table/os2.rb +261 -151
  51. data/lib/ttfunk/table/post.rb +1 -1
  52. data/lib/ttfunk/table/sbix.rb +15 -13
  53. data/lib/ttfunk/table/vorg.rb +1 -1
  54. data/lib/ttfunk/ttf_encoder.rb +4 -4
  55. metadata +29 -99
  56. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71064b02c8c85fc71ceada9b60f6952e63bbfb8455ef8515b6c7177ab47ac011
4
- data.tar.gz: a38f13b6e110788e6f4104e0923976ad4a549fb1768be6311ec2769786effd88
3
+ metadata.gz: 8c6a1d61ab884e88dd7424c80680f5dac53de5d891645f5b3fb5699ebbcffce3
4
+ data.tar.gz: 7031ece12dacbf351ea1e98fceccca054bca245ddd7437a62ca746e1d85b40e9
5
5
  SHA512:
6
- metadata.gz: c5b344b9ef01adc031d7c518ad86ddf9dade4ccc8bc5722622c55a19baee775a99c34b1873a6ed59cc91532dc492b977dc868013857e3ef56716e38d6f2db0e9
7
- data.tar.gz: fe3b0ebad333cc6710f756db0b39de990113869e51fea20f8f5da532be8237c5bf6854604a9b3faf3f781804762dd761e267e1dc7b6d3aebcfb65e8bf057fbb3
6
+ metadata.gz: f2481488976f0015fb0abf49c8fa510cf6b8ee6120d17eebd04a01d4fcda5c96397c8bcf729bf42efae8f08238ebe3cba914f082bac2966d92f867f62e87b92b
7
+ data.tar.gz: fc4561d7ff2892a7a8f1c752c473a4b6e0a1e7b17042e60c175c98ef83bea9cbbdf6893ddab92c841f9ec9759af9fa41617445d304903c585a6f20d111e59e6e
@@ -1 +1,2 @@
1
- ���9 o��Pw��֤ �V��=��mc�<�ۦʾmΧ���9��U}�|�-��~��d���~uAv=�B~O��}��w��v��9l�&髽�ȤaC����Dd �c=nȘ��2$�cմ�m�T�J���Z$|T��(#��=�z�=s~Z�y��0f�2��0�.ܽ54��gdޗa�Da��'�$Mn��!�f��A�r�Ùѹ��a��<�_YQ���bi��ز���nO��/)h<. k"rm�s��
1
+ ��5�*���pl�}�[���@p��-Q�������Ɗ������Ogs{s_IfBy��.˥�����y䩙��G�y&�@ӳ��B)<�w�UD@4o���}S#����q�e�NPki|x} B�sj��٭؏
2
+ AD�
data.tar.gz.sig CHANGED
Binary file
@@ -7,6 +7,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 1.7.0
11
+
12
+ ### Changes
13
+
14
+ * Allow gem installation on Ruby 3.0
15
+
16
+ Pavel Lobashov
17
+
18
+ * Allow TTC files to be read from IO object
19
+
20
+ Tom de Grunt
21
+
10
22
  ## [1.6.2.1]
11
23
 
12
24
  ### Fixed
@@ -198,7 +210,9 @@ Initial release as a standalone gem
198
210
 
199
211
 
200
212
 
201
- [Unreleased]: https://github.com/prawnpdf/ttfunk/compare/1.6.2...HEAD
213
+ [Unreleased]: https://github.com/prawnpdf/ttfunk/compare/1.7.0...HEAD
214
+ [1.7.0]: https://github.com/prawnpdf/ttfunk/compare/1.6.2.1...1.7.0
215
+ [1.6.2.1]: https://github.com/prawnpdf/ttfunk/compare/1.6.2...1.6.2.1
202
216
  [1.6.2]: https://github.com/prawnpdf/ttfunk/compare/1.6.1...1.6.2
203
217
  [1.6.1]: https://github.com/prawnpdf/ttfunk/compare/1.6.0...1.6.1
204
218
  [1.6.0]: https://github.com/prawnpdf/ttfunk/compare/1.5.1...1.6.0
@@ -21,6 +21,8 @@ require_relative 'ttfunk/sum'
21
21
  require_relative 'ttfunk/one_based_array'
22
22
 
23
23
  module TTFunk
24
+ class Error < StandardError; end
25
+
24
26
  class File
25
27
  attr_reader :contents
26
28
  attr_reader :directory
@@ -53,8 +55,7 @@ module TTFunk
53
55
  io_or_path = Pathname.new(io_or_path)
54
56
  raise ArgumentError, "#{io_or_path} not found" unless io_or_path.file?
55
57
 
56
- io = io_or_path.open('rb')
57
- io
58
+ io_or_path.open('rb')
58
59
  end
59
60
 
60
61
  def initialize(contents, offset = 0)
@@ -13,7 +13,7 @@ module TTFunk
13
13
  end
14
14
 
15
15
  def on?(pos)
16
- value & 2**pos > 0
16
+ (value & 2**pos).positive?
17
17
  end
18
18
 
19
19
  def off(pos)
@@ -5,8 +5,14 @@ module TTFunk
5
5
  include Enumerable
6
6
 
7
7
  def self.open(path)
8
- ::File.open(path, 'rb') do |io|
9
- yield new(io)
8
+ if path.respond_to?(:read)
9
+ result = yield new(path)
10
+ path.rewind
11
+ result
12
+ else
13
+ ::File.open(path, 'rb') do |io|
14
+ yield new(io)
15
+ end
10
16
  end
11
17
  end
12
18
 
@@ -34,7 +34,7 @@ module TTFunk
34
34
  end
35
35
 
36
36
  def align!(width = 4)
37
- if length % width > 0
37
+ if (length % width).positive?
38
38
  self << "\0" * (width - length % width)
39
39
  end
40
40
 
@@ -47,8 +47,8 @@ module TTFunk
47
47
 
48
48
  def string
49
49
  unless placeholders.empty?
50
- raise UnresolvedPlaceholderError, 'string contains '\
51
- "#{placeholders.size} unresolved placeholder(s)"
50
+ raise UnresolvedPlaceholderError,
51
+ "string contains #{placeholders.size} unresolved placeholder(s)"
52
52
  end
53
53
 
54
54
  io.string
@@ -5,6 +5,7 @@ module TTFunk
5
5
  attr_reader :value
6
6
 
7
7
  def initialize(init_value = nil)
8
+ super()
8
9
  @value = init_value
9
10
  end
10
11
 
@@ -5,6 +5,7 @@ module TTFunk
5
5
  attr_reader :value
6
6
 
7
7
  def initialize(init_value = nil)
8
+ super()
8
9
  @value = init_value
9
10
  end
10
11
 
@@ -9,7 +9,7 @@ module TTFunk
9
9
  end
10
10
 
11
11
  def [](idx)
12
- if idx == 0
12
+ if idx.zero?
13
13
  raise IndexError,
14
14
  "index #{idx} was outside the bounds of the array"
15
15
  end
@@ -39,7 +39,7 @@ module TTFunk
39
39
  'BASE' => base_table,
40
40
  'VORG' => vorg_table,
41
41
  'CFF ' => cff_table
42
- ).reject { |_tag, table| table.nil? }
42
+ ).compact
43
43
  end
44
44
 
45
45
  def optimal_table_order
@@ -33,15 +33,15 @@ module TTFunk
33
33
  bytes = string.unpack('C*')
34
34
  bytes.each_with_index do |c, i|
35
35
  printf('%02X', c)
36
- if (i + 1) % 16 == 0
36
+ if ((i + 1) % 16).zero?
37
37
  puts
38
- elsif (i + 1) % 8 == 0
38
+ elsif ((i + 1) % 8).zero?
39
39
  print ' '
40
40
  else
41
41
  print ' '
42
42
  end
43
43
  end
44
- puts unless bytes.length % 16 == 0
44
+ puts unless (bytes.length % 16).zero?
45
45
  end
46
46
  end
47
47
  end
@@ -17,7 +17,7 @@ module TTFunk
17
17
  def ==(other)
18
18
  case other
19
19
  when Float
20
- other == to_f
20
+ other == to_f # rubocop: disable Lint/FloatComparison
21
21
  when self.class
22
22
  other.significand == significand &&
23
23
  other.exponent == exponent
@@ -9,10 +9,10 @@ module TTFunk
9
9
  module Subset
10
10
  def self.for(original, encoding)
11
11
  case encoding.to_sym
12
- when :unicode then Unicode.new(original)
12
+ when :unicode then Unicode.new(original)
13
13
  when :unicode_8bit then Unicode8Bit.new(original)
14
- when :mac_roman then MacRoman.new(original)
15
- when :windows_1252 then Windows1252.new(original)
14
+ when :mac_roman then MacRoman.new(original)
15
+ when :windows_1252 then Windows1252.new(original) # rubocop: disable Naming/VariableNumber
16
16
  else raise NotImplementedError, "encoding #{encoding} is not supported"
17
17
  end
18
18
  end
@@ -54,14 +54,15 @@ module TTFunk
54
54
  end
55
55
 
56
56
  def collect_glyphs(glyph_ids)
57
- collected = glyph_ids.each_with_object({}) do |id, h|
58
- h[id] = glyph_for(id)
59
- end
57
+ collected =
58
+ glyph_ids.each_with_object({}) do |id, h|
59
+ h[id] = glyph_for(id)
60
+ end
60
61
 
61
62
  additional_ids = collected.values
62
- .select { |g| g && g.compound? }
63
- .map(&:glyph_ids)
64
- .flatten
63
+ .select { |g| g && g.compound? }
64
+ .map(&:glyph_ids)
65
+ .flatten
65
66
 
66
67
  collected.update(collect_glyphs(additional_ids)) if additional_ids.any?
67
68
 
@@ -69,23 +70,25 @@ module TTFunk
69
70
  end
70
71
 
71
72
  def old_to_new_glyph
72
- @old_to_new_glyph ||= begin
73
- charmap = new_cmap_table[:charmap]
74
- old_to_new = charmap.each_with_object(0 => 0) do |(_, ids), map|
75
- map[ids[:old]] = ids[:new]
76
- end
77
-
78
- next_glyph_id = new_cmap_table[:max_glyph_id]
79
-
80
- glyphs.keys.each do |old_id|
81
- unless old_to_new.key?(old_id)
82
- old_to_new[old_id] = next_glyph_id
83
- next_glyph_id += 1
73
+ @old_to_new_glyph ||=
74
+ begin
75
+ charmap = new_cmap_table[:charmap]
76
+ old_to_new =
77
+ charmap.each_with_object(0 => 0) do |(_, ids), map|
78
+ map[ids[:old]] = ids[:new]
79
+ end
80
+
81
+ next_glyph_id = new_cmap_table[:max_glyph_id]
82
+
83
+ glyphs.each_key do |old_id|
84
+ unless old_to_new.key?(old_id)
85
+ old_to_new[old_id] = next_glyph_id
86
+ next_glyph_id += 1
87
+ end
84
88
  end
85
- end
86
89
 
87
- old_to_new
88
- end
90
+ old_to_new
91
+ end
89
92
  end
90
93
 
91
94
  def new_to_old_glyph
@@ -9,19 +9,15 @@ module TTFunk
9
9
  class CodePage < Base
10
10
  class << self
11
11
  def unicode_mapping_for(encoding)
12
- mapping_cache[encoding] ||= (0..255).each_with_object({}) do |c, ret|
13
- # rubocop:disable Lint/SuppressedException
14
- begin
15
- ret[c] = c.chr(encoding)
16
- .encode(Encoding::UTF_8)
17
- .codepoints
18
- .first
19
- rescue Encoding::UndefinedConversionError
20
- # There is not a strict 1:1 mapping between all code page
21
- # characters and unicode.
12
+ mapping_cache[encoding] ||=
13
+ (0..255).each_with_object({}) do |c, ret|
14
+ codepoint =
15
+ c.chr(encoding)
16
+ .encode(Encoding::UTF_8, undef: :replace, replace: '')
17
+ .codepoints
18
+ .first
19
+ ret[c] = codepoint if codepoint
22
20
  end
23
- # rubocop:enable Lint/SuppressedException
24
- end
25
21
  end
26
22
 
27
23
  private
@@ -65,15 +61,16 @@ module TTFunk
65
61
  end
66
62
 
67
63
  def new_cmap_table
68
- @new_cmap_table ||= begin
69
- mapping = {}
64
+ @new_cmap_table ||=
65
+ begin
66
+ mapping = {}
70
67
 
71
- @subset.each_with_index do |unicode, roman|
72
- mapping[roman] = unicode_cmap[unicode]
73
- end
68
+ @subset.each_with_index do |unicode, roman|
69
+ mapping[roman] = unicode_cmap[unicode]
70
+ end
74
71
 
75
- TTFunk::Table::Cmap.encode(mapping, :mac_roman)
76
- end
72
+ TTFunk::Table::Cmap.encode(mapping, :mac_roman)
73
+ end
77
74
  end
78
75
 
79
76
  def original_glyph_ids
@@ -39,13 +39,15 @@ module TTFunk
39
39
  end
40
40
 
41
41
  def new_cmap_table
42
- @new_cmap_table ||= begin
43
- mapping = @subset.each_with_object({}) do |code, map|
44
- map[code] = unicode_cmap[code]
42
+ @new_cmap_table ||=
43
+ begin
44
+ mapping =
45
+ @subset.each_with_object({}) do |code, map|
46
+ map[code] = unicode_cmap[code]
47
+ end
48
+
49
+ TTFunk::Table::Cmap.encode(mapping, :unicode)
45
50
  end
46
-
47
- TTFunk::Table::Cmap.encode(mapping, :unicode)
48
- end
49
51
  end
50
52
 
51
53
  def original_glyph_ids
@@ -42,19 +42,21 @@ module TTFunk
42
42
  end
43
43
 
44
44
  def new_cmap_table
45
- @new_cmap_table ||= begin
46
- mapping = @subset.each_with_object({}) do |(code, unicode), map|
47
- map[code] = unicode_cmap[unicode]
48
- map
49
- end
45
+ @new_cmap_table ||=
46
+ begin
47
+ mapping =
48
+ @subset.each_with_object({}) do |(code, unicode), map|
49
+ map[code] = unicode_cmap[unicode]
50
+ map
51
+ end
50
52
 
51
- # since we're mapping a subset of the unicode glyphs into an
52
- # arbitrary 256-character space, the actual encoding we're
53
- # using is irrelevant. We choose MacRoman because it's a 256-character
54
- # encoding that happens to be well-supported in both TTF and
55
- # PDF formats.
56
- TTFunk::Table::Cmap.encode(mapping, :mac_roman)
57
- end
53
+ # since we're mapping a subset of the unicode glyphs into an
54
+ # arbitrary 256-character space, the actual encoding we're
55
+ # using is irrelevant. We choose MacRoman because it's a 256-character
56
+ # encoding that happens to be well-supported in both TTF and
57
+ # PDF formats.
58
+ TTFunk::Table::Cmap.encode(mapping, :mac_roman)
59
+ end
58
60
  end
59
61
 
60
62
  def original_glyph_ids
@@ -5,6 +5,7 @@ module TTFunk
5
5
  attr_reader :value
6
6
 
7
7
  def initialize(init_value = 0)
8
+ super()
8
9
  @value = init_value
9
10
  end
10
11
 
@@ -3,24 +3,24 @@
3
3
  module TTFunk
4
4
  class Table
5
5
  class Cff < TTFunk::Table
6
- autoload :Charset, 'ttfunk/table/cff/charset'
7
- autoload :Charsets, 'ttfunk/table/cff/charsets'
8
- autoload :Charstring, 'ttfunk/table/cff/charstring'
6
+ autoload :Charset, 'ttfunk/table/cff/charset'
7
+ autoload :Charsets, 'ttfunk/table/cff/charsets'
8
+ autoload :Charstring, 'ttfunk/table/cff/charstring'
9
9
  autoload :CharstringsIndex, 'ttfunk/table/cff/charstrings_index'
10
- autoload :Dict, 'ttfunk/table/cff/dict'
11
- autoload :Encoding, 'ttfunk/table/cff/encoding'
12
- autoload :Encodings, 'ttfunk/table/cff/encodings'
13
- autoload :FdSelector, 'ttfunk/table/cff/fd_selector'
14
- autoload :FontDict, 'ttfunk/table/cff/font_dict'
15
- autoload :FontIndex, 'ttfunk/table/cff/font_index'
16
- autoload :Header, 'ttfunk/table/cff/header'
17
- autoload :Index, 'ttfunk/table/cff/index'
18
- autoload :OneBasedIndex, 'ttfunk/table/cff/one_based_index'
19
- autoload :Path, 'ttfunk/table/cff/path'
20
- autoload :PrivateDict, 'ttfunk/table/cff/private_dict'
21
- autoload :SubrIndex, 'ttfunk/table/cff/subr_index'
22
- autoload :TopDict, 'ttfunk/table/cff/top_dict'
23
- autoload :TopIndex, 'ttfunk/table/cff/top_index'
10
+ autoload :Dict, 'ttfunk/table/cff/dict'
11
+ autoload :Encoding, 'ttfunk/table/cff/encoding'
12
+ autoload :Encodings, 'ttfunk/table/cff/encodings'
13
+ autoload :FdSelector, 'ttfunk/table/cff/fd_selector'
14
+ autoload :FontDict, 'ttfunk/table/cff/font_dict'
15
+ autoload :FontIndex, 'ttfunk/table/cff/font_index'
16
+ autoload :Header, 'ttfunk/table/cff/header'
17
+ autoload :Index, 'ttfunk/table/cff/index'
18
+ autoload :OneBasedIndex, 'ttfunk/table/cff/one_based_index'
19
+ autoload :Path, 'ttfunk/table/cff/path'
20
+ autoload :PrivateDict, 'ttfunk/table/cff/private_dict'
21
+ autoload :SubrIndex, 'ttfunk/table/cff/subr_index'
22
+ autoload :TopDict, 'ttfunk/table/cff/top_dict'
23
+ autoload :TopIndex, 'ttfunk/table/cff/top_index'
24
24
 
25
25
  TAG = 'CFF ' # the extra space is important
26
26
 
@@ -56,7 +56,7 @@ module TTFunk
56
56
  end
57
57
 
58
58
  def [](glyph_id)
59
- return FIRST_GLYPH_STRING if glyph_id == 0
59
+ return FIRST_GLYPH_STRING if glyph_id.zero?
60
60
 
61
61
  find_string(sid_for(glyph_id))
62
62
  end
@@ -83,12 +83,13 @@ module TTFunk
83
83
  ranges = TTFunk::BinUtils.rangify(sids)
84
84
  range_max = ranges.map(&:last).max
85
85
 
86
- range_bytes = if range_max > 0
87
- (Math.log2(range_max) / 8).floor + 1
88
- else
89
- # for cases when there are no sequences at all
90
- Float::INFINITY
91
- end
86
+ range_bytes =
87
+ if range_max.positive?
88
+ (Math.log2(range_max) / 8).floor + 1
89
+ else
90
+ # for cases when there are no sequences at all
91
+ Float::INFINITY
92
+ end
92
93
 
93
94
  # calculate whether storing the charset as a series of ranges is
94
95
  # more efficient (i.e. takes up less space) vs storing it as an
@@ -99,7 +100,7 @@ module TTFunk
99
100
  if total_array_size <= total_range_size
100
101
  ([format_int(:array_format)] + sids).pack('Cn*')
101
102
  else
102
- fmt = range_bytes == 1 ? :range_format_8 : :range_format_16
103
+ fmt = range_bytes == 1 ? :range_format8 : :range_format16
103
104
  element_fmt = element_format(fmt)
104
105
  result = [format_int(fmt)].pack('C')
105
106
  ranges.each { |range| result << range.pack(element_fmt) }
@@ -110,7 +111,7 @@ module TTFunk
110
111
  private
111
112
 
112
113
  def sid_for(glyph_id)
113
- return 0 if glyph_id == 0
114
+ return 0 if glyph_id.zero?
114
115
 
115
116
  # rather than validating the glyph as part of one of the predefined
116
117
  # charsets, just pass it through
@@ -120,8 +121,8 @@ module TTFunk
120
121
  when :array_format
121
122
  entries[glyph_id]
122
123
 
123
- when :range_format_8, :range_format_16
124
- entries.inject(glyph_id) do |remaining, range|
124
+ when :range_format8, :range_format16
125
+ entries.reduce(glyph_id) do |remaining, range|
125
126
  if range.size >= remaining
126
127
  break (range.first + remaining) - 1
127
128
  end
@@ -156,7 +157,7 @@ module TTFunk
156
157
  @length = count * element_width
157
158
  @entries = OneBasedArray.new(read(length, 'n*'))
158
159
 
159
- when :range_format_8, :range_format_16
160
+ when :range_format8, :range_format16
160
161
  # The number of ranges is not explicitly specified in the font.
161
162
  # Instead, software utilizing this data simply processes ranges
162
163
  # until all glyphs in the font are covered.
@@ -174,37 +175,37 @@ module TTFunk
174
175
  end
175
176
 
176
177
  def element_width(fmt = format_sym)
177
- case fmt
178
- when :array_format then 2 # SID
179
- when :range_format_8 then 3 # SID + Card8
180
- when :range_format_16 then 4 # SID + Card16
181
- end
178
+ {
179
+ array_format: 2, # SID
180
+ range_format8: 3, # SID + Card8
181
+ range_format16: 4 # SID + Card16
182
+ }[fmt]
182
183
  end
183
184
 
184
185
  def element_format(fmt = format_sym)
185
- case fmt
186
- when :array_format then 'n'
187
- when :range_format_8 then 'nC'
188
- when :range_format_16 then 'nn'
189
- end
186
+ {
187
+ array_format: 'n',
188
+ range_format8: 'nC',
189
+ range_format16: 'nn'
190
+ }[fmt]
190
191
  end
191
192
 
192
193
  def format_sym
193
194
  case @format
194
195
  when ARRAY_FORMAT then :array_format
195
- when RANGE_FORMAT_8 then :range_format_8
196
- when RANGE_FORMAT_16 then :range_format_16
196
+ when RANGE_FORMAT_8 then :range_format8
197
+ when RANGE_FORMAT_16 then :range_format16
197
198
  else
198
- raise "unsupported charset format '#{fmt}'"
199
+ raise Error, "unsupported charset format '#{fmt}'"
199
200
  end
200
201
  end
201
202
 
202
203
  def format_int(sym = format_sym)
203
- case sym
204
- when :array_format then ARRAY_FORMAT
205
- when :range_format_8 then RANGE_FORMAT_8
206
- when :range_format_16 then RANGE_FORMAT_16
207
- end
204
+ {
205
+ array_format: ARRAY_FORMAT,
206
+ range_format8: RANGE_FORMAT_8,
207
+ range_format16: RANGE_FORMAT_16
208
+ }[sym]
208
209
  end
209
210
  end
210
211
  end