Add support for images
This commit is contained in:
@@ -5,7 +5,10 @@ module Ezdoc
|
||||
class DocumentXml
|
||||
NAMESPACES = {
|
||||
"xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
||||
"xmlns:r" => "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
||||
"xmlns:r" => "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
||||
"xmlns:wp" => "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
||||
"xmlns:a" => "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
"xmlns:pic" => "http://schemas.openxmlformats.org/drawingml/2006/picture"
|
||||
}.freeze
|
||||
|
||||
def initialize(nodes)
|
||||
@@ -60,6 +63,15 @@ module Ezdoc
|
||||
end
|
||||
|
||||
def render_run(xml, run)
|
||||
case run
|
||||
when Nodes::Image
|
||||
render_image(xml, run)
|
||||
when Nodes::Run
|
||||
render_text_run(xml, run)
|
||||
end
|
||||
end
|
||||
|
||||
def render_text_run(xml, run)
|
||||
xml["w"].r do
|
||||
if run.bold || run.italic || run.underline
|
||||
xml["w"].rPr do
|
||||
@@ -72,6 +84,45 @@ module Ezdoc
|
||||
end
|
||||
end
|
||||
|
||||
def render_image(xml, image)
|
||||
xml["w"].r do
|
||||
xml["w"].drawing do
|
||||
xml["wp"].inline(distT: "0", distB: "0", distL: "0", distR: "0") do
|
||||
xml["wp"].extent(cx: image.width_emu.to_s, cy: image.height_emu.to_s)
|
||||
xml["wp"].docPr(id: image.doc_pr_id.to_s, name: image.filename)
|
||||
xml["wp"].cNvGraphicFramePr do
|
||||
xml["a"].graphicFrameLocks(noChangeAspect: "1")
|
||||
end
|
||||
xml["a"].graphic do
|
||||
xml["a"].graphicData(uri: "http://schemas.openxmlformats.org/drawingml/2006/picture") do
|
||||
xml["pic"].pic do
|
||||
xml["pic"].nvPicPr do
|
||||
xml["pic"].cNvPr(id: "0", name: image.filename)
|
||||
xml["pic"].cNvPicPr
|
||||
end
|
||||
xml["pic"].blipFill do
|
||||
xml["a"].blip("r:embed" => image.rid)
|
||||
xml["a"].stretch do
|
||||
xml["a"].fillRect
|
||||
end
|
||||
end
|
||||
xml["pic"].spPr do
|
||||
xml["a"].xfrm do
|
||||
xml["a"].off(x: "0", y: "0")
|
||||
xml["a"].ext(cx: image.width_emu.to_s, cy: image.height_emu.to_s)
|
||||
end
|
||||
xml["a"].prstGeom(prst: "rect") do
|
||||
xml["a"].avLst
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def render_table(xml, table)
|
||||
xml["w"].tbl do
|
||||
xml["w"].tblPr do
|
||||
|
||||
Reference in New Issue
Block a user