@@ -40,7 +40,7 @@ import Codec.Archive.Zip
4040import Text.Pandoc.Options ( WriterOptions(..), WrapOption(..) )
4141import Text.Pandoc.Shared ( stringify, fetchItem', warn,
4242 getDefaultReferenceODT )
43−import Text.Pandoc.ImageSize ( imageSize, desiredSizeInPoints )
43+import Text.Pandoc.ImageSize
4444import Text.Pandoc.MIME ( getMimeType, extensionFromMimeType )
4545import Text.Pandoc.Definition
4646import Text.Pandoc.Walk
@@ -125,22 +125,36 @@ writeODT opts doc@(Pandoc meta _) = do
125125 $ addEntryToArchive metaEntry archive'
126126 return $ fromArchive archive''
127127
128+-- | transform both Image and Math elements
128129transformPicMath :: WriterOptions -> IORef [Entry] -> Inline -> IO Inline
129−transformPicMath opts entriesRef (Image attr lab (src,t)) = do
130+transformPicMath opts entriesRef (Image attr@(id', cls, _) lab (src,t)) = do
130131 res <- fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
131132 case res of
132133 Left (_ :: E.SomeException) -> do
133134 warn $ "Could not find image `" ++ src ++ "', skipping..."
134135 return $ Emph lab
135136 Right (img, mbMimeType) -> do
136− (w,h) <- case imageSize img of
137− Right size -> return $
138− desiredSizeInPoints opts attr size
139− Left msg -> do
140− warn $ "Could not determine image size in `" ++
141− src ++ "': " ++ msg
142− return (0,0)
143− let tit' = show w ++ "x" ++ show h
137+ (ptX, ptY) <- case imageSize img of
138+ Right s -> return $ sizeInPoints s
139+ Left msg -> do
140+ warn $ "Could not determine image size in `" ++
141+ src ++ "': " ++ msg
142+ return (100, 100)
143+ let dims =
144+ case (getDim Width, getDim Height) of
145+ (Just w, Just h) -> [("width", show w), ("height", show h)]
146+ (Just w@(Percent _), Nothing) -> [("width", show w), ("style:rel-height", "scale")]
147+ (Nothing, Just h@(Percent _)) -> [("style:rel-width", "scale"), ("height", show h)]
148+ (Just w@(Inch i), Nothing) -> [("width", show w), ("height", show (i / ratio) ++ "in")]
149+ (Nothing, Just h@(Inch i)) -> [("width", show (i * ratio) ++ "in"), ("height", show h)]
150+ _ -> [("width", show ptX ++ "pt"), ("height", show ptY ++ "pt")]
151+ where
152+ ratio = ptX / ptY
153+ getDim dir = case (dimension dir attr) of
154+ Just (Percent i) -> Just $ Percent i
155+ Just dim -> Just $ Inch $ inInch opts dim
156+ Nothing -> Nothing
157+ let newattr = (id', cls, dims)
144158 entries <- readIORef entriesRef
145159 let extension = fromMaybe (takeExtension $ takeWhile (/='?') src)
146160 (mbMimeType >>= extensionFromMimeType)
@@ -149,9 +163,7 @@ transformPicMath opts entriesRef (Image attr lab (src,t)) = do
149163 epochtime <- floor `fmap` getPOSIXTime
150164 let entry = toEntry newsrc epochtime $ toLazy img
151165 modifyIORef entriesRef (entry:)
152− let fig | "fig:" `isPrefixOf` t = "fig:"
153− | otherwise = ""
154− return $ Image attr lab (newsrc, fig++tit')
166+ return $ Image newattr lab (newsrc, t)
155167transformPicMath _ entriesRef (Math t math) = do
156168 entries <- readIORef entriesRef
157169 let dt = if t == InlineMath then DisplayInline else DisplayBlock