aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/Text/Pandoc/Writers/ODT.hs9
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs4
2 files changed, 10 insertions, 3 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
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
index 1153aab6a..a0317511a 100644
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -404,11 +404,11 @@ inlineToOpenDocument o ils
return nn
-- a title of the form "120x140" will be interpreted as image
--- size in pixels.
+-- size in points.
attrsFromTitle :: String -> [(String,String)]
attrsFromTitle s = if null xs || null ys
then []
- else [("svg:x",xs),("svg:y",ys)]
+ else [("svg:width",xs ++ "pt"),("svg:height",ys ++ "pt")]
where (xs,rest) = span isDigit s
ys = case rest of
('x':zs) | all isDigit zs -> zs