Class: RubyDocx::Elements::Equation
- Inherits:
-
Element
- Object
- Element
- RubyDocx::Elements::Equation
show all
- Defined in:
- lib/ruby_docx/elements/equation.rb
Instance Attribute Summary collapse
Attributes inherited from Element
#doc, #grid, #node
Instance Method Summary
collapse
Methods inherited from Element
#elements, #initialize, #inspect, #to_xml
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link.
8
9
10
|
# File 'lib/ruby_docx/elements/equation.rb', line 8
def link
@link
end
|
Instance Method Details
#base64_data ⇒ Object
58
59
60
|
# File 'lib/ruby_docx/elements/equation.rb', line 58
def base64_data
"data:image/png;base64,#{Base64.strict_encode64(self.to_png)}"
end
|
#data ⇒ Object
54
55
56
|
# File 'lib/ruby_docx/elements/equation.rb', line 54
def data
self.to_png
end
|
#replace(lnk) ⇒ Object
68
69
70
|
# File 'lib/ruby_docx/elements/equation.rb', line 68
def replace(lnk)
@link = lnk
end
|
#replace_with_latex(txt) ⇒ Object
27
28
|
# File 'lib/ruby_docx/elements/equation.rb', line 27
def replace_with_latex(txt)
end
|
#replace_with_mathml(txt) ⇒ Object
24
25
|
# File 'lib/ruby_docx/elements/equation.rb', line 24
def replace_with_mathml(txt)
end
|
#save(path) ⇒ Object
62
63
64
65
66
|
# File 'lib/ruby_docx/elements/equation.rb', line 62
def save(path)
file = File.new(path, "wb")
file.write(self.to_png)
file.close
end
|
#size ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/ruby_docx/elements/equation.rb', line 35
def size
return @size if @size
sz = ImageSize.new(self.data)
@size = [sz.width/7.2, sz.height/7.2]
rescue
nil
end
|
#style ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/ruby_docx/elements/equation.rb', line 45
def style
if self.size
"width: #{self.size[0]}px; height: #{self.size[1]}px;"
else
""
end
end
|
#to_html ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/ruby_docx/elements/equation.rb', line 72
def to_html
if @link
"<img class=\"Wirisformula\" role='math' src='#{@link}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='#{self.style}' />"
else
"<img class=\"Wirisformula\" role='math' src='#{self.base64_data}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='#{self.style}' />"
end
end
|
#to_latex ⇒ Object
15
16
17
|
# File 'lib/ruby_docx/elements/equation.rb', line 15
def to_latex
TeXMath.convert("#{self.to_omml}", :from => :omml, :to => :tex)
end
|
#to_mathml ⇒ Object
19
20
21
|
# File 'lib/ruby_docx/elements/equation.rb', line 19
def to_mathml
TeXMath.convert("#{self.to_omml}", :from => :omml, :to => :mathml)
end
|
#to_omml ⇒ Object
10
11
12
13
|
# File 'lib/ruby_docx/elements/equation.rb', line 10
def to_omml
ele = @node.xpath(".//m:oMath").first
ele.to_s
end
|
#to_png ⇒ Object
30
31
32
33
|
# File 'lib/ruby_docx/elements/equation.rb', line 30
def to_png
@path ||= Calculus::Expression.new("#{self.to_latex}", :parse => false).to_png
File.read(@path)
end
|
#to_s ⇒ Object
80
81
82
|
# File 'lib/ruby_docx/elements/equation.rb', line 80
def to_s
self.to_latex.to_s
end
|