module Graphics.PS.Paper where
import Graphics.PS.Unit
data Units = MM | PT deriving (Eq,Show)
data Paper = Paper {units :: Units
,width :: Int
,height :: Int}
deriving (Eq,Show)
paper_size_pt :: Paper -> (Int,Int)
paper_size_pt (Paper unit w h) =
case unit of
MM -> (mm_pt_int w,mm_pt_int h)
PT -> (w,h)
data BBox = BBox {llx :: Int
,lly :: Int
,urx :: Int
,ury :: Int
}
| HRBBox {llx :: Int
,lly :: Int
,urx :: Int
,ury :: Int
,hrllx :: Double
,hrlly :: Double
,hrurx :: Double
,hrury :: Double
}
deriving (Eq,Show)
landscape :: Paper -> Paper
landscape (Paper u w h) = Paper u h w
proportion :: Paper -> Double
proportion (Paper _ w h) = i_to_d h / i_to_d w
inset_margin :: Paper -> Paper -> (Units,Int,Int)
inset_margin (Paper u1 w1 h1) (Paper u2 w2 h2) =
if u1 /= u2
then error "inset_margin: unequal units"
else (u2,(w2 w1) `div` 2,(h2 h1) `div` 2)
bbox_sum :: BBox -> BBox -> BBox
bbox_sum p q =
case (p,q) of
(BBox x0 y0 x1 y1,BBox x2 y2 x3 y3) ->
BBox (min x0 x2) (min y0 y2) (max x1 x3) (max y1 y3)
_ -> error "bbox_sum: HR not handled"
bbox_mm_to_pt :: BBox -> BBox
bbox_mm_to_pt bb =
case bb of
BBox x y x' y' ->
BBox (mm_pt_int x) (mm_pt_int y) (mm_pt_int x') (mm_pt_int y')
HRBBox x y x' y' hx hy hx' hy' ->
HRBBox (mm_pt_int x) (mm_pt_int y) (mm_pt_int x') (mm_pt_int y')
(mm_pt hx) (mm_pt hy) (mm_pt hx') (mm_pt hy')
divRound :: Int -> Int -> Int
divRound x y =
let x' = (fromIntegral x)::Double
y' = (fromIntegral y)::Double
in round (x' / y')