This commit is contained in:
@@ -110,9 +110,9 @@
|
||||
(comment
|
||||
(let [out (ByteArrayOutputStream.)]
|
||||
(p/shell {:out (tee-output-stream
|
||||
out
|
||||
(l/log-stream :info "blah"))}
|
||||
"echo" "hello" "worms")))
|
||||
out (l/log-stream :info "blah"))}
|
||||
"echo" "hello\n" "worms")
|
||||
(.toString out)))
|
||||
|
||||
(defn invoke [opts & cmd]
|
||||
(l/info (str/join " " (cons "$" cmd)))
|
||||
@@ -122,7 +122,4 @@
|
||||
opts)
|
||||
cmd)
|
||||
bin (first cmd)]
|
||||
(l/infof "%s (stdout): %s" bin (:out r))
|
||||
(l/infof "%s (stderr): %s" bin (:err r))
|
||||
(l/infof "%s exited with status %s" bin (str (:exit r)))
|
||||
r))
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
(:require [babashka.process :as p]
|
||||
[net.deertopia.doerg.common :as common]
|
||||
[clj-cbor.core :as cbor]
|
||||
[clojure.java.io :as io]))
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as l])
|
||||
(:import (java.io ByteArrayOutputStream)))
|
||||
|
||||
;;; XeLaTeX
|
||||
|
||||
@@ -13,15 +16,41 @@
|
||||
(def ^:private tightpage-regexp
|
||||
#"^Preview: Tightpage (-?[0-9]+)\s*(-?[0-9]+)\s*(-?[0-9]+)\s*(-?[0-9]+)")
|
||||
|
||||
(def ^:private preview-end-regexp
|
||||
#"(?:^Preview: Tightpage.*$)?\n! Preview: Snippet \d+ ended.\((\d+)\+(\d+)x(\d+)\)")
|
||||
|
||||
(defn- invoke [extra-opts & args]
|
||||
(let [namespace (or (::ns extra-opts)
|
||||
(first args))
|
||||
out-stream (common/tee-output-stream
|
||||
(ByteArrayOutputStream.)
|
||||
(l/log-stream :info (str namespace "/out")))
|
||||
err-stream (common/tee-output-stream
|
||||
(ByteArrayOutputStream.)
|
||||
(l/log-stream :info (str namespace "/err")))
|
||||
opts (merge extra-opts
|
||||
{:out out-stream :err err-stream :continue true
|
||||
:shutdown p/destroy-tree
|
||||
:pre-start-fn (fn [{:keys [cmd]}]
|
||||
(l/infof "$ %s"
|
||||
(str/join " " cmd)))
|
||||
:exit-fn (fn [{:keys [cmd exit]}]
|
||||
(l/infof "%s exited w/ status %d"
|
||||
(first cmd) exit))})
|
||||
r (apply p/shell opts args)
|
||||
out (.toString out-stream)]
|
||||
(-> r
|
||||
(assoc ::out out))))
|
||||
|
||||
(defn- invoke-xelatex [& {:keys [file output-dir]}]
|
||||
(let [{:keys [out]} (common/invoke
|
||||
{:dir output-dir}
|
||||
"xelatex" "-no-pdf" "-interaction" "nonstopmode"
|
||||
"-output-directory" output-dir file)
|
||||
(let [{out ::out} (invoke
|
||||
{:dir output-dir}
|
||||
"xelatex" "-no-pdf" "-interaction" "nonstopmode"
|
||||
"-output-directory" output-dir file)
|
||||
[tp1 tp2 tp3 tp4] (->> (re-find tightpage-regexp out)
|
||||
(drop 1)
|
||||
(map parse-long))]
|
||||
(->> (re-find-all preview-end-regexp out)
|
||||
(->> (re-seq preview-end-regexp out)
|
||||
(map #(let [[d1 d2 d3] (map parse-long (drop 1 %))
|
||||
depth (/ (- d2 tp2)
|
||||
scale-divisor
|
||||
@@ -29,11 +58,11 @@
|
||||
{:depth depth
|
||||
:height (+ depth
|
||||
(/ (+ d1 tp4)
|
||||
tex-scale-divisor
|
||||
tex-fontsize))
|
||||
scale-divisor
|
||||
font-size))
|
||||
:width (/ (+ d3 tp3 (- tp2))
|
||||
tex-scale-divisor
|
||||
tex-fontsize)})))))
|
||||
scale-divisor
|
||||
font-size)})))))
|
||||
|
||||
|
||||
;;; Temml
|
||||
|
||||
Reference in New Issue
Block a user