codepage.c 18.9 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 18
 *
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
#include "winnls.h"
#include "x11font.h"
30
#include "wine/debug.h"
31

32
WINE_DEFAULT_DEBUG_CHANNEL(text);
33

Hidenori Takeshima's avatar
Hidenori Takeshima committed
34
/***********************************************************************
35
 *           IsLegalDBCSChar for cp932/936/949/950/euc
Hidenori Takeshima's avatar
Hidenori Takeshima committed
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 65 66 67
 */
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 ) ) );
}

68 69 70 71 72 73 74 75
static inline
int IsLegalDBCSChar_euc( BYTE lead, BYTE trail )
{
    return ( ( lead >= (BYTE)0xa1 && lead <= (BYTE)0xfe ) &&
             ( trail >= (BYTE)0xa1 && trail <= (BYTE)0xfe ) );
}


Hidenori Takeshima's avatar
Hidenori Takeshima committed
76
/***********************************************************************
77
 *           DBCSCharToXChar2b for cp932/euc
Hidenori Takeshima's avatar
Hidenori Takeshima committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
 */

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

static inline
110
void DBCSCharToXChar2b_euc( XChar2b* pch, BYTE lead, BYTE trail )
Hidenori Takeshima's avatar
Hidenori Takeshima committed
111 112 113 114 115 116 117
{
    pch->byte1 = lead & (BYTE)0x7f;
    pch->byte2 = trail & (BYTE)0x7f;
}



118

119
static WORD X11DRV_enum_subfont_charset_normal( UINT index )
120 121 122 123
{
    return DEFAULT_CHARSET;
}

124
static WORD X11DRV_enum_subfont_charset_cp932( UINT index )
125 126 127
{
    switch ( index )
    {
128 129
    case 0: return X11FONT_JISX0201_CHARSET;
    case 1: return X11FONT_JISX0212_CHARSET;
130 131 132 133 134
    }

    return DEFAULT_CHARSET;
}

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

142 143 144
    return DEFAULT_CHARSET;
}

145
static WORD X11DRV_enum_subfont_charset_cp949( UINT index )
146 147 148 149 150 151 152 153 154
{
    switch ( index )
    {
    case 0: return ANSI_CHARSET;
    }

    return DEFAULT_CHARSET;
}

155
static WORD X11DRV_enum_subfont_charset_cp950( UINT index )
156
{
157 158 159 160 161
    switch ( index )
    {
    case 0: return ANSI_CHARSET;
    }

162 163 164 165
    return DEFAULT_CHARSET;
}


166 167 168 169 170
static XChar2b* X11DRV_unicode_to_char2b_sbcs( fontObject* pfo,
                                               LPCWSTR lpwstr, UINT count )
{
    XChar2b *str2b;
    UINT i;
Mike McCormack's avatar
Mike McCormack committed
171
    char *str;
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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
    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
219
    char *str;
220
    BYTE *str_src;
221 222 223 224 225 226 227 228 229 230
    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
231 232 233

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

Mike McCormack's avatar
Mike McCormack committed
235
    str_src = (BYTE*) str;
236
    str2b_dst = str2b;
237
    for (i = 0; i < count; i++, str_src++, str2b_dst++)
238
    {
Hidenori Takeshima's avatar
Hidenori Takeshima committed
239
	if ( IsLegalDBCSChar_cp932( *str_src, *(str_src+1) ) )
240
	{
Hidenori Takeshima's avatar
Hidenori Takeshima committed
241
	    DBCSCharToXChar2b_cp932( str2b_dst, *str_src, *(str_src+1) );
242
	    str_src++;
243 244 245 246
	}
	else
	{
	    str2b_dst->byte1 = 0;
247
	    str2b_dst->byte2 = *str_src;
248 249 250 251 252 253 254 255 256 257 258 259
	}
    }

    HeapFree( GetProcessHeap(), 0, str );

    return str2b;
}


static XChar2b* X11DRV_unicode_to_char2b_cp936( fontObject* pfo,
                                                LPCWSTR lpwstr, UINT count )
{
260 261
    XChar2b *str2b;
    XChar2b *str2b_dst;
Mike McCormack's avatar
Mike McCormack committed
262
    char *str;
263 264 265 266 267 268 269 270 271 272 273 274 275
    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
276
    str_src = (BYTE*) str;
277 278 279 280 281
    str2b_dst = str2b;
    for (i = 0; i < count; i++, str_src++, str2b_dst++)
    {
	if ( IsLegalDBCSChar_cp936( *str_src, *(str_src+1) ) )
	{
282 283
	    str2b_dst->byte1 = *str_src;
	    str2b_dst->byte2 = *(str_src+1);
284 285 286 287 288 289 290 291 292 293 294 295
	    str_src++;
	}
	else
	{
	    str2b_dst->byte1 = 0;
	    str2b_dst->byte2 = *str_src;
	}
    }

    HeapFree( GetProcessHeap(), 0, str );

    return str2b;
296 297 298 299 300 301 302
}

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
303
    char *str;
304
    BYTE *str_src;
305 306 307 308 309 310 311 312 313 314
    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
315
    WideCharToMultiByte( 949, 0, lpwstr, count, str, count*2, &ch, NULL );
316

Mike McCormack's avatar
Mike McCormack committed
317
    str_src = (BYTE*) str;
318
    str2b_dst = str2b;
319
    for (i = 0; i < count; i++, str_src++, str2b_dst++)
