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 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 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
52 53 54 55 56 |
# File 'lib/fontisan/converters/type1_converter.rb', line 52 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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fontisan/converters/type1_converter.rb', line 65 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
96 97 98 99 100 101 102 103 |
# File 'lib/fontisan/converters/type1_converter.rb', line 96 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
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fontisan/converters/type1_converter.rb', line 112 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 |