~alcinnz/harfbuzz-pure

2856718617f21a8520ffcc3a8aed134d5df00555 — Adrian Cochrane 1 year, 10 months ago cd20a1c
Expose Harfbuzz 3.3 APIs.
M Data/Text/Glyphize/Buffer.hs => Data/Text/Glyphize/Buffer.hs +3 -4
@@ 201,7 201,6 @@ hb_language_from_string str =
foreign import ccall "hb_language_from_string" hb_language_from_string'
    :: CString -> Int -> IO Language

{-
-- | Check whether a second language tag is the same or a more specific version
-- of the provided language tag.
-- For example, "fa_IR.utf8" is a more specific tag for "fa" or for "fa_IR".


@@ 318,7 317,7 @@ withBuffer buf cb = withNewBuffer $ \buf' -> bufferWithText buf' (text buf) $ do
        ClusterChars -> 2
    hb_buffer_set_invisible_glyph buf' $ c2w $ invisibleGlyph buf
    hb_buffer_set_replacement_codepoint buf' $ c2w $ replacementCodepoint buf
--    hb_buffer_set_not_found_glyph buf' $ c2w $ notFoundGlyph buf
    hb_buffer_set_not_found_glyph buf' $ c2w $ notFoundGlyph buf
    case (contentType buf, direction buf, script buf, language buf) of
        (Just ContentTypeUnicode, Nothing, _, _) -> hb_buffer_guess_segment_properties buf'
        (Just ContentTypeUnicode, _, Nothing, _) -> hb_buffer_guess_segment_properties buf'


@@ 339,8 338,8 @@ foreign import ccall "hb_buffer_set_invisible_glyph" hb_buffer_set_invisible_gly
    :: Buffer' -> Word32 -> IO ()
foreign import ccall "hb_buffer_set_replacement_codepoint" hb_buffer_set_replacement_codepoint
    :: Buffer' -> Word32 -> IO ()
--foreign import ccall "hb_buffer_set_not_found_glyph" hb_buffer_set_not_found_glyph
--    :: Buffer' -> Word32 -> IO ()
foreign import ccall "hb_buffer_set_not_found_glyph" hb_buffer_set_not_found_glyph
    :: Buffer' -> Word32 -> IO ()
foreign import ccall "hb_buffer_guess_segment_properties" hb_buffer_guess_segment_properties
    :: Buffer' -> IO ()
foreign import ccall "hb_buffer_allocation_successful" hb_buffer_allocation_successful

M Data/Text/Glyphize/Font.hs => Data/Text/Glyphize/Font.hs +8 -10
@@ 666,12 666,11 @@ fontScale font = unsafePerformIO $
foreign import ccall "hb_font_get_scale" hb_font_get_scale
    :: Font_ -> Ptr Int -> Ptr Int -> IO ()

{-
-- | Fetches the "synthetic slant" of a font.
fontSyntheticSlant :: Font -> Float
fontSyntheticSlant = fontFunc hb_font_get_synthetic_slant
foreign import ccall "hb_font_get_synthetic_slant" hb_font_get_synthetic_slant ::
    Font_ -> Float-}
    Font_ -> Float

-- | Fetches the glyph ID for a Unicode codepoint when followed by
-- the specified variation-selector codepoint, in the specified `Font`.


@@ 689,7 688,6 @@ fontVarGlyph' font unicode varSel = unsafePerformIO $
foreign import ccall "hb_font_get_variation_glyph" hb_font_get_variation_glyph
    :: Font_ -> Word32 -> Word32 -> Ptr Word32 -> IO Bool

{-
-- | Fetches the list of variation coordinates (in design-space units)
-- currently set on a `Font`.
-- Note that this returned list may only contain values for some (or none) of the axes;


@@ 701,7 699,7 @@ fontVarCoordsDesign font = unsafePerformIO $
        length <- peek length'
        forM [0..fromEnum length-1] $ peekElemOff arr
foreign import ccall "hb_font_get_var_coords_design"
    hb_font_get_var_coords_design :: Font_ -> Ptr Word -> IO (Ptr Float)-}
    hb_font_get_var_coords_design :: Font_ -> Ptr Word -> IO (Ptr Float)

-- | Fetches the list of normalized variation coordinates currently set on a font.
-- Note that this returned list may only contain values for some (or none) of the axes;


@@ 813,7 811,7 @@ data FontOptions = FontOptions {
    -- ^ Sets the font-face value of the newly-created `Font`.
    optionParent :: Maybe Font,
    -- ^ Sets the parent `Font` of the newly-created `Font`.
--    optionSynthSlant :: Maybe Float,
    optionSynthSlant :: Maybe Float,
    -- ^ Sets the "synthetic slant" of a newly-created `Font`. By default is zero.
    -- Synthetic slant is the graphical skew applied to the font at rendering time.
    -- Harfbuzz needs to know this value to adjust shaping results, metrics,


@@ 837,7 835,7 @@ data FontOptions = FontOptions {
-- | `FontOptions` which has no effect on the newly-created `Font`.
defaultFontOptions = FontOptions {
    optionPPEm = Nothing, optionPtEm = Nothing, optionScale = Nothing,
    optionFace = Nothing, optionParent = Nothing,-- optionSynthSlant = Nothing,
    optionFace = Nothing, optionParent = Nothing, optionSynthSlant = Nothing,
    optionVariations = [], optionVarCoordsDesign = [], optionVarCoordsNormalized = [],
    optionVarNamedInstance = Nothing
}


@@ 858,9 856,9 @@ _setFontOptions font opts = do
    case optionParent opts of
        Just parent -> withForeignPtr parent $ hb_font_set_parent font
        Nothing -> return ()
    {-case optionSynthSlant opts of
    case optionSynthSlant opts of
        Just slant -> hb_font_set_synthetic_slant font slant
        Nothing -> return ()-}
        Nothing -> return ()

    unless (null $ optionVariations opts) $
        withArrayLen (optionVariations opts) $ \len vars ->


@@ 879,8 877,8 @@ foreign import ccall "hb_font_set_ptem" hb_font_set_ptem :: Font_ -> Float -> IO
foreign import ccall "hb_font_set_scale" hb_font_set_scale :: Font_ -> Int -> Int -> IO ()
foreign import ccall "hb_font_set_face" hb_font_set_face :: Font_ -> Face_ -> IO ()
foreign import ccall "hb_font_set_parent" hb_font_set_parent :: Font_ -> Font_ -> IO ()
{-foreign import ccall "hb_font_set_synthetic_slant" hb_font_set_synthetic_slant ::
    Font_ -> Float -> IO ()-}
foreign import ccall "hb_font_set_synthetic_slant" hb_font_set_synthetic_slant ::
    Font_ -> Float -> IO ()
foreign import ccall "hb_font_set_variations" hb_font_set_variations ::
    Font_ -> Ptr Variation -> Word -> IO ()
foreign import ccall "hb_font_set_var_coords_design" hb_font_set_var_coords_design ::

A Data/Text/Glyphize/Oom.hs => Data/Text/Glyphize/Oom.hs +17 -0
@@ 0,0 1,17 @@
module Data.Text.Glyphize.Oom where

import Control.Exception
import Foreign.Ptr (nullPtr, Ptr)

data HarfbuzzError = OutOfMemory deriving (Show)
instance Exception HarfbuzzError

throwFalse :: IO Bool -> IO ()
throwFalse cb = do
    ret <- cb
    if ret then return () else throwIO OutOfMemory

throwNull :: IO (Ptr a) -> IO (Ptr a)
throwNull cb = do
    ptr <- cb
    if ptr == nullPtr then throwIO OutOfMemory else return ptr

M harfbuzz-pure.cabal => harfbuzz-pure.cabal +2 -1
@@ 17,6 17,7 @@ synopsis:            Pure-functional Harfbuzz language bindings

-- A longer description of the package.
description:         HarfBuzz is a text shaping library. Using the HarfBuzz library allows programs to convert a sequence of Unicode input into properly formatted and positioned glyph output—for any writing system and language.
                    NOTE: You may need to install Harfbuzz 3.3.0 (Jan 2022) from source, it hasn't been widely packaged yet.

-- URL for the project homepage or repository.
homepage:            https://harfbuzz.github.io/


@@ 62,7 63,7 @@ library
  -- Other library packages from which modules are imported.
  build-depends:       base >=4.12 && <4.13, text >= 2.0 && < 3,
                       bytestring >= 0.11, freetype2 >= 0.2, derive-storable >= 0.3 && < 1
  pkgconfig-depends:   harfbuzz
  pkgconfig-depends:   harfbuzz >= 3.3
  
  -- Directories containing source files.
  -- hs-source-dirs: