codepage.c 19.1 KB
Newer Older
1 2 3 4
/*
 * X11 codepage handling
 *
 * Copyright 2000 Hidenori Takeshima <hidenori@a2.ctktv.ne.jp>
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22
 */

#include "config.h"

23
#include <math.h>
24
#include <stdarg.h>
25

26
#include "windef.h"
27
#include "winbase.h"
28 29 30
#include "winnls.h"
#include "x11font.h"

Hidenori Takeshima's avatar
Hidenori Takeshima committed
31
/***********************************************************************
32
 *           IsLegalDBCSChar for cp932/936/949/950/euc
Hidenori Takeshima's avatar
Hidenori Takeshima committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
 */
static inline
int IsLegalDBCSChar_cp932( BYTE lead, BYTE trail )
{
    return ( ( ( lead >= (BYTE)0x81 && lead <= (BYTE)0x9f ) ||
	       ( lead >= (BYTE)0xe0 && lead <= (BYTE)0xfc ) ) &&
	     ( ( trail >= (BYTE)0x40 && trail <= (BYTE)0x7e ) ||
	       ( trail >= (BYTE)0x80 && trail <= (BYTE)0xfc ) ) );
}

static inline
int IsLegalDBCSChar_cp936( BYTE lead, BYTE trail )
{
    return ( ( lead >= (BYTE)0x81 && lead <= (BYTE)0xfe ) &&
	     ( trail >= (BYTE)0x40 && trail <= (BYTE)0xfe ) );
}

static inline
int IsLegalDBCSChar_cp949( BYTE lead, BYTE trail )
{
    return ( ( lead >= (BYTE)0x81 && lead <= (BYTE)0xfe ) &&
	     ( trail >= (BYTE)0x41 && trail <= (BYTE)0xfe ) );
}

static inline
int IsLegalDBCSChar_cp950( BYTE lead, BYTE trail )
{
    return (   ( lead >= (BYTE)0x81 && lead <= (BYTE)0xfe ) &&
	     ( ( trail >= (BYTE)0x40 && trail <= (BYTE)0x7e ) ||
	       ( trail >= (BYTE)0xa1 && trail <= (BYTE)0xfe ) ) );
}

65

Hidenori Takeshima's avatar
Hidenori Takeshima committed
66
/***********************************************************************
67
 *           DBCSCharToXChar2b for cp932/euc
Hidenori Takeshima's avatar
Hidenori Takeshima committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
 */

static inline
void DBCSCharToXChar2b_cp932( XChar2b* pch, BYTE lead, BYTE trail )
{
    unsigned int  high, low;

    high = (unsigned int)lead;
    low = (unsigned int)trail;

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

    pch->byte1 = (unsigned char)high;
    pch->byte2 = (unsigned char)low;
}

99

100
static WORD X11DRV_enum_subfont_charset_normal( UINT index )
101 102 103 104
{
    return DEFAULT_CHARSET;
}

105
static WORD X11DRV_enum_subfont_charset_cp932( UINT index )
106 107 108
{
    switch ( index )
    {
109 110
    case 0: return X11FONT_JISX0201_CHARSET;
    case 1: return X11FONT_JISX0212_CHARSET;
111 112 113 114 115
    }

    return DEFAULT_CHARSET;
}

116
static WORD X11DRV_enum_subfont_charset_cp936( UINT index )
117
{
118 119 120 121 122
    switch ( index )
    {
    case 0: return ANSI_CHARSET;
    }

123 124 125
    return DEFAULT_CHARSET;
}

126
static WORD X11DRV_enum_subfont_charset_cp949( UINT index )
127 128 129 130 131 132 133 134 135
{
    switch ( index )
    {
    case 0: return ANSI_CHARSET;
    }

    return DEFAULT_CHARSET;
}

136
static WORD X11DRV_enum_subfont_charset_cp950( UINT index )
137
{
138 139 140 141 142
    switch ( index )
    {
    case 0: return ANSI_CHARSET;
    }

143 144 145 146
    return DEFAULT_CHARSET;
}


147 148 149 150 151
static XChar2b* X11DRV_unicode_to_char2b_sbcs( fontObject* pfo,
                                               LPCWSTR lpwstr, UINT count )
{
    XChar2b *str2b;
    UINT i;
Mike McCormack's avatar
Mike McCormack committed
152
    char *str;
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
    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;
Mike McCormack's avatar
Mike McCormack committed
200
    char *str;
201
    BYTE *str_src;
202 203 204 205 206 207 208 209 210 211
    UINT i;
    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;
    }
