git.iko.soy/typeable/pandoc
on master help sign in
EMF Image size support (#4375)
bb7681aAndrew Pritchard
src/Text/Pandoc/ImageSize.hs+37−1
@@ -71,7 +71,7 @@ import Data.Maybe (fromMaybe)
71-- quick and dirty functions to get image sizes
71-- quick and dirty functions to get image sizes
72-- algorithms borrowed from wwwis.pl
72-- algorithms borrowed from wwwis.pl
73
73
74−data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps deriving Show
74+data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps | Emf deriving Show
75data Direction = Width | Height
75data Direction = Width | Height
76instance Show Direction where
76instance Show Direction where
77 show Width = "width"
77 show Width = "width"
@@ -125,6 +125,9 @@ imageType img = case B.take 4 img of
125 "%!PS"
125 "%!PS"
126 | B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
126 | B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
127 -> return Eps
127 -> return Eps
128+ "\x01\x00\x00\x00"
129+ | B.take 4 (B.drop 40 img) == " EMF"
130+ -> return Emf
128 _ -> mzero
131 _ -> mzero
129
132
130findSvgTag :: ByteString -> Bool
133findSvgTag :: ByteString -> Bool
@@ -139,6 +142,7 @@ imageSize opts img =
139 Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
142 Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
140 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
143 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
141 Just Pdf -> mbToEither "could not determine PDF size" $ pdfSize img
144 Just Pdf -> mbToEither "could not determine PDF size" $ pdfSize img
145+ Just Emf -> mbToEither "could not determine EMF size" $ emfSize img
142 Nothing -> Left "could not determine image type"
146 Nothing -> Left "could not determine image type"
143 where mbToEither msg Nothing = Left msg
147 where mbToEither msg Nothing = Left msg
144 mbToEither _ (Just x) = Right x
148 mbToEither _ (Just x) = Right x
@@ -357,6 +361,38 @@ svgSize opts img = do
357 , dpiX = dpi
361 , dpiX = dpi
358 , dpiY = dpi
362 , dpiY = dpi
359 }
363 }
364+
365+emfSize :: ByteString -> Maybe ImageSize
366+emfSize img =
367+ let
368+ parseheader = runGetOrFail $ do
369+ skip 0x18 -- 0x00
370+ frameL <- getWord32le -- 0x18 measured in 1/100 of a millimetre
371+ frameT <- getWord32le -- 0x1C
372+ frameR <- getWord32le -- 0x20
373+ frameB <- getWord32le -- 0x24
374+ skip 0x20 -- 0x28
375+ deviceX <- getWord32le -- 0x48 pixels of reference device
376+ deviceY <- getWord32le -- 0x4C
377+ mmX <- getWord32le -- 0x50 real mm of reference device (always 320*240?)
378+ mmY <- getWord32le -- 0x58
379+ -- end of header
380+ let
381+ w = (deviceX * (frameR - frameL)) `quot` (mmX * 100)
382+ h = (deviceY * (frameB - frameT)) `quot` (mmY * 100)
383+ dpiW = (deviceX * 254) `quot` (mmX * 10)
384+ dpiH = (deviceY * 254) `quot` (mmY * 10)
385+ return $ ImageSize
386+ { pxX = fromIntegral w
387+ , pxY = fromIntegral h
388+ , dpiX = fromIntegral dpiW
389+ , dpiY = fromIntegral dpiH
390+ }
391+ in
392+ case parseheader . BL.fromStrict $ img of
393+ Left _ -> Nothing
394+ Right (_, _, size) -> Just size
395+
360
396
361jpegSize :: ByteString -> Either String ImageSize
397jpegSize :: ByteString -> Either String ImageSize
362jpegSize img =
398jpegSize img =
src/Text/Pandoc/Writers/Docx.hs+1
@@ -1339,6 +1339,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
1339 Just Pdf -> ".pdf"
1339 Just Pdf -> ".pdf"
1340 Just Eps -> ".eps"
1340 Just Eps -> ".eps"
1341 Just Svg -> ".svg"
1341 Just Svg -> ".svg"
1342+ Just Emf -> ".emf"
1342 Nothing -> ""
1343 Nothing -> ""
1343 if null imgext
1344 if null imgext
1344 then -- without an extension there is no rule for content type
1345 then -- without an extension there is no rule for content type
src/Text/Pandoc/Writers/Powerpoint/Output.hs+1
@@ -475,6 +475,7 @@ registerMedia fp caption = do
475 Just Pdf -> Just ".pdf"
475 Just Pdf -> Just ".pdf"
476 Just Eps -> Just ".eps"
476 Just Eps -> Just ".eps"
477 Just Svg -> Just ".svg"
477 Just Svg -> Just ".svg"
478+ Just Emf -> Just ".emf"
478 Nothing -> Nothing
479 Nothing -> Nothing
479
480
480 let newGlobalId = case M.lookup fp globalIds of
481 let newGlobalId = case M.lookup fp globalIds of