{-# 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 <- PangoItem -> IO Font
pangoItemGetFont PangoItem
pi
  alloca $ \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)
  ink <- Ptr PangoRectangle -> IO PangoRectangle
forall a. Storable a => Ptr a -> IO a
peek Ptr PangoRectangle
inkPtr
  log <- peek logPtr
  return (ink, 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 <- PangoItem -> IO Font
pangoItemGetFont PangoItem
pi
  alloca $ \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)
  log <- Ptr PangoRectangle -> IO PangoRectangle
forall a. Storable a => Ptr a -> IO a
peek Ptr PangoRectangle
logPtr
  ink <- peek inkPtr
  return (log, 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
    int <- Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
intPtr
    bool <- peek boolPtr
    return (ofsFromUTF (fromIntegral int) uc, toBool 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
  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
  withPangoString ps $ \UTFCorrection
uc CInt
l Ptr CChar
strPtr -> do
    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)
    allocaArray (fromIntegral logLen) $ \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
      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
      return (map intToPu 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
  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
  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) gs
  pir1 <- makeNewPangoItemRaw pirPtr1
  gsr1 <- makeNewGlyphStringRaw gsrPtr1
  allocaBytes 32 $ \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
    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 giPtr2==nullPtr then
       throwIO (IndexOutOfBounds
         ("Graphics.Rendering.Pango.GlyphStorage."++
          "glyphItemSplit: cannot split item at index "++show pos)) else do
      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)}) giPtr2
      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)}) giPtr2
      g_free giPtr2
      pir2 <- makeNewPangoItemRaw pirPtr2
      gsr2 <- makeNewGlyphStringRaw gsrPtr2
      return (GlyphItem (PangoItem ps pir2) gsr2,
              GlyphItem (PangoItem ps pir1) 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 ()))