{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- t'GI.PangoCairo.Interfaces.Font.Font' is an interface exported by fonts for
-- use with Cairo. The actual type of the font will depend
-- on the particular font technology Cairo was compiled to use.
-- 
-- /Since: 1.18/

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.PangoCairo.Interfaces.Font
    ( 

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


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveFontMethod                       ,
#endif


-- ** getScaledFont #method:getScaledFont#

#if defined(ENABLE_OVERLOADING)
    FontGetScaledFontMethodInfo             ,
#endif
    fontGetScaledFont                       ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.Cairo.Structs.ScaledFont as Cairo.ScaledFont
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Pango.Objects.Font as Pango.Font

-- interface Font 
-- | Memory-managed wrapper type.
newtype Font = Font (ManagedPtr Font)
    deriving (Font -> Font -> Bool
(Font -> Font -> Bool) -> (Font -> Font -> Bool) -> Eq Font
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Font -> Font -> Bool
$c/= :: Font -> Font -> Bool
== :: Font -> Font -> Bool
$c== :: Font -> Font -> Bool
Eq)
-- | A convenience alias for `Nothing` :: `Maybe` `Font`.
noFont :: Maybe Font
noFont :: Maybe Font
noFont = Maybe Font
forall a. Maybe a
Nothing

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Font = FontSignalList
type FontSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

foreign import ccall "pango_cairo_font_get_type"
    c_pango_cairo_font_get_type :: IO GType

instance GObject Font where
    gobjectType :: IO GType
gobjectType = IO GType
c_pango_cairo_font_get_type
    

-- | Convert 'Font' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue Font where
    toGValue :: Font -> IO GValue
toGValue o :: Font
o = do
        GType
gtype <- IO GType
c_pango_cairo_font_get_type
        Font -> (Ptr Font -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Font
o (GType -> (GValue -> Ptr Font -> IO ()) -> Ptr Font -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Font -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
        
    fromGValue :: GValue -> IO Font
fromGValue gv :: GValue
gv = do
        Ptr Font
ptr <- GValue -> IO (Ptr Font)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr Font)
        (ManagedPtr Font -> Font) -> Ptr Font -> IO Font
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr Font -> Font
Font Ptr Font
ptr
        
    

-- | Type class for types which can be safely cast to `Font`, for instance with `toFont`.
class (GObject o, O.IsDescendantOf Font o) => IsFont o
instance (GObject o, O.IsDescendantOf Font o) => IsFont o

instance O.HasParentTypes Font
type instance O.ParentTypes Font = '[Pango.Font.Font, GObject.Object.Object]

-- | Cast to `Font`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toFont :: (MonadIO m, IsFont o) => o -> m Font
toFont :: o -> m Font
toFont = IO Font -> m Font
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Font -> m Font) -> (o -> IO Font) -> o -> m Font
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Font -> Font) -> o -> IO Font
forall o o'.
(HasCallStack, GObject o, GObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr Font -> Font
Font

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Font
type instance O.AttributeList Font = FontAttributeList
type FontAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveFontMethod (t :: Symbol) (o :: *) :: * where
    ResolveFontMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveFontMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveFontMethod "describe" o = Pango.Font.FontDescribeMethodInfo
    ResolveFontMethod "describeWithAbsoluteSize" o = Pango.Font.FontDescribeWithAbsoluteSizeMethodInfo
    ResolveFontMethod "findShaper" o = Pango.Font.FontFindShaperMethodInfo
    ResolveFontMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveFontMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveFontMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveFontMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveFontMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveFontMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveFontMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveFontMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveFontMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveFontMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveFontMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveFontMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveFontMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveFontMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveFontMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveFontMethod "getFontMap" o = Pango.Font.FontGetFontMapMethodInfo
    ResolveFontMethod "getGlyphExtents" o = Pango.Font.FontGetGlyphExtentsMethodInfo
    ResolveFontMethod "getMetrics" o = Pango.Font.FontGetMetricsMethodInfo
    ResolveFontMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveFontMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveFontMethod "getScaledFont" o = FontGetScaledFontMethodInfo
    ResolveFontMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveFontMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveFontMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveFontMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveFontMethod t Font, O.MethodInfo info Font p) => OL.IsLabel t (Font -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif

-- method Font::get_scaled_font
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "font"
--           , argType =
--               TInterface Name { namespace = "PangoCairo" , name = "Font" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #PangoFont from a #PangoCairoFontMap"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "cairo" , name = "ScaledFont" })
-- throws : False
-- Skip return : False

foreign import ccall "pango_cairo_font_get_scaled_font" pango_cairo_font_get_scaled_font :: 
    Ptr Font ->                             -- font : TInterface (Name {namespace = "PangoCairo", name = "Font"})
    IO (Ptr Cairo.ScaledFont.ScaledFont)

-- | Gets the t'GI.Cairo.Structs.ScaledFont.ScaledFont' used by /@font@/.
-- The scaled font can be referenced and kept using
-- @/cairo_scaled_font_reference()/@.
-- 
-- /Since: 1.18/
fontGetScaledFont ::
    (B.CallStack.HasCallStack, MonadIO m, IsFont a) =>
    a
    -- ^ /@font@/: a t'GI.Pango.Objects.Font.Font' from a t'GI.PangoCairo.Interfaces.FontMap.FontMap'
    -> m (Maybe Cairo.ScaledFont.ScaledFont)
    -- ^ __Returns:__ the t'GI.Cairo.Structs.ScaledFont.ScaledFont' used by /@font@/,
    --               or 'P.Nothing' if /@font@/ is 'P.Nothing'.
fontGetScaledFont :: a -> m (Maybe ScaledFont)
fontGetScaledFont font :: a
font = IO (Maybe ScaledFont) -> m (Maybe ScaledFont)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe ScaledFont) -> m (Maybe ScaledFont))
-> IO (Maybe ScaledFont) -> m (Maybe ScaledFont)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Font
font' <- a -> IO (Ptr Font)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
font
    Ptr ScaledFont
result <- Ptr Font -> IO (Ptr ScaledFont)
pango_cairo_font_get_scaled_font Ptr Font
font'
    Maybe ScaledFont
maybeResult <- Ptr ScaledFont
-> (Ptr ScaledFont -> IO ScaledFont) -> IO (Maybe ScaledFont)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr ScaledFont
result ((Ptr ScaledFont -> IO ScaledFont) -> IO (Maybe ScaledFont))
-> (Ptr ScaledFont -> IO ScaledFont) -> IO (Maybe ScaledFont)
forall a b. (a -> b) -> a -> b
$ \result' :: Ptr ScaledFont
result' -> do
        ScaledFont
result'' <- ((ManagedPtr ScaledFont -> ScaledFont)
-> Ptr ScaledFont -> IO ScaledFont
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr ScaledFont -> ScaledFont
Cairo.ScaledFont.ScaledFont) Ptr ScaledFont
result'
        ScaledFont -> IO ScaledFont
forall (m :: * -> *) a. Monad m => a -> m a
return ScaledFont
result''
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
font
    Maybe ScaledFont -> IO (Maybe ScaledFont)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ScaledFont
maybeResult

#if defined(ENABLE_OVERLOADING)
data FontGetScaledFontMethodInfo
instance (signature ~ (m (Maybe Cairo.ScaledFont.ScaledFont)), MonadIO m, IsFont a) => O.MethodInfo FontGetScaledFontMethodInfo a signature where
    overloadedMethod = fontGetScaledFont

#endif