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);
}