From 7901c0b505604f90c91f6d0c0f8c4e7f9df58ab8 Mon Sep 17 00:00:00 2001 From: Hidenori Takeshima Date: Sun, 20 Aug 2000 20:08:35 +0000 Subject: [PATCH] Handle the codepage of fonts if supported by the graphics driver. --- graphics/x11drv/xfont.c | 4 +++ include/gdi.h | 1 + objects/dc.c | 1 + objects/font.c | 34 ++++++++++++++---------- objects/text.c | 57 ++++++++++++++++++++++++----------------- 5 files changed, 59 insertions(+), 38 deletions(-) diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c index 4a384e4b64d..4decaee360f 100644 --- a/graphics/x11drv/xfont.c +++ b/graphics/x11drv/xfont.c @@ -2995,6 +2995,10 @@ HFONT X11DRV_FONT_SelectObject( DC* dc, HFONT hfont, FONTOBJ* font ) hPrevFont = dc->w.hFont; dc->w.hFont = hfont; + dc->w.codepage = CP_ACP; + /* NOTE: the codepage of UNICODE is treated as CP_ACP(=0) */ + if ( CHECK_PFONT(physDev->font) ) + dc->w.codepage = __PFONT(physDev->font)->fi->codepage; LeaveCriticalSection( &crtsc_fonts_X11 ); diff --git a/include/gdi.h b/include/gdi.h index 91b5fd186ab..736c8533bc3 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -134,6 +134,7 @@ typedef struct XFORM xformWorld2Vport; /* World-to-viewport transformation */ XFORM xformVport2World; /* Inverse of the above transformation */ BOOL vport2WorldValid; /* Is xformVport2World valid? */ + WORD codepage; /* codepage of the selected font */ } WIN_DC_INFO; diff --git a/objects/dc.c b/objects/dc.c index 7ed1bf50fcb..b7c761d22ac 100644 --- a/objects/dc.c +++ b/objects/dc.c @@ -73,6 +73,7 @@ static void DC_Init_DC_INFO( WIN_DC_INFO *win_dc_info ) win_dc_info->xformWorld2Vport = win_dc_info->xformWorld2Wnd; win_dc_info->xformVport2World = win_dc_info->xformWorld2Wnd; win_dc_info->vport2WorldValid = TRUE; + win_dc_info->codepage = CP_ACP; PATH_InitGdiPath(&win_dc_info->path); } diff --git a/objects/font.c b/objects/font.c index 66423fed616..f1f930adb94 100644 --- a/objects/font.c +++ b/objects/font.c @@ -889,22 +889,28 @@ BOOL16 WINAPI GetTextExtentPoint16( HDC16 hdc, LPCSTR str, INT16 count, BOOL WINAPI GetTextExtentPoint32A( HDC hdc, LPCSTR str, INT count, LPSIZE size ) { - LPWSTR p; - BOOL ret; - UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */ - UINT wlen; + BOOL ret = FALSE; + DC * dc = DC_GetDCPtr( hdc ); - /* str may not be 0 terminated so we can't use HEAP_strdupWtoA. - * We allocate one more than we need so that lstrcpynWtoA can write a - * trailing 0 if it wants. - */ + if (!dc) return FALSE; - wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0); - p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) ); - wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen); - - ret = GetTextExtentPoint32W( hdc, p, wlen, size ); - HeapFree( GetProcessHeap(), 0, p ); + if (dc->funcs->pGetTextExtentPoint) + { + /* str may not be 0 terminated so we can't use HEAP_strdupWtoA. + * So we use MultiByteToWideChar. + */ + UINT wlen = MultiByteToWideChar(dc->w.codepage,0,str,count,NULL,0); + LPWSTR p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) ); + if (p) + { + wlen = MultiByteToWideChar(dc->w.codepage,0,str,count,p,wlen); + ret = dc->funcs->pGetTextExtentPoint( dc, p, wlen, size ); + HeapFree( GetProcessHeap(), 0, p ); + } + } + GDI_ReleaseObj( hdc ); + TRACE("(%08x %s %d %p): returning %d,%d\n", + hdc, debugstr_an (str, count), count, size, size->cx, size->cy ); return ret; } diff --git a/objects/text.c b/objects/text.c index 99b9e23301e..e43af0d46fa 100644 --- a/objects/text.c +++ b/objects/text.c @@ -52,35 +52,44 @@ BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags, const RECT *lprect, LPCSTR str, UINT count, const INT *lpDx ) { + DC * dc = DC_GetDCUpdate( hdc ); LPWSTR p; - INT ret; - UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */ - UINT wlen; + BOOL ret = FALSE; LPINT lpDxW = NULL; - wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0); - if(lpDx){ - int i, j; - i = 0; j = 0; + if (!dc) return FALSE; - lpDxW = (LPINT)HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(INT)); - while(i < count){ - if(IsDBCSLeadByteEx(codepage, str[i])){ - lpDxW[j++] = lpDx[i] + lpDx[i+1]; - i = i + 2; - } - else{ - lpDxW[j++] = lpDx[i]; - i = i + 1; - } - } - lpDx = lpDxW; + if (dc->funcs->pExtTextOut) + { + UINT wlen = MultiByteToWideChar(dc->w.codepage,0,str,count,NULL,0); + if (lpDx) + { + int i = 0, j = 0; + + lpDxW = (LPINT)HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(INT)); + while(i < count) + { + if(IsDBCSLeadByteEx(dc->w.codepage, str[i])) + { + lpDxW[j++] = lpDx[i] + lpDx[i+1]; + i = i + 2; + } + else + { + lpDxW[j++] = lpDx[i]; + i = i + 1; + } + } + } + if ((p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) ))) + { + wlen = MultiByteToWideChar(dc->w.codepage,0,str,count,p,wlen); + ret = dc->funcs->pExtTextOut( dc, x, y, flags, lprect, p, wlen, lpDxW ); + HeapFree( GetProcessHeap(), 0, p ); + } + if (lpDxW) HeapFree( GetProcessHeap(), 0, lpDxW ); } - p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) ); - wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen); - ret = ExtTextOutW( hdc, x, y, flags, lprect, p, wlen, lpDxW ); - if (lpDxW) HeapFree( GetProcessHeap(), 0, lpDxW ); - HeapFree( GetProcessHeap(), 0, p ); + GDI_ReleaseObj( hdc ); return ret; }