"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Text/Pandoc/ImageSize.hs" between
pandoc-2.14.0.3.tar.gz and pandoc-2.14.1.tar.gz

About: Pandoc converts files from one markup format into another.

ImageSize.hs  (pandoc-2.14.0.3):ImageSize.hs  (pandoc-2.14.1)
skipping to change at line 60 skipping to change at line 60
import qualified Data.Text.Encoding as TE import qualified Data.Text.Encoding as TE
import Control.Applicative import Control.Applicative
import qualified Data.Attoparsec.ByteString.Char8 as A import qualified Data.Attoparsec.ByteString.Char8 as A
import qualified Codec.Picture.Metadata as Metadata import qualified Codec.Picture.Metadata as Metadata
import qualified Codec.Picture.Metadata.Exif as Exif import qualified Codec.Picture.Metadata.Exif as Exif
import Codec.Picture (decodeImageWithMetadata) import Codec.Picture (decodeImageWithMetadata)
-- quick and dirty functions to get image sizes -- quick and dirty functions to get image sizes
-- algorithms borrowed from wwwis.pl -- algorithms borrowed from wwwis.pl
data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps | Emf deriving Show data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps | Emf | Tiff
deriving Show
data Direction = Width | Height data Direction = Width | Height
instance Show Direction where instance Show Direction where
show Width = "width" show Width = "width"
show Height = "height" show Height = "height"
data Dimension = Pixel Integer data Dimension = Pixel Integer
| Centimeter Double | Centimeter Double
| Millimeter Double | Millimeter Double
| Inch Double | Inch Double
| Percent Double | Percent Double
skipping to change at line 103 skipping to change at line 104
removeExtra0s :: T.Text -> T.Text removeExtra0s :: T.Text -> T.Text
removeExtra0s s = case T.dropWhileEnd (=='0') s of removeExtra0s s = case T.dropWhileEnd (=='0') s of
(T.unsnoc -> Just (xs, '.')) -> xs (T.unsnoc -> Just (xs, '.')) -> xs
xs -> xs xs -> xs
imageType :: ByteString -> Maybe ImageType imageType :: ByteString -> Maybe ImageType
imageType img = case B.take 4 img of imageType img = case B.take 4 img of
"\x89\x50\x4e\x47" -> return Png "\x89\x50\x4e\x47" -> return Png
"\x47\x49\x46\x38" -> return Gif "\x47\x49\x46\x38" -> return Gif
"\x49\x49\x2a\x00" -> return Tiff
"\x4D\x4D\x00\x2a" -> return Tiff
"\xff\xd8\xff\xe0" -> return Jpeg -- JFIF "\xff\xd8\xff\xe0" -> return Jpeg -- JFIF
"\xff\xd8\xff\xe1" -> return Jpeg -- Exif "\xff\xd8\xff\xe1" -> return Jpeg -- Exif
"%PDF" -> return Pdf "%PDF" -> return Pdf
"<svg" -> return Svg "<svg" -> return Svg
"<?xm" "<?xm"
| findSvgTag img | findSvgTag img
-> return Svg -> return Svg
"%!PS" "%!PS"
| B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF " | B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF "
-> return Eps -> return Eps
skipping to change at line 127 skipping to change at line 130
findSvgTag :: ByteString -> Bool findSvgTag :: ByteString -> Bool
findSvgTag img = "<svg" `B.isInfixOf` img || "<SVG" `B.isInfixOf` img findSvgTag img = "<svg" `B.isInfixOf` img || "<SVG" `B.isInfixOf` img
imageSize :: WriterOptions -> ByteString -> Either T.Text ImageSize imageSize :: WriterOptions -> ByteString -> Either T.Text ImageSize
imageSize opts img = checkDpi <$> imageSize opts img = checkDpi <$>
case imageType img of case imageType img of
Just Png -> getSize img Just Png -> getSize img
Just Gif -> getSize img Just Gif -> getSize img
Just Jpeg -> getSize img Just Jpeg -> getSize img
Just Tiff -> getSize img
Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
Just Eps -> mbToEither "could not determine EPS size" $ epsSize img Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
Just Pdf -> mbToEither "could not determine PDF size" $ pdfSize img Just Pdf -> mbToEither "could not determine PDF size" $ pdfSize img
Just Emf -> mbToEither "could not determine EMF size" $ emfSize img Just Emf -> mbToEither "could not determine EMF size" $ emfSize img
Nothing -> Left "could not determine image type" Nothing -> Left "could not determine image type"
where mbToEither msg Nothing = Left msg where mbToEither msg Nothing = Left msg
mbToEither _ (Just x) = Right x mbToEither _ (Just x) = Right x
-- see #6880, some defective JPEGs may encode dpi 0, so default to 72 -- see #6880, some defective JPEGs may encode dpi 0, so default to 72
-- if that value is 0 -- if that value is 0
checkDpi size = checkDpi size =
 End of changes. 3 change blocks. 
1 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)