~alcinnz/CatTrap

7d7cb04a82eb7945e379fcbfa3eb476020f238fe — Adrian Cochrane 1 year, 3 months ago 86d19fc
Expose utility to inform atlas construction.
2 files changed, 17 insertions(+), 3 deletions(-)

M Graphics/Layout.hs
M cattrap.cabal
M Graphics/Layout.hs => Graphics/Layout.hs +14 -2
@@ 1,16 1,22 @@
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module Graphics.Layout where

import Data.Text.ParagraphLayout (Paragraph(..), ParagraphOptions(..), Fragment)
import Data.Text.ParagraphLayout (Paragraph(..), ParagraphOptions(..), Fragment(..))

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.Internal (Font')
import Graphics.Layout.CSS.Internal (Font'(..))

import Data.Maybe (fromMaybe)

-- To gather glyphs for atlases.
import qualified Data.IntSet as IS
import qualified Data.Map.Strict as M
import qualified Data.Text.Glyphize as Hb
import Graphics.Text.Font.Choose (Pattern)

data LayoutItem m n x =
    LayoutFlow x (PaddedBox m n) [LayoutItem m n x]
    | LayoutGrid x (Grid m n) [(GridItem m n, LayoutItem m n x)]


@@ 315,3 321,9 @@ boxLayout parent self paginate = self8
    (_, self6) = boxMaxHeight parent self5
    (_, self7) = boxHeight parent self6
    self8 = boxPosition (0, 0) self7

-- Useful for assembling glyph atlases.
glyphsPerFont :: LayoutItem x y z -> M.Map Pattern IS.IntSet
glyphsPerFont (LayoutSpan _ font self) = pattern 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

M cattrap.cabal => cattrap.cabal +3 -1
@@ 23,7 23,9 @@ library
                        Graphics.Layout.Inline, Graphics.Layout.Inline.CSS
  -- other-modules:
  -- other-extensions:
  build-depends:       base >=4.12 && <4.16, css-syntax, scientific, text, stylist-traits, fontconfig-pure, harfbuzz-pure, bytestring, balkon
  build-depends:       base >=4.12 && <4.16, containers,
                        css-syntax, scientific, text, stylist-traits,
                        fontconfig-pure, harfbuzz-pure, bytestring, balkon
  -- hs-source-dirs:
  default-language:    Haskell2010
  ghc-options:         -Wincomplete-patterns