From 6fe243abbdd3394c8c5fa50db107e4dcc87c6a63 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 9 May 2015 21:32:31 -0700 Subject: ImageSize: make imageSize return an Either, not a Maybe. This will give us better error reporting options. This is part of a fix for #1834. --- src/Text/Pandoc/Writers/Docx.hs | 6 ++++-- src/Text/Pandoc/Writers/ODT.hs | 6 ++++-- src/Text/Pandoc/Writers/RTF.hs | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 3638114d9..cacf5102f 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -1120,8 +1120,10 @@ inlineToOpenXML opts (Image alt (src, tit)) = do inlinesToOpenXML opts alt Right (img, mt) -> do ident <- ("rId"++) `fmap` getUniqueId - let size = imageSize img - let (xpt,ypt) = maybe (120,120) sizeInPoints size + (xpt,ypt) <- case imageSize img of + Right size -> return $ sizeInPoints size + Left msg -> do liftIO (warn msg) + return (120,120) -- 12700 emu = 1 pt let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700) (pageWidth * 12700) let cNvPicPr = mknode "pic:cNvPicPr" [] $ diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs index 96928c4f6..33d9ec9d2 100644 --- a/src/Text/Pandoc/Writers/ODT.hs +++ b/src/Text/Pandoc/Writers/ODT.hs @@ -134,8 +134,10 @@ transformPicMath opts entriesRef (Image lab (src,t)) = do warn $ "Could not find image `" ++ src ++ "', skipping..." return $ Emph lab Right (img, mbMimeType) -> do - let size = imageSize img - let (w,h) = fromMaybe (0,0) $ sizeInPoints `fmap` size + (w,h) <- case imageSize img of + Right size -> return $ sizeInPoints size + Left msg -> do warn msg + return (0,0) let tit' = show w ++ "x" ++ show h entries <- readIORef entriesRef let extension = fromMaybe (takeExtension $ takeWhile (/='?') src) diff --git a/src/Text/Pandoc/Writers/RTF.hs b/src/Text/Pandoc/Writers/RTF.hs index 01bc4b782..588506f34 100644 --- a/src/Text/Pandoc/Writers/RTF.hs +++ b/src/Text/Pandoc/Writers/RTF.hs @@ -56,9 +56,9 @@ rtfEmbedImage opts x@(Image _ (src,_)) = do "image/jpeg" -> "\\jpegblip" "image/png" -> "\\pngblip" _ -> error "Unknown file type" - let sizeSpec = case imageSize imgdata of - Nothing -> "" - Just sz -> "\\picw" ++ show xpx ++ + sizeSpec <- case imageSize imgdata of + Left msg -> warn msg >> return "" + Right sz -> return $ "\\picw" ++ show xpx ++ "\\pich" ++ show ypx ++ "\\picwgoal" ++ show (xpt * 20) ++ "\\pichgoal" ++ show (ypt * 20) -- cgit v1.2.3