Re: gdk_fontset_load and font descriptor



On Sat, Jan 12, 2002 at 06:05:39PM +0100, marillat christian wanadoo fr wrote:
> 
> >> "VH" == Vlad Harchev <hvv hippo ru> writes:
> 
> [...]
> 
> >  Also it would be wornderfull if gdk_fontset_load wrote to the stderr the name
> > of the font it failed to load - then it would be trivial to find out whether
> > translator is guilty or app loading exotic (and non-existant) font name.
> >  Also it it would be nice if gdk_fontset_load felt back to "*-r-*" font if it
> > can't load the user-supplied fontset..
> 
> Interesting. Who want to add that ? Owen ?
> 

Something like the attach function will try to create a fontset name
given a full xlfd. It will fill in the size use the original xlfd:
 from: -isas-song ti-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0
 to: -isas-song ti-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0,-*-*-medium-r-*-*-16-*-*-*-*-*-*-*

 It still won't solve that a symbolic font might be loaded or fonts like
'fixed' is used, but at least the proper size could be preserved in some
cases.

Or better yet, figure out other informations from the current
locale's /etc/gtk/gtkrc.* files. But since gtk2.0 will replace gtk1.2
soon (really, when?), the better solution is too much trouble. :)

-- 
Best regard
hashao
#include <glib.h>

/* Append ,-*-*-size-*-* to a full xlfd. Thus try to
 * create a better default fontset name. */
gchar* create_fontset_xlfd(gchar* ifontname)
{
    gchar* p;
    gchar **tokens;
    gchar *ofontname;
    GString *tempout;   /* Temperary output font. */
    GString *temp2nd;   /* Temperary 2nd half of output fontset. */
    gint count = 0;

    /* We need all 14 fields in the first font. */
    for( p = ifontname; *p != '\0'&& *p != ',';  p++) {
	if(*p == '-') {
	    count++;
	}
    }

    /* if not a full xlfd name, do nothing. */
    if( count != 14){
	ofontname = g_strdup(ifontname);
	return ofontname;
    }

    tokens = g_strsplit(ifontname, "-", 15); /* first field empty. */
    temp2nd = g_string_new(",-*-*-");
    g_string_append(temp2nd, tokens[3]);   /* medium/bold */
    g_string_append(temp2nd, "-r-*-*-");
    g_string_append(temp2nd, tokens[7]);   /* size, default 12. */
    g_string_append(temp2nd, "-*-*-*-*-*-*-*");
    g_strfreev(tokens);

    tempout = g_string_new(ifontname);
    g_string_append(tempout, temp2nd->str);
    ofontname = tempout->str;
    g_string_free(temp2nd, TRUE);
    g_string_free(tempout, FALSE);
    return ofontname;
}

#if 0
int main(void)
{
    gchar* fontname;
    gchar* fontset_name;
    
    fontname = g_strdup("-isas-song ti-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0,-*-r-*");
    fontset_name = create_fontset_xlfd(fontname);
    puts(fontname);
    puts(fontset_name);
    free(fontname);
    free(fontset_name);
}
#endif /* 0 */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]