320
    {
Hidenori Takeshima's avatar
Hidenori Takeshima committed
321
	if ( IsLegalDBCSChar_cp949( *str_src, *(str_src+1) ) )
322
	{
323 324
            str2b_dst->byte1 = *str_src;
	    str2b_dst->byte2 = *(str_src+1);
325
	    str_src++;
326 327 328 329
	}
	else
	{
	    str2b_dst->byte1 = 0;
330
	    str2b_dst->byte2 = *str_src;
331 332 333 334 335 336 337 338 339 340 341 342
	}
    }

    HeapFree( GetProcessHeap(), 0, str );

    return str2b;
}


static XChar2b* X11DRV_unicode_to_char2b_cp950( fontObject* pfo,
                                                LPCWSTR lpwstr, UINT count )
{
343 344
    XChar2b *str2b;
    XChar2b *str2b_dst;
Mike McCormack's avatar
Mike McCormack committed
345
    char *str;
346 347 348 349 350 351 352 353 354 355 356 357 358
    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
359
    str_src = (BYTE*) str;
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
    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;
379 380
}

381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
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;
}

405 406 407 408 409

static void X11DRV_DrawString_normal( fontObject* pfo, Display* pdisp,
                                      Drawable d, GC gc, int x, int y,
                                      XChar2b* pstr, int count )
{
410 411 412
    wine_tsx11_lock();
    XDrawString16( pdisp, d, gc, x, y, pstr, count );
    wine_tsx11_unlock();
413 414 415 416
}

static int X11DRV_TextWidth_normal( fontObject* pfo, XChar2b* pstr, int count )
{
417 418 419 420 421
    int ret;
    wine_tsx11_lock();
    ret = XTextWidth16( pfo->fs, pstr, count );
    wine_tsx11_unlock();
    return ret;
422 423 424 425 426 427
}

static void X11DRV_DrawText_normal( fontObject* pfo, Display* pdisp, Drawable d,
                                    GC gc, int x, int y, XTextItem16* pitems,
                                    int count )
{
428 429 430
    wine_tsx11_lock();
    XDrawText16( pdisp, d, gc, x, y, pitems, count );
    wine_tsx11_unlock();
431 432 433 434 435 436 437 438
}

static void X11DRV_TextExtents_normal( fontObject* pfo, XChar2b* pstr, int count,
                                       int* pdir, int* pascent, int* pdescent,
                                       int* pwidth )
{
    XCharStruct info;

439 440 441
    wine_tsx11_lock();
    XTextExtents16( pfo->fs, pstr, count, pdir, pascent, pdescent, &info );
    wine_tsx11_unlock();
442 443 444
    *pwidth = info.width;
}

445
static void X11DRV_GetTextMetricsW_normal( fontObject* pfo, LPTEXTMETRICW pTM )
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 473
{
    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;
474
    if( pfo->fo_flags & FO_SYNTH_ITALIC )
475 476 477
    {
	pTM->tmOverhang += pTM->tmHeight/3;
	pTM->tmItalic = 1;
478
    } else
479 480 481
	pTM->tmItalic = pdf->dfItalic;

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

    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;
}
499 500 501 502



static
503 504 505
void X11DRV_DrawString_dbcs( fontObject* pfo, Display* pdisp,
                             Drawable d, GC gc, int x, int y,
                             XChar2b* pstr, int count )
506
{
507 508 509 510 511 512 513 514
    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 );
515 516 517
}

static
518
int X11DRV_TextWidth_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count )
519 520 521
{
    int i;
    int width;
522 523 524 525 526 527
    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;
528 529

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

static
542 543 544
void X11DRV_DrawText_dbcs_2fonts( fontObject* pfo, Display* pdisp, Drawable d,
                                  GC gc, int x, int y, XTextItem16* pitems,
                                  int count )
545
{
546 547 548 549 550 551 552 553
    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;
554
    if ( pfos[0] == NULL ) pfos[0] = pfo;
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 587

    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 ++;
    }
588 589 590
    wine_tsx11_lock();
    XDrawText16( pdisp, d, gc, x, y, ptibuf, pti - ptibuf );
    wine_tsx11_unlock();
591
    HeapFree( GetProcessHeap(), 0, ptibuf );
592 593 594
}

static
595 596 597
void X11DRV_TextExtents_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count,
                                     int* pdir, int* pascent, int* pdescent,
                                     int* pwidth )
598 599 600 601
{
    XCharStruct info;
    int ascent, descent, width;
    int i;
602 603 604 605 606 607
    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;
608 609 610 611

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

621 622
	pstr ++;
    }
623
    wine_tsx11_unlock();
624 625 626
    *pwidth = width;
}

627
static void X11DRV_GetTextMetricsW_cp932( fontObject* pfo, LPTEXTMETRICW pTM )
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
{
    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);
651
	pTM->tmMaxCharWidth = max(pfo_ansi->foMaxCharWidth, pfo->foMaxCharWidth) * pfo->rescale;
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
    }
    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;
668
    if( pfo->fo_flags & FO_SYNTH_ITALIC )
669 670 671
    {
	pTM->tmOverhang += pTM->tmHeight/3;
	pTM->tmItalic = 1;
672
    } else
673 674 675
	pTM->tmItalic = pdf->dfItalic;

    pTM->tmWeight = pdf->dfWeight;
676
    if( pfo->fo_flags & FO_SYNTH_BOLD )
677
    {
678
	pTM->tmOverhang++;
679
	pTM->tmWeight += 100;
680
    }
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695

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



696 697


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