@@ -38,6 +38,8 @@ module Text.Pandoc.ImageSize ( ImageType(..)
3838 , Dimension(..)
3939 , Direction(..)
4040 , dimension
41+ , lengthToDim
42+ , scaleDimension
4143 , inInch
4244 , inPixel
4345 , inPoints
@@ -78,6 +80,7 @@ data Dimension = Pixel Integer
7880 | Centimeter Double
7981 | Inch Double
8082 | Percent Double
83+
8184instance Show Dimension where
8285 show (Pixel a) = show a ++ "px"
8386 show (Centimeter a) = showFl a ++ "cm"
@@ -202,6 +205,15 @@ numUnit s =
202205 Just n -> Just (n, unit)
203206 Nothing -> Nothing
204207
208+-- | Scale a dimension by a factor.
209+scaleDimension :: Double -> Dimension -> Dimension
210+scaleDimension factor dim =
211+ case dim of
212+ Pixel x -> Pixel (round $ factor * fromIntegral x)
213+ Centimeter x -> Centimeter (factor * x)
214+ Inch x -> Inch (factor * x)
215+ Percent x -> Percent (factor * x)
216+
205217-- | Read a Dimension from an Attr attribute.
206218-- `dimension Width attr` might return `Just (Pixel 3)` or for example `Just (Centimeter 2.0)`, etc.
207219dimension :: Direction -> Attr -> Maybe Dimension