From e28e1038c405439eb5dd656ab9b0adb9ae706272 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Thu, 17 Nov 2011 23:58:27 +0530 Subject: [PATCH] org-odt.el: Rescale a large images so that it fits in text area * contrib/lisp/org-odt.el (org-export-odt-max-image-size): New variable. (org-odt-image-size-from-file): Honor above variable. Ivars Finvers says - One minor issue that I came across in using the ODT exporter relates to the size of embedded images. I often need to include plots of simulation results in my documents. These plots can be larger than a normal page, which causes problems in the text flow. In LaTeX, I've grown used to being able to automatically rescale a plot to match the maximum text width of the document. It would be useful to have such a feature for the ODT exporter. --- contrib/lisp/org-odt.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contrib/lisp/org-odt.el b/contrib/lisp/org-odt.el index 65c50ea02..81abf5d4b 100644 --- a/contrib/lisp/org-odt.el +++ b/contrib/lisp/org-odt.el @@ -1623,6 +1623,12 @@ ATTR is a string of other attributes of the a element." "Hardcoded image dimensions one for each of the anchor methods.") +;; A4 page size is 21.0 by 29.7 cms +;; The default page settings has 2cm margin on each of the sides. So +;; the effective text area is 17.0 by 25.7 cm +(defvar org-export-odt-max-image-size '(17.0 . 20.0) + "Limiting dimensions for an embedded image.") + (defun org-odt-do-image-size (probe-method file &optional dpi anchor-type) (setq dpi (or dpi org-export-odt-pixels-per-inch)) (setq anchor-type (or anchor-type "paragraph")) @@ -1671,6 +1677,14 @@ ATTR is a string of other attributes of the a element." (user-width (setq height (* user-width (/ height width)) width user-width)) (t (ignore))) + ;; ensure that an embedded image fits comfortably within a page + (let ((max-width (car org-export-odt-max-image-size)) + (max-height (cdr org-export-odt-max-image-size))) + (when (or (> width max-width) (> height max-height)) + (let* ((scale1 (/ max-width width)) + (scale2 (/ max-height height)) + (scale (min scale1 scale2))) + (setq width (* scale width) height (* scale height))))) (cons width height))) (defvar org-odt-entity-labels-alist nil -- 2.11.4.GIT