From e7928d3e4e343dc9da5c18ca7668cd64c71692fa Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Wed, 1 Feb 2023 09:24:19 +1300 Subject: [PATCH] Finish testing the FontConfig bridges to FreeType & Harfbuzz! --- fontconfig-harfbuzz/app/Main.hs | 25 ++++++++++++------- fontconfig-harfbuzz/fontconfig-harfbuzz.cabal | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/fontconfig-harfbuzz/app/Main.hs b/fontconfig-harfbuzz/app/Main.hs index d26893b..caec924 100644 --- a/fontconfig-harfbuzz/app/Main.hs +++ b/fontconfig-harfbuzz/app/Main.hs @@ -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 diff --git a/fontconfig-harfbuzz/fontconfig-harfbuzz.cabal b/fontconfig-harfbuzz/fontconfig-harfbuzz.cabal index 07e7d12..72b4b11 100644 --- a/fontconfig-harfbuzz/fontconfig-harfbuzz.cabal +++ b/fontconfig-harfbuzz/fontconfig-harfbuzz.cabal @@ -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 -- 2.30.2