{- |
Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
A #PangoGlyphItemIter is an iterator over the clusters in a
#PangoGlyphItem. The forward direction of the
iterator is the logical direction of text. That is, with increasing
@start_index and @start_char values. If @glyph_item is right-to-left
(that is, if @glyph_item->item->analysis.level is odd),
then @start_glyph decreases as the iterator moves forward. Moreover,
in right-to-left cases, @start_glyph is greater than @end_glyph.
An iterator should be initialized using either of
pango_glyph_item_iter_init_start() and
pango_glyph_item_iter_init_end(), for forward and backward iteration
respectively, and walked over using any desired mixture of
pango_glyph_item_iter_next_cluster() and
pango_glyph_item_iter_prev_cluster(). A common idiom for doing a
forward iteration over the clusters is:
PangoGlyphItemIter cluster_iter;
gboolean have_cluster;
for (have_cluster = pango_glyph_item_iter_init_start (&cluster_iter,
glyph_item, text);
have_cluster;
have_cluster = pango_glyph_item_iter_next_cluster (&cluster_iter))
{
...
}
Note that @text is the start of the text for layout, which is then
indexed by @glyph_item->item->offset to get to the
text of @glyph_item. The @start_index and @end_index values can directly
index into @text. The @start_glyph, @end_glyph, @start_char, and @end_char
values however are zero-based for the @glyph_item. For each cluster, the
item pointed at by the start variables is included in the cluster while
the one pointed at by end variables is not.
None of the members of a #PangoGlyphItemIter should be modified manually.
-}
module GI.Pango.Structs.GlyphItemIter
(
-- * Exported types
GlyphItemIter(..) ,
newZeroGlyphItemIter ,
noGlyphItemIter ,
-- * Methods
-- ** glyphItemIterCopy
GlyphItemIterCopyMethodInfo ,
glyphItemIterCopy ,
-- ** glyphItemIterFree
GlyphItemIterFreeMethodInfo ,
glyphItemIterFree ,
-- ** glyphItemIterInitEnd
GlyphItemIterInitEndMethodInfo ,
glyphItemIterInitEnd ,
-- ** glyphItemIterInitStart
GlyphItemIterInitStartMethodInfo ,
glyphItemIterInitStart ,
-- ** glyphItemIterNextCluster
GlyphItemIterNextClusterMethodInfo ,
glyphItemIterNextCluster ,
-- ** glyphItemIterPrevCluster
GlyphItemIterPrevClusterMethodInfo ,
glyphItemIterPrevCluster ,
-- * Properties
-- ** EndChar
glyphItemIterReadEndChar ,
-- ** EndGlyph
glyphItemIterReadEndGlyph ,
-- ** EndIndex
glyphItemIterReadEndIndex ,
-- ** GlyphItem
glyphItemIterReadGlyphItem ,
-- ** StartChar
glyphItemIterReadStartChar ,
-- ** StartGlyph
glyphItemIterReadStartGlyph ,
-- ** StartIndex
glyphItemIterReadStartIndex ,
-- ** Text
glyphItemIterReadText ,
) where
import Prelude ()
import Data.GI.Base.ShortPrelude
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import GI.Pango.Types
import GI.Pango.Callbacks
newtype GlyphItemIter = GlyphItemIter (ForeignPtr GlyphItemIter)
foreign import ccall "pango_glyph_item_iter_get_type" c_pango_glyph_item_iter_get_type ::
IO GType
instance BoxedObject GlyphItemIter where
boxedType _ = c_pango_glyph_item_iter_get_type
-- | Construct a `GlyphItemIter` struct initialized to zero.
newZeroGlyphItemIter :: MonadIO m => m GlyphItemIter
newZeroGlyphItemIter = liftIO $ callocBoxedBytes 40 >>= wrapBoxed GlyphItemIter
noGlyphItemIter :: Maybe GlyphItemIter
noGlyphItemIter = Nothing
glyphItemIterReadGlyphItem :: GlyphItemIter -> IO GlyphItem
glyphItemIterReadGlyphItem s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO (Ptr GlyphItem)
val' <- (newBoxed GlyphItem) val
return val'
glyphItemIterReadText :: GlyphItemIter -> IO T.Text
glyphItemIterReadText s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 8) :: IO CString
val' <- cstringToText val
return val'
glyphItemIterReadStartGlyph :: GlyphItemIter -> IO Int32
glyphItemIterReadStartGlyph s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 16) :: IO Int32
return val
glyphItemIterReadStartIndex :: GlyphItemIter -> IO Int32
glyphItemIterReadStartIndex s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 20) :: IO Int32
return val
glyphItemIterReadStartChar :: GlyphItemIter -> IO Int32
glyphItemIterReadStartChar s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 24) :: IO Int32
return val
glyphItemIterReadEndGlyph :: GlyphItemIter -> IO Int32
glyphItemIterReadEndGlyph s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 28) :: IO Int32
return val
glyphItemIterReadEndIndex :: GlyphItemIter -> IO Int32
glyphItemIterReadEndIndex s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 32) :: IO Int32
return val
glyphItemIterReadEndChar :: GlyphItemIter -> IO Int32
glyphItemIterReadEndChar s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 36) :: IO Int32
return val
-- method GlyphItemIter::copy
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "Pango" "GlyphItemIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TInterface "Pango" "GlyphItemIter"
-- throws : False
-- Skip return : False
foreign import ccall "pango_glyph_item_iter_copy" pango_glyph_item_iter_copy ::
Ptr GlyphItemIter -> -- _obj : TInterface "Pango" "GlyphItemIter"
IO (Ptr GlyphItemIter)
glyphItemIterCopy ::
(MonadIO m) =>
GlyphItemIter -- _obj
-> m GlyphItemIter -- result
glyphItemIterCopy _obj = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
result <- pango_glyph_item_iter_copy _obj'
checkUnexpectedReturnNULL "pango_glyph_item_iter_copy" result
result' <- (wrapBoxed GlyphItemIter) result
touchManagedPtr _obj
return result'
data GlyphItemIterCopyMethodInfo
instance (signature ~ (m GlyphItemIter), MonadIO m) => MethodInfo GlyphItemIterCopyMethodInfo GlyphItemIter signature where
overloadedMethod _ = glyphItemIterCopy
-- method GlyphItemIter::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "Pango" "GlyphItemIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "pango_glyph_item_iter_free" pango_glyph_item_iter_free ::
Ptr GlyphItemIter -> -- _obj : TInterface "Pango" "GlyphItemIter"
IO ()
glyphItemIterFree ::
(MonadIO m) =>
GlyphItemIter -- _obj
-> m () -- result
glyphItemIterFree _obj = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
pango_glyph_item_iter_free _obj'
touchManagedPtr _obj
return ()
data GlyphItemIterFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => MethodInfo GlyphItemIterFreeMethodInfo GlyphItemIter signature where
overloadedMethod _ = glyphItemIterFree
-- method GlyphItemIter::init_end
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "Pango" "GlyphItemIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "glyph_item", argType = TInterface "Pango" "GlyphItem", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False
foreign import ccall "pango_glyph_item_iter_init_end" pango_glyph_item_iter_init_end ::
Ptr GlyphItemIter -> -- _obj : TInterface "Pango" "GlyphItemIter"
Ptr GlyphItem -> -- glyph_item : TInterface "Pango" "GlyphItem"
CString -> -- text : TBasicType TUTF8
IO CInt
glyphItemIterInitEnd ::
(MonadIO m) =>
GlyphItemIter -- _obj
-> GlyphItem -- glyphItem
-> T.Text -- text
-> m Bool -- result
glyphItemIterInitEnd _obj glyphItem text = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
let glyphItem' = unsafeManagedPtrGetPtr glyphItem
text' <- textToCString text
result <- pango_glyph_item_iter_init_end _obj' glyphItem' text'
let result' = (/= 0) result
touchManagedPtr _obj
touchManagedPtr glyphItem
freeMem text'
return result'
data GlyphItemIterInitEndMethodInfo
instance (signature ~ (GlyphItem -> T.Text -> m Bool), MonadIO m) => MethodInfo GlyphItemIterInitEndMethodInfo GlyphItemIter signature where
overloadedMethod _ = glyphItemIterInitEnd
-- method GlyphItemIter::init_start
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "Pango" "GlyphItemIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "glyph_item", argType = TInterface "Pango" "GlyphItem", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False
foreign import ccall "pango_glyph_item_iter_init_start" pango_glyph_item_iter_init_start ::
Ptr GlyphItemIter -> -- _obj : TInterface "Pango" "GlyphItemIter"
Ptr GlyphItem -> -- glyph_item : TInterface "Pango" "GlyphItem"
CString -> -- text : TBasicType TUTF8
IO CInt
glyphItemIterInitStart ::
(MonadIO m) =>
GlyphItemIter -- _obj
-> GlyphItem -- glyphItem
-> T.Text -- text
-> m Bool -- result
glyphItemIterInitStart _obj glyphItem text = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
let glyphItem' = unsafeManagedPtrGetPtr glyphItem
text' <- textToCString text
result <- pango_glyph_item_iter_init_start _obj' glyphItem' text'
let result' = (/= 0) result
touchManagedPtr _obj
touchManagedPtr glyphItem
freeMem text'
return result'
data GlyphItemIterInitStartMethodInfo
instance (signature ~ (GlyphItem -> T.Text -> m Bool), MonadIO m) => MethodInfo GlyphItemIterInitStartMethodInfo GlyphItemIter signature where
overloadedMethod _ = glyphItemIterInitStart
-- method GlyphItemIter::next_cluster
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "Pango" "GlyphItemIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False
foreign import ccall "pango_glyph_item_iter_next_cluster" pango_glyph_item_iter_next_cluster ::
Ptr GlyphItemIter -> -- _obj : TInterface "Pango" "GlyphItemIter"
IO CInt
glyphItemIterNextCluster ::
(MonadIO m) =>
GlyphItemIter -- _obj
-> m Bool -- result
glyphItemIterNextCluster _obj = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
result <- pango_glyph_item_iter_next_cluster _obj'
let result' = (/= 0) result
touchManagedPtr _obj
return result'
data GlyphItemIterNextClusterMethodInfo
instance (signature ~ (m Bool), MonadIO m) => MethodInfo GlyphItemIterNextClusterMethodInfo GlyphItemIter signature where
overloadedMethod _ = glyphItemIterNextCluster
-- method GlyphItemIter::prev_cluster
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "Pango" "GlyphItemIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False
foreign import ccall "pango_glyph_item_iter_prev_cluster" pango_glyph_item_iter_prev_cluster ::
Ptr GlyphItemIter -> -- _obj : TInterface "Pango" "GlyphItemIter"
IO CInt
glyphItemIterPrevCluster ::
(MonadIO m) =>
GlyphItemIter -- _obj
-> m Bool -- result
glyphItemIterPrevCluster _obj = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
result <- pango_glyph_item_iter_prev_cluster _obj'
let result' = (/= 0) result
touchManagedPtr _obj
return result'
data GlyphItemIterPrevClusterMethodInfo
instance (signature ~ (m Bool), MonadIO m) => MethodInfo GlyphItemIterPrevClusterMethodInfo GlyphItemIter signature where
overloadedMethod _ = glyphItemIterPrevCluster
type family ResolveGlyphItemIterMethod (t :: Symbol) (o :: *) :: * where
ResolveGlyphItemIterMethod "copy" o = GlyphItemIterCopyMethodInfo
ResolveGlyphItemIterMethod "free" o = GlyphItemIterFreeMethodInfo
ResolveGlyphItemIterMethod "initEnd" o = GlyphItemIterInitEndMethodInfo
ResolveGlyphItemIterMethod "initStart" o = GlyphItemIterInitStartMethodInfo
ResolveGlyphItemIterMethod "nextCluster" o = GlyphItemIterNextClusterMethodInfo
ResolveGlyphItemIterMethod "prevCluster" o = GlyphItemIterPrevClusterMethodInfo
ResolveGlyphItemIterMethod l o = MethodResolutionFailed l o
instance (info ~ ResolveGlyphItemIterMethod t GlyphItemIter, MethodInfo info GlyphItemIter p) => IsLabelProxy t (GlyphItemIter -> p) where
fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info)
#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveGlyphItemIterMethod t GlyphItemIter, MethodInfo info GlyphItemIter p) => IsLabel t (GlyphItemIter -> p) where
fromLabel _ = overloadedMethod (MethodProxy :: MethodProxy info)
#endif