Class: Fontisan::Svg::StandaloneGlyph
- Inherits:
-
Object
- Object
- Fontisan::Svg::StandaloneGlyph
- Defined in:
- lib/fontisan/svg/standalone_glyph.rb
Overview
Renders a single UFO glyph as a standalone SVG document (a
<svg> root with one <path> and a viewBox sized to the
glyph's bounding box). Distinct from FontGenerator, which
emits a <svg><defs><font> document covering every glyph.
Used by the fontisan ufo extract CLI command and by
downstream consumers that want per-glyph SVG exports without
having to slice up a font-format SVG themselves.
Path rendering supports quadratic and cubic Bezier curves (UFO's standard outline model). Curve logic is inlined here rather than reaching into GlyphGenerator's private path code — that logic is font-format-specific (Y-axis flip via ViewBoxCalculator) and doesn't cleanly factor out.
Instance Method Summary collapse
-
#generate(glyph) ⇒ String
Standalone SVG XML.
-
#initialize(units_per_em: 1000, ascent: 800, descent: -200)) ⇒ StandaloneGlyph
constructor
A new instance of StandaloneGlyph.
Constructor Details
#initialize(units_per_em: 1000, ascent: 800, descent: -200)) ⇒ StandaloneGlyph
Returns a new instance of StandaloneGlyph.
23 24 25 26 27 |
# File 'lib/fontisan/svg/standalone_glyph.rb', line 23 def initialize(units_per_em: 1000, ascent: 800, descent: -200) @units_per_em = units_per_em.to_i @ascent = ascent.to_i @descent = descent.to_i end |
Instance Method Details
#generate(glyph) ⇒ String
Returns standalone SVG XML.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fontisan/svg/standalone_glyph.rb', line 31 def generate(glyph) path_data = path_data_for(glyph) view_box = view_box_for(glyph) <<~SVG <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox="#{view_box}"> <path d="#{path_data}"/> </svg> SVG end |