Hidenori Takeshima's avatar
Hidenori Takeshima committed
212 213 214

    /* handle jisx0212.1990... */
    WideCharToMultiByte( 932, 0, lpwstr, count, str, count*2, &ch, NULL );
215

Mike McCormack's avatar
Mike McCormack committed
216
    str_src = (BYTE*) str;
217
    str2b_dst = str2b;
218
    for (i = 0; i < count; i++, str_src++, str2b_dst++)
219
    {
Hidenori Takeshima's avatar
Hidenori Takeshima committed
220
	if ( IsLegalDBCSChar_cp932( *str_src, *(str_src+1) ) )
221
	{
Hidenori Takeshima's avatar
Hidenori Takeshima committed
222
	    DBCSCharToXChar2b_cp932( str2b_dst, *str_src, *(str_src+1) );
223
	    str_src++;
224 225 226 227
	}
	else
	{
	    str2b_dst->byte1 = 0;
228
	    str2b_dst->byte2 = *str_src;
229 230 231 232 233 234 235 236 237 238 239 240
	}
    }

    HeapFree( GetProcessHeap(), 0, str );

    return str2b;
}


static XChar2b* X11DRV_unicode_to_char2b_cp936( fontObject* pfo,
                                                LPCWSTR lpwstr, UINT count )
{
241 242
    XChar2b *str2b;
    XChar2b *str2b_dst;
Mike McCormack's avatar
Mike McCormack committed
243
    char *str;
244 245 246 247 248 249 250 251 252 253 254 255 256
    BYTE *str_src;
    UINT i;
    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( 936, 0, lpwstr, count, str, count*2, &ch, NULL );

Mike McCormack's avatar
Mike McCormack committed
257
    str_src = (BYTE*) str;
258 259 260 261 262
    str2b_dst = str2b;
    for (i = 0; i < count; i++, str_src++, str2b_dst++)
    {
	if ( IsLegalDBCSChar_cp936( *str_src, *(str_src+1) ) )
	{
263 264
	    str2b_dst->byte1 = *str_src;
	    str2b_dst->byte2 = *(str_src+1);
265 266 267 268 269 270 271 272 273 274 275 276
	    str_src++;
	}
	else
	{
	    str2b_dst->byte1 = 0;
	    str2b_dst->byte2 = *str_src;
	}
    }

    HeapFree( GetProcessHeap(), 0, str );

    return str2b;
277 278 279 280 281 282 283
}

static XChar2b* X11DRV_unicode_to_char2b_cp949( fontObject* pfo,
                                                LPCWSTR lpwstr, UINT count )
{
    XChar2b *str2b;
    XChar2b *str2b_dst;
Mike McCormack's avatar
Mike McCormack committed
284
    char *str;
285
    BYTE *str_src;
286 287 288 289 290 291 292 293 294 295
    UINT i;
    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;
    }
Hidenori Takeshima's avatar
Hidenori Takeshima committed
296
    WideCharToMultiByte( 949, 0, lpwstr, count, str, count*2, &ch, NULL );
297

Mike McCormack's avatar
Mike McCormack committed
298
    str_src = (BYTE*) str;
299
    str2b_dst = str2b;
300
    for (i = 0; i < count; i++, str_src++, str2b_dst++)
301
    {
Hidenori Takeshima's avatar
Hidenori Takeshima committed
302
	if ( IsLegalDBCSChar_cp949( *str_src, *(str_src+1) ) )
303
	{
304 305
            str2b_dst->byte1 = *str_src;
	    str2b_dst->byte2 = *(str_src+1);
306
	    str_src++;
307 308 309 310
	}
	else
	{
	    str2b_dst->byte1 = 0;
311
	    str2b_dst->byte2 = *str_src;
312 313 314 315 316 317 318 319 320 321 322 323
	}
    }

    HeapFree( GetProcessHeap(), 0, str );

    return str2b;
}


