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`](lib/fontisan/svg/font_generator.rb) 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 => unicode, 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
50 51 52 53 54 55 56 |
# File 'lib/fontisan/svg/font_generator.rb', line 50 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.
33 34 35 |
# File 'lib/fontisan/svg/font_generator.rb', line 33 def font @font end |
#glyph_data ⇒ Hash (readonly)
Returns Glyph data map (glyph_id => unicode, name, advance).
36 37 38 |
# File 'lib/fontisan/svg/font_generator.rb', line 36 def glyph_data @glyph_data end |
#options ⇒ Hash (readonly)
Returns Generation options.
39 40 41 |
# File 'lib/fontisan/svg/font_generator.rb', line 39 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.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fontisan/svg/font_generator.rb', line 64 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 |