@@ -20,7 +20,7 @@ module Graphics.X11.Xlib.Font(
20
20
fontFromGC ,
21
21
loadQueryFont ,
22
22
freeFont ,
23
- FontStruct ,
23
+ FontStruct ,
24
24
fontFromFontStruct ,
25
25
ascentFromFontStruct ,
26
26
descentFromFontStruct ,
@@ -55,9 +55,9 @@ type Glyph = Word16
55
55
-- | pointer to an X11 @XFontStruct@ structure
56
56
newtype FontStruct = FontStruct (Ptr FontStruct )
57
57
#if __GLASGOW_HASKELL__
58
- deriving (Eq , Ord , Show , Typeable , Data )
58
+ deriving (Eq , Ord , Show , Typeable , Data )
59
59
#else
60
- deriving (Eq , Ord , Show )
60
+ deriving (Eq , Ord , Show )
61
61
#endif
62
62
63
63
-- Disnae exist: %fun LoadFont :: Display -> String -> IO Font
@@ -70,7 +70,7 @@ newtype FontStruct = FontStruct (Ptr FontStruct)
70
70
71
71
-- | interface to the X11 library function @XQueryFont()@.
72
72
foreign import ccall unsafe " HsXlib.h XQueryFont"
73
- queryFont :: Display -> Font -> IO FontStruct
73
+ queryFont :: Display -> Font -> IO FontStruct
74
74
75
75
-- Note that this _WILL NOT WORK_ unless you have explicitly set the font.
76
76
-- I'm slowly but surely coming to the conclusion that Xlib is a pile of
@@ -79,40 +79,40 @@ foreign import ccall unsafe "HsXlib.h XQueryFont"
79
79
-- | interface to the X11 library function @XGetGCValues()@.
80
80
fontFromGC :: Display -> GC -> IO Font
81
81
fontFromGC display gc =
82
- allocaBytes # {size XGCValues } $ \ values -> do
83
- throwIfZero " fontFromGC" $
84
- xGetGCValues display gc # {const GCFont } values
85
- # {peek XGCValues ,font} values
82
+ allocaBytes # {size XGCValues } $ \ values -> do
83
+ throwIfZero " fontFromGC" $
84
+ xGetGCValues display gc # {const GCFont } values
85
+ # {peek XGCValues ,font} values
86
86
foreign import ccall unsafe " HsXlib.h XGetGCValues"
87
- xGetGCValues :: Display -> GC -> ValueMask -> Ptr GCValues -> IO CInt
87
+ xGetGCValues :: Display -> GC -> ValueMask -> Ptr GCValues -> IO CInt
88
88
89
89
type ValueMask = # {type unsigned long }
90
90
91
91
-- | interface to the X11 library function @XLoadQueryFont()@.
92
92
loadQueryFont :: Display -> String -> IO FontStruct
93
93
loadQueryFont display name =
94
- withCString name $ \ c_name -> do
95
- fs <- throwIfNull " loadQueryFont" $ xLoadQueryFont display c_name
96
- return (FontStruct fs)
94
+ withCString name $ \ c_name -> do
95
+ fs <- throwIfNull " loadQueryFont" $ xLoadQueryFont display c_name
96
+ return (FontStruct fs)
97
97
foreign import ccall unsafe " HsXlib.h XLoadQueryFont"
98
- xLoadQueryFont :: Display -> CString -> IO (Ptr FontStruct )
98
+ xLoadQueryFont :: Display -> CString -> IO (Ptr FontStruct )
99
99
100
100
-- | interface to the X11 library function @XFreeFont()@.
101
101
foreign import ccall unsafe " HsXlib.h XFreeFont"
102
- freeFont :: Display -> FontStruct -> IO ()
102
+ freeFont :: Display -> FontStruct -> IO ()
103
103
-- %fun XSetFontPath :: Display -> ListString -> IO () using XSetFontPath(arg1,arg2,arg2_size)
104
104
105
105
fontFromFontStruct :: FontStruct -> Font
106
106
fontFromFontStruct (FontStruct fs) = unsafePerformIO $
107
- # {peek XFontStruct ,fid} fs
107
+ # {peek XFontStruct ,fid} fs
108
108
109
109
ascentFromFontStruct :: FontStruct -> Int32
110
110
ascentFromFontStruct (FontStruct fs) = unsafePerformIO $
111
- # {peek XFontStruct ,ascent} fs
111
+ # {peek XFontStruct ,ascent} fs
112
112
113
113
descentFromFontStruct :: FontStruct -> Int32
114
114
descentFromFontStruct (FontStruct fs) = unsafePerformIO $
115
- # {peek XFontStruct ,descent} fs
115
+ # {peek XFontStruct ,descent} fs
116
116
117
117
-- %prim XGetFontPath :: Display -> IO ListString
118
118
-- Int r_size;
@@ -135,58 +135,58 @@ descentFromFontStruct (FontStruct fs) = unsafePerformIO $
135
135
136
136
-- We marshall this across right away because it's usually one-off info
137
137
type CharStruct =
138
- ( CInt -- lbearing (origin to left edge of raster)
139
- , CInt -- rbearing (origin to right edge of raster)
140
- , CInt -- width (advance to next char's origin)
141
- , CInt -- ascent (baseline to top edge of raster)
142
- , CInt -- descent (baseline to bottom edge of raster)
143
- -- attributes omitted
144
- )
138
+ ( CInt -- lbearing (origin to left edge of raster)
139
+ , CInt -- rbearing (origin to right edge of raster)
140
+ , CInt -- width (advance to next char's origin)
141
+ , CInt -- ascent (baseline to top edge of raster)
142
+ , CInt -- descent (baseline to bottom edge of raster)
143
+ -- attributes omitted
144
+ )
145
145
146
146
peekCharStruct :: Ptr CharStruct -> IO CharStruct
147
147
peekCharStruct p = do
148
- lbearing <- # {peek XCharStruct ,lbearing} p
149
- rbearing <- # {peek XCharStruct ,rbearing} p
150
- width <- # {peek XCharStruct ,width} p
151
- ascent <- # {peek XCharStruct ,ascent} p
152
- descent <- # {peek XCharStruct ,descent} p
153
- return (fromIntegral (lbearing:: CShort ),
154
- fromIntegral (rbearing:: CShort ),
155
- fromIntegral (width:: CShort ),
156
- fromIntegral (ascent:: CShort ),
157
- fromIntegral (descent:: CShort ))
148
+ lbearing <- # {peek XCharStruct ,lbearing} p
149
+ rbearing <- # {peek XCharStruct ,rbearing} p
150
+ width <- # {peek XCharStruct ,width} p
151
+ ascent <- # {peek XCharStruct ,ascent} p
152
+ descent <- # {peek XCharStruct ,descent} p
153
+ return (fromIntegral (lbearing:: CShort ),
154
+ fromIntegral (rbearing:: CShort ),
155
+ fromIntegral (width:: CShort ),
156
+ fromIntegral (ascent:: CShort ),
157
+ fromIntegral (descent:: CShort ))
158
158
159
159
-- No need to put this in the IO monad - this info is essentially constant
160
160
161
161
-- | interface to the X11 library function @XTextExtents()@.
162
162
textExtents :: FontStruct -> String -> (FontDirection , Int32 , Int32 , CharStruct )
163
163
textExtents font_struct string = unsafePerformIO $
164
- withCStringLen string $ \ (c_string, nchars) ->
165
- alloca $ \ direction_return ->
166
- alloca $ \ font_ascent_return ->
167
- alloca $ \ font_descent_return ->
168
- allocaBytes # {size XCharStruct } $ \ overall_return -> do
169
- _ <- xTextExtents font_struct c_string (fromIntegral nchars) direction_return
170
- font_ascent_return font_descent_return overall_return
171
- direction <- peek direction_return
172
- ascent <- peek font_ascent_return
173
- descent <- peek font_descent_return
174
- cs <- peekCharStruct overall_return
175
- return (direction, ascent, descent, cs)
164
+ withCStringLen string $ \ (c_string, nchars) ->
165
+ alloca $ \ direction_return ->
166
+ alloca $ \ font_ascent_return ->
167
+ alloca $ \ font_descent_return ->
168
+ allocaBytes # {size XCharStruct } $ \ overall_return -> do
169
+ _ <- xTextExtents font_struct c_string (fromIntegral nchars) direction_return
170
+ font_ascent_return font_descent_return overall_return
171
+ direction <- peek direction_return
172
+ ascent <- peek font_ascent_return
173
+ descent <- peek font_descent_return
174
+ cs <- peekCharStruct overall_return
175
+ return (direction, ascent, descent, cs)
176
176
foreign import ccall unsafe " HsXlib.h XTextExtents"
177
- xTextExtents :: FontStruct -> CString -> CInt ->
178
- Ptr FontDirection -> Ptr Int32 -> Ptr Int32 ->
179
- Ptr CharStruct -> IO CInt
177
+ xTextExtents :: FontStruct -> CString -> CInt ->
178
+ Ptr FontDirection -> Ptr Int32 -> Ptr Int32 ->
179
+ Ptr CharStruct -> IO CInt
180
180
181
181
-- No need to put ths in the IO monad - this info is essentially constant
182
182
183
183
-- | interface to the X11 library function @XTextWidth()@.
184
184
textWidth :: FontStruct -> String -> Int32
185
185
textWidth font_struct string = unsafePerformIO $
186
- withCStringLen string $ \ (c_string, len) ->
187
- xTextWidth font_struct c_string (fromIntegral len)
186
+ withCStringLen string $ \ (c_string, len) ->
187
+ xTextWidth font_struct c_string (fromIntegral len)
188
188
foreign import ccall unsafe " HsXlib.h XTextWidth"
189
- xTextWidth :: FontStruct -> CString -> CInt -> IO Int32
189
+ xTextWidth :: FontStruct -> CString -> CInt -> IO Int32
190
190
191
191
-- XTextExtents16 omitted
192
192
-- XTextWidth16 omitted
0 commit comments