Created
October 11, 2018 20:07
-
-
Save schell/412ad1ada6a7fe2e3e50a1c37457023f to your computer and use it in GitHub Desktop.
things to do with typograffiti
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- It would be nice to introduce more layout options. Something like annotated text | |
-- in iOS/UIKit. | |
-- | This is how Sandy uses cairo/pango. | |
-- https://github.com/isovector/sequoia/blob/master/src/Game/Sequoia.hs#L262-L284 | |
renderElement :: Engine -> Element -> Cairo.Render () | |
renderElement _ (TextElement (Text { textColor = (Color r g b a), .. })) = do | |
Cairo.save | |
layout <- Pango.createLayout textUTF8 | |
Cairo.liftIO $ Pango.layoutSetAttributes layout | |
[ Pango.AttrFamily { paStart = i, paEnd = j, paFamily = textTypeface } | |
, Pango.AttrWeight { paStart = i, paEnd = j, paWeight = mapFontWeight textWeight } | |
, Pango.AttrStyle { paStart = i, paEnd = j, paStyle = mapFontStyle textStyle } | |
, Pango.AttrSize { paStart = i, paEnd = j, paSize = textHeight } | |
] | |
Pango.PangoRectangle x y w h <- fmap snd $ Cairo.liftIO $ Pango.layoutGetExtents layout | |
Cairo.translate ((-w / 2) -x) ((-h / 2) - y) | |
for_ textStroke $ \ls -> do | |
Pango.layoutPath layout | |
setLineStyle ls | |
Cairo.setSourceRGBA r g b a | |
Pango.showLayout layout | |
Cairo.restore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment