Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

comp.windows.x Frequently Asked Questions (FAQ) 3/7
Section - 48) How do I get a font name from the structure?

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Business Photos and Profiles ]


Top Document: comp.windows.x Frequently Asked Questions (FAQ) 3/7
Previous Document: News Headers
Next Document: 49) How can I set backgroundPixmap in a defaults file?
See reader questions & answers on this topic! - Help others by sharing your knowledge

You can't, although you can build up the font properties to rebuild a
description of the font in XLFD format, which should be sufficient.

This routine is derived from source provided by John L. Cwikla 
(cwikla@wri.com).

#include <X11/Xlib.h>

#include <stdio.h>

/* Stolen from mit/fonts/lib/font/bitmap/bitscale.c */

enum scaleType
{
    atom, pixel_size, point_size,
    resolution, resolution_x, resolution_y, average_width,
    scaledX, scaledY, unscaled, scaledXoverY, uncomputed,
};

typedef struct _fontProp
{
    char       *name;
    Atom        atom;
    enum scaleType type;
    char found;
} fontProp;

static fontProp fontNamePropTable[] = 
{
	{ "FOUNDRY", 0, atom, 0},
	{ "FAMILY_NAME", 0, atom, 0},
	{ "WEIGHT_NAME", 0, atom, 0},
	{ "SLANT", 0, atom, 0},
	{ "SETWIDTH_NAME", 0, atom, 0},
	{ "ADD_STYLE_NAME", 0, atom, 0},
	{ "PIXEL_SIZE", 0, pixel_size, 0},
	{ "POINT_SIZE", 0, point_size, 0},
	{ "RESOLUTION_X", 0, resolution_x, 0},
	{ "RESOLUTION_Y", 0, resolution_y, 0},
	{ "SPACING", 0, atom, 0},
	{ "AVERAGE_WIDTH", 0, average_width, 0},
	{ "CHARSET_REGISTRY", 0, atom, 0},
	{ "CHARSET_ENCODING", 0, atom, 0},
#if 0
	{ "FONT", 0, atom, 0},
#endif /* 0 */
};

#define NUMITEMS(arr) ((int) (sizeof(arr) / sizeof(arr[0])))

void regenerateFontName(Display *display, XFontStruct *xfs)
{
	int i;
	unsigned long retValue;
	if (xfs)
	{
	     for(i=0;i<NUMITEMS(fontNamePropTable); i++)
		{
		        fontNamePropTable[i].atom = 
				XInternAtom(display, fontNamePropTable[i].name, 0);
			if (XGetFontProperty(xfs, fontNamePropTable[i].atom, &retValue))
			{
				switch(fontNamePropTable[i].type)
				{
					case atom:
						printf("%s", XGetAtomName(display, (Atom)retValue));
						break;

					case pixel_size:
					case point_size:
					case resolution:
					case resolution_x:
					case resolution_y:
					case average_width:
					case scaledX:
					case scaledY:
					case unscaled:
					case scaledXoverY:
					case uncomputed:
							printf("%d", retValue);
							break;
				}
			}
			else
				printf("*");

			if (i != (NUMITEMS(fontNamePropTable)-1))
				printf("-");
			else
				printf("\n");
		}
	}
}

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




Top Document: comp.windows.x Frequently Asked Questions (FAQ) 3/7
Previous Document: News Headers
Next Document: 49) How can I set backgroundPixmap in a defaults file?

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
faq%craft@uunet.uu.net (X FAQ maintenance address)





Last Update March 27 2014 @ 02:12 PM