Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parse_afm(file)
- section = []
- File.open(file,"rb") do |file|
- file.each do |line|
- case line
- when /^Start(\w+)/
- section.push $1
- next
- when /^End(\w+)/
- section.pop
- next
- end
- case section
- when ["FontMetrics", "CharMetrics"]
- next unless line =~ /^CH?\s/
- name = line[/\bN\s+(\.?\w+)\s*;/, 1]
- @glyph_widths[name] = line[/\bWX\s+(\d+)\s*;/, 1].to_i
- @bounding_boxes[name] = line[/\bB\s+([^;]+);/, 1].to_s.rstrip
- when ["FontMetrics", "KernData", "KernPairs"]
- next unless line =~ /^KPX\s+(\.?\w+)\s+(\.?\w+)\s+(-?\d+)/
- @kern_pairs[[$1, $2]] = $3.to_i
- when ["FontMetrics", "KernData", "TrackKern"],
- ["FontMetrics", "Composites"]
- next
- else
- parse_generic_afm_attribute(line)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment