Page 1 of 1

Writing .odt file; image with no declared height

PostPosted: Tue Nov 03, 2020 8:57 pm
by alexjordan
I'm new to this forum and uncertain if this is the right subforum to post to. Please advise me if I should take this elsewhere.

I am a contributor to a project that converts PreTeXt XML to various output formats. I'm currently working on an XSLT conversion to .odt, and I have hit an obstacle. I'm hoping to find insight here for how to proceed.

The issue is that PreTeXt XML does not declare heights for image files. A width is always declared (or inferred to be 100%) and it is assumed that the image file knows its own aspect ratio, and that the renderer will use the defined width and the image file to infer a height for display. I'm not having success translating to an .odt file that opens and shows images. I'm creating content with constructions like:

Code: Select all   Expand viewCollapse view
<text:p>
  <draw:frame  svg:width="some width"  text:anchor-type="as-char">
    <draw:image  xlink:href="the correct path"  xlink:type="simple"  xlink:show="embed"  xlink:actuate="onLoad"  draw:mime-type="the correct type"/>
  </draw:image>
</text:p>


and I do have a style applied to the p and to the frame. But in OpenOffice and LibreOffice, the output looks like a value of 0 is being used for svg:height and I see an almost completely flat line where an image should be. MS Word appears to be using a 1 inch default here, so the images are all visible but their aspect ratio is distorted.

Is it possible to build a .odt file with images, not declare an image height, and still expect the word processors to display the images with their native aspect ratio? (If not, the conversion process from PreTeXt to .odt will need to analyze image files, which will be a significant additional stage to conversion.)

Re: Writing .odt file; image with no declared height

PostPosted: Wed Nov 04, 2020 11:56 pm
by JeJe
You can get/set the dimensions when in the odt file

https://www.openoffice.org/api/docs/com ... ActualSize

In basic for the first drawing in a document you would put this
Code: Select all   Expand viewCollapse view
thiscomponent.drawpage.getbyindex(0).actualsize