packages feed

ktx-font 0.4.0.0 → 0.4.1.0

raw patch · 4 files changed

+43/−13 lines, 4 filesdep ~kb-text-layoutPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: kb-text-layout

API changes (from Hackage documentation)

+ Codec.Ktx2.Font.Layout: lineRanges :: LayoutOptions -> Float -> ShapedText -> [LineRange]
- Codec.Ktx2.Font.Layout: PlacedLine :: [PlacedRun] -> Text -> Float -> LineEnd -> Bool -> (Float, Float) -> PlacedLine
+ Codec.Ktx2.Font.Layout: PlacedLine :: ~[PlacedRun] -> ~Text -> Float -> LineEnd -> Bool -> (Float, Float) -> PlacedLine
- Codec.Ktx2.Font.Layout: [runs] :: PlacedLine -> [PlacedRun]
+ Codec.Ktx2.Font.Layout: [runs] :: PlacedLine -> ~[PlacedRun]
- Codec.Ktx2.Font.Layout: [text] :: PlacedLine -> Text
+ Codec.Ktx2.Font.Layout: [text] :: PlacedLine -> ~Text

Files

CHANGELOG.md view
@@ -6,6 +6,14 @@ and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). +## 0.4.1.0 - 2026-12-03++- Added `Layout.lineRanges`, the line breaks that `placeText` places.+  Counting the lines of a block no longer places its glyphs.+- `PlacedLine` keeps `runs` and `text` lazy.+  Measuring placed lines by their `width` no longer builds their glyph runs and text.+  A renderer builds them only for the lines it draws.+ ## 0.4.0.0 - 2026-12-02  - Added `Codec.Ktx2.Font.Slug` to pack quadratic outlines into curve and band data for the Slug renderer.
ktx-font.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           ktx-font-version:        0.4.0.0+version:        0.4.1.0 synopsis:       GPU-ready rasterized fonts category:       Graphics author:         IC Rainbow@@ -161,6 +161,7 @@     , directory >=1.3 && <2     , filepath >=1.4 && <2     , half+    , kb-text-layout     , ktx-font     , msdf-atlas     , tasty
src/Codec/Ktx2/Font/Layout.hs view
@@ -17,6 +17,7 @@   , shapeText     -- * Placing   , placeText+  , lineRanges   , LayoutOptions(..)   , Strategy(..)   , Align(..)@@ -152,8 +153,8 @@     }  data PlacedLine = PlacedLine-  { runs :: [Shaping.PlacedRun]-  , text :: Text -- ^ What landed on the line, including the trailing @-@ when hyphenated.+  { runs :: ~[Shaping.PlacedRun]+  , text :: ~Text -- ^ What landed on the line, including the trailing @-@ when hyphenated.   , width :: Float -- ^ Placed line width, excluding trailing spaces and including the justification spread.   , ended :: Break.LineEnd   , overfull :: Bool@@ -169,17 +170,9 @@ -} placeText :: LayoutOptions -> Float -> ShapedText -> [PlacedLine] placeText opts maxWidth st =-  zipWith placeLine [0 :: Int ..] ranges+  zipWith placeLine [0 :: Int ..] (lineRanges opts maxWidth st)   where-    ranges = case opts.strategy of-      Greedy -> Break.layoutGreedyWith opts.overflow st.prepared maxWidth-      Optimal -> Break.layoutOptimalWith spacing opts.overflow st.prepared maxWidth--    spacing =-      if opts.align == AlignJustify then-        Break.justified-      else-        Break.ragged+    spacing = spacingOf opts      segments = st.prepared.segments     lastSegment = Vector.length segments - 1@@ -267,6 +260,19 @@       HardBreak -> False       ZeroWidthBreak -> False       _ -> True++lineRanges :: LayoutOptions -> Float -> ShapedText -> [Break.LineRange]+lineRanges opts maxWidth st =+  case opts.strategy of+    Greedy -> Break.layoutGreedyWith opts.overflow st.prepared maxWidth+    Optimal -> Break.layoutOptimalWith (spacingOf opts) opts.overflow st.prepared maxWidth++spacingOf :: LayoutOptions -> Break.Spacing+spacingOf opts =+  if opts.align == AlignJustify then+    Break.justified+  else+    Break.ragged  {- | Break text to fit the maximum width, then shape and place the lines. 
test/Spec.hs view
@@ -12,6 +12,7 @@ import Data.Maybe (isJust) import Data.Vector qualified as Vector import Data.Vector.Storable qualified as Storable+import KB.Text.Layout.Break qualified as Break import Numeric.Half qualified as Half import System.Directory (doesDirectoryExist, doesFileExist, listDirectory) import System.FilePath ((</>))@@ -235,6 +236,20 @@             abs (y0 + fromIntegral i * 2.0) < 0.001           plain <- Shaping.shapeText cursor{Shaping.curX = x0, Shaping.curY = y0} ctx line.text           planesOf line.runs `closeTo` planesOf plain++    , testCase "line ranges break like the placed lines" do+        (ctx, style) <- getStack+        shaped <- Layout.shapeText ctx style pangrams+        for_ [Layout.Greedy, Layout.Optimal] \strategy ->+          for_ [Layout.AlignLeft, Layout.AlignJustify] \align ->+            for_ (0 : [4.0, 4.37 .. 14.0]) \w -> do+              let+                options = Layout.LayoutOptions{cursor, strategy, align, overflow = Layout.KeepWords}+                ranges :: [Break.LineRange]+                ranges = Layout.lineRanges options w shaped+                placed = Layout.placeText options w shaped+              map (.ended) ranges @?= map (.ended) placed+              map (.overfull) ranges @?= map (.overfull) placed      , testCase "kept words put one whole word on each line at zero width" do         (ctx, style) <- getStack