summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJambunathan K <kjambunathan@gmail.com>2011-11-17 23:58:27 +0530
committerJambunathan K <kjambunathan@gmail.com>2011-11-17 23:58:42 +0530
commite28e1038c405439eb5dd656ab9b0adb9ae706272 (patch)
treeb6b11922ed71e889020744c53b46f542ac7f1009
parent78f7382879c0c5218d252687a2330cd8d4b92a43 (diff)
downloadorg-mode-e28e1038c405439eb5dd656ab9b0adb9ae706272.tar.gz
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 <ifinvers@shaw.ca> 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.
-rw-r--r--contrib/lisp/org-odt.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/contrib/lisp/org-odt.el b/contrib/lisp/org-odt.el
index 65c50ea..81abf5d 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