Class: Fontisan::Converters::Type1Converter
- Inherits:
-
Object
- Object
- Fontisan::Converters::Type1Converter
- Includes:
- CffTableBuilder, ConversionStrategy
- Defined in:
- lib/fontisan/converters/type1_converter.rb
Overview
Converter for Adobe Type 1 fonts to/from SFNT formats.
[‘Type1Converter`](lib/fontisan/converters/type1_converter.rb) handles bidirectional conversion between Type 1 fonts (PFB/PFA) and SFNT-based formats (TTF, OTF, WOFF, WOFF2).
Conversion Strategy
Type 1 fonts use PostScript CharStrings that are similar to CFF CharStrings used in OpenType fonts. The conversion uses CharStringConverter for the CharString translation.
-
Type 1 → OTF: Convert Type 1 CharStrings to CFF format, build CFF table
-
OTF → Type 1: Convert CFF CharStrings to Type 1 format, build PFB/PFA
-
Type 1 → TTF: Type 1 → OTF → TTF (via OutlineConverter)
-
TTF → Type 1: TTF → OTF → Type 1
Conversion Options
The converter accepts [‘ConversionOptions`](../conversion_options) with opening and generating options:
-
Opening options: decompose_composites, generate_unicode, read_all_records
-
Generating options: decompose_on_output, hinting_mode, write_pfm, write_afm
Instance Method Summary collapse
-
#convert(font, options = {}) ⇒ Hash<String, String>
Convert font to target format.
-
#initialize(options = {}) ⇒ Type1Converter
constructor
Initialize a new Type1Converter.
-
#supported_conversions ⇒ Array<Array<Symbol>>
Get supported conversions.
-
#validate(font, target_format) ⇒ Boolean
Validate font for conversion.
Methods included from CffTableBuilder
Methods included from ConversionStrategy
Constructor Details
#initialize(options = {}) ⇒ Type1Converter
Initialize a new Type1Converter
61 62 63 64 65 |
# File 'lib/fontisan/converters/type1_converter.rb', line 61 def initialize( = {}) @optimize_cff = .fetch(:optimize_cff, false) @preserve_hints = .fetch(:preserve_hints, true) @target_format = [:target_format] end |
Instance Method Details
#convert(font, options = {}) ⇒ Hash<String, String>
Convert font to target format
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fontisan/converters/type1_converter.rb', line 74 def convert(font, = {}) # Extract ConversionOptions if provided = () target_format = [:target_format] || &.to || @target_format || detect_target_format(font) validate(font, target_format) # Apply opening options to source font (font, ) if source_format = detect_format(font) case [source_format, target_format] when %i[type1 otf] convert_type1_to_otf(font, ) when %i[otf type1] convert_otf_to_type1(font, ) when %i[type1 ttf] convert_type1_to_ttf(font, ) when %i[ttf type1] convert_ttf_to_type1(font, ) else raise Fontisan::Error, "Unsupported conversion: #{source_format} → #{target_format}" end end |
#supported_conversions ⇒ Array<Array<Symbol>>
Get supported conversions
105 106 107 108 109 110 111 112 |
# File 'lib/fontisan/converters/type1_converter.rb', line 105 def supported_conversions [ %i[type1 otf], %i[otf type1], %i[type1 ttf], %i[ttf type1], ] end |
#validate(font, target_format) ⇒ Boolean
Validate font for conversion
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/fontisan/converters/type1_converter.rb', line 121 def validate(font, target_format) raise ArgumentError, "Font cannot be nil" if font.nil? unless font.respond_to?(:font_dictionary) || font.respond_to?(:tables) raise ArgumentError, "Font must be Type1Font or have :tables method" end source_format = detect_format(font) unless supports?(source_format, target_format) raise Fontisan::Error, "Conversion #{source_format} → #{target_format} not supported" end true end |