Beispiel #1
0
static wxFont* RwxLoadFont (wxDesc *gtkd, int face, int size)
{
    wxString fontname;
    wxFont *tmp_font;
    int pixelsize;

    if (face < 1 || face > 5)
	face = 1;

    if (size < SMALLEST) size = SMALLEST;

    /* Here's a 1st class fudge: make sure that the Adobe design sizes
       8, 10, 11, 12, 14, 17, 18, 20, 24, 25, 34 can be obtained via
       an integer "size" at 100 dpi, namely 6, 7, 8, 9, 10, 12, 13,
       14, 17, 18, 24 points. It's almost y = x * 100/72, but not
       quite. The constants were found using lm(). --pd */
    if (IS_100DPI) size = (int) R_rint (size * 1.43 - 0.4);

    /* 'size' is the requested size, 'pixelsize' the size of the
       actually allocated font*/
    pixelsize = size;

    tmp_font = new wxFont(pixelsize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);

#if 0
    if(face == 5)
        fontname = wxString::Format(symbolname, pixelsize);
    else
	fontname = wxString::Format(fontname_R6,
				    weight[(face-1)%2],
				    slant[((face-1)/2)%2],
				    pixelsize);

    tmp_font = gdk_font_load(fontname);

    if (!tmp_font) {
	static int near[]=
	{14,14,14,17,17,18,20,20,20,20,24,24,24,25,25,25,25};
	/* 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  */
	
	/* If ADOBE_SIZE(pixelsize) is true at this point then
	   the user's system does not have the standard ADOBE font set
	   so we just have to use a "fixed" font.
	   If we can't find a "fixed" font then something is seriously
	   wrong */
	if (ADOBE_SIZE (pixelsize)) {
	    tmp_font = gdk_font_load ("fixed");
	    if (!tmp_font)
		error("Could not find any X11 fonts\nCheck that the Font Path is correct.");
	}
	
	if (pixelsize < 8)
	    pixelsize = 8;
	else if (pixelsize == 9)
	    pixelsize = 8;
	else if (pixelsize >= 13 && pixelsize < 30) 
	    pixelsize = near[size-13];
	else
	    pixelsize = 34;
	
	g_free(fontname);
	if(face == 5)
	    fontname = g_strdup_printf(symbolname, pixelsize);
	else
	    fontname = g_strdup_printf(fontname_R6,
				       weight[(face-1)%2],
				       slant[((face-1)/2)%2],
				       pixelsize);	    
	tmp_font = gdk_font_load (fontname);
    }
    
    if(tmp_font) {
#ifdef HASH_FONTS
        font_htab[fontname] = tmp_font;
#endif
	if (fabs( (pixelsize - size)/(double)size ) > 0.2)
	    warning("wxWidgets used font size %d when %d was requested",
		    pixelsize, size);
    }
#endif 

    return tmp_font;
}
Beispiel #2
0
static GdkFont* RGTKLoadFont (gint face, gint size)
{
    gchar *fontname;
    GdkFont *tmp_font;
    gint pixelsize;

    if (face < 1 || face > 5)
	face = 1;

    if (size < SMALLEST) size = SMALLEST;

    /* Here's a 1st class fudge: make sure that the Adobe design sizes
       8, 10, 11, 12, 14, 17, 18, 20, 24, 25, 34 can be obtained via
       an integer "size" at 100 dpi, namely 6, 7, 8, 9, 10, 12, 13,
       14, 17, 18, 24 points. It's almost y = x * 100/72, but not
       quite. The constants were found using lm(). --pd */
    if (IS_100DPI) size = R_rint (size * 1.43 - 0.4);

    /* 'size' is the requested size, 'pixelsize' the size of the
       actually allocated font*/
    pixelsize = size;

    if(face == 5)
	fontname = g_strdup_printf(symbolname, pixelsize);
    else
	fontname = g_strdup_printf(fontname_R6,
				   weight[(face-1)%2],
				   slant[((face-1)/2)%2],
				   pixelsize);
#ifdef DEBUG_GTK
    Rprintf("loading:\n%s\n", fontname);
#endif
    tmp_font = gdk_font_load(fontname);
#ifdef DEBUG_GTK
    if (tmp_font) Rprintf("success\n"); else Rprintf("failure\n");
#endif

    if (!tmp_font) {
	static int near[]=
	{14,14,14,17,17,18,20,20,20,20,24,24,24,25,25,25,25};
	/* 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  */
	
	/* If ADOBE_SIZE(pixelsize) is true at this point then
	   the user's system does not have the standard ADOBE font set
	   so we just have to use a "fixed" font.
	   If we can't find a "fixed" font then something is seriously
	   wrong */
	if (ADOBE_SIZE (pixelsize)) {
	    tmp_font = gdk_font_load ("fixed");
	    if (!tmp_font)
		error("Could not find any X11 fonts\nCheck that the Font Path is correct.");
	}
	
	if (pixelsize < 8)
	    pixelsize = 8;
	else if (pixelsize == 9)
	    pixelsize = 8;
	else if (pixelsize >= 13 && pixelsize < 30) 
	    pixelsize = near[size-13];
	else
	    pixelsize = 34;
	
	g_free(fontname);
	if(face == 5)
	    fontname = g_strdup_printf(symbolname, pixelsize);
	else
	    fontname = g_strdup_printf(fontname_R6,
				       weight[(face-1)%2],
				       slant[((face-1)/2)%2],
				       pixelsize);	    
#ifdef DEBUG_GTK
	Rprintf("loading:\n%s\n", fontname);
#endif
	tmp_font = gdk_font_load (fontname);
#ifdef DEBUG_GTK
	if (tmp_font) Rprintf("success\n"); else Rprintf("failure\n");
#endif
    }
    
    if(tmp_font) {
	g_hash_table_insert(font_htab, (gpointer) g_strdup(fontname),
			    (gpointer) tmp_font);
	if (fabs( (pixelsize - size)/(double)size ) > 0.2)
	    warning("GTK used font size %d when %d was requested",
		    pixelsize, size);
    }

    g_free(fontname);
    return tmp_font;
}