1 | /* |
---|
2 | * $Id: StrToXFont.c,v 1.2 1999-01-22 23:17:01 ghudson Exp $ |
---|
3 | * |
---|
4 | * Copyright 1990, 1991 by the Massachusetts Institute of Technology. |
---|
5 | * |
---|
6 | * For copying and distribution information, please see the file |
---|
7 | * <mit-copyright.h>. |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #if (!defined(lint)) && (!defined(SABER)) |
---|
12 | static char *rcsid = |
---|
13 | "$Id: StrToXFont.c,v 1.2 1999-01-22 23:17:01 ghudson Exp $"; |
---|
14 | #endif |
---|
15 | |
---|
16 | #include "mit-copyright.h" |
---|
17 | #include "Jets.h" |
---|
18 | #include "hash.h" |
---|
19 | |
---|
20 | struct hash *fonts = NULL; |
---|
21 | |
---|
22 | static XFontStruct *XjLoadQueryFontCache(display, name) |
---|
23 | Display *display; |
---|
24 | char *name; |
---|
25 | { |
---|
26 | XrmQuark qname; |
---|
27 | XFontStruct *fs; |
---|
28 | |
---|
29 | if (fonts == NULL) |
---|
30 | fonts = create_hash(13); |
---|
31 | |
---|
32 | qname = XrmStringToQuark(name); |
---|
33 | fs = (XFontStruct *)hash_lookup(fonts, qname); |
---|
34 | |
---|
35 | if (fs == NULL) |
---|
36 | fs = XLoadQueryFont(display, name); |
---|
37 | |
---|
38 | if (fs != NULL) |
---|
39 | (void)hash_store(fonts, qname, (caddr_t) fs); |
---|
40 | |
---|
41 | return fs; |
---|
42 | } |
---|
43 | |
---|
44 | /* |
---|
45 | * string to XFontStruct conversion |
---|
46 | */ |
---|
47 | int StrToXFontStruct(display, window, where, resource, type, address) |
---|
48 | Display *display; |
---|
49 | Window window; |
---|
50 | caddr_t where; |
---|
51 | XjResource *resource; |
---|
52 | char *type; |
---|
53 | caddr_t address; |
---|
54 | { |
---|
55 | char errtext[100]; |
---|
56 | XFontStruct *fontstr; |
---|
57 | |
---|
58 | char *sub1 = "-*-*-medium-r-*-*-*-120-*-*-*-*-iso8859-1"; |
---|
59 | char *trying = "trying to substitute `%s'."; |
---|
60 | |
---|
61 | if (strcmp(XjDefaultFont, address) != 0) |
---|
62 | { |
---|
63 | fontstr = XjLoadQueryFontCache(display, address); |
---|
64 | if (fontstr != NULL) |
---|
65 | { |
---|
66 | *(XFontStruct **) |
---|
67 | ((char *)where + resource->resource_offset) = |
---|
68 | fontstr; |
---|
69 | return 0; |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | sprintf(errtext, "Unknown font: \"%s\"", address); |
---|
74 | XjWarning(errtext); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | sprintf(errtext, trying, sub1); |
---|
79 | XjWarning(errtext); |
---|
80 | fontstr = XjLoadQueryFontCache(display, sub1); |
---|
81 | |
---|
82 | if (fontstr == NULL) |
---|
83 | { |
---|
84 | char *sub2 = "fixed"; |
---|
85 | |
---|
86 | sprintf(errtext, trying, sub2); |
---|
87 | XjWarning(errtext); |
---|
88 | fontstr = XjLoadQueryFontCache(display, sub2); |
---|
89 | } |
---|
90 | |
---|
91 | if (fontstr == NULL) |
---|
92 | { |
---|
93 | XrmQuark key; |
---|
94 | fontstr = (XFontStruct *) hash_give_any_value(fonts, &key); |
---|
95 | if (fontstr != NULL) |
---|
96 | { |
---|
97 | sprintf(errtext, "substituting font: `%s'", |
---|
98 | XrmQuarkToString(key)); |
---|
99 | XjWarning(errtext); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | if (fontstr == NULL) |
---|
104 | XjFatalError("couldn't get a font"); |
---|
105 | |
---|
106 | *(XFontStruct **)((char *)where + resource->resource_offset) = |
---|
107 | fontstr; |
---|
108 | return 0; |
---|
109 | } |
---|