packages feed

ktx-font 0.2.0.1 → 0.3.0.0

raw patch · 4 files changed

+67/−8 lines, 4 filesdep ~kb-text-layoutdep ~kb-text-shapePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: kb-text-layout, kb-text-shape

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -6,6 +6,18 @@ and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). +## 0.3.0.0 - 2026-11-17++- Migrated to `kb-text-shape >= 0.3` and `kb-text-layout >= 0.2`.+  The bundled kbts blobs changed format again. Rebuild the `.ktxf` assets.+- Shaping failures throw the `ShapeException` from `kb-text-shape` instead of calling `error`.+- `Layout.shapeText` and the break hyphen shape the text as a single run in the style's font.+  A style whose font sat under another one in the stack used to get the tail of its text from the font above.+  Even with the font on top, the text could split into two runs and lose a ligature.+  `kb-text-layout` measures text the same way. The line breaks now agree with the placed glyphs.+- `Shaping.withFont_` carries the caveats of its `kb-text-shape` counterpart.+  A section reaching the end of the input shapes its tail in the font below it.+ ## 0.2.0.1 - 2026-09-06  - Bring back foldl' import for older base.
ktx-font.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           ktx-font-version:        0.2.0.1+version:        0.3.0.0 synopsis:       GPU-ready rasterized fonts category:       Graphics author:         IC Rainbow@@ -69,8 +69,8 @@     , base >=4.11 && <5     , bytestring     , containers-    , kb-text-layout >=0.1.1.0 && <0.2-    , kb-text-shape >=0.2.1.0 && <0.3+    , kb-text-layout ==0.2.*+    , kb-text-shape ==0.3.*     , ktx-codec >=0.1     , msdf-atlas     , text
src/Codec/Ktx2/Font/Layout.hs view
@@ -38,6 +38,7 @@ import Codec.Ktx2.Font.Shaping qualified as Shaping import Control.Concurrent (withMVar) import Data.Foldable (foldl')+import Data.Maybe (mapMaybe) import Data.Text (Text) import Data.Text qualified as Text import Data.Vector (Vector, (!))@@ -46,6 +47,7 @@ import KB.Text.Layout.Analysis (BreakKind(..)) import KB.Text.Layout.Break qualified as Break import KB.Text.Layout.Measure qualified as Measure+import KB.Text.Shape qualified as TextShape import KB.Text.Shape.Font (withFontData)  {- | A font bundle prepared for measuring.@@ -74,8 +76,8 @@  shapeHyphen :: Font.StackContext a -> Font.Bundle -> IO Hyphen shapeHyphen ctx bundle =-  Shaping.shape (Shaping.initialCursorDown 0) ctx (Shaping.withFont_ bundle (Shaping.text_ "-")) >>= \case-    [(font, glyphs)] -> pure Hyphen{font, glyphs}+  withMVar ctx.shapeContext (\kbts -> shapeInBundle kbts ctx bundle "-") >>= \case+    [(font, clusters)] -> pure Hyphen{font, glyphs = mapMaybe (.placed) clusters}     runs -> fail $ "Expected a single run for the hyphen, got " <> show (length runs)  data Strategy@@ -115,8 +117,7 @@       if Text.null t then         pure []       else-        Shaping.unsafeShapeClusters kbts ctx $-          Shaping.withFont_ ts.bundle (Shaping.text_ t)+        shapeInBundle kbts ctx ts.bundle t     pure (prepared, runs)   let     size = Text.length t@@ -262,3 +263,9 @@ -- | Drop the measurement caches, e.g. after evicting some fonts. clearLayoutCache :: Font.StackContext a -> IO () clearLayoutCache ctx = Measure.clearCache ctx.layout++shapeInBundle :: TextShape.Context -> Font.StackContext a -> Font.Bundle -> Text -> IO [Shaping.ClusterRun]+shapeInBundle kbts ctx bundle t =+  withFontData bundle.fontData \font ->+    TextShape.withFontVariations kbts font [] $+      Shaping.unsafeShapeClusters kbts ctx (Shaping.text_ t)
test/Spec.hs view
@@ -2,7 +2,7 @@  import Control.Monad (unless) import Data.Foldable (for_)-import Data.List (isSuffixOf)+import Data.List (isSuffixOf, nub) import Data.Text qualified as Text import Data.Traversable (for) import Data.Vector.Storable qualified as Storable@@ -50,6 +50,8 @@             assertBool (ligatureBundle <> " is missing, run the ktx-build asset build")        , withStack [ligatureBundle] ligatureTests++      , withBuriedStyle buriedStyleTests       ]  bundleTests :: FilePath -> TestTree@@ -285,6 +287,44 @@     ligature = "ffi"     place shaped width = Layout.placeText Layout.LayoutOptions{cursor, strategy = Layout.Greedy, align = Layout.AlignLeft} width shaped     glyphsOf lns = concatMap snd (Layout.placedRuns lns)++withBuriedStyle :: (IO (Font.StackContext FilePath, Layout.TextStyle) -> TestTree) -> TestTree+withBuriedStyle withCtx =+  withResource acquire release $ withCtx . fmap snd+  where+    acquire = do+      styled <- Font.loadBundleFile ligatureBundle+      above <- Font.loadBundleFile monoBundle+      ctx <- Font.createStackContext [styled, above]+      style <- Layout.bundleStyle ctx styled+      let tagged = Font.mapWithBundle [(styled, const ligatureBundle), (above, const monoBundle)] ctx+      pure ([styled, above], (tagged, style))++    release (bundles, (ctx, _style)) = do+      Font.destroyStackContext ctx+      for_ bundles Font.freeBundle++monoBundle :: FilePath+monoBundle = ".." </> "assets" </> "demo" </> "MapleMono-Regular.ktxf"++buriedStyleTests :: IO (Font.StackContext FilePath, Layout.TextStyle) -> TestTree+buriedStyleTests getStack =+  testGroup "style font under another"+    [ testCase "the whole text stays in the style's font" do+        (ctx, style) <- getStack+        lns <- Layout.layoutText cursor ctx style 1e6 "Sphinx of black quartz, judge my vow."+        bundlesOf ctx lns @?= [Just ligatureBundle]++    , testCase "the break hyphen comes from the style's font" do+        (ctx, style) <- getStack+        shaped <- Layout.shapeText ctx style "hyphen\173ation"+        w <- Layout.measureText ctx style "hyphenation"+        let lns = Layout.placeText Layout.LayoutOptions{cursor, strategy = Layout.Greedy, align = Layout.AlignLeft} (w * 0.75) shaped+        map (.ended) lns @?= [Layout.Hyphenated, Layout.Finished]+        bundlesOf ctx lns @?= [Just ligatureBundle]+    ]+  where+    bundlesOf ctx lns = nub [Font.lookupBundled font ctx | ((font, _atlas), _glyphs) <- Layout.placedRuns lns]  cursor :: Shaping.Cursor cursor = Shaping.initialCursorDown 2.0