From 86409e89c0a872388ecc18e2095b641445ada1c3 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Wed, 7 Sep 2011 22:42:33 +0530 Subject: [PATCH] org-odt.el: Sanitize formatting of Images * contrib/lisp/org-odt.el (org-odt-format-frame): New. (org-odt-format-textbox): Use the above function. (org-export-odt-do-format-image): Use the above two functions. Use the new custom styles for the Frame and Graphics elements. (org-odt-image-attrs-from-size): Remove this. * contrib/odt/styles/OrgOdtAutomaticStyles.xml: Removed all Frame and Graphics entries. * contrib/odt/styles/OrgOdtStyles.xml: Added following custom styles - OrgSimpleGraphics, OrgCaptionedGraphics, OrgCaptionFrame, OrgInlineGraphics and OrgInlineFormula. --- contrib/lisp/org-odt.el | 97 ++++++++++++---------------- contrib/odt/styles/OrgOdtAutomaticStyles.xml | 82 ----------------------- contrib/odt/styles/OrgOdtStyles.xml | 24 +++++++ 3 files changed, 64 insertions(+), 139 deletions(-) diff --git a/contrib/lisp/org-odt.el b/contrib/lisp/org-odt.el index 33ad426c4..f41a53722 100644 --- a/contrib/lisp/org-odt.el +++ b/contrib/lisp/org-odt.el @@ -1200,19 +1200,26 @@ MAY-INLINE-P allows inlining it as an image." (plist-get attr-plist :height) (plist-get attr-plist :scale) nil embed-as))) (org-export-odt-do-format-image - embed-as caption attr label size href)))) - -(defun org-odt-format-textbox (text style) - (let ((draw-frame-pair - '("" . ""))) + embed-as caption attr label (car size) (cdr size) href)))) + +(defun org-odt-format-frame (text style &optional + width height extra anchor-type) + (let ((frame-attrs + (concat + (if width (format " svg:width=\"%0.2fcm\"" width) "") + (if height (format " svg:height=\"%0.2fcm\"" height) "") + extra + (format " text:anchor-type=\"%s\"" (or anchor-type "paragraph"))))) (org-odt-format-tags - draw-frame-pair - (org-odt-format-tags - '("" . "") - text 0) style))) + '("" . "") + text style frame-attrs))) + +(defun org-odt-format-textbox (text style &optional width height) + (org-odt-format-frame + (org-odt-format-tags + '("" . "") + text (format " fo:min-height=\"%0.2fcm\"" (or height 0.5))) + style width nil (and (not width) " style:rel-width=\"100%\""))) (defun org-odt-format-inlinetask (heading content &optional todo priority tags) @@ -1226,47 +1233,29 @@ MAY-INLINE-P allows inlining it as an image." content) "OrgInlineTaskFrame"))) (defun org-export-odt-do-format-image (embed-as caption attr label - size href) + width height href) "Create image tag with source and attributes." (save-match-data - (let ((width (car size)) (height (cdr size)) - (draw-frame-pair - '("" . ""))) - (cond - ((and (not caption) (not label)) - (let (style-name anchor-type) - (cond - ((eq embed-as 'paragraph) - (setq style-name "OrgGraphicsParagraph" anchor-type "paragraph")) - ((eq embed-as 'character) - (setq style-name "OrgGraphicsBaseline" anchor-type "as-char"))) - (org-odt-format-tags - draw-frame-pair href style-name anchor-type 0 - (org-odt-image-attrs-from-size width height)))) - - (t - (concat - ;; (when par-open (org-odt-close-par)) - (org-odt-format-tags - draw-frame-pair - (org-odt-format-tags - '("" . "") - (org-odt-format-stylized-paragraph - 'illustration - (concat - (let ((extra " style:rel-width=\"100%\" style:rel-height=\"scale\"")) - (org-odt-format-tags - draw-frame-pair href "OrgGraphicsParagraphContent" "paragraph" 2 - (concat (org-odt-image-attrs-from-size width height) extra))) - (org-odt-format-entity-caption label caption))) - height) - "OrgFrame" "paragraph" 1 - (org-odt-image-attrs-from-size width)) - - ;; (when par-open (org-odt-open-par)) - )))))) + (cond + ((and (not caption) (not label)) + (let (style-name anchor-type) + (cond + ((eq embed-as 'paragraph) + (setq style-name "OrgSimpleGraphics" anchor-type "paragraph")) + ((eq embed-as 'character) + (setq style-name "OrgInlineGraphics" anchor-type "as-char"))) + (org-odt-format-frame href style-name width height nil anchor-type))) + (t + (concat + (org-odt-format-textbox + (org-odt-format-stylized-paragraph + 'illustration + (concat + (let ((extra " style:rel-width=\"100%\" style:rel-height=\"scale\"")) + (org-odt-format-frame + href "OrgCaptionedGraphics" width height extra "paragraph")) + (org-odt-format-entity-caption label caption))) + "OrgCaptionFrame" width height)))))) (defvar org-odt-embedded-images-count 0) (defun org-odt-copy-image-file (path) @@ -1291,12 +1280,6 @@ MAY-INLINE-P allows inlining it as an image." (org-odt-create-manifest-file-entry media-type target-file)) target-file)) -(defun org-odt-image-attrs-from-size (&optional width height) - (concat - (when width (format "svg:width=\"%0.2fcm\"" width)) - " " - (when height (format "svg:height=\"%0.2fcm\"" height)))) - (defvar org-export-odt-image-size-probe-method '(emacs imagemagick force) "Ordered list of methods by for determining size of an embedded diff --git a/contrib/odt/styles/OrgOdtAutomaticStyles.xml b/contrib/odt/styles/OrgOdtAutomaticStyles.xml index c4116c0f3..d3f73bb83 100644 --- a/contrib/odt/styles/OrgOdtAutomaticStyles.xml +++ b/contrib/odt/styles/OrgOdtAutomaticStyles.xml @@ -72,86 +72,4 @@ - - - - - - - - - - - - - - - - diff --git a/contrib/odt/styles/OrgOdtStyles.xml b/contrib/odt/styles/OrgOdtStyles.xml index 0cdff5f7c..7f6f0ad61 100644 --- a/contrib/odt/styles/OrgOdtStyles.xml +++ b/contrib/odt/styles/OrgOdtStyles.xml @@ -362,6 +362,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + -- 2.11.4.GIT