From f8e4c3a4b8d808b9c9b7aba2acfeb7f7f98d4ea3 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 17 Feb 2023 19:11:58 +1300 Subject: [PATCH] Ensure baselines line up! --- src/Typograffiti/Atlas.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Typograffiti/Atlas.hs b/src/Typograffiti/Atlas.hs index 63a4332..8a37379 100644 --- a/src/Typograffiti/Atlas.hs +++ b/src/Typograffiti/Atlas.hs @@ -57,8 +57,10 @@ data TypograffitiError = data GlyphMetrics = GlyphMetrics { glyphTexBB :: (V2 Int, V2 Int), -- ^ Bounding box of the glyph in the texture. - glyphSize :: V2 Int + glyphSize :: V2 Int, -- ^ Size of the glyph onscreen. + glyphOffset :: V2 Int + -- ^ Left & top bearings. } deriving (Show, Eq) -- | Cache of rendered glyphs to be composited into place on the GPU. @@ -150,11 +152,10 @@ texturize cb xymap atlas@Atlas{..} glyph canon = floor . (* 0.5) . (* 0.015625) . realToFrac . fromIntegral vecsz = canon <$> V2 (gmWidth metrics) (gmHeight metrics) vecxb = canon <$> V2 (gmHoriBearingX metrics) (gmHoriBearingY metrics) - vecyb = canon <$> V2 (gmVertBearingX metrics) (gmVertBearingY metrics) - vecad = canon <$> V2 (gmHoriAdvance metrics) (gmVertAdvance metrics) mtrcs = GlyphMetrics { glyphTexBB = (pos, pos + vecwh), - glyphSize = vecsz + glyphSize = vecsz, + glyphOffset = vecxb } return atlas { atlasMetrics = IM.insert (fromEnum glyph) mtrcs atlasMetrics } | otherwise = do @@ -207,14 +208,16 @@ makeCharQuad Atlas {..} (penx, peny, mLast) (GlyphInfo {codepoint=glyph}, GlyphP let x = penx + f x_offset*fst atlasScale y = peny + f y_offset*snd atlasScale V2 w h = f' <$> glyphSize + V2 dx dy = f' <$> glyphOffset + (x', y') = (x + dx, y - dy) V2 aszW aszH = f' <$> atlasTextureSize V2 texL texT = f' <$> fst glyphTexBB V2 texR texB = f' <$> snd glyphTexBB - tl = (V2 (x) (y-h), V2 (texL/aszW) (texT/aszH)) - tr = (V2 (x+w) (y-h), V2 (texR/aszW) (texT/aszH)) - br = (V2 (x+w) y, V2 (texR/aszW) (texB/aszH)) - bl = (V2 (x) y, V2 (texL/aszW) (texB/aszH)) + tl = (V2 (x') (y'), V2 (texL/aszW) (texT/aszH)) + tr = (V2 (x'+w) (y'), V2 (texR/aszW) (texT/aszH)) + br = (V2 (x'+w) (y'+h), V2 (texR/aszW) (texB/aszH)) + bl = (V2 (x') (y'+h), V2 (texL/aszW) (texB/aszH)) return (penx + f x_advance*fst atlasScale, peny + f y_advance*snd atlasScale, UV.fromList [tl, tr, br, tl, br, bl] : mLast) -- 2.30.2