From b3484b533476aa6d6263775b7a79670bc9eec70e Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 21 Dec 2016 02:21:54 +0530 Subject: Initial commit --- ksh-biometry.el | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ksh-biometry.el (limited to 'ksh-biometry.el') diff --git a/ksh-biometry.el b/ksh-biometry.el new file mode 100644 index 0000000..0e5f1d7 --- /dev/null +++ b/ksh-biometry.el @@ -0,0 +1,41 @@ +(defun draw-biometry (param-name param param-age percentile) + (let ((temp-script-file (make-temp-script + (format "%s %s" param-name param) + param-age (string-to-number percentile)))) + (message "Drawing %s..." temp-script-file) + (shell-command + (format "asy -f pdf -o %s %s" (file-name-directory temp-script-file) temp-script-file)) + (delete-file temp-script-file) + (format "%s.pdf" temp-script-file))) + +(defun make-temp-script (param param-age percentile) + (let ((temp-script-file (make-temp-file "biometry"))) + (with-temp-file temp-script-file + (insert "include \"biometry\";\n") + (insert (format + "draw_biometry(\"%s\", \"%s\", %d);" + param param-age percentile))) + temp-script-file)) + +(defun insert-biometry (readings) + (princ + (format "[[%s]]\n" + (crop-pdf + (combine-pdfs + (mapcar (lambda (reading) + (apply 'draw-biometry + (mapcar 'get-field reading))) readings)))))) + +(defun combine-pdfs (pdfs) + (let ((temp-combination (make-temp-file "pdfjam" nil ".pdf"))) + (apply 'call-process "pdfjam" nil nil nil + "--nup" "4x1" + "--outfile" temp-combination pdfs) + (mapc 'delete-file pdfs) + temp-combination)) + +(defun crop-pdf (pdf) + (message "Cropping %s..." pdf) + (let ((output-pdf (format "%s-crop.pdf" (file-name-sans-extension pdf)))) + (shell-command (format "pdfcrop %s %s" pdf output-pdf)) + (delete-file pdf) output-pdf)) -- cgit v1.2.3