Skip to content
Open
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
10 changes: 6 additions & 4 deletions lib/ttfunk/table/cff/dict.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'bigdecimal'

module TTFunk
class Table
class Cff < TTFunk::Table
Expand Down Expand Up @@ -92,7 +90,7 @@ def encode_operand(operand)
case operand
when Integer
encode_integer(operand)
when Float, BigDecimal
when Float, ->(op) { defined?(BigDecimal) && op.is_a?(BigDecimal) }
encode_float(operand)
when SciForm
encode_sci(operand)
Expand Down Expand Up @@ -141,7 +139,11 @@ def encode_exponent(exp)
end

def encode_significand(sig)
sig.to_s.each_char.with_object([]) do |char, ret|
if defined?(BigDecimal) && sig.is_a?(BigDecimal)
sig.to_s('F')
else
sig.to_s
end.each_char.with_object([]) do |char, ret|
case char
when '0'..'9'
ret << Integer(char)
Expand Down
15 changes: 15 additions & 0 deletions spec/ttfunk/table/cff/dict_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,19 @@

expect(dict1.encode).to eq(dict2.encode)
end

begin
require('bigdecimal')
rescue StandardError
# ignore
end
if defined?(BigDecimal)
it 'encodes BigDecimal' do
dict = described_class.new(TestFile.new(StringIO.new('')), 0, 0)

dict[1] = BigDecimal('42')

expect(dict.encode).to eq("\x1EB\xA0\xFF\x01".b)
end
end
end
2 changes: 1 addition & 1 deletion 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_dependency('bigdecimal', '~> 3.1')
spec.add_development_dependency('bigdecimal', '>= 3.1')
spec.add_development_dependency('prawn-dev', '~> 0.6.0')
end