{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

'GI.PangoCairo.Interfaces.FontMap.FontMap' is an interface exported by font maps for
use with Cairo. The actual type of the font map will depend
on the particular font technology Cairo was compiled to use.

/Since: 1.10/
-}

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

module GI.PangoCairo.Interfaces.FontMap
    (

-- * Exported types
    FontMap(..)                             ,
    noFontMap                               ,
    IsFontMap                               ,
    toFontMap                               ,


 -- * Methods
-- ** getDefault #method:getDefault#

    fontMapGetDefault                       ,


-- ** getFontType #method:getFontType#

#if ENABLE_OVERLOADING
    FontMapGetFontTypeMethodInfo            ,
#endif
    fontMapGetFontType                      ,


-- ** getResolution #method:getResolution#

#if ENABLE_OVERLOADING
    FontMapGetResolutionMethodInfo          ,
#endif
    fontMapGetResolution                    ,


-- ** new #method:new#

    fontMapNew                              ,


-- ** newForFontType #method:newForFontType#

    fontMapNewForFontType                   ,


-- ** setDefault #method:setDefault#

#if ENABLE_OVERLOADING
    FontMapSetDefaultMethodInfo             ,
#endif
    fontMapSetDefault                       ,


-- ** setResolution #method:setResolution#

#if ENABLE_OVERLOADING
    FontMapSetResolutionMethodInfo          ,
#endif
    fontMapSetResolution                    ,




    ) 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.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.Enums as Cairo.Enums
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Pango.Objects.FontMap as Pango.FontMap

-- interface FontMap 
-- | Memory-managed wrapper type.
newtype FontMap = FontMap (ManagedPtr FontMap)
-- | A convenience alias for `Nothing` :: `Maybe` `FontMap`.
noFontMap :: Maybe FontMap
noFontMap = Nothing

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

#endif

foreign import ccall "pango_cairo_font_map_get_type"
    c_pango_cairo_font_map_get_type :: IO GType

instance GObject FontMap where
    gobjectType = c_pango_cairo_font_map_get_type


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

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

-- | Cast to `FontMap`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toFontMap :: (MonadIO m, IsFontMap o) => o -> m FontMap
toFontMap = liftIO . unsafeCastTo FontMap

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

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type family ResolveFontMapMethod (t :: Symbol) (o :: *) :: * where
    ResolveFontMapMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveFontMapMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveFontMapMethod "changed" o = Pango.FontMap.FontMapChangedMethodInfo
    ResolveFontMapMethod "createContext" o = Pango.FontMap.FontMapCreateContextMethodInfo
    ResolveFontMapMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveFontMapMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveFontMapMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveFontMapMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveFontMapMethod "listFamilies" o = Pango.FontMap.FontMapListFamiliesMethodInfo
    ResolveFontMapMethod "loadFont" o = Pango.FontMap.FontMapLoadFontMethodInfo
    ResolveFontMapMethod "loadFontset" o = Pango.FontMap.FontMapLoadFontsetMethodInfo
    ResolveFontMapMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveFontMapMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveFontMapMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveFontMapMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveFontMapMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveFontMapMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveFontMapMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveFontMapMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveFontMapMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveFontMapMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveFontMapMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveFontMapMethod "getFontType" o = FontMapGetFontTypeMethodInfo
    ResolveFontMapMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveFontMapMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveFontMapMethod "getResolution" o = FontMapGetResolutionMethodInfo
    ResolveFontMapMethod "getSerial" o = Pango.FontMap.FontMapGetSerialMethodInfo
    ResolveFontMapMethod "getShapeEngineType" o = Pango.FontMap.FontMapGetShapeEngineTypeMethodInfo
    ResolveFontMapMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveFontMapMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveFontMapMethod "setDefault" o = FontMapSetDefaultMethodInfo
    ResolveFontMapMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveFontMapMethod "setResolution" o = FontMapSetResolutionMethodInfo
    ResolveFontMapMethod l o = O.MethodResolutionFailed l o

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

#endif

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

foreign import ccall "pango_cairo_font_map_get_font_type" pango_cairo_font_map_get_font_type ::
    Ptr FontMap ->                          -- fontmap : TInterface (Name {namespace = "PangoCairo", name = "FontMap"})
    IO CUInt

{- |
Gets the type of Cairo font backend that /@fontmap@/ uses.

/Since: 1.18/
-}
fontMapGetFontType ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontMap a) =>
    a
    {- ^ /@fontmap@/: a 'GI.PangoCairo.Interfaces.FontMap.FontMap' -}
    -> m Cairo.Enums.FontType
    {- ^ __Returns:__ the 'GI.Cairo.Enums.FontType' cairo font backend type -}
fontMapGetFontType fontmap = liftIO $ do
    fontmap' <- unsafeManagedPtrCastPtr fontmap
    result <- pango_cairo_font_map_get_font_type fontmap'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr fontmap
    return result'

