diff --git a/graphics/x11drv/Makefile.in b/graphics/x11drv/Makefile.in index f7b8953b5c1..5edf5faecb7 100644 --- a/graphics/x11drv/Makefile.in +++ b/graphics/x11drv/Makefile.in @@ -10,6 +10,7 @@ C_SRCS = \ bitmap.c \ brush.c \ clipping.c \ + codepage.c \ dib.c \ graphics.c \ init.c \ diff --git a/graphics/x11drv/codepage.c b/graphics/x11drv/codepage.c new file mode 100644 index 00000000000..a13b931a1cd --- /dev/null +++ b/graphics/x11drv/codepage.c @@ -0,0 +1,262 @@ +/* + * X11 codepage handling + * + * Copyright 2000 Hidenori Takeshima + */ + +#include "config.h" + +#include "ts_xlib.h" + +#include "windef.h" +#include "winnls.h" +#include "heap.h" +#include "x11font.h" +#include "debugtools.h" + +DEFAULT_DEBUG_CHANNEL(text); + + +static XChar2b* X11DRV_unicode_to_char2b_sbcs( fontObject* pfo, + LPCWSTR lpwstr, UINT count ) +{ + XChar2b *str2b; + UINT i; + BYTE *str; + UINT codepage = pfo->fi->codepage; + char ch = pfo->fs->default_char; + + if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) ))) + return NULL; + if (!(str = HeapAlloc( GetProcessHeap(), 0, count ))) + { + HeapFree( GetProcessHeap(), 0, str2b ); + return NULL; + } + + WideCharToMultiByte( codepage, 0, lpwstr, count, str, count, &ch, NULL ); + + for (i = 0; i < count; i++) + { + str2b[i].byte1 = 0; + str2b[i].byte2 = str[i]; + } + HeapFree( GetProcessHeap(), 0, str ); + + return str2b; +} + +static XChar2b* X11DRV_unicode_to_char2b_unicode( fontObject* pfo, + LPCWSTR lpwstr, UINT count ) +{ + XChar2b *str2b; + UINT i; + + if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) ))) + return NULL; + + for (i = 0; i < count; i++) + { + str2b[i].byte1 = lpwstr[i] >> 8; + str2b[i].byte2 = lpwstr[i] & 0xff; + } + + return str2b; +} + +/* FIXME: handle jisx0212.1990... */ +static XChar2b* X11DRV_unicode_to_char2b_cp932( fontObject* pfo, + LPCWSTR lpwstr, UINT count ) +{ + XChar2b *str2b; + XChar2b *str2b_dst; + BYTE *str; + UINT i; + UINT codepage = pfo->fi->codepage; + char ch = pfo->fs->default_char; + + if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) ))) + return NULL; + if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 ))) + { + HeapFree( GetProcessHeap(), 0, str2b ); + return NULL; + } + WideCharToMultiByte( codepage, 0, lpwstr, count, str, count*2, &ch, NULL ); + + str2b_dst = str2b; + for (i = 0; i < count; i++, str2b_dst++) + { + if ( ( str[i] >= (BYTE)0x80 && str[i] <= (BYTE)0x9f ) || + ( str[i] >= (BYTE)0xe0 && str[i] <= (BYTE)0xfc ) ) + { + unsigned int high, low; + + high = (unsigned int)str[i]; + low = (unsigned int)str[i+1]; + + if ( high <= 0x9f ) + high = (high<<1) - 0xe0; + else + high = (high<<1) - 0x160; + if ( low < 0x9f ) + { + high --; + if ( low < 0x7f ) + low -= 0x1f; + else + low -= 0x20; + } + else + { + low -= 0x7e; + } + + str2b_dst->byte1 = (unsigned char)high; + str2b_dst->byte2 = (unsigned char)low; + i++; + } + else + { + str2b_dst->byte1 = 0; + str2b_dst->byte2 = str[i]; + } + } + + HeapFree( GetProcessHeap(), 0, str ); + + return str2b; +} + + +static XChar2b* X11DRV_unicode_to_char2b_cp936( fontObject* pfo, + LPCWSTR lpwstr, UINT count ) +{ + FIXME( "please implement X11DRV_unicode_to_char2b_cp936!\n" ); + return NULL; +} + + +static XChar2b* X11DRV_unicode_to_char2b_cp949( fontObject* pfo, + LPCWSTR lpwstr, UINT count ) +{ + XChar2b *str2b; + XChar2b *str2b_dst; + BYTE *str; + UINT i; + UINT codepage = pfo->fi->codepage; + char ch = pfo->fs->default_char; + + if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) ))) + return NULL; + if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 ))) + { + HeapFree( GetProcessHeap(), 0, str2b ); + return NULL; + } + WideCharToMultiByte( codepage, 0, lpwstr, count, str, count*2, &ch, NULL ); + + str2b_dst = str2b; + for (i = 0; i < count; i++, str2b_dst++) + { + if ( str[i] & (BYTE)0x80 ) + { + str2b_dst->byte1 = str[i]; + str2b_dst->byte2 = str[i+1]; + i++; + } + else + { + str2b_dst->byte1 = 0; + str2b_dst->byte2 = str[i]; + } + } + + HeapFree( GetProcessHeap(), 0, str ); + + return str2b; +} + + +static XChar2b* X11DRV_unicode_to_char2b_cp950( fontObject* pfo, + LPCWSTR lpwstr, UINT count ) +{ + FIXME( "please implement X11DRV_unicode_to_char2b_cp950!\n" ); + return NULL; +} + + +static void X11DRV_DrawString_normal( fontObject* pfo, Display* pdisp, + Drawable d, GC gc, int x, int y, + XChar2b* pstr, int count ) +{ + TSXDrawString16( pdisp, d, gc, x, y, pstr, count ); +} + +static int X11DRV_TextWidth_normal( fontObject* pfo, XChar2b* pstr, int count ) +{ + return TSXTextWidth16( pfo->fs, pstr, count ); +} + +static void X11DRV_DrawText_normal( fontObject* pfo, Display* pdisp, Drawable d, + GC gc, int x, int y, XTextItem16* pitems, + int count ) +{ + TSXDrawText16( pdisp, d, gc, x, y, pitems, count ); +} + +static void X11DRV_TextExtents_normal( fontObject* pfo, XChar2b* pstr, int count, + int* pdir, int* pascent, int* pdescent, + int* pwidth ) +{ + XCharStruct info; + + TSXTextExtents16( pfo->fs, pstr, count, pdir, pascent, pdescent, &info ); + *pwidth = info.width; +} + +const X11DRV_CP X11DRV_cptable[X11DRV_CPTABLE_COUNT] = +{ + { /* SBCS */ + X11DRV_unicode_to_char2b_sbcs, + X11DRV_DrawString_normal, + X11DRV_TextWidth_normal, + X11DRV_DrawText_normal, + X11DRV_TextExtents_normal, + }, + { /* UNICODE */ + X11DRV_unicode_to_char2b_unicode, + X11DRV_DrawString_normal, + X11DRV_TextWidth_normal, + X11DRV_DrawText_normal, + X11DRV_TextExtents_normal, + }, + { /* CP932 */ + X11DRV_unicode_to_char2b_cp932, + X11DRV_DrawString_normal, /* FIXME */ + X11DRV_TextWidth_normal, /* FIXME */ + X11DRV_DrawText_normal, /* FIXME */ + X11DRV_TextExtents_normal, /* FIXME */ + }, + { /* CP936 */ + X11DRV_unicode_to_char2b_cp936, + X11DRV_DrawString_normal, /* FIXME */ + X11DRV_TextWidth_normal, /* FIXME */ + X11DRV_DrawText_normal, /* FIXME */ + X11DRV_TextExtents_normal, /* FIXME */ + }, + { /* CP949 */ + X11DRV_unicode_to_char2b_cp949, + X11DRV_DrawString_normal, /* FIXME */ + X11DRV_TextWidth_normal, /* FIXME */ + X11DRV_DrawText_normal, /* FIXME */ + X11DRV_TextExtents_normal, /* FIXME */ + }, + { /* CP950 */ + X11DRV_unicode_to_char2b_cp950, + X11DRV_DrawString_normal, /* FIXME */ + X11DRV_TextWidth_normal, /* FIXME */ + X11DRV_DrawText_normal, /* FIXME */ + X11DRV_TextExtents_normal, /* FIXME */ + }, +}; diff --git a/graphics/x11drv/text.c b/graphics/x11drv/text.c index f45488a554e..7a90fd28c8a 100644 --- a/graphics/x11drv/text.c +++ b/graphics/x11drv/text.c @@ -27,74 +27,6 @@ DEFAULT_DEBUG_CHANNEL(text); #define IROUND(x) (int)((x)>0? (x)+0.5 : (x) - 0.5) -/*********************************************************************** - * unicode_to_char2b - * - * dup a Unicode string into a XChar2b array; must be HeapFree'd by the caller - */ -static XChar2b *unicode_to_char2b( LPCWSTR wstr, UINT count, UINT codepage, UINT def_char ) -{ - XChar2b *str2b; - UINT i; - - if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) ))) - return NULL; - - if (codepage != 0) /* multibyte font */ - { - BYTE *str; - char ch = def_char; - CPINFO cpinfo; - - /* allocate the worst case count * 2 bytes */ - if (!(str = HeapAlloc( GetProcessHeap(), 0, count * 2 ))) - { - HeapFree( GetProcessHeap(), 0, str2b ); - return NULL; - } - - /* we have to convert from unicode to codepage first */ - WideCharToMultiByte( codepage, 0, wstr, count, str, count, &ch, NULL ); - - GetCPInfo( codepage, &cpinfo ); - - if (cpinfo.MaxCharSize == 1) - { - for (i = 0; i < count; i++) - { - str2b[i].byte1 = 0; - str2b[i].byte2 = str[i]; - } - } - else - { - XChar2b *str2b_dst = str2b; - for (i = 0; i < count; i++, str2b_dst++) - { - str2b_dst->byte2 = str[i]; - if (IsDBCSLeadByteEx( codepage, str[i] )) - { - str2b_dst->byte1 = str[i + 1]; - i++; - } - else - str2b_dst->byte1 = 0; - } - } - HeapFree( GetProcessHeap(), 0, str ); - } - else /* codepage 0 -> unicode font */ - { - for (i = 0; i < count; i++) - { - str2b[i].byte1 = wstr[i] >> 8; - str2b[i].byte2 = wstr[i] & 0xff; - } - } - return str2b; -} - - /*********************************************************************** * X11DRV_ExtTextOut */ @@ -294,7 +226,7 @@ X11DRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags, } /* Draw the text (count > 0 verified) */ - if (!(str2b = unicode_to_char2b( wstr, count, pfo->fi->codepage, pfo->fs->default_char ))) + if (!(str2b = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, wstr, count ))) goto FAIL; TSXSetForeground( display, physDev->gc, physDev->textPixel ); @@ -302,8 +234,9 @@ X11DRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags, { if (!dc->w.charExtra && !dc->w.breakExtra && !lpDx) { - TSXDrawString16( display, physDev->drawable, physDev->gc, - dc->w.DCOrgX + x, dc->w.DCOrgY + y, str2b, count ); + X11DRV_cptable[pfo->fi->cptable].pDrawString( + pfo, display, physDev->drawable, physDev->gc, + dc->w.DCOrgX + x, dc->w.DCOrgY + y, str2b, count ); } else /* Now the fun begins... */ { @@ -336,7 +269,8 @@ X11DRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags, do { delta += (lpDx[i] * dc->vportExtX + extra) / dc->wndExtX - - TSXTextWidth16( font, str2b + i, 1); + - X11DRV_cptable[pfo->fi->cptable].pTextWidth( + pfo, str2b + i, 1); pitem->nchars++; } while ((++i < count) && !delta); pitem++; @@ -363,8 +297,9 @@ X11DRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags, } } - TSXDrawText16( display, physDev->drawable, physDev->gc, - dc->w.DCOrgX + x, dc->w.DCOrgY + y, items, pitem - items ); + X11DRV_cptable[pfo->fi->cptable].pDrawText( pfo, display, + physDev->drawable, physDev->gc, + dc->w.DCOrgX + x, dc->w.DCOrgY + y, items, pitem - items ); HeapFree( GetProcessHeap(), 0, items ); } } @@ -383,8 +318,9 @@ X11DRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags, int y_i = IROUND((double) (dc->w.DCOrgY + y) - offset * pfo->lpX11Trans->b / pfo->lpX11Trans->pixelsize ); - TSXDrawString16( display, physDev->drawable, physDev->gc, - x_i, y_i, &str2b[i], 1); + X11DRV_cptable[pfo->fi->cptable].pDrawString( + pfo, display, physDev->drawable, physDev->gc, + x_i, y_i, &str2b[i], 1); if (lpDx) offset += XLSTODS(dc, lpDx[i]); else @@ -460,11 +396,12 @@ BOOL X11DRV_GetTextExtentPoint( DC *dc, LPCWSTR str, INT count, if( pfo ) { if( !pfo->lpX11Trans ) { int dir, ascent, descent; - XCharStruct info; - XChar2b *p = unicode_to_char2b( str, count, pfo->fi->codepage, pfo->fs->default_char ); + int info_width; + XChar2b *p = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, str, count ); if (!p) return FALSE; - TSXTextExtents16( pfo->fs, p, count, &dir, &ascent, &descent, &info ); - size->cx = abs((info.width + dc->w.breakRem + count * + X11DRV_cptable[pfo->fi->cptable].pTextExtents( pfo, p, + count, &dir, &ascent, &descent, &info_width ); + size->cx = abs((info_width + dc->w.breakRem + count * dc->w.charExtra) * dc->wndExtX / dc->vportExtX); size->cy = abs((pfo->fs->ascent + pfo->fs->descent) * dc->wndExtY / dc->vportExtY); diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c index 8fa590909fc..7f659fcb20a 100644 --- a/graphics/x11drv/xfont.c +++ b/graphics/x11drv/xfont.c @@ -102,117 +102,118 @@ static const char* INIDefaultSansSerif = "DefaultSansSerif"; typedef struct __sufch { - LPSTR psuffix; - BYTE charset; - UINT16 codepage; + LPCSTR psuffix; + BYTE charset; + WORD codepage; + WORD cptable; } SuffixCharset; -static SuffixCharset sufch_ansi[] = { - { "0", ANSI_CHARSET, 1252 }, - { NULL, ANSI_CHARSET, 1252 }}; +static const SuffixCharset sufch_ansi[] = { + { "0", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, + { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_iso646[] = { - { "irv", ANSI_CHARSET, 1252 }, - { NULL, ANSI_CHARSET, 1252 }}; +static const SuffixCharset sufch_iso646[] = { + { "irv", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, + { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_iso8859[] = { - { "1", ANSI_CHARSET, 28591 }, - { "2", EE_CHARSET, 28592 }, - { "3", ISO3_CHARSET, 28593 }, - { "4", ISO4_CHARSET, 28594 }, - { "5", RUSSIAN_CHARSET, 28595 }, - { "6", ARABIC_CHARSET, 28596 }, - { "7", GREEK_CHARSET, 28597 }, - { "8", HEBREW_CHARSET, 28598 }, - { "9", TURKISH_CHARSET, 28599 }, - { "10", BALTIC_CHARSET, 1257 }, /* FIXME */ - { "11", THAI_CHARSET, 874 }, /* FIXME */ - { "12", SYMBOL_CHARSET, CP_SYMBOL }, - { "13", SYMBOL_CHARSET, CP_SYMBOL }, - { "14", SYMBOL_CHARSET, CP_SYMBOL }, - { "15", ANSI_CHARSET, 1252 }, - { NULL, ANSI_CHARSET, 1252 }}; +static const SuffixCharset sufch_iso8859[] = { + { "1", ANSI_CHARSET, 28591, X11DRV_CPTABLE_SBCS }, + { "2", EE_CHARSET, 28592, X11DRV_CPTABLE_SBCS }, + { "3", ISO3_CHARSET, 28593, X11DRV_CPTABLE_SBCS }, + { "4", ISO4_CHARSET, 28594, X11DRV_CPTABLE_SBCS }, + { "5", RUSSIAN_CHARSET, 28595, X11DRV_CPTABLE_SBCS }, + { "6", ARABIC_CHARSET, 28596, X11DRV_CPTABLE_SBCS }, + { "7", GREEK_CHARSET, 28597, X11DRV_CPTABLE_SBCS }, + { "8", HEBREW_CHARSET, 28598, X11DRV_CPTABLE_SBCS }, + { "9", TURKISH_CHARSET, 28599, X11DRV_CPTABLE_SBCS }, + { "10", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS }, /* FIXME */ + { "11", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */ + { "12", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS }, + { "13", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS }, + { "14", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS }, + { "15", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, + { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_microsoft[] = { - { "cp1250", EE_CHARSET, 1250 }, - { "cp1251", RUSSIAN_CHARSET, 1251 }, - { "cp1252", ANSI_CHARSET, 1252 }, - { "cp1253", GREEK_CHARSET, 1253 }, - { "cp1254", TURKISH_CHARSET, 1254 }, - { "cp1255", HEBREW_CHARSET, 1255 }, - { "cp1256", ARABIC_CHARSET, 1256 }, - { "cp1257", BALTIC_CHARSET, 1257 }, - { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL }, - { "symbol", SYMBOL_CHARSET, CP_SYMBOL }, - { NULL, ANSI_CHARSET, 1252 }}; +static const SuffixCharset sufch_microsoft[] = { + { "cp1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS }, + { "cp1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS }, + { "cp1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, + { "cp1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS }, + { "cp1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS }, + { "cp1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS }, + { "cp1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS }, + { "cp1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS }, + { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS }, + { "symbol", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS }, + { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_tcvn[] = { - { "0", TCVN_CHARSET, 1252 }, /* FIXME */ - { NULL, TCVN_CHARSET, 1252 }}; +static const SuffixCharset sufch_tcvn[] = { + { "0", TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */ + { NULL, TCVN_CHARSET, 1252, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_tis620[] = { - { "0", THAI_CHARSET, 874 }, /* FIXME */ - { NULL, THAI_CHARSET, 874 }}; +static const SuffixCharset sufch_tis620[] = { + { "0", THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }, /* FIXME */ + { NULL, THAI_CHARSET, 874, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_viscii[] = { - { "1", VISCII_CHARSET, 1252 }, /* FIXME */ - { NULL, VISCII_CHARSET, 1252 }}; +static const SuffixCharset sufch_viscii[] = { + { "1", VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, /* FIXME */ + { NULL, VISCII_CHARSET, 1252, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_windows[] = { - { "1250", EE_CHARSET, 1250 }, - { "1251", RUSSIAN_CHARSET, 1251 }, - { "1252", ANSI_CHARSET, 1252 }, - { "1253", GREEK_CHARSET, 1253 }, - { "1254", TURKISH_CHARSET, 1254 }, - { "1255", HEBREW_CHARSET, 1255 }, - { "1256", ARABIC_CHARSET, 1256 }, - { "1257", BALTIC_CHARSET, 1257 }, - { NULL, ANSI_CHARSET, 1252 }}; +static const SuffixCharset sufch_windows[] = { + { "1250", EE_CHARSET, 1250, X11DRV_CPTABLE_SBCS }, + { "1251", RUSSIAN_CHARSET, 1251, X11DRV_CPTABLE_SBCS }, + { "1252", ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }, + { "1253", GREEK_CHARSET, 1253, X11DRV_CPTABLE_SBCS }, + { "1254", TURKISH_CHARSET, 1254, X11DRV_CPTABLE_SBCS }, + { "1255", HEBREW_CHARSET, 1255, X11DRV_CPTABLE_SBCS }, + { "1256", ARABIC_CHARSET, 1256, X11DRV_CPTABLE_SBCS }, + { "1257", BALTIC_CHARSET, 1257, X11DRV_CPTABLE_SBCS }, + { NULL, ANSI_CHARSET, 1252, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_koi8[] = { - { "r", RUSSIAN_CHARSET, 20866 }, - { "u", RUSSIAN_CHARSET, 20866 }, - { NULL, RUSSIAN_CHARSET, 20866 }}; +static const SuffixCharset sufch_koi8[] = { + { "r", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS }, + { "u", RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS }, + { NULL, RUSSIAN_CHARSET, 20866, X11DRV_CPTABLE_SBCS }}; /* FIXME: DBCS charsets need 2 or more fonts */ -static SuffixCharset sufch_jisx0201[] = { - { "0", ANSI_CHARSET, 932 }, - { NULL, ANSI_CHARSET, 932 }}; +static const SuffixCharset sufch_jisx0201[] = { + { "0", ANSI_CHARSET, 932, X11DRV_CPTABLE_SBCS }, + { NULL, ANSI_CHARSET, 932, X11DRV_CPTABLE_SBCS }}; -static SuffixCharset sufch_jisx0208[] = { - { "0", SHIFTJIS_CHARSET, 932 }, - { NULL, SHIFTJIS_CHARSET, 932 }}; +static const SuffixCharset sufch_jisx0208[] = { + { "0", SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 }, + { NULL, SHIFTJIS_CHARSET, 932, X11DRV_CPTABLE_CP932 }}; -static SuffixCharset sufch_ksc5601[] = { - { "0", HANGEUL_CHARSET, 949 }, - { NULL, HANGEUL_CHARSET, 949 }}; +static const SuffixCharset sufch_ksc5601[] = { + { "0", HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 }, + { NULL, HANGEUL_CHARSET, 949, X11DRV_CPTABLE_CP949 }}; -static SuffixCharset sufch_gb2312[] = { - { "0", GB2312_CHARSET, 936 }, - { NULL, GB2312_CHARSET, 936 }}; +static const SuffixCharset sufch_gb2312[] = { + { "0", GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 }, + { NULL, GB2312_CHARSET, 936, X11DRV_CPTABLE_CP936 }}; -static SuffixCharset sufch_big5[] = { - { "0", CHINESEBIG5_CHARSET, 950 }, - { NULL, CHINESEBIG5_CHARSET, 950 }}; +static const SuffixCharset sufch_big5[] = { + { "0", CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 }, + { NULL, CHINESEBIG5_CHARSET, 950, X11DRV_CPTABLE_CP950 }}; -static SuffixCharset sufch_unicode[] = { - { "0", DEFAULT_CHARSET, 0 }, - { NULL, DEFAULT_CHARSET, 0 }}; +static const SuffixCharset sufch_unicode[] = { + { "0", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }, + { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }}; -static SuffixCharset sufch_iso10646[] = { - { "1", DEFAULT_CHARSET, 0 }, - { NULL, DEFAULT_CHARSET, 0 }}; +static const SuffixCharset sufch_iso10646[] = { + { "1", DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }, + { NULL, DEFAULT_CHARSET, 0, X11DRV_CPTABLE_UNICODE }}; /* Each of these must be matched explicitly */ -static SuffixCharset sufch_any[] = { - { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL }, - { NULL, 0, 0 }}; +static const SuffixCharset sufch_any[] = { + { "fontspecific", SYMBOL_CHARSET, CP_SYMBOL, X11DRV_CPTABLE_SBCS }, + { NULL, 0, 0, X11DRV_CPTABLE_SBCS }}; typedef struct __fet { LPSTR prefix; - SuffixCharset* sufch; + const SuffixCharset* sufch; struct __fet* next; } fontEncodingTemplate; @@ -390,7 +391,7 @@ static LFD* LFD_Parse(LPSTR lpFont) static void LFD_UnParse(LPSTR dp, UINT buf_size, LFD* lfd) { - char* lfd_fld[LFD_FIELDS]; + const char* lfd_fld[LFD_FIELDS]; int i; if (!buf_size) @@ -415,7 +416,7 @@ static void LFD_UnParse(LPSTR dp, UINT buf_size, LFD* lfd) for (i = 0; i < LFD_FIELDS; i++) { - char* sp = lfd_fld[i]; + const char* sp = lfd_fld[i]; if (!sp || !buf_size) break; @@ -523,7 +524,7 @@ static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname ) int i, j, dec_style_check, scalability; fontEncodingTemplate* boba; const char* ridiculous = "font '%s' has ridiculous %s\n"; - char* lpstr; + const char* lpstr; if (!lfd->charset_registry) { @@ -649,7 +650,7 @@ static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname ) strstr(lpstr, "gb2312") || strstr(lpstr, "big5") ) { - FIXME("DBCS fonts like '%s' are not worked correctly now.\n", fullname); + FIXME("DBCS fonts like '%s' are not working correctly now.\n", fullname); } fi->df.dfCharSet = ANSI_CHARSET; @@ -666,6 +667,7 @@ static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname ) { fi->df.dfCharSet = boba->sufch[j].charset; fi->codepage = boba->sufch[j].codepage; + fi->cptable = boba->sufch[j].cptable; goto done; } } @@ -675,6 +677,7 @@ static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname ) fullname, lfd->charset_encoding); fi->df.dfCharSet = boba->sufch[j].charset; fi->codepage = boba->sufch[j].codepage; + fi->cptable = boba->sufch[j].cptable; j = 254; goto done; } @@ -685,6 +688,7 @@ static int LFD_InitFontInfo( fontInfo* fi, const LFD* lfd, LPCSTR fullname ) ; fi->df.dfCharSet = boba->sufch[j].charset; fi->codepage = boba->sufch[j].codepage; + fi->cptable = boba->sufch[j].cptable; j = 255; goto done; } @@ -2062,6 +2066,7 @@ static BOOL XFONT_ReadCachedMetrics( int fd, int res, unsigned x_checksum, int x while( TRUE ) { if( offset > length || + pfi->cptable >= (UINT16)X11DRV_CPTABLE_COUNT || (int)(pfi->next) != j++ ) goto fail; if( pfi->df.dfPixHeight == 0 ) goto fail; diff --git a/include/x11font.h b/include/x11font.h index 0b99d87b1d3..2731f7fb4a1 100644 --- a/include/x11font.h +++ b/include/x11font.h @@ -72,12 +72,24 @@ typedef struct #define FI_ENC_TCVN 7 #define FI_ENC_TIS620 8 +enum X11DRV_CPTABLE +{ + X11DRV_CPTABLE_SBCS, + X11DRV_CPTABLE_UNICODE, + X11DRV_CPTABLE_CP932, + X11DRV_CPTABLE_CP936, + X11DRV_CPTABLE_CP949, + X11DRV_CPTABLE_CP950, + X11DRV_CPTABLE_COUNT +}; + typedef struct tagFontInfo { struct tagFontInfo* next; UINT16 fi_flags; UINT16 fi_encoding; UINT16 codepage; + UINT16 cptable; /* LFD parameters can be quite different from the actual metrics */ @@ -96,20 +108,20 @@ typedef struct tagFontInfo #define LFD_FIELDS 14 typedef struct { - char* foundry; - char* family; - char* weight; - char* slant; - char* set_width; - char* add_style; - char* pixel_size; - char* point_size; - char* resolution_x; - char* resolution_y; - char* spacing; - char* average_width; - char* charset_registry; - char* charset_encoding; + const char* foundry; + const char* family; + const char* weight; + const char* slant; + const char* set_width; + const char* add_style; + const char* pixel_size; + const char* point_size; + const char* resolution_x; + const char* resolution_y; + const char* spacing; + const char* average_width; + const char* charset_registry; + const char* charset_encoding; } LFD; typedef struct tagFontResource @@ -214,4 +226,20 @@ extern fontObject* XFONT_GetFontObject( X_PHYSFONT pFont ); extern XFontStruct* XFONT_GetFontStruct( X_PHYSFONT pFont ); extern LPIFONTINFO16 XFONT_GetFontInfo( X_PHYSFONT pFont ); +typedef struct tagX11DRV_CP +{ + XChar2b* (*punicode_to_char2b)( fontObject* pfo, + LPCWSTR lpwstr, UINT count ); + void (*pDrawString)( fontObject* pfo, Display* pdisp, Drawable d, GC gc, + int x, int y, XChar2b* pstr, int count ); + int (*pTextWidth)( fontObject* pfo, XChar2b* pstr, int count ); + void (*pDrawText)( fontObject* pfo, Display* pdisp, Drawable d, GC gc, + int x, int y, XTextItem16* pitems, int count ); + void (*pTextExtents)( fontObject* pfo, XChar2b* pstr, int count, + int* pdir, int* pascent, int* pdescent, + int* pwidth ); +} X11DRV_CP; + +extern const X11DRV_CP X11DRV_cptable[X11DRV_CPTABLE_COUNT]; + #endif /* __WINE_X11FONT_H */