Class: Fontisan::Type1::PFMParser
- Inherits:
-
Object
- Object
- Fontisan::Type1::PFMParser
- Defined in:
- lib/fontisan/type1/pfm_parser.rb
Overview
PFM (Printer Font Metrics) file parser
PFMParser parses Printer Font Metrics
files which contain font metric information for Type 1 fonts on Windows.
PFM files are binary files that include:
- Character widths
- Kerning pairs
- Font metadata (name, version, copyright, etc.)
- Extended text metrics
Constant Summary collapse
- PFM_HEADER_SIZE =
PFM Header structure
256- PFM_VERSION =
0x0100
Instance Attribute Summary collapse
-
#character_widths ⇒ Hash<String, Integer>
readonly
Character widths (glyph index => width).
-
#copyright ⇒ String
readonly
Copyright notice.
-
#extended_metrics ⇒ Hash
readonly
Extended text metrics.
-
#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(Integer), Integer>
readonly
Kerning pairs ([left_idx, right_idx] => adjustment).
-
#raw_data ⇒ String
readonly
Raw data.
Class Method Summary collapse
-
.parse(content) ⇒ PFMParser
Parse PFM content.
-
.parse_file(path) ⇒ PFMParser
Parse PFM file.
-
.parse_string(content) ⇒ Object
Alias for parse method.
Instance Method Summary collapse
-
#has_character?(char_index) ⇒ Boolean
Check if character exists.
-
#initialize ⇒ PFMParser
constructor
Initialize a new PFMParser.
-
#kerning(left_idx, right_idx) ⇒ Integer?
Get kerning adjustment for character pair.
-
#parse(content) ⇒ PFMParser
Parse PFM content.
-
#width(char_index) ⇒ Integer?
Get character width for character index.
Constructor Details
#initialize ⇒ PFMParser
Initialize a new PFMParser
86 87 88 89 90 91 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 86 def initialize @character_widths = {} @kerning_pairs = {} @extended_metrics = {} @font_bbox = nil end |
Instance Attribute Details
#character_widths ⇒ Hash<String, Integer> (readonly)
Returns Character widths (glyph index => width).
41 42 43 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 41 def character_widths @character_widths end |
#copyright ⇒ String (readonly)
Returns Copyright notice.
38 39 40 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 38 def copyright @copyright end |
#extended_metrics ⇒ Hash (readonly)
Returns Extended text metrics.
47 48 49 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 47 def extended_metrics @extended_metrics end |
#family_name ⇒ String (readonly)
Returns Family name.
35 36 37 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 35 def family_name @family_name end |
#font_bbox ⇒ Integer (readonly)
Returns Font bounding box [llx, lly, urx, ury].
50 51 52 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 50 def font_bbox @font_bbox end |
#font_name ⇒ String (readonly)
Returns Font name.
29 30 31 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 29 def font_name @font_name end |
#full_name ⇒ String (readonly)
Returns Full name.
32 33 34 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 32 def full_name @full_name end |
#kerning_pairs ⇒ Hash<Array(Integer), Integer> (readonly)
Returns Kerning pairs ([left_idx, right_idx] => adjustment).
44 45 46 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 44 def kerning_pairs @kerning_pairs end |
#raw_data ⇒ String (readonly)
Returns Raw data.
53 54 55 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 53 def raw_data @raw_data end |
Class Method Details
.parse(content) ⇒ PFMParser
Parse PFM content
76 77 78 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 76 def self.parse(content) new.parse(content) end |
.parse_file(path) ⇒ PFMParser
Parse PFM file
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 61 def self.parse_file(path) raise ArgumentError, "Path cannot be nil" if path.nil? unless File.exist?(path) raise Fontisan::Error, "PFM file not found: #{path}" end content = File.binread(path) parse(content) end |
.parse_string(content) ⇒ Object
Alias for parse method
81 82 83 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 81 def self.parse_string(content) parse(content) end |
Instance Method Details
#has_character?(char_index) ⇒ Boolean
Check if character exists
128 129 130 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 128 def has_character?(char_index) @character_widths.key?(char_index) end |
#kerning(left_idx, right_idx) ⇒ Integer?
Get kerning adjustment for character pair
120 121 122 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 120 def kerning(left_idx, right_idx) @kerning_pairs[[left_idx, right_idx]] end |
#parse(content) ⇒ PFMParser
Parse PFM content
97 98 99 100 101 102 103 104 105 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 97 def parse(content) @raw_data = content parse_header(content) parse_driver_info(content) parse_extended_metrics(content) parse_character_widths(content) parse_kerning_pairs(content) self end |
#width(char_index) ⇒ Integer?
Get character width for character index
111 112 113 |
# File 'lib/fontisan/type1/pfm_parser.rb', line 111 def width(char_index) @character_widths[char_index] end |