From 90e99e3130bd382b65c26f6f539ba86bbb2836b9 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sun, 13 Feb 2022 08:20:43 +1300 Subject: [PATCH] Expose util functions on scripts & buffers. --- Data/Text/Glyphize/Buffer.hs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Data/Text/Glyphize/Buffer.hs b/Data/Text/Glyphize/Buffer.hs index d4b9c17..bbf6368 100644 --- a/Data/Text/Glyphize/Buffer.hs +++ b/Data/Text/Glyphize/Buffer.hs @@ -142,9 +142,16 @@ instance Storable GlyphPos where pokeElemOff q 2 xoff pokeElemOff q 3 yoff --- guessSegmentProperties :: Buffer -> Buffer --- glyphInfo & glyphPositions to be zipped & return from shape function --- scriptHorizontalDir :: ShortText -> Direction +guessSegmentProperties :: Buffer -> Buffer +guessSegmentProperties = thaw . freeze +scriptHorizontalDir :: ShortText -> Maybe Direction +scriptHorizontalDir script = + case hb_script_get_horizontal_direction $ hb_script_from_txt script of + 4 -> Just DirLTR + 5 -> Just DirRTL + 6 -> Just DirTTB + 7 -> Just DirBTT + _ -> Nothing dirReverse DirLTR = DirRTL dirReverse DirRTL = DirLTR @@ -306,6 +313,8 @@ hb_script_from_string str = hb_tag_from_string $ case titlecase str of hb_script_from_txt txt = hb_script_from_string $ Short.toString txt foreign import ccall "hb_buffer_set_script" hb_buffer_set_script :: Ptr Buffer'' -> Word32 -> IO () +foreign import ccall "hb_script_get_horizontal_direction" hb_script_get_horizontal_direction + :: Word32 -> Int foreign import ccall "hb_language_from_string" hb_language_from_string :: Ptr Word8 -> Int -> Int hb_language_from_txt txt = let Strict.PS ptr offset size = toByteString txt -- 2.30.2