module Graphics.Rendering.Pango.Description (
FontDescription,
fontDescriptionNew,
fontDescriptionCopy,
fontDescriptionSetFamily,
fontDescriptionGetFamily,
fontDescriptionSetStyle,
fontDescriptionGetStyle,
fontDescriptionSetVariant,
fontDescriptionGetVariant,
fontDescriptionSetWeight,
fontDescriptionGetWeight,
fontDescriptionSetStretch,
fontDescriptionGetStretch,
fontDescriptionSetSize,
fontDescriptionGetSize,
FontMask(..),
fontDescriptionUnsetFields,
fontDescriptionMerge,
fontDescriptionBetterMatch,
fontDescriptionFromString,
fontDescriptionToString
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.Flags (Flags, fromFlags)
import System.Glib.UTFString
import Graphics.Rendering.Pango.Types
import Graphics.Rendering.Pango.Enums
import Graphics.Rendering.Pango.Structs ( puToInt, intToPu )
import Graphics.Rendering.Pango.BasicTypes
fontDescriptionNew :: IO FontDescription
fontDescriptionNew = pango_font_description_new >>= makeNewFontDescription
fontDescriptionCopy :: FontDescription -> IO FontDescription
fontDescriptionCopy fd = (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_copy argPtr1) fd >>= makeNewFontDescription
fontDescriptionSetFamily :: FontDescription -> String -> IO ()
fontDescriptionSetFamily fd family = withUTFString family $ \strPtr ->
(\(FontDescription arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_set_family argPtr1 arg2) fd strPtr
fontDescriptionGetFamily :: FontDescription -> IO (Maybe String)
fontDescriptionGetFamily fd = do
strPtr <- (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_family argPtr1) fd
if strPtr==nullPtr then return Nothing else
liftM Just $ peekUTFString strPtr
data FontMask = PangoFontMaskFamily
| PangoFontMaskStyle
| PangoFontMaskVariant
| PangoFontMaskWeight
| PangoFontMaskStretch
| PangoFontMaskSize
| PangoFontMaskGravity
deriving (Bounded)
instance Enum FontMask where
fromEnum PangoFontMaskFamily = 1
fromEnum PangoFontMaskStyle = 2
fromEnum PangoFontMaskVariant = 4
fromEnum PangoFontMaskWeight = 8
fromEnum PangoFontMaskStretch = 16
fromEnum PangoFontMaskSize = 32
fromEnum PangoFontMaskGravity = 64
toEnum 1 = PangoFontMaskFamily
toEnum 2 = PangoFontMaskStyle
toEnum 4 = PangoFontMaskVariant
toEnum 8 = PangoFontMaskWeight
toEnum 16 = PangoFontMaskStretch
toEnum 32 = PangoFontMaskSize
toEnum 64 = PangoFontMaskGravity
toEnum unmatched = error ("FontMask.toEnum: Cannot match " ++ show unmatched)
succ PangoFontMaskFamily = PangoFontMaskStyle
succ PangoFontMaskStyle = PangoFontMaskVariant
succ PangoFontMaskVariant = PangoFontMaskWeight
succ PangoFontMaskWeight = PangoFontMaskStretch
succ PangoFontMaskStretch = PangoFontMaskSize
succ PangoFontMaskSize = PangoFontMaskGravity
succ _ = undefined
pred PangoFontMaskStyle = PangoFontMaskFamily
pred PangoFontMaskVariant = PangoFontMaskStyle
pred PangoFontMaskWeight = PangoFontMaskVariant
pred PangoFontMaskStretch = PangoFontMaskWeight
pred PangoFontMaskSize = PangoFontMaskStretch
pred PangoFontMaskGravity = PangoFontMaskSize
pred _ = undefined
enumFromTo x y | fromEnum x == fromEnum y = [ y ]
| otherwise = x : enumFromTo (succ x) y
enumFrom x = enumFromTo x PangoFontMaskGravity
enumFromThen _ _ = error "Enum FontMask: enumFromThen not implemented"
enumFromThenTo _ _ _ = error "Enum FontMask: enumFromThenTo not implemented"
instance Flags FontMask
fontDescriptionSetStyle :: FontDescription -> FontStyle -> IO ()
fontDescriptionSetStyle fd p =
(\(FontDescription arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_set_style argPtr1 arg2) fd (fromIntegral (fromEnum p))
fontDescriptionGetStyle :: FontDescription -> IO (Maybe FontStyle)
fontDescriptionGetStyle fd = do
fields <- (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_set_fields argPtr1) fd
if (fromEnum PangoFontMaskStyle) .&. (fromIntegral fields) /=0
then liftM (Just . toEnum . fromIntegral) $
(\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_style argPtr1) fd
else return Nothing
fontDescriptionSetVariant :: FontDescription -> Variant -> IO ()
fontDescriptionSetVariant fd p =
(\(FontDescription arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_set_variant argPtr1 arg2) fd (fromIntegral (fromEnum p))
fontDescriptionGetVariant :: FontDescription -> IO (Maybe Variant)
fontDescriptionGetVariant fd = do
fields <- (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_set_fields argPtr1) fd
if (fromEnum PangoFontMaskVariant) .&. (fromIntegral fields) /=0
then liftM (Just . toEnum . fromIntegral) $
(\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_variant argPtr1) fd
else return Nothing
fontDescriptionSetWeight :: FontDescription -> Weight -> IO ()
fontDescriptionSetWeight fd p =
(\(FontDescription arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_set_weight argPtr1 arg2) fd (fromIntegral (fromEnum p))
fontDescriptionGetWeight :: FontDescription -> IO (Maybe Weight)
fontDescriptionGetWeight fd = do
fields <- (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_set_fields argPtr1) fd
if (fromEnum PangoFontMaskWeight) .&. (fromIntegral fields) /=0
then liftM (Just . toEnum . fromIntegral) $
(\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_weight argPtr1) fd
else return Nothing
fontDescriptionSetStretch :: FontDescription -> Stretch -> IO ()
fontDescriptionSetStretch fd p =
(\(FontDescription arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_set_stretch argPtr1 arg2) fd (fromIntegral (fromEnum p))
fontDescriptionGetStretch :: FontDescription -> IO (Maybe Stretch)
fontDescriptionGetStretch fd = do
fields <- (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_set_fields argPtr1) fd
if (fromEnum PangoFontMaskStretch) .&. (fromIntegral fields) /=0
then liftM (Just . toEnum . fromIntegral) $
(\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_stretch argPtr1) fd
else return Nothing
fontDescriptionSetSize :: FontDescription -> Double -> IO ()
fontDescriptionSetSize fd p =
(\(FontDescription arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_set_size argPtr1 arg2) fd (puToInt p)
fontDescriptionGetSize :: FontDescription -> IO (Maybe Double)
fontDescriptionGetSize fd = do
fields <- (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_set_fields argPtr1) fd
if (fromEnum PangoFontMaskSize) .&. (fromIntegral fields) /=0
then liftM (\x -> Just (intToPu x)) $
(\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_get_size argPtr1) fd
else return Nothing
fontDescriptionUnsetFields :: FontDescription -> [FontMask] -> IO ()
fontDescriptionUnsetFields fd mask =
(\(FontDescription arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_unset_fields argPtr1 arg2) fd (fromIntegral (fromFlags mask))
fontDescriptionMerge :: FontDescription -> FontDescription -> Bool -> IO ()
fontDescriptionMerge fd1 fd2 replace =
(\(FontDescription arg1) (FontDescription arg2) arg3 -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->pango_font_description_merge argPtr1 argPtr2 arg3) fd1 fd2 (fromBool replace)
fontDescriptionIsMatch :: FontDescription -> FontDescription -> Bool
fontDescriptionIsMatch fdA fdB = unsafePerformIO $ liftM toBool $
(\(FontDescription arg1) (FontDescription arg2) (FontDescription arg3) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg3 $ \argPtr3 ->pango_font_description_better_match argPtr1 argPtr2 argPtr3) fdA (FontDescription nullForeignPtr) fdB
fontDescriptionBetterMatch :: FontDescription -> FontDescription ->
FontDescription -> Bool
fontDescriptionBetterMatch fd fdA fdB = unsafePerformIO $ liftM toBool $
(\(FontDescription arg1) (FontDescription arg2) (FontDescription arg3) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg3 $ \argPtr3 ->pango_font_description_better_match argPtr1 argPtr2 argPtr3) fd fdA fdB
fontDescriptionFromString :: String -> IO FontDescription
fontDescriptionFromString descr = withUTFString descr $ \strPtr ->
pango_font_description_from_string strPtr >>= makeNewFontDescription
fontDescriptionToString :: FontDescription -> IO String
fontDescriptionToString fd = do
strPtr <- (\(FontDescription arg1) -> withForeignPtr arg1 $ \argPtr1 ->pango_font_description_to_string argPtr1) fd
str <- peekUTFString strPtr
g_free (castPtr strPtr)
return str
foreign import ccall unsafe "pango_font_description_new"
pango_font_description_new :: (IO (Ptr FontDescription))
foreign import ccall unsafe "pango_font_description_copy"
pango_font_description_copy :: ((Ptr FontDescription) -> (IO (Ptr FontDescription)))
foreign import ccall unsafe "pango_font_description_set_family"
pango_font_description_set_family :: ((Ptr FontDescription) -> ((Ptr CChar) -> (IO ())))
foreign import ccall unsafe "pango_font_description_get_family"
pango_font_description_get_family :: ((Ptr FontDescription) -> (IO (Ptr CChar)))
foreign import ccall unsafe "pango_font_description_set_style"
pango_font_description_set_style :: ((Ptr FontDescription) -> (CInt -> (IO ())))
foreign import ccall unsafe "pango_font_description_get_set_fields"
pango_font_description_get_set_fields :: ((Ptr FontDescription) -> (IO CInt))
foreign import ccall unsafe "pango_font_description_get_style"
pango_font_description_get_style :: ((Ptr FontDescription) -> (IO CInt))
foreign import ccall unsafe "pango_font_description_set_variant"
pango_font_description_set_variant :: ((Ptr FontDescription) -> (CInt -> (IO ())))
foreign import ccall unsafe "pango_font_description_get_variant"
pango_font_description_get_variant :: ((Ptr FontDescription) -> (IO CInt))
foreign import ccall unsafe "pango_font_description_set_weight"
pango_font_description_set_weight :: ((Ptr FontDescription) -> (CInt -> (IO ())))
foreign import ccall unsafe "pango_font_description_get_weight"
pango_font_description_get_weight :: ((Ptr FontDescription) -> (IO CInt))
foreign import ccall unsafe "pango_font_description_set_stretch"
pango_font_description_set_stretch :: ((Ptr FontDescription) -> (CInt -> (IO ())))
foreign import ccall unsafe "pango_font_description_get_stretch"
pango_font_description_get_stretch :: ((Ptr FontDescription) -> (IO CInt))
foreign import ccall unsafe "pango_font_description_set_size"
pango_font_description_set_size :: ((Ptr FontDescription) -> (CInt -> (IO ())))
foreign import ccall unsafe "pango_font_description_get_size"
pango_font_description_get_size :: ((Ptr FontDescription) -> (IO CInt))
foreign import ccall unsafe "pango_font_description_unset_fields"
pango_font_description_unset_fields :: ((Ptr FontDescription) -> (CInt -> (IO ())))
foreign import ccall unsafe "pango_font_description_merge"
pango_font_description_merge :: ((Ptr FontDescription) -> ((Ptr FontDescription) -> (CInt -> (IO ()))))
foreign import ccall unsafe "pango_font_description_better_match"
pango_font_description_better_match :: ((Ptr FontDescription) -> ((Ptr FontDescription) -> ((Ptr FontDescription) -> (IO CInt))))
foreign import ccall unsafe "pango_font_description_from_string"
pango_font_description_from_string :: ((Ptr CChar) -> (IO (Ptr FontDescription)))
foreign import ccall unsafe "pango_font_description_to_string"
pango_font_description_to_string :: ((Ptr FontDescription) -> (IO (Ptr CChar)))
foreign import ccall unsafe "g_free"
g_free :: ((Ptr ()) -> (IO ()))