From aed0013aa7c2b9831af52c44146386bec734f378 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 17 Mar 2023 15:28:37 +1300 Subject: [PATCH] Attempt to fix failure to query system fonts. --- Graphics/Layout/CSS/Internal.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Graphics/Layout/CSS/Internal.hs b/Graphics/Layout/CSS/Internal.hs index c147d73..5f7ba6c 100644 --- a/Graphics/Layout/CSS/Internal.hs +++ b/Graphics/Layout/CSS/Internal.hs @@ -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 -- 2.30.2