diff options
| author | John MacFarlane <[email protected]> | 2025-07-29 10:30:44 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-07-29 10:30:44 -0700 |
| commit | ce6ef5cad0e9d05986aff4fe6ee00fa99b69ea9d (patch) | |
| tree | 87e4dafdb65db9d99d672b1266cc2fb40ee0a0b1 | |
| parent | 39a2fd43082a95a4fba5b0aa75411698df0ef22e (diff) | |
ImageSize: Add Point and Pica as constructors of ImageSize.
[API change]
This will prevent unnecessary conversion of units.
Closes #8957.
| -rw-r--r-- | src/Text/Pandoc/ImageSize.hs | 18 | ||||
| -rw-r--r-- | test/command/8957.md | 7 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/Text/Pandoc/ImageSize.hs b/src/Text/Pandoc/ImageSize.hs index b957b49bd..55b0db63c 100644 --- a/src/Text/Pandoc/ImageSize.hs +++ b/src/Text/Pandoc/ImageSize.hs @@ -72,6 +72,8 @@ data Dimension = Pixel Integer | Centimeter Double | Millimeter Double | Inch Double + | Point Double + | Pica Double | Percent Double | Em Double deriving Eq @@ -81,6 +83,8 @@ instance Show Dimension where show (Centimeter a) = T.unpack (showFl a) ++ "cm" show (Millimeter a) = T.unpack (showFl a) ++ "mm" show (Inch a) = T.unpack (showFl a) ++ "in" + show (Point a) = T.unpack (showFl a) ++ "pt" + show (Pica a) = T.unpack (showFl a) ++ "pc" show (Percent a) = show a ++ "%" show (Em a) = T.unpack (showFl a) ++ "em" @@ -203,6 +207,8 @@ inInch opts dim = (Centimeter a) -> a * 0.3937007874 (Millimeter a) -> a * 0.03937007874 (Inch a) -> a + (Point a) -> (a / 72) + (Pica a) -> (a / 6) (Percent _) -> 0 (Em a) -> a * (11/64) @@ -210,11 +216,7 @@ inPixel :: WriterOptions -> Dimension -> Integer inPixel opts dim = case dim of (Pixel a) -> a - (Centimeter a) -> floor $ dpi * a * 0.3937007874 :: Integer - (Millimeter a) -> floor $ dpi * a * 0.03937007874 :: Integer - (Inch a) -> floor $ dpi * a :: Integer - (Percent _) -> 0 - (Em a) -> floor $ dpi * a * (11/64) :: Integer + _ -> floor (dpi * inInch opts dim) where dpi = fromIntegral $ writerDpi opts @@ -244,6 +246,8 @@ scaleDimension factor dim = Centimeter x -> Centimeter (factor * x) Millimeter x -> Millimeter (factor * x) Inch x -> Inch (factor * x) + Point x -> Point (factor * x) + Pica x -> Pica (factor * x) Percent x -> Percent (factor * x) Em x -> Em (factor * x) @@ -267,8 +271,8 @@ lengthToDim s = numUnit s >>= uncurry toDim toDim a "%" = Just $ Percent a toDim a "px" = Just $ Pixel (floor a::Integer) toDim a "" = Just $ Pixel (floor a::Integer) - toDim a "pt" = Just $ Inch (a / 72) - toDim a "pc" = Just $ Inch (a / 6) + toDim a "pt" = Just $ Point a + toDim a "pc" = Just $ Pica a toDim a "em" = Just $ Em a toDim _ _ = Nothing diff --git a/test/command/8957.md b/test/command/8957.md new file mode 100644 index 000000000..66840f75b --- /dev/null +++ b/test/command/8957.md @@ -0,0 +1,7 @@ +``` +% pandoc -f latex -t html --wrap=none +{width="342pt" height="9pc"} +^D +<p><span>width="342pt" height="9pc"</span></p> + +``` |
