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

Inherits:
Emfsvg::Svg::Element show all
Defined in:
lib/emfsvg/svg/elements/clip_path.rb

Overview

...: defines a clipping region. Contains one or more child shapes whose union forms the clip.

Defined Under Namespace

Classes: PathFlattenerForClip

Constant Summary collapse

ELEMENT_NAME =
"clipPath"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Emfsvg::Svg::Element

#clip_path, #element_name, register

Constructor Details

#initialize(id:, children:) ⇒ ClipPath

Returns a new instance of ClipPath.



14
15
16
17
# File 'lib/emfsvg/svg/elements/clip_path.rb', line 14

def initialize(id:, children:)
  @id = id
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



12
13
14
# File 'lib/emfsvg/svg/elements/clip_path.rb', line 12

def children
  @children
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/emfsvg/svg/elements/clip_path.rb', line 12

def id
  @id
end

Class Method Details

.from_node(node) ⇒ Object



19
20
21
22
23
24
# File 'lib/emfsvg/svg/elements/clip_path.rb', line 19

def self.from_node(node)
  new(
    id: node["id"],
    children: node.element_children.map { |c| Element.from_node(c) }
  )
end

Instance Method Details

#clip_boundsObject

Bounds [left, top, right, bottom] of the clip region for IntersectClipRect emission. Handles three forms:

  1. Single child — use rect bounds directly.
  2. Single child whose d-string traces a rectangle (4 unique corners + close) — extract corner bounds.
  3. Anything else — use the union bounding box of all child geometry (lossy: curves flattened to bounds).


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/emfsvg/svg/elements/clip_path.rb', line 34

def clip_bounds
  return nil if children.empty?

  if children.size == 1
    child = children.first
    return rect_bounds(child) if child.is_a?(Elements::Rect)
    return path_rect_bounds(child) if child.is_a?(Elements::Path)
  end

  bounding_box_of(children)
end

#rectangular_boundsObject

Alias retained for backward compatibility with shared_gdi.rb.



47
48
49
# File 'lib/emfsvg/svg/elements/clip_path.rb', line 47

def rectangular_bounds
  clip_bounds
end