kb-text-shape-0.3.0.0: src/KB/Text/Shape/FFI/Handles.hsc
module KB.Text.Shape.FFI.Handles where
import Foreign
import Data.Coerce (Coercible, coerce)
#include "kb_text_shape.h"
{-# INLINE intHandle #-}
intHandle :: Coercible h (Ptr a) => h -> Int
intHandle ptrLike = i
where
IntPtr i = ptrToIntPtr (coerce ptrLike)
-- | An opaque handle to the shaping context..
newtype ShapeContext = ShapeContext (Ptr ShapeContext)
deriving (Eq, Ord, Show)
deriving newtype (Storable)
-- | An opaque handle to the font data.
newtype Font = Font (Ptr Font)
deriving (Eq, Ord, Show)
deriving newtype (Storable)
{- | Amount of bytes needed to hold the font data structure
Usually you don't have to look inside, but may have to allocate one to get the 'Font' handle.
-}
sizeOfFontData :: Int
sizeOfFontData = #size kbts_font
{- | A font's slot in a context's font stack, written by the @kbts_ShapePushFont*2@ functions.
A failed push writes 'CONTEXT_FONT_HANDLE_INVALID'.
NB: as of 2.32 a popped font's handle is not reliably invalidated.
Popping the first font of a @KBTS_CONTEXT_FONTS_PER_BLOCK@ block resets the slot generations.
The next push then gets the same handle.
The stale handle thus addresses the new font.
Drop handles when popping their fonts.
-}
newtype ContextFontHandle = ContextFontHandle Word32
deriving (Eq, Ord, Show)
deriving newtype (Storable)
-- | The handle a failed push writes.
pattern CONTEXT_FONT_HANDLE_INVALID :: ContextFontHandle
pattern CONTEXT_FONT_HANDLE_INVALID = ContextFontHandle 0xFFFF0000
newtype ShapeConfig = ShapeConfig (Ptr ShapeConfig)
deriving (Eq, Ord, Show)
deriving newtype (Storable)
newtype ShapeScratchpad = ShapeScratchpad (Ptr ShapeScratchpad)
deriving (Eq, Ord, Show)
deriving newtype (Storable)
newtype GlyphConfig = GlyphConfig (Ptr GlyphConfig)
deriving (Eq, Ord, Show)
deriving newtype (Storable)
newtype BreakState = BreakState (Ptr BreakState)
deriving (Eq, Ord, Show)
deriving newtype (Storable)
{- | Amount of bytes needed to hold a @kbts_break_state@.
Allocate (and zero) this much to get a 'BreakState' for the segmentation API.
-}
sizeOfBreakState :: Int
sizeOfBreakState = #size kbts_break_state