git.iko.soy/typeable/pandoc
on master help sign in
imageSize interface change
3f6b50emb21
src/Text/Pandoc/ImageSize.hs+5−6
@@ -115,13 +115,13 @@ imageType img = case B.take 4 img of
115 -- B.groupBy openingTag matches first "<svg" or "<html" but not "<!--"
115 -- B.groupBy openingTag matches first "<svg" or "<html" but not "<!--"
116 openingTag x y = x == '<' && y /= '!'
116 openingTag x y = x == '<' && y /= '!'
117
117
118−imageSize :: ByteString -> Either String ImageSize
118+imageSize :: WriterOptions -> ByteString -> Either String ImageSize
119−imageSize img =
119+imageSize opts img =
120 case imageType img of
120 case imageType img of
121 Just Png -> mbToEither "could not determine PNG size" $ pngSize img
121 Just Png -> mbToEither "could not determine PNG size" $ pngSize img
122 Just Gif -> mbToEither "could not determine GIF size" $ gifSize img
122 Just Gif -> mbToEither "could not determine GIF size" $ gifSize img
123 Just Jpeg -> jpegSize img
123 Just Jpeg -> jpegSize img
124− Just Svg -> mbToEither "could not determine SVG size" $ svgSize img
124+ Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
125 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
125 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
126 Just Pdf -> Left "could not determine PDF size" -- TODO
126 Just Pdf -> Left "could not determine PDF size" -- TODO
127 Nothing -> Left "could not determine image type"
127 Nothing -> Left "could not determine image type"
@@ -286,10 +286,9 @@ gifSize img = do
286 }
286 }
287 _ -> Nothing -- "GIF parse error"
287 _ -> Nothing -- "GIF parse error"
288
288
289−svgSize :: ByteString -> Maybe ImageSize
289+svgSize :: WriterOptions -> ByteString -> Maybe ImageSize
290−svgSize img = do
290+svgSize opts img = do
291 doc <- Xml.parseXMLDoc $ UTF8.toString img
291 doc <- Xml.parseXMLDoc $ UTF8.toString img
292− let opts = def --TODO: use proper opts instead of def, which simply contains dpi=72
293 let dpi = fromIntegral $ writerDpi opts
292 let dpi = fromIntegral $ writerDpi opts
294 let dirToInt dir = do
293 let dirToInt dir = do
295 dim <- Xml.findAttrBy (== Xml.QName dir Nothing Nothing) doc >>= lengthToDim
294 dim <- Xml.findAttrBy (== Xml.QName dir Nothing Nothing) doc >>= lengthToDim
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -1184,7 +1184,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
1184 Right (img, mt) -> do
1184 Right (img, mt) -> do
1185 ident <- ("rId"++) `fmap` ((lift . lift) getUniqueId)
1185 ident <- ("rId"++) `fmap` ((lift . lift) getUniqueId)
1186 let (xpt,ypt) = desiredSizeInPoints opts attr
1186 let (xpt,ypt) = desiredSizeInPoints opts attr
1187− (either (const def) id (imageSize img))
1187+ (either (const def) id (imageSize opts img))
1188 -- 12700 emu = 1 pt
1188 -- 12700 emu = 1 pt
1189 let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700) (pageWidth * 12700)
1189 let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700) (pageWidth * 12700)
1190 let cNvPicPr = mknode "pic:cNvPicPr" [] $
1190 let cNvPicPr = mknode "pic:cNvPicPr" [] $
src/Text/Pandoc/Writers/ICML.hs+1−1
@@ -546,7 +546,7 @@ imageICML opts style attr (src, _) = do
546 report $ CouldNotFetchResource src ""
546 report $ CouldNotFetchResource src ""
547 return def
547 return def
548 Right (img, _) -> do
548 Right (img, _) -> do
549− case imageSize img of
549+ case imageSize opts img of
550 Right size -> return size
550 Right size -> return size
551 Left msg -> do
551 Left msg -> do
552 report $ CouldNotDetermineImageSize src msg
552 report $ CouldNotDetermineImageSize src msg
src/Text/Pandoc/Writers/ODT.hs+1−1
@@ -153,7 +153,7 @@ transformPicMath opts (Image attr@(id', cls, _) lab (src,t)) = do
153 report $ CouldNotFetchResource src ""
153 report $ CouldNotFetchResource src ""
154 return $ Emph lab
154 return $ Emph lab
155 Right (img, mbMimeType) -> do
155 Right (img, mbMimeType) -> do
156− (ptX, ptY) <- case imageSize img of
156+ (ptX, ptY) <- case imageSize opts img of
157 Right s -> return $ sizeInPoints s
157 Right s -> return $ sizeInPoints s
158 Left msg -> do
158 Left msg -> do
159 report $ CouldNotDetermineImageSize src msg
159 report $ CouldNotDetermineImageSize src msg
src/Text/Pandoc/Writers/RTF.hs+1−1
@@ -63,7 +63,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
63 "image/jpeg" -> return "\\jpegblip"
63 "image/jpeg" -> return "\\jpegblip"
64 "image/png" -> return "\\pngblip"
64 "image/png" -> return "\\pngblip"
65 _ -> throwError $ PandocSomeError "Unknown file type"
65 _ -> throwError $ PandocSomeError "Unknown file type"
66− sizeSpec <- case imageSize imgdata of
66+ sizeSpec <- case imageSize opts imgdata of
67 Left msg -> do
67 Left msg -> do
68 report $ CouldNotDetermineImageSize src msg
68 report $ CouldNotDetermineImageSize src msg
69 return ""
69 return ""