Class: Fontisan::Type1::PFBGenerator
- Inherits:
-
Object
- Object
- Fontisan::Type1::PFBGenerator
- Defined in:
- lib/fontisan/type1/pfb_generator.rb
Overview
PFB (Printer Font Binary) Generator
PFBGenerator generates Type 1 PFB files
from TrueType fonts.
PFB files are segmented binary files used by Windows for Type 1 fonts. They contain:
- ASCII segment: Font dictionary
- Binary segment: CharString data
- ASCII segment: Trailer
Constant Summary collapse
- ASCII_SEGMENT =
PFB segment markers
0x01- BINARY_SEGMENT =
0x02- END_SEGMENT =
0x03- PFB_HEADER =
Header format string
"%%!PS-AdobeFont-1.0: %s 1.0\n"
Class Method Summary collapse
-
.generate(font, options = {}) ⇒ String
Generate PFB from TTF font.
Instance Method Summary collapse
-
#generate ⇒ String
Generate PFB file content.
-
#initialize(font, options = {}) ⇒ PFBGenerator
constructor
A new instance of PFBGenerator.
Constructor Details
#initialize(font, options = {}) ⇒ PFBGenerator
Returns a new instance of PFBGenerator.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fontisan/type1/pfb_generator.rb', line 47 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 PFB from TTF font
43 44 45 |
# File 'lib/fontisan/type1/pfb_generator.rb', line 43 def self.generate(font, = {}) new(font, ).generate end |
Instance Method Details
#generate ⇒ String
Generate PFB file content
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fontisan/type1/pfb_generator.rb', line 70 def generate # Build PFB segments ascii_segment1 = build_ascii_segment_1 binary_segment = build_binary_segment ascii_segment2 = build_ascii_segment_2 # Combine with segment headers [ segment_header(ASCII_SEGMENT, ascii_segment1.bytesize), ascii_segment1, segment_header(BINARY_SEGMENT, binary_segment.bytesize), binary_segment, segment_header(ASCII_SEGMENT, ascii_segment2.bytesize), ascii_segment2, [END_SEGMENT, 0, 0, 0, 0, 0].pack("CV"), ].join end |