Module: Ucode::Glyphs::LastResort::Glif
- Defined in:
- lib/ucode/glyphs/last_resort/glif.rb
Overview
Parses one UFO ‘.glif` outline file into a Outline value object: advance width + list of contours, each contour being a list of Points.
UFO point semantics:
* `type="move"` — on-curve; starts a new contour.
* `type="line"` — on-curve; straight line from previous.
* `type="curve"` — on-curve; cubic Bezier. The preceding 1–2
points with no `type` are off-curve control
points.
* `type="qcurve"` — on-curve; quadratic Bezier. Preceding N
points with no `type` are off-curve controls.
* no `type` — off-curve control point.
Contours are implicitly closed (UFO follows PostScript convention). Svg adds the closing ‘Z` when emitting SVG path data, so the outline representation here is open.
All coordinates are in font units (integers in the Last Resort UFO; the parser accepts floats too for forward compatibility).
Defined Under Namespace
Classes: Contour, Outline, Point
Class Method Summary collapse
Class Method Details
.parse(path) ⇒ Outline
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ucode/glyphs/last_resort/glif.rb', line 70 def self.parse(path) doc = Nokogiri::XML(path.read) do |config| config.noblanks.strict end glyph = doc.at_xpath("/glyph") || doc.at_xpath("//glyph") raise Ucode::GlyphError, "not a UFO .glif file: #{path}" unless glyph advance = parse_advance(glyph) contours = parse_contours(glyph) Outline.new(advance: advance, contours: contours) end |
.read(path) ⇒ Outline
64 65 66 |
# File 'lib/ucode/glyphs/last_resort/glif.rb', line 64 def self.read(path) parse(Pathname.new(path)) end |