Class: Fontisan::SvgToGlyf::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/svg_to_glyf/document.rb

Overview

Walks an SVG XML document to extract path data and accumulated transforms. The Document is the single source of truth for which transforms apply to which paths and what coordinate space the SVG defines (via viewBox).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Document

Returns a new instance of Document.

Parameters:

  • doc (Nokogiri::XML::Document)


25
26
27
28
29
# File 'lib/fontisan/svg_to_glyf/document.rb', line 25

def initialize(doc)
  @doc = doc
  @source = doc
  extract_viewbox
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/fontisan/svg_to_glyf/document.rb', line 12

def source
  @source
end

#viewbox_heightObject (readonly)

Returns the value of attribute viewbox_height.



12
13
14
# File 'lib/fontisan/svg_to_glyf/document.rb', line 12

def viewbox_height
  @viewbox_height
end

#viewbox_widthObject (readonly)

Returns the value of attribute viewbox_width.



12
13
14
# File 'lib/fontisan/svg_to_glyf/document.rb', line 12

def viewbox_width
  @viewbox_width
end

Class Method Details

.from_file(path) ⇒ Object

Parameters:

  • path (String)

    file path to an .svg file



20
21
22
# File 'lib/fontisan/svg_to_glyf/document.rb', line 20

def self.from_file(path)
  from_xml(File.read(path))
end

.from_xml(xml) ⇒ Object

Parameters:

  • xml (String)

    raw SVG XML



15
16
17
# File 'lib/fontisan/svg_to_glyf/document.rb', line 15

def self.from_xml(xml)
  new(Nokogiri::XML(xml))
end

Instance Method Details

#each_path {|path_data, transform| ... } ⇒ Object

Yield each element's d= string along with the accumulated AffineTransform from all ancestor transform= attributes.

Yield Parameters:



36
37
38
39
40
# File 'lib/fontisan/svg_to_glyf/document.rb', line 36

def each_path(&)
  return enum_for(:each_path) unless block_given?

  walk(@doc.root, Geometry::AffineTransform.identity, &)
end