Guest User

Untitled

a guest
May 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. def parse_afm(file)
  2. section = []
  3.  
  4. File.open(file,"rb") do |file|
  5. file.each do |line|
  6. case line
  7. when /^Start(\w+)/
  8. section.push $1
  9. next
  10. when /^End(\w+)/
  11. section.pop
  12. next
  13. end
  14.  
  15. case section
  16. when ["FontMetrics", "CharMetrics"]
  17. next unless line =~ /^CH?\s/
  18.  
  19. name = line[/\bN\s+(\.?\w+)\s*;/, 1]
  20. @glyph_widths[name] = line[/\bWX\s+(\d+)\s*;/, 1].to_i
  21. @bounding_boxes[name] = line[/\bB\s+([^;]+);/, 1].to_s.rstrip
  22. when ["FontMetrics", "KernData", "KernPairs"]
  23. next unless line =~ /^KPX\s+(\.?\w+)\s+(\.?\w+)\s+(-?\d+)/
  24. @kern_pairs[[$1, $2]] = $3.to_i
  25. when ["FontMetrics", "KernData", "TrackKern"],
  26. ["FontMetrics", "Composites"]
  27. next
  28. else
  29. parse_generic_afm_attribute(line)
  30. end
  31. end
  32. end
  33. end
Add Comment
Please, Sign In to add comment