git.iko.soy/typeable/pandoc
on master help sign in
RTF writer: Improved image embedding.

Use calculated sizes.

commit23d806644f07e1df35b946bfac63d877005df443 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 30 Jul 2014, 14:49 (12 years ago) parente365af9
1 file changed+12−1
src/Text/Pandoc/Writers/RTF.hs+12−1
src/Text/Pandoc/Writers/RTF.hs+12−1
@@ -40,6 +40,7 @@ import Data.Char ( ord, chr, isDigit )
4040import qualified Data.ByteString as B
4141import qualified Data.Map as M
4242import Text.Printf ( printf )
43+import Text.Pandoc.ImageSize
4344
4445-- | Convert Image inlines into a raw RTF embedded image, read from a file,
4546-- or a MediaBag, or the internet.
@@ -55,7 +56,17 @@ rtfEmbedImage opts x@(Image _ (src,_)) = do
5556 "image/jpeg" -> "\\jpegblip"
5657 "image/png" -> "\\pngblip"
5758 _ -> error "Unknown file type"
58− let raw = "{\\pict" ++ filetype ++ " " ++ concat bytes ++ "}"
59+ let sizeSpec = case imageSize imgdata of
60+ Nothing -> ""
61+ Just sz -> "\\picw" ++ show xpx ++
62+ "\\pich" ++ show ypx ++
63+ "\\picwgoal" ++ show (xpt * 20)
64+ ++ "\\pichgoal" ++ show (ypt * 20)
65+ -- twip = 1/1440in = 1/20pt
66+ where (xpx, ypx) = sizeInPixels sz
67+ (xpt, ypt) = sizeInPoints sz
68+ let raw = "{\\pict" ++ filetype ++ sizeSpec ++ " " ++
69+ concat bytes ++ "}"
5970 return $ if B.null imgdata
6071 then x
6172 else RawInline (Format "rtf") raw