Sha256: bf5b9025794d5e00f25144b8eda9cbc57fa251dfc86e281b1ce6350085031f98

Contents?: true

Size: 852 Bytes

Versions: 5

Compression:

Stored size: 852 Bytes

Contents

# frozen_string_literal: true

require_relative 'format10'
require 'stringio'

module TTFunk
  class Table
    class Post
      module Format20
        include Format10

        def glyph_for(code)
          index = @glyph_name_index[code]
          return '.notdef' unless index

          if index <= 257
            POSTSCRIPT_GLYPHS[index]
          else
            @names[index - 258] || '.notdef'
          end
        end

        private

        def parse_format!
          number_of_glyphs = read(2, 'n').first
          @glyph_name_index = read(number_of_glyphs * 2, 'n*')
          @names = []

          strings = StringIO.new(io.read(offset + length - io.pos))
          until strings.eof?
            length = strings.read(1).unpack1('C')
            @names << strings.read(length)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ttfunk-1.7.0 lib/ttfunk/table/post/format20.rb
ttfunk-1.6.2.1 lib/ttfunk/table/post/format20.rb
ttfunk-1.6.2 lib/ttfunk/table/post/format20.rb
ttfunk-1.6.1 lib/ttfunk/table/post/format20.rb
ttfunk-1.6.0 lib/ttfunk/table/post/format20.rb