summaryrefslogtreecommitdiff
path: root/support/rfil/examples/plinfo
blob: 1ceda6c5cb91b6acf5d19490ae9a5c82e35ca8f8 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env ruby
#--
# Last Change: Tue May 16 18:14:38 2006
#++
=begin rdoc
== plinfo -- output information about a pl file.

  Usage: plinfo [options] tfmfile.pl [file...]
      -e, --encoding enc               set the encoding for the file
      -l, --list-chars                 list all available characters
      -h, --help                       Show this help
  

---
Author:: Patrick Gundlach <patrick@gundla.ch>
License::  Copyright (c) 2005 Patrick Gundlach.
           Released under the terms of the GNU General Public License
=end


# :enddoc:

require 'optparse'
require 'ostruct'

require 'rfil/tex/tfm'
require 'rfil/tex/kpathsea'
require 'rfil/tex/enc'

include RFIL
include TeX

kpse=Kpathsea.new

@options=OpenStruct.new

ARGV.options { |opt|
  opt.banner = "Usage: #{File.basename($0)} [options] tfmfile.pl [file...]"
  opt.on("--encoding enc", "-e", "set the encoding for the file") { |e|
    kpse.open_file(e,"enc") { |f|
      @options.encoding = ENC.new(f)
    }
  }
  opt.on("--list-chars", "-l", "list all available characters") {
    @options.listchars=true }
  opt.on("--help", "-h", "Show this help") { puts opt; exit 0 }
  opt.separator  ""
  opt.parse!
}

if ARGV.size < 1
  puts "#{File.basename($0)}: Need at least one file argument."
  puts "Try `#{File.basename($0)} --help' for more information."
  exit 0
end


def dump_maininfo(filename)
  puts "General font information:"
  puts "========================="
  print "filename=#{File.basename(filename)} "
  # puts @isvpl ? "(vpl)" : "(pl)"
  puts "Family: #{@tfm.fontfamily}"
  puts "Designsize: #{@tfm.designsize}"
  puts "Codingscheme: #{@tfm.codingscheme}"
  puts "Fontdimen:"
  paramname=%w( SLANT SPACE STRETCH SHRINK XHEIGHT QUAD EXTRASPACE )
    if @tfm.codingscheme=="TeX math symbols"
      paramname += %w(NUM1 NUM2 NUM3 DENOM1 DENOM2 SUP1 SUP2 SUP3
                      SUB1 SUB2 SUPDROP)
    elsif @tfm.codingscheme=="TeX math extension"
      paramname += %w(DEFAULT_RULE_THICKNESS BIG_OP_SPACING1
      BIG_OP_SPACING2 BIG_OP_SPACING3 BIG_OP_SPACING4 BIG_OP_SPACING5) 
    end

  (1..@tfm.params.size-1).each {|i|
    puts "  #{paramname[i-1]} = #{@tfm.params[i]}"
  }
end

def dump_charsinfo
  stdformat="%9s|"
  count=0
  0.upto(255)  { |i|
    if c=@tfm.chars[i]
      if count % 32 == 0
        puts "\n slot|   width |  height |   depth |      ic |lig/kern?|   extra |  char"
        puts "-----|---------|---------|---------|---------|---------|---------|-------"
      end

      has_krn= c[:lig_kern] ?  "yes" : ""
      extra = ""
      char = @options.encoding ? @options.encoding[i] : ""
      puts sprintf("%5s|"+stdformat*6+" %s", "#{i}","#{c[:charwd]}","#{c[:charht]}","#{c[:chardp]}","#{c[:charic]}", has_krn,"",char)
      count += 1
      
    end

  }
end

ARGV.each { |plfilename|
  @tfm=TFM.new()
  @tfm.read_pl(plfilename)
  dump_maininfo(plfilename)
  if @options.listchars
    dump_charsinfo
  end
}