Class: Fontisan::SvgToGlyf::Document
- Inherits:
-
Object
- Object
- Fontisan::SvgToGlyf::Document
- 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
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#viewbox_height ⇒ Object
readonly
Returns the value of attribute viewbox_height.
-
#viewbox_width ⇒ Object
readonly
Returns the value of attribute viewbox_width.
Class Method Summary collapse
Instance Method Summary collapse
-
#each_path {|path_data, transform| ... } ⇒ Object
Yield each
element's d= string along with the accumulated AffineTransform from all ancestor transform= attributes. -
#initialize(doc) ⇒ Document
constructor
A new instance of Document.
Constructor Details
#initialize(doc) ⇒ Document
Returns a new instance of 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
#source ⇒ Object (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_height ⇒ Object (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_width ⇒ Object (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
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
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
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 |