diff options
author | Jambunathan K <kjambunathan@gmail.com> | 2011-09-07 22:42:33 +0530 |
---|---|---|
committer | Jambunathan K <kjambunathan@gmail.com> | 2011-09-08 18:56:08 +0530 |
commit | 86409e89c0a872388ecc18e2095b641445ada1c3 (patch) | |
tree | a2949e12de44db92461e985be9700d1b856e2d25 | |
parent | 2178b635455fbeacfe447a94fb2bbf95ccc9622e (diff) | |
download | org-mode-86409e89c0a872388ecc18e2095b641445ada1c3.tar.gz |
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.
-rw-r--r-- | contrib/lisp/org-odt.el | 97 | ||||
-rw-r--r-- | contrib/odt/styles/OrgOdtAutomaticStyles.xml | 82 | ||||
-rw-r--r-- | 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 33ad426..f41a537 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 - '("<draw:frame draw:style-name=\"%s\" - text:anchor-type=\"paragraph\" - style:rel-width=\"100%%\" - draw:z-index=\"0\">" . "</draw:frame>"))) + 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 - '("<draw:text-box fo:min-height=\"%dcm\">" . "</draw:text-box>") - text 0) style))) + '("<draw:frame draw:style-name=\"%s\"%s>" . "</draw:frame>") + text style frame-attrs))) + +(defun org-odt-format-textbox (text style &optional width height) + (org-odt-format-frame + (org-odt-format-tags + '("<draw:text-box %s>" . "</draw:text-box>") + 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 - '("<draw:frame draw:style-name=\"%s\" - text:anchor-type=\"%s\" - draw:z-index=\"%d\" %s>" . "</draw:frame>"))) - (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 - '("<draw:text-box fo:min-height=\"%dcm\">" . "</draw:text-box>") - (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 c4116c0..d3f73bb 100644 --- a/contrib/odt/styles/OrgOdtAutomaticStyles.xml +++ b/contrib/odt/styles/OrgOdtAutomaticStyles.xml @@ -72,86 +72,4 @@ <style:style style:name="OrgTblCellTBLR" style:family="table-cell"> <style:table-cell-properties style:vertical-align="middle" fo:padding="0.159cm" fo:border-top="0.035cm solid #808080" fo:border-bottom="0.035cm solid #808080" fo:border-left="0.035cm solid #808080" fo:border-right="0.035cm solid #808080"/> </style:style> - <style:style style:name="OrgFrame" - style:family="graphic" - style:parent-style-name="Frame"> - <style:graphic-properties fo:margin-left="0cm" - fo:margin-right="0cm" - fo:margin-top="0cm" - fo:margin-bottom="0cm" - style:run-through="foreground" - style:wrap="none" - style:vertical-pos="top" - style:vertical-rel="paragraph" - style:horizontal-pos="center" - style:horizontal-rel="paragraph" - fo:padding="0cm" fo:border="none" - style:shadow="none"/> - </style:style> - - <style:style style:name="OrgGraphicsParagraphContent" - style:family="graphic" - style:parent-style-name="Graphics"> - <style:graphic-properties fo:margin-left="0cm" - fo:margin-right="0cm" - fo:margin-top="0cm" - fo:margin-bottom="0cm" - style:run-through="foreground" - style:wrap="none" - style:vertical-pos="from-top" - style:vertical-rel="paragraph-content" - style:horizontal-pos="from-left" - style:horizontal-rel="paragraph-content" - fo:padding="0cm" - fo:border="none" - style:shadow="none" - style:mirror="none" - fo:clip="rect(0cm, 0cm, 0cm, 0cm)" - draw:luminance="0%" - draw:contrast="0%" - draw:red="0%" - draw:green="0%" - draw:blue="0%" - draw:gamma="100%" - draw:color-inversion="false" - draw:image-opacity="100%" - draw:color-mode="standard"/> - </style:style> - - <style:style style:name="OrgGraphicsBaseline" - style:family="graphic" - style:parent-style-name="Graphics"> - <style:graphic-properties style:vertical-pos="top" - style:vertical-rel="baseline" - style:mirror="none" - fo:clip="rect(0cm, 0cm, 0cm, 0cm)" - draw:luminance="0%" - draw:contrast="0%" - draw:red="0%" - draw:green="0%" - draw:blue="0%" - draw:gamma="100%" - draw:color-inversion="false" - draw:image-opacity="100%" - draw:color-mode="standard"/> - </style:style> - - <style:style style:name="OrgGraphicsParagraph" - style:family="graphic" - style:parent-style-name="Graphics"> - <style:graphic-properties style:horizontal-pos="center" - style:horizontal-rel="paragraph" - style:mirror="none" - fo:clip="rect(0cm, 0cm, 0cm, 0cm)" - draw:luminance="0%" - draw:contrast="0%" - draw:red="0%" - draw:green="0%" - draw:blue="0%" - draw:gamma="100%" - draw:color-inversion="false" - draw:image-opacity="100%" - draw:color-mode="standard"/> - </style:style> - </office:automatic-styles> diff --git a/contrib/odt/styles/OrgOdtStyles.xml b/contrib/odt/styles/OrgOdtStyles.xml index 0cdff5f..7f6f0ad 100644 --- a/contrib/odt/styles/OrgOdtStyles.xml +++ b/contrib/odt/styles/OrgOdtStyles.xml @@ -362,6 +362,30 @@ <style:graphic-properties text:anchor-type="paragraph" svg:x="0cm" svg:y="0cm" fo:margin-left="0.201cm" fo:margin-right="0.201cm" fo:margin-top="0.201cm" fo:margin-bottom="0.201cm" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" style:wrap-contour="false" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="center" style:horizontal-rel="paragraph-content" fo:padding="0.15cm" fo:border="0.002cm solid #000000"/> </style:style> + <!-- Simple Images --> + <style:style style:name="OrgSimpleGraphics" style:family="graphic" style:parent-style-name="Graphics"> + <style:graphic-properties text:anchor-type="paragraph" style:wrap="none" style:vertical-pos="top" style:vertical-rel="paragraph" style:horizontal-pos="center" style:horizontal-rel="paragraph"/> + </style:style> + + <!-- Captioned Images --> + <style:style style:name="OrgCaptionedGraphics" style:family="graphic" style:parent-style-name="Graphics"> + <style:graphic-properties style:rel-width="100%" text:anchor-type="paragraph" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0cm" fo:margin-bottom="0cm" style:run-through="foreground" style:wrap="none" style:vertical-pos="from-top" style:vertical-rel="paragraph-content" style:horizontal-pos="from-left" style:horizontal-rel="paragraph-content" fo:padding="0cm" fo:border="none" style:shadow="none"/> + </style:style> + + <style:style style:name="OrgCaptionFrame" style:family="graphic" style:parent-style-name="Frame"> + <style:graphic-properties text:anchor-type="paragraph" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0cm" fo:margin-bottom="0cm" style:wrap="none" style:vertical-pos="top" style:vertical-rel="paragraph" style:horizontal-pos="center" style:horizontal-rel="paragraph" fo:padding="0cm" fo:border="none"/> + </style:style> + + <!-- Inlined Images --> + <style:style style:name="OrgInlineGraphics" style:family="graphic" style:parent-style-name="Graphics"> + <style:graphic-properties text:anchor-type="as-char" style:vertical-pos="top" style:vertical-rel="baseline" style:horizontal-pos="center" style:horizontal-rel="paragraph"/> + </style:style> + + <!-- Inline Formula --> + <style:style style:name="OrgInlineFormula" style:family="graphic" style:parent-style-name="Formula"> + <style:graphic-properties text:anchor-type="as-char" fo:margin-left="0.201cm" fo:margin-right="0.201cm" style:vertical-pos="middle" style:vertical-rel="text"/> + </style:style> + <!-- Inline Tasks --> <style:style style:name="OrgInlineTaskHeading" style:family="paragraph" style:parent-style-name="Caption" style:next-style-name="Text_20_body"> <style:text-properties style:font-name="Arial1" fo:font-style="normal" fo:font-weight="bold"/> |