2 * X11 codepage handling
4 * Copyright 2000 Hidenori Takeshima <hidenori@a2.ctktv.ne.jp>
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(text);
22 static WORD X11DRV_enum_subfont_charset_normal( UINT index )
24 return DEFAULT_CHARSET;
27 static WORD X11DRV_enum_subfont_charset_cp932( UINT index )
31 case 0: return X11FONT_JISX0201_CHARSET;
32 case 1: return X11FONT_JISX0212_CHARSET;
35 return DEFAULT_CHARSET;
38 static WORD X11DRV_enum_subfont_charset_cp936( UINT index )
40 FIXME( "please implement X11DRV_enum_subfont_charset_cp936!\n" );
41 return DEFAULT_CHARSET;
44 static WORD X11DRV_enum_subfont_charset_cp949( UINT index )
48 case 0: return ANSI_CHARSET;
51 return DEFAULT_CHARSET;
54 static WORD X11DRV_enum_subfont_charset_cp950( UINT index )
56 FIXME( "please implement X11DRV_enum_subfont_charset_cp950!\n" );
57 return DEFAULT_CHARSET;
61 static XChar2b* X11DRV_unicode_to_char2b_sbcs( fontObject* pfo,
62 LPCWSTR lpwstr, UINT count )
67 UINT codepage = pfo->fi->codepage;
68 char ch = pfo->fs->default_char;
70 if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
72 if (!(str = HeapAlloc( GetProcessHeap(), 0, count )))
74 HeapFree( GetProcessHeap(), 0, str2b );
78 WideCharToMultiByte( codepage, 0, lpwstr, count, str, count, &ch, NULL );
80 for (i = 0; i < count; i++)
83 str2b[i].byte2 = str[i];
85 HeapFree( GetProcessHeap(), 0, str );
90 static XChar2b* X11DRV_unicode_to_char2b_unicode( fontObject* pfo,
91 LPCWSTR lpwstr, UINT count )
96 if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
99 for (i = 0; i < count; i++)
101 str2b[i].byte1 = lpwstr[i] >> 8;
102 str2b[i].byte2 = lpwstr[i] & 0xff;
108 /* FIXME: handle jisx0212.1990... */
109 static XChar2b* X11DRV_unicode_to_char2b_cp932( fontObject* pfo,
110 LPCWSTR lpwstr, UINT count )
117 UINT codepage = pfo->fi->codepage;
118 char ch = pfo->fs->default_char;
120 if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
122 if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 )))
124 HeapFree( GetProcessHeap(), 0, str2b );
127 WideCharToMultiByte( codepage, 0, lpwstr, count, str, count*2, &ch, NULL );
131 for (i = 0; i < count; i++, str_src++, str2b_dst++)
133 if ( ( *str_src >= (BYTE)0x80 && *str_src <= (BYTE)0x9f ) ||
134 ( *str_src >= (BYTE)0xe0 && *str_src <= (BYTE)0xfc ) )
136 unsigned int high, low;
138 high = (unsigned int)*str_src;
139 low = (unsigned int)*(str_src+1);
142 high = (high<<1) - 0xe0;
144 high = (high<<1) - 0x160;
158 str2b_dst->byte1 = (unsigned char)high;
159 str2b_dst->byte2 = (unsigned char)low;
164 str2b_dst->byte1 = 0;
165 str2b_dst->byte2 = *str_src;
169 HeapFree( GetProcessHeap(), 0, str );
175 static XChar2b* X11DRV_unicode_to_char2b_cp936( fontObject* pfo,
176 LPCWSTR lpwstr, UINT count )
178 FIXME( "please implement X11DRV_unicode_to_char2b_cp936!\n" );
183 static XChar2b* X11DRV_unicode_to_char2b_cp949( fontObject* pfo,
184 LPCWSTR lpwstr, UINT count )
191 UINT codepage = pfo->fi->codepage;
192 char ch = pfo->fs->default_char;
194 if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
196 if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 )))
198 HeapFree( GetProcessHeap(), 0, str2b );
201 WideCharToMultiByte( codepage, 0, lpwstr, count, str, count*2, &ch, NULL );
205 for (i = 0; i < count; i++, str_src++, str2b_dst++)
207 if ( (*str_src) & (BYTE)0x80 )
209 str2b_dst->byte1 = (*str_src) & 0x7f;
210 str2b_dst->byte2 = (*(str_src+1)) & 0x7f;
215 str2b_dst->byte1 = 0;
216 str2b_dst->byte2 = *str_src;
220 HeapFree( GetProcessHeap(), 0, str );
226 static XChar2b* X11DRV_unicode_to_char2b_cp950( fontObject* pfo,
227 LPCWSTR lpwstr, UINT count )
229 FIXME( "please implement X11DRV_unicode_to_char2b_cp950!\n" );
234 static void X11DRV_DrawString_normal( fontObject* pfo, Display* pdisp,
235 Drawable d, GC gc, int x, int y,
236 XChar2b* pstr, int count )
238 TSXDrawString16( pdisp, d, gc, x, y, pstr, count );
241 static int X11DRV_TextWidth_normal( fontObject* pfo, XChar2b* pstr, int count )
243 return TSXTextWidth16( pfo->fs, pstr, count );
246 static void X11DRV_DrawText_normal( fontObject* pfo, Display* pdisp, Drawable d,
247 GC gc, int x, int y, XTextItem16* pitems,
250 TSXDrawText16( pdisp, d, gc, x, y, pitems, count );
253 static void X11DRV_TextExtents_normal( fontObject* pfo, XChar2b* pstr, int count,
254 int* pdir, int* pascent, int* pdescent,
259 TSXTextExtents16( pfo->fs, pstr, count, pdir, pascent, pdescent, &info );
260 *pwidth = info.width;
263 static void X11DRV_GetTextMetricsA_normal( fontObject* pfo, LPTEXTMETRICA pTM )
265 LPIFONTINFO16 pdf = &pfo->fi->df;
267 if( ! pfo->lpX11Trans ) {
268 pTM->tmAscent = pfo->fs->ascent;
269 pTM->tmDescent = pfo->fs->descent;
271 pTM->tmAscent = pfo->lpX11Trans->ascent;
272 pTM->tmDescent = pfo->lpX11Trans->descent;
275 pTM->tmAscent *= pfo->rescale;
276 pTM->tmDescent *= pfo->rescale;
278 pTM->tmHeight = pTM->tmAscent + pTM->tmDescent;
280 pTM->tmAveCharWidth = pfo->foAvgCharWidth * pfo->rescale;
281 pTM->tmMaxCharWidth = pfo->foMaxCharWidth * pfo->rescale;
283 pTM->tmInternalLeading = pfo->foInternalLeading * pfo->rescale;
284 pTM->tmExternalLeading = pdf->dfExternalLeading * pfo->rescale;
286 pTM->tmStruckOut = (pfo->fo_flags & FO_SYNTH_STRIKEOUT )
287 ? 1 : pdf->dfStrikeOut;
288 pTM->tmUnderlined = (pfo->fo_flags & FO_SYNTH_UNDERLINE )
289 ? 1 : pdf->dfUnderline;
292 if( pfo->fo_flags & FO_SYNTH_ITALIC )
294 pTM->tmOverhang += pTM->tmHeight/3;
297 pTM->tmItalic = pdf->dfItalic;
299 pTM->tmWeight = pdf->dfWeight;
300 if( pfo->fo_flags & FO_SYNTH_BOLD )
303 pTM->tmWeight += 100;
306 pTM->tmFirstChar = pdf->dfFirstChar;
307 pTM->tmLastChar = pdf->dfLastChar;
308 pTM->tmDefaultChar = pdf->dfDefaultChar;
309 pTM->tmBreakChar = pdf->dfBreakChar;
311 pTM->tmCharSet = pdf->dfCharSet;
312 pTM->tmPitchAndFamily = pdf->dfPitchAndFamily;
314 pTM->tmDigitizedAspectX = pdf->dfHorizRes;
315 pTM->tmDigitizedAspectY = pdf->dfVertRes;
321 void X11DRV_DrawString_dbcs( fontObject* pfo, Display* pdisp,
322 Drawable d, GC gc, int x, int y,
323 XChar2b* pstr, int count )
331 X11DRV_cptable[pfo->fi->cptable].pDrawText(
332 pfo, pdisp, d, gc, x, y, &item, 1 );
336 int X11DRV_TextWidth_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count )
341 fontObject* pfos[X11FONT_REFOBJS_MAX+1];
343 pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
345 if ( pfos[0] == NULL ) pfos[0] = pfo;
348 for ( i = 0; i < count; i++ )
350 curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
351 width += TSXTextWidth16( pfos[curfont]->fs, pstr, 1 );
359 void X11DRV_DrawText_dbcs_2fonts( fontObject* pfo, Display* pdisp, Drawable d,
360 GC gc, int x, int y, XTextItem16* pitems,
363 int i, nitems, prevfont = -1, curfont;
367 fontObject* pfos[X11FONT_REFOBJS_MAX+1];
369 pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
371 if ( pfos[0] == NULL ) pfos[0] = pfo;
374 for ( i = 0; i < count; i++ )
375 nitems += pitems->nchars;
376 ptibuf = HeapAlloc( GetProcessHeap(), 0, sizeof(XTextItem16) * nitems );
377 if ( ptibuf == NULL )
378 return; /* out of memory */
381 while ( count-- > 0 )
383 pti->chars = pstr = pitems->chars;
384 pti->delta = pitems->delta;
386 for ( i = 0; i < pitems->nchars; i++, pstr++ )
388 curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
389 if ( curfont != prevfont )
391 if ( pstr != pti->chars )
393 pti->nchars = pstr - pti->chars;
398 pti->font = pfos[curfont]->fs->fid;
402 pti->nchars = pstr - pti->chars;
405 TSXDrawText16( pdisp, d, gc, x, y, ptibuf, pti - ptibuf );
406 HeapFree( GetProcessHeap(), 0, ptibuf );
410 void X11DRV_TextExtents_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count,
411 int* pdir, int* pascent, int* pdescent,
415 int ascent, descent, width;
418 fontObject* pfos[X11FONT_REFOBJS_MAX+1];
420 pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
422 if ( pfos[0] == NULL ) pfos[0] = pfo;
427 for ( i = 0; i < count; i++ )
429 curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
430 TSXTextExtents16( pfos[curfont]->fs, pstr, 1, pdir,
431 &ascent, &descent, &info );
432 if ( *pascent < ascent ) *pascent = ascent;
433 if ( *pdescent < descent ) *pdescent = descent;
442 static void X11DRV_GetTextMetricsA_cp932( fontObject* pfo, LPTEXTMETRICA pTM )
444 fontObject* pfo_ansi = XFONT_GetFontObject( pfo->prefobjs[0] );
445 LPIFONTINFO16 pdf = &pfo->fi->df;
446 LPIFONTINFO16 pdf_ansi;
448 pdf_ansi = ( pfo_ansi != NULL ) ? (&pfo_ansi->fi->df) : pdf;
450 if( ! pfo->lpX11Trans ) {
451 pTM->tmAscent = pfo->fs->ascent;
452 pTM->tmDescent = pfo->fs->descent;
454 pTM->tmAscent = pfo->lpX11Trans->ascent;
455 pTM->tmDescent = pfo->lpX11Trans->descent;
458 pTM->tmAscent *= pfo->rescale;
459 pTM->tmDescent *= pfo->rescale;
461 pTM->tmHeight = pTM->tmAscent + pTM->tmDescent;
463 if ( pfo_ansi != NULL )
465 pTM->tmAveCharWidth = floor((pfo_ansi->foAvgCharWidth * 2.0 + pfo->foAvgCharWidth) / 3.0 * pfo->rescale + 0.5);
466 pTM->tmMaxCharWidth = __max(pfo_ansi->foMaxCharWidth, pfo->foMaxCharWidth) * pfo->rescale;
470 pTM->tmAveCharWidth = floor((pfo->foAvgCharWidth * pfo->rescale + 1.0) / 2.0);
471 pTM->tmMaxCharWidth = pfo->foMaxCharWidth * pfo->rescale;
474 pTM->tmInternalLeading = pfo->foInternalLeading * pfo->rescale;
475 pTM->tmExternalLeading = pdf->dfExternalLeading * pfo->rescale;
477 pTM->tmStruckOut = (pfo->fo_flags & FO_SYNTH_STRIKEOUT )
478 ? 1 : pdf->dfStrikeOut;
479 pTM->tmUnderlined = (pfo->fo_flags & FO_SYNTH_UNDERLINE )
480 ? 1 : pdf->dfUnderline;
483 if( pfo->fo_flags & FO_SYNTH_ITALIC )
485 pTM->tmOverhang += pTM->tmHeight/3;
488 pTM->tmItalic = pdf->dfItalic;
490 pTM->tmWeight = pdf->dfWeight;
491 if( pfo->fo_flags & FO_SYNTH_BOLD )
494 pTM->tmWeight += 100;
497 pTM->tmFirstChar = pdf_ansi->dfFirstChar;
498 pTM->tmLastChar = pdf_ansi->dfLastChar;
499 pTM->tmDefaultChar = pdf_ansi->dfDefaultChar;
500 pTM->tmBreakChar = pdf_ansi->dfBreakChar;
502 pTM->tmCharSet = pdf->dfCharSet;
503 pTM->tmPitchAndFamily = pdf->dfPitchAndFamily;
505 pTM->tmDigitizedAspectX = pdf->dfHorizRes;
506 pTM->tmDigitizedAspectY = pdf->dfVertRes;
513 const X11DRV_CP X11DRV_cptable[X11DRV_CPTABLE_COUNT] =
516 X11DRV_enum_subfont_charset_normal,
517 X11DRV_unicode_to_char2b_sbcs,
518 X11DRV_DrawString_normal,
519 X11DRV_TextWidth_normal,
520 X11DRV_DrawText_normal,
521 X11DRV_TextExtents_normal,
522 X11DRV_GetTextMetricsA_normal,
525 X11DRV_enum_subfont_charset_normal,
526 X11DRV_unicode_to_char2b_unicode,
527 X11DRV_DrawString_normal,
528 X11DRV_TextWidth_normal,
529 X11DRV_DrawText_normal,
530 X11DRV_TextExtents_normal,
531 X11DRV_GetTextMetricsA_normal,
534 X11DRV_enum_subfont_charset_cp932,
535 X11DRV_unicode_to_char2b_cp932,
536 X11DRV_DrawString_dbcs,
537 X11DRV_TextWidth_dbcs_2fonts,
538 X11DRV_DrawText_dbcs_2fonts,
539 X11DRV_TextExtents_dbcs_2fonts,
540 X11DRV_GetTextMetricsA_cp932,
543 X11DRV_enum_subfont_charset_cp936,
544 X11DRV_unicode_to_char2b_cp936,
545 X11DRV_DrawString_normal, /* FIXME */
546 X11DRV_TextWidth_normal, /* FIXME */
547 X11DRV_DrawText_normal, /* FIXME */
548 X11DRV_TextExtents_normal, /* FIXME */
549 X11DRV_GetTextMetricsA_normal, /* FIXME */
552 X11DRV_enum_subfont_charset_cp949,
553 X11DRV_unicode_to_char2b_cp949,
554 X11DRV_DrawString_dbcs,
555 X11DRV_TextWidth_dbcs_2fonts,
556 X11DRV_DrawText_dbcs_2fonts,
557 X11DRV_TextExtents_dbcs_2fonts,
558 X11DRV_GetTextMetricsA_normal, /* FIXME */
561 X11DRV_enum_subfont_charset_cp950,
562 X11DRV_unicode_to_char2b_cp950,
563 X11DRV_DrawString_normal, /* FIXME */
564 X11DRV_TextWidth_normal, /* FIXME */
565 X11DRV_DrawText_normal, /* FIXME */
566 X11DRV_TextExtents_normal, /* FIXME */
567 X11DRV_GetTextMetricsA_normal, /* FIXME */