{-# LANGUAGE  CApiFFI #-}
module OpenCascade.Font.BRepFont 
( BRepFont
, new
, fromPathAndSize
, initFromPathAndSize
, initFromNameAspectAndSize
, ascender
, descender
, lineSpacing
, pointSize
) where

import OpenCascade.Font.Types (BRepFont)
import Data.Acquire (Acquire, mkAcquire)
import Foreign.C
import Foreign.Ptr
import OpenCascade.Font.Internal.Destructors (deleteBRepFont)
import Data.Coerce
import OpenCascade.Internal.Bool (cBoolToBool)
import OpenCascade.Font.FontAspect (FontAspect)


foreign import capi unsafe "hs_Font_BRepFont.h hs_new_Font_BRepFont" rawNew :: IO (Ptr BRepFont)

new :: Acquire (Ptr BRepFont)
new :: Acquire (Ptr BRepFont)
new  = IO (Ptr BRepFont)
-> (Ptr BRepFont -> IO ()) -> Acquire (Ptr BRepFont)
forall a. IO a -> (a -> IO ()) -> Acquire a
mkAcquire IO (Ptr BRepFont)
rawNew Ptr BRepFont -> IO ()
deleteBRepFont

foreign import capi unsafe "hs_Font_BRepFont.h hs_new_Font_BRepFont_fromStringAndSize" rawFromPathAndSize :: CString -> CDouble -> IO (Ptr BRepFont)

fromPathAndSize :: FilePath -> Double -> Acquire (Ptr BRepFont)
fromPathAndSize :: FilePath -> Double -> Acquire (Ptr BRepFont)
fromPathAndSize FilePath
path Double
size = IO (Ptr BRepFont)
-> (Ptr BRepFont -> IO ()) -> Acquire (Ptr BRepFont)
forall a. IO a -> (a -> IO ()) -> Acquire a
mkAcquire (FilePath -> (CString -> IO (Ptr BRepFont)) -> IO (Ptr BRepFont)
forall a. FilePath -> (CString -> IO a) -> IO a
withCString FilePath
path ((CString -> IO (Ptr BRepFont)) -> IO (Ptr BRepFont))
-> (CString -> IO (Ptr BRepFont)) -> IO (Ptr BRepFont)
forall a b. (a -> b) -> a -> b
$ \CString
str -> CString -> CDouble -> IO (Ptr BRepFont)
rawFromPathAndSize CString
str (Double -> CDouble
forall a b. Coercible a b => a -> b
coerce Double
size)) Ptr BRepFont -> IO ()
deleteBRepFont

foreign import capi unsafe "hs_Font_BRepFont.h hs_Font_BRepFont_initPathAndSize" rawInitFromPathAndSize :: Ptr BRepFont ->  CString -> CDouble -> IO CBool

initFromPathAndSize :: Ptr BRepFont -> FilePath -> Double -> IO Bool
initFromPathAndSize :: Ptr BRepFont -> FilePath -> Double -> IO Bool
initFromPathAndSize Ptr BRepFont
font FilePath
fontPath Double
size = FilePath -> (CString -> IO Bool) -> IO Bool
forall a. FilePath -> (CString -> IO a) -> IO a
withCString FilePath
fontPath ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
str -> CBool -> Bool
cBoolToBool (CBool -> Bool) -> IO CBool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr BRepFont -> CString -> CDouble -> IO CBool
rawInitFromPathAndSize Ptr BRepFont
font CString
str (Double -> CDouble
forall a b. Coercible a b => a -> b
coerce Double
size)

foreign import capi unsafe "hs_Font_BRepFont.h hs_Font_BRepFont_initNameAspectAndSize" rawInitFromNameAspectAndSize :: Ptr BRepFont ->  CString -> CInt -> CDouble -> IO CBool

initFromNameAspectAndSize :: Ptr BRepFont -> String -> FontAspect -> Double -> IO Bool
initFromNameAspectAndSize :: Ptr BRepFont -> FilePath -> FontAspect -> Double -> IO Bool
initFromNameAspectAndSize Ptr BRepFont
font FilePath
fontname FontAspect
aspect Double
size = 
    FilePath -> (CString -> IO Bool) -> IO Bool
forall a. FilePath -> (CString -> IO a) -> IO a
withCString FilePath
fontname ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
str -> CBool -> Bool
cBoolToBool (CBool -> Bool) -> IO CBool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr BRepFont -> CString -> CInt -> CDouble -> IO CBool
rawInitFromNameAspectAndSize Ptr BRepFont
font CString
str (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (FontAspect -> Int) -> FontAspect -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FontAspect -> Int
forall a. Enum a => a -> Int
fromEnum (FontAspect -> CInt) -> FontAspect -> CInt
forall a b. (a -> b) -> a -> b
$ FontAspect
aspect) (Double -> CDouble
forall a b. Coercible a b => a -> b
coerce Double
size)


foreign import capi unsafe "hs_Font_BRepFont.h hs_Font_BRepFont_ascender" rawAscender :: Ptr BRepFont -> IO CDouble

ascender :: Ptr BRepFont -> IO Double
ascender :: Ptr BRepFont -> IO Double
ascender = (Ptr BRepFont -> IO CDouble) -> Ptr BRepFont -> IO Double
forall a b. Coercible a b => a -> b
coerce Ptr BRepFont -> IO CDouble
rawAscender

foreign import capi unsafe "hs_Font_BRepFont.h hs_Font_BRepFont_descender" rawDescender :: Ptr BRepFont -> IO CDouble

descender :: Ptr BRepFont -> IO Double
descender :: Ptr BRepFont -> IO Double
descender = (Ptr BRepFont -> IO CDouble) -> Ptr BRepFont -> IO Double
forall a b. Coercible a b => a -> b
coerce Ptr BRepFont -> IO CDouble
rawDescender

foreign import capi unsafe "hs_Font_BRepFont.h hs_Font_BRepFont_lineSpacing" rawLineSpacing :: Ptr BRepFont -> IO CDouble

lineSpacing :: Ptr BRepFont -> IO Double
lineSpacing :: Ptr BRepFont -> IO Double
lineSpacing = (Ptr BRepFont -> IO CDouble) -> Ptr BRepFont -> IO Double
forall a b. Coercible a b => a -> b
coerce Ptr BRepFont -> IO CDouble
rawLineSpacing

foreign import capi unsafe "hs_Font_BRepFont.h hs_Font_BRepFont_pointSize" rawPointSize :: Ptr BRepFont -> IO CDouble

pointSize :: Ptr BRepFont -> IO Double
pointSize :: Ptr BRepFont -> IO Double
pointSize = (Ptr BRepFont -> IO CDouble) -> Ptr BRepFont -> IO Double
forall a b. Coercible a b => a -> b
coerce Ptr BRepFont -> IO CDouble
rawPointSize