nanogui: Thread: Cyrillic font buit-in


[<<] [<] Page 2 of 2 [>] [>>]
Subject: Re: [nanogui] Cyrillic font buit-in
From: Cristian Chiarello ####@####.####
Date: 15 May 2008 06:21:04 -0000
Message-Id: <482BD67C.1010808@fimm.com>

Follow, Greg relpy. I have forgot to CC to the ML.
Sorry, Cristian.

> Starting from pcfdemo.c, I have write builtinfont.c that use GrText
> function that also call GdText function: I'm not be able to see the
> right symbols

You're switching from win32 to nano-X API, so you're
introducing new code paths to debug.  You should write
the demo in win32.


> but I have some new questions:
> 1) UTF8 use 1 2 and sometimes 4 bytes for one symbol: I use a char array
>   for store the text file. Is this correct? (see attach for source code)

The "tmp" variable should be short not int since you're specifying
UC16, not UC32.  Taking an address of an int doesn't guarantee
working especially on big-endian archs.



> 2) with fontforge I have open the .bdf and I have see that first
> cyrillic symbol is the 1024 (unicode). I have try to show this only one
> but I get an error (see attach char_utf8.txt). Why?

Pretty strange.  You might try turning off background painting
with GrSetGCUseBackground(FALSE) before the GrText
call, we need to debug why a drawhorzline call is being made
for text, I think its for text field area clearing...  a gdb stack
trace would be a good idea, there is something wrong here.
Could have something to do with the converted builtin bdf
file.  Make sure you're running CVS code by the way, since
there were some bugs fixed in the convbdf program some
months ago.

Regards,

Greg



>
> Tnx.
> Regards, Cristian
>


----------------------------------------------------------------------------
----


> /*
>  * pcfdemo - demonstrate PCF font loading for Nano-X
>  */
> #include <stdio.h>
> #include <stdlib.h>
> #define MWINCLUDECOLORS
> #include "nano-X.h"
>
> GR_FONT_ID font = 0;
> GR_WINDOW_ID main_wid;
> GR_FONT_INFO finfo;
>
> static void
> draw_string(void)
> {
> int count = 0;
> int x = 10;
> int y = 10;
> unsigned char ch;
> int tmp = 1024;
> GR_GC_ID gc = GrNewGC();
>
> GrSetGCFont(gc, font);
>
> GrSetGCForeground(gc, GR_RGB(255, 255, 255));
> GrSetGCBackground(gc, GR_RGB(0, 0, 0));
>
> printf("First char = %d, last char = %d\n", finfo.firstchar,
>        finfo.lastchar);
> printf("Max width = %d, max height = %d\n", finfo.maxwidth,
>        finfo.height);
>
> GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16); //this cause an
assert error
>
> /*
> for (ch = 0; ch < 255; ch++) {
> if (ch < finfo.firstchar || ch > finfo.lastchar)
> GrFillRect(main_wid, gc, x, y, finfo.maxwidth, finfo.height);
> else
> GrText(main_wid, gc, x, y, &ch, 1, GR_TFTOP | GR_TFASCII);
>
> if (++count >= 16) {
> x = 0;
> y += finfo.height;
> count = 0;
> } else
> x += finfo.maxwidth + 2;
> }
> */
> GrDestroyGC(gc);
> }
>
> static void drawFile(const char * fname){
> char buf[20]; //or int... unsigned?
> int count = 0;
> int x = 0;
> int y = 10;
> unsigned char ch;
> FILE * pfile;
>
> GR_GC_ID gc = GrNewGC();
>
> GrSetGCFont(gc, font);
>
> GrSetGCForeground(gc, GR_RGB(255, 255, 255));
> GrSetGCBackground(gc, GR_RGB(0, 0, 0));
>
> pfile = fopen(fname, "r");
> if( pfile > 0 ){
> fread(buf, 1, 20, pfile);
> GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUTF8);
> }
> GrDestroyGC(gc);
> }
>
> int
> main(int argc, char **argv)
> {
> int width, height;
>
> if (GrOpen() == -1)
> return (-1);
>
> font = GrCreateFont("DejaVuLGCSans", 19, 0); //This is a builtin fonts
generated by convbdf
> if (!font)
> printf("Unable to load font\n");
>
> GrGetFontInfo(font, &finfo);
>
> width = ((finfo.maxwidth + 2) * 16);
> height =
> (((finfo.lastchar - finfo.firstchar) / 16) +
> 5) * finfo.height;
>
> main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "builtinfont",
> GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
> GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
> GrMapWindow(main_wid);
>
> while (1) {
> GR_EVENT event;
> GrGetNextEvent(&event);
>
> if (event.type == GR_EVENT_TYPE_EXPOSURE)
> draw_string();
> // drawFile("utf8.txt");
> // drawFile("unicode.txt");
>
>         if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
> GrClose();
> exit(0);
>       }
> }
> }
>


----------------------------------------------------------------------------
----


