    {-# LINE 2 "./Graphics/Rendering/Pango/GlyphStorage.chs" #-}
    {-# OPTIONS_HADDOCK hide #-}
    -- -*-haskell-*-
    -- GIMP Toolkit (GTK) Glyph Storage of Pango
    --
    -- Author : Axel Simon
    --
    -- Created: 31 July 2005
    --
    -- Copyright (C) 2005 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.GlyphStorage (
      glyphItemExtents,
      glyphItemExtentsRange,
      glyphItemIndexToX,
      glyphItemXToIndex,
      glyphItemGetLogicalWidths,

      glyphItemSplit

      ) where

    import Control.Monad (liftM)
    import System.Glib.FFI
    import Graphics.Rendering.Pango.Types (Font(..))
    import System.Glib.UTFString
    import Graphics.Rendering.Pango.BasicTypes
    {-# LINE 48 "./Graphics/Rendering/Pango/GlyphStorage.chs" #-}
    import Graphics.Rendering.Pango.Structs
    import Control.Exception (throwIO, ArrayException(IndexOutOfBounds) )

    {-# LINE 52 "./Graphics/Rendering/Pango/GlyphStorage.chs" #-}

    --------------------
    -- Methods

    -- | Ask for bounding rectangles of this glyph sequence.
    --
    -- * Compute the ink and logical extents of a glyph string. The
    -- logical size is used for positioning, the ink size is the smallest
    -- bounding box that includes all character pixels. The ink size can be
    -- smaller or larger than the logical size.
    --
    glyphItemExtents :: GlyphItem -> IO (PangoRectangle, PangoRectangle)
    glyphItemExtents :: GlyphItem -> IO (PangoRectangle, PangoRectangle)
    glyphItemExtents (GlyphItem PangoItem
    pi GlyphStringRaw
    self) = do
      Font
    font <- PangoItem -> IO Font
    pangoItemGetFont PangoItem
    pi
      (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
     -> IO (PangoRectangle, PangoRectangle))
    -> (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. (a -> b) -> a -> b
    $ \Ptr PangoRectangle
    inkPtr -> (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
     -> IO (PangoRectangle, PangoRectangle))
    -> (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. (a -> b) -> a -> b
    $ \Ptr PangoRectangle
    logPtr -> do
      (\(GlyphStringRaw ForeignPtr GlyphStringRaw
    arg1) (Font ForeignPtr Font
    arg2) Ptr ()
    arg3 Ptr ()
    arg4 -> ForeignPtr GlyphStringRaw -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GlyphStringRaw
    arg1 ((Ptr GlyphStringRaw -> IO ()) -> IO ())
    -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr GlyphStringRaw
    argPtr1 ->ForeignPtr Font -> (Ptr Font -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr Font
    arg2 ((Ptr Font -> IO ()) -> IO ()) -> (Ptr Font -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr Font
    argPtr2 ->Ptr GlyphStringRaw -> Ptr Font -> Ptr () -> Ptr () -> IO ()
    pango_glyph_string_extents Ptr GlyphStringRaw
    argPtr1 Ptr Font
    argPtr2 Ptr ()
    arg3 Ptr ()
    arg4) GlyphStringRaw
    self Font
    font
        (Ptr PangoRectangle -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr PangoRectangle
    inkPtr) (Ptr PangoRectangle -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr PangoRectangle
    logPtr)
      PangoRectangle
    ink <- Ptr PangoRectangle -> IO PangoRectangle
    forall a. Storable a => Ptr a -> IO a
    peek Ptr PangoRectangle
    inkPtr
      PangoRectangle
    log <- Ptr PangoRectangle -> IO PangoRectangle
    forall a. Storable a => Ptr a -> IO a
    peek Ptr PangoRectangle
    logPtr
      (PangoRectangle, PangoRectangle)
    -> IO (PangoRectangle, PangoRectangle)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (PangoRectangle
    ink, PangoRectangle
    log)

    -- | Ask for bounding rectangles for a sub-range of a glyph sequence.
    --
    -- * The returned rectangles are relative to the given sub-range, that is,
    -- the result of this function is the same as if 'glyphItemExtents'
    -- were called on the sub-string.
    --
    glyphItemExtentsRange :: GlyphItem -> Int -> Int ->
                               IO (PangoRectangle, PangoRectangle)

    glyphItemExtentsRange :: GlyphItem -> Int -> Int -> IO (PangoRectangle, PangoRectangle)
    glyphItemExtentsRange (GlyphItem pi :: PangoItem
    pi@(PangoItem (PangoString UTFCorrection
    uc CInt
    _ ForeignPtr CChar
    _) PangoItemRaw
    _) GlyphStringRaw
    self)
      Int
    start Int
    end = do
      Font
    font <- PangoItem -> IO Font
    pangoItemGetFont PangoItem
    pi
      (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
     -> IO (PangoRectangle, PangoRectangle))
    -> (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. (a -> b) -> a -> b
    $ \Ptr PangoRectangle
    logPtr -> (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
     -> IO (PangoRectangle, PangoRectangle))
    -> (Ptr PangoRectangle -> IO (PangoRectangle, PangoRectangle))
    -> IO (PangoRectangle, PangoRectangle)
    forall a b. (a -> b) -> a -> b
    $ \Ptr PangoRectangle
    inkPtr -> do
      (\(GlyphStringRaw ForeignPtr GlyphStringRaw
    arg1) CInt
    arg2 CInt
    arg3 (Font ForeignPtr Font
    arg4) Ptr ()
    arg5 Ptr ()
    arg6 -> ForeignPtr GlyphStringRaw -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GlyphStringRaw
    arg1 ((Ptr GlyphStringRaw -> IO ()) -> IO ())
    -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr GlyphStringRaw
    argPtr1 ->ForeignPtr Font -> (Ptr Font -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr Font
    arg4 ((Ptr Font -> IO ()) -> IO ()) -> (Ptr Font -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr Font
    argPtr4 ->Ptr GlyphStringRaw
    -> CInt -> CInt -> Ptr Font -> Ptr () -> Ptr () -> IO ()
    pango_glyph_string_extents_range Ptr GlyphStringRaw
    argPtr1 CInt
    arg2 CInt
    arg3 Ptr Font
    argPtr4 Ptr ()
    arg5 Ptr ()
    arg6) GlyphStringRaw
    self
        (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int -> UTFCorrection -> Int
    ofsToUTF Int
    start UTFCorrection
    uc)) (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int -> UTFCorrection -> Int
    ofsToUTF Int
    end UTFCorrection
    uc))
        Font
    font (Ptr PangoRectangle -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr PangoRectangle
    logPtr) (Ptr PangoRectangle -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr PangoRectangle
    inkPtr)
      PangoRectangle
    log <- Ptr PangoRectangle -> IO PangoRectangle
    forall a. Storable a => Ptr a -> IO a
    peek Ptr PangoRectangle
    logPtr
      PangoRectangle
    ink <- Ptr PangoRectangle -> IO PangoRectangle
    forall a. Storable a => Ptr a -> IO a
    peek Ptr PangoRectangle
    inkPtr
      (PangoRectangle, PangoRectangle)
    -> IO (PangoRectangle, PangoRectangle)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (PangoRectangle
    log, PangoRectangle
    ink)

    -- | Get the horizontal position of a character.
    --
    -- * Clusters (e.g. \"e\" with an accent modifier) are divided up into equal
    -- portions.
    --
    glyphItemIndexToX :: GlyphItem -- ^ the rendered string
                        -> Int -- ^ the index into the string
                        -> Bool -- ^ return the beginning (@False@) or the end
                                -- of the character
                        -> IO Double
    glyphItemIndexToX :: GlyphItem -> Int -> Bool -> IO Double
    glyphItemIndexToX (GlyphItem (PangoItem PangoString
    ps PangoItemRaw
    pir) GlyphStringRaw
    gs) Int
    pos Bool
    beg =
      PangoItemRaw -> (Ptr PangoItemRaw -> IO Double) -> IO Double
    forall a. PangoItemRaw -> (Ptr PangoItemRaw -> IO a) -> IO a
    withPangoItemRaw PangoItemRaw
    pir ((Ptr PangoItemRaw -> IO Double) -> IO Double)
    -> (Ptr PangoItemRaw -> IO Double) -> IO Double
    forall a b. (a -> b) -> a -> b
    $ \Ptr PangoItemRaw
    pirPtr -> (Ptr CInt -> IO Double) -> IO Double
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO Double) -> IO Double)
    -> (Ptr CInt -> IO Double) -> IO Double
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    intPtr ->
      PangoString
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO Double) -> IO Double
    forall a.
    PangoString -> (UTFCorrection -> CInt -> Ptr CChar -> IO a) -> IO a
    withPangoString PangoString
    ps ((UTFCorrection -> CInt -> Ptr CChar -> IO Double) -> IO Double)
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO Double) -> IO Double
    forall a b. (a -> b) -> a -> b
    $ \UTFCorrection
    uc CInt
    l Ptr CChar
    strPtr -> do
        (\(GlyphStringRaw ForeignPtr GlyphStringRaw
    arg1) Ptr CChar
    arg2 CInt
    arg3 Ptr ()
    arg4 CInt
    arg5 CInt
    arg6 Ptr CInt
    arg7 -> ForeignPtr GlyphStringRaw -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GlyphStringRaw
    arg1 ((Ptr GlyphStringRaw -> IO ()) -> IO ())
    -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr GlyphStringRaw
    argPtr1 ->Ptr GlyphStringRaw
    -> Ptr CChar -> CInt -> Ptr () -> CInt -> CInt -> Ptr CInt -> IO ()
    pango_glyph_string_index_to_x Ptr GlyphStringRaw
    argPtr1 Ptr CChar
    arg2 CInt
    arg3 Ptr ()
    arg4 CInt
    arg5 CInt
    arg6 Ptr CInt
    arg7) GlyphStringRaw
    gs Ptr CChar
    strPtr
          (CInt -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    l) (Ptr PangoItemRaw -> Ptr ()
    forall a b. Ptr a -> Ptr b
    pangoItemRawAnalysis Ptr PangoItemRaw
    pirPtr)
          (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int -> UTFCorrection -> Int
    ofsToUTF Int
    pos UTFCorrection
    uc)) (Bool -> CInt
    forall a. Num a => Bool -> a
    fromBool Bool
    beg) Ptr CInt
    intPtr
        (CInt -> Double) -> IO CInt -> IO Double
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM CInt -> Double
    intToPu (IO CInt -> IO Double) -> IO CInt -> IO Double
    forall a b. (a -> b) -> a -> b
    $ Ptr CInt -> IO CInt
    forall a. Storable a => Ptr a -> IO a
    peek Ptr CInt
    intPtr

    -- | Get the character at the given horizontal position.
    --
    -- * The position is clipped to the width of this line.
    --
    -- * The function returns the position in the string that corresponds
    -- to the given horizontal location. Furthermore, if the position lies
    -- on the first half of the character, @False@ is returned.
    --
    glyphItemXToIndex :: GlyphItem -> Double -> IO (Int, Bool)
    glyphItemXToIndex :: GlyphItem -> Double -> IO (Int, Bool)
    glyphItemXToIndex (GlyphItem (PangoItem PangoString
    ps PangoItemRaw
    pir) GlyphStringRaw
    gs) Double
    pos =
      PangoItemRaw
    -> (Ptr PangoItemRaw -> IO (Int, Bool)) -> IO (Int, Bool)
    forall a. PangoItemRaw -> (Ptr PangoItemRaw -> IO a) -> IO a
    withPangoItemRaw PangoItemRaw
    pir ((Ptr PangoItemRaw -> IO (Int, Bool)) -> IO (Int, Bool))
    -> (Ptr PangoItemRaw -> IO (Int, Bool)) -> IO (Int, Bool)
    forall a b. (a -> b) -> a -> b
    $ \Ptr PangoItemRaw
    pirPtr -> (Ptr CInt -> IO (Int, Bool)) -> IO (Int, Bool)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO (Int, Bool)) -> IO (Int, Bool))
    -> (Ptr CInt -> IO (Int, Bool)) -> IO (Int, Bool)
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    intPtr ->
      (Ptr CInt -> IO (Int, Bool)) -> IO (Int, Bool)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO (Int, Bool)) -> IO (Int, Bool))
    -> (Ptr CInt -> IO (Int, Bool)) -> IO (Int, Bool)
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    boolPtr -> PangoString
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO (Int, Bool))
    -> IO (Int, Bool)
    forall a.
    PangoString -> (UTFCorrection -> CInt -> Ptr CChar -> IO a) -> IO a
    withPangoString PangoString
    ps ((UTFCorrection -> CInt -> Ptr CChar -> IO (Int, Bool))
     -> IO (Int, Bool))
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO (Int, Bool))
    -> IO (Int, Bool)
    forall a b. (a -> b) -> a -> b
    $ \UTFCorrection
    uc CInt
    l Ptr CChar
    strPtr -> do
        (\(GlyphStringRaw ForeignPtr GlyphStringRaw
    arg1) Ptr CChar
    arg2 CInt
    arg3 Ptr ()
    arg4 CInt
    arg5 Ptr CInt
    arg6 Ptr CInt
    arg7 -> ForeignPtr GlyphStringRaw -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GlyphStringRaw
    arg1 ((Ptr GlyphStringRaw -> IO ()) -> IO ())
    -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr GlyphStringRaw
    argPtr1 ->Ptr GlyphStringRaw
    -> Ptr CChar
    -> CInt
    -> Ptr ()
    -> CInt
    -> Ptr CInt
    -> Ptr CInt
    -> IO ()
    pango_glyph_string_x_to_index Ptr GlyphStringRaw
    argPtr1 Ptr CChar
    arg2 CInt
    arg3 Ptr ()
    arg4 CInt
    arg5 Ptr CInt
    arg6 Ptr CInt
    arg7) GlyphStringRaw
    gs Ptr CChar
    strPtr
          (CInt -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    l) (Ptr PangoItemRaw -> Ptr ()
    forall a b. Ptr a -> Ptr b
    pangoItemRawAnalysis Ptr PangoItemRaw
    pirPtr) (Double -> CInt
    puToInt Double
    pos)
          Ptr CInt
    intPtr Ptr CInt
    boolPtr
        CInt
    int <- Ptr CInt -> IO CInt
    forall a. Storable a => Ptr a -> IO a
    peek Ptr CInt
    intPtr
        CInt
    bool <- Ptr CInt -> IO CInt
    forall a. Storable a => Ptr a -> IO a
    peek Ptr CInt
    boolPtr
        (Int, Bool) -> IO (Int, Bool)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int -> UTFCorrection -> Int
    ofsFromUTF (CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    int) UTFCorrection
    uc, CInt -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool CInt
    bool)

    -- | Retrieve the width of every character in a string.
    --
    -- * The boolean parameter
    -- determines if the returned array starts with the leftmost glyph
    -- (@False@) or with the rightmost glyph (@True@). If @Nothing@ is
    -- passed in, the direction is taken from the 'GlyphItem', i.e.,
    -- the array starts with the leftmost glyph for left-to-right text
    -- and with the rightmost glyph for right-to-left text. When multiple
    -- characters compose a single glyph, the width of this glyph is
    -- divided among the characters that compose this cluster.
    --
    glyphItemGetLogicalWidths :: GlyphItem -> Maybe Bool -> IO [Double]
    glyphItemGetLogicalWidths :: GlyphItem -> Maybe Bool -> IO [Double]
    glyphItemGetLogicalWidths (GlyphItem (PangoItem PangoString
    ps PangoItemRaw
    pir) GlyphStringRaw
    gs) Maybe Bool
    mDir = do
      Bool
    dir <- case Maybe Bool
    mDir of
        Just Bool
    dir -> Bool -> IO Bool
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Bool
    dir
        Maybe Bool
    Nothing -> PangoItemRaw -> (Ptr PangoItemRaw -> IO Bool) -> IO Bool
    forall a. PangoItemRaw -> (Ptr PangoItemRaw -> IO a) -> IO a
    withPangoItemRaw PangoItemRaw
    pir Ptr PangoItemRaw -> IO Bool
    forall pangoItem. Ptr pangoItem -> IO Bool
    pangoItemRawGetLevel
      PangoString
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO [Double])
    -> IO [Double]
    forall a.
    PangoString -> (UTFCorrection -> CInt -> Ptr CChar -> IO a) -> IO a
    withPangoString PangoString
    ps ((UTFCorrection -> CInt -> Ptr CChar -> IO [Double])
     -> IO [Double])
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO [Double])
    -> IO [Double]
    forall a b. (a -> b) -> a -> b
    $ \UTFCorrection
    uc CInt
    l Ptr CChar
    strPtr -> do
        CLong
    logLen <- Ptr CChar -> CLong -> IO CLong
    g_utf8_strlen Ptr CChar
    strPtr (CInt -> CLong
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    l)
        Int -> (Ptr CInt -> IO [Double]) -> IO [Double]
    forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
    allocaArray (CLong -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CLong
    logLen) ((Ptr CInt -> IO [Double]) -> IO [Double])
    -> (Ptr CInt -> IO [Double]) -> IO [Double]
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    arrPtr -> do
          (\(GlyphStringRaw ForeignPtr GlyphStringRaw
    arg1) Ptr CChar
    arg2 CInt
    arg3 CInt
    arg4 Ptr CInt
    arg5 -> ForeignPtr GlyphStringRaw -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GlyphStringRaw
    arg1 ((Ptr GlyphStringRaw -> IO ()) -> IO ())
    -> (Ptr GlyphStringRaw -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr GlyphStringRaw
    argPtr1 ->Ptr GlyphStringRaw
    -> Ptr CChar -> CInt -> CInt -> Ptr CInt -> IO ()
    pango_glyph_string_get_logical_widths Ptr GlyphStringRaw
    argPtr1 Ptr CChar
    arg2 CInt
    arg3 CInt
    arg4 Ptr CInt
    arg5)
    {-# LINE 150 "./Graphics/Rendering/Pango/GlyphStorage.chs" #-}
            GlyphStringRaw
    gs Ptr CChar
    strPtr (CInt -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    l) (Bool -> CInt
    forall a. Num a => Bool -> a
    fromBool Bool
    dir) Ptr CInt
    arrPtr
          [CInt]
    elems <- Int -> Ptr CInt -> IO [CInt]
    forall a. Storable a => Int -> Ptr a -> IO [a]
    peekArray (CLong -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CLong
    logLen) Ptr CInt
    arrPtr
          [Double] -> IO [Double]
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ((CInt -> Double) -> [CInt] -> [Double]
    forall a b. (a -> b) -> [a] -> [b]
    map CInt -> Double
    intToPu [CInt]
    elems)

    -- | Split a 'GlyphItem' at the given index.
    --
    -- * The given 'GlyphItem' is split at the given index. The index must be
    -- at least one and not greater or equal to length, i.e. the item must
    -- be split into two non-empty segments. The function throws an
    -- 'ArrayException' if the index is out of bounds.
    --
    glyphItemSplit :: GlyphItem -> Int -> IO (GlyphItem, GlyphItem)
    glyphItemSplit :: GlyphItem -> Int -> IO (GlyphItem, GlyphItem)
    glyphItemSplit (GlyphItem (PangoItem PangoString
    ps PangoItemRaw
    pir) GlyphStringRaw
    gs) Int
    pos = do
      Ptr PangoItemRaw
    pirPtr1 <- (\(PangoItemRaw ForeignPtr PangoItemRaw
    arg1) -> ForeignPtr PangoItemRaw
    -> (Ptr PangoItemRaw -> IO (Ptr PangoItemRaw))
    -> IO (Ptr PangoItemRaw)
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr PangoItemRaw
    arg1 ((Ptr PangoItemRaw -> IO (Ptr PangoItemRaw))
     -> IO (Ptr PangoItemRaw))
    -> (Ptr PangoItemRaw -> IO (Ptr PangoItemRaw))
    -> IO (Ptr PangoItemRaw)
    forall a b. (a -> b) -> a -> b
    $ \Ptr PangoItemRaw
    argPtr1 ->Ptr PangoItemRaw -> IO (Ptr PangoItemRaw)
    pango_item_copy Ptr PangoItemRaw
    argPtr1) PangoItemRaw
    pir
      Ptr GlyphStringRaw
    gsrPtr1 <- (\(GlyphStringRaw ForeignPtr GlyphStringRaw
    arg1) -> ForeignPtr GlyphStringRaw
    -> (Ptr GlyphStringRaw -> IO (Ptr GlyphStringRaw))
    -> IO (Ptr GlyphStringRaw)
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr GlyphStringRaw
    arg1 ((Ptr GlyphStringRaw -> IO (Ptr GlyphStringRaw))
     -> IO (Ptr GlyphStringRaw))
    -> (Ptr GlyphStringRaw -> IO (Ptr GlyphStringRaw))
    -> IO (Ptr GlyphStringRaw)
    forall a b. (a -> b) -> a -> b
    $ \Ptr GlyphStringRaw
    argPtr1 ->Ptr GlyphStringRaw -> IO (Ptr GlyphStringRaw)
    pango_glyph_string_copy Ptr GlyphStringRaw
    argPtr1) GlyphStringRaw
    gs
      PangoItemRaw
    pir1 <- Ptr PangoItemRaw -> IO PangoItemRaw
    makeNewPangoItemRaw Ptr PangoItemRaw
    pirPtr1
      GlyphStringRaw
    gsr1 <- Ptr GlyphStringRaw -> IO GlyphStringRaw
    makeNewGlyphStringRaw Ptr GlyphStringRaw
    gsrPtr1
      Int
    -> (Ptr () -> IO (GlyphItem, GlyphItem))
    -> IO (GlyphItem, GlyphItem)
    forall a b. Int -> (Ptr a -> IO b) -> IO b
    allocaBytes Int
    32 ((Ptr () -> IO (GlyphItem, GlyphItem))
     -> IO (GlyphItem, GlyphItem))
    -> (Ptr () -> IO (GlyphItem, GlyphItem))
    -> IO (GlyphItem, GlyphItem)
    forall a b. (a -> b) -> a -> b
    $ \Ptr ()
    giPtr1 -> do
        (\Ptr ()
    ptr Ptr PangoItemRaw
    val -> do {Ptr () -> Int -> Ptr PangoItemRaw -> IO ()
    forall b. Ptr b -> Int -> Ptr PangoItemRaw -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr ()
    ptr Int
    0 (Ptr PangoItemRaw
    val::(Ptr PangoItemRaw))}) Ptr ()
    giPtr1 Ptr PangoItemRaw
    pirPtr1
        (\Ptr ()
    ptr Ptr GlyphStringRaw
    val -> do {Ptr () -> Int -> Ptr GlyphStringRaw -> IO ()
    forall b. Ptr b -> Int -> Ptr GlyphStringRaw -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr ()
    ptr Int
    8 (Ptr GlyphStringRaw
    val::(Ptr GlyphStringRaw))}) Ptr ()
    giPtr1 Ptr GlyphStringRaw
    gsrPtr1
        Ptr ()
    giPtr2 <- PangoString
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO (Ptr ()))
    -> IO (Ptr ())
    forall a.
    PangoString -> (UTFCorrection -> CInt -> Ptr CChar -> IO a) -> IO a
    withPangoString PangoString
    ps ((UTFCorrection -> CInt -> Ptr CChar -> IO (Ptr ()))
     -> IO (Ptr ()))
    -> (UTFCorrection -> CInt -> Ptr CChar -> IO (Ptr ()))
    -> IO (Ptr ())
    forall a b. (a -> b) -> a -> b
    $ \UTFCorrection
    uc CInt
    l Ptr CChar
    strPtr ->
          Ptr () -> Ptr CChar -> CInt -> IO (Ptr ())
    pango_glyph_item_split Ptr ()
    giPtr1 Ptr CChar
    strPtr
            (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int -> UTFCorrection -> Int
    ofsToUTF Int
    pos UTFCorrection
    uc))
        if Ptr ()
    giPtr2Ptr () -> Ptr () -> Bool
    forall a. Eq a => a -> a -> Bool
    ==Ptr ()
    forall a. Ptr a
    nullPtr then
           ArrayException -> IO (GlyphItem, GlyphItem)
    forall e a. Exception e => e -> IO a
    throwIO (String -> ArrayException
    IndexOutOfBounds
             (String
    "Graphics.Rendering.Pango.GlyphStorage."String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++
              String
    "glyphItemSplit: cannot split item at index "String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++Int -> String
    forall a. Show a => a -> String
    show Int
    pos)) else do
          Ptr PangoItemRaw
    pirPtr2 <- (\Ptr ()
    ptr -> do {Ptr () -> Int -> IO (Ptr PangoItemRaw)
    forall b. Ptr b -> Int -> IO (Ptr PangoItemRaw)
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr ()
    ptr Int
    0 ::IO (Ptr PangoItemRaw)}) Ptr ()
    giPtr2
          Ptr GlyphStringRaw
    gsrPtr2 <- (\Ptr ()
    ptr -> do {Ptr () -> Int -> IO (Ptr GlyphStringRaw)
    forall b. Ptr b -> Int -> IO (Ptr GlyphStringRaw)
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr ()
    ptr Int
    8 ::IO (Ptr GlyphStringRaw)}) Ptr ()
    giPtr2
          Ptr () -> IO ()
    g_free Ptr ()
    giPtr2
          PangoItemRaw
    pir2 <- Ptr PangoItemRaw -> IO PangoItemRaw
    makeNewPangoItemRaw Ptr PangoItemRaw
    pirPtr2
          GlyphStringRaw
    gsr2 <- Ptr GlyphStringRaw -> IO GlyphStringRaw
    makeNewGlyphStringRaw Ptr GlyphStringRaw
    gsrPtr2
          (GlyphItem, GlyphItem) -> IO (GlyphItem, GlyphItem)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (PangoItem -> GlyphStringRaw -> GlyphItem
    GlyphItem (PangoString -> PangoItemRaw -> PangoItem
    PangoItem PangoString
    ps PangoItemRaw
    pir2) GlyphStringRaw
    gsr2,
                  PangoItem -> GlyphStringRaw -> GlyphItem
    GlyphItem (PangoString -> PangoItemRaw -> PangoItem
    PangoItem PangoString
    ps PangoItemRaw
    pir1) GlyphStringRaw
    gsr1)

    foreign import ccall unsafe "pango_glyph_string_extents"
      pango_glyph_string_extents :: ((Ptr GlyphStringRaw) -> ((Ptr Font) -> ((Ptr ()) -> ((Ptr ()) -> (IO ())))))

    foreign import ccall unsafe "pango_glyph_string_extents_range"
      pango_glyph_string_extents_range :: ((Ptr GlyphStringRaw) -> (CInt -> (CInt -> ((Ptr Font) -> ((Ptr ()) -> ((Ptr ()) -> (IO ())))))))

    foreign import ccall unsafe "pango_glyph_string_index_to_x"
      pango_glyph_string_index_to_x :: ((Ptr GlyphStringRaw) -> ((Ptr CChar) -> (CInt -> ((Ptr ()) -> (CInt -> (CInt -> ((Ptr CInt) -> (IO ()))))))))

    foreign import ccall unsafe "pango_glyph_string_x_to_index"
      pango_glyph_string_x_to_index :: ((Ptr GlyphStringRaw) -> ((Ptr CChar) -> (CInt -> ((Ptr ()) -> (CInt -> ((Ptr CInt) -> ((Ptr CInt) -> (IO ()))))))))

    foreign import ccall unsafe "g_utf8_strlen"
      g_utf8_strlen :: ((Ptr CChar) -> (CLong -> (IO CLong)))

    foreign import ccall unsafe "pango_glyph_string_get_logical_widths"
      pango_glyph_string_get_logical_widths :: ((Ptr GlyphStringRaw) -> ((Ptr CChar) -> (CInt -> (CInt -> ((Ptr CInt) -> (IO ()))))))

    foreign import ccall unsafe "pango_item_copy"
      pango_item_copy :: ((Ptr PangoItemRaw) -> (IO (Ptr PangoItemRaw)))

    foreign import ccall unsafe "pango_glyph_string_copy"
      pango_glyph_string_copy :: ((Ptr GlyphStringRaw) -> (IO (Ptr GlyphStringRaw)))

    foreign import ccall unsafe "pango_glyph_item_split"
      pango_glyph_item_split :: ((Ptr ()) -> ((Ptr CChar) -> (CInt -> (IO (Ptr ())))))

    foreign import ccall unsafe "g_free"
      g_free :: ((Ptr ()) -> (IO ()))