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`](lib/fontisan/type1/pfb_generator.rb) 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.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fontisan/type1/pfb_generator.rb', line 52 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
48 49 50 |
# File 'lib/fontisan/type1/pfb_generator.rb', line 48 def self.generate(font, = {}) new(font, ).generate end |
Instance Method Details
#generate ⇒ String
Generate PFB file content
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fontisan/type1/pfb_generator.rb', line 75 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 |