module Graphics.Rendering.MiniTypeset.Common where
data BasicStyle
= Regular
| Bold
| Italic
| BoldItalic
deriving (Eq,Ord,Show)
newtype Height
= Height Int
deriving (Eq,Ord,Show)
data Col
= Col !Double !Double !Double
deriving (Eq,Ord,Show)
colToTriple :: Col -> (Double,Double,Double)
colToTriple (Col r g b) = (r,g,b)
tripleToCol :: (Double,Double,Double) -> Col
tripleToCol (r,g,b) = Col r g b
black, white, red, green, blue, yellow, cyan, magenta :: Col
black = Col 0 0 0
white = Col 1 1 1
red = Col 1 0 0
green = Col 0 1 0
blue = Col 0 0 1
yellow = Col 1 1 0
cyan = Col 0 1 1
magenta = Col 1 0 1
data HAlign
= AlignLeft
| AlignRight
deriving (Eq,Ord,Show)
data VAlign
= AlignBottom
| AlignTop
deriving (Eq,Ord,Show)
data Pos
= Pos !Double !Double
deriving (Eq,Ord,Show)
posToPair :: Pos -> (Double,Double)
posToPair (Pos x y) = (x,y)
instance Num Pos where
(+) (Pos x y) (Pos u v) = Pos (x+u) (y+v)
(-) (Pos x y) (Pos u v) = Pos (x-u) (y-v)
negate (Pos x y) = Pos (negate x) (negate y)
(*) = error "Pos/Num/*: does not make sense"
fromInteger n = if n == 0
then Pos 0 0
else error "Pos/Num/fromInteger: does not make sense"
abs (Pos x y) = Pos (abs x) (abs y)
signum = error "Pos/Num/signum: does not make sense"
class Translate a where
translate :: Pos -> a -> a
instance Translate Pos where
translate = (+)
data Bracket
= Paren
| Square
| Brace
| Angle
| Ceil
| Floor
| Top
| Bottom
| AngleQuote
| FrenchQuote
deriving (Eq,Ord,Show)
bracketChars :: Bracket -> (Char,Char)
bracketChars b = case b of
Paren -> ( '(' , ')' )
Square -> ( '[' , ']' )
Brace -> ( '{' , '}' )
Angle -> ( '\x2329' , '\x232a' )
Ceil -> ( '\x2308' , '\x2309' )
Floor -> ( '\x230a' , '\x230b' )
Top -> ( '\x231c' , '\x231d' )
Bottom -> ( '\x231e' , '\x231f' )
AngleQuote -> ( '\x2039' , '\x203a' )
FrenchQuote -> ( '\x00ab' , '\x00bb' )
mapAccumM :: Monad m => (a -> b -> m (a, c)) -> a -> [b] -> m (a, [c])
mapAccumM f x0 ys = go x0 ys where
go !x (y:ys) = do { (x',z) <- f x y ; (x'',zs) <- go x' ys ; return (x'',z:zs) }
go !x [] = return (x,[])