Class: Fontisan::Svg::FontGenerator
- Inherits:
-
Object
- Object
- Fontisan::Svg::FontGenerator
- Defined in:
- lib/fontisan/svg/font_generator.rb
Overview
Generates complete SVG font XML structure
FontGenerator orchestrates all
SVG font generation components to produce a complete SVG font document.
It coordinates FontFaceGenerator, GlyphGenerator, and ViewBoxCalculator
to build valid SVG font XML.
Responsibilities:
- Generate complete SVG font XML structure
- Coordinate sub-generators (font-face, glyphs)
- Create proper XML namespaces and structure
- Handle font ID and default advance width
- Format XML with proper indentation
This is the main orchestrator for SVG font generation, following the single responsibility principle by delegating specific tasks to specialized generators.
Instance Attribute Summary collapse
-
#font ⇒ TrueTypeFont, OpenTypeFont
readonly
Font instance.
-
#glyph_data ⇒ Hash
readonly
Glyph data map (glyph_id => codepoints, name, advance).
-
#options ⇒ Hash
readonly
Generation options.
Instance Method Summary collapse
-
#generate ⇒ String
Generate complete SVG font XML.
-
#initialize(font, glyph_data, options = {}) ⇒ FontGenerator
constructor
Initialize generator.
Constructor Details
#initialize(font, glyph_data, options = {}) ⇒ FontGenerator
Initialize generator
46 47 48 49 50 51 52 |
# File 'lib/fontisan/svg/font_generator.rb', line 46 def initialize(font, glyph_data, = {}) validate_parameters!(font, glyph_data) @font = font @glyph_data = glyph_data @options = .merge() end |
Instance Attribute Details
#font ⇒ TrueTypeFont, OpenTypeFont (readonly)
Returns Font instance.
29 30 31 |
# File 'lib/fontisan/svg/font_generator.rb', line 29 def font @font end |
#glyph_data ⇒ Hash (readonly)
Returns Glyph data map (glyph_id => codepoints, name, advance).
32 33 34 |
# File 'lib/fontisan/svg/font_generator.rb', line 32 def glyph_data @glyph_data end |
#options ⇒ Hash (readonly)
Returns Generation options.
35 36 37 |
# File 'lib/fontisan/svg/font_generator.rb', line 35 def @options end |
Instance Method Details
#generate ⇒ String
Generate complete SVG font XML
Creates a complete SVG document with embedded font definition. The structure follows SVG 1.1 font specification.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fontisan/svg/font_generator.rb', line 60 def generate parts = [] parts << xml_declaration parts << svg_opening_tag parts << " <defs>" parts << generate_font_element parts << " </defs>" parts << svg_closing_tag parts.join("\n") end |