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