Module: Ea::Image::EmfRenderer

Defined in:
lib/ea/image/emf_renderer.rb

Overview

Converts EA's t_image EMF blobs to SVG strings by delegating to the pure-Ruby emfsvg gem. Lazy-loads the gem on first call.

When emfsvg is unavailable, returns nil — callers should fall back to skipping image rendering. This keeps the gem optional rather than a hard runtime requirement.

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns true if the emfsvg gem can be loaded.

Returns:

  • (Boolean)

    true if the emfsvg gem can be loaded



30
31
32
33
34
35
36
37
38
39
# File 'lib/ea/image/emf_renderer.rb', line 30

def available?
  return @available if defined?(@available)

  begin
    require "emfsvg"
    @available = !!Emfsvg
  rescue LoadError
    @available = false
  end
end

.render(bytes, **options) ⇒ String?

Convert an EMF blob (raw bytes) to an SVG string.

Parameters:

  • bytes (String, nil)

    EMF binary blob from t_image.Image

  • options (Hash)

    forwarded to Emfsvg.from_bytes

Returns:

  • (String, nil)

    SVG markup, or nil if emfsvg unavailable



19
20
21
22
23
24
25
26
27
# File 'lib/ea/image/emf_renderer.rb', line 19

def render(bytes, **options)
  return nil if bytes.nil? || bytes.empty?
  return nil unless available?

  Emfsvg.from_bytes(bytes, **options)
rescue StandardError => e
  warn "[ea] emfsvg render failed: #{e.message}" if ENV["EA_DEBUG"]
  nil
end