Sha256: a9e37d75fccb54a1dc35741dd587213d47cb6d9f2c7526361784ca24f3cf7f21

Contents?: true

Size: 1.05 KB

Versions: 34

Compression:

Stored size: 1.05 KB

Contents

require 'ttfunk/table'

module TTFunk
  class Table
    class Loca < Table
      attr_reader :offsets

      # Accepts an array of offsets, with each index corresponding to the
      # glyph id with that index.
      #
      # Returns a hash containing:
      #
      # * :table - the string representing the table's contents
      # * :type  - the type of offset (to be encoded in the 'head' table)
      def self.encode(offsets)
        if offsets.any? { |ofs| ofs > 0xFFFF }
          { :type => 1, :table => offsets.pack("N*") }
        else
          { :type => 0, :table => offsets.map { |o| o/2 }.pack("n*") }
        end
      end

      def index_of(glyph_id)
        @offsets[glyph_id]
      end

      def size_of(glyph_id)
        @offsets[glyph_id+1] - @offsets[glyph_id]
      end

      private

        def parse!
          type = file.header.index_to_loc_format == 0 ? "n" : "N"
          @offsets = read(length, "#{type}*")

          if file.header.index_to_loc_format == 0
            @offsets.map! { |v| v * 2 }
          end
        end
    end
  end
end

Version data entries

34 entries across 34 versions & 10 rubygems

Version Path
ttfunk-1.2.2 lib/ttfunk/table/loca.rb
ttfunk-1.2.1 lib/ttfunk/table/loca.rb
ttfunk-1.2.0 lib/ttfunk/table/loca.rb
ttfunk-1.1.1 lib/ttfunk/table/loca.rb
ttfunk-1.1.0 lib/ttfunk/table/loca.rb
ttfunk-1.0.3 lib/ttfunk/table/loca.rb
ttfunk-1.0.2 lib/ttfunk/table/loca.rb
ttfunk-1.0.1 lib/ttfunk/table/loca.rb
davebenvenuti-prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/table/loca.rb
piglop-prawn-0.10.2.3 vendor/ttfunk/lib/ttfunk/table/loca.rb
piglop-prawn-0.10.2.2 vendor/ttfunk/lib/ttfunk/table/loca.rb
piglop-prawn-0.10.2.1 vendor/ttfunk/lib/ttfunk/table/loca.rb
glyph_imager-0.1.1 vendor/ttfunk/lib/ttfunk/table/loca.rb
prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/table/loca.rb
goodwill-prawn-edge-0.10.0 vendor/ttfunk/lib/ttfunk/table/loca.rb
alphasights-prawn-0.10.4 vendor/ttfunk/lib/ttfunk/table/loca.rb
alphasights-prawn-0.10.3 vendor/ttfunk/lib/ttfunk/table/loca.rb
alphasights-prawn-0.10.2 vendor/ttfunk/lib/ttfunk/table/loca.rb
alphasights-prawn-0.10.1 vendor/ttfunk/lib/ttfunk/table/loca.rb
glyph_imager-0.1.0 vendor/ttfunk/lib/ttfunk/table/loca.rb