From 83e2a9cc192721b83d0bdafc7ded6c4c6f2b0aeb Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 26 Oct 2023 12:52:10 +1300 Subject: [PATCH] Expose text data from main module. --- Graphics/Layout.hs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Graphics/Layout.hs b/Graphics/Layout.hs index e37866a..bb412da 100644 --- a/Graphics/Layout.hs +++ b/Graphics/Layout.hs @@ -8,7 +8,8 @@ module Graphics.Layout(LayoutItem(..), UserData, layoutGetBox, layoutGetChilds, layoutGetInner, boxMinWidth, boxMaxWidth, boxNatWidth, boxWidth, boxNatHeight, boxMinHeight, boxMaxHeight, boxHeight, - boxSplit, boxPaginate, boxPosition, boxLayout{-, glyphsPerFont-}) where + boxSplit, boxPaginate, boxPosition, boxLayout, + glyphs, codepoints, fragmentFont, {-, glyphsPerFont-}) where import Data.Text.ParagraphLayout.Rich (Paragraph(..), ParagraphOptions(..), ParagraphLayout(..), layoutRich) @@ -21,7 +22,7 @@ import Graphics.Layout.Box as B import Graphics.Layout.Grid as G import Graphics.Layout.Flow as F import Graphics.Layout.Inline as I -import Graphics.Layout.CSS.Font (Font') +import Graphics.Layout.CSS.Font (Font'(..)) import Data.Maybe (fromMaybe) @@ -396,11 +397,15 @@ boxLayout parent self paginate = self9 -- | Compute a mapping from a layout tree indicating which glyphs for which fonts -- are required. -- Useful for assembling glyph atlases. -{- glyphsPerFont :: LayoutItem x y z -> M.Map (Pattern, Double) IS.IntSet -glyphsPerFont (LayoutSpan _ font self) = - (pattern font, fontSize font) `M.singleton` IS.fromList glyphs - where glyphs = map fromEnum $ map Hb.codepoint $ map fst $ fragmentGlyphs self -glyphsPerFont node = M.unionsWith IS.union $ map glyphsPerFont $ layoutGetChilds node -} +glyphsPerFont :: (CastDouble x, CastDouble y, Eq x, Eq y, Eq z) => + LayoutItem x y z -> M.Map (Pattern, Double) IS.IntSet +glyphsPerFont (LayoutSpan self) | (_:_) <- glyphs = + (pattern font, fontSize font) `M.singleton` IS.fromList glyphs + | otherwise = M.empty + where + glyphs = map fromEnum $ codepoints self + (font, _) = fragmentFont self +glyphsPerFont node = M.unionsWith IS.union $ map glyphsPerFont $ layoutGetChilds node parMap' :: NFData b => (a -> b) -> [a] -> [b] parMap' = parMap rdeepseq -- 2.30.2