Class: Emfsvg::Translation::Handlers::GroupHandler

Inherits:
Object
  • Object
show all
Includes:
Emf::Emr::Binary::TypeCodes
Defined in:
lib/emfsvg/translation/handlers/group_handler.rb

Overview

Translate into SaveDC + SetWorldTransform (if transformed) + children + RestoreDC. Matches EMF→SVG's reverse transform_group emission.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(element, context) ⇒ Object



14
15
16
# File 'lib/emfsvg/translation/handlers/group_handler.rb', line 14

def self.call(element, context)
  new.translate(element, context)
end

Instance Method Details

#translate(element, context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/emfsvg/translation/handlers/group_handler.rb', line 18

def translate(element, context)
  context.emit(Emf::Emr::Binary::Records::SaveDc, i_type: SAVEDC)
  # Always emit SetWorldTransform — emfsvg's EMF→SVG renderer
  # emits `<g transform="matrix(...)">` for every SetWorldTransform
  # record, regardless of whether the matrix is identity. Skipping
  # it would drop the group wrapper from the round-tripped SVG.
  emit_world_transform(element.transform_matrix, context)
  element.children.each { |child| context.dispatch(child) }
  context.emit(Emf::Emr::Binary::Records::RestoreDc,
               i_type: RESTOREDC, saved_dc: -1)
end