> tfb800@utfb800:~/src/x86/microwin_cvs/src/bin$ ./builtinfont
> XDefaultVisual:
>   Visual  class: TrueColor (4)
>              id: 35
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Screen RootDepth: 24
> Screen RootVisual
>   Visual  class: TrueColor (4)
>              id: 35
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Depth: 24
> Visual: 0
>   Visual  class: TrueColor (4)
>              id: 35
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 1
>   Visual  class: TrueColor (4)
>              id: 36
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 2
>   Visual  class: TrueColor (4)
>              id: 37
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 3
>   Visual  class: TrueColor (4)
>              id: 38
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 4
>   Visual  class: TrueColor (4)
>              id: 39
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 5
>   Visual  class: TrueColor (4)
>              id: 40
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 6
>   Visual  class: TrueColor (4)
>              id: 41
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 7
>   Visual  class: TrueColor (4)
>              id: 42
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 8
>   Visual  class: DirectColor (5)
>              id: 43
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 9
>   Visual  class: DirectColor (5)
>              id: 44
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 10
>   Visual  class: DirectColor (5)
>              id: 45
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 11
>   Visual  class: DirectColor (5)
>              id: 46
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 12
>   Visual  class: DirectColor (5)
>              id: 47
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 13
>   Visual  class: DirectColor (5)
>              id: 48
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 14
>   Visual  class: DirectColor (5)
>              id: 49
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Visual: 15
>   Visual  class: DirectColor (5)
>              id: 50
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Depth: 1
> Depth: 4
> Depth: 8
> Depth: 15
> Depth: 16
> Depth: 32
> Visual: 0
>   Visual  class: TrueColor (4)
>              id: 96
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> Selected Visual:
>   Visual  class: TrueColor (4)
>              id: 35
>    bits_per_rgb: 8
>     map_entries: 256
>        red_mask: 0x00ff0000
>      green_mask: 0x0000ff00
>       blue_mask: 0x000000ff
> createfont: (height == 0) found builtin font System (0)
> createfont: (height == 0) found builtin font System (0)
> fnt_createfont: DejaVuLGCSans,19 not found
> pcf_createfont: DejaVuLGCSans,19 not found
> createfont: (height != 0) using builtin font DejaVuLGCSans (4)
> First char = 32, last char = 65533
> Max width = 74, max height = 19
> builtinfont: /home/tfb800/src/x86/microwin_cvs/src/drivers/fblin32.c:68:
linear32_drawhorzline: Assertion `x2 >= x1' failed.
> Aborted (core dumped)
>



Subject: Re: [nanogui] Cyrillic font buit-in
From: Cristian Chiarello ####@####.####
Date: 15 May 2008 09:51:16 -0000
Message-Id: <482C07CC.3000307@fimm.com>

Greg Haerr:
>> 2) with fontforge I have open the .bdf and I have see that first
>> cyrillic symbol is the 1024 (unicode). I have try to show this only one
>> but I get an error (see attach char_utf8.txt). Why?
> 
> Pretty strange.  You might try turning off background painting
> with GrSetGCUseBackground(FALSE) before the GrText
> call, we need to debug why a drawhorzline call is being made
> for text, I think its for text field area clearing...  a gdb stack
> trace would be a good idea, there is something wrong here.

On a first test with GrSetGCUseBackground(gc, GR_FALSE); the application
work but not show the symbol (also with unsigned short type).

> Could have something to do with the converted builtin bdf
> file.  Make sure you're running CVS code by the way, since
> there were some bugs fixed in the convbdf program some
> months ago.
> 
cvs status convbdf.c say to me is up-to-date (rev 1.4) and the root of
repository I'm using is ####@####.####
I have made only few test on the target device with old source, the 
others I have made was on a pc, source from cvs and upon X11.
I have edited the DejaVuLGCSans.c and DejaVuLGCSans.bdf: the ascii 
representation of char 1024 is the same (also the 1025 and 1026) of the 
symbol show by fontforge: it seems to work correctly.

I have wrote a win32 application starting from mtest.c (see attach) 
where I call MwExtTextOut directly but result is the same: symbols from 
UTF8 coded file are wrong.
Both application not draw the symbol 1024 but everyone show different 
symbol reading from the same file.
Furthermore, I have see that I read 20 char from UTF8 file but only 8 
are showed.
I attach the source of both application, win32 and nanox.

Regards, Cristian






/*
 * builtinfont - demonstrate unicode builtin font loading for Nano-X
 */
#include <stdio.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"

GR_FONT_ID font = 0;
GR_WINDOW_ID main_wid;
GR_FONT_INFO finfo;

static void
drawSymbol(void)
{
	int x = 10;
	int y = 10;
	unsigned short tmp = 1024; //This should be the first symbol of cyrillic alphabet

	GR_GC_ID gc = GrNewGC();
	GrSetGCFont(gc, font);
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	//GrSetGCBackground(gc, GR_RGB(0, 0, 0)); //this crash the application
	GrSetGCUseBackground(gc, GR_FALSE);

	GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16);
	GrText(main_wid, gc, x, y+20, "ASCII", 5, GR_TFTOP | GR_TFASCII);

	GrDestroyGC(gc);
}


static void drawFileUTF8(const char * fname){
	/* see
	static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned short *unicode16)
	in microwin_cvs/src/engine/devfont.c
	for text array type
	*/
	unsigned char buf[20];
	int x = 10;
	int y = 50;
	FILE * pfile;

	GR_GC_ID gc = GrNewGC();
	GrSetGCFont(gc, font);
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCUseBackground(gc, GR_FALSE);

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		fread(buf, 1, 20, pfile);
		GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUTF8);
		fclose(pfile);
	}
	GrDestroyGC(gc);
}

static void drawFileUC16(const char * fname){
	/* see
	static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned short *unicode16)
	in microwin_cvs/src/engine/devfont.c
	for text array type
	*/
	unsigned short buf[20];
	int x = 10;
	int y = 70;
	FILE * pfile;

	GR_GC_ID gc = GrNewGC();
	GrSetGCFont(gc, font);
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCUseBackground(gc, GR_FALSE);

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		fread(buf, 1, 20, pfile);
		GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUC16);
		fclose(pfile);
	}
	GrDestroyGC(gc);
}

int
main(int argc, char **argv)
{
	int width, height;

	if (GrOpen() == -1)
		return (-1);

	font = GrCreateFont("DejaVuLGCSans", 19, 0);
	if (!font)
		printf("Unable to load font\n");

	GrGetFontInfo(font, &finfo);

	width = ((finfo.maxwidth + 2) * 16);
	height =
		(((finfo.lastchar - finfo.firstchar) / 16) +
		 5) * finfo.height;

	main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "builtinfont",
			GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
	GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(main_wid);

	while (1) {
		GR_EVENT event;
		GrGetNextEvent(&event);

		if (event.type == GR_EVENT_TYPE_EXPOSURE)
			drawSymbol();
			drawFileUTF8("utf8.txt");
			drawFileUC16("unicode.txt");

	        if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
	      }
	}
}

/* builtin test program*/
#include <windows.h>

extern BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions,
		CONST RECT *lprc, LPCVOID lpszString, UINT cbCount,
		CONST INT *lpDx, int flags);

LRESULT CALLBACK wproc(HWND,UINT,WPARAM,LPARAM);

unsigned char bufUTF8[20];
unsigned short bufUC16[20];

static void loadBufFromFileUTF8(const char * fname){
	FILE * pfile;
	int readed;

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		readed = fread(bufUTF8, 1, 20, pfile);
		printf("%d bytes readed from %s\n", readed, fname);
		fclose(pfile);
	}
}

static void loadBufFromFileUC16(const char * fname){
	FILE * pfile;
	int readed;

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		readed = fread(bufUC16, 1, 20, pfile);
		printf("%d bytes readed from %s\n", readed, fname);
		fclose(pfile);
	}
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
        static char szAppName[]="FontWin";
        HWND hwnd;
        MSG msg;
        WNDCLASS wndclass;

        wndclass.style          = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = (WNDPROC)wproc;
        wndclass.cbClsExtra     =0;
        wndclass.cbWndExtra     =0;
        wndclass.hInstance      =0;
        wndclass.hIcon          =0;
        wndclass.hCursor        =0;
        wndclass.hbrBackground  =(HBRUSH)GetStockObject(LTGRAY_BRUSH);
        wndclass.lpszMenuName   =NULL;
        wndclass.lpszClassName  = szAppName;

        RegisterClass(&wndclass);
        hwnd=CreateWindowEx(0L,
                          szAppName,
                          "mbuiltinfont",
                          WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          200,
                          200,
                          NULL,
                          NULL,
                          NULL,
                          NULL);
               
               
        ShowWindow(hwnd,iCmdShow);
        UpdateWindow(hwnd);
        
        while (GetMessage(&msg,NULL,0,0)) {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
        }      
        return msg.wParam;
}       
LRESULT CALLBACK wproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{       
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;
	short tmp = 1024;
	HGDIOBJ oldfont;
        
        switch (iMsg) {
        case WM_CREATE:
                break;
        case WM_PAINT:
        /*case WM_MOUSEFIRST:*/
                hdc=BeginPaint(hwnd,&ps);
                GetClientRect(hwnd,&rect);
	        oldfont=SelectObject(hdc,CreateFont(19,
			0,0,0,0,0,0,0,0,0,0,0,
			FF_DONTCARE|DEFAULT_PITCH,
			"DejaVuLGCSans"));
		loadBufFromFileUTF8("utf8.txt");
		loadBufFromFileUC16("unicode.txt");
		MwExtTextOut(hdc, 0, 10, 0, NULL, &tmp, 1, NULL, MWTF_UC16); //This do not show nothing
		MwExtTextOut(hdc, 0, 20, 0, NULL, "ASCII", 5, NULL, MWTF_ASCII); 
		MwExtTextOut(hdc, 0, 40, 0, NULL, bufUTF8, 19, NULL, MWTF_UTF8); //This show only 8 symbols
		MwExtTextOut(hdc, 0, 60, 0, NULL, bufUC16, 19, NULL, MWTF_UC16);
//              DrawText(hdc, "Hola, NOS ¤¾¤¿¤¤ÇÑ", -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                EndPaint(hwnd,&ps);
                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProc(hwnd,iMsg,wParam,lParam);
        }      
        return (0);
}
Subject: Re: [nanogui] Cyrillic font buit-in
From: "Greg Haerr" ####@####.####
Date: 15 May 2008 17:45:25 -0000
Message-Id: <0ed301c8b6b3$e8c1b7f0$6401a8c0@gregnewport>

> On a first test with GrSetGCUseBackground(gc, GR_FALSE); the application
> work but not show the symbol (also with unsigned short type).

Then there is second bug with the internal font display where
for some reason the clear background triggers an assert
in fblin32.c.  I can probably debug this (unrelated) bug if
you send me your .bdf file and original nano-X .c program.

> I have wrote a win32 application starting from mtest.c (see attach) 
> Both application not draw the symbol 1024 

The quickest test I can think of for the next step would be
to use convbdf -f to create a .fnt file from your .bdf file,
and then comment out the builtin font, and let nano-X/win32
load the .fnt file (using the same code in your application) from
disk, and using the tested .fnt file method for displaying unicode
fonts.  If this works, then we know that the problem is in 
the builtin font display mechanism.  If it still fails, then there
is some issue relating to the .bdf file and/or the way we're
decoding and indexing the font glyphs.



> where I call MwExtTextOut directly but result is the same: symbols from 
> UTF8 coded file are wrong.
but everyone show different 
> symbol reading from the same file.
> Furthermore, I have see that I read 20 char from UTF8 file but only 8 
> are showed.

Do the nano-X and win32 programs display different text in these
cases?  

You might put some printf() debug statements in the 
engine/devfont.c::ConvertEncoding (I think that's the function name)
which converts to and from all text encodings).

We should also take a quick look at the builtin font structure
where you specify your builtin .c font: its very important what
you use for the "encoding" member.

Regards,

Greg
Subject: Re: [nanogui] Cyrillic font buit-in
From: Cristian Chiarello ####@####.####
Date: 21 May 2008 06:40:43 -0000
Message-Id: <4833C429.1070606@fimm.com>

Greg Haerr:
>> On a first test with GrSetGCUseBackground(gc, GR_FALSE); the application
>> work but not show the symbol (also with unsigned short type).
> 
> Then there is second bug with the internal font display where
> for some reason the clear background triggers an assert
> in fblin32.c.  I can probably debug this (unrelated) bug if
> you send me your .bdf file and original nano-X .c program.

Ok. (The bdf file is too big for the ML)

> 
>> I have wrote a win32 application starting from mtest.c (see attach) 
>> Both application not draw the symbol 1024 
> 
> The quickest test I can think of for the next step would be
> to use convbdf -f to create a .fnt file from your .bdf file,
> and then comment out the builtin font, and let nano-X/win32
> load the .fnt file (using the same code in your application) from
> disk, and using the tested .fnt file method for displaying unicode
> fonts.  If this works, then we know that the problem is in 
> the builtin font display mechanism.  If it still fails, then there
> is some issue relating to the .bdf file and/or the way we're
> decoding and indexing the font glyphs.
> 
> 
> 
>> where I call MwExtTextOut directly but result is the same: symbols from 
>> UTF8 coded file are wrong.
> but everyone show different 
>> symbol reading from the same file.
>> Furthermore, I have see that I read 20 char from UTF8 file but only 8 
>> are showed.
> 
> Do the nano-X and win32 programs display different text in these
> cases?  

Yes.

> 
> You might put some printf() debug statements in the 
> engine/devfont.c::ConvertEncoding (I think that's the function name)
> which converts to and from all text encodings).
> 
> We should also take a quick look at the builtin font structure
> where you specify your builtin .c font: its very important what
> you use for the "encoding" member.

You are a big big man Greg!
Looking in drivers/genfont.c I'm using the same fontprocs of the others
font but they use the ASCII encoding.
I have added a fontprocsUC16 with MWTF_UC16 as encoding flag and the
UTF8 text in mwin application is correctly showed!!!! :D
Also 1024 symbol work well!
(see genfont.c)

The only one things that not work is the text in nanox application that
is still display different text.
Symbol 1024 and ascii is the same.
Nanox not show utf8 text, mwin yes.
Nanox show 2 more char than mwin app with unicode text.

Regards, Cristian


/*
 * pcfdemo - demonstrate PCF font loading for Nano-X
 */
#include <stdio.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"

GR_FONT_ID font = 0;
GR_WINDOW_ID main_wid;
GR_FONT_INFO finfo;

static void
draw_string(void)
{
	int count = 0;
	int x = 10;
	int y = 10;
	unsigned char ch;
	int tmp = 1024;
	GR_GC_ID gc = GrNewGC();

	GrSetGCFont(gc, font);

	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCBackground(gc, GR_RGB(0, 0, 0));

	printf("First char = %d, last char = %d\n", finfo.firstchar,
	       finfo.lastchar);
	printf("Max width = %d, max height = %d\n", finfo.maxwidth,
	       finfo.height);

	GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16); //this cause an assert error

/*
	for (ch = 0; ch < 255; ch++) {
		if (ch < finfo.firstchar || ch > finfo.lastchar)
			GrFillRect(main_wid, gc, x, y, finfo.maxwidth, finfo.height);
		else
			GrText(main_wid, gc, x, y, &ch, 1, GR_TFTOP | GR_TFASCII);

		if (++count >= 16) {
			x = 0;
			y += finfo.height;
			count = 0;
		} else
			x += finfo.maxwidth + 2;
	}
*/
	GrDestroyGC(gc);
}

static void drawFile(const char * fname){
	char buf[20]; //or int... unsigned?
	int count = 0;
	int x = 0;
	int y = 10;
	unsigned char ch;
	FILE * pfile;

	GR_GC_ID gc = GrNewGC();

	GrSetGCFont(gc, font);

	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCBackground(gc, GR_RGB(0, 0, 0));

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		fread(buf, 1, 20, pfile);
		GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUTF8);
	}
	GrDestroyGC(gc);
}

int
main(int argc, char **argv)
{
	int width, height;

	if (GrOpen() == -1)
		return (-1);

	font = GrCreateFont("DejaVuLGCSans", 19, 0); //This is a builtin fonts generated by convbdf
	if (!font)
		printf("Unable to load font\n");

	GrGetFontInfo(font, &finfo);

	width = ((finfo.maxwidth + 2) * 16);
	height =
		(((finfo.lastchar - finfo.firstchar) / 16) +
		 5) * finfo.height;

	main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "builtinfont",
			GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
	GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(main_wid);

	while (1) {
		GR_EVENT event;
		GrGetNextEvent(&event);

		if (event.type == GR_EVENT_TYPE_EXPOSURE)
			draw_string();
//			drawFile("utf8.txt");
//			drawFile("unicode.txt");

	        if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
	      }
	}
}



/*
 * pcfdemo - demonstrate PCF font loading for Nano-X
 */
#include <stdio.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"

GR_FONT_ID font = 0;
GR_WINDOW_ID main_wid;
GR_FONT_INFO finfo;

static void
draw_string(void)
{
	int count = 0;
	int x = 0;
	int y = 10;
	unsigned char ch;
	GR_GC_ID gc = GrNewGC();

	GrSetGCFont(gc, font);

	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCBackground(gc, GR_RGB(0, 0, 0));

	printf("First char = %d, last char = %d\n", finfo.firstchar,
	       finfo.lastchar);
	printf("Max width = %d, max height = %d\n", finfo.maxwidth,
	       finfo.height);

	for (ch = 0; ch < 255; ch++) {
		if (ch < finfo.firstchar || ch > finfo.lastchar)
			GrFillRect(main_wid, gc, x, y, finfo.maxwidth,
				   finfo.height);
		else
			GrText(main_wid, gc, x, y, &ch, 1,
			       GR_TFTOP | GR_TFASCII);

		if (++count >= 16) {
			x = 0;
			y += finfo.height;
			count = 0;
		} else
			x += finfo.maxwidth + 2;
	}

	GrDestroyGC(gc);
}

static void
drawSymbol(void)
{
	int x = 10;
	int y = 10;
	unsigned short tmp = 1024; //This should be the first symbol of cyrillic alphabet

	GR_GC_ID gc = GrNewGC();
	GrSetGCFont(gc, font);
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	//GrSetGCBackground(gc, GR_RGB(0, 0, 0)); //this crash the application
	GrSetGCUseBackground(gc, GR_FALSE);

	GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16);
	GrText(main_wid, gc, x, y+20, "ASCII", 5, GR_TFTOP | GR_TFASCII);

	GrDestroyGC(gc);
}

int
main(int argc, char **argv)
{
	int width, height;

	if (argc < 3){
		printf("Usage: %s <font> <size>\n", argv[0]);
		return (-1);
	}

	if (GrOpen() == -1)
		return (-1);

	font = GrCreateFont(argv[1], atoi(argv[2]), 0);
	if (!font)
		printf("Unable to load %s\n", argv[1]);

	GrGetFontInfo(font, &finfo);

	width = ((finfo.maxwidth + 2) * 16);
	height =
		(((finfo.lastchar - finfo.firstchar) / 16) +
		 5) * finfo.height;

	main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "pcfdemo",
			GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
	GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(main_wid);

	while (1) {
		GR_EVENT event;
		GrGetNextEvent(&event);

		if (event.type == GR_EVENT_TYPE_EXPOSURE)
			//draw_string();
			drawSymbol();

	        if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
	      }
	}
}


/*
 * builtinfont - demonstrate unicode builtin font loading for Nano-X
 */
#include <stdio.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"

GR_FONT_ID font = 0;
GR_WINDOW_ID main_wid;
GR_FONT_INFO finfo;

static void
drawSymbol(void)
{
	int x = 10;
	int y = 10;
	unsigned short tmp = 1024; //This should be the first symbol of cyrillic alphabet

	GR_GC_ID gc = GrNewGC();
	GrSetGCFont(gc, font);
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	//GrSetGCBackground(gc, GR_RGB(0, 0, 0)); //this crash the application
	GrSetGCUseBackground(gc, GR_FALSE);

	GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16);
	GrText(main_wid, gc, x, y+20, "ASCII", 5, GR_TFTOP | GR_TFASCII);

	GrDestroyGC(gc);
}


static void drawFileUTF8(const char * fname){
	/* see
	static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned short *unicode16)
	in microwin_cvs/src/engine/devfont.c
	for text array type
	*/
	unsigned char buf[20];
	int x = 10;
	int y = 50;
	FILE * pfile;

	GR_GC_ID gc = GrNewGC();
	GrSetGCFont(gc, font);
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCUseBackground(gc, GR_FALSE);

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		fread(buf, 1, 20, pfile);
		GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUTF8);
		fclose(pfile);
	}
	GrDestroyGC(gc);
}

static void drawFileUC16(const char * fname){
	/* see
	static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned short *unicode16)
	in microwin_cvs/src/engine/devfont.c
	for text array type
	*/
	unsigned short buf[20];
	int x = 10;
	int y = 70;
	FILE * pfile;

	GR_GC_ID gc = GrNewGC();
	GrSetGCFont(gc, font);
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCUseBackground(gc, GR_FALSE);

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		fread(buf, 1, 20, pfile);
		GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUC16);
		fclose(pfile);
	}
	GrDestroyGC(gc);
}

int
main(int argc, char **argv)
{
	int width, height;

	if (GrOpen() == -1)
		return (-1);

	font = GrCreateFont("DejaVuSans", 19, 0);
	if (!font)
		printf("Unable to load font\n");

	GrGetFontInfo(font, &finfo);

	width = ((finfo.maxwidth + 2) * 16);
	height =
		(((finfo.lastchar - finfo.firstchar) / 16) +
		 5) * finfo.height;

	main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "builtinfont",
			GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
	GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(main_wid);

	while (1) {
		GR_EVENT event;
		GrGetNextEvent(&event);

		if (event.type == GR_EVENT_TYPE_EXPOSURE)
			drawSymbol();
			drawFileUTF8("utf8.txt");
			drawFileUC16("unicode.txt");

	        if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
	      }
	}
}


/* builtin test program*/
#include <windows.h>

extern BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions,
		CONST RECT *lprc, LPCVOID lpszString, UINT cbCount,
		CONST INT *lpDx, int flags);

LRESULT CALLBACK wproc(HWND,UINT,WPARAM,LPARAM);

unsigned char bufUTF8[20];
unsigned short bufUC16[20];

static void loadBufFromFileUTF8(const char * fname){
	FILE * pfile;
	int readed;

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		readed = fread(bufUTF8, 1, 20, pfile);
		printf("%d bytes readed from %s\n", readed, fname);
		fclose(pfile);
	}
}

static void loadBufFromFileUC16(const char * fname){
	FILE * pfile;
	int readed;

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		readed = fread(bufUC16, 1, 20, pfile);
		printf("%d bytes readed from %s\n", readed, fname);
		fclose(pfile);
	}
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
        static char szAppName[]="FontWin";
        HWND hwnd;
        MSG msg;
        WNDCLASS wndclass;

        wndclass.style          = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = (WNDPROC)wproc;
        wndclass.cbClsExtra     =0;
        wndclass.cbWndExtra     =0;
        wndclass.hInstance      =0;
        wndclass.hIcon          =0;
        wndclass.hCursor        =0;
        wndclass.hbrBackground  =(HBRUSH)GetStockObject(LTGRAY_BRUSH);
        wndclass.lpszMenuName   =NULL;
        wndclass.lpszClassName  = szAppName;

        RegisterClass(&wndclass);
        hwnd=CreateWindowEx(0L,
                          szAppName,
                          "mbuiltinfont",
                          WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          200,
                          200,
                          NULL,
                          NULL,
                          NULL,
                          NULL);
               
               
        ShowWindow(hwnd,iCmdShow);
        UpdateWindow(hwnd);
        
        while (GetMessage(&msg,NULL,0,0)) {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
        }      
        return msg.wParam;
}       
LRESULT CALLBACK wproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{       
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;
	short tmp = 1024;
	HGDIOBJ oldfont;
        
        switch (iMsg) {
        case WM_CREATE:
                break;
        case WM_PAINT:
        /*case WM_MOUSEFIRST:*/
                hdc=BeginPaint(hwnd,&ps);
                GetClientRect(hwnd,&rect);
	        oldfont=SelectObject(hdc,CreateFont(19,
			0,0,0,0,0,0,0,0,0,0,0,
			FF_DONTCARE|DEFAULT_PITCH,
			"DejaVuSans"));
		loadBufFromFileUTF8("utf8.txt");
		loadBufFromFileUC16("unicode.txt");
		MwExtTextOut(hdc, 0, 10, 0, NULL, &tmp, 1, NULL, MWTF_UC16); //This do not show nothing
		MwExtTextOut(hdc, 0, 20, 0, NULL, "ASCII", 5, NULL, MWTF_ASCII); 
		MwExtTextOut(hdc, 0, 40, 0, NULL, bufUTF8, 19, NULL, MWTF_UTF8); //This show only 8 symbols
		MwExtTextOut(hdc, 0, 60, 0, NULL, bufUC16, 19, NULL, MWTF_UC16);
//              DrawText(hdc, "Hola, NOS ¤¾¤¿¤¤ÇÑ", -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                EndPaint(hwnd,&ps);
                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProc(hwnd,iMsg,wParam,lParam);
        }      
        return (0);
}


/*
 * Copyright (c) 1999, 2000, 2003, 2005 Greg Haerr ####@####.####
 *
 * Screen Driver Utilities
 * 
 * Microwindows Proportional Fonts & Routines (proportional font format)
 *
 * Modify this file to add/subtract builtin fonts from Microwindows
 *
 * This file contains the generalized low-level font/text
 * drawing routines.  Both fixed and proportional fonts are
 * supported, with fixed pitch structure allowing much smaller
 * font files.
 */
#include <stdio.h>
#include "device.h"
#include "genfont.h"

/* compiled in fonts*/
extern MWCFONT font_winFreeSansSerif11x13;	/* new MWFONT_SYSTEM_VAR (was MWFONT_GUI_VAR)*/
extern MWCFONT font_X6x13;			/* MWFONT_SYSTEM_FIXED (should be ansi)*/
extern MWCFONT font_DejaVuSans;		/**/
/*extern MWCFONT font_winFreeSystem14x16;*/	/* deprecated MWFONT_SYSTEM_VAR*/
/*extern MWCFONT font_rom8x16;*/		/* deprecated MWFONT_OEM_FIXED*/
/*extern MWCFONT font_rom8x8, font_X5x7;*/	/* unused*/

/* handling routines for MWCOREFONT*/
static MWFONTPROCS fontprocs = {
	MWTF_ASCII,		/* routines expect ascii*/
	gen_getfontinfo,
	gen_gettextsize,
	gen_gettextbits,
	gen_unloadfont,
	corefont_drawtext,
	NULL,			/* setfontsize*/
	NULL,			/* setfontrotation*/
	NULL,			/* setfontattr*/
};

/* handling routines for MWCOREFONT*/
static MWFONTPROCS fontprocsUC16 = {
	MWTF_UC16,		/* routines expect UC16*/
	gen_getfontinfo,
	gen_gettextsize,
	gen_gettextbits,
	gen_unloadfont,
	corefont_drawtext,
	NULL,			/* setfontsize*/
	NULL,			/* setfontrotation*/
	NULL,			/* setfontattr*/
};

/*
 * Starting in v0.89pl12, we've moved to just two standard fonts,
 * MWFONT_SYSTEM_VAR, and MWFONT_SYSTEM_FIXED in order to reduce
 * the core Microwindows size.  The original, slightly smaller
 * MWFONT_GUI_VAR (ansi) is used as MWFONT_SYSTEM_VAR.  The original
 * MWFONT_SYSTEM_VAR (ansi) and MWFONT_OEM_FIXED are removed.
 * However, we redirect requests for the deprecated MWFONT_GUI_VAR
 * and MWFONT_OEM_FIXED to the included system variable and fixed
 * pitch fonts, respectively, to keep older programs running as expected.
 *
 * Additional builtin fonts can be added here by extending the 
 * gen_fonts array.  An better alternative, if running on a filesystem
 * is to use the new HAVE_FNT_SUPPORT .fnt file loader, which operates
 * internally exactly the same way after the fonts are loaded.  BDF
 * fonts can be converted to either .c format for use here or .fnt 
 * format for use by the .fnt loader using the fonts/convbdf.c program.
 */

/* first font is default font*/
MWCOREFONT gen_fonts[NUMBER_FONTS] = {
	{&fontprocs, 0, 0, 0, MWFONT_SYSTEM_VAR,   &font_winFreeSansSerif11x13},
	{&fontprocs, 0, 0, 0, MWFONT_SYSTEM_FIXED, &font_X6x13},
	/* deprecated redirections for the time being*/
	{&fontprocs, 0, 0, 0, "Helvetica",         &font_winFreeSansSerif11x13}, /* redirect*/
	{&fontprocs, 0, 0, 0, "Terminal",          &font_X6x13},	/* redirect*/
	{&fontprocsUC16, 0, 0, 0, "DejaVuSans",     &font_DejaVuSans}
};

/*GB: pointer to an user builtin font table. */
MWCOREFONT *user_builtin_fonts = NULL;

/*  Sets the fontproc to fontprocs.  */
void
gen_setfontproc(MWCOREFONT *pf)
{
	pf->fontprocs = &fontprocs;
}

/*
 * Generalized low level get font info routine.  This
 * routine works with fixed and proportional fonts.
 */
MWBOOL
gen_getfontinfo(PMWFONT pfont, PMWFONTINFO pfontinfo)
{
	PMWCFONT	pf = ((PMWCOREFONT)pfont)->cfont;
	int		i;

	pfontinfo->maxwidth = pf->maxwidth;
	pfontinfo->height = pf->height;
	pfontinfo->baseline = pf->ascent;
	pfontinfo->firstchar = pf->firstchar;
	pfontinfo->lastchar = pf->firstchar + pf->size - 1;
	pfontinfo->fixed = pf->width == NULL? TRUE: FALSE;
	for(i=0; i<256; ++i) {
		if(pf->width == NULL)
			pfontinfo->widths[i] = pf->maxwidth;
		else {
			if(i<pf->firstchar || i >= pf->firstchar+pf->size)
				pfontinfo->widths[i] = 0;
			else pfontinfo->widths[i] = pf->width[i-pf->firstchar];
		}
	}
	return TRUE;
}

/*
 * Generalized low level routine to calc bounding box for text output.
 * Handles both fixed and proportional fonts.  Passed ascii string.
 */
void
gen_gettextsize(PMWFONT pfont, const void *text, int cc, MWTEXTFLAGS flags,
	MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
	PMWCFONT		pf = ((PMWCOREFONT)pfont)->cfont;
	const unsigned char *	str = text;
	unsigned int		c;
	int			width;

	if(pf->width == NULL)
		width = cc * pf->maxwidth;
	else {
		width = 0;
		while(--cc >= 0) {
			c = *str++;
			if(c >= pf->firstchar && c < pf->firstchar+pf->size)
				width += pf->width[c - pf->firstchar];
		}
	}
	*pwidth = width;
	*pheight = pf->height;
	*pbase = pf->ascent;
}

#if HAVE_FNT_SUPPORT | HAVE_PCF_SUPPORT
/*
 * Routine to calc bounding box for text output.
 * Handles both fixed and proportional fonts.  Passed MWTF_UC16 string.
 */
void
gen16_gettextsize(PMWFONT pfont, const void *text, int cc, MWTEXTFLAGS flags,
	MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
	PMWCFONT		pf = ((PMWCOREFONT) pfont)->cfont;
	const unsigned short *	str = text;
	unsigned		int c;
	int			width;

	if (pf->width == NULL)
		width = cc * pf->maxwidth;
	else {
		width = 0;
		while (--cc >= 0) {
			c = *str++;
			if (c >= pf->firstchar && c < pf->firstchar + pf->size)
				width += pf->width[c - pf->firstchar];
		}
	}
	*pwidth = width;
	*pheight = pf->height;
	*pbase = pf->ascent;
}
#endif /* HAVE_FNT_SUPPORT | HAVE_PCF_SUPPORT*/

/*
 * Generalized low level routine to get the bitmap associated
 * with a character.  Handles fixed and proportional fonts.
 */
void
gen_gettextbits(PMWFONT pfont, int ch, const MWIMAGEBITS **retmap,
	MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
	PMWCFONT		pf = ((PMWCOREFONT)pfont)->cfont;
	int 			count, width;
	const MWIMAGEBITS *	bits;

	/* if char not in font, map to first character by default*/
	if(ch < pf->firstchar || ch >= pf->firstchar+pf->size)
		ch = pf->firstchar;

	ch -= pf->firstchar;

	/* get font bitmap depending on fixed pitch or not*/
	/* GB: automatically detect if offset is 16 or 32 bit */
	if( pf->offset ) {
		if( ((unsigned long*)pf->offset)[0] >= 0x00010000 )
			bits = pf->bits + ((unsigned short*)pf->offset)[ch];
		else
			bits = pf->bits + ((unsigned long*)pf->offset)[ch];
	} else
		bits = pf->bits + (pf->height * ch);
		
 	width = pf->width ? pf->width[ch] : pf->maxwidth;
	count = MWIMAGE_WORDS(width) * pf->height; 

	*retmap = bits;

	/* return width depending on fixed pitch or not*/
	*pwidth = width; 
	*pheight = pf->height;
	*pbase = pf->ascent; 
}

void
gen_unloadfont(PMWFONT pfont)
{
	/* builtins can't be unloaded*/
}

#if NOTUSED
/* 
 * Generalized low level text draw routine, called only
 * if no clipping is required
 */
void
gen_drawtext(PMWFONT pfont,PSD psd,MWCOORD x,MWCOORD y,const void *text,
	int n,MWPIXELVAL fg)
{
	PMWCFONT		pf = ((PMWCOREFONT)pfont)->cfont;
	const unsigned char *	str = text;
	MWCOORD 		width;		/* width of character */
	MWCOORD 		height;		/* height of character */
	const MWIMAGEBITS *	bitmap;

	/* x, y is bottom left corner*/
	y -= pf->height - 1;
	while (n-- > 0) {
		pfont->GetTextBits(pfont, *s++, &bitmap, &width, &height);
		gen_drawbitmap(psd, x, y, width, height, bitmap, fg);
		x += width;
	}
}

/*
 * Generalized low level bitmap output routine, called
 * only if no clipping is required.  Only the set bits
 * in the bitmap are drawn, in the foreground color.
 */
void
gen_drawbitmap(PSD psd,MWCOORD x, MWCOORD y, MWCOORD width, MWCOORD height,
	MWIMAGEBITS *table, PIXELVAL fgcolor)
{
  MWCOORD minx;
  MWCOORD maxx;
  MWIMAGEBITS bitvalue;	/* bitmap word value */
  int bitcount;		/* number of bits left in bitmap word */

  minx = x;
  maxx = x + width - 1;
  bitcount = 0;
  while (height > 0) {
	if (bitcount <= 0) {
		bitcount = MWIMAGE_BITSPERIMAGE;
		bitvalue = *table++;
	}
	if (MWIMAGE_TESTBIT(bitvalue))
		psd->DrawPixel(psd, x, y, fgcolor);
	bitvalue = MWIMAGE_SHIFTBIT(bitvalue);
	--bitcount;
	if (x++ == maxx) {
		x = minx;
		++y;
		--height;
		bitcount = 0;
	}
  }
}
#endif /* NOTUSED*/

Subject: Re: [nanogui] Cyrillic font buit-in
From: Cristian Chiarello ####@####.####
Date: 21 May 2008 09:58:13 -0000
Message-Id: <4833F275.6000301@fimm.com>

> We should also take a quick look at the builtin font structure
> where you specify your builtin .c font: its very important what
> you use for the "encoding" member.

There is another strange effect: with fontprocs->encoding field set to 
MWTF_UC16 the text is showed correctly but all the win32 widgets seem to 
use the "System" builtin font ad all bounds is ignored by the text.

Regards, Cristian.
Subject: Re: [nanogui] Cyrillic font buit-in
From: "Greg Haerr" ####@####.####
Date: 21 May 2008 19:39:34 -0000
Message-Id: <151801c8bb7a$60a32d10$0300a8c0@RDP>

: There is another strange effect: with fontprocs->encoding field set to 
: MWTF_UC16 the text is showed correctly but all the win32 widgets seem to 
: use the "System" builtin font ad all bounds is ignored by the text.

All the win32 widgets are coded to use only the System font, unless
you send them a message (or change the initialization code) to
use your own font.  The encoding field doesn't have anything
to do with this.

What do you mean by the bounds problem?  Does this occur 
normally without your font being builtin? (or the field set as above?)

Regards,

Greg
Subject: Re: [nanogui] Cyrillic font buit-in
From: "Greg Haerr" ####@####.####
Date: 21 May 2008 19:41:19 -0000
Message-Id: <154301c8bb7a$9d348c10$0300a8c0@RDP>

: Nanox not show utf8 text, mwin yes.
: Nanox show 2 more char than mwin app with unicode text.

Which is correct then, nano-X or win32?  I assume
you're passing exactly the same string with exactly the
same encoding flags.

Regards,

Greg
Subject: Re: [nanogui] Cyrillic font buit-in
From: Cristian Chiarello ####@####.####
Date: 22 May 2008 13:04:16 -0000
Message-Id: <48356F8E.2040705@fimm.com>

Greg Haerr ha scritto:
> : There is another strange effect: with fontprocs->encoding field set to 
> : MWTF_UC16 the text is showed correctly but all the win32 widgets seem to 
> : use the "System" builtin font ad all bounds is ignored by the text.
> 
> All the win32 widgets are coded to use only the System font, unless
> you send them a message (or change the initialization code) to
> use your own font.  The encoding field doesn't have anything
> to do with this.
> 
> What do you mean by the bounds problem?

I mean that the text was drawn upon the window.
Window with editbox seem to use the system font while text use the 
builtin font so I get a little window with big text over it.

   Does this occur
> normally without your font being builtin? (or the field set as above?)

If I unset the fontprocs->encoding (leave it to ASCII) all works ok: the 
text is inside of the editbox and window but only the latin symbols are 
showed. If I set it to UC16 I get the effect as mentioned above.


Now I make my test direct on the target that use a c++ wrapper class 
(developed by G. Brugnoni): inside it the SetWindowText is used.
So I have modified the win32 demo by adding an editbox but this one not 
show the utf8 text. I attach my example.

Regards, Cristian.


/* builtin test program*/
#include <windows.h>
#define DEBUG	1
#include <device.h>
#include <debug.h>
#include "../../drivers/genfont.h"
extern MWCFONT font_DejaVuSans;			/* unicode font */

#define BYTES_TO_READ 15

/*
For structure references, wdmlib\source\microwindows\src\include\device.h MWCOREFONT and PMWCFONT
*/
static MWCOREFONT userBuiltinFonts[] = {
	{NULL, 0, 0, 0, "DejaVu Sans", &font_DejaVuSans},	/* unicode font */
	{NULL, 0, 0, 0, NULL,   NULL}	/* terminator */
};

/*
This array is used in microwindows/src/mwin/winfont.c
*/
void initUserBuiltinFonts ()
{
	extern MWCOREFONT *user_builtin_fonts;
	
	DPRINTF("initBuiltinFonts: Set encoding for %s\n", userBuiltinFonts[0].name );
	gen_setfontproc(&userBuiltinFonts[0]);
	userBuiltinFonts[0].fontprocs->encoding = MWTF_UC16;	
	user_builtin_fonts = userBuiltinFonts;
}


extern BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions,
		CONST RECT *lprc, LPCVOID lpszString, UINT cbCount,
		CONST INT *lpDx, int flags);


unsigned char bufANSI[BYTES_TO_READ];
unsigned char bufUTF8[BYTES_TO_READ];
unsigned short bufUC16[BYTES_TO_READ];

static void loadBufFromFileANSI(const char * fname){
	FILE * pfile;
	int readed;

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		readed = fread(bufANSI, 1, BYTES_TO_READ, pfile);
		printf("%d bytes readed from %s\n", readed, fname);
		fclose(pfile);
	}
}

static void loadBufFromFileUTF8(const char * fname){
	FILE * pfile;
	int readed;

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		readed = fread(bufUTF8, 1, BYTES_TO_READ, pfile);
		printf("%d bytes readed from %s\n", readed, fname);
		fclose(pfile);
	}
}

static void loadBufFromFileUC16(const char * fname){
	FILE * pfile;
	int readed;

	pfile = fopen(fname, "r");
	if( pfile > 0 ){
		readed = fread(bufUC16, 1, BYTES_TO_READ, pfile);
		printf("%d bytes readed from %s\n", readed, fname);
		fclose(pfile);
	}
}

LRESULT CALLBACK wproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{       
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;
		short tmp = 1024;
		HGDIOBJ oldfont;
        
        switch (iMsg) {
		case WM_CREATE:
		{
			HFONT hfDefault;
			HWND hEdit;

			hEdit=CreateWindowEx(0L, "EDIT",
				"OK",WS_BORDER|WS_CHILD | WS_VISIBLE,
				0,0,320,140,hwnd, (HMENU)5, NULL, NULL);
			
			/*
			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
				WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
				0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
			if(hEdit == NULL)
				MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
			hfDefault = GetStockObject(DEFAULT_GUI_FONT);
			SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
			*/
			hfDefault = CreateFont(20,
			0,0,0,0,0,0,0,0,0,0,0,
			FF_DONTCARE|DEFAULT_PITCH,
			"DejaVu Sans");
			SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
			loadBufFromFileUTF8("utf8.txt");
			SetDlgItemText(hwnd, 5, (const char *)bufUTF8);
			//SetWindowText(hEdit,(const char *)bufUTF8);
			//loadBufFromFileANSI("ansi.txt");
			//SetDlgItemText(hwnd, 5, (const char *)bufANSI);
			//SetWindowText(hEdit,(const char *)bufANSI);
		}
            break;
        case WM_PAINT:
		{
			hdc=BeginPaint(hwnd,&ps);
			GetClientRect(hwnd,&rect);
			oldfont=SelectObject(hdc,CreateFont(20,
			0,0,0,0,0,0,0,0,0,0,0,
			FF_DONTCARE|DEFAULT_PITCH,
			"DejaVu Sans"));
			//loadBufFromFileUTF8("utf8.txt");
			//loadBufFromFileUC16("unicode.txt");
			//MwExtTextOut(hdc, 0, 10, 0, NULL, &tmp, 1, NULL, MWTF_UC16); //This do not show nothing
			//MwExtTextOut(hdc, 0, 20, 0, NULL, "ASCII", 5, NULL, MWTF_ASCII); 
			//MwExtTextOut(hdc, 0, 40, 0, NULL, bufUTF8, 19, NULL, MWTF_UTF8); //This show only 8 symbols
			//MwExtTextOut(hdc, 0, 60, 0, NULL, bufUC16, 19, NULL, MWTF_UC16);
			//DrawText(hdc, "Hola, NOS ¤¾¤¿¤¤ÇÑ", -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
			
			MwExtTextOut(hdc, 0, 200, 0, NULL, bufUTF8, BYTES_TO_READ-1, NULL, MWTF_UTF8);
			
			EndPaint(hwnd,&ps);
			
		}
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd,iMsg,wParam,lParam);
        }      
        return (0);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
        static char szAppName[]="FontWin";
        HWND hwnd;
        MSG msg;
        WNDCLASS wndclass;
		
		initUserBuiltinFonts();
		
		MwRegisterEditControl(NULL);

        wndclass.style          = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = (WNDPROC)wproc;
        wndclass.cbClsExtra     =0;
        wndclass.cbWndExtra     =0;
        wndclass.hInstance      =0;
        wndclass.hIcon          =0;
        wndclass.hCursor        =0;
        wndclass.hbrBackground  =(HBRUSH)GetStockObject(LTGRAY_BRUSH);
        wndclass.lpszMenuName   =NULL;
        wndclass.lpszClassName  = szAppName;

        RegisterClass(&wndclass);
        hwnd=CreateWindowEx(0L,szAppName,"mbuiltinfont",WS_OVERLAPPEDWINDOW | WS_VISIBLE,
		0,0,320,240,NULL,NULL,NULL,NULL);
		
        ShowWindow(hwnd,iCmdShow);
        UpdateWindow(hwnd);
        
        while (GetMessage(&msg,NULL,0,0)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
        }      
        return msg.wParam;
}
Subject: Re: [nanogui] Cyrillic font buit-in
From: Cristian Chiarello ####@####.####
Date: 22 May 2008 13:07:29 -0000
Message-Id: <48357037.8020408@fimm.com>

Greg Haerr:
> : Nanox not show utf8 text, mwin yes.
> : Nanox show 2 more char than mwin app with unicode text.
> 
> Which is correct then, nano-X or win32? 

The win32 app.

  I assume
> you're passing exactly the same string with exactly the
> same encoding flags.

Yes, string and font are the same.

Regards, Cristian
Subject: Re: [nanogui] Cyrillic font buit-in
From: Cristian Chiarello ####@####.####
Date: 3 Jun 2008 08:34:30 -0000
Message-Id: <4845025C.2080204@fimm.com>

Greg Haerr:
> : Nanox not show utf8 text, mwin yes.
> : Nanox show 2 more char than mwin app with unicode text.
> 
> Which is correct then, nano-X or win32?  I assume
> you're passing exactly the same string with exactly the
> same encoding flags.
> 
With this settings, the unicode builtin font seems to work correctly 
also with cyrillic symbols:

extern MWCFONT font_DejaVuSans;			/* unicode font */
...

static MWCOREFONT userBuiltinFonts[] = {
	{NULL, 0, 0, 0, "DejaVu Sans", &font_DejaVuSans},	/* unicode font */
	{NULL, 0, 0, 0, NULL,   NULL}	/* terminator */
};

...

void initUserBuiltinFonts ()
{
	extern MWCOREFONT *user_builtin_fonts;
	
	DPRINTF("initBuiltinFonts: Set encoding for %s\n", 
userBuiltinFonts[0].name );
	gen_setfontproc(&userBuiltinFonts[0]);
	userBuiltinFonts[0].fontprocs->encoding = MWTF_UC16;	
	userBuiltinFonts[0].fontprocs->GetTextSize = gen16_gettextsize;	
	user_builtin_fonts = userBuiltinFonts;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
...
initUserBuiltinFonts();
...
}

Thanks. Regards Cristian C.
[<<] [<] Page 2 of 2 [>] [>>]


Powered by ezmlm-browse 0.20.