Class: DoctorNinja::Parsers::Drawing
- Inherits:
-
Base
- Object
- Base
- DoctorNinja::Parsers::Drawing
show all
- Includes:
- Magick
- Defined in:
- lib/doctor_ninja/parsers/drawing.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #parse_children
Class Method Details
.applicable_to?(node) ⇒ Boolean
8
9
10
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 8
def self.applicable_to?(node)
node.name == "drawing"
end
|
Instance Method Details
#extent ⇒ Object
28
29
30
31
32
33
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 28
def extent
@extent ||= {
x: extent_node.attribute("cx").value.to_i,
y: extent_node.attribute("cy").value.to_i
}
end
|
#extent_node ⇒ Object
35
36
37
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 35
def extent_node
@node.xpath(".//wp:extent")
end
|
#parse ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 12
def parse
width = extent[:x]/DoctorNinja::EMU_PER_PIXEL
height = extent[:y]/DoctorNinja::EMU_PER_PIXEL
rvg = RVG.new(width,height).viewbox(0,0,width,height) do |canvas|
context = @context.dup
context[:canvas] = canvas
parse_children(context)
end
format = "png"
base64 = Base64.encode64 rvg.draw.to_blob { self.format = format }
"<img src=\"data:image/#{format};base64,#{base64}\"/>"
end
|