Class: Emfsvg::Translation::EmfRenderer
- Inherits:
-
Object
- Object
- Emfsvg::Translation::EmfRenderer
- Defined in:
- lib/emfsvg/translation/emf_renderer.rb
Overview
Top-level orchestrator: takes an Svg::Document, walks its element tree via a HandlerRegistry, and produces an Emf::Model::Metafile whose serialized bytes can be re-parsed by Emf.parse and re-rendered by Emfsvg.from_bytes.
The default registry maps the supported SVG element vocabulary (rect, ellipse, circle, line, polyline, polygon, path, group, text, image, defs, clipPath) to handler classes.
If the SVG contains any decimal coordinates, the renderer installs
Scaler::Fixed (multiplies coords by 10_000 to preserve 4
decimal places in EMF int32 fields) and emits SetMapMode +
SetWindowExtEx + SetViewportExtEx so emfsvg's renderer computes
the matching sf_x = 1/10_000.
Constant Summary collapse
- DEFAULT_REGISTRY =
HandlerRegistry.new
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(document, registry: DEFAULT_REGISTRY) ⇒ EmfRenderer
constructor
A new instance of EmfRenderer.
Constructor Details
#initialize(document, registry: DEFAULT_REGISTRY) ⇒ EmfRenderer
Returns a new instance of EmfRenderer.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/emfsvg/translation/emf_renderer.rb', line 43 def initialize(document, registry: DEFAULT_REGISTRY) @document = document @registry = registry @scaler = pick_scaler @context = Context.new( handler_registry: registry, clip_path_registry: Svg::ClipPathRegistry.from_document(document), scaler: @scaler ) end |
Class Method Details
.call(document, registry: DEFAULT_REGISTRY) ⇒ Object
24 25 26 |
# File 'lib/emfsvg/translation/emf_renderer.rb', line 24 def self.call(document, registry: DEFAULT_REGISTRY) new(document, registry: registry).call end |
.register_default_handlers! ⇒ Object
Instance Method Details
#call ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/emfsvg/translation/emf_renderer.rb', line 54 def call emit_scaling_prelude if @scaler.scaled? dispatch_root(@document.root_element) emit_eof header = HeaderBuilder.build(@document, n_records: @context.records.size + 1, n_handles: @context.object_table.size + 1) Emf::Model::Metafile.new( format: :emf, header: header, records: @context.records.freeze ) end |