    {-# LINE 1 "Graphics/Rendering/Pango/Structs.hsc" #-}
    {-# LANGUAGE CPP, ScopedTypeVariables #-}
    {-# OPTIONS_HADDOCK hide #-}
    -- -*-haskell-*-
    --  GIMP Toolkit (GTK) Structures for Pango
    --
    --  Author : Axel Simon
    --
    --  Created: 2 March 2008
    --
    --  Copyright (C) 2008 Axel Simon
    --
    --  This library is free software; you can redistribute it and/or
    --  modify it under the terms of the GNU Lesser General Public
    --  License as published by the Free Software Foundation; either
    --  version 2.1 of the License, or (at your option) any later version.
    --
    --  This library is distributed in the hope that it will be useful,
    --  but WITHOUT ANY WARRANTY; without even the implied warranty of
    --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    --  Lesser General Public License for more details.
    --
    -- #hide

    -- |
    -- Maintainer  : gtk2hs-users@lists.sourceforge.net
    -- Stability   : provisional
    -- Portability : portable (depends on GHC)
    --
    module Graphics.Rendering.Pango.Structs (
      PangoUnit,
      Color(..),
      Rectangle(..),
      PangoRectangle(..),
      peekIntPangoRectangle,

      PangoDirection(..),

      pangoScale,
      puToInt, puToUInt,
      intToPu, uIntToPu,
      pangodirToLevel,
      PangoAttribute(..),
      setAttrPos,
      pangoItemGetFont,
      pangoItemGetLanguage,
      pangoItemRawGetOffset,
      pangoItemRawGetLength,
      pangoItemRawAnalysis,
      pangoItemRawGetLevel,
      readAttr
      ) where

    import Control.Monad            (liftM)
    import Data.IORef
    import Control.Exception

    import System.Glib.FFI
    import System.Glib.UTFString ( peekUTFString, UTFCorrection,
                                   ofsToUTF, ofsFromUTF, DefaultGlibString )
    import System.Glib.GObject              (makeNewGObject)
    import Graphics.Rendering.Pango.Types
    import Graphics.Rendering.Pango.BasicTypes

    -- A pango unit is an internal euclidean metric, that is, a measure for
    -- lengths and position.
    --
    -- * Deprecated. Replaced by Double.
    type PangoUnit = Double

    -- | Color
    --
    -- * Specifies a color with three integer values for red, green and blue.
    --   All values range from 0 (least intense) to 65535 (highest intensity).
    --
    data Color = Color (Word16) (Word16) (Word16)
    {-# LINE 80 "Graphics/Rendering/Pango/Structs.hsc" #-}
                 deriving (Color -> Color -> Bool
    (Color -> Color -> Bool) -> (Color -> Color -> Bool) -> Eq Color
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Color -> Color -> Bool
    == :: Color -> Color -> Bool
    $c/= :: Color -> Color -> Bool
    /= :: Color -> Color -> Bool
    Eq,Int -> Color -> ShowS
    [Color] -> ShowS
    Color -> String
    (Int -> Color -> ShowS)
    -> (Color -> String) -> ([Color] -> ShowS) -> Show Color
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Color -> ShowS
    showsPrec :: Int -> Color -> ShowS
    $cshow :: Color -> String
    show :: Color -> String
    $cshowList :: [Color] -> ShowS
    showList :: [Color] -> ShowS
    Show)

    -- PangoColor is different from GdkColor, but for the Gtk2Hs user we pretend they
    -- are the same. To do this, we need a different marshalling routine for PangoColors.

    peekPangoColor :: Ptr Color -> IO Color
    peekPangoColor :: Ptr Color -> IO Color
    peekPangoColor Ptr Color
    ptr = do
        Word16
    red    <- (\Ptr Color
    hsc_ptr -> Ptr Color -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Color
    hsc_ptr Int
    0) Ptr Color
    ptr
    {-# LINE 88 "Graphics/Rendering/Pango/Structs.hsc" #-}
        green  <- (\hsc_ptr -> peekByteOff hsc_ptr 2) ptr
    {-# LINE 89 "Graphics/Rendering/Pango/Structs.hsc" #-}
        blue   <- (\hsc_ptr -> peekByteOff hsc_ptr 4) ptr
    {-# LINE 90 "Graphics/Rendering/Pango/Structs.hsc" #-}
        return $ Color red green blue

    -- | Rectangle
    --
    -- * Specifies x, y, width and height
    --
    data Rectangle = Rectangle Int Int Int Int deriving (Rectangle -> Rectangle -> Bool
    (Rectangle -> Rectangle -> Bool)
    -> (Rectangle -> Rectangle -> Bool) -> Eq Rectangle
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Rectangle -> Rectangle -> Bool
    == :: Rectangle -> Rectangle -> Bool
    $c/= :: Rectangle -> Rectangle -> Bool
    /= :: Rectangle -> Rectangle -> Bool
    Eq,Int -> Rectangle -> ShowS
    [Rectangle] -> ShowS
    Rectangle -> String
    (Int -> Rectangle -> ShowS)
    -> (Rectangle -> String)
    -> ([Rectangle] -> ShowS)
    -> Show Rectangle
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Rectangle -> ShowS
    showsPrec :: Int -> Rectangle -> ShowS
    $cshow :: Rectangle -> String
    show :: Rectangle -> String
    $cshowList :: [Rectangle] -> ShowS
    showList :: [Rectangle] -> ShowS
    Show)

    -- | Rectangles describing an area in 'Double's.
    --
    -- * Specifies x, y, width and height
    --
    data PangoRectangle = PangoRectangle Double Double Double Double
                          deriving Int -> PangoRectangle -> ShowS
    [PangoRectangle] -> ShowS
    PangoRectangle -> String
    (Int -> PangoRectangle -> ShowS)
    -> (PangoRectangle -> String)
    -> ([PangoRectangle] -> ShowS)
    -> Show PangoRectangle
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> PangoRectangle -> ShowS
    showsPrec :: Int -> PangoRectangle -> ShowS
    $cshow :: PangoRectangle -> String
    show :: PangoRectangle -> String
    $cshowList :: [PangoRectangle] -> ShowS
    showList :: [PangoRectangle] -> ShowS
    Show

    instance Storable PangoRectangle where
      sizeOf :: PangoRectangle -> Int
    sizeOf PangoRectangle
    _ = Int
    16
    {-# LINE 107 "Graphics/Rendering/Pango/Structs.hsc" #-}
      alignment _ = alignment (undefined:: Int32)
    {-# LINE 108 "Graphics/Rendering/Pango/Structs.hsc" #-}
      peek ptr = do
        (Rectangle x_ y_ w_ h_) <- peekIntPangoRectangle ptr
        return $ PangoRectangle (fromIntegral x_/pangoScale) (fromIntegral y_/pangoScale)
                                (fromIntegral w_/pangoScale) (fromIntegral h_/pangoScale)
      poke :: Ptr PangoRectangle -> PangoRectangle -> IO ()
    poke Ptr PangoRectangle
    ptr (PangoRectangle Double
    x Double
    y Double
    w Double
    h) = do
        (\Ptr PangoRectangle
    hsc_ptr -> Ptr PangoRectangle -> Int -> Int32 -> IO ()
    forall b. Ptr b -> Int -> Int32 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr PangoRectangle
    hsc_ptr Int
    0) Ptr PangoRectangle
    ptr ((Double -> Int32
    forall b. Integral b => Double -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    truncate (Double
    xDouble -> Double -> Double
    forall a. Num a => a -> a -> a
    *Double
    pangoScale))::Int32)
    {-# LINE 114 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 4) ptr ((truncate (y*pangoScale))::Int32)
    {-# LINE 115 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 8) ptr ((truncate (w*pangoScale))::Int32)
    {-# LINE 116 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 12) ptr ((truncate (h*pangoScale))::Int32)
    {-# LINE 117 "Graphics/Rendering/Pango/Structs.hsc" #-}

    peekIntPangoRectangle :: Ptr PangoRectangle -> IO Rectangle
    peekIntPangoRectangle :: Ptr PangoRectangle -> IO Rectangle
    peekIntPangoRectangle Ptr PangoRectangle
    ptr = do
        (Int32
    x_ ::Int32)    <- (\Ptr PangoRectangle
    hsc_ptr -> Ptr PangoRectangle -> Int -> IO Int32
    forall b. Ptr b -> Int -> IO Int32
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr PangoRectangle
    hsc_ptr Int
    0) Ptr PangoRectangle
    ptr
    {-# LINE 121 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (y_ ::Int32)    <- (\hsc_ptr -> peekByteOff hsc_ptr 4) ptr
    {-# LINE 122 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (w_ ::Int32)    <- (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
    {-# LINE 123 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (h_ ::Int32)    <- (\hsc_ptr -> peekByteOff hsc_ptr 12) ptr
    {-# LINE 124 "Graphics/Rendering/Pango/Structs.hsc" #-}
        return (Rectangle (fromIntegral x_) (fromIntegral y_)
                          (fromIntegral w_) (fromIntegral h_))

    -- | The 'PangoDirection' type represents a direction in the Unicode
    -- bidirectional algorithm.
    --
    -- * The \"weak\" values denote a left-to-right or right-to-left direction
    --   only if there is no character with a strong direction in a paragraph.
    --   An example is a sequence of special, graphical characters which are
    --   neutral with respect to their rendering direction. A fresh
    --   'Graphics.Rendering.Pango.Rendering.PangoContext' is by default weakly
    --   left-to-right.
    --
    -- * Not every value in this enumeration makes sense for every usage
    --   of 'PangoDirection'; for example, the return value of
    --   'unicharDirection' and 'findBaseDir' cannot be 'PangoDirectionWeakLtr'
    --   or 'PangoDirectionWeakRtl', since every character is either neutral or
    --   has a strong direction; on the other hand 'PangoDirectionNeutral'
    --   doesn't make sense to pass to 'log2visGetEmbeddingLevels'.
    --
    data PangoDirection = PangoDirectionLtr
                        | PangoDirectionRtl

    {-# LINE 147 "Graphics/Rendering/Pango/Structs.hsc" #-}
                        | PangoDirectionWeakLtr
                        | PangoDirectionWeakRtl
                        | PangoDirectionNeutral

    {-# LINE 151 "Graphics/Rendering/Pango/Structs.hsc" #-}
                        deriving (PangoDirection -> PangoDirection -> Bool
    (PangoDirection -> PangoDirection -> Bool)
    -> (PangoDirection -> PangoDirection -> Bool) -> Eq PangoDirection
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: PangoDirection -> PangoDirection -> Bool
    == :: PangoDirection -> PangoDirection -> Bool
    $c/= :: PangoDirection -> PangoDirection -> Bool
    /= :: PangoDirection -> PangoDirection -> Bool
    Eq,Eq PangoDirection
    Eq PangoDirection =>
    (PangoDirection -> PangoDirection -> Ordering)
    -> (PangoDirection -> PangoDirection -> Bool)
    -> (PangoDirection -> PangoDirection -> Bool)
    -> (PangoDirection -> PangoDirection -> Bool)
    -> (PangoDirection -> PangoDirection -> Bool)
    -> (PangoDirection -> PangoDirection -> PangoDirection)
    -> (PangoDirection -> PangoDirection -> PangoDirection)
    -> Ord PangoDirection
    PangoDirection -> PangoDirection -> Bool
    PangoDirection -> PangoDirection -> Ordering
    PangoDirection -> PangoDirection -> PangoDirection
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: PangoDirection -> PangoDirection -> Ordering
    compare :: PangoDirection -> PangoDirection -> Ordering
    $c< :: PangoDirection -> PangoDirection -> Bool
    < :: PangoDirection -> PangoDirection -> Bool
    $c<= :: PangoDirection -> PangoDirection -> Bool
    <= :: PangoDirection -> PangoDirection -> Bool
    $c> :: PangoDirection -> PangoDirection -> Bool
    > :: PangoDirection -> PangoDirection -> Bool
    $c>= :: PangoDirection -> PangoDirection -> Bool
    >= :: PangoDirection -> PangoDirection -> Bool
    $cmax :: PangoDirection -> PangoDirection -> PangoDirection
    max :: PangoDirection -> PangoDirection -> PangoDirection
    $cmin :: PangoDirection -> PangoDirection -> PangoDirection
    min :: PangoDirection -> PangoDirection -> PangoDirection
    Ord)

    -- Internal unit of measuring sizes.
    --
    -- * This constant represents the scale between
    --   dimensions used for distances in text rendering and Pango device units.
    --   The
    --   definition of device unit is dependent on the output device; it will
    --   typically be pixels for a screen, and points for a printer.  When
    --   setting font sizes, device units are always considered to be points
    --   (as in \"12 point font\"), rather than pixels.
    --
    pangoScale :: Double
    pangoScale :: Double
    pangoScale = Double
    1024
    {-# LINE 167 "Graphics/Rendering/Pango/Structs.hsc" #-}

    puToInt :: Double -> GInt
    puToInt :: Double -> GInt
    puToInt Double
    u = Double -> GInt
    forall b. Integral b => Double -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    truncate (Double
    uDouble -> Double -> Double
    forall a. Num a => a -> a -> a
    *Double
    pangoScale)

    puToUInt :: Double -> GInt
    puToUInt :: Double -> GInt
    puToUInt Double
    u = let u' :: Double
    u' = Double
    uDouble -> Double -> Double
    forall a. Num a => a -> a -> a
    *Double
    pangoScale in if Double
    u'Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    <Double
    0 then GInt
    0 else Double -> GInt
    forall b. Integral b => Double -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    truncate Double
    u'

    intToPu :: GInt -> Double
    intToPu :: GInt -> Double
    intToPu GInt
    i = GInt -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GInt
    iDouble -> Double -> Double
    forall a. Fractional a => a -> a -> a
    /Double
    pangoScale

    uIntToPu :: GInt -> Double
    uIntToPu :: GInt -> Double
    uIntToPu GInt
    i = GInt -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GInt
    iDouble -> Double -> Double
    forall a. Fractional a => a -> a -> a
    /Double
    pangoScale

    instance Enum PangoDirection where
      fromEnum :: PangoDirection -> Int
    fromEnum PangoDirection
    PangoDirectionLtr        = Int
    0
    {-# LINE 182 "Graphics/Rendering/Pango/Structs.hsc" #-}
      fromEnum PangoDirectionRtl        = 1
    {-# LINE 183 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 184 "Graphics/Rendering/Pango/Structs.hsc" #-}
      fromEnum PangoDirectionWeakLtr    = 4
    {-# LINE 185 "Graphics/Rendering/Pango/Structs.hsc" #-}
      fromEnum PangoDirectionWeakRtl    = 5
    {-# LINE 186 "Graphics/Rendering/Pango/Structs.hsc" #-}
      fromEnum PangoDirectionNeutral    = 6
    {-# LINE 187 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 188 "Graphics/Rendering/Pango/Structs.hsc" #-}
      toEnum 0 = PangoDirectionLtr
    {-# LINE 189 "Graphics/Rendering/Pango/Structs.hsc" #-}
      toEnum 1 = PangoDirectionRtl
    {-# LINE 190 "Graphics/Rendering/Pango/Structs.hsc" #-}
      toEnum 2 = PangoDirectionLtr
    {-# LINE 191 "Graphics/Rendering/Pango/Structs.hsc" #-}
      toEnum 3 = PangoDirectionRtl
    {-# LINE 192 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 193 "Graphics/Rendering/Pango/Structs.hsc" #-}
      toEnum 4 = PangoDirectionWeakLtr
    {-# LINE 194 "Graphics/Rendering/Pango/Structs.hsc" #-}
      toEnum 5 = PangoDirectionWeakRtl
    {-# LINE 195 "Graphics/Rendering/Pango/Structs.hsc" #-}
      toEnum 6 = PangoDirectionNeutral
    {-# LINE 196 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 197 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- This is a copy of the local function direction_simple in pango-layout.c
    pangodirToLevel :: PangoDirection -> Int
    pangodirToLevel :: PangoDirection -> Int
    pangodirToLevel PangoDirection
    PangoDirectionLtr = Int
    1
    pangodirToLevel PangoDirection
    PangoDirectionRtl = -Int
    1

    {-# LINE 203 "Graphics/Rendering/Pango/Structs.hsc" #-}
    pangodirToLevel PangoDirectionWeakLtr = 1
    pangodirToLevel PangoDirection
    PangoDirectionWeakRtl = -Int
    1
    pangodirToLevel PangoDirection
    PangoDirectionNeutral = Int
    0

    {-# LINE 207 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- | Extract the font used for this 'PangoItem'.
    --
    pangoItemGetFont :: PangoItem -> IO Font
    pangoItemGetFont :: PangoItem -> IO Font
    pangoItemGetFont (PangoItem PangoString
    _ (PangoItemRaw ForeignPtr PangoItemRaw
    pir)) =
      ForeignPtr PangoItemRaw -> (Ptr PangoItemRaw -> IO Font) -> IO Font
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr PangoItemRaw
    pir Ptr PangoItemRaw -> IO Font
    forall pangoItem. Ptr pangoItem -> IO Font
    pangoItemRawGetFont

    -- | Extract the 'Language' used for this 'PangoItem'.
    --
    pangoItemGetLanguage :: PangoItem -> IO Language
    pangoItemGetLanguage :: PangoItem -> IO Language
    pangoItemGetLanguage (PangoItem PangoString
    _ (PangoItemRaw ForeignPtr PangoItemRaw
    pir)) =
      (CString -> Language) -> IO CString -> IO Language
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (Ptr Language -> Language
    Language (Ptr Language -> Language)
    -> (CString -> Ptr Language) -> CString -> Language
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . CString -> Ptr Language
    forall a b. Ptr a -> Ptr b
    castPtr) (IO CString -> IO Language) -> IO CString -> IO Language
    forall a b. (a -> b) -> a -> b
    $ ForeignPtr PangoItemRaw
    -> (Ptr PangoItemRaw -> IO CString) -> IO CString
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr PangoItemRaw
    pir Ptr PangoItemRaw -> IO CString
    forall pangoItem. Ptr pangoItem -> IO CString
    pangoItemRawGetLanguage

    -- Get the font of a PangoAnalysis within a PangoItem.
    pangoItemRawGetFont :: Ptr pangoItem -> IO Font
    pangoItemRawGetFont :: forall pangoItem. Ptr pangoItem -> IO Font
    pangoItemRawGetFont Ptr pangoItem
    ptr =
      (ForeignPtr Font -> Font, FinalizerPtr Font)
    -> IO (Ptr Font) -> IO Font
    forall obj.
    GObjectClass obj =>
    (ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
    makeNewGObject (ForeignPtr Font -> Font, FinalizerPtr Font)
    forall {a}. (ForeignPtr Font -> Font, FinalizerPtr a)
    mkFont ((\Ptr pangoItem
    hsc_ptr -> Ptr pangoItem -> Int -> IO (Ptr Font)
    forall b. Ptr b -> Int -> IO (Ptr Font)
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr pangoItem
    hsc_ptr Int
    32) Ptr pangoItem
    ptr)
    {-# LINE 224 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- Get the font of a PangoAnalysis within a PangoItem.
    pangoItemRawGetLanguage :: Ptr pangoItem -> IO (Ptr CChar)
    pangoItemRawGetLanguage :: forall pangoItem. Ptr pangoItem -> IO CString
    pangoItemRawGetLanguage Ptr pangoItem
    ptr =
      (\Ptr pangoItem
    hsc_ptr -> Ptr pangoItem -> Int -> IO CString
    forall b. Ptr b -> Int -> IO CString
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr pangoItem
    hsc_ptr Int
    48) Ptr pangoItem
    ptr
    {-# LINE 229 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- Get the offset at which a PangoItem starts
    pangoItemRawGetOffset :: Ptr pangoItem -> IO Int32
    {-# LINE 232 "Graphics/Rendering/Pango/Structs.hsc" #-}
    pangoItemRawGetOffset = (\hsc_ptr -> peekByteOff hsc_ptr 0)
    {-# LINE 233 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- Get the number of bytes that the PangoItem affects
    pangoItemRawGetLength :: Ptr pangoItem -> IO Int32
    {-# LINE 236 "Graphics/Rendering/Pango/Structs.hsc" #-}
    pangoItemRawGetLength = (\hsc_ptr -> peekByteOff hsc_ptr 4)
    {-# LINE 237 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- Get the PangoAnalysis within a PangoItem
    pangoItemRawAnalysis :: Ptr pangoItem -> Ptr pangoAnalysis
    pangoItemRawAnalysis :: forall a b. Ptr a -> Ptr b
    pangoItemRawAnalysis = (\Ptr pangoItem
    hsc_ptr -> Ptr pangoItem
    hsc_ptr Ptr pangoItem -> Int -> Ptr pangoAnalysis
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` Int
    16)
    {-# LINE 241 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- Get the text direction of this PangoItem.
    pangoItemRawGetLevel :: Ptr pangoItem -> IO Bool
    pangoItemRawGetLevel :: forall pangoItem. Ptr pangoItem -> IO Bool
    pangoItemRawGetLevel Ptr pangoItem
    ptr = do
      Word8
    level <- (\Ptr pangoItem
    hsc_ptr -> Ptr pangoItem -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr pangoItem
    hsc_ptr Int
    40) Ptr pangoItem
    ptr
    {-# LINE 246 "Graphics/Rendering/Pango/Structs.hsc" #-}
      return (toBool (level :: Word8))
    {-# LINE 247 "Graphics/Rendering/Pango/Structs.hsc" #-}

    -- Set the start and end position of an attribute
    setAttrPos :: UTFCorrection -> Int -> Int -> IO (Ptr ()) -> IO (Ptr ())
    setAttrPos :: UTFCorrection -> Int -> Int -> IO (Ptr ()) -> IO (Ptr ())
    setAttrPos UTFCorrection
    correct Int
    start Int
    end IO (Ptr ())
    act = do
      Ptr ()
    atPtr <- IO (Ptr ())
    act
      (\Ptr ()
    hsc_ptr -> Ptr () -> Int -> Word32 -> IO ()
    forall b. Ptr b -> Int -> Word32 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr ()
    hsc_ptr Int
    8) Ptr ()
    atPtr
    {-# LINE 253 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (fromIntegral (ofsToUTF start correct) :: Word32)
    {-# LINE 254 "Graphics/Rendering/Pango/Structs.hsc" #-}
      (\hsc_ptr -> pokeByteOff hsc_ptr 12) atPtr
    {-# LINE 255 "Graphics/Rendering/Pango/Structs.hsc" #-}
        (fromIntegral (ofsToUTF end correct) :: Word32)
    {-# LINE 256 "Graphics/Rendering/Pango/Structs.hsc" #-}
      return atPtr

    -- | Attributes for 'PangoItem's.
    --
    -- * A given attribute is applied from its start position 'paStart' up,
    --   but not including the end position, 'paEnd'.
    --
    data PangoAttribute
      -- | A hint as to what language this piece of text is written in.
      = AttrLanguage { PangoAttribute -> Int
    paStart :: Int, PangoAttribute -> Int
    paEnd :: Int, PangoAttribute -> Language
    paLang :: Language }
      -- | The font family, e.g. @sans serif@.
      | AttrFamily { paStart :: Int, paEnd :: Int, PangoAttribute -> DefaultGlibString
    paFamily :: DefaultGlibString }
      -- | The slant of the current font.
      | AttrStyle { paStart :: Int, paEnd :: Int, PangoAttribute -> FontStyle
    paStyle :: FontStyle }
      -- | Weight of font, e.g. 'WeightBold'.
      | AttrWeight { paStart :: Int, paEnd :: Int, PangoAttribute -> Weight
    paWeight :: Weight }
      -- | 'VariantSmallCaps' will display lower case letters as small
      -- upper case letters (if the font supports this).
      | AttrVariant { paStart :: Int, paEnd :: Int, PangoAttribute -> Variant
    paVariant :: Variant }
      -- | Stretch or condense the width of the letters.
      | AttrStretch { paStart :: Int, paEnd :: Int, PangoAttribute -> Stretch
    paStretch :: Stretch }
      -- | Specify the size of the font in points.
      | AttrSize { paStart :: Int, paEnd :: Int, PangoAttribute -> Double
    paSize :: Double }

    {-# LINE 280 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Specify the size of the font in device units (pixels).
      --
      -- * Available in Pango 1.8.0 and higher.
      --
      | AttrAbsSize { paStart :: Int, paEnd :: Int, paSize :: Double }

    {-# LINE 286 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Specify several attributes of a font at once. Note that no deep copy
      --   of the description is made when this attributes is passed to or received
      --   from functions.
        | AttrFontDescription { paStart :: Int, paEnd :: Int,
                              PangoAttribute -> FontDescription
    paFontDescription :: FontDescription }
      -- | Specify the foreground color.
      | AttrForeground { paStart :: Int, paEnd :: Int, PangoAttribute -> Color
    paColor :: Color }
      -- | Specify the background color.
      | AttrBackground { paStart :: Int, paEnd :: Int, paColor :: Color }
      -- | Specify the kind of underline, e.g. 'UnderlineSingle'.
      | AttrUnderline { paStart :: Int, paEnd :: Int, PangoAttribute -> Underline
    paUnderline :: Underline }

    {-# LINE 299 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Specify the color of an underline.
      --
      -- * Available in Pango 1.8.0 and higher.
      --
      | AttrUnderlineColor { paStart :: Int, paEnd :: Int, paColor :: Color }

    {-# LINE 305 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Specify if this piece of text should have a line through it.
      | AttrStrikethrough { paStart :: Int, paEnd :: Int, PangoAttribute -> Bool
    paStrikethrough :: Bool }

    {-# LINE 309 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Specify the color of the strike through line.
      --
      -- * Available in Pango 1.8.0 and higher.
      --
      | AttrStrikethroughColor { paStart :: Int, paEnd :: Int, paColor :: Color }

    {-# LINE 315 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Displace the text vertically. Positive values move the text upwards.
      | AttrRise { paStart :: Int, paEnd :: Int, PangoAttribute -> Double
    paRise :: Double }

    {-# LINE 318 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Restrict the amount of what is drawn of the marked shapes.
      --
      -- * Available in Pango 1.8.0 and higher.
      --
      | AttrShape { paStart :: Int, paEnd :: Int, PangoAttribute -> PangoRectangle
    paInk :: PangoRectangle,
                    PangoAttribute -> PangoRectangle
    paLogical :: PangoRectangle }

    {-# LINE 325 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Scale the font up (values greater than one) or shrink the font.
      | AttrScale { paStart :: Int, paEnd :: Int, PangoAttribute -> Double
    paScale :: Double }

    {-# LINE 328 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Determine if a fall back font should be substituted if no matching
      -- font is available.
      | AttrFallback { paStart :: Int, paEnd :: Int, PangoAttribute -> Bool
    paFallback :: Bool }

    {-# LINE 332 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 333 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Add extra space between graphemes of the text.
      --
      -- * Available in Pango 1.6.0 and higher.
      --
      | AttrLetterSpacing { paStart :: Int, paEnd :: Int,
                            PangoAttribute -> Double
    paLetterSpacing :: Double }

    {-# LINE 340 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 341 "Graphics/Rendering/Pango/Structs.hsc" #-}
      -- | Sets the gravity field of a font description. The gravity field specifies
      -- how the glyphs should be rotated. If gravity is 'GravityAuto', this
      -- actually unsets the gravity mask on the font description.
      --
      -- * This function is seldom useful to the user. Gravity should normally be
      --   set on a 'PangoContext'.
      --
      -- * Available in Pango 1.16.0 and higher.
      --
      | AttrGravity { paStart :: Int, paEnd :: Int,
                            PangoAttribute -> PangoGravity
    paGravity :: PangoGravity }

            -- | Set the way horizontal scripts behave in a vertical context.
      --
      -- * Available in Pango 1.16.0 and higher.
      --
            | AttrGravityHint  { paStart :: Int, paEnd :: Int,
                            PangoAttribute -> PangoGravityHint
    paGravityHint :: PangoGravityHint }

    {-# LINE 360 "Graphics/Rendering/Pango/Structs.hsc" #-}
      deriving Show

    -- | Convert a pointer to an attribute to an attribute.
    readAttr :: UTFCorrection -> CPangoAttribute -> IO PangoAttribute
    readAttr :: UTFCorrection -> Ptr () -> IO PangoAttribute
    readAttr UTFCorrection
    correct Ptr ()
    attrPtr = do
      Ptr Any
    klassPtr <- (\Ptr ()
    hsc_ptr -> Ptr () -> Int -> IO (Ptr Any)
    forall b. Ptr b -> Int -> IO (Ptr Any)
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr ()
    hsc_ptr Int
    0) Ptr ()
    attrPtr
    {-# LINE 366 "Graphics/Rendering/Pango/Structs.hsc" #-}
      startByte <- (\hsc_ptr -> peekByteOff hsc_ptr 8) attrPtr
    {-# LINE 367 "Graphics/Rendering/Pango/Structs.hsc" #-}
      endByte <- (\hsc_ptr -> peekByteOff hsc_ptr 12) attrPtr
    {-# LINE 368 "Graphics/Rendering/Pango/Structs.hsc" #-}
      ty <- (\hsc_ptr -> peekByteOff hsc_ptr 0) klassPtr
    {-# LINE 369 "Graphics/Rendering/Pango/Structs.hsc" #-}
      let b :: Int
          b = ofsFromUTF (fromIntegral (startByte :: Word32)) correct
    {-# LINE 371 "Graphics/Rendering/Pango/Structs.hsc" #-}
          e :: Int
          e = ofsFromUTF (fromIntegral (endByte :: Word32)) correct
    {-# LINE 373 "Graphics/Rendering/Pango/Structs.hsc" #-}
      case ty :: Word32 of
    {-# LINE 374 "Graphics/Rendering/Pango/Structs.hsc" #-}
        1 -> do
    {-# LINE 375 "Graphics/Rendering/Pango/Structs.hsc" #-}
          lang <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 376 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrLanguage b e (Language lang)
        2 -> do
    {-# LINE 378 "Graphics/Rendering/Pango/Structs.hsc" #-}
          strPtr <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 379 "Graphics/Rendering/Pango/Structs.hsc" #-}
          str <- peekUTFString strPtr
          return $ AttrFamily b e str
        3 -> do
    {-# LINE 382 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 383 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrStyle b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 384 "Graphics/Rendering/Pango/Structs.hsc" #-}
        4 -> do
    {-# LINE 385 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 386 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrWeight b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 387 "Graphics/Rendering/Pango/Structs.hsc" #-}
        5 -> do
    {-# LINE 388 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 389 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrVariant b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 390 "Graphics/Rendering/Pango/Structs.hsc" #-}
        6 -> do
    {-# LINE 391 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 392 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrStretch b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 393 "Graphics/Rendering/Pango/Structs.hsc" #-}
        7 -> do
    {-# LINE 394 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 395 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrSize b e (realToFrac (v::Double))
    {-# LINE 396 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 397 "Graphics/Rendering/Pango/Structs.hsc" #-}
        20 -> do
    {-# LINE 398 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 399 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrAbsSize b e (realToFrac (v::Double))
    {-# LINE 400 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 401 "Graphics/Rendering/Pango/Structs.hsc" #-}
        8 -> do
    {-# LINE 402 "Graphics/Rendering/Pango/Structs.hsc" #-}
          fdPtr <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 403 "Graphics/Rendering/Pango/Structs.hsc" #-}
          fd <- makeNewFontDescription fdPtr
          return $ AttrFontDescription b e fd
        9 -> do
    {-# LINE 406 "Graphics/Rendering/Pango/Structs.hsc" #-}
          col <- peekPangoColor ((\hsc_ptr -> hsc_ptr `plusPtr` 16) attrPtr)
    {-# LINE 407 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrForeground b e col
        10 -> do
    {-# LINE 409 "Graphics/Rendering/Pango/Structs.hsc" #-}
          col <- peekPangoColor ((\hsc_ptr -> hsc_ptr `plusPtr` 16) attrPtr)
    {-# LINE 410 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrBackground b e col
        11 -> do
    {-# LINE 412 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 413 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrUnderline b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 414 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 416 "Graphics/Rendering/Pango/Structs.hsc" #-}
        18 -> do
    {-# LINE 417 "Graphics/Rendering/Pango/Structs.hsc" #-}
          col <- peekPangoColor ((\hsc_ptr -> hsc_ptr `plusPtr` 16) attrPtr)
    {-# LINE 418 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrUnderlineColor b e col

    {-# LINE 420 "Graphics/Rendering/Pango/Structs.hsc" #-}
        12 -> do
    {-# LINE 421 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 422 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrStrikethrough b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 423 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 425 "Graphics/Rendering/Pango/Structs.hsc" #-}
        19 -> do
    {-# LINE 426 "Graphics/Rendering/Pango/Structs.hsc" #-}
          col <- peekPangoColor ((\hsc_ptr -> hsc_ptr `plusPtr` 16) attrPtr)
    {-# LINE 427 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrStrikethroughColor b e col

    {-# LINE 429 "Graphics/Rendering/Pango/Structs.hsc" #-}
        13 -> do
    {-# LINE 430 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 431 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrRise b e  (realToFrac (v::Double))
    {-# LINE 432 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 433 "Graphics/Rendering/Pango/Structs.hsc" #-}
        14 -> do
    {-# LINE 434 "Graphics/Rendering/Pango/Structs.hsc" #-}
          rect1 <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 435 "Graphics/Rendering/Pango/Structs.hsc" #-}
          rect2 <- (\hsc_ptr -> peekByteOff hsc_ptr 32) attrPtr
    {-# LINE 436 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrShape b e rect1 rect2

    {-# LINE 438 "Graphics/Rendering/Pango/Structs.hsc" #-}
        15 -> do
    {-# LINE 439 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 440 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrScale b e (realToFrac (v::Double))
    {-# LINE 441 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 442 "Graphics/Rendering/Pango/Structs.hsc" #-}
        16 -> do
    {-# LINE 443 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 444 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrFallback b e (toBool (v::Int32))
    {-# LINE 445 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 446 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 447 "Graphics/Rendering/Pango/Structs.hsc" #-}
        17 -> do
    {-# LINE 448 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 449 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrLetterSpacing b e (realToFrac (v::Double))
    {-# LINE 450 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 451 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 452 "Graphics/Rendering/Pango/Structs.hsc" #-}
        21 -> do
    {-# LINE 453 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 454 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrGravity b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 455 "Graphics/Rendering/Pango/Structs.hsc" #-}
        22 -> do
    {-# LINE 456 "Graphics/Rendering/Pango/Structs.hsc" #-}
          v <- (\hsc_ptr -> peekByteOff hsc_ptr 16) attrPtr
    {-# LINE 457 "Graphics/Rendering/Pango/Structs.hsc" #-}
          return $ AttrGravityHint b e (toEnum (fromIntegral (v::Int32)))
    {-# LINE 458 "Graphics/Rendering/Pango/Structs.hsc" #-}

    {-# LINE 459 "Graphics/Rendering/Pango/Structs.hsc" #-}
        _ -> error "extracting pango attributes: unknown attribute type"