Class: Fontisan::SvgToGlyf::Geometry::Normalizer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(viewbox_width:, viewbox_height:, upm:) ⇒ Normalizer

Returns a new instance of Normalizer.

Parameters:

  • viewbox_width (Float)

    SVG viewBox width

  • viewbox_height (Float)

    SVG viewBox height

  • upm (Integer)

    font units-per-em



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

#upmObject (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_heightObject (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_widthObject (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.

Parameters:

  • group_transform (AffineTransform) (defaults to: AffineTransform.identity)

    accumulated transforms

Returns:



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

#matrixAffineTransform

Returns the viewBox→font normalization.

Returns:



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