Class: Fontisan::Type1::PFAGenerator
- Inherits:
-
Object
- Object
- Fontisan::Type1::PFAGenerator
- Defined in:
- lib/fontisan/type1/pfa_generator.rb
Overview
PFA (Printer Font ASCII) Generator
PFAGenerator generates Type 1 PFA files
from TrueType fonts.
PFA files are ASCII-encoded Type 1 fonts used by Unix systems. They are the same as PFB files but with binary data hex-encoded.
Constant Summary collapse
- HEX_LINE_LENGTH =
Hex line length for ASCII encoding
64
Class Method Summary collapse
-
.generate(font, options = {}) ⇒ String
Generate PFA from TTF font.
Instance Method Summary collapse
-
#generate ⇒ String
Generate PFA file content.
-
#initialize(font, options = {}) ⇒ PFAGenerator
constructor
A new instance of PFAGenerator.
Constructor Details
#initialize(font, options = {}) ⇒ PFAGenerator
Returns a new instance of PFAGenerator.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fontisan/type1/pfa_generator.rb', line 39 def initialize(font, = {}) @font = font @options = @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 # Set up converter options @convert_curves = .fetch(:convert_curves, true) end |
Class Method Details
.generate(font, options = {}) ⇒ String
Generate PFA from TTF font
35 36 37 |
# File 'lib/fontisan/type1/pfa_generator.rb', line 35 def self.generate(font, = {}) new(font, ).generate end |
Instance Method Details
#generate ⇒ String
Generate PFA file content
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fontisan/type1/pfa_generator.rb', line 62 def generate lines = [] # Header (ASCII section 1) lines << build_pfa_header lines << build_font_dict lines << build_private_dict lines << "" lines << "currentdict end" lines << "dup /FontName get exch definefont pop" lines << "" # Binary section (hex-encoded) lines << "%--Data to be hex-encoded:" hex_data = build_hex_encoded_charstrings lines.concat(hex_data) lines << "" # Trailer lines << build_pfa_trailer lines.join("\n") end |