24
24
toDouble = fromIntegral
26
26
type LayoutFunc = G.PangoLayout -> G.Markup -> IO ()
27
type LayoutFuncGlowing = String -> CXy -> Double -> String -> IO (G.PangoLayout, G.PangoLayout, Double, Double)
28
29
stringToLayout :: String -> LayoutFunc -> CXy -> Double -> String -> IO (G.PangoLayout, Double, Double)
29
stringToLayout fname lFun (x, _) fsize text = do
30
stringToLayout fname func (x, _) fsize text = do
30
31
lay <- G.cairoCreateContext Nothing >>= G.layoutEmpty
32
33
G.layoutSetWrap lay G.WrapPartialWords
34
35
fd <- liftIO G.fontDescriptionNew
53
54
truePosition _ _ (x', y') =
54
55
error $ "called with x=" ++ show x' ++ " y=" ++ show y'
56
renderLayout' :: String -> LayoutFunc -> CXy -> Double -> String -> C.Render Double
57
renderLayout' fname lFun (x, y) fsize text = do
57
stringToLayoutGlowing :: LayoutFunc -> LayoutFunc -> LayoutFuncGlowing
58
stringToLayoutGlowing funcBack funcFront fname xy fsize text = do
59
(layB, _, _) <- stringToLayout fname funcBack xy fsize text
60
(lay, lw, lh) <- stringToLayout fname funcFront xy fsize text
61
return (layB, lay, lw, lh)
63
renderLayout' :: String -> LayoutFuncGlowing -> CXy -> Double -> String -> C.Render Double
64
renderLayout' fname func (x, y) fsize text = do
59
(lay, lw, lh) <- liftIO $ stringToLayout fname lFun (x, y) fsize text
66
(layB, lay, lw, lh) <- liftIO $ func fname (x, y) fsize text
60
67
let (xt, yt) = truePosition fsize lw (x, y)
68
mapM_ (moveShowLayout layB)
69
[(xt + xd, yt + yd) | xd <- [-0.7, 0.7], yd <- [-0.7, 0.7]]
70
moveShowLayout lay (xt, yt)
74
moveShowLayout l (x', y') = C.moveTo x' y' >> G.showLayout l
66
76
renderLayoutM :: CXy -> Double -> String -> C.Render Double
67
renderLayoutM = renderLayout' "IPA P明朝" G.layoutSetText
78
renderLayout' "IPA P明朝" (stringToLayoutGlowing fb ff)
80
fb l t = void $ G.layoutSetMarkup l ("<span foreground=\"white\">" ++ G.escapeMarkup t ++ "</span>")
69
renderLayoutG' :: LayoutFunc -> CXy -> Double -> String -> C.Render Double
83
renderLayoutG' :: LayoutFuncGlowing -> CXy -> Double -> String -> C.Render Double
70
84
renderLayoutG' = renderLayout' "IPAゴシック"
72
86
renderLayoutG :: Attr -> CXy -> Double -> String -> C.Render Double
73
renderLayoutG (_, [], _) xy fs txt =
74
renderLayoutG' G.layoutSetText xy fs txt
75
renderLayoutG (_, classs, _) xy fs txt =
76
renderLayoutG' f xy fs txt'
78
txt' = formatPangoMarkup (head classs) txt
79
f l t = void $ G.layoutSetMarkup l t
87
renderLayoutG (_, [], _) =
88
renderLayoutG' (stringToLayoutGlowing fb ff)
90
fb l t = void $ G.layoutSetMarkup l ("<span foreground=\"white\">" ++ G.escapeMarkup t ++ "</span>")
92
renderLayoutG (_, classs, _) =
93
renderLayoutG' (stringToLayoutGlowing fb ff)
95
fb l t = void $ G.layoutSetMarkup l (formatPangoMarkupWhite (head classs) t)
96
ff l t = void $ G.layoutSetMarkup l (formatPangoMarkup (head classs) t)
81
98
renderSurface :: Double -> Double -> Double -> C.Surface -> C.Render ()
82
99
renderSurface x y alpha surface = do