Class: Fontisan::Type1::AFMGenerator
- Inherits:
-
Object
- Object
- Fontisan::Type1::AFMGenerator
- Defined in:
- lib/fontisan/type1/afm_generator.rb
Overview
AFM (Adobe Font Metrics) file generator
[‘AFMGenerator`](lib/fontisan/type1/afm_generator.rb) generates Adobe Font Metrics files from TTF/OTF fonts.
AFM files include:
-
Character widths
-
Kerning pairs
-
Character bounding boxes
-
Font metadata (name, version, copyright, etc.)
Class Method Summary collapse
-
.adobe_glyph_name(codepoint, encoding: nil) ⇒ String
Get Adobe glyph name from Unicode codepoint.
-
.generate(font, options = {}) ⇒ String
Generate AFM content from a font.
-
.generate_to_file(font, path, options = {}) ⇒ void
Generate AFM file from a font and write to file.
Instance Method Summary collapse
-
#generate_afm ⇒ String
Generate AFM content.
-
#initialize(font, options = {}) ⇒ AFMGenerator
constructor
Initialize a new AFMGenerator.
Constructor Details
#initialize(font, options = {}) ⇒ AFMGenerator
Initialize a new AFMGenerator
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fontisan/type1/afm_generator.rb', line 74 def initialize(font, = {}) @font = font @metrics = MetricsCalculator.new(font) # Set up scaler upm_scale = [:upm_scale] || 1000 @scaler = if upm_scale == :native UPMScaler.native(font) else UPMScaler.new(font, target_upm: upm_scale) end # Set up encoding @encoding = [:encoding] || Encodings::AdobeStandard end |
Class Method Details
.adobe_glyph_name(codepoint, encoding: nil) ⇒ String
Get Adobe glyph name from Unicode codepoint
61 62 63 64 65 66 67 |
# File 'lib/fontisan/type1/afm_generator.rb', line 61 def adobe_glyph_name(codepoint, encoding: nil) if encoding encoding.glyph_name_for_code(codepoint) else AGL.glyph_name_for_unicode(codepoint) end end |
.generate(font, options = {}) ⇒ String
Generate AFM content from a font
41 42 43 |
# File 'lib/fontisan/type1/afm_generator.rb', line 41 def generate(font, = {}) new(font, ).generate_afm end |
.generate_to_file(font, path, options = {}) ⇒ void
This method returns an undefined value.
Generate AFM file from a font and write to file
51 52 53 54 |
# File 'lib/fontisan/type1/afm_generator.rb', line 51 def generate_to_file(font, path, = {}) afm_content = generate(font, ) File.write(path, afm_content, encoding: "ISO-8859-1") end |
Instance Method Details
#generate_afm ⇒ String
Generate AFM content
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/fontisan/type1/afm_generator.rb', line 93 def generate_afm afm_lines = [] # Header afm_lines << "StartFontMetrics 4.1" # Font metadata (afm_lines) # Font bounding box add_font_bounding_box(afm_lines) # Character metrics add_character_metrics(afm_lines) # Kerning data add_kerning_data(afm_lines) # Footer afm_lines << "EndFontMetrics" afm_lines.join("\n") end |