~alcinnz/CatTrap

aed0013aa7c2b9831af52c44146386bec734f378 — Adrian Cochrane 1 year, 8 months ago 03748b5
Attempt to fix failure to query system fonts.
1 files changed, 5 insertions(+), 8 deletions(-)

M Graphics/Layout/CSS/Internal.hs
M Graphics/Layout/CSS/Internal.hs => Graphics/Layout/CSS/Internal.hs +5 -8
@@ 14,7 14,7 @@ import Data.Text.Glyphize as HB
import Graphics.Text.Font.Choose (Pattern(..), Value(..), normalizePattern,
                                  getValue', getValue0, setValue, Binding(..),
                                  configSubstitute', defaultSubstitute,
                                  fontMatch', MatchKind(..))
                                  fontSort', MatchKind(..), fontRenderPrepare')
import qualified Data.ByteString as B
import System.IO.Unsafe (unsafePerformIO)



@@ 89,10 89,6 @@ hbScale f = fontSize f*hbUnit
hbUnit = 64 :: Double

pattern2hbfont :: Pattern -> Int -> [Variation] -> Font
pattern2hbfont pat scale variations | Nothing <- lookup "file" pat =
    let fontpath = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf" :: String
    in let pat' = setValue "file" Strong fontpath pat
    in pattern2hbfont pat' scale variations
pattern2hbfont pat scale variations = createFontWithOptions options face
  where
    bytes = unsafePerformIO $ B.readFile $ getValue0 "file" pat


@@ 133,11 129,12 @@ pattern2font pat styles parent root = Font' {
        fontSize' = lowerLength' (cssFontSize styles) parent
        lowerLength' a = lowerLength (fontSize parent) . finalizeLength a
        fontGlyph' ch = fromMaybe 0 $ fontGlyph font' ch Nothing
        pat' | Nothing <- lookup "family" pat, Just val <- lookup "family" $ pattern root =
        q | 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 = fromMaybe (pattern parent) $ fontMatch' $ defaultSubstitute $
                flip configSubstitute' MatchPattern pat'
        font = case fontSort' (defaultSubstitute $ configSubstitute' q MatchPattern) False of
            Just (font:_, _) -> fontRenderPrepare' q font
            _ -> error "TODO: Set fallback font!"
        font' = pattern2hbfont font (round scale') $ variations' fontSize' styles
        scale' = fontSize'*hbUnit