aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-26 23:40:09 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-26 23:40:09 +0100
commit092c8f7732858d378f81dd2ff1f1fe16d10746ab (patch)
treedc40382b643e10bb930ccdba0300db4e95303514 /src/Text
parent377c27befedd8f9e54975296a71bf4c954399d2d (diff)
downloadpandoc-092c8f7732858d378f81dd2ff1f1fe16d10746ab.tar.gz
ImageSize: export lengthToDim, new function scaleDimension.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/ImageSize.hs12
1 files changed, 12 insertions, 0 deletions
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