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.
This commit is contained in:
Jambunathan K 2011-11-17 23:58:27 +05:30
parent 78f7382879
commit e28e1038c4
1 changed files with 14 additions and 0 deletions

View File

@ -1623,6 +1623,12 @@ ATTR is a string of other attributes of the a element."
"Hardcoded image dimensions one for each of the anchor "Hardcoded image dimensions one for each of the anchor
methods.") 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) (defun org-odt-do-image-size (probe-method file &optional dpi anchor-type)
(setq dpi (or dpi org-export-odt-pixels-per-inch)) (setq dpi (or dpi org-export-odt-pixels-per-inch))
(setq anchor-type (or anchor-type "paragraph")) (setq anchor-type (or anchor-type "paragraph"))
@ -1671,6 +1677,14 @@ ATTR is a string of other attributes of the a element."
(user-width (user-width
(setq height (* user-width (/ height width)) width user-width)) (setq height (* user-width (/ height width)) width user-width))
(t (ignore))) (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))) (cons width height)))
(defvar org-odt-entity-labels-alist nil (defvar org-odt-entity-labels-alist nil