static XChar2b* X11DRV_unicode_to_char2b_cp950( fontObject* pfo,
                                                LPCWSTR lpwstr, UINT count )
{
324 325
    XChar2b *str2b;
    XChar2b *str2b_dst;
Mike McCormack's avatar
Mike McCormack committed
326
    char *str;
327 328 329 330 331 332 333 334 335 336 337 338 339
    BYTE *str_src;
    UINT i;
    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( 950, 0, lpwstr, count, str, count*2, &ch, NULL );

Mike McCormack's avatar
Mike McCormack committed
340
    str_src = (BYTE*) str;
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
    str2b_dst = str2b;
    for (i = 0; i < count; i++, str_src++, str2b_dst++)
    {
	if ( IsLegalDBCSChar_cp950( *str_src, *(str_src+1) ) )
	{
            str2b_dst->byte1 = *str_src;
	    str2b_dst->byte2 = *(str_src+1);
	    str_src++;
	}
	else
	{
	    str2b_dst->byte1 = 0;
	    str2b_dst->byte2 = *str_src;
	}
    }

    HeapFree( GetProcessHeap(), 0, str );

    return str2b;
360 361
}

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
static XChar2b* X11DRV_unicode_to_char2b_symbol( fontObject* pfo,
						 LPCWSTR lpwstr, UINT count )
{
    XChar2b *str2b;
    UINT i;
    char ch = pfo->fs->default_char;

    if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
	return NULL;

    for (i = 0; i < count; i++)
    {
	str2b[i].byte1 = 0;
	if(lpwstr[i] >= 0xf000 && lpwstr[i] < 0xf100)
	    str2b[i].byte2 = lpwstr[i] - 0xf000;
	else if(lpwstr[i] < 0x100)
	    str2b[i].byte2 = lpwstr[i];
	else
	    str2b[i].byte2 = ch;
    }

    return str2b;
}

386 387 388 389 390

static void X11DRV_DrawString_normal( fontObject* pfo, Display* pdisp,
                                      Drawable d, GC gc, int x, int y,
                                      XChar2b* pstr, int count )
{
391 392 393
    wine_tsx11_lock();
    XDrawString16( pdisp, d, gc, x, y, pstr, count );
    wine_tsx11_unlock();
394 395 396 397
}

static int X11DRV_TextWidth_normal( fontObject* pfo, XChar2b* pstr, int count )
{
398 399 400 401 402
    int ret;
    wine_tsx11_lock();
    ret = XTextWidth16( pfo->fs, pstr, count );
    wine_tsx11_unlock();
    return ret;
403 404 405 406 407 408
}

static void X11DRV_DrawText_normal( fontObject* pfo, Display* pdisp, Drawable d,
                                    GC gc, int x, int y, XTextItem16* pitems,
                                    int count )
{
409 410 411
    wine_tsx11_lock();
    XDrawText16( pdisp, d, gc, x, y, pitems, count );
    wine_tsx11_unlock();
412 413 414 415
}

static void X11DRV_TextExtents_normal( fontObject* pfo, XChar2b* pstr, int count,
                                       int* pdir, int* pascent, int* pdescent,
416 417
                                       int* pwidth, int max_extent, int* pfit,
                                       int* partial_extents )
418 419
{
    XCharStruct info;
420 421
    int ascent, descent, width;
    int i, fit;
422

423 424 425 426
    width = 0;
    fit = 0;
    *pascent = 0;
    *pdescent = 0;
427
    wine_tsx11_lock();
428 429 430 431 432 433 434 435 436 437 438
    for ( i = 0; i < count; i++ )
    {
	XTextExtents16( pfo->fs, pstr, 1, pdir, &ascent, &descent, &info );
	if ( *pascent < ascent ) *pascent = ascent;
	if ( *pdescent < descent ) *pdescent = descent;
	width += info.width;
	if ( partial_extents ) partial_extents[i] = width;
	if ( width < max_extent ) fit++;

	pstr++;
    }
439
    wine_tsx11_unlock();
440 441
    *pwidth = width;
    if ( pfit ) *pfit = fit;
442 443
}

