module Graphics.Rendering.Cairo.Internal.Utilities where
import Graphics.Rendering.Cairo.Types
import Foreign
import Foreign.C
import Data.Char (ord, chr)
statusToString :: Status -> IO (String)
statusToString a1 =
let {a1' = cFromEnum a1} in
statusToString'_ a1' >>= \res ->
peekCString res >>= \res' ->
return (res')
version :: Int
version =
let {res = version'_} in
let {res' = cIntConv res} in
(res')
versionString :: String
versionString =
unsafePerformIO $
let {res = versionString'_} in
peekCString res >>= \res' ->
return (res')
withUTFString :: String -> (CString -> IO a) -> IO a
withUTFString hsStr = withCAString (toUTF hsStr)
where
toUTF :: String -> String
toUTF [] = []
toUTF (x:xs) | ord x<=0x007F = x:toUTF xs
| ord x<=0x07FF = chr (0xC0 .|. ((ord x `shift` (6)) .&. 0x1F)):
chr (0x80 .|. (ord x .&. 0x3F)):
toUTF xs
| otherwise = chr (0xE0 .|. ((ord x `shift` (12)) .&. 0x0F)):
chr (0x80 .|. ((ord x `shift` (6)) .&. 0x3F)):
chr (0x80 .|. (ord x .&. 0x3F)):
toUTF xs
foreign import ccall safe "cairo_status_to_string"
statusToString'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall safe "cairo_version"
version'_ :: CInt
foreign import ccall safe "cairo_version_string"
versionString'_ :: (Ptr CChar)