Class: Fontisan::Converters::SvgGenerator
- Inherits:
-
Object
- Object
- Fontisan::Converters::SvgGenerator
- Includes:
- ConversionStrategy
- Defined in:
- lib/fontisan/converters/svg_generator.rb
Overview
SVG font generator conversion strategy
SvgGenerator implements
the ConversionStrategy interface to convert TTF or OTF fonts to SVG
font format for web use, inspection, or conversion purposes.
SVG font generation process:
- Extract font metadata from tables
- Extract glyph outlines using OutlineExtractor
- Get unicode mappings from cmap table
- Get advance widths from hmtx table
- Build glyph data map
- Generate complete SVG XML using FontGenerator
Note: SVG fonts are deprecated in favor of WOFF/WOFF2 but remain useful for fallback, conversion workflows, and font inspection.
Instance Method Summary collapse
-
#convert(font, options = {}) ⇒ Hash
Convert font to SVG format.
-
#supported_conversions ⇒ Array<Array<Symbol>>
Get list of supported conversions.
-
#validate(font, target_format) ⇒ Boolean
Validate that conversion is possible.
Methods included from ConversionStrategy
Instance Method Details
#convert(font, options = {}) ⇒ Hash
Convert font to SVG format
Returns a hash with :svg_xml key containing complete SVG font XML. This follows the same pattern as Woff2Encoder.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fontisan/converters/svg_generator.rb', line 41 def convert(font, = {}) validate(font, :svg) # Extract glyph data glyph_data = extract_glyph_data(font, ) # Generate SVG XML generator = Svg::FontGenerator.new(font, glyph_data, ) svg_xml = generator.generate # Return in special format for ConvertCommand to handle { svg_xml: svg_xml } end |
#supported_conversions ⇒ Array<Array<Symbol>>
Get list of supported conversions
58 59 60 61 62 63 |
# File 'lib/fontisan/converters/svg_generator.rb', line 58 def supported_conversions [ %i[ttf svg], %i[otf svg], ] end |
#validate(font, target_format) ⇒ Boolean
Validate that conversion is possible
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fontisan/converters/svg_generator.rb', line 71 def validate(font, target_format) unless target_format == :svg raise Fontisan::Error, "SvgGenerator only supports conversion to svg, " \ "got: #{target_format}" end # Verify font has required tables required_tables = %w[head hhea maxp cmap] required_tables.each do |tag| unless font.table(tag) raise Fontisan::Error, "Font is missing required table: #{tag}" end end # Verify font has either glyf or CFF table unless font.has_table?("glyf") || font.has_table?("CFF ") || font.has_table?("CFF2") raise Fontisan::Error, "Font must have either glyf or CFF/CFF2 table" end true end |