nanogui: truetype with fltk


Previous by date: 29 Sep 2004 10:24:12 +0100 Re: Applications for nano-X, tian tao
Next by date: 29 Sep 2004 10:24:12 +0100 How to use nxcal??, zeng_pengcheng
Previous in thread: 29 Sep 2004 10:24:12 +0100 truetype with fltk, Hinko Kocevar
Next in thread: 29 Sep 2004 10:24:12 +0100 Re: truetype with fltk, Hinko Kocevar

Subject: Re: [nanogui] truetype with fltk
From: Steven Scholz ####@####.####
Date: 29 Sep 2004 10:24:12 +0100
Message-Id: <415A7F34.3060306@imc-berlin.de>

Hinko Kocevar wrote:

> Hi,
> 
> I've managed to build freetype-2.1.3 lib and I can see truetype fonts - 
> tested with fontdemo. I have this simple app using fltk that just lists 
> all found fonts and then displayed hello string using selected font.
> PCF fonts are working but with treutype fonts nano-X and nxlib are 
> seraching for the wrong name of the font. Eg. I want to use bitstream 
> vera sans at size 14;  this is printk() output around XLoadFont:
> 
> before _nxFindX11Font: -bitsteam-Bitstream Vera 
> Sans-medium-r-normal--14-0-0-0-p-0-iso8859-1
> after _nxFindX11Font: (null)
> XLoadFont('-bitsteam-Bitstream Vera 
> Sans-medium-r-normal--14-0-0-0-p-0-iso8859-1') = '(null)' [0]
> 
> In fonts dir only '-bitsteam-Bitstream Vera 
> Sans-medium-r-normal--0-0-0-0-p-0-iso8859-1' exists, since this font is 
> variable height it does not contain size in it name.
> 
> How can this be overcome?

By hacking the the above mentioned functions to look for e.g. 
Sans-medium-r-normal--0-0-0-0-p-0-iso8859-1 if 
Sans-medium-r-normal--14-0-0-0-p-0-iso8859-1 can not be found.

The attached patch is UGLY and only intended to show the idea!

Good luck,

--
Steven

diff -wru nxlib-0.45.prestine/LoadFont.c nxlib-0.45/LoadFont.c
--- nxlib-0.45.prestine/LoadFont.c	2003-08-11 22:04:45.000000000 +0200
+++ nxlib-0.45/LoadFont.c	2004-09-07 11:25:37.000000000 +0200
@@ -2,6 +2,41 @@
 #include <stdlib.h>
 #include <string.h>

+#include <ctype.h>
+// return dash number N, or pointer to ending null if none:
+const char* fl_font_word(const char* p, int n)
+{
+	while (*p) {
+		if (*p=='-') {
+			if (!--n)
+				break;
+		}
+		p++;
+	}
+	return p;
+}
+
+// return a pointer to a number we think is "point size":
+char* fl_find_fontsize(char* name)
+{
+	char* c = name;
+	// for standard x font names, try after 7th dash:
+	if (*c == '-') {
+		c = (char*)fl_font_word(c,7);
+		if (*c++ && isdigit(*c))
+			return c;
+		return 0; // malformed x font name?
+	}
+	char* r = 0;
+	// find last set of digits:
+	for (c++;* c; c++)
+		if (isdigit(*c) && !isdigit(*(c-1)))
+			r = c;
+	return r;
+}
+
+
+
 static int
 prefix(const char *prestr, char *allstr)
 {
@@ -107,7 +142,10 @@
 XLoadFont(Display * dpy, _Xconst char *name)
 {
 	GR_FONT_ID font = 0;
-	char *fontname;
+	char *fontname=NULL;
+	int size=0;
+
+//	printf("%s(%d) fontname=%s, name=%s\n", __FUNCTION__, __LINE__, fontname, name);

 	/* first check for wildcards*/
 	if (any('*', name) || any('?', name)) {
@@ -121,18 +159,46 @@
 	} else
 		fontname = (char *)name;

+//	printf("%s(%d) fontname=%s, name=%s\n", __FUNCTION__, __LINE__, fontname, name);
+
 	/* first try to find from X11/fonts.dir file*/
 	fontname = _nxFindX11Font(fontname);

+//	printf("%s(%d) fontname=%s, name=%s\n", __FUNCTION__, __LINE__, fontname, name);
+
 	/* if not found, try 6x13 for "fixed"*/
 	if (!fontname && !strcmp(name, "fixed"))
 		fontname = _nxFindX11Font("6x13");

+//	printf("%s(%d) fontname=%s, name=%s\n", __FUNCTION__, __LINE__, fontname, name);
+
+	if (!fontname) {
+		char namebuffer[1024];	// holds scalable font name
+		char* c = fl_find_fontsize(name);
+		if (c) {
+			int thissize = c ? atoi(c) : 1;
+			int thislength = strlen(name);
+			int l = c - name;
+			memcpy(namebuffer, name, l);
+			l += sprintf(namebuffer+l,"%d", 0);
+			while (*c != '-')
+				c++;
+			strcpy(namebuffer+l, c);
+			printf("Found font size=%d\n", thissize);
+			printf("New name: %s...\n", namebuffer);
+			fontname = _nxFindX11Font(namebuffer);
+			size = thissize;
+		}
+	}
+
+//	printf("%s(%d) fontname=%s, name=%s\n", __FUNCTION__, __LINE__, fontname, name);
+
 	/* found font, load into server*/
 	if (fontname)
-		font = GrCreateFont(fontname, 0, NULL);
+		font = GrCreateFont(fontname, size, NULL);

-printf("XLoadFont('%s') = '%s' [%d]\n", name, fontname, font);
+//	printf("%s(%d) fontname=%s, name=%s\n", __FUNCTION__, __LINE__, fontname, name);
+//printf("XLoadFont('%s') = '%s' [%d]\n", name, fontname, font);
 	if (fontname)
 		Xfree(fontname);
 	return font;

Previous by date: 29 Sep 2004 10:24:12 +0100 Re: Applications for nano-X, tian tao
Next by date: 29 Sep 2004 10:24:12 +0100 How to use nxcal??, zeng_pengcheng
Previous in thread: 29 Sep 2004 10:24:12 +0100 truetype with fltk, Hinko Kocevar
Next in thread: 29 Sep 2004 10:24:12 +0100 Re: truetype with fltk, Hinko Kocevar


Powered by ezmlm-browse 0.20.