class RubyDocx::Elements::OleObject

Attributes

image_path[RW]
path[RW]
zip[RW]

Public Instance Methods

base64_data() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 69
def base64_data
  "data:image/png;base64,#{Base64.strict_encode64(self.to_png)}"
end
data() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 65
def data
  self.to_png
end
relation_id() click to toggle source

def style

element = @node.xpath(".//v:shape").first
if element && element.attributes.keys.index("style")
  element.attributes["style"].value
else
  nil
end

end

# File lib/ruby_docx/elements/ole_object.rb, line 38
def relation_id
  element = @node.xpath(".//o:OLEObject").first
  if element && element.attributes.keys.index("id")
    element.attributes["id"].value
  else
    nil
  end
end
replace(lnk) click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 97
def replace(lnk)
  @link = lnk
end
save(path) click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 91
def save(path)
  file = File.new(path, "wb")
  file.write(self.to_png)
  file.close
end
size() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 73
def size
  return @size if @size

  sz = ImageSize.new(self.data)

  @size = [sz.width/7.2, sz.height/7.2]
rescue
  nil
end
style() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 83
def style
  if self.size
    "width: #{self.size[0]}px; height: #{self.size[1]}px;"
  else
    nil
  end
end
to_html() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 101
def to_html
  if self.style
    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

  else
    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='height: 13px;' />"
    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='height: 13px;' />"
    end
  end

end
to_latex() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 56
def to_latex
  TeXMath.convert("#{self.to_mathml}", :from => :mathml, :to => :tex)
end
to_mathml() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 47
def to_mathml
  io = StringIO.new(@zip.read("word/" + @path))
  # xml = Mathtype::Converter.new(io)
  # # puts xml.to_xml
  # xml.to_xml

  mathml = MathTypeToMathML::Converter.new(io).convert
end
to_png() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 60
def to_png
  @image_path ||= Calculus::Expression.new("#{self.to_latex}", :parse => false).to_png
  File.read(@image_path)
end
to_s() click to toggle source
# File lib/ruby_docx/elements/ole_object.rb, line 119
def to_s
  self.to_latex.to_s
end