diff options
| author | John MacFarlane <[email protected]> | 2023-07-26 09:49:37 -0600 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-07-26 09:49:37 -0600 |
| commit | ecb59e1cdef1e32d0dfc71412ef72a3affc016f4 (patch) | |
| tree | bb58b277148e60ab98a6a8c2c961c240954c0053 | |
| parent | d7c43fda32b3cedc362196d0fc4d09aa4770841a (diff) | |
SelfContained: fix calculation of svg width and height.
We were computing width and height from viewBox incorrectly.
See #8969.
| -rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 6 | ||||
| -rw-r--r-- | test/command/8948.md | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index 428a18f0f..9e07f8850 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -213,11 +213,11 @@ combineSvgAttrs svgAttrs imgAttrs = case (mbViewBox, mbHeight, mbWidth) of (Nothing, Just h, Just w) -> -- calculate viewBox combinedAttrs ++ [("viewBox", T.unwords ["0", "0", tshow w, tshow h])] - (Just (llx,lly,urx,ury), Nothing, Nothing) -> -- calculate width, height + (Just (_minx,_miny,width,height), Nothing, Nothing) -> combinedAttrs ++ - [ ("width", tshow (floor urx - floor llx :: Int)) | + [ ("width", tshow (floor width :: Int)) | isNothing (lookup "width" combinedAttrs) ] ++ - [ ("height", tshow (floor ury - floor lly :: Int)) | + [ ("height", tshow (floor height :: Int)) | isNothing (lookup "height" combinedAttrs) ] _ -> combinedAttrs where diff --git a/test/command/8948.md b/test/command/8948.md index 233f9e585..abd35bc4c 100644 --- a/test/command/8948.md +++ b/test/command/8948.md @@ -3,7 +3,7 @@   ^D -<p><svg alt="minimal"><use href="#svg_7868854ffb8f30209cd0" /></svg> <svg id="svg_7868854ffb8f30209cd0" alt="minimal" viewBox="-.333 -.333 480 150" style="background-color:#ffffff00" xml:space="preserve" width="481" height="151"> +<p><svg alt="minimal"><use href="#svg_7868854ffb8f30209cd0" /></svg> <svg id="svg_7868854ffb8f30209cd0" alt="minimal" viewBox="-.333 -.333 480 150" style="background-color:#ffffff00" xml:space="preserve" width="480" height="150"> <path d="M 0 35.5 L 6.5 22.5 L 16 37 L 23 24 L 34.8 43.7 L 42.5 30 L 50.3 47 L 59.7 27.7 L 69 47 L 85 17.7 L 98.3 39 L 113 9.7 L 127.7 42.3 L 136.3 23.7 L 147 44.3 L 158.3 20.3 L 170.3 40.3 L 177.7 25.7 L 189.7 43 L 199.7 21 L 207.7 35 L 219 11 L 233 37 L 240.3 23.7 L 251 43 L 263 18.3 L 272.7 33.3 L 283 10 L 295 32.3 L 301.3 23 L 311.7 37 L 323.7 7.7 L 339.3 39 L 346.3 25.7 L 356.3 42.3 L 369.7 15 L 376.3 25.7 L 384 9 L 393 28.3 L 400.3 19 L 411.7 38.3 L 421 21 L 434.3 43 L 445 25 L 453 36.3 L 464.3 18.3 L 476.2 40.3 L 480 33.5 L 480 215 L 0 215 L 0 35.5 Z" fill="#175720"></path> </svg></p> ``` @@ -13,7 +13,7 @@  {#foo} ^D -<p><svg alt="minimal"><use href="#foo" /></svg> <svg id="foo" alt="minimal" viewBox="-.333 -.333 480 150" style="background-color:#ffffff00" xml:space="preserve" width="481" height="151"> +<p><svg alt="minimal"><use href="#foo" /></svg> <svg id="foo" alt="minimal" viewBox="-.333 -.333 480 150" style="background-color:#ffffff00" xml:space="preserve" width="480" height="150"> <path d="M 0 35.5 L 6.5 22.5 L 16 37 L 23 24 L 34.8 43.7 L 42.5 30 L 50.3 47 L 59.7 27.7 L 69 47 L 85 17.7 L 98.3 39 L 113 9.7 L 127.7 42.3 L 136.3 23.7 L 147 44.3 L 158.3 20.3 L 170.3 40.3 L 177.7 25.7 L 189.7 43 L 199.7 21 L 207.7 35 L 219 11 L 233 37 L 240.3 23.7 L 251 43 L 263 18.3 L 272.7 33.3 L 283 10 L 295 32.3 L 301.3 23 L 311.7 37 L 323.7 7.7 L 339.3 39 L 346.3 25.7 L 356.3 42.3 L 369.7 15 L 376.3 25.7 L 384 9 L 393 28.3 L 400.3 19 L 411.7 38.3 L 421 21 L 434.3 43 L 445 25 L 453 36.3 L 464.3 18.3 L 476.2 40.3 L 480 33.5 L 480 215 L 0 215 L 0 35.5 Z" fill="#175720"></path> </svg></p> ``` |
