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 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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fontisan/type1/afm_generator.rb', line 70 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
57 58 59 60 61 62 63 |
# File 'lib/fontisan/type1/afm_generator.rb', line 57 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
37 38 39 |
# File 'lib/fontisan/type1/afm_generator.rb', line 37 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
47 48 49 50 |
# File 'lib/fontisan/type1/afm_generator.rb', line 47 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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fontisan/type1/afm_generator.rb', line 89 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 |