Class: Fontisan::Type1::PFMGenerator
- Inherits:
-
Object
- Object
- Fontisan::Type1::PFMGenerator
- Defined in:
- lib/fontisan/type1/pfm_generator.rb
Overview
PFM (Printer Font Metrics) file generator
[‘PFMGenerator`](lib/fontisan/type1/pfm_generator.rb) generates Printer Font Metrics files from TTF/OTF fonts.
PFM files are binary files used by Windows for printer font metrics. They include:
-
Character widths
-
Kerning pairs
-
Font metadata (name, version, copyright, etc.)
-
Extended text metrics
Constant Summary collapse
- PFM_VERSION =
PFM constants
0x0100- PFM_HEADER_SIZE =
256- DRIVER_INFO_SIZE =
Driver info structure
118- EXT_METRICS_SIZE =
Extended metrics size
48- ANSI_CHARSET =
Windows charset constants
0- DEFAULT_CHARSET =
1- SYMBOL_CHARSET =
2- FIXED_PITCH =
Font pitch and family bits
1- VARIABLE_PITCH =
0- FAMILY_DONTCARE =
Family bits (shift left 4)
0 << 4
- FAMILY_ROMAN =
1 << 4
- FAMILY_SWISS =
2 << 4
- FAMILY_MODERN =
3 << 4
- FAMILY_SCRIPT =
4 << 4
- FAMILY_DECORATIVE =
5 << 4
- FAMILY_MODERN_LOWERCASE =
6 << 4
Class Method Summary collapse
-
.generate(font, options = {}) ⇒ String
Generate PFM binary data from a font.
-
.generate_to_file(font, path, options = {}) ⇒ void
Generate PFM file from a font and write to file.
Instance Method Summary collapse
-
#generate_pfm ⇒ String
Generate PFM binary data.
-
#initialize(font, options = {}) ⇒ PFMGenerator
constructor
Initialize a new PFMGenerator.
Constructor Details
#initialize(font, options = {}) ⇒ PFMGenerator
Initialize a new PFMGenerator
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fontisan/type1/pfm_generator.rb', line 86 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 end |
Class Method Details
.generate(font, options = {}) ⇒ String
Generate PFM binary data from a font
66 67 68 |
# File 'lib/fontisan/type1/pfm_generator.rb', line 66 def generate(font, = {}) new(font, ).generate_pfm end |
.generate_to_file(font, path, options = {}) ⇒ void
This method returns an undefined value.
Generate PFM file from a font and write to file
76 77 78 79 |
# File 'lib/fontisan/type1/pfm_generator.rb', line 76 def generate_to_file(font, path, = {}) pfm_data = generate(font, ) File.binwrite(path, pfm_data) end |
Instance Method Details
#generate_pfm ⇒ String
Generate PFM binary data
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/fontisan/type1/pfm_generator.rb', line 102 def generate_pfm # Collect font data char_widths = collect_character_widths return "" if char_widths.empty? # Build sections header_data = build_header(char_widths) face_name_data = build_face_name driver_info_data = build_driver_info ext_metrics_data = build_extended_metrics width_table_data = build_width_table(char_widths) kerning_data = build_kerning_table # Calculate offsets dfFace_offset = PFM_HEADER_SIZE dfExtMetrics_offset = dfFace_offset + face_name_data.length + driver_info_data.length dfExtentTable_offset = dfExtMetrics_offset + ext_metrics_data.length dfPairKernTable_offset = if kerning_data.empty? 0 else dfExtentTable_offset + width_table_data.length end dfDriverInfo_offset = if dfPairKernTable_offset.positive? dfPairKernTable_offset + kerning_data.length else dfExtentTable_offset + width_table_data.length end # Update offsets in header update_header_offsets(header_data, dfFace_offset, dfExtMetrics_offset, dfExtentTable_offset, dfPairKernTable_offset, dfDriverInfo_offset) # Combine all sections: Header + Face Name + Driver Info + Ext Metrics + Width Table + Kerning header_data + face_name_data + driver_info_data + ext_metrics_data + width_table_data + kerning_data end |