From 7f7ef85aea3911cbe350ec0f313623908d3053fe Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 10 Feb 2022 18:36:15 +1300 Subject: [PATCH] Integrate glyph-mutating callback into atlas preparation. --- src/Typograffiti/Atlas.hs | 10 +++++----- src/Typograffiti/Utils.hs | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Typograffiti/Atlas.hs b/src/Typograffiti/Atlas.hs index edccf71..127b327 100644 --- a/src/Typograffiti/Atlas.hs +++ b/src/Typograffiti/Atlas.hs @@ -25,8 +25,6 @@ import Graphics.GL.Types import FreeType.Core.Types as BM import FreeType.Support.Bitmap as BM import FreeType.Support.Bitmap.Internal as BM ---import Graphics.Rendering.FreeType.Internal.Bitmap as BM ---import Graphics.Rendering.FreeType.Internal.GlyphMetrics as GM import Linear import Typograffiti.GL @@ -85,10 +83,11 @@ spacing = 1 measure :: FT_Face -> Int + -> (FT_GlyphSlot -> FreeTypeIO ()) -> (IntMap AtlasMeasure, AtlasMeasure) -> Char -> FreeTypeIO (IntMap AtlasMeasure, AtlasMeasure) -measure fce maxw (prev, am@AM{..}) char +measure fce maxw glyphCb (prev, am@AM{..}) char -- Skip chars that have already been measured | fromEnum char `IM.member` prev = return (prev, am) | otherwise = do @@ -96,10 +95,11 @@ measure fce maxw (prev, am@AM{..}) char V2 w h = amWH -- Load the char, replacing the glyph according to -- https://www.freetype.org/freetype2/docs/tutorial/step1.html - loadChar fce (fromIntegral $ fromEnum char) ft_LOAD_RENDER + loadChar fce (fromIntegral $ fromEnum char) ft_LOAD_DEFAULT -- Get the glyph slot fce' <- liftIO $ peek fce let slot = frGlyph fce' + glyphCb slot -- Get the bitmap slot' <- liftIO $ peek slot let bmp = gsrBitmap slot' @@ -183,7 +183,7 @@ allocAtlas fontFilePath gs str = do GlyphSizeInPixels w h -> setPixelSizes fce w h GlyphSizeByChar (CharSize w h dpix dpiy) -> setCharSize fce w h dpix dpiy - (amMap, am) <- foldM (measure fce 512) (mempty, emptyAM) str + (amMap, am) <- foldM (measure fce 512 renderGlyph) (mempty, emptyAM) str let V2 w h = amWH am xymap :: IntMap (V2 Int) diff --git a/src/Typograffiti/Utils.hs b/src/Typograffiti/Utils.hs index 316b853..6f2eb67 100644 --- a/src/Typograffiti/Utils.hs +++ b/src/Typograffiti/Utils.hs @@ -12,6 +12,7 @@ module Typograffiti.Utils ( -- , hasKerning , loadChar , loadGlyph + , renderGlyph , newFace , setCharSize , setPixelSizes @@ -112,6 +113,9 @@ loadGlyph ff fg flags = runIOErr "ft_Load_Glyph" $ ft_Load_Glyph' ff fg flags loadChar :: MonadIO m => FT_Face -> FT_ULong -> FT_Int32 -> FreeTypeT m () loadChar ff char flags = runIOErr "ft_Load_Char" $ ft_Load_Char' ff char flags +renderGlyph :: MonadIO m => FT_GlyphSlot -> FreeTypeT m () +renderGlyph glyph = runIOErr "ft_Render_Glyph" $ ft_Render_Glyph' glyph 0 + --hasKerning :: MonadIO m => FT_Face -> FreeTypeT m Bool --hasKerning = liftIO . ft_HAS_KERNING --ft_HAS_KERNING FT_HAS_KERNING = return True -- 2.30.2