Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/stencil/model/content_types.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,21 @@
:stencil.model/path (.getName cts)}))


(defn- extra-file-overrides [model]
(for [section [[(-> model :main)]
(-> model :main :headers+footers)
(-> model :main :stencil.model/slide-layouts)]
part section
:when (:stencil.model/path part)
[_ rel] (-> part :relations :parsed)
:when (:stencil.model/mime-type rel)]
[(str "/" (fs/unix-path (fs/unroll (file (fs/parent-file (file (:stencil.model/path part)))
(:stencil.model/target rel)))))
(:stencil.model/mime-type rel)]))

(defn with-content-types [model]
(let [parsed (-> model :content-types :parsed)
parsed (update parsed ::override into (extra-file-overrides model))
tree {:tag tag-types
:attrs {:xmlns xmlns}
:content (concat (for [[k v] (::default parsed)]
Expand Down
3 changes: 3 additions & 0 deletions src/stencil/ooxml.clj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
"http://schemas.microsoft.com/office/powerpoint/2012/main" "p15"
})

;; extension list, used for SVG image reference inside a blip
(def ext-lst :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fdrawingml%2F2006%2Fmain/extLst)

;; drawing, binary large image or picture
(def blip :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fdrawingml%2F2006%2Fmain/blip)
;; hyperlinks
Expand Down
7 changes: 6 additions & 1 deletion src/stencil/postprocess/images.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
new-val (-> data .relation)]
(assert new-val)
(log/debug "Replacing image relation {} by {}" current-rel new-val)
(assoc-in img-node [:attrs attr-key] new-val)))
(-> img-node
(assoc-in [:attrs attr-key] new-val)
; If placeholder has an SVG graphic, remove so the replacement raster image is used directly:
(update :content #(remove (comp #{ooxml/ext-lst} :tag) %)))))


(defn- replace-image [marker-loc]
(if-let [img-loc (->> (zip/remove marker-loc)
Expand Down Expand Up @@ -83,6 +87,7 @@
{:new-id new-rel
:stencil.model/type relations/rel-type-image
:stencil.model/target (image-path new-rel mime-type)
:stencil.model/mime-type mime-type
:writer (bytes->writer bytes)}))

;; replaces the nearest image with the content
Expand Down
Loading