Class: Emfsvg::Translation::Scaler::Fixed

Inherits:
Object
  • Object
show all
Defined in:
lib/emfsvg/translation/scaler/fixed.rb

Overview

Fixed-factor scaler: multiplies SVG decimal coords by FACTOR (default 10_000) so 4 decimal places are preserved as integer fractions in EMF int32 fields. emfsvg's renderer computes sf_x = viewport_ext / window_ext = 1 / FACTOR and divides back to recover the decimal.

Choice of 10_000 matches emfsvg's %.4f formatting exactly. Larger factors risk int32 overflow on big coords (max safe SVG coord ~ 214_000 with FACTOR=10_000).

Constant Summary collapse

FACTOR =
10_000
MAX_SAFE_INPUT =

(2**31 - 1) / FACTOR, with margin

214_748

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factor = FACTOR) ⇒ Fixed

Returns a new instance of Fixed.



21
22
23
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 21

def initialize(factor = FACTOR)
  @factor = factor
end

Instance Attribute Details

#factorObject (readonly)

Returns the value of attribute factor.



19
20
21
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 19

def factor
  @factor
end

Instance Method Details

#scaled?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 29

def scaled?
  true
end

#to_int(decimal) ⇒ Object



25
26
27
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 25

def to_int(decimal)
  (decimal.to_f * factor).round
end

#unsafe?(value) ⇒ Boolean

True if value would overflow int32 when scaled. The renderer falls back to Identity when ANY coord is unsafe.

Returns:

  • (Boolean)


35
36
37
# File 'lib/emfsvg/translation/scaler/fixed.rb', line 35

def unsafe?(value)
  value.to_f.abs > MAX_SAFE_INPUT
end