Class: Vectory::Emf

Inherits:
Vector show all
Defined in:
lib/vectory/emf.rb

Instance Attribute Summary

Attributes inherited from Vector

#initial_path

Attributes inherited from Image

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Vector

#file_size, from_datauri, from_path, #height, #initialize, #mime, #path, #size, #to_uri, #width, #write

Methods inherited from Image

from_content, from_path, #initialize

Constructor Details

This class inherits a constructor from Vectory::Vector

Class Method Details

.all_mimetypesObject



11
12
13
# File 'lib/vectory/emf.rb', line 11

def self.all_mimetypes
  [mimetype] + alternative_mimetypes
end

.alternative_mimetypesObject



19
20
21
# File 'lib/vectory/emf.rb', line 19

def self.alternative_mimetypes
  ["application/x-msmetafile"]
end

.default_extensionObject



7
8
9
# File 'lib/vectory/emf.rb', line 7

def self.default_extension
  "emf"
end

.from_node(node) ⇒ Object



23
24
25
26
27
28
# File 'lib/vectory/emf.rb', line 23

def self.from_node(node)
  uri = node["src"]
  return Vectory::Datauri.new(uri).to_vector if %r{^data:}.match?(uri)

  from_path(uri)
end

.mimetypeObject



15
16
17
# File 'lib/vectory/emf.rb', line 15

def self.mimetype
  "image/emf"
end

Instance Method Details

#to_epsObject



40
41
42
43
44
45
46
47
# File 'lib/vectory/emf.rb', line 40

def to_eps
  InkscapeWrapper.convert(
    content: content,
    input_format: :emf,
    output_format: :eps,
    output_class: Eps,
  )
end

#to_psObject



49
50
51
52
53
54
55
56
# File 'lib/vectory/emf.rb', line 49

def to_ps
  InkscapeWrapper.convert(
    content: content,
    input_format: :emf,
    output_format: :ps,
    output_class: Ps,
  )
end

#to_svgObject



30
31
32
33
34
35
36
37
38
# File 'lib/vectory/emf.rb', line 30

def to_svg
  Dir.mktmpdir do |dir|
    input_path = File.join(dir, "image.emf")
    File.binwrite(input_path, content)

    svg_content = Emf2svg.from_file(input_path)
    Svg.from_content(svg_content)
  end
end