AeUtils.c++ 1.45 KB
#include <time.h>
#include "AeUtils.h"


//
// This routine converts a font name into a font
// list.  Intended to be used when reading in
// font resources.  Needs the current display to
// load in the associated font structure.
//
// If an error occurs, returns NULL.
//
XmFontList
FontName2FontList (Display *display, const char * fontName)
{
    XFontStruct *	fontStructP;
    XmFontListEntry 	fontListEntry;
    XmFontList		fontList;

    // Load in the font and get a pointer to its info struct.
    if ((fontStructP = XLoadQueryFont (display, fontName)) == NULL)
	goto Fail;

    // Create a font list entry from the font struct.
    if ((fontListEntry = XmFontListEntryCreate
	 (XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, fontStructP)) == NULL)
	goto Fail;

    // NULL indicates to create a new font list.
    fontList = XmFontListAppendEntry (NULL, fontListEntry); 

    return fontList;

Fail:
    return NULL;
}


XmFontList
FontStruct2FontList (XFontStruct * fontStructP)
{
    XmFontListEntry 	fontListEntry;
    XmFontList		fontList = NULL;

    // Create a font list entry from the font struct.
    if (fontListEntry = XmFontListEntryCreate (XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, fontStructP))
    {
	// NULL indicates to create a new font list.
	fontList = XmFontListAppendEntry (NULL, fontListEntry); 
    }
    
    return fontList;
}

    

long
GetClockMSecs (void)
{
    #define CLOCKS_PER_MSEC	(CLOCKS_PER_SEC / 1000)

    return clock() / CLOCKS_PER_MSEC;
}