<commit_before>-- | Texture fonts

module Graphics.FreetypeGL.TextureFont
    ( TextureFont(..), newFromFile, newFromMemory, delete
    , PtSize, getSize
    , getAtlas
    ) where

import qualified Bindings.FreetypeGL.TextureFont as TF
import           Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import           Foreign.C.String (withCString)
import           Foreign.Marshal.Error (throwIfNull)
import           Foreign.Ptr (Ptr, castPtr)
import           Foreign.Storable (peek)
import           Graphics.FreetypeGL.TextureAtlas (TextureAtlas(..))

data TextureFont = TextureFont (Ptr TF.C'texture_font_t)

type PtSize = Float

newFromFile :: TextureAtlas -> PtSize -> FilePath -> IO TextureFont
newFromFile (TextureAtlas atlas) size path =
    withCString path $ \cPath ->
    TextureFont
    <$> throwIfNull "texture_font_new_from_file failed"
        ( TF.c'texture_font_new_from_file atlas (realToFrac size) cPath )

newFromMemory :: TextureAtlas -> PtSize -> ByteString -> IO TextureFont
newFromMemory (TextureAtlas atlas) size mem =
    BS.useAsCStringLen mem $ \(cStr, len) ->
    TextureFont
    <$> throwIfNull "texture_font_new_from_memory failed"
        ( TF.c'texture_font_new_from_memory atlas
          (realToFrac size) (castPtr cStr) (fromIntegral len) )

delete :: TextureFont -> IO ()
delete (TextureFont ptr) = TF.c'texture_font_delete ptr

getSize :: TextureFont -> IO PtSize
getSize (TextureFont ptr) = realToFrac <$> peek (TF.p'texture_font_t'size ptr)

getAtlas :: TextureFont -> IO TextureAtlas
getAtlas (TextureFont ptr) = TextureAtlas <$> peek (TF.p'texture_font_t'atlas ptr)<commit_msg>TextureFont: Expose more attributes<commit_after>-- | Texture fonts

module Graphics.FreetypeGL.TextureFont
    ( TextureFont(..), newFromFile, newFromMemory, delete
    , PtSize, getSize, getAtlas
    , getHeight, ascender, descender, underlinePosition, underlineThickness
    ) where

import qualified Bindings.FreetypeGL.TextureFont as TF
import           Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import           Foreign.C.String (withCString)
import           Foreign.Marshal.Error (throwIfNull)
import           Foreign.Ptr (Ptr, castPtr)
import           Foreign.Storable (peek)
import           Graphics.FreetypeGL.TextureAtlas (TextureAtlas(..))

data TextureFont = TextureFont (Ptr TF.C'texture_font_t)

type PtSize = Float

newFromFile :: TextureAtlas -> PtSize -> FilePath -> IO TextureFont
newFromFile (TextureAtlas atlas) size path =
    withCString path $ \cPath ->
    TextureFont
    <$> throwIfNull "texture_font_new_from_file failed"
        ( TF.c'texture_font_new_from_file atlas (realToFrac size) cPath )

newFromMemory :: TextureAtlas -> PtSize -> ByteString -> IO TextureFont
newFromMemory (TextureAtlas atlas) size mem =
    BS.useAsCStringLen mem $ \(cStr, len) ->
    TextureFont
    <$> throwIfNull "texture_font_new_from_memory failed"
        ( TF.c'texture_font_new_from_memory atlas
          (realToFrac size) (castPtr cStr) (fromIntegral len) )

delete :: TextureFont -> IO ()
delete (TextureFont ptr) = TF.c'texture_font_delete ptr

getHeight :: TextureFont -> IO Float
getHeight (TextureFont ptr) = realToFrac <$> peek (TF.p'texture_font_t'height ptr)

ascender :: TextureFont -> IO Float
ascender (TextureFont ptr) = realToFrac <$> peek (TF.p'texture_font_t'ascender ptr)

descender :: TextureFont -> IO Float
descender (TextureFont ptr) = realToFrac <$> peek (TF.p'texture_font_t'descender ptr)

underlinePosition :: TextureFont -> IO Float
underlinePosition (TextureFont ptr) = realToFrac <$> peek (TF.p'texture_font_t'underline_position ptr)

underlineThickness :: TextureFont -> IO Float
underlineThickness (TextureFont ptr) = realToFrac <$> peek (TF.p'texture_font_t'underline_thickness ptr)

getSize :: TextureFont -> IO PtSize
getSize (TextureFont ptr) = realToFrac <$> peek (TF.p'texture_font_t'size ptr)

getAtlas :: TextureFont -> IO TextureAtlas
getAtlas (TextureFont ptr) = TextureAtlas <$> peek (TF.p'texture_font_t'atlas ptr)
{'fraction_non_alphanumeric': 0.09713297083539298, 'fraction_numerical': 0.0, 'mean_word_length': 4.155414012738854, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3384621', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1319, 'n_words': 322}