#if ENABLE_OVERLOADING
data FontMapGetFontTypeMethodInfo
instance (signature ~ (m Cairo.Enums.FontType), MonadIO m, IsFontMap a) => O.MethodInfo FontMapGetFontTypeMethodInfo a signature where
    overloadedMethod _ = fontMapGetFontType

#endif

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

foreign import ccall "pango_cairo_font_map_get_resolution" pango_cairo_font_map_get_resolution ::
    Ptr FontMap ->                          -- fontmap : TInterface (Name {namespace = "PangoCairo", name = "FontMap"})
    IO CDouble

{- |
Gets the resolution for the fontmap. See 'GI.PangoCairo.Interfaces.FontMap.fontMapSetResolution'

/Since: 1.10/
-}
fontMapGetResolution ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontMap a) =>
    a
    {- ^ /@fontmap@/: a 'GI.PangoCairo.Interfaces.FontMap.FontMap' -}
    -> m Double
    {- ^ __Returns:__ the resolution in \"dots per inch\" -}
fontMapGetResolution fontmap = liftIO $ do
    fontmap' <- unsafeManagedPtrCastPtr fontmap
    result <- pango_cairo_font_map_get_resolution fontmap'
    let result' = realToFrac result
    touchManagedPtr fontmap
    return result'

#if ENABLE_OVERLOADING
data FontMapGetResolutionMethodInfo
instance (signature ~ (m Double), MonadIO m, IsFontMap a) => O.MethodInfo FontMapGetResolutionMethodInfo a signature where
    overloadedMethod _ = fontMapGetResolution

#endif

-- method FontMap::set_default
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "fontmap", argType = TInterface (Name {namespace = "PangoCairo", name = "FontMap"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The new default font map, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_cairo_font_map_set_default" pango_cairo_font_map_set_default ::
    Ptr FontMap ->                          -- fontmap : TInterface (Name {namespace = "PangoCairo", name = "FontMap"})
    IO ()

{- |
Sets a default 'GI.PangoCairo.Interfaces.FontMap.FontMap' to use with Cairo.

This can be used to change the Cairo font backend that the
default fontmap uses for example.  The old default font map
is unreffed and the new font map referenced.

Note that since Pango 1.32.6, the default fontmap is per-thread.
This function only changes the default fontmap for
the current thread.   Default fontmaps of exisiting threads
are not changed.  Default fontmaps of any new threads will
still be created using 'GI.PangoCairo.Functions.fontMapNew'.

A value of 'Nothing' for /@fontmap@/ will cause the current default
font map to be released and a new default font
map to be created on demand, using 'GI.PangoCairo.Functions.fontMapNew'.

/Since: 1.22/
-}
fontMapSetDefault ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontMap a) =>
    a
    {- ^ /@fontmap@/: The new default font map, or 'Nothing' -}
    -> m ()
fontMapSetDefault fontmap = liftIO $ do
    fontmap' <- unsafeManagedPtrCastPtr fontmap
    pango_cairo_font_map_set_default fontmap'
    touchManagedPtr fontmap
    return ()

#if ENABLE_OVERLOADING
data FontMapSetDefaultMethodInfo
instance (signature ~ (m ()), MonadIO m, IsFontMap a) => O.MethodInfo FontMapSetDefaultMethodInfo a signature where
    overloadedMethod _ = fontMapSetDefault

#endif

-- method FontMap::set_resolution
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "fontmap", argType = TInterface (Name {namespace = "PangoCairo", name = "FontMap"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoCairoFontMap", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dpi", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the resolution in \"dots per inch\". (Physical inches aren't actually\n  involved; the terminology is conventional.)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_cairo_font_map_set_resolution" pango_cairo_font_map_set_resolution ::
    Ptr FontMap ->                          -- fontmap : TInterface (Name {namespace = "PangoCairo", name = "FontMap"})
    CDouble ->                              -- dpi : TBasicType TDouble
    IO ()

{- |
Sets the resolution for the fontmap. This is a scale factor between
points specified in a 'GI.Pango.Structs.FontDescription.FontDescription' and Cairo units. The
default value is 96, meaning that a 10 point font will be 13
units high. (10 * 96. \/ 72. = 13.3).

/Since: 1.10/
-}
fontMapSetResolution ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontMap a) =>
    a
    {- ^ /@fontmap@/: a 'GI.PangoCairo.Interfaces.FontMap.FontMap' -}
    -> Double
    {- ^ /@dpi@/: the resolution in \"dots per inch\". (Physical inches aren\'t actually
  involved; the terminology is conventional.) -}
    -> m ()
fontMapSetResolution fontmap dpi = liftIO $ do
    fontmap' <- unsafeManagedPtrCastPtr fontmap
    let dpi' = realToFrac dpi
    pango_cairo_font_map_set_resolution fontmap' dpi'
    touchManagedPtr fontmap
    return ()

#if ENABLE_OVERLOADING
data FontMapSetResolutionMethodInfo
instance (signature ~ (Double -> m ()), MonadIO m, IsFontMap a) => O.MethodInfo FontMapSetResolutionMethodInfo a signature where
    overloadedMethod _ = fontMapSetResolution

#endif

-- method FontMap::get_default
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "PangoCairo", name = "FontMap"}))
-- throws : False
-- Skip return : False

