Mercurial > cpython-lru_cache-weakref
annotate Modules/fmmodule.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | d36250aefb82 |
| rev | line source |
|---|---|
| 164 | 1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
3 The Netherlands. |
| 164 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 164 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 164 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
15 permission. |
| 164 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 164 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 32 /* Font Manager module */ | |
| 33 | |
| 34 #include "allobjects.h" | |
| 35 | |
| 36 #include "modsupport.h" | |
| 37 | |
| 38 #include <gl.h> | |
| 39 #include <device.h> | |
| 40 #include <fmclient.h> | |
| 41 | |
| 42 | |
| 43 /* Font Handle object implementation */ | |
| 44 | |
| 45 typedef struct { | |
| 46 OB_HEAD | |
| 47 fmfonthandle fh_fh; | |
| 48 } fhobject; | |
| 49 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
50 staticforward typeobject Fhtype; |
| 164 | 51 |
| 52 #define is_fhobject(v) ((v)->ob_type == &Fhtype) | |
| 53 | |
| 54 static object * | |
| 55 newfhobject(fh) | |
| 56 fmfonthandle fh; | |
| 57 { | |
| 58 fhobject *fhp; | |
| 59 if (fh == NULL) { | |
| 60 err_setstr(RuntimeError, "error creating new font handle"); | |
| 61 return NULL; | |
| 62 } | |
| 63 fhp = NEWOBJ(fhobject, &Fhtype); | |
| 64 if (fhp == NULL) | |
| 65 return NULL; | |
| 66 fhp->fh_fh = fh; | |
| 67 return (object *)fhp; | |
| 68 } | |
| 69 | |
| 70 /* Font Handle methods */ | |
| 71 | |
| 72 static object * | |
| 73 fh_scalefont(self, args) | |
| 74 fhobject *self; | |
| 75 object *args; | |
| 76 { | |
| 77 double size; | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
78 if (!getargs(args, "d", &size)) |
| 164 | 79 return NULL; |
| 80 return newfhobject(fmscalefont(self->fh_fh, size)); | |
| 81 } | |
| 82 | |
| 83 /* XXX fmmakefont */ | |
| 84 | |
| 85 static object * | |
| 86 fh_setfont(self, args) | |
| 87 fhobject *self; | |
| 88 object *args; | |
| 89 { | |
| 90 if (!getnoarg(args)) | |
| 91 return NULL; | |
| 92 fmsetfont(self->fh_fh); | |
| 93 INCREF(None); | |
| 94 return None; | |
| 95 } | |
| 96 | |
| 97 static object * | |
| 98 fh_getfontname(self, args) | |
| 99 fhobject *self; | |
| 100 object *args; | |
| 101 { | |
| 102 char fontname[256]; | |
| 103 int len; | |
| 104 if (!getnoarg(args)) | |
| 105 return NULL; | |
| 106 len = fmgetfontname(self->fh_fh, sizeof fontname, fontname); | |
| 107 if (len < 0) { | |
| 108 err_setstr(RuntimeError, "error in fmgetfontname"); | |
| 109 return NULL; | |
| 110 } | |
| 111 return newsizedstringobject(fontname, len); | |
| 112 } | |
| 113 | |
| 114 static object * | |
| 115 fh_getcomment(self, args) | |
| 116 fhobject *self; | |
| 117 object *args; | |
| 118 { | |
| 119 char comment[256]; | |
| 120 int len; | |
| 121 if (!getnoarg(args)) | |
| 122 return NULL; | |
| 123 len = fmgetcomment(self->fh_fh, sizeof comment, comment); | |
| 124 if (len < 0) { | |
| 125 err_setstr(RuntimeError, "error in fmgetcomment"); | |
| 126 return NULL; | |
| 127 } | |
| 128 return newsizedstringobject(comment, len); | |
| 129 } | |
| 130 | |
| 131 static object * | |
| 132 fh_getfontinfo(self, args) | |
| 133 fhobject *self; | |
| 134 object *args; | |
| 135 { | |
| 136 fmfontinfo info; | |
| 137 object *v; | |
| 138 if (!getnoarg(args)) | |
| 139 return NULL; | |
| 140 if (fmgetfontinfo(self->fh_fh, &info) < 0) { | |
| 141 err_setstr(RuntimeError, "error in fmgetfontinfo"); | |
| 142 return NULL; | |
| 143 } | |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
144 return mkvalue("(llllllll)", |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
145 info.printermatched, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
146 info.fixed_width, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
147 info.xorig, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
148 info.yorig, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
149 info.xsize, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
150 info.ysize, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
151 info.height, |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
152 info.nglyphs); |
| 164 | 153 } |
| 154 | |
| 155 #if 0 | |
| 156 static object * | |
| 157 fh_getwholemetrics(self, args) | |
| 158 fhobject *self; | |
| 159 object *args; | |
| 160 { | |
| 161 } | |
| 162 #endif | |
| 163 | |
| 164 static object * | |
| 165 fh_getstrwidth(self, args) | |
| 166 fhobject *self; | |
| 167 object *args; | |
| 168 { | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
169 char *str; |
| 164 | 170 if (!getstrarg(args, &str)) |
| 171 return NULL; | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
172 return newintobject(fmgetstrwidth(self->fh_fh, str)); |
| 164 | 173 } |
| 174 | |
| 175 static struct methodlist fh_methods[] = { | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
176 {"scalefont", (method)fh_scalefont}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
177 {"setfont", (method)fh_setfont}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
178 {"getfontname", (method)fh_getfontname}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
179 {"getcomment", (method)fh_getcomment}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
180 {"getfontinfo", (method)fh_getfontinfo}, |
| 164 | 181 #if 0 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
182 {"getwholemetrics", (method)fh_getwholemetrics}, |
| 164 | 183 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
184 {"getstrwidth", (method)fh_getstrwidth}, |
| 164 | 185 {NULL, NULL} /* sentinel */ |
| 186 }; | |
| 187 | |
| 188 static object * | |
| 189 fh_getattr(fhp, name) | |
| 190 fhobject *fhp; | |
| 191 char *name; | |
| 192 { | |
| 193 return findmethod(fh_methods, (object *)fhp, name); | |
| 194 } | |
| 195 | |
| 196 static void | |
| 197 fh_dealloc(fhp) | |
| 198 fhobject *fhp; | |
| 199 { | |
| 200 fmfreefont(fhp->fh_fh); | |
| 201 DEL(fhp); | |
| 202 } | |
| 203 | |
| 204 static typeobject Fhtype = { | |
| 205 OB_HEAD_INIT(&Typetype) | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
206 0, /*ob_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
207 "font handle", /*tp_name*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
208 sizeof(fhobject), /*tp_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
209 0, /*tp_itemsize*/ |
| 164 | 210 /* methods */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
211 (destructor)fh_dealloc, /*tp_dealloc*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
212 0, /*tp_print*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
213 (getattrfunc)fh_getattr, /*tp_getattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
214 0, /*tp_setattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
215 0, /*tp_compare*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
216 0, /*tp_repr*/ |
| 164 | 217 }; |
| 218 | |
| 219 | |
| 220 /* Font Manager functions */ | |
| 221 | |
| 222 static object * | |
| 223 fm_init(self, args) | |
| 224 object *self, *args; | |
| 225 { | |
| 226 if (!getnoarg(args)) | |
| 227 return NULL; | |
| 228 fminit(); | |
| 229 INCREF(None); | |
| 230 return None; | |
| 231 } | |
| 232 | |
| 233 static object * | |
| 234 fm_findfont(self, args) | |
| 235 object *self, *args; | |
| 236 { | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
237 char *str; |
| 164 | 238 if (!getstrarg(args, &str)) |
| 239 return NULL; | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
240 return newfhobject(fmfindfont(str)); |
| 164 | 241 } |
| 242 | |
| 243 static object * | |
| 244 fm_prstr(self, args) | |
| 245 object *self, *args; | |
| 246 { | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
247 char *str; |
| 164 | 248 if (!getstrarg(args, &str)) |
| 249 return NULL; | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
250 fmprstr(str); |
| 164 | 251 INCREF(None); |
| 252 return None; | |
| 253 } | |
| 254 | |
| 255 /* XXX This uses a global variable as temporary! Not re-entrant! */ | |
| 256 | |
| 257 static object *fontlist; | |
| 258 | |
| 259 static void | |
| 260 clientproc(fontname) | |
| 261 char *fontname; | |
| 262 { | |
| 263 int err; | |
| 264 object *v; | |
| 265 if (fontlist == NULL) | |
| 266 return; | |
| 267 v = newstringobject(fontname); | |
| 268 if (v == NULL) | |
| 269 err = -1; | |
| 270 else { | |
| 271 err = addlistitem(fontlist, v); | |
| 272 DECREF(v); | |
| 273 } | |
| 274 if (err != 0) { | |
| 275 DECREF(fontlist); | |
| 276 fontlist = NULL; | |
| 277 } | |
| 278 } | |
| 279 | |
| 280 static object * | |
| 281 fm_enumerate(self, args) | |
| 282 object *self, *args; | |
| 283 { | |
| 284 object *res; | |
| 285 if (!getnoarg(args)) | |
| 286 return NULL; | |
| 287 fontlist = newlistobject(0); | |
| 288 if (fontlist == NULL) | |
| 289 return NULL; | |
| 290 fmenumerate(clientproc); | |
| 291 res = fontlist; | |
| 292 fontlist = NULL; | |
| 293 return res; | |
| 294 } | |
| 295 | |
| 296 static object * | |
| 297 fm_setpath(self, args) | |
| 298 object *self, *args; | |
| 299 { | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
300 char *str; |
| 164 | 301 if (!getstrarg(args, &str)) |
| 302 return NULL; | |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
164
diff
changeset
|
303 fmsetpath(str); |
| 164 | 304 INCREF(None); |
| 305 return None; | |
| 306 } | |
| 307 | |
| 308 static object * | |
| 309 fm_fontpath(self, args) | |
| 310 object *self, *args; | |
| 311 { | |
| 312 if (!getnoarg(args)) | |
| 313 return NULL; | |
| 314 return newstringobject(fmfontpath()); | |
| 315 } | |
| 316 | |
| 317 static struct methodlist fm_methods[] = { | |
| 318 {"init", fm_init}, | |
| 319 {"findfont", fm_findfont}, | |
| 320 {"enumerate", fm_enumerate}, | |
| 321 {"prstr", fm_prstr}, | |
| 322 {"setpath", fm_setpath}, | |
| 323 {"fontpath", fm_fontpath}, | |
| 324 {NULL, NULL} /* sentinel */ | |
| 325 }; | |
| 326 | |
| 327 | |
| 328 void | |
| 329 initfm() | |
| 330 { | |
| 331 initmodule("fm", fm_methods); | |
| 332 fminit(); | |
| 333 } |
