Class: Emfsvg::Svg::Elements::ClipPath::PathFlattenerForClip

Inherits:
Object
  • Object
show all
Defined in:
lib/emfsvg/svg/elements/clip_path.rb

Overview

Minimal path flattener for clip extraction. Only handles absolute M/L/H/V/Z — enough for emfsvg's rectangular clip output. Relative commands and curves fall through (returns nil → caller treats as non-rectangular).

Instance Method Summary collapse

Instance Method Details

#flatten(commands) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/emfsvg/svg/elements/clip_path.rb', line 99

def flatten(commands)
  points = []
  current = [0.0, 0.0]
  commands.each do |cmd|
    case cmd.letter
    when "M"
      current = cmd.args
      points << current.dup
    when "L"
      current = cmd.args
      points << current.dup
    when "H"
      current = [cmd.args.first, current.last]
      points << current.dup
    when "V"
      current = [current.first, cmd.args.first]
      points << current.dup
    when "Z"
      # close — ignored for bounds extraction
    else
      return nil
    end
  end
  points
end