From 23d806644f07e1df35b946bfac63d877005df443 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 30 Jul 2014 14:49:57 -0700 Subject: RTF writer: Improved image embedding. Use calculated sizes. --- src/Text/Pandoc/Writers/RTF.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Text/Pandoc/Writers/RTF.hs b/src/Text/Pandoc/Writers/RTF.hs index 2994385dc..43405ce3c 100644 --- a/src/Text/Pandoc/Writers/RTF.hs +++ b/src/Text/Pandoc/Writers/RTF.hs @@ -40,6 +40,7 @@ import Data.Char ( ord, chr, isDigit ) import qualified Data.ByteString as B import qualified Data.Map as M import Text.Printf ( printf ) +import Text.Pandoc.ImageSize -- | Convert Image inlines into a raw RTF embedded image, read from a file, -- or a MediaBag, or the internet. @@ -55,7 +56,17 @@ rtfEmbedImage opts x@(Image _ (src,_)) = do "image/jpeg" -> "\\jpegblip" "image/png" -> "\\pngblip" _ -> error "Unknown file type" - let raw = "{\\pict" ++ filetype ++ " " ++ concat bytes ++ "}" + let sizeSpec = case imageSize imgdata of + Nothing -> "" + Just sz -> "\\picw" ++ show xpx ++ + "\\pich" ++ show ypx ++ + "\\picwgoal" ++ show (xpt * 20) + ++ "\\pichgoal" ++ show (ypt * 20) + -- twip = 1/1440in = 1/20pt + where (xpx, ypx) = sizeInPixels sz + (xpt, ypt) = sizeInPoints sz + let raw = "{\\pict" ++ filetype ++ sizeSpec ++ " " ++ + concat bytes ++ "}" return $ if B.null imgdata then x else RawInline (Format "rtf") raw -- cgit v1.2.3