Class: Fontisan::Svg::StandaloneGlyph

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(units_per_em: 1000, ascent: 800, descent: -200)) ⇒ StandaloneGlyph

Returns a new instance of StandaloneGlyph.

Parameters:

  • units_per_em (Integer) (defaults to: 1000)

    font units-per-em (default 1000)

  • ascent (Integer) (defaults to: 800)

    font ascender in font units (default 800)

  • descent (Integer) (defaults to: -200))

    font descender in font units (default -200)



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.

Parameters:

Returns:

  • (String)

    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