foreign import ccall "pango_cairo_font_map_get_default" pango_cairo_font_map_get_default ::
    IO (Ptr FontMap)

{- |
Gets a default 'GI.PangoCairo.Interfaces.FontMap.FontMap' to use with Cairo.

Note that the type of the returned object will depend
on the particular font backend Cairo was compiled to use;
You generally should only use the 'GI.Pango.Objects.FontMap.FontMap' and
'GI.PangoCairo.Interfaces.FontMap.FontMap' interfaces on the returned object.

The default Cairo fontmap can be changed by using
'GI.PangoCairo.Interfaces.FontMap.fontMapSetDefault'.  This can be used to
change the Cairo font backend that the default fontmap
uses for example.

Note that since Pango 1.32.6, the default fontmap is per-thread.
Each thread gets its own default fontmap.  In this way,
PangoCairo can be used safely from multiple threads.

/Since: 1.10/
-}
fontMapGetDefault ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m FontMap
    {- ^ __Returns:__ the default PangoCairo fontmap
 for the current thread. This object is owned by Pango and must not be freed. -}
fontMapGetDefault  = liftIO $ do
    result <- pango_cairo_font_map_get_default
    checkUnexpectedReturnNULL "fontMapGetDefault" result
    result' <- (newObject FontMap) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method FontMap::new
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "PangoCairo", name = "FontMap"}))
-- throws : False
-- Skip return : False

foreign import ccall "pango_cairo_font_map_new" pango_cairo_font_map_new ::
    IO (Ptr FontMap)

{- |
Creates a new 'GI.PangoCairo.Interfaces.FontMap.FontMap' object; a fontmap is used
to cache information about available fonts, and holds
certain global parameters such as the resolution.
In most cases, you can use 'GI.PangoCairo.Functions.fontMapGetDefault'
instead.

Note that the type of the returned object will depend
on the particular font backend Cairo was compiled to use;
You generally should only use the 'GI.Pango.Objects.FontMap.FontMap' and
'GI.PangoCairo.Interfaces.FontMap.FontMap' interfaces on the returned object.

You can override the type of backend returned by using an
environment variable @/PANGOCAIRO_BACKEND/@.  Supported types,
based on your build, are fc (fontconfig), win32, and coretext.
If requested type is not available, NULL is returned. Ie.
this is only useful for testing, when at least two backends
are compiled in.

/Since: 1.10/
-}
fontMapNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m FontMap
    {- ^ __Returns:__ the newly allocated 'GI.Pango.Objects.FontMap.FontMap',
              which should be freed with 'GI.GObject.Objects.Object.objectUnref'. -}
fontMapNew  = liftIO $ do
    result <- pango_cairo_font_map_new
    checkUnexpectedReturnNULL "fontMapNew" result
    result' <- (wrapObject FontMap) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method FontMap::new_for_font_type
-- method type : MemberFunction
-- Args : [Arg {argCName = "fonttype", argType = TInterface (Name {namespace = "cairo", name = "FontType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "desired #cairo_font_type_t", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "PangoCairo", name = "FontMap"}))
-- throws : False
-- Skip return : False

foreign import ccall "pango_cairo_font_map_new_for_font_type" pango_cairo_font_map_new_for_font_type ::
    CUInt ->                                -- fonttype : TInterface (Name {namespace = "cairo", name = "FontType"})
    IO (Ptr FontMap)

{- |
Creates a new 'GI.PangoCairo.Interfaces.FontMap.FontMap' object of the type suitable
to be used with cairo font backend of type /@fonttype@/.

In most cases one should simply use /@pangoCairoFontMapNew@/(),
or in fact in most of those cases, just use
/@pangoCairoFontMapGetDefault@/().

/Since: 1.18/
-}
fontMapNewForFontType ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cairo.Enums.FontType
    {- ^ /@fonttype@/: desired 'GI.Cairo.Enums.FontType' -}
    -> m (Maybe FontMap)
    {- ^ __Returns:__ the newly allocated
              'GI.Pango.Objects.FontMap.FontMap' of suitable type which should be freed
              with 'GI.GObject.Objects.Object.objectUnref', or 'Nothing' if the requested
              cairo font backend is not supported \/ compiled in. -}
fontMapNewForFontType fonttype = liftIO $ do
    let fonttype' = (fromIntegral . fromEnum) fonttype
    result <- pango_cairo_font_map_new_for_font_type fonttype'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject FontMap) result'
        return result''
    return maybeResult

#if ENABLE_OVERLOADING
#endif