~alcinnz/fontconfig-pure

e7928d3e4e343dc9da5c18ca7668cd64c71692fa — Adrian Cochrane 1 year, 3 months ago 196a28a
Finish testing the FontConfig bridges to FreeType & Harfbuzz!
2 files changed, 17 insertions(+), 10 deletions(-)

M fontconfig-harfbuzz/app/Main.hs
M fontconfig-harfbuzz/fontconfig-harfbuzz.cabal
M fontconfig-harfbuzz/app/Main.hs => fontconfig-harfbuzz/app/Main.hs +16 -9
@@ 5,17 5,18 @@ import Graphics.UI.GLUT
import Graphics.GL.Core32

import FreeType.Core.Base
import FreeType.FontConfig (instantiatePattern)
import FreeType.FontConfig (instantiatePattern, bmpAndMetricsForIndex, FTFC_Subpixel(..))

import Graphics.Text.Font.Choose as Font
import Typograffiti (makeDrawGlyphs)
import Typograffiti (makeDrawGlyphs, allocAtlas, AllocatedRendering(..), move)
import Linear (V2(..))

import Data.Text.Glyphize
import Data.Text.Glyphize.Choose

import System.Environment (getArgs)
import System.Exit (exitFailure)
import Control.Monad.Except (runExceptT)
import System.Exit (die)
import Control.Monad.Except (runExceptT, liftIO)
import Data.Maybe (fromMaybe)

main :: IO ()


@@ 32,8 33,7 @@ main = do
    font <- case fontSort' query' False of
        Just (f:_, _) -> return f
        _ -> do
            putStrLn ("Failed to locate font " ++ show query)
            exitFailure
            die ("Failed to locate font " ++ show query)

    let buf = defaultBuffer { text = "sphinx of black quartz judge my vow" }
    let glyphs = shape (pattern2hbfont font []) buf []


@@ 41,11 41,18 @@ main = do
    ft_With_FreeType $ \ft -> do
        inst <- instantiatePattern ft font (fromMaybe 12 $ getValue' "size" font, 20)
        res <- runExceptT $ do
--            render <- makeDrawGlyphs
            allocAtlas ?? $ map (fst . codepoint) glyphs
            return atlas
            render <- makeDrawGlyphs
            let codepoints = map codepoint $ map fst $ glyphs
            atlas <- allocAtlas (liftIO . bmpAndMetricsForIndex inst SubpixelNone) codepoints
            renderer <- render atlas glyphs
            return renderer
        renderer <- case res of
            Left err -> die $ show err
            Right r -> return r

        displayCallback $= do
            clear [ ColorBuffer ]
            Size x y <- get windowSize
            arDraw renderer [move 0 50] $ V2 (fromEnum x) (fromEnum y)
            flush
        mainLoop

M fontconfig-harfbuzz/fontconfig-harfbuzz.cabal => fontconfig-harfbuzz/fontconfig-harfbuzz.cabal +1 -1
@@ 79,7 79,7 @@ executable fontconfig-harfbuzz
  -- Other library packages from which modules are imported.
  build-depends:       base >=4.12 && <4.13, typograffiti>=0.2, text,
                        harfbuzz-pure, GLUT >= 2.7, gl, mtl, fontconfig-pure,
                        freetype2, fontconfig-harfbuzz
                        freetype2, fontconfig-harfbuzz, linear

  -- Directories containing source files.
  hs-source-dirs:      app