Class: Fontisan::SvgToGlyf::Assembler
- Inherits:
-
Object
- Object
- Fontisan::SvgToGlyf::Assembler
- Defined in:
- lib/fontisan/svg_to_glyf/assembler.rb
Overview
Orchestrates the full SVG → Ufo::Glyph pipeline:
path data + transforms
→ Path::Parser.parse → [Command]
→ Path::ContourBuilder.build → [Ufo::Contour]
→ apply final transform (normalization · group transform)
→ round to Integer
→ Ufo::Glyph
For SVG files and directories, the Document class extracts the viewBox, accumulated transforms, and path data; the Assembler composes the normalizer with the group transform and runs the pipeline once per path.
Instance Attribute Summary collapse
-
#upm ⇒ Object
readonly
Returns the value of attribute upm.
Instance Method Summary collapse
-
#build_from_directory(dir) ⇒ Fontisan::Ufo::Font
Build a font from a directory of SVG files.
-
#build_from_file(file_path, codepoint: nil) ⇒ Fontisan::Ufo::Glyph
Build a glyph from an SVG file.
-
#build_from_path_data(path_data, codepoint: nil, name: nil, viewbox: nil, transform: nil) ⇒ Fontisan::Ufo::Glyph
Build a glyph directly from a path data string.
-
#initialize(upm: SvgToGlyf::DEFAULT_UPM) ⇒ Assembler
constructor
A new instance of Assembler.
Constructor Details
#initialize(upm: SvgToGlyf::DEFAULT_UPM) ⇒ Assembler
Returns a new instance of Assembler.
22 23 24 |
# File 'lib/fontisan/svg_to_glyf/assembler.rb', line 22 def initialize(upm: SvgToGlyf::DEFAULT_UPM) @upm = upm.to_i end |
Instance Attribute Details
#upm ⇒ Object (readonly)
Returns the value of attribute upm.
19 20 21 |
# File 'lib/fontisan/svg_to_glyf/assembler.rb', line 19 def upm @upm end |
Instance Method Details
#build_from_directory(dir) ⇒ Fontisan::Ufo::Font
Build a font from a directory of SVG files.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fontisan/svg_to_glyf/assembler.rb', line 62 def build_from_directory(dir) font = Fontisan::Ufo::Font.new font.info.units_per_em = @upm Dir.glob(File.join(dir, "*.svg")).each do |path| glyph = build_from_file(path) font.glyphs[glyph.name] = glyph end font end |
#build_from_file(file_path, codepoint: nil) ⇒ Fontisan::Ufo::Glyph
Build a glyph from an SVG file.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fontisan/svg_to_glyf/assembler.rb', line 47 def build_from_file(file_path, codepoint: nil) doc = Document.from_file(file_path) codepoint ||= codepoint_from_filename(File.basename(file_path)) doc.each_path.with_object(nil) do |(data, transform), _| return build_from_doc_path(data, transform, doc, codepoint) end empty_glyph(codepoint) end |
#build_from_path_data(path_data, codepoint: nil, name: nil, viewbox: nil, transform: nil) ⇒ Fontisan::Ufo::Glyph
Build a glyph directly from a path data string.
34 35 36 37 38 39 40 |
# File 'lib/fontisan/svg_to_glyf/assembler.rb', line 34 def build_from_path_data(path_data, codepoint: nil, name: nil, viewbox: nil, transform: nil) viewbox ||= { width: @upm, height: @upm } final = normalizer_for(**viewbox).final_transform(transform || Geometry::AffineTransform.identity) contours = build_contours(path_data, final) assemble_glyph(name || glyph_name_for(codepoint), contours, codepoint) end |