~alcinnz/CatTrap

6099cfd91bc68ec5a3c3657ffa5d3461e929d931 — Adrian Cochrane 1 year, 8 months ago 7d7cb04
Actually query for desired font, remove needless Maybe.
2 files changed, 11 insertions(+), 8 deletions(-)

M Graphics/Layout/CSS/Internal.hs
M Graphics/Layout/Inline/CSS.hs
M Graphics/Layout/CSS/Internal.hs => Graphics/Layout/CSS/Internal.hs +10 -6
@@ 12,7 12,9 @@ import Graphics.Layout.Box

import Data.Text.Glyphize as HB
import Graphics.Text.Font.Choose (Pattern(..), Value(..), normalizePattern,
                                  getValue', getValue0, setValue, Binding(..))
                                  getValue', getValue0, setValue, Binding(..),
                                  configSubstitute', defaultSubstitute,
                                  fontMatch', MatchKind(..))
import qualified Data.ByteString as B
import System.IO.Unsafe (unsafePerformIO)



@@ 67,7 69,7 @@ finalizeLength (_,unit) _ = trace ("Invalid unit " ++ Txt.unpack unit) $ Pixels 
px2pt f x = x / scale f / 96 * 72

data Font' = Font' {
    hbFont :: Maybe Font, -- Optional for sake of demo script, FIXME better solution?
    hbFont :: Font,
    pattern :: Pattern,
    fontHeight :: Char -> Double,
    fontAdvance :: Char -> Double,


@@ 81,7 83,7 @@ data Font' = Font' {
    vmin :: Double,
    scale :: Double
}
placeholderFont = Font' Nothing [] (const 0) (const 0) 0 0 0 0  0 0 0 0  1
placeholderFont = Font' undefined [] (const 0) (const 0) 0 0 0 0  0 0 0 0  1
hbScale f = fontSize f*hbUnit
hbUnit = 64



@@ 103,8 105,8 @@ pattern2font :: Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font pat styles@CSSFont { cssFontSize = (x,"initial") } parent root =
    pattern2font pat styles { cssFontSize = (x*fontSize root," ") } parent root
pattern2font pat styles parent root = Font' {
        hbFont = Just font',
        pattern = pat',
        hbFont = font',
        pattern = font,
        fontHeight = height' . fontGlyphExtents font' . fontGlyph',
        fontAdvance = fromIntegral . fontGlyphHAdvance font' . fontGlyph',
        fontSize = fontSize',


@@ 129,7 131,9 @@ pattern2font pat styles parent root = Font' {
        pat' | Nothing <- lookup "family" pat, Just val <- lookup "family" $ pattern root =
                ("family", val):setValue "size" Weak (px2pt root fontSize') pat
            | otherwise = setValue "size" Weak (px2pt root fontSize') pat
        font' = pattern2hbfont pat' (round scale') $ variations' fontSize' styles
        font = fromMaybe (pattern parent) $ fontMatch' $ defaultSubstitute $
                flip configSubstitute' MatchPattern pat'
        font' = pattern2hbfont font (round scale') $ variations' fontSize' styles
        scale' = fontSize'*hbUnit

data CSSFont = CSSFont {

M Graphics/Layout/Inline/CSS.hs => Graphics/Layout/Inline/CSS.hs +1 -2
@@ 8,7 8,6 @@ import qualified Data.Text as Txt
import Data.Text.Internal (Text(..))
import Data.Text.ParagraphLayout (Span(..), SpanOptions(..), LineHeight(..),
                                Paragraph(..), ParagraphOptions(..))
import Data.Maybe (fromJust)

import Graphics.Layout.CSS.Internal (Font'(..), hbScale)



@@ 44,7 43,7 @@ finalizeParagraph (ParagraphBuilder txt ops) font' = Paragraph txt' 0 ops pOps
    where
        Text txt' _ _ = Lz.toStrict txt
        pOps = ParagraphOptions {
            paragraphFont = fromJust $ hbFont font',
            paragraphFont = hbFont font',
            paragraphLineHeight = Absolute $ round (lineheight font' * hbScale font'),
            paragraphMaxWidth = 0 -- This is what we're computing!
        }