File: head.rb

package info (click to toggle)
ruby-ttfunk 1.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 916 kB
  • sloc: ruby: 1,719; makefile: 16
file content (44 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'ttfunk/table'

module TTFunk  
  class Table
    class Head < TTFunk::Table
      attr_reader :version
      attr_reader :font_revision
      attr_reader :checksum_adjustment
      attr_reader :magic_number
      attr_reader :flags
      attr_reader :units_per_em
      attr_reader :created
      attr_reader :modified
      attr_reader :x_min
      attr_reader :y_min
      attr_reader :x_max
      attr_reader :y_max
      attr_reader :mac_style
      attr_reader :lowest_rec_ppem
      attr_reader :font_direction_hint
      attr_reader :index_to_loc_format
      attr_reader :glyph_data_format

      def self.encode(head, loca)
        table = head.raw
        table[8,4] = "\0\0\0\0" # set checksum adjustment to 0 initially
        table[-4,2] = [loca[:type]].pack("n") # set index_to_loc_format
        return table
      end

      private

        def parse!
          @version, @font_revision, @check_sum_adjustment, @magic_number,
            @flags, @units_per_em, @created, @modified = read(36, "N4n2q2")
      
          @x_min, @y_min, @x_max, @y_max = read_signed(4)
      
          @mac_style, @lowest_rec_ppem, @font_direction_hint,
            @index_to_loc_format, @glyph_data_format = read(10, "n*")
        end
    end
  end
end