{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.Pango.Objects.Font
    ( 

-- * Exported types
    Font(..)                                ,
    FontK                                   ,
    toFont                                  ,
    noFont                                  ,


 -- * Methods
-- ** fontDescribe
    fontDescribe                            ,


-- ** fontDescribeWithAbsoluteSize
    fontDescribeWithAbsoluteSize            ,


-- ** fontDescriptionsFree
    fontDescriptionsFree                    ,


-- ** fontGetFontMap
    fontGetFontMap                          ,


-- ** fontGetGlyphExtents
    fontGetGlyphExtents                     ,


-- ** fontGetMetrics
    fontGetMetrics                          ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Pango.Types
import GI.Pango.Callbacks
import qualified GI.GObject as GObject

newtype Font = Font (ForeignPtr Font)
foreign import ccall "pango_font_get_type"
    c_pango_font_get_type :: IO GType

type instance ParentTypes Font = FontParentTypes
type FontParentTypes = '[GObject.Object]

instance GObject Font where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_pango_font_get_type
    

class GObject o => FontK o
instance (GObject o, IsDescendantOf Font o) => FontK o

toFont :: FontK o => o -> IO Font
toFont = unsafeCastTo Font

noFont :: Maybe Font
noFont = Nothing

type instance AttributeList Font = FontAttributeList
type FontAttributeList = ('[ ] :: [(Symbol, *)])

type instance SignalList Font = FontSignalList
type FontSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method Font::describe
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Pango" "FontDescription"
-- throws : False
-- Skip return : False

foreign import ccall "pango_font_describe" pango_font_describe :: 
    Ptr Font ->                             -- _obj : TInterface "Pango" "Font"
    IO (Ptr FontDescription)


fontDescribe ::
    (MonadIO m, FontK a) =>
    a ->                                    -- _obj
    m FontDescription
fontDescribe _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- pango_font_describe _obj'
    checkUnexpectedReturnNULL "pango_font_describe" result
    result' <- (wrapBoxed FontDescription) result
    touchManagedPtr _obj
    return result'

-- method Font::describe_with_absolute_size
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Pango" "FontDescription"
-- throws : False
-- Skip return : False

foreign import ccall "pango_font_describe_with_absolute_size" pango_font_describe_with_absolute_size :: 
    Ptr Font ->                             -- _obj : TInterface "Pango" "Font"
    IO (Ptr FontDescription)


fontDescribeWithAbsoluteSize ::
    (MonadIO m, FontK a) =>
    a ->                                    -- _obj
    m FontDescription
fontDescribeWithAbsoluteSize _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- pango_font_describe_with_absolute_size _obj'
    checkUnexpectedReturnNULL "pango_font_describe_with_absolute_size" result
    result' <- (wrapBoxed FontDescription) result
    touchManagedPtr _obj
    return result'

-- method Font::get_font_map
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Pango" "FontMap"
-- throws : False
-- Skip return : False

foreign import ccall "pango_font_get_font_map" pango_font_get_font_map :: 
    Ptr Font ->                             -- _obj : TInterface "Pango" "Font"
    IO (Ptr FontMap)


fontGetFontMap ::
    (MonadIO m, FontK a) =>
    a ->                                    -- _obj
    m FontMap
fontGetFontMap _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- pango_font_get_font_map _obj'
    checkUnexpectedReturnNULL "pango_font_get_font_map" result
    result' <- (newObject FontMap) result
    touchManagedPtr _obj
    return result'

-- method Font::get_glyph_extents
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "glyph", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "ink_rect", argType = TInterface "Pango" "Rectangle", direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "logical_rect", argType = TInterface "Pango" "Rectangle", direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "glyph", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "pango_font_get_glyph_extents" pango_font_get_glyph_extents :: 
    Ptr Font ->                             -- _obj : TInterface "Pango" "Font"
    Word32 ->                               -- glyph : TBasicType TUInt32
    Ptr Rectangle ->                        -- ink_rect : TInterface "Pango" "Rectangle"
    Ptr Rectangle ->                        -- logical_rect : TInterface "Pango" "Rectangle"
    IO ()


fontGetGlyphExtents ::
    (MonadIO m, FontK a) =>
    a ->                                    -- _obj
    Word32 ->                               -- glyph
    m (Rectangle,Rectangle)
fontGetGlyphExtents _obj glyph = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    ink_rect <- callocBytes 16 :: IO (Ptr Rectangle)
    logical_rect <- callocBytes 16 :: IO (Ptr Rectangle)
    pango_font_get_glyph_extents _obj' glyph ink_rect logical_rect
    ink_rect' <- (wrapPtr Rectangle) ink_rect
    logical_rect' <- (wrapPtr Rectangle) logical_rect
    touchManagedPtr _obj
    return (ink_rect', logical_rect')

-- method Font::get_metrics
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "language", argType = TInterface "Pango" "Language", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Pango" "Font", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "language", argType = TInterface "Pango" "Language", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Pango" "FontMetrics"
-- throws : False
-- Skip return : False

foreign import ccall "pango_font_get_metrics" pango_font_get_metrics :: 
    Ptr Font ->                             -- _obj : TInterface "Pango" "Font"
    Ptr Language ->                         -- language : TInterface "Pango" "Language"
    IO (Ptr FontMetrics)


fontGetMetrics ::
    (MonadIO m, FontK a) =>
    a ->                                    -- _obj
    Maybe (Language) ->                     -- language
    m FontMetrics
fontGetMetrics _obj language = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    maybeLanguage <- case language of
        Nothing -> return nullPtr
        Just jLanguage -> do
            let jLanguage' = unsafeManagedPtrGetPtr jLanguage
            return jLanguage'
    result <- pango_font_get_metrics _obj' maybeLanguage
    checkUnexpectedReturnNULL "pango_font_get_metrics" result
    result' <- (wrapBoxed FontMetrics) result
    touchManagedPtr _obj
    whenJust language touchManagedPtr
    return result'

-- method Font::descriptions_free
-- method type : MemberFunction
-- Args : [Arg {argName = "descs", argType = TCArray False (-1) 1 (TInterface "Pango" "FontDescription"), direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything},Arg {argName = "n_descs", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : [Arg {argName = "n_descs", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- hInArgs : [Arg {argName = "descs", argType = TCArray False (-1) 1 (TInterface "Pango" "FontDescription"), direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "pango_font_descriptions_free" pango_font_descriptions_free :: 
    Ptr (Ptr FontDescription) ->            -- descs : TCArray False (-1) 1 (TInterface "Pango" "FontDescription")
    Int32 ->                                -- n_descs : TBasicType TInt32
    IO ()


fontDescriptionsFree ::
    (MonadIO m) =>
    Maybe ([FontDescription]) ->            -- descs
    m ()
fontDescriptionsFree descs = liftIO $ do
    let n_descs = case descs of
            Nothing -> 0
            Just jDescs -> fromIntegral $ length jDescs
    maybeDescs <- case descs of
        Nothing -> return nullPtr
        Just jDescs -> do
            jDescs' <- mapM copyBoxed jDescs
            jDescs'' <- packPtrArray jDescs'
            return jDescs''
    pango_font_descriptions_free maybeDescs n_descs
    whenJust descs (mapM_ touchManagedPtr)
    return ()