Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image height in % does not retain image aspect ratio for odt output #3239

Closed
kwijk opened this issue Nov 17, 2016 · 3 comments · Fixed by #3478
Closed

image height in % does not retain image aspect ratio for odt output #3239

kwijk opened this issue Nov 17, 2016 · 3 comments · Fixed by #3478

Comments

@kwijk
Copy link

kwijk commented Nov 17, 2016

Reproducibility

When an image link is included in markdown input one can give the image width and image height. Providing only the image width should keep the image aspect ratio in the output dcument. It does when the unit is 'cm' or 'px'. It does not when unit is '%'.

  • add to a markdown document an inline reference to an image
    [A Screenshot](screenshot.png){width=15%}
  • call pandoc myfile.md -o myfile.odt

==> The image in the odt file has its image scaled ok horizontaly, but it does not retain its ascpect ratio. Using {width=15cm} does work as expected.

expected behaviour

When image width is given explicitly as in {width=x%} without giving the image height I expect the aspect ratio to be kept the same.

version

pandoc 1.18

@jgm
Copy link
Owner

jgm commented Nov 18, 2016

Here's the relevant code:

       let dims =
             case (getDim Width, getDim Height) of
               (Just w, Just h)              -> [("width", show w), ("height", show h)]
               (Just w@(Percent _), Nothing) -> [("width", show w), ("style:rel-height", "scale")]
               (Nothing, Just h@(Percent _)) -> [("style:rel-width", "scale"), ("height", show h)]
               (Just w@(Inch i), Nothing)    -> [("width", show w), ("height", show (i / ratio) ++ "in")]
               (Nothing, Just h@(Inch i))    -> [("width", show (i * ratio) ++ "in"), ("height", show h)]
               _                             -> [("width", show ptX ++ "pt"), ("height", show ptY ++ "pt")]
             where
               ratio = ptX / ptY
               getDim dir = case (dimension dir attr) of
                              Just (Percent i) -> Just $ Percent i
                              Just dim         -> Just $ Inch $ inInch opts dim
                              Nothing          -> Nothing

As you can see, when a percent is used, we use style:rel-height="scale". That sounds as if it should do what you want, but apparently not?

@bruvellu
Copy link

bruvellu commented Feb 28, 2017

Hi, I just ran into this issue (Pandoc 1.19.2.1, LibreOffice 5.3.0.3). Using % does not maintain image aspect ratio for ODT. Markdown input:

![Figure legend.](Fig.png){ width=100% }

ODT output:

<draw:frame draw:name="img1" svg:width="100.0%" style:rel-height="scale">

Somehow this is not enough for ODT. It seems that it needs both svg:width and svg:height to draw the figure properly. Removing rel-height and adding an explicit height % renders the image correctly (no surprise there, though):

<draw:frame draw:name="img1" svg:width="100.0%" svg:height="40.0%">

I couldn't figure out if this is a ODT bug or feature, but perhaps a workaround would be Pandoc calculating the ratio percentage on its own, if % is used.

@mb21
Copy link
Collaborator

mb21 commented Feb 28, 2017

Indeed, this seems to be a known bug in LibreOffice, reported in 2012. I'll take a look...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants