Class: Fontisan::Type1::AFMParser
- Inherits:
-
Object
- Object
- Fontisan::Type1::AFMParser
- Defined in:
- lib/fontisan/type1/afm_parser.rb
Overview
AFM (Adobe Font Metrics) file parser
AFMParser parses Adobe Font Metrics
files which contain font metric information for Type 1 fonts.
AFM files include:
- Character widths
- Kerning pairs
- Character bounding boxes
- Font metadata (name, version, copyright, etc.)
Instance Attribute Summary collapse
-
#character_bboxes ⇒ Hash
readonly
Character bounding boxes (glyph name => lly, urx, ury).
-
#character_widths ⇒ Hash<String, Integer>
readonly
Character widths (glyph name => width).
-
#copyright ⇒ String
readonly
Copyright notice.
-
#family_name ⇒ String
readonly
Family name.
-
#font_bbox ⇒ Integer
readonly
Font bounding box [llx, lly, urx, ury].
-
#font_name ⇒ String
readonly
Font name.
-
#full_name ⇒ String
readonly
Full name.
-
#kerning_pairs ⇒ Hash<Array(String>, Integer>
readonly
Kerning pairs ([left, right] => adjustment).
-
#raw_data ⇒ Hash
readonly
Raw AFM data.
-
#version ⇒ String
readonly
Version.
-
#weight ⇒ String
readonly
Weight.
Class Method Summary collapse
-
.parse(content) ⇒ AFMParser
Parse AFM content.
-
.parse_file(path) ⇒ AFMParser
Parse AFM file.
-
.parse_string(content) ⇒ Object
Alias for parse method.
Instance Method Summary collapse
-
#has_character?(glyph_name) ⇒ Boolean
Check if character exists.
-
#initialize ⇒ AFMParser
constructor
Initialize a new AFMParser.
-
#kerning(left, right) ⇒ Integer?
Get kerning adjustment for character pair.
-
#parse(content) ⇒ AFMParser
Parse AFM content.
-
#width(glyph_name) ⇒ Integer?
Get character width for glyph.
Constructor Details
#initialize ⇒ AFMParser
Initialize a new AFMParser
88 89 90 91 92 93 94 |
# File 'lib/fontisan/type1/afm_parser.rb', line 88 def initialize @character_widths = {} @kerning_pairs = {} @character_bboxes = {} @raw_data = {} @font_bbox = nil end |
Instance Attribute Details
#character_bboxes ⇒ Hash (readonly)
Returns Character bounding boxes (glyph name => lly, urx, ury).
49 50 51 |
# File 'lib/fontisan/type1/afm_parser.rb', line 49 def character_bboxes @character_bboxes end |
#character_widths ⇒ Hash<String, Integer> (readonly)
Returns Character widths (glyph name => width).
43 44 45 |
# File 'lib/fontisan/type1/afm_parser.rb', line 43 def character_widths @character_widths end |
#copyright ⇒ String (readonly)
Returns Copyright notice.
40 41 42 |
# File 'lib/fontisan/type1/afm_parser.rb', line 40 def copyright @copyright end |
#family_name ⇒ String (readonly)
Returns Family name.
31 32 33 |
# File 'lib/fontisan/type1/afm_parser.rb', line 31 def family_name @family_name end |
#font_bbox ⇒ Integer (readonly)
Returns Font bounding box [llx, lly, urx, ury].
52 53 54 |
# File 'lib/fontisan/type1/afm_parser.rb', line 52 def font_bbox @font_bbox end |
#font_name ⇒ String (readonly)
Returns Font name.
25 26 27 |
# File 'lib/fontisan/type1/afm_parser.rb', line 25 def font_name @font_name end |
#full_name ⇒ String (readonly)
Returns Full name.
28 29 30 |
# File 'lib/fontisan/type1/afm_parser.rb', line 28 def full_name @full_name end |
#kerning_pairs ⇒ Hash<Array(String>, Integer> (readonly)
Returns Kerning pairs ([left, right] => adjustment).
46 47 48 |
# File 'lib/fontisan/type1/afm_parser.rb', line 46 def kerning_pairs @kerning_pairs end |
#raw_data ⇒ Hash (readonly)
Returns Raw AFM data.
55 56 57 |
# File 'lib/fontisan/type1/afm_parser.rb', line 55 def raw_data @raw_data end |
#version ⇒ String (readonly)
Returns Version.
37 38 39 |
# File 'lib/fontisan/type1/afm_parser.rb', line 37 def version @version end |
#weight ⇒ String (readonly)
Returns Weight.
34 35 36 |
# File 'lib/fontisan/type1/afm_parser.rb', line 34 def weight @weight end |
Class Method Details
.parse(content) ⇒ AFMParser
Parse AFM content
78 79 80 |
# File 'lib/fontisan/type1/afm_parser.rb', line 78 def self.parse(content) new.parse(content) end |
.parse_file(path) ⇒ AFMParser
Parse AFM file
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fontisan/type1/afm_parser.rb', line 63 def self.parse_file(path) raise ArgumentError, "Path cannot be nil" if path.nil? unless File.exist?(path) raise Fontisan::Error, "AFM file not found: #{path}" end content = File.read(path, encoding: "ISO-8859-1") parse(content) end |
.parse_string(content) ⇒ Object
Alias for parse method
83 84 85 |
# File 'lib/fontisan/type1/afm_parser.rb', line 83 def self.parse_string(content) parse(content) end |
Instance Method Details
#has_character?(glyph_name) ⇒ Boolean
Check if character exists
128 129 130 |
# File 'lib/fontisan/type1/afm_parser.rb', line 128 def has_character?(glyph_name) @character_widths.key?(glyph_name) end |
#kerning(left, right) ⇒ Integer?
Get kerning adjustment for character pair
120 121 122 |
# File 'lib/fontisan/type1/afm_parser.rb', line 120 def kerning(left, right) @kerning_pairs[[left, right]] end |
#parse(content) ⇒ AFMParser
Parse AFM content
100 101 102 103 104 105 |
# File 'lib/fontisan/type1/afm_parser.rb', line 100 def parse(content) parse_global_metrics(content) parse_character_metrics(content) parse_kerning_data(content) self end |
#width(glyph_name) ⇒ Integer?
Get character width for glyph
111 112 113 |
# File 'lib/fontisan/type1/afm_parser.rb', line 111 def width(glyph_name) @character_widths[glyph_name] end |