From 092c8f7732858d378f81dd2ff1f1fe16d10746ab Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 26 Feb 2017 23:40:09 +0100 Subject: ImageSize: export lengthToDim, new function scaleDimension. --- src/Text/Pandoc/ImageSize.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/ImageSize.hs b/src/Text/Pandoc/ImageSize.hs index b698535ce..5cede7083 100644 --- a/src/Text/Pandoc/ImageSize.hs +++ b/src/Text/Pandoc/ImageSize.hs @@ -38,6 +38,8 @@ module Text.Pandoc.ImageSize ( ImageType(..) , Dimension(..) , Direction(..) , dimension + , lengthToDim + , scaleDimension , inInch , inPixel , inPoints @@ -78,6 +80,7 @@ data Dimension = Pixel Integer | Centimeter Double | Inch Double | Percent Double + instance Show Dimension where show (Pixel a) = show a ++ "px" show (Centimeter a) = showFl a ++ "cm" @@ -202,6 +205,15 @@ numUnit s = Just n -> Just (n, unit) Nothing -> Nothing +-- | Scale a dimension by a factor. +scaleDimension :: Double -> Dimension -> Dimension +scaleDimension factor dim = + case dim of + Pixel x -> Pixel (round $ factor * fromIntegral x) + Centimeter x -> Centimeter (factor * x) + Inch x -> Inch (factor * x) + Percent x -> Percent (factor * x) + -- | Read a Dimension from an Attr attribute. -- `dimension Width attr` might return `Just (Pixel 3)` or for example `Just (Centimeter 2.0)`, etc. dimension :: Direction -> Attr -> Maybe Dimension -- cgit v1.2.3