~alcinnz/CatTrap

cdc350349a9cf2f83b74014a0bd7c264c67c8c79 — Adrian Cochrane 1 year, 1 day ago 484ba2c
Fixes to traverse & retrieve laid out text!
3 files changed, 16 insertions(+), 6 deletions(-)

M Graphics/Layout.hs
M app/Integration.hs
M app/Integration2.hs
M Graphics/Layout.hs => Graphics/Layout.hs +3 -2
@@ 95,7 95,8 @@ layoutGetBox' = mapX' toDouble . mapY' toDouble . layoutGetBox
-- | Retrieve the subtree under a node.
layoutGetChilds (LayoutFlow _ _ ret) = ret
layoutGetChilds (LayoutGrid _ _ _ ret) = ret
layoutGetChilds (LayoutSpan _) = []
layoutGetChilds (LayoutSpan (Leaf _)) = []
layoutGetChilds (LayoutSpan (Branch _ ret)) = map LayoutSpan ret
layoutGetChilds (LayoutInline _ self _) = map LayoutSpan $ inlineChildren self
layoutGetChilds (LayoutInline' _ self _) = map LayoutSpan $ layoutChildren self
layoutGetChilds (LayoutConst _ _ childs) = childs


@@ 444,7 445,7 @@ boxLayout parent self paginate = self9
-- Useful for assembling glyph atlases.
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 =
glyphsPerFont (LayoutSpan self@(Leaf _)) | (_:_) <- glyphs =
        (pattern font, fontSize font) `M.singleton` IS.fromList glyphs
    | otherwise = M.empty
  where

M app/Integration.hs => app/Integration.hs +5 -2
@@ 12,7 12,7 @@ import qualified System.Directory as Dir

import Graphics.Layout.CSS (CSSBox(..), finalizeCSS')
import Graphics.Layout.CSS.Font (placeholderFont)
import Graphics.Layout (LayoutItem, boxLayout,
import Graphics.Layout (LayoutItem, boxLayout, glyphsPerFont,
                        layoutGetBox, layoutGetChilds, layoutGetInner)
import Graphics.Layout.Box (zeroBox)
import qualified Graphics.Layout.Box as B


@@ 42,6 42,7 @@ import SDL hiding (rotate)
import Foreign.C.Types (CInt)
import Data.Function (fix)
import Control.Monad (unless)
import Control.Exception (evaluate)
import qualified Graphics.Text.Font.Choose as FC

initReferer :: IO (Page (CSSCond.ConditionalStyles (CSSBox Nil)))


@@ 140,7 141,9 @@ main = do

        pages <- tryReadMVar pages'
        case pages of
            Just (display:_) -> renderDisplay renderer display
            Just (display:_) -> do
                evaluate $ glyphsPerFont display 
                renderDisplay renderer display
            _ -> return ()

        present renderer

M app/Integration2.hs => app/Integration2.hs +8 -2
@@ 14,7 14,7 @@ import Data.Maybe (fromMaybe)

import Graphics.Layout.CSS.Font (placeholderFont)
import Graphics.Layout.CSS (finalizeCSS', CSSBox)
import Graphics.Layout (LayoutItem, boxLayout)
import Graphics.Layout (LayoutItem, boxLayout, glyphsPerFont)
import Graphics.Layout.Box (Length, Size(..), PaddedBox(..), zeroBox)

import Control.Exception (evaluate)


@@ 51,7 51,13 @@ main = do
        layout = finalizeCSS' placeholderFont styles
    layout `seq` print "Laying out page!"
    res <- forkCompute $ boxLayout zeroBox { size = Size 1280 480 } layout False
    readMVar res
    res' <- readMVar res
    case res' of
        (page:_) -> do
            print "Gathering atlas"
            evaluate $ glyphsPerFont page
            return ()
        _ -> return ()
    --performGC
    --FC.fini -- FIXME: GC still left FontConfig references...
    return ()