org-mode-ox-odt
org-mode-ox-odt copied to clipboard
Provide a means "overlay" the caption over an image
Provide a means "overlay" the caption over an image
Conventionally caption text as added as a text "apart" from the image. It would be useful to add caption as a "overlay" right over the image. Here is one such attempt. (Ofcourse I need to code it up in Lisp)
Zip file: alternative-way-to-caption.zip
My little experiments suggests that are multiple ways of going about it.
To get this
do this
#+odt_extra_images: images/org-mode-unicorn.png
#+odt_extra_styles: <draw:fill-image draw:name="org-mode-unicorn"
#+odt_extra_styles: xlink:actuate="onLoad"
#+odt_extra_styles: xlink:href="images/org-mode-unicorn.png"
#+odt_extra_styles: xlink:show="embed"
#+odt_extra_styles: xlink:type="simple" />
#+odt_extra_styles: <style:style style:name="MyImageFrame"
#+odt_extra_styles: style:family="graphic">
#+odt_extra_styles: <style:graphic-properties draw:fill="bitmap"
#+odt_extra_styles: draw:fill-color="#ffffff"
#+odt_extra_styles: draw:fill-image-height="100%"
#+odt_extra_styles: draw:fill-image-name="org-mode-unicorn"
#+odt_extra_styles: draw:fill-image-ref-point="top-left"
#+odt_extra_styles: draw:fill-image-width="100%"
#+odt_extra_styles: fo:min-height="7.77cm"
#+odt_extra_styles: style:horizontal-pos="center"
#+odt_extra_styles: style:horizontal-rel="paragraph"
#+odt_extra_styles: style:number-wrapped-paragraphs="no-limit"
#+odt_extra_styles: style:repeat="no-repeat"
#+odt_extra_styles: style:run-through="foreground"
#+odt_extra_styles: style:vertical-pos="top"
#+odt_extra_styles: style:vertical-rel="paragraph"
#+odt_extra_styles: style:wrap="run-through"
#+odt_extra_styles: style:writing-mode="lr-tb"
#+odt_extra_styles: svg:width="0.041cm"
#+odt_extra_styles: svg:x="0cm"
#+odt_extra_styles: svg:y="0cm"
#+odt_extra_styles: text:anchor-type="paragraph">
#+odt_extra_styles: <style:background-image style:position="top left"
#+odt_extra_styles: style:repeat="no-repeat"
#+odt_extra_styles: xlink:actuate="onLoad"
#+odt_extra_styles: xlink:href="images/org-mode-unicorn.png"
#+odt_extra_styles: xlink:type="simple" />
#+odt_extra_styles: </style:graphic-properties>
#+odt_extra_styles: </style:style>
#+odt_extra_styles: <style:style style:name="OrgCaptionText"
#+odt_extra_styles: style:parent-style-name="Text_20_body"
#+odt_extra_styles: style:family="paragraph">
#+odt_extra_styles: <style:paragraph-properties fo:margin-bottom="0.21cm"
#+odt_extra_styles: fo:margin-top="3cm"
#+odt_extra_styles: fo:text-align="end"
#+odt_extra_styles: style:justify-single-word="false" />
#+odt_extra_styles: <style:text-properties fo:color="#ff0000"
#+odt_extra_styles: fo:font-weight="bold" />
#+odt_extra_styles: </style:style>
#+ATTR_ODT: :style "MyImageFrame" :width 5 :height 5
#+begin_textbox
#+ATTR_ODT: :style "OrgCaptionText"
Org Mode Unicorn
#+end_textbox
Cc @QiangF
This is an issue I have created from this discussion Text on Image Disappears.
In that issue you don't want the caption text and image as separate items arranged relative to each other. But you want the text and image to lie one on top of the other. The LibreOffice way of coding up your requirement is to add a background(?) image to either a paragraph or frame.
Experiment with it and see if you run in to further issues with Org
or XML
markup.
I will be happy to incorporate your feedback when I flush this issue out as a feature. (I am still experimenting with LibreOffice and I have identified atleast one another way to "overlay" caption over text.
#+odt_extra_styles: <style:style style:name="OrgCaptionText" #+odt_extra_styles: style:parent-style-name="Text_20_body" #+odt_extra_styles: style:family="paragraph"> #+odt_extra_styles: <style:paragraph-properties fo:margin-bottom="0.21cm" #+odt_extra_styles: fo:margin-top="3cm" #+odt_extra_styles: fo:text-align="end" #+odt_extra_styles: style:justify-single-word="false" />
If you haven't already noticed, you adjust the fo:margin-top
and fo:text-align
props of OrgCaptionText
to adjust the position of caption on the image.
(Note that the image has to be in a subdir. In other words, use :image "images/org-mode-unicorn.png"
instead of :image "org-mode-unicorn.png"
. As a side note, fill images typically occur as part of #+odt_extra_images: ...
)
To get this
do this
#+odt_preferred_output_format: docx
#+odt_extra_styles: <style:style style:name="OrgCaptionText"
#+odt_extra_styles: style:parent-style-name="Text_20_body"
#+odt_extra_styles: style:family="paragraph">
#+odt_extra_styles: <style:paragraph-properties fo:margin-bottom="0.21cm"
#+odt_extra_styles: fo:margin-top="5cm"
#+odt_extra_styles: fo:text-align="end"
#+odt_extra_styles: style:justify-single-word="false" />
#+odt_extra_styles: <style:text-properties fo:color="#ff0000"
#+odt_extra_styles: fo:font-weight="bold" />
#+odt_extra_styles: </style:style>
#+ATTR_ODT: :height 7 :image "images/org-mode-unicorn.png"
#+begin_textbox
#+ATTR_ODT: :style "OrgCaptionText"
\\
\\
Org Mode Unicorn
#+end_textbox
When exported to docx
file via LibreOffice, the border around the frame disappears. This seems like a bug in LibreOffice.
https://github.com/kjambunathan/org-mode-ox-odt/commit/ae70b7b237e421b5fb338dbe5b1ed4b4b147296c
This commit produces invalid ODF document with following error
ODT Zip Dir is /tmp/odt-a69TbG/
Formatting LaTeX using mathml
Embedding /home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/images/org-mode-unicorn.png as Images/0001.png...
ox-odt: Content template file is /home/kjambunathan/src1/org-mode-ox-odt/etc/styles/OrgOdtContentTemplate.xml
Wrote /tmp/odt-a69TbG/content.xml
ox-odt: Styles file is /home/kjambunathan/src1/org-mode-ox-odt/etc/styles/OrgOdtStyles.xml
Wrote /tmp/odt-a69TbG/styles.xml
Wrote /tmp/odt-a69TbG/meta.xml
Wrote /tmp/odt-a69TbG/mimetype
Wrote /tmp/odt-a69TbG/META-INF/manifest.xml
Create OpenDocument file ‘textbox-with-image-fill.odt’...
Using schema /usr/local/share/emacs/29.0.50/etc/schema/OpenDocument-schema-v1.3+libreoffice.rnc
Running zip -mX0 textbox-with-image-fill.odt mimetype
Running zip -rmTq textbox-with-image-fill.odt .
Created /home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt
Validating file ‘/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt’ ...
Running java -jar /home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/odfvalidator-0.10.0-jar-with-dependencies.jar -v textbox-with-image-fill.odt
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt: Info: ODF version of root document: 1.2
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/META-INF/manifest.xml: Warning: The directory 'Images/' is not a sub-document and should not be listed in the 'META-INF/manifest.xml' file of ODF package 'file:///home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt'!
internal:/schema/odf1.2/OpenDocument-v1.2-os-manifest-schema.rng: Info: parsed.
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/META-INF/manifest.xml: Info: no errors, 1 warnings
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/mimetype: Info: no errors, no warnings
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt: Info: Media Type: application/vnd.oasis.opendocument.text
internal:/schema/odf1.2/OpenDocument-v1.2-os-schema.rng: Info: parsed.
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/meta.xml: Info: no errors, no warnings
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/styles.xml: Info: no errors, no warnings
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/content.xml[2030,128]: Error: tag name "draw:fill-image" is not allowed. Possible tag names are: <boolean-style>,<currency-style>,<date-style>,<list-style>,<number-style>,<page-layout>,<percentage-style>,<style>,<text-style>,<time-style>
ink:show="embed" xlink:type="simple" /
----^
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/content.xml[2040,30]: Error: attribute "draw:fill-image-name" has a bad value
>
----^
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt/content.xml: Info: 2 errors, no warnings
internal:/schema/odf1.2/OpenDocument-v1.2-os-dsig-schema.rng: Info: parsed.
/home/kjambunathan/src/org-mode-ox-odt/testing/examples/odt/textbox-with-image-fill/textbox-with-image-fill.odt: Info: 2 errors, 1 warnings
condition-case: OpenDocument export failed with error: ‘File ‘textbox-with-image-fill.odt’ is malformed’
Mark set [3 times]
Copied text until "tbox-with-image-fill.odt’ is malformed’
"
Updated test case: textbox-with-image-fill.zip
This is super cool. An inprovment will be support figure caption, now there is one more way to insert a figure with text overlay: by insert a textbox and use the figure as backgroud. Borrowed from the list table example, maybe make the syntax like:
#+caption: a figure
#+label: fig:1
#+attr_odt: :category "figure" :width 10 :image "images/org-mode-unicorn.png"
#+begin_textbox
#+ATTR_ODT: :style "OrgCaptionText"
\\
\\
Org Mode Unicorn
#+end_textbox
superb to see such improvement and I can't wait to put it into operation.