444
static void X11DRV_GetTextMetricsW_normal( fontObject* pfo, LPTEXTMETRICW pTM )
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
{
    LPIFONTINFO16 pdf = &pfo->fi->df;

    if( ! pfo->lpX11Trans ) {
      pTM->tmAscent = pfo->fs->ascent;
      pTM->tmDescent = pfo->fs->descent;
    } else {
      pTM->tmAscent = pfo->lpX11Trans->ascent;
      pTM->tmDescent = pfo->lpX11Trans->descent;
    }

    pTM->tmAscent *= pfo->rescale;
    pTM->tmDescent *= pfo->rescale;

    pTM->tmHeight = pTM->tmAscent + pTM->tmDescent;

    pTM->tmAveCharWidth = pfo->foAvgCharWidth * pfo->rescale;
    pTM->tmMaxCharWidth = pfo->foMaxCharWidth * pfo->rescale;

    pTM->tmInternalLeading = pfo->foInternalLeading * pfo->rescale;
    pTM->tmExternalLeading = pdf->dfExternalLeading * pfo->rescale;

    pTM->tmStruckOut = (pfo->fo_flags & FO_SYNTH_STRIKEOUT )
			? 1 : pdf->dfStrikeOut;
    pTM->tmUnderlined = (pfo->fo_flags & FO_SYNTH_UNDERLINE )
			? 1 : pdf->dfUnderline;

    pTM->tmOverhang = 0;
473
    if( pfo->fo_flags & FO_SYNTH_ITALIC )
474 475 476
    {
	pTM->tmOverhang += pTM->tmHeight/3;
	pTM->tmItalic = 1;
477
    } else
478 479 480
	pTM->tmItalic = pdf->dfItalic;

    pTM->tmWeight = pdf->dfWeight;
481
    if( pfo->fo_flags & FO_SYNTH_BOLD )
482
    {
483
	pTM->tmOverhang++;
484
	pTM->tmWeight += 100;
485
    }
486 487 488 489 490 491 492 493 494 495 496 497

    pTM->tmFirstChar = pdf->dfFirstChar;
    pTM->tmLastChar = pdf->dfLastChar;
    pTM->tmDefaultChar = pdf->dfDefaultChar;
    pTM->tmBreakChar = pdf->dfBreakChar;

    pTM->tmCharSet = pdf->dfCharSet;
    pTM->tmPitchAndFamily = pdf->dfPitchAndFamily;

    pTM->tmDigitizedAspectX = pdf->dfHorizRes;
    pTM->tmDigitizedAspectY = pdf->dfVertRes;
}
498 499 500 501



static
502 503 504
void X11DRV_DrawString_dbcs( fontObject* pfo, Display* pdisp,
                             Drawable d, GC gc, int x, int y,
                             XChar2b* pstr, int count )
505
{
506 507 508 509 510 511 512 513
    XTextItem16 item;

    item.chars = pstr;
    item.delta = 0;
    item.nchars = count;
    item.font = None;
    X11DRV_cptable[pfo->fi->cptable].pDrawText(
		pfo, pdisp, d, gc, x, y, &item, 1 );
514 515 516
}

static
517
int X11DRV_TextWidth_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count )
518 519 520
{
    int i;
    int width;
521 522 523 524 525 526
    int curfont;
    fontObject* pfos[X11FONT_REFOBJS_MAX+1];

    pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
    pfos[1] = pfo;
    if ( pfos[0] == NULL ) pfos[0] = pfo;
527 528

    width = 0;
529
    wine_tsx11_lock();
530 531
    for ( i = 0; i < count; i++ )
    {
532
	curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
533
	width += XTextWidth16( pfos[curfont]->fs, pstr, 1 );
534 535
	pstr ++;
    }
536
    wine_tsx11_unlock();
537 538 539 540
    return width;
}

static
541 542 543
void X11DRV_DrawText_dbcs_2fonts( fontObject* pfo, Display* pdisp, Drawable d,
                                  GC gc, int x, int y, XTextItem16* pitems,
                                  int count )
544
{
545 546 547 548 549 550 551 552
    int i, nitems, prevfont = -1, curfont;
    XChar2b* pstr;
    XTextItem16* ptibuf;
    XTextItem16* pti;
    fontObject* pfos[X11FONT_REFOBJS_MAX+1];

    pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
    pfos[1] = pfo;
553
    if ( pfos[0] == NULL ) pfos[0] = pfo;
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586

    nitems = 0;
    for ( i = 0; i < count; i++ )
	nitems += pitems->nchars;
    ptibuf = HeapAlloc( GetProcessHeap(), 0, sizeof(XTextItem16) * nitems );
    if ( ptibuf == NULL )
	return; /* out of memory */

    pti = ptibuf;
    while ( count-- > 0 )
    {
	pti->chars = pstr = pitems->chars;
	pti->delta = pitems->delta;
	pti->font = None;
	for ( i = 0; i < pitems->nchars; i++, pstr++ )
	{
	    curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
	    if ( curfont != prevfont )
	    {
		if ( pstr != pti->chars )
		{
		    pti->nchars = pstr - pti->chars;
		    pti ++;
		    pti->chars = pstr;
		    pti->delta = 0;
		}
		pti->font = pfos[curfont]->fs->fid;
		prevfont = curfont;
	    }
	}
	pti->nchars = pstr - pti->chars;
	pitems ++; pti ++;
    }
587 588 589
    wine_tsx11_lock();
    XDrawText16( pdisp, d, gc, x, y, ptibuf, pti - ptibuf );
    wine_tsx11_unlock();
590
    HeapFree( GetProcessHeap(), 0, ptibuf );
591 592 593
}

static
594 595
void X11DRV_TextExtents_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count,
                                     int* pdir, int* pascent, int* pdescent,
596 597
                                     int* pwidth, int max_extent, int* pfit,
                                     int* partial_extents )
598 599 600 601
{
    XCharStruct info;
    int ascent, descent, width;
    int i;
602
    int fit;
603 604 605 606 607 608
    int curfont;
    fontObject* pfos[X11FONT_REFOBJS_MAX+1];

    pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
    pfos[1] = pfo;
    if ( pfos[0] == NULL ) pfos[0] = pfo;
609 610

    width = 0;
611
    fit = 0;
612 613
    *pascent = 0;
    *pdescent = 0;
614
    wine_tsx11_lock();
615 616
    for ( i = 0; i < count; i++ )
    {
617
	curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
618
	XTextExtents16( pfos[curfont]->fs, pstr, 1, pdir, &ascent, &descent, &info );
619 620 621
	if ( *pascent < ascent ) *pascent = ascent;
	if ( *pdescent < descent ) *pdescent = descent;
	width += info.width;
622 623
	if ( partial_extents ) partial_extents[i] = width;
	if ( width <= max_extent ) fit++;
624

625 626
	pstr ++;
    }
627
    wine_tsx11_unlock();
628
    *pwidth = width;
629
    if ( pfit ) *pfit = fit;
630 631
}

632
static void X11DRV_GetTextMetricsW_cp932( fontObject* pfo, LPTEXTMETRICW pTM )
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
{
    fontObject* pfo_ansi = XFONT_GetFontObject( pfo->prefobjs[0] );
    LPIFONTINFO16 pdf = &pfo->fi->df;
    LPIFONTINFO16 pdf_ansi;

    pdf_ansi = ( pfo_ansi != NULL ) ? (&pfo_ansi->fi->df) : pdf;

    if( ! pfo->lpX11Trans ) {
      pTM->tmAscent = pfo->fs->ascent;
      pTM->tmDescent = pfo->fs->descent;
    } else {
      pTM->tmAscent = pfo->lpX11Trans->ascent;
      pTM->tmDescent = pfo->lpX11Trans->descent;
    }

    pTM->tmAscent *= pfo->rescale;
    pTM->tmDescent *= pfo->rescale;

    pTM->tmHeight = pTM->tmAscent + pTM->tmDescent;

    if ( pfo_ansi != NULL )
    {
	pTM->tmAveCharWidth = floor((pfo_ansi->foAvgCharWidth * 2.0 + pfo->foAvgCharWidth) / 3.0 * pfo->rescale + 0.5);
656
	pTM->tmMaxCharWidth = max(pfo_ansi->foMaxCharWidth, pfo->foMaxCharWidth) * pfo->rescale;
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
    }
    else
    {
	pTM->tmAveCharWidth = floor((pfo->foAvgCharWidth * pfo->rescale + 1.0) / 2.0);
	pTM->tmMaxCharWidth = pfo->foMaxCharWidth * pfo->rescale;
    }

    pTM->tmInternalLeading = pfo->foInternalLeading * pfo->rescale;
    pTM->tmExternalLeading = pdf->dfExternalLeading * pfo->rescale;

    pTM->tmStruckOut = (pfo->fo_flags & FO_SYNTH_STRIKEOUT )
			? 1 : pdf->dfStrikeOut;
    pTM->tmUnderlined = (pfo->fo_flags & FO_SYNTH_UNDERLINE )
			? 1 : pdf->dfUnderline;

    pTM->tmOverhang = 0;
673
    if( pfo->fo_flags & FO_SYNTH_ITALIC )
674 675 676
    {
	pTM->tmOverhang += pTM->tmHeight/3;
	pTM->tmItalic = 1;
677
    } else
678 679 680
	pTM->tmItalic = pdf->dfItalic;

    pTM->tmWeight = pdf->dfWeight;
681
    if( pfo->fo_flags & FO_SYNTH_BOLD )
682
    {
683
	pTM->tmOverhang++;
684
	pTM->tmWeight += 100;
685
    }
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700

    pTM->tmFirstChar = pdf_ansi->dfFirstChar;
    pTM->tmLastChar = pdf_ansi->dfLastChar;
    pTM->tmDefaultChar = pdf_ansi->dfDefaultChar;
    pTM->tmBreakChar = pdf_ansi->dfBreakChar;

    pTM->tmCharSet = pdf->dfCharSet;
    pTM->tmPitchAndFamily = pdf->dfPitchAndFamily;

    pTM->tmDigitizedAspectX = pdf->dfHorizRes;
    pTM->tmDigitizedAspectY = pdf->dfVertRes;
}



701 702


703 704 705
const X11DRV_CP X11DRV_cptable[X11DRV_CPTABLE_COUNT] =
{
    { /* SBCS */
706
	X11DRV_enum_subfont_charset_normal,
707 708 709 710 711
	X11DRV_unicode_to_char2b_sbcs,
	X11DRV_DrawString_normal,
	X11DRV_TextWidth_normal,
	X11DRV_DrawText_normal,
	X11DRV_TextExtents_normal,
712
	X11DRV_GetTextMetricsW_normal,
713 714
    },
    { /* UNICODE */
715
	X11DRV_enum_subfont_charset_normal,
716 717 718 719 720
	X11DRV_unicode_to_char2b_unicode,
	X11DRV_DrawString_normal,
	X11DRV_TextWidth_normal,
	X11DRV_DrawText_normal,
	X11DRV_TextExtents_normal,
721
        X11DRV_GetTextMetricsW_normal,
722 723
    },
    { /* CP932 */
724
	X11DRV_enum_subfont_charset_cp932,
725
	X11DRV_unicode_to_char2b_cp932,
726
	X11DRV_DrawString_dbcs,
727 728 729
	X11DRV_TextWidth_dbcs_2fonts,
	X11DRV_DrawText_dbcs_2fonts,
	X11DRV_TextExtents_dbcs_2fonts,
730
        X11DRV_GetTextMetricsW_cp932,
731 732
    },
    { /* CP936 */
733
	X11DRV_enum_subfont_charset_cp936,
734
	X11DRV_unicode_to_char2b_cp936,
735 736 737 738
	X11DRV_DrawString_dbcs,
	X11DRV_TextWidth_dbcs_2fonts,
	X11DRV_DrawText_dbcs_2fonts,
	X11DRV_TextExtents_dbcs_2fonts,
739
        X11DRV_GetTextMetricsW_normal, /* FIXME */
740 741
    },
    { /* CP949 */
742
	X11DRV_enum_subfont_charset_cp949,
743
	X11DRV_unicode_to_char2b_cp949,
744 745 746 747
	X11DRV_DrawString_dbcs,
	X11DRV_TextWidth_dbcs_2fonts,
	X11DRV_DrawText_dbcs_2fonts,
	X11DRV_TextExtents_dbcs_2fonts,
748
        X11DRV_GetTextMetricsW_normal, /* FIXME */
749 750
    },
    { /* CP950 */
751
	X11DRV_enum_subfont_charset_cp950,
752
	X11DRV_unicode_to_char2b_cp950,
753 754 755 756
	X11DRV_DrawString_dbcs,
	X11DRV_TextWidth_dbcs_2fonts,
	X11DRV_DrawText_dbcs_2fonts,
	X11DRV_TextExtents_dbcs_2fonts,
757
        X11DRV_GetTextMetricsW_cp932,
758
    },
759 760 761 762 763 764 765
    { /* SYMBOL */
	X11DRV_enum_subfont_charset_normal,
	X11DRV_unicode_to_char2b_symbol,
	X11DRV_DrawString_normal,
	X11DRV_TextWidth_normal,
	X11DRV_DrawText_normal,
	X11DRV_TextExtents_normal,
766
	X11DRV_GetTextMetricsW_normal,
767
    }
768
};