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
-
.available? ⇒ Boolean
True if the emfsvg gem can be loaded.
-
.render(bytes, **options) ⇒ String?
Convert an EMF blob (raw bytes) to an SVG string.
Class Method Details
.available? ⇒ Boolean
Returns 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.
19 20 21 22 23 24 25 26 27 |
# File 'lib/ea/image/emf_renderer.rb', line 19 def render(bytes, **) return nil if bytes.nil? || bytes.empty? return nil unless available? Emfsvg.from_bytes(bytes, **) rescue StandardError => e warn "[ea] emfsvg render failed: #{e.}" if ENV["EA_DEBUG"] nil end |