module Data.Text.Glyphize (shape, version, versionAtLeast, versionString,
Buffer(..), ContentType(..), ClusterLevel(..), Direction(..), defaultBuffer,
dirFromStr, dirToStr, dirReverse, dirBackward, dirForward, dirHorizontal, dirVertical,
scriptHorizontalDir, languageDefault, tag_from_string, tag_to_string, guessSegmentProperties,
GlyphInfo(..), GlyphPos(..), Feature(..), featTag, Variation(..), varTag,
parseFeature, unparseFeature, parseVariation, unparseVariation, globalStart, globalEnd,
countFace, Face, createFace, ftCreateFace, emptyFace, faceTableTags, faceGlyphCount,
faceCollectUnicodes, faceCollectVarSels, faceCollectVarUnicodes, faceIndex, faceUpem,
faceBlob, faceTable,
Font, createFont, ftCreateFont, emptyFont, fontFace, fontGlyph, fontGlyphAdvance,
fontGlyphContourPoint, fontGlyphContourPointForOrigin, fontGlyphFromName,
fontGlyphHAdvance, fontGlyphVAdvance, fontGlyphHKerning, fontGlyphHOrigin, fontGlyphVOrigin,
fontGlyphKerningForDir, fontGlyphName, fontGlyphName_, fontGlyphOriginForDir,
fontNominalGlyph, fontPPEm, fontPtEm, fontScale, fontVarGlyph, -- fontSyntheticSlant,
fontVarCoordsNormalized, fontTxt2Glyph, fontGlyph2Str, -- fontVarCoordsDesign,
GlyphExtents(..), fontGlyphExtents, fontGlyphExtentsForOrigin,
FontExtents(..), fontExtentsForDir, fontHExtents, fontVExtents,
FontOptions(..), defaultFontOptions, createFontWithOptions, ftCreateFontWithOptions,
) where
import Data.Text.Glyphize.Font
import Data.Text.Glyphize.Buffer
import System.IO.Unsafe (unsafePerformIO)
import Foreign.Ptr (Ptr(..))
import Foreign.ForeignPtr (withForeignPtr)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Storable (peek)
import Foreign.C.String (CString(..), peekCString)
import Foreign.Marshal.Array (withArrayLen)
shape :: Font -> Buffer -> [Feature] -> [(GlyphInfo, GlyphPos)]
shape font buffer features = unsafePerformIO $ withForeignPtr font $ \font' ->
withBuffer buffer $ \buffer' -> withArrayLen features $ \len features' -> do
hb_shape font' buffer' features' $ toEnum len
infos <- glyphInfos buffer'
pos <- glyphsPos buffer'
return $ zip infos pos
foreign import ccall "hb_shape" hb_shape :: Font_ -> Buffer' -> Ptr Feature -> Word -> IO ()
guessSegmentProperties :: Buffer -> Buffer
guessSegmentProperties = unsafePerformIO . flip withBuffer thawBuffer
foreign import ccall "hb_version" hb_version :: Ptr Int -> Ptr Int -> Ptr Int -> IO ()
version :: (Int, Int, Int)
version = unsafePerformIO $
alloca $ \a' -> alloca $ \b' -> alloca $ \c' -> do
hb_version a' b' c'
a <- peek a'
b <- peek b'
c <- peek c'
return (a, b, c)
foreign import ccall "hb_version_atleast" versionAtLeast :: Int -> Int -> Int -> Bool
foreign import ccall "hb_version_string" hb_version_string :: CString
versionString :: String
versionString = unsafePerformIO $ peekCString hb_version_string