Class: Fontisan::SvgToGlyf::Geometry::Normalizer
- Inherits:
-
Object
- Object
- Fontisan::SvgToGlyf::Geometry::Normalizer
- Defined in:
- lib/fontisan/svg_to_glyf/geometry/normalizer.rb
Overview
Computes the affine transform that maps SVG viewBox coordinates (Y-down, origin at top-left) into font coordinates (Y-up, origin at bottom-left, scaled to UPM).
The normalization combines a Y-flip across the viewBox midline with a uniform scale from viewBox units to font units. The resulting matrix is then composed with the SVG document's accumulated group transform to produce the final per-point transform.
Instance Attribute Summary collapse
-
#upm ⇒ Object
readonly
Returns the value of attribute upm.
-
#viewbox_height ⇒ Object
readonly
Returns the value of attribute viewbox_height.
-
#viewbox_width ⇒ Object
readonly
Returns the value of attribute viewbox_width.
Instance Method Summary collapse
-
#final_transform(group_transform = AffineTransform.identity) ⇒ AffineTransform
Compose the normalization with an SVG group transform, producing the final per-point transform.
-
#initialize(viewbox_width:, viewbox_height:, upm:) ⇒ Normalizer
constructor
A new instance of Normalizer.
-
#matrix ⇒ AffineTransform
The viewBox→font normalization.
Constructor Details
#initialize(viewbox_width:, viewbox_height:, upm:) ⇒ Normalizer
Returns a new instance of Normalizer.
21 22 23 24 25 |
# File 'lib/fontisan/svg_to_glyf/geometry/normalizer.rb', line 21 def initialize(viewbox_width:, viewbox_height:, upm:) @viewbox_width = viewbox_width.to_f @viewbox_height = viewbox_height.to_f @upm = upm.to_f end |
Instance Attribute Details
#upm ⇒ Object (readonly)
Returns the value of attribute upm.
16 17 18 |
# File 'lib/fontisan/svg_to_glyf/geometry/normalizer.rb', line 16 def upm @upm end |
#viewbox_height ⇒ Object (readonly)
Returns the value of attribute viewbox_height.
16 17 18 |
# File 'lib/fontisan/svg_to_glyf/geometry/normalizer.rb', line 16 def viewbox_height @viewbox_height end |
#viewbox_width ⇒ Object (readonly)
Returns the value of attribute viewbox_width.
16 17 18 |
# File 'lib/fontisan/svg_to_glyf/geometry/normalizer.rb', line 16 def viewbox_width @viewbox_width end |
Instance Method Details
#final_transform(group_transform = AffineTransform.identity) ⇒ AffineTransform
Compose the normalization with an SVG group transform, producing the final per-point transform.
39 40 41 |
# File 'lib/fontisan/svg_to_glyf/geometry/normalizer.rb', line 39 def final_transform(group_transform = AffineTransform.identity) matrix.compose(group_transform) end |
#matrix ⇒ AffineTransform
Returns the viewBox→font normalization.
28 29 30 31 32 |
# File 'lib/fontisan/svg_to_glyf/geometry/normalizer.rb', line 28 def matrix sx = @upm / @viewbox_width sy = @upm / @viewbox_height AffineTransform.new(sx, 0, 0, -sy, 0, @upm) end |