[comp.windows.x] How do you set widget fonts with XtSetArg?

roy@neptune.iex.com (Roy Cantu) (06/29/90)

First of all, I would like to apologize for the butchered version
of my previous posting asking for help with the ascii Text Widget.
As of now, the question still remains as to how one may go about
saving the contents of the ascii Text widget.  Any suggestions?

However, the most recent problem involves fonts.  I have yet to
uncover a method of setting widget fonts using XtSetArg.  For 
example, the Athena Label widget possesses the attribute XtNfont 
which I would like to set as such:

	i = 0;
	XtSetArg(args[i], XtNfont, ?????); i++;
	XtSetValues(label_widget, args, i);

But what belongs in the ???????   
I have tried many things, including:

	-adobe-helvetica-hold-o-normal--24-240-75-75-p-138-iso8859-1

	"-adobe-helvetica-hold-o-normal--24-240-75-75-p-138-iso8859-1"

	9x15

	/usr/include/X11....somefontfilename


Apparently, I am way in left field.  Still, I would like to have
a font in my X Window program other than the default.

PLEASE tell me what to put in the ??????  !!!!



Thank you,

roy

rlh2@ukc.ac.uk (R.L.Hesketh) (06/29/90)

In article <roy.646598613@neptune> roy@neptune.iex.com (Roy Cantu) writes:
>However, the most recent problem involves fonts.  I have yet to
>uncover a method of setting widget fonts using XtSetArg.  For 
>example, the Athena Label widget possesses the attribute XtNfont 
>which I would like to set as such:
>
>	i = 0;
>	XtSetArg(args[i], XtNfont, ?????); i++;
>	XtSetValues(label_widget, args, i);
>
>But what belongs in the ???????   

a pointer to an XFontStruct (documented as just "XFontStruct" not
"XFontStruct *" in the Xaw manual).

This can be found in R3 using the following ..

	XFontStruct *afont;

	afont = XLoadQueryFont(XtDisplay(label_widget),
		"-adobe-helvetica-hold-o-normal--24-240-75-75-p-138-iso8859-1");
	if (afont != NULL) {
		i = 0;
		XtSetArg(args[i], XtNfont, afont); i++;
		XtSetValues(label_widget, args, i);
	}

or even better in R4 ...

	String font_name =
	     "-adobe-helvetica-hold-o-normal--24-240-75-75-p-138-iso8859-1";

	XtVaSetValues(label_widget, XtVaTypedArg, XtNfont, XtRString,
			font_name, strlen(font_name), NULL);

using the R4 varargs interface in Xt which calls the StringToFontStruct
converter.

>Thank you,

thats ok

>roy

Richard Hesketh   :   @nsfnet-relay.ac.uk:rlh2@ukc.ac.uk
		  :   rlh2@ukc.ac.uk    ..!mcsun!ukc!rlh2
---                                               
Computing Lab., University of Kent at Canterbury,
Canterbury, Kent, CT2 7NF, United Kingdom.    Tel: +44 227 764000 ext 3682/7620

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (06/29/90)

> First of all, I would like to apologize for the butchered version
> of my previous posting asking for help with the ascii Text Widget.
> As of now, the question still remains as to how one may go about
> saving the contents of the ascii Text widget.  Any suggestions?

If you are using R4, then RTFM.  Athena widget's section 5.6.2.1.
XawAsciiSaveAsFile() is probabally exactly what you want.  Unfortunatly your
message is sufficiently vague that I cannot be sure which verion of X you 
are using, or wher you are trying to save the contents.

>	i = 0;
>	XtSetArg(args[i], XtNfont, ?????); i++;
>	XtSetValues(label_widget, args, i);

> But what belongs in the ???????.

What belongs here is a valid X Font Structure.  The thing returned from
XQueryLoadFont() (Or is is XLoadQueryFont, I can never remember).  

A MUCH better solution is to put the font specification in the applications
app-default file, this is not only simplier, but more portable.  Remember that
fonts are inherently non-portable, since I may not have the same fonts on my X
Terminal that you have on your workstation, or whatever.

In an app-default file you can just add the line:

*label_widget_name:	<Font Name>

The Font name is either something like 6x10, or 9x15 or an XLFD name such as:

-adobe-helvetica-bold-o-normal--24-240-75-75-p-138-iso8859-1

or

-*-helvetica-bold-o-normal--*-240-*-*-*-*-iso8859-1


The latter is better since it is resolution independent, but in either case if
the user doesn't have this font on his system he can just override it with one
that he does have, it may not look as nice, but at least the application will
work.  If you hard-code the font value in with XtSetValues, and I don't have
that font then your application is instantly useless.

						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213