Class: Vectory::Eps

Inherits:
Vector show all
Defined in:
lib/vectory/eps.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, #initialize, #mime, #path, #size, #to_uri, #write

Methods inherited from Image

from_content, from_path, #initialize

Constructor Details

This class inherits a constructor from Vectory::Vector

Class Method Details

.default_extensionObject



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

def self.default_extension
  "eps"
end

.from_node(node) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/vectory/eps.rb', line 15

def self.from_node(node)
  return from_content(node.children.to_xml) unless node.text.strip.empty?

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

  from_path(uri)
end

.mimetypeObject



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

def self.mimetype
  "application/postscript"
end

Instance Method Details

#heightObject



48
49
50
51
52
53
# File 'lib/vectory/eps.rb', line 48

def height
  bbox = parse_bounding_box
  return super unless bbox

  bbox[:ury] - bbox[:lly]
end

#to_emfObject



32
33
34
# File 'lib/vectory/eps.rb', line 32

def to_emf
  to_pdf.to_emf
end

#to_pdfObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vectory/eps.rb', line 36

def to_pdf
  pdf_content = GhostscriptWrapper.convert(content, eps_crop: true)
  pdf = Pdf.new(pdf_content)
  # Pass original BoundingBox dimensions to preserve them in conversions
  bbox = parse_bounding_box
  if bbox
    pdf.original_width = bbox[:urx] - bbox[:llx]
    pdf.original_height = bbox[:ury] - bbox[:lly]
  end
  pdf
end

#to_psObject



24
25
26
# File 'lib/vectory/eps.rb', line 24

def to_ps
  to_pdf.to_ps
end

#to_svgObject



28
29
30
# File 'lib/vectory/eps.rb', line 28

def to_svg
  Svg.from_content(Postsvg.convert(content))
end

#widthObject



55
56
57
58
59
60
# File 'lib/vectory/eps.rb', line 55

def width
  bbox = parse_bounding_box
  return super unless bbox

  bbox[:urx] - bbox[:llx]
end