Debian Codegraph @

src/Graphics/UI/GLUT/Raw/Fonts.hs

raw
1 {-# OPTIONS_HADDOCK hide #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Graphics.UI.GLUT.Raw.Fonts
5 -- Copyright : (c) Sven Panne 2018
6 -- License : BSD3
7 --
8 -- Maintainer : Sven Panne <[email protected]>
9 -- Stability : stable
10 -- Portability : portable
11 --
12 -- Our own functions to access font identifiers in a portable way.
13 --
14 -----------------------------------------------------------------------------
15
16 module Graphics.UI.GLUT.Raw.Fonts (
17 BitmapFont(..), GLUTbitmapFont, marshalBitmapFont,
18 StrokeFont(..), GLUTstrokeFont, marshalStrokeFont
19 ) where
20
21 import Control.Monad.IO.Class ( MonadIO(..) )
22 import Foreign.C.Types
23 import Foreign.Ptr ( Ptr )
24
25 --------------------------------------------------------------------------------
26
27 -- | The bitmap fonts available in GLUT. The exact bitmap to be used is
28 -- defined by the standard X glyph bitmaps for the X font with the given name.
29
30 data BitmapFont
31 = Fixed8By13 -- ^ A fixed width font with every character fitting in an 8
32 -- by 13 pixel rectangle.
33 -- (@-misc-fixed-medium-r-normal--13-120-75-75-C-80-iso8859-1@)
34 | Fixed9By15 -- ^ A fixed width font with every character fitting in an 9
35 -- by 15 pixel rectangle.
36 -- (@-misc-fixed-medium-r-normal--15-140-75-75-C-90-iso8859-1@)
37 | TimesRoman10 -- ^ A 10-point proportional spaced Times Roman font.
38 -- (@-adobe-times-medium-r-normal--10-100-75-75-p-54-iso8859-1@)
39 | TimesRoman24 -- ^ A 24-point proportional spaced Times Roman font.
40 -- (@-adobe-times-medium-r-normal--24-240-75-75-p-124-iso8859-1@)
41 | Helvetica10 -- ^ A 10-point proportional spaced Helvetica font.
42 -- (@-adobe-helvetica-medium-r-normal--10-100-75-75-p-56-iso8859-1@)
43 | Helvetica12 -- ^ A 12-point proportional spaced Helvetica font.
44 -- (@-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1@)
45 | Helvetica18 -- ^ A 18-point proportional spaced Helvetica font.
46 -- (@-adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1@)
47 deriving ( Eq, Ord, Show )
48
49 -- Alas, fonts in GLUT are not denoted by some integral value, but by opaque
50 -- pointers on the C side. Even worse: For WinDoze, they are simply small ints,
51 -- casted to void*, for other platforms addresses of global variables are used.
52 -- And all is done via ugly #ifdef-ed #defines... Aaaaargl! So the only portable
53 -- way is using integers on the Haskell side and doing the marshaling via some
54 -- small C wrappers around those macros. *sigh*
55 type GLUTbitmapFont = Ptr ()
56
57 marshalBitmapFont :: MonadIO m => BitmapFont -> m GLUTbitmapFont
58 marshalBitmapFont x = liftIO $ case x of
59 Fixed8By13 -> hs_GLUT_marshalBitmapFont 0
60 Fixed9By15 -> hs_GLUT_marshalBitmapFont 1
61 TimesRoman10 -> hs_GLUT_marshalBitmapFont 2
62 TimesRoman24 -> hs_GLUT_marshalBitmapFont 3
63 Helvetica10 -> hs_GLUT_marshalBitmapFont 4
64 Helvetica12 -> hs_GLUT_marshalBitmapFont 5
65 Helvetica18 -> hs_GLUT_marshalBitmapFont 6
66
67 foreign import ccall unsafe "hs_GLUT_marshalBitmapFont"
68 hs_GLUT_marshalBitmapFont :: CInt -> IO (Ptr a)
69
70 --------------------------------------------------------------------------------
71
72 -- | The stroke fonts available in GLUT.
73 data StrokeFont
74 = Roman -- ^ A proportionally spaced Roman Simplex font for ASCII
75 -- characters 32 through 127. The maximum top character in the
76 -- font is 119.05 units; the bottom descends 33.33 units.
77 | MonoRoman -- ^ A mono-spaced spaced Roman Simplex font (same characters as
78 -- 'Roman') for ASCII characters 32 through 127. The maximum
79 -- top character in the font is 119.05 units; the bottom
80 -- descends 33.33 units. Each character is 104.76 units wide.
81 deriving ( Eq, Ord, Show )
82
83 -- Same remarks as for GLUTbitmapFont
84 type GLUTstrokeFont = Ptr ()
85
86 marshalStrokeFont :: MonadIO m => StrokeFont -> m GLUTstrokeFont
87 marshalStrokeFont x = liftIO $ case x of
88 Roman -> hs_GLUT_marshalStrokeFont 0
89 MonoRoman -> hs_GLUT_marshalStrokeFont 1
90
91 foreign import ccall unsafe "hs_GLUT_marshalStrokeFont"
92 hs_GLUT_marshalStrokeFont :: CInt -> IO (Ptr a)