winex11.drv: Cast-qual warnings fix.
[wine] / dlls / winex11.drv / codepage.c
1 /*
2  * X11 codepage handling
3  *
4  * Copyright 2000 Hidenori Takeshima <hidenori@a2.ctktv.ne.jp>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 #include "config.h"
22
23 #include <math.h>
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "x11font.h"
30
31 /***********************************************************************
32  *           IsLegalDBCSChar for cp932/936/949/950/euc
33  */
34 static inline
35 int IsLegalDBCSChar_cp932( BYTE lead, BYTE trail )
36 {
37     return ( ( ( lead >= (BYTE)0x81 && lead <= (BYTE)0x9f ) ||
38                ( lead >= (BYTE)0xe0 && lead <= (BYTE)0xfc ) ) &&
39              ( ( trail >= (BYTE)0x40 && trail <= (BYTE)0x7e ) ||
40                ( trail >= (BYTE)0x80 && trail <= (BYTE)0xfc ) ) );
41 }
42
43 static inline
44 int IsLegalDBCSChar_cp936( BYTE lead, BYTE trail )
45 {
46     return ( ( lead >= (BYTE)0x81 && lead <= (BYTE)0xfe ) &&
47              ( trail >= (BYTE)0x40 && trail <= (BYTE)0xfe ) );
48 }
49
50 static inline
51 int IsLegalDBCSChar_cp949( BYTE lead, BYTE trail )
52 {
53     return ( ( lead >= (BYTE)0x81 && lead <= (BYTE)0xfe ) &&
54              ( trail >= (BYTE)0x41 && trail <= (BYTE)0xfe ) );
55 }
56
57 static inline
58 int IsLegalDBCSChar_cp950( BYTE lead, BYTE trail )
59 {
60     return (   ( lead >= (BYTE)0x81 && lead <= (BYTE)0xfe ) &&
61              ( ( trail >= (BYTE)0x40 && trail <= (BYTE)0x7e ) ||
62                ( trail >= (BYTE)0xa1 && trail <= (BYTE)0xfe ) ) );
63 }
64
65 static inline
66 int IsLegalDBCSChar_euc( BYTE lead, BYTE trail )
67 {
68     return ( ( lead >= (BYTE)0xa1 && lead <= (BYTE)0xfe ) &&
69              ( trail >= (BYTE)0xa1 && trail <= (BYTE)0xfe ) );
70 }
71
72
73 /***********************************************************************
74  *           DBCSCharToXChar2b for cp932/euc
75  */
76
77 static inline
78 void DBCSCharToXChar2b_cp932( XChar2b* pch, BYTE lead, BYTE trail )
79 {
80     unsigned int  high, low;
81
82     high = (unsigned int)lead;
83     low = (unsigned int)trail;
84
85     if ( high <= 0x9f )
86         high = (high<<1) - 0xe0;
87     else
88         high = (high<<1) - 0x160;
89     if ( low < 0x9f )
90     {
91         high --;
92         if ( low < 0x7f )
93             low -= 0x1f;
94         else
95             low -= 0x20;
96     }
97     else
98     {
99         low -= 0x7e;
100     }
101
102     pch->byte1 = (unsigned char)high;
103     pch->byte2 = (unsigned char)low;
104 }
105
106 static inline
107 void DBCSCharToXChar2b_euc( XChar2b* pch, BYTE lead, BYTE trail )
108 {
109     pch->byte1 = lead & (BYTE)0x7f;
110     pch->byte2 = trail & (BYTE)0x7f;
111 }
112
113
114
115
116 static WORD X11DRV_enum_subfont_charset_normal( UINT index )
117 {
118     return DEFAULT_CHARSET;
119 }
120
121 static WORD X11DRV_enum_subfont_charset_cp932( UINT index )
122 {
123     switch ( index )
124     {
125     case 0: return X11FONT_JISX0201_CHARSET;
126     case 1: return X11FONT_JISX0212_CHARSET;
127     }
128
129     return DEFAULT_CHARSET;
130 }
131
132 static WORD X11DRV_enum_subfont_charset_cp936( UINT index )
133 {
134     switch ( index )
135     {
136     case 0: return ANSI_CHARSET;
137     }
138
139     return DEFAULT_CHARSET;
140 }
141
142 static WORD X11DRV_enum_subfont_charset_cp949( UINT index )
143 {
144     switch ( index )
145     {
146     case 0: return ANSI_CHARSET;
147     }
148
149     return DEFAULT_CHARSET;
150 }
151
152 static WORD X11DRV_enum_subfont_charset_cp950( UINT index )
153 {
154     switch ( index )
155     {
156     case 0: return ANSI_CHARSET;
157     }
158
159     return DEFAULT_CHARSET;
160 }
161
162
163 static XChar2b* X11DRV_unicode_to_char2b_sbcs( fontObject* pfo,
164                                                LPCWSTR lpwstr, UINT count )
165 {
166     XChar2b *str2b;
167     UINT i;
168     char *str;
169     UINT codepage = pfo->fi->codepage;
170     char ch = pfo->fs->default_char;
171
172     if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
173         return NULL;
174     if (!(str = HeapAlloc( GetProcessHeap(), 0, count )))
175     {
176         HeapFree( GetProcessHeap(), 0, str2b );
177         return NULL;
178     }
179
180     WideCharToMultiByte( codepage, 0, lpwstr, count, str, count, &ch, NULL );
181
182     for (i = 0; i < count; i++)
183     {
184         str2b[i].byte1 = 0;
185         str2b[i].byte2 = str[i];
186     }
187     HeapFree( GetProcessHeap(), 0, str );
188
189     return str2b;
190 }
191
192 static XChar2b* X11DRV_unicode_to_char2b_unicode( fontObject* pfo,
193                                                   LPCWSTR lpwstr, UINT count )
194 {
195     XChar2b *str2b;
196     UINT i;
197
198     if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
199         return NULL;
200
201     for (i = 0; i < count; i++)
202     {
203         str2b[i].byte1 = lpwstr[i] >> 8;
204         str2b[i].byte2 = lpwstr[i] & 0xff;
205     }
206
207     return str2b;
208 }
209
210 /* FIXME: handle jisx0212.1990... */
211 static XChar2b* X11DRV_unicode_to_char2b_cp932( fontObject* pfo,
212                                                 LPCWSTR lpwstr, UINT count )
213 {
214     XChar2b *str2b;
215     XChar2b *str2b_dst;
216     char *str;
217     BYTE *str_src;
218     UINT i;
219     char ch = pfo->fs->default_char;
220
221     if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
222         return NULL;
223     if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 )))
224     {
225         HeapFree( GetProcessHeap(), 0, str2b );
226         return NULL;
227     }
228
229     /* handle jisx0212.1990... */
230     WideCharToMultiByte( 932, 0, lpwstr, count, str, count*2, &ch, NULL );
231
232     str_src = (BYTE*) str;
233     str2b_dst = str2b;
234     for (i = 0; i < count; i++, str_src++, str2b_dst++)
235     {
236         if ( IsLegalDBCSChar_cp932( *str_src, *(str_src+1) ) )
237         {
238             DBCSCharToXChar2b_cp932( str2b_dst, *str_src, *(str_src+1) );
239             str_src++;
240         }
241         else
242         {
243             str2b_dst->byte1 = 0;
244             str2b_dst->byte2 = *str_src;
245         }
246     }
247
248     HeapFree( GetProcessHeap(), 0, str );
249
250     return str2b;
251 }
252
253
254 static XChar2b* X11DRV_unicode_to_char2b_cp936( fontObject* pfo,
255                                                 LPCWSTR lpwstr, UINT count )
256 {
257     XChar2b *str2b;
258     XChar2b *str2b_dst;
259     char *str;
260     BYTE *str_src;
261     UINT i;
262     char ch = pfo->fs->default_char;
263
264     if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
265         return NULL;
266     if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 )))
267     {
268         HeapFree( GetProcessHeap(), 0, str2b );
269         return NULL;
270     }
271     WideCharToMultiByte( 936, 0, lpwstr, count, str, count*2, &ch, NULL );
272
273     str_src = (BYTE*) str;
274     str2b_dst = str2b;
275     for (i = 0; i < count; i++, str_src++, str2b_dst++)
276     {
277         if ( IsLegalDBCSChar_cp936( *str_src, *(str_src+1) ) )
278         {
279             str2b_dst->byte1 = *str_src;
280             str2b_dst->byte2 = *(str_src+1);
281             str_src++;
282         }
283         else
284         {
285             str2b_dst->byte1 = 0;
286             str2b_dst->byte2 = *str_src;
287         }
288     }
289
290     HeapFree( GetProcessHeap(), 0, str );
291
292     return str2b;
293 }
294
295 static XChar2b* X11DRV_unicode_to_char2b_cp949( fontObject* pfo,
296                                                 LPCWSTR lpwstr, UINT count )
297 {
298     XChar2b *str2b;
299     XChar2b *str2b_dst;
300     char *str;
301     BYTE *str_src;
302     UINT i;
303     char ch = pfo->fs->default_char;
304
305     if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
306         return NULL;
307     if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 )))
308     {
309         HeapFree( GetProcessHeap(), 0, str2b );
310         return NULL;
311     }
312     WideCharToMultiByte( 949, 0, lpwstr, count, str, count*2, &ch, NULL );
313
314     str_src = (BYTE*) str;
315     str2b_dst = str2b;
316     for (i = 0; i < count; i++, str_src++, str2b_dst++)
317     {
318         if ( IsLegalDBCSChar_cp949( *str_src, *(str_src+1) ) )
319         {
320             str2b_dst->byte1 = *str_src;
321             str2b_dst->byte2 = *(str_src+1);
322             str_src++;
323         }
324         else
325         {
326             str2b_dst->byte1 = 0;
327             str2b_dst->byte2 = *str_src;
328         }
329     }
330
331     HeapFree( GetProcessHeap(), 0, str );
332
333     return str2b;
334 }
335
336
337 static XChar2b* X11DRV_unicode_to_char2b_cp950( fontObject* pfo,
338                                                 LPCWSTR lpwstr, UINT count )
339 {
340     XChar2b *str2b;
341     XChar2b *str2b_dst;
342     char *str;
343     BYTE *str_src;
344     UINT i;
345     char ch = pfo->fs->default_char;
346
347     if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
348         return NULL;
349     if (!(str = HeapAlloc( GetProcessHeap(), 0, count*2 )))
350     {
351         HeapFree( GetProcessHeap(), 0, str2b );
352         return NULL;
353     }
354     WideCharToMultiByte( 950, 0, lpwstr, count, str, count*2, &ch, NULL );
355
356     str_src = (BYTE*) str;
357     str2b_dst = str2b;
358     for (i = 0; i < count; i++, str_src++, str2b_dst++)
359     {
360         if ( IsLegalDBCSChar_cp950( *str_src, *(str_src+1) ) )
361         {
362             str2b_dst->byte1 = *str_src;
363             str2b_dst->byte2 = *(str_src+1);
364             str_src++;
365         }
366         else
367         {
368             str2b_dst->byte1 = 0;
369             str2b_dst->byte2 = *str_src;
370         }
371     }
372
373     HeapFree( GetProcessHeap(), 0, str );
374
375     return str2b;
376 }
377
378 static XChar2b* X11DRV_unicode_to_char2b_symbol( fontObject* pfo,
379                                                  LPCWSTR lpwstr, UINT count )
380 {
381     XChar2b *str2b;
382     UINT i;
383     char ch = pfo->fs->default_char;
384
385     if (!(str2b = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XChar2b) )))
386         return NULL;
387
388     for (i = 0; i < count; i++)
389     {
390         str2b[i].byte1 = 0;
391         if(lpwstr[i] >= 0xf000 && lpwstr[i] < 0xf100)
392             str2b[i].byte2 = lpwstr[i] - 0xf000;
393         else if(lpwstr[i] < 0x100)
394             str2b[i].byte2 = lpwstr[i];
395         else
396             str2b[i].byte2 = ch;
397     }
398
399     return str2b;
400 }
401
402
403 static void X11DRV_DrawString_normal( fontObject* pfo, Display* pdisp,
404                                       Drawable d, GC gc, int x, int y,
405                                       XChar2b* pstr, int count )
406 {
407     wine_tsx11_lock();
408     XDrawString16( pdisp, d, gc, x, y, pstr, count );
409     wine_tsx11_unlock();
410 }
411
412 static int X11DRV_TextWidth_normal( fontObject* pfo, XChar2b* pstr, int count )
413 {
414     int ret;
415     wine_tsx11_lock();
416     ret = XTextWidth16( pfo->fs, pstr, count );
417     wine_tsx11_unlock();
418     return ret;
419 }
420
421 static void X11DRV_DrawText_normal( fontObject* pfo, Display* pdisp, Drawable d,
422                                     GC gc, int x, int y, XTextItem16* pitems,
423                                     int count )
424 {
425     wine_tsx11_lock();
426     XDrawText16( pdisp, d, gc, x, y, pitems, count );
427     wine_tsx11_unlock();
428 }
429
430 static void X11DRV_TextExtents_normal( fontObject* pfo, XChar2b* pstr, int count,
431                                        int* pdir, int* pascent, int* pdescent,
432                                        int* pwidth, int max_extent, int* pfit,
433                                        int* partial_extents )
434 {
435     XCharStruct info;
436     int ascent, descent, width;
437     int i, fit;
438
439     width = 0;
440     fit = 0;
441     *pascent = 0;
442     *pdescent = 0;
443     wine_tsx11_lock();
444     for ( i = 0; i < count; i++ )
445     {
446         XTextExtents16( pfo->fs, pstr, 1, pdir, &ascent, &descent, &info );
447         if ( *pascent < ascent ) *pascent = ascent;
448         if ( *pdescent < descent ) *pdescent = descent;
449         width += info.width;
450         if ( partial_extents ) partial_extents[i] = width;
451         if ( width < max_extent ) fit++;
452
453         pstr++;
454     }
455     wine_tsx11_unlock();
456     *pwidth = width;
457     if ( pfit ) *pfit = fit;
458 }
459
460 static void X11DRV_GetTextMetricsW_normal( fontObject* pfo, LPTEXTMETRICW pTM )
461 {
462     LPIFONTINFO16 pdf = &pfo->fi->df;
463
464     if( ! pfo->lpX11Trans ) {
465       pTM->tmAscent = pfo->fs->ascent;
466       pTM->tmDescent = pfo->fs->descent;
467     } else {
468       pTM->tmAscent = pfo->lpX11Trans->ascent;
469       pTM->tmDescent = pfo->lpX11Trans->descent;
470     }
471
472     pTM->tmAscent *= pfo->rescale;
473     pTM->tmDescent *= pfo->rescale;
474
475     pTM->tmHeight = pTM->tmAscent + pTM->tmDescent;
476
477     pTM->tmAveCharWidth = pfo->foAvgCharWidth * pfo->rescale;
478     pTM->tmMaxCharWidth = pfo->foMaxCharWidth * pfo->rescale;
479
480     pTM->tmInternalLeading = pfo->foInternalLeading * pfo->rescale;
481     pTM->tmExternalLeading = pdf->dfExternalLeading * pfo->rescale;
482
483     pTM->tmStruckOut = (pfo->fo_flags & FO_SYNTH_STRIKEOUT )
484                         ? 1 : pdf->dfStrikeOut;
485     pTM->tmUnderlined = (pfo->fo_flags & FO_SYNTH_UNDERLINE )
486                         ? 1 : pdf->dfUnderline;
487
488     pTM->tmOverhang = 0;
489     if( pfo->fo_flags & FO_SYNTH_ITALIC )
490     {
491         pTM->tmOverhang += pTM->tmHeight/3;
492         pTM->tmItalic = 1;
493     } else
494         pTM->tmItalic = pdf->dfItalic;
495
496     pTM->tmWeight = pdf->dfWeight;
497     if( pfo->fo_flags & FO_SYNTH_BOLD )
498     {
499         pTM->tmOverhang++;
500         pTM->tmWeight += 100;
501     }
502
503     pTM->tmFirstChar = pdf->dfFirstChar;
504     pTM->tmLastChar = pdf->dfLastChar;
505     pTM->tmDefaultChar = pdf->dfDefaultChar;
506     pTM->tmBreakChar = pdf->dfBreakChar;
507
508     pTM->tmCharSet = pdf->dfCharSet;
509     pTM->tmPitchAndFamily = pdf->dfPitchAndFamily;
510
511     pTM->tmDigitizedAspectX = pdf->dfHorizRes;
512     pTM->tmDigitizedAspectY = pdf->dfVertRes;
513 }
514
515
516
517 static
518 void X11DRV_DrawString_dbcs( fontObject* pfo, Display* pdisp,
519                              Drawable d, GC gc, int x, int y,
520                              XChar2b* pstr, int count )
521 {
522     XTextItem16 item;
523
524     item.chars = pstr;
525     item.delta = 0;
526     item.nchars = count;
527     item.font = None;
528     X11DRV_cptable[pfo->fi->cptable].pDrawText(
529                 pfo, pdisp, d, gc, x, y, &item, 1 );
530 }
531
532 static
533 int X11DRV_TextWidth_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count )
534 {
535     int i;
536     int width;
537     int curfont;
538     fontObject* pfos[X11FONT_REFOBJS_MAX+1];
539
540     pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
541     pfos[1] = pfo;
542     if ( pfos[0] == NULL ) pfos[0] = pfo;
543
544     width = 0;
545     wine_tsx11_lock();
546     for ( i = 0; i < count; i++ )
547     {
548         curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
549         width += XTextWidth16( pfos[curfont]->fs, pstr, 1 );
550         pstr ++;
551     }
552     wine_tsx11_unlock();
553     return width;
554 }
555
556 static
557 void X11DRV_DrawText_dbcs_2fonts( fontObject* pfo, Display* pdisp, Drawable d,
558                                   GC gc, int x, int y, XTextItem16* pitems,
559                                   int count )
560 {
561     int i, nitems, prevfont = -1, curfont;
562     XChar2b* pstr;
563     XTextItem16* ptibuf;
564     XTextItem16* pti;
565     fontObject* pfos[X11FONT_REFOBJS_MAX+1];
566
567     pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
568     pfos[1] = pfo;
569     if ( pfos[0] == NULL ) pfos[0] = pfo;
570
571     nitems = 0;
572     for ( i = 0; i < count; i++ )
573         nitems += pitems->nchars;
574     ptibuf = HeapAlloc( GetProcessHeap(), 0, sizeof(XTextItem16) * nitems );
575     if ( ptibuf == NULL )
576         return; /* out of memory */
577
578     pti = ptibuf;
579     while ( count-- > 0 )
580     {
581         pti->chars = pstr = pitems->chars;
582         pti->delta = pitems->delta;
583         pti->font = None;
584         for ( i = 0; i < pitems->nchars; i++, pstr++ )
585         {
586             curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
587             if ( curfont != prevfont )
588             {
589                 if ( pstr != pti->chars )
590                 {
591                     pti->nchars = pstr - pti->chars;
592                     pti ++;
593                     pti->chars = pstr;
594                     pti->delta = 0;
595                 }
596                 pti->font = pfos[curfont]->fs->fid;
597                 prevfont = curfont;
598             }
599         }
600         pti->nchars = pstr - pti->chars;
601         pitems ++; pti ++;
602     }
603     wine_tsx11_lock();
604     XDrawText16( pdisp, d, gc, x, y, ptibuf, pti - ptibuf );
605     wine_tsx11_unlock();
606     HeapFree( GetProcessHeap(), 0, ptibuf );
607 }
608
609 static
610 void X11DRV_TextExtents_dbcs_2fonts( fontObject* pfo, XChar2b* pstr, int count,
611                                      int* pdir, int* pascent, int* pdescent,
612                                      int* pwidth, int max_extent, int* pfit,
613                                      int* partial_extents )
614 {
615     XCharStruct info;
616     int ascent, descent, width;
617     int i;
618     int fit;
619     int curfont;
620     fontObject* pfos[X11FONT_REFOBJS_MAX+1];
621
622     pfos[0] = XFONT_GetFontObject( pfo->prefobjs[0] );
623     pfos[1] = pfo;
624     if ( pfos[0] == NULL ) pfos[0] = pfo;
625
626     width = 0;
627     fit = 0;
628     *pascent = 0;
629     *pdescent = 0;
630     wine_tsx11_lock();
631     for ( i = 0; i < count; i++ )
632     {
633         curfont = ( pstr->byte1 != 0 ) ? 1 : 0;
634         XTextExtents16( pfos[curfont]->fs, pstr, 1, pdir, &ascent, &descent, &info );
635         if ( *pascent < ascent ) *pascent = ascent;
636         if ( *pdescent < descent ) *pdescent = descent;
637         width += info.width;
638         if ( partial_extents ) partial_extents[i] = width;
639         if ( width <= max_extent ) fit++;
640
641         pstr ++;
642     }
643     wine_tsx11_unlock();
644     *pwidth = width;
645     if ( pfit ) *pfit = fit;
646 }
647
648 static void X11DRV_GetTextMetricsW_cp932( fontObject* pfo, LPTEXTMETRICW pTM )
649 {
650     fontObject* pfo_ansi = XFONT_GetFontObject( pfo->prefobjs[0] );
651     LPIFONTINFO16 pdf = &pfo->fi->df;
652     LPIFONTINFO16 pdf_ansi;
653
654     pdf_ansi = ( pfo_ansi != NULL ) ? (&pfo_ansi->fi->df) : pdf;
655
656     if( ! pfo->lpX11Trans ) {
657       pTM->tmAscent = pfo->fs->ascent;
658       pTM->tmDescent = pfo->fs->descent;
659     } else {
660       pTM->tmAscent = pfo->lpX11Trans->ascent;
661       pTM->tmDescent = pfo->lpX11Trans->descent;
662     }
663
664     pTM->tmAscent *= pfo->rescale;
665     pTM->tmDescent *= pfo->rescale;
666
667     pTM->tmHeight = pTM->tmAscent + pTM->tmDescent;
668
669     if ( pfo_ansi != NULL )
670     {
671         pTM->tmAveCharWidth = floor((pfo_ansi->foAvgCharWidth * 2.0 + pfo->foAvgCharWidth) / 3.0 * pfo->rescale + 0.5);
672         pTM->tmMaxCharWidth = max(pfo_ansi->foMaxCharWidth, pfo->foMaxCharWidth) * pfo->rescale;
673     }
674     else
675     {
676         pTM->tmAveCharWidth = floor((pfo->foAvgCharWidth * pfo->rescale + 1.0) / 2.0);
677         pTM->tmMaxCharWidth = pfo->foMaxCharWidth * pfo->rescale;
678     }
679
680     pTM->tmInternalLeading = pfo->foInternalLeading * pfo->rescale;
681     pTM->tmExternalLeading = pdf->dfExternalLeading * pfo->rescale;
682
683     pTM->tmStruckOut = (pfo->fo_flags & FO_SYNTH_STRIKEOUT )
684                         ? 1 : pdf->dfStrikeOut;
685     pTM->tmUnderlined = (pfo->fo_flags & FO_SYNTH_UNDERLINE )
686                         ? 1 : pdf->dfUnderline;
687
688     pTM->tmOverhang = 0;
689     if( pfo->fo_flags & FO_SYNTH_ITALIC )
690     {
691         pTM->tmOverhang += pTM->tmHeight/3;
692         pTM->tmItalic = 1;
693     } else
694         pTM->tmItalic = pdf->dfItalic;
695
696     pTM->tmWeight = pdf->dfWeight;
697     if( pfo->fo_flags & FO_SYNTH_BOLD )
698     {
699         pTM->tmOverhang++;
700         pTM->tmWeight += 100;
701     }
702
703     pTM->tmFirstChar = pdf_ansi->dfFirstChar;
704     pTM->tmLastChar = pdf_ansi->dfLastChar;
705     pTM->tmDefaultChar = pdf_ansi->dfDefaultChar;
706     pTM->tmBreakChar = pdf_ansi->dfBreakChar;
707
708     pTM->tmCharSet = pdf->dfCharSet;
709     pTM->tmPitchAndFamily = pdf->dfPitchAndFamily;
710
711     pTM->tmDigitizedAspectX = pdf->dfHorizRes;
712     pTM->tmDigitizedAspectY = pdf->dfVertRes;
713 }
714
715
716
717
718
719 const X11DRV_CP X11DRV_cptable[X11DRV_CPTABLE_COUNT] =
720 {
721     { /* SBCS */
722         X11DRV_enum_subfont_charset_normal,
723         X11DRV_unicode_to_char2b_sbcs,
724         X11DRV_DrawString_normal,
725         X11DRV_TextWidth_normal,
726         X11DRV_DrawText_normal,
727         X11DRV_TextExtents_normal,
728         X11DRV_GetTextMetricsW_normal,
729     },
730     { /* UNICODE */
731         X11DRV_enum_subfont_charset_normal,
732         X11DRV_unicode_to_char2b_unicode,
733         X11DRV_DrawString_normal,
734         X11DRV_TextWidth_normal,
735         X11DRV_DrawText_normal,
736         X11DRV_TextExtents_normal,
737         X11DRV_GetTextMetricsW_normal,
738     },
739     { /* CP932 */
740         X11DRV_enum_subfont_charset_cp932,
741         X11DRV_unicode_to_char2b_cp932,
742         X11DRV_DrawString_dbcs,
743         X11DRV_TextWidth_dbcs_2fonts,
744         X11DRV_DrawText_dbcs_2fonts,
745         X11DRV_TextExtents_dbcs_2fonts,
746         X11DRV_GetTextMetricsW_cp932,
747     },
748     { /* CP936 */
749         X11DRV_enum_subfont_charset_cp936,
750         X11DRV_unicode_to_char2b_cp936,
751         X11DRV_DrawString_dbcs,
752         X11DRV_TextWidth_dbcs_2fonts,
753         X11DRV_DrawText_dbcs_2fonts,
754         X11DRV_TextExtents_dbcs_2fonts,
755         X11DRV_GetTextMetricsW_normal, /* FIXME */
756     },
757     { /* CP949 */
758         X11DRV_enum_subfont_charset_cp949,
759         X11DRV_unicode_to_char2b_cp949,
760         X11DRV_DrawString_dbcs,
761         X11DRV_TextWidth_dbcs_2fonts,
762         X11DRV_DrawText_dbcs_2fonts,
763         X11DRV_TextExtents_dbcs_2fonts,
764         X11DRV_GetTextMetricsW_normal, /* FIXME */
765     },
766     { /* CP950 */
767         X11DRV_enum_subfont_charset_cp950,
768         X11DRV_unicode_to_char2b_cp950,
769         X11DRV_DrawString_dbcs,
770         X11DRV_TextWidth_dbcs_2fonts,
771         X11DRV_DrawText_dbcs_2fonts,
772         X11DRV_TextExtents_dbcs_2fonts,
773         X11DRV_GetTextMetricsW_cp932,
774     },
775     { /* SYMBOL */
776         X11DRV_enum_subfont_charset_normal,
777         X11DRV_unicode_to_char2b_symbol,
778         X11DRV_DrawString_normal,
779         X11DRV_TextWidth_normal,
780         X11DRV_DrawText_normal,
781         X11DRV_TextExtents_normal,
782         X11DRV_GetTextMetricsW_normal,
783     }
784 };