aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/ODT.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-01-14 12:38:14 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-01-14 12:38:14 -0800
commit28a043fe44bacb3e0e24b9f4e9402480d50d665a (patch)
tree6130c9de48ee3e8ed0f2640e77bf10c2a6cf9f1d /src/Text/Pandoc/Writers/ODT.hs
parent0d1740ea08c8e802d17687f670a6dc26d51ca427 (diff)
downloadpandoc-28a043fe44bacb3e0e24b9f4e9402480d50d665a.tar.gz
ODT writer now sizes images appropriately.
OpenDocument writer: a title like "123x467" is interpreted as size in *points*. ODT writer: while adding images to the archive, computes their sizes and inserts a title attribute with the size before calling opendocument writer. Size is computed as follows: size in points = size in pixels * 96 / 72
Diffstat (limited to 'src/Text/Pandoc/Writers/ODT.hs')
-rw-r--r--src/Text/Pandoc/Writers/ODT.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs
index f8030965c..f5030e6d8 100644
--- a/src/Text/Pandoc/Writers/ODT.hs
+++ b/src/Text/Pandoc/Writers/ODT.hs
@@ -37,6 +37,7 @@ import Codec.Archive.Zip
import System.Time
import Paths_pandoc ( getDataFileName )
import Text.Pandoc.Shared ( WriterOptions(..) )
+import Text.Pandoc.ImageSize ( readImageSize )
import Text.Pandoc.MIME ( getMimeType )
import Text.Pandoc.Definition
import Text.Pandoc.Generic
@@ -102,11 +103,17 @@ writeODT mbRefOdt opts doc = do
transformPic :: FilePath -> IORef [Entry] -> Inline -> IO Inline
transformPic sourceDir entriesRef (Image lab (src,tit)) = do
let src' = unEscapeString src
+ mbSize <- readImageSize src'
+ let pxToPoints px = px * 72 `div` 96
+ let tit' = case mbSize of
+ Just (w,h) -> show (pxToPoints w) ++ "x" ++
+ show (pxToPoints h)
+ Nothing -> tit
entries <- readIORef entriesRef
let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src'
catch (readEntry [] (sourceDir </> src') >>= \entry ->
modifyIORef entriesRef (entry{ eRelativePath = newsrc } :) >>
- return (Image lab (newsrc, tit)))
+ return (Image lab (newsrc, tit')))
(\_ -> return (Emph lab))
transformPic _ _ x = return x