{-# LINE 2 "./Graphics/Rendering/Pango/Font.chs" #-}
module Graphics.Rendering.Pango.Font (
module Graphics.Rendering.Pango.Description,
FontMap,
FontMapClass,
pangoFontMapListFamilies,
FontFamily,
FontFamilyClass,
pangoFontFamilyIsMonospace,
pangoFontFamilyListFaces,
FontFace,
FontFaceClass,
pangoFontFaceListSizes,
pangoFontFaceDescribe,
Font,
FontClass,
) where
import Control.Monad (liftM)
import qualified Data.Text as T (unpack)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.GObject (makeNewGObject)
import Graphics.Rendering.Pango.BasicTypes
{-# LINE 83 "./Graphics/Rendering/Pango/Font.chs" #-}
import Graphics.Rendering.Pango.Types
{-# LINE 84 "./Graphics/Rendering/Pango/Font.chs" #-}
import Graphics.Rendering.Pango.Enums (FontMetrics)
import Graphics.Rendering.Pango.Description
import Graphics.Rendering.Pango.Structs
{-# LINE 89 "./Graphics/Rendering/Pango/Font.chs" #-}
pangoFontMapListFamilies :: FontMap -> IO [FontFamily]
pangoFontMapListFamilies :: FontMap -> IO [FontFamily]
pangoFontMapListFamilies FontMap
fm = (Ptr (Ptr FontFamily) -> IO [FontFamily]) -> IO [FontFamily]
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr FontFamily) -> IO [FontFamily]) -> IO [FontFamily])
-> (Ptr (Ptr FontFamily) -> IO [FontFamily]) -> IO [FontFamily]
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr FontFamily)
arrPtrPtr -> (Ptr CInt -> IO [FontFamily]) -> IO [FontFamily]
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO [FontFamily]) -> IO [FontFamily])
-> (Ptr CInt -> IO [FontFamily]) -> IO [FontFamily]
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
sizePtr -> do
(\(FontMap ForeignPtr FontMap
arg1) Ptr (Ptr FontFamily)
arg2 Ptr CInt
arg3 -> ForeignPtr FontMap -> (Ptr FontMap -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr FontMap
arg1 ((Ptr FontMap -> IO ()) -> IO ())
-> (Ptr FontMap -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr FontMap
argPtr1 ->Ptr FontMap -> Ptr (Ptr FontFamily) -> Ptr CInt -> IO ()
pango_font_map_list_families Ptr FontMap
argPtr1 Ptr (Ptr FontFamily)
arg2 Ptr CInt
arg3) FontMap
fm Ptr (Ptr FontFamily)
arrPtrPtr Ptr CInt
sizePtr
Ptr FontFamily
arrPtr <- Ptr (Ptr FontFamily) -> IO (Ptr FontFamily)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr FontFamily)
arrPtrPtr
CInt
size <- Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
sizePtr
[Ptr FontFamily]
ffsPtr <- Int -> Ptr (Ptr FontFamily) -> IO [Ptr FontFamily]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
size)
(Ptr FontFamily -> Ptr (Ptr FontFamily)
forall a b. Ptr a -> Ptr b
castPtr Ptr FontFamily
arrPtr::Ptr (Ptr FontFamily))
Ptr () -> IO ()
g_free (Ptr FontFamily -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr FontFamily
arrPtr)
(Ptr FontFamily -> IO FontFamily)
-> [Ptr FontFamily] -> IO [FontFamily]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((ForeignPtr FontFamily -> FontFamily, FinalizerPtr FontFamily)
-> IO (Ptr FontFamily) -> IO FontFamily
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewGObject (ForeignPtr FontFamily -> FontFamily, FinalizerPtr FontFamily)
forall {a}. (ForeignPtr FontFamily -> FontFamily, FinalizerPtr a)
mkFontFamily (IO (Ptr FontFamily) -> IO FontFamily)
-> (Ptr FontFamily -> IO (Ptr FontFamily))
-> Ptr FontFamily
-> IO FontFamily
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr FontFamily -> IO (Ptr FontFamily)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr FontFamily -> IO (Ptr FontFamily))
-> (Ptr FontFamily -> Ptr FontFamily)
-> Ptr FontFamily
-> IO (Ptr FontFamily)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr FontFamily -> Ptr FontFamily
forall a b. Ptr a -> Ptr b
castPtr) [Ptr FontFamily]
ffsPtr
instance Show FontFamily where
show :: FontFamily -> String
show FontFamily
ff = Text -> String
T.unpack (Text -> String) -> (IO Text -> Text) -> IO Text -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO Text -> Text
forall a. IO a -> a
unsafePerformIO (IO Text -> String) -> IO Text -> String
forall a b. (a -> b) -> a -> b
$ do
Ptr CChar
strPtr <- (\(FontFamily ForeignPtr FontFamily
arg1) -> ForeignPtr FontFamily
-> (Ptr FontFamily -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr FontFamily
arg1 ((Ptr FontFamily -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr FontFamily -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ \Ptr FontFamily
argPtr1 ->Ptr FontFamily -> IO (Ptr CChar)
pango_font_family_get_name Ptr FontFamily
argPtr1) FontFamily
ff
Ptr CChar -> IO Text
forall s. GlibString s => Ptr CChar -> IO s
peekUTFString Ptr CChar
strPtr
pangoFontFamilyIsMonospace :: FontFamily -> Bool
pangoFontFamilyIsMonospace :: FontFamily -> Bool
pangoFontFamilyIsMonospace FontFamily
ff = IO Bool -> Bool
forall a. IO a -> a
unsafePerformIO (IO Bool -> Bool) -> IO Bool -> Bool
forall a b. (a -> b) -> a -> b
$
(CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$ (\(FontFamily ForeignPtr FontFamily
arg1) -> ForeignPtr FontFamily -> (Ptr FontFamily -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr FontFamily
arg1 ((Ptr FontFamily -> IO CInt) -> IO CInt)
-> (Ptr FontFamily -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr FontFamily
argPtr1 ->Ptr FontFamily -> IO CInt
pango_font_family_is_monospace Ptr FontFamily
argPtr1) FontFamily
ff
pangoFontFamilyListFaces :: FontFamily -> IO [FontFace]
pangoFontFamilyListFaces :: FontFamily -> IO [FontFace]
pangoFontFamilyListFaces FontFamily
ff = (Ptr (Ptr FontFace) -> IO [FontFace]) -> IO [FontFace]
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr FontFace) -> IO [FontFace]) -> IO [FontFace])
-> (Ptr (Ptr FontFace) -> IO [FontFace]) -> IO [FontFace]
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr FontFace)
arrPtrPtr -> (Ptr CInt -> IO [FontFace]) -> IO [FontFace]
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO [FontFace]) -> IO [FontFace])
-> (Ptr CInt -> IO [FontFace]) -> IO [FontFace]
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
sizePtr -> do
(\(FontFamily ForeignPtr FontFamily
arg1) Ptr (Ptr FontFace)
arg2 Ptr CInt
arg3 -> ForeignPtr FontFamily -> (Ptr FontFamily -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr FontFamily
arg1 ((Ptr FontFamily -> IO ()) -> IO ())
-> (Ptr FontFamily -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr FontFamily
argPtr1 ->Ptr FontFamily -> Ptr (Ptr FontFace) -> Ptr CInt -> IO ()
pango_font_family_list_faces Ptr FontFamily
argPtr1 Ptr (Ptr FontFace)
arg2 Ptr CInt
arg3) FontFamily
ff Ptr (Ptr FontFace)
arrPtrPtr Ptr CInt
sizePtr
Ptr FontFace
arrPtr <- Ptr (Ptr FontFace) -> IO (Ptr FontFace)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr FontFace)
arrPtrPtr
CInt
size <- Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
sizePtr
[Ptr FontFace]
ffsPtr <- Int -> Ptr (Ptr FontFace) -> IO [Ptr FontFace]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
size)
(Ptr FontFace -> Ptr (Ptr FontFace)
forall a b. Ptr a -> Ptr b
castPtr Ptr FontFace
arrPtr::Ptr (Ptr FontFace))
Ptr () -> IO ()
g_free (Ptr FontFace -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr FontFace
arrPtr)
(Ptr FontFace -> IO FontFace) -> [Ptr FontFace] -> IO [FontFace]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((ForeignPtr FontFace -> FontFace, FinalizerPtr FontFace)
-> IO (Ptr FontFace) -> IO FontFace
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewGObject (ForeignPtr FontFace -> FontFace, FinalizerPtr FontFace)
forall {a}. (ForeignPtr FontFace -> FontFace, FinalizerPtr a)
mkFontFace (IO (Ptr FontFace) -> IO FontFace)
-> (Ptr FontFace -> IO (Ptr FontFace))
-> Ptr FontFace
-> IO FontFace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr FontFace -> IO (Ptr FontFace)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr FontFace -> IO (Ptr FontFace))
-> (Ptr FontFace -> Ptr FontFace)
-> Ptr FontFace
-> IO (Ptr FontFace)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr FontFace -> Ptr FontFace
forall a b. Ptr a -> Ptr b
castPtr) [Ptr FontFace]
ffsPtr
instance Show FontFace where
show :: FontFace -> String
show FontFace
ff = Text -> String
T.unpack (Text -> String) -> (IO Text -> Text) -> IO Text -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO Text -> Text
forall a. IO a -> a
unsafePerformIO (IO Text -> String) -> IO Text -> String
forall a b. (a -> b) -> a -> b
$ do
Ptr CChar
strPtr <- (\(FontFace ForeignPtr FontFace
arg1) -> ForeignPtr FontFace
-> (Ptr FontFace -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr FontFace
arg1 ((Ptr FontFace -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr FontFace -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ \Ptr FontFace
argPtr1 ->Ptr FontFace -> IO (Ptr CChar)
pango_font_face_get_face_name Ptr FontFace
argPtr1) FontFace
ff
Ptr CChar -> IO Text
forall s. GlibString s => Ptr CChar -> IO s
peekUTFString Ptr CChar
strPtr
pangoFontFaceListSizes :: FontFace -> IO (Maybe [Double])
pangoFontFaceListSizes :: FontFace -> IO (Maybe [Double])
pangoFontFaceListSizes FontFace
ff = (Ptr (Ptr CInt) -> IO (Maybe [Double])) -> IO (Maybe [Double])
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CInt) -> IO (Maybe [Double])) -> IO (Maybe [Double]))
-> (Ptr (Ptr CInt) -> IO (Maybe [Double])) -> IO (Maybe [Double])
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CInt)
arrPtrPtr -> (Ptr CInt -> IO (Maybe [Double])) -> IO (Maybe [Double])
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Maybe [Double])) -> IO (Maybe [Double]))
-> (Ptr CInt -> IO (Maybe [Double])) -> IO (Maybe [Double])
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
sizePtr -> do
(\(FontFace ForeignPtr FontFace
arg1) Ptr (Ptr CInt)
arg2 Ptr CInt
arg3 -> ForeignPtr FontFace -> (Ptr FontFace -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr FontFace
arg1 ((Ptr FontFace -> IO ()) -> IO ())
-> (Ptr FontFace -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr FontFace
argPtr1 ->Ptr FontFace -> Ptr (Ptr CInt) -> Ptr CInt -> IO ()
pango_font_face_list_sizes Ptr FontFace
argPtr1 Ptr (Ptr CInt)
arg2 Ptr CInt
arg3) FontFace
ff Ptr (Ptr CInt)
arrPtrPtr Ptr CInt
sizePtr
Ptr CInt
arrPtr <- Ptr (Ptr CInt) -> IO (Ptr CInt)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr CInt)
arrPtrPtr
CInt
size <- Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
sizePtr
if Ptr CInt
arrPtrPtr CInt -> Ptr CInt -> Bool
forall a. Eq a => a -> a -> Bool
==Ptr CInt
forall a. Ptr a
nullPtr then Maybe [Double] -> IO (Maybe [Double])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe [Double]
forall a. Maybe a
Nothing else do
[CInt]
sizes <- Int -> Ptr CInt -> IO [CInt]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
size) Ptr CInt
arrPtr
Ptr () -> IO ()
g_free (Ptr CInt -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr CInt
arrPtr)
Maybe [Double] -> IO (Maybe [Double])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Double] -> Maybe [Double]
forall a. a -> Maybe a
Just ((CInt -> Double) -> [CInt] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
map CInt -> Double
intToPu [CInt]
sizes))
pangoFontFaceDescribe :: FontFace -> IO FontDescription
pangoFontFaceDescribe :: FontFace -> IO FontDescription
pangoFontFaceDescribe FontFace
ff = do
Ptr FontDescription
fdPtr <- (\(FontFace ForeignPtr FontFace
arg1) -> ForeignPtr FontFace
-> (Ptr FontFace -> IO (Ptr FontDescription))
-> IO (Ptr FontDescription)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr FontFace
arg1 ((Ptr FontFace -> IO (Ptr FontDescription))
-> IO (Ptr FontDescription))
-> (Ptr FontFace -> IO (Ptr FontDescription))
-> IO (Ptr FontDescription)
forall a b. (a -> b) -> a -> b
$ \Ptr FontFace
argPtr1 ->Ptr FontFace -> IO (Ptr FontDescription)
pango_font_face_describe Ptr FontFace
argPtr1) FontFace
ff
Ptr FontDescription -> IO FontDescription
makeNewFontDescription Ptr FontDescription
fdPtr
foreign import ccall unsafe "pango_font_map_list_families"
pango_font_map_list_families :: ((Ptr FontMap) -> ((Ptr (Ptr FontFamily)) -> ((Ptr CInt) -> (IO ()))))
foreign import ccall unsafe "g_free"
g_free :: ((Ptr ()) -> (IO ()))
foreign import ccall unsafe "pango_font_family_get_name"
pango_font_family_get_name :: ((Ptr FontFamily) -> (IO (Ptr CChar)))
foreign import ccall unsafe "pango_font_family_is_monospace"
pango_font_family_is_monospace :: ((Ptr FontFamily) -> (IO CInt))
foreign import ccall unsafe "pango_font_family_list_faces"
pango_font_family_list_faces :: ((Ptr FontFamily) -> ((Ptr (Ptr FontFace)) -> ((Ptr CInt) -> (IO ()))))
foreign import ccall unsafe "pango_font_face_get_face_name"
pango_font_face_get_face_name :: ((Ptr FontFace) -> (IO (Ptr CChar)))
foreign import ccall unsafe "pango_font_face_list_sizes"
pango_font_face_list_sizes :: ((Ptr FontFace) -> ((Ptr (Ptr CInt)) -> ((Ptr CInt) -> (IO ()))))
foreign import ccall unsafe "pango_font_face_describe"
pango_font_face_describe :: ((Ptr FontFace) -> (IO (Ptr FontDescription)))