| Title: | DECWINDOWS 26-JAN-89 to 29-NOV-90 |
| Notice: | See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit |
| Moderator: | STAR::VATNE |
| Created: | Mon Oct 30 1989 |
| Last Modified: | Mon Dec 31 1990 |
| Last Successful Update: | Fri Jun 06 1997 |
| Number of topics: | 3726 |
| Total number of notes: | 19516 |
I'd like to be able to get the active font id from the
root window of my application. The strategies I have
tried include:
1) Copying the root window's GC with XtGetGC, then
XCopyGC this to my writeable GC with mask set to
"GCFont". This, however, results in BadFont X errors.
2) Copying the DefaultGCOfScreen to my writeable GC.
The desired font id apparently is not found, since the
desired font has been replaced with "fixed".
"fixed" is not terribly visible on my application,
though it does beat dumping core.
3) Using XGContextFromGC to get a GContext ID, then passing this
off to XQueryText, which returns an XFontStruct, which
contains a Font field, fid. Problem is, this fid is not
a Font ID, but rather, the GContext ID I passed off to
XGContextID earlier.
Any suggestions...?
| T.R | Title | User | Personal Name | Date | Lines |
|---|---|---|---|---|---|
| 2429.1 | Use XQueryFont(GC) | TOOLEY::B_WACKER | Tue Mar 13 1990 10:00 | 1 | |
XQueryFont also takes a GC instead of the font_id. | |||||
| 2429.2 | TRNSAM::HOLT | Robert Holt, ISV Atelier West | Wed Mar 14 1990 23:28 | 12 | |
I don't think so.. QueryFont gives me a fat nada when I use GC,
This may require accessing the FONT property for the application
root window, then a LoadQuery using the newly-obtained value
for the FONT name.
I'll work on this tomorrow and post a solution.
So many Xlib calls to get font charateristics, yet none will simply
tell me the name of the current font.... why is that?
| |||||
| 2429.3 | the rest of the answer | TOOLEY::B_WACKER | Thu Mar 15 1990 10:09 | 4 | |
> I don't think so.. QueryFont gives me a fat nada when I use GC,
I forgot to mention you have to use XGCContextFromGC to get the right
kind of id! See the 5.3 bookreader doc on query font.
| |||||
| 2429.4 | DECWIN::FISHER | Prune Juice: A Warrior's Drink! | Thu Mar 15 1990 14:56 | 10 | |
Ha...that's right. Since XLIB does not know whether you are giving it a font or a GC, it does not know whether to take the number directly (for a font) or use it as a pointer to its local GC structure to get the GCID which the server really wants. I'm glad that DEC is not the only place that the right and left hands don't communicate. (Well, actually, XLib was designed at DEC and the server protocol was designed at MIT, so it was only half DEC). Burns | |||||
| 2429.5 | TRNSAM::HOLT | Robert Holt, ISV Atelier West | Thu Mar 15 1990 15:47 | 14 | |
Thanks, Burns..
It just seems reasonable that after going to the trouble to
get a GContextID, that QueryFont would give me
a useful fid instead of the selfsame GContextID I already
know about.
I think that the best alternative will turn out to use XGetWindowProperty
and extract the value of the FONT_NAME property of a window with the
desired font.
| |||||
| 2429.6 | General purpose routine for getting fontname... | TRNSAM::HOLT | Robert Holt. ISV Atelier West. | Wed Mar 28 1990 13:53 | 73 |
#include <X11/DECwDwtWidgetProg.h>
#include <stdio.h>
/*-------------------------------------------------------------+
| get_font_name - Search default resource files for a font |
| for this application name/class. |
| |
| First, the user's .Xdefaults is searched |
| for "app-name.Font" or "app-name.font" |
| |
| If no font is found, the default resource |
| file "/usr/lib/X11/app-defaults/"app-name" |
| is searched. |
| |
| If this is unsuccessful, the font "fixed" |
| is returned. |
| |
| DEC ISVG/West - rah 3/90 |
+-------------------------------------------------------------*/
char *get_font_name(app_name)
char *app_name;
{
char str_ret[40],
*font_name,
class_str[40],
name_str[40],
app_def_str[40],
home_dir_str[40],
*get_home_dir();
XrmDatabase database;
XrmValue value_ret;
static char default_font_name[]="fixed";
strcpy(home_dir_str,get_home_dir());
strcat(home_dir_str,"/.Xdefaults");
strcpy(class_str,app_name);
strcat(class_str,".Font");
strcpy(name_str,app_name);
strcat(name_str,".font");
strcpy(app_def_str,"/usr/lib/X11/app-defaults");
strcat(app_def_str,"/");
strcat(app_def_str,app_name);
/* checking .Xdefaults */
if ((database = XrmGetFileDatabase(home_dir_str)) != NULL) {
strcpy(name_str,".font");
strcpy(class_str,".Font");
XrmGetResource(database,name_str,class_str,str_ret,&value_ret);
}
/* see if there is a name here */
if (value_ret.size)
font_name = value_ret.addr;
/* else check apps-default */
else if ((database = XrmGetFileDatabase(app_def_str)) != NULL) {
XrmGetResource(database,name_str,class_str,str_ret,&value_ret);
}
/* see if there is a name here */
if (value_ret.size)
font_name = value_ret.addr;
else {
/* no name found, so punt with "fixed" */
font_name = default_font_name;
}
return(font_name);
}
| |||||
| 2429.7 | FYI; XtDatabase | LEOVAX::TREGGIARI | Mon Apr 02 1990 19:39 | 5 | |
If it is a toolkit application, you don't need to "build" the Xrm
databases. You can get the one the toolkit has already merged from
the various sources by calling XtDatabase (I think it's called...).
Leo
| |||||