Release 980215
[wine.git] / objects / font.c
blobb1ac08d5638eb96608a508d2fa20b97b6a25a751
1 /*
2 * GDI font objects
4 * Copyright 1993 Alexandre Julliard
5 * 1997 Alex Korobka
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "font.h"
12 #include "heap.h"
13 #include "metafile.h"
14 #include "options.h"
15 #include "stddebug.h"
16 #include "debug.h"
17 #include "debugstr.h"
19 #define ENUM_UNICODE 0x00000001
21 typedef struct
23 LPLOGFONT16 lpLogFontParam;
24 FONTENUMPROCEX16 lpEnumFunc;
25 LPARAM lpData;
27 LPNEWTEXTMETRICEX16 lpTextMetric;
28 LPENUMLOGFONTEX16 lpLogFont;
29 SEGPTR segTextMetric;
30 SEGPTR segLogFont;
31 } fontEnum16;
33 typedef struct
35 LPLOGFONT32W lpLogFontParam;
36 FONTENUMPROC32W lpEnumFunc;
37 LPARAM lpData;
39 LPNEWTEXTMETRICEX32W lpTextMetric;
40 LPENUMLOGFONTEX32W lpLogFont;
41 DWORD dwFlags;
42 } fontEnum32;
44 /***********************************************************************
45 * LOGFONT conversion functions.
47 static void __logfont32to16( INT16* plf16, const INT32* plf32 )
49 int i;
50 for( i = 0; i < 5; i++ ) *plf16++ = *plf32++;
51 *((INT32*)plf16)++ = *plf32++;
52 *((INT32*)plf16) = *plf32;
55 static void __logfont16to32( INT32* plf32, const INT16* plf16 )
57 int i;
58 for( i = 0; i < 5; i++ ) *plf32++ = *plf16++;
59 *plf32++ = *((INT32*)plf16)++;
60 *plf32 = *((INT32*)plf16);
63 void FONT_LogFont32ATo16( const LOGFONT32A* font32, LPLOGFONT16 font16 )
65 __logfont32to16( (INT16*)font16, (const INT32*)font32 );
66 lstrcpyn32A( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
69 void FONT_LogFont32WTo16( const LOGFONT32W* font32, LPLOGFONT16 font16 )
71 __logfont32to16( (INT16*)font16, (const INT32*)font32 );
72 lstrcpynWtoA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
75 void FONT_LogFont16To32A( const LPLOGFONT16 font16, LPLOGFONT32A font32 )
77 __logfont16to32( (INT32*)font32, (const INT16*)font16 );
78 lstrcpyn32A( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
81 void FONT_LogFont16To32W( const LPLOGFONT16 font16, LPLOGFONT32W font32 )
83 __logfont16to32( (INT32*)font32, (const INT16*)font16 );
84 lstrcpynAtoW( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
87 /***********************************************************************
88 * TEXTMETRIC conversion functions.
90 void FONT_TextMetric32Ato16(const LPTEXTMETRIC32A ptm32, LPTEXTMETRIC16 ptm16 )
92 ptm16->tmHeight = ptm32->tmHeight;
93 ptm16->tmAscent = ptm32->tmAscent;
94 ptm16->tmDescent = ptm32->tmDescent;
95 ptm16->tmInternalLeading = ptm32->tmInternalLeading;
96 ptm16->tmExternalLeading = ptm32->tmExternalLeading;
97 ptm16->tmAveCharWidth = ptm32->tmAveCharWidth;
98 ptm16->tmMaxCharWidth = ptm32->tmMaxCharWidth;
99 ptm16->tmWeight = ptm32->tmWeight;
100 ptm16->tmOverhang = ptm32->tmOverhang;
101 ptm16->tmDigitizedAspectX = ptm32->tmDigitizedAspectX;
102 ptm16->tmDigitizedAspectY = ptm32->tmDigitizedAspectY;
103 ptm16->tmFirstChar = ptm32->tmFirstChar;
104 ptm16->tmLastChar = ptm32->tmLastChar;
105 ptm16->tmDefaultChar = ptm32->tmDefaultChar;
106 ptm16->tmBreakChar = ptm32->tmBreakChar;
107 ptm16->tmItalic = ptm32->tmItalic;
108 ptm16->tmUnderlined = ptm32->tmUnderlined;
109 ptm16->tmStruckOut = ptm32->tmStruckOut;
110 ptm16->tmPitchAndFamily = ptm32->tmPitchAndFamily;
111 ptm16->tmCharSet = ptm32->tmCharSet;
114 void FONT_TextMetric32Wto16(const LPTEXTMETRIC32W ptm32, LPTEXTMETRIC16 ptm16 )
116 ptm16->tmHeight = ptm32->tmHeight;
117 ptm16->tmAscent = ptm32->tmAscent;
118 ptm16->tmDescent = ptm32->tmDescent;
119 ptm16->tmInternalLeading = ptm32->tmInternalLeading;
120 ptm16->tmExternalLeading = ptm32->tmExternalLeading;
121 ptm16->tmAveCharWidth = ptm32->tmAveCharWidth;
122 ptm16->tmMaxCharWidth = ptm32->tmMaxCharWidth;
123 ptm16->tmWeight = ptm32->tmWeight;
124 ptm16->tmOverhang = ptm32->tmOverhang;
125 ptm16->tmDigitizedAspectX = ptm32->tmDigitizedAspectX;
126 ptm16->tmDigitizedAspectY = ptm32->tmDigitizedAspectY;
127 ptm16->tmFirstChar = ptm32->tmFirstChar;
128 ptm16->tmLastChar = ptm32->tmLastChar;
129 ptm16->tmDefaultChar = ptm32->tmDefaultChar;
130 ptm16->tmBreakChar = ptm32->tmBreakChar;
131 ptm16->tmItalic = ptm32->tmItalic;
132 ptm16->tmUnderlined = ptm32->tmUnderlined;
133 ptm16->tmStruckOut = ptm32->tmStruckOut;
134 ptm16->tmPitchAndFamily = ptm32->tmPitchAndFamily;
135 ptm16->tmCharSet = ptm32->tmCharSet;
138 void FONT_TextMetric16to32A(const LPTEXTMETRIC16 ptm16, LPTEXTMETRIC32A ptm32 )
140 ptm32->tmHeight = ptm16->tmHeight;
141 ptm32->tmAscent = ptm16->tmAscent;
142 ptm32->tmDescent = ptm16->tmDescent;
143 ptm32->tmInternalLeading = ptm16->tmInternalLeading;
144 ptm32->tmExternalLeading = ptm16->tmExternalLeading;
145 ptm32->tmAveCharWidth = ptm16->tmAveCharWidth;
146 ptm32->tmMaxCharWidth = ptm16->tmMaxCharWidth;
147 ptm32->tmWeight = ptm16->tmWeight;
148 ptm32->tmOverhang = ptm16->tmOverhang;
149 ptm32->tmDigitizedAspectX = ptm16->tmDigitizedAspectX;
150 ptm32->tmDigitizedAspectY = ptm16->tmDigitizedAspectY;
151 ptm32->tmFirstChar = ptm16->tmFirstChar;
152 ptm32->tmLastChar = ptm16->tmLastChar;
153 ptm32->tmDefaultChar = ptm16->tmDefaultChar;
154 ptm32->tmBreakChar = ptm16->tmBreakChar;
155 ptm32->tmItalic = ptm16->tmItalic;
156 ptm32->tmUnderlined = ptm16->tmUnderlined;
157 ptm32->tmStruckOut = ptm16->tmStruckOut;
158 ptm32->tmPitchAndFamily = ptm16->tmPitchAndFamily;
159 ptm32->tmCharSet = ptm16->tmCharSet;
162 void FONT_TextMetric16to32W(const LPTEXTMETRIC16 ptm16, LPTEXTMETRIC32W ptm32 )
164 ptm32->tmHeight = ptm16->tmHeight;
165 ptm32->tmAscent = ptm16->tmAscent;
166 ptm32->tmDescent = ptm16->tmDescent;
167 ptm32->tmInternalLeading = ptm16->tmInternalLeading;
168 ptm32->tmExternalLeading = ptm16->tmExternalLeading;
169 ptm32->tmAveCharWidth = ptm16->tmAveCharWidth;
170 ptm32->tmMaxCharWidth = ptm16->tmMaxCharWidth;
171 ptm32->tmWeight = ptm16->tmWeight;
172 ptm32->tmOverhang = ptm16->tmOverhang;
173 ptm32->tmDigitizedAspectX = ptm16->tmDigitizedAspectX;
174 ptm32->tmDigitizedAspectY = ptm16->tmDigitizedAspectY;
175 ptm32->tmFirstChar = ptm16->tmFirstChar;
176 ptm32->tmLastChar = ptm16->tmLastChar;
177 ptm32->tmDefaultChar = ptm16->tmDefaultChar;
178 ptm32->tmBreakChar = ptm16->tmBreakChar;
179 ptm32->tmItalic = ptm16->tmItalic;
180 ptm32->tmUnderlined = ptm16->tmUnderlined;
181 ptm32->tmStruckOut = ptm16->tmStruckOut;
182 ptm32->tmPitchAndFamily = ptm16->tmPitchAndFamily;
183 ptm32->tmCharSet = ptm16->tmCharSet;
186 void FONT_TextMetric32Ato32W(const LPTEXTMETRIC32A ptm32A, LPTEXTMETRIC32W ptm32W )
188 ptm32W->tmHeight = ptm32A->tmHeight;
189 ptm32W->tmAscent = ptm32A->tmAscent;
190 ptm32W->tmDescent = ptm32A->tmDescent;
191 ptm32W->tmInternalLeading = ptm32A->tmInternalLeading;
192 ptm32W->tmExternalLeading = ptm32A->tmExternalLeading;
193 ptm32W->tmAveCharWidth = ptm32A->tmAveCharWidth;
194 ptm32W->tmMaxCharWidth = ptm32A->tmMaxCharWidth;
195 ptm32W->tmWeight = ptm32A->tmWeight;
196 ptm32W->tmOverhang = ptm32A->tmOverhang;
197 ptm32W->tmDigitizedAspectX = ptm32A->tmDigitizedAspectX;
198 ptm32W->tmDigitizedAspectY = ptm32A->tmDigitizedAspectY;
199 ptm32W->tmFirstChar = ptm32A->tmFirstChar;
200 ptm32W->tmLastChar = ptm32A->tmLastChar;
201 ptm32W->tmDefaultChar = ptm32A->tmDefaultChar;
202 ptm32W->tmBreakChar = ptm32A->tmBreakChar;
203 ptm32W->tmItalic = ptm32A->tmItalic;
204 ptm32W->tmUnderlined = ptm32A->tmUnderlined;
205 ptm32W->tmStruckOut = ptm32A->tmStruckOut;
206 ptm32W->tmPitchAndFamily = ptm32A->tmPitchAndFamily;
207 ptm32W->tmCharSet = ptm32A->tmCharSet;
210 /***********************************************************************
211 * CreateFontIndirect16 (GDI.57)
213 HFONT16 WINAPI CreateFontIndirect16( const LOGFONT16 *font )
215 HFONT16 hFont = 0;
217 if (font)
219 hFont = GDI_AllocObject( sizeof(FONTOBJ), FONT_MAGIC );
220 if( hFont )
222 FONTOBJ* fontPtr;
223 fontPtr = (FONTOBJ *) GDI_HEAP_LOCK( hFont );
224 memcpy( &fontPtr->logfont, font, sizeof(LOGFONT16) );
226 dprintf_font(stddeb,"CreateFontIndirect(%i %i) '%s' %s %s => %04x\n",
227 font->lfHeight, font->lfWidth,
228 font->lfFaceName ? font->lfFaceName : "NULL",
229 font->lfWeight > 400 ? "Bold" : "",
230 font->lfItalic ? "Italic" : "",
231 hFont);
232 GDI_HEAP_UNLOCK( hFont );
235 else fprintf(stderr,"CreateFontIndirect(NULL) => NULL\n");
237 return hFont;
240 /***********************************************************************
241 * CreateFontIndirect32A (GDI32.44)
243 HFONT32 WINAPI CreateFontIndirect32A( const LOGFONT32A *font )
245 LOGFONT16 font16;
247 FONT_LogFont32ATo16( font, &font16 );
248 return CreateFontIndirect16( &font16 );
251 /***********************************************************************
252 * CreateFontIndirect32W (GDI32.45)
254 HFONT32 WINAPI CreateFontIndirect32W( const LOGFONT32W *font )
256 LOGFONT16 font16;
258 FONT_LogFont32WTo16( font, &font16 );
259 return CreateFontIndirect16( &font16 );
262 /***********************************************************************
263 * CreateFont16 (GDI.56)
265 HFONT16 WINAPI CreateFont16(INT16 height, INT16 width, INT16 esc, INT16 orient,
266 INT16 weight, BYTE italic, BYTE underline,
267 BYTE strikeout, BYTE charset, BYTE outpres,
268 BYTE clippres, BYTE quality, BYTE pitch,
269 LPCSTR name )
271 LOGFONT16 logfont = { height, width, esc, orient, weight, italic, underline,
272 strikeout, charset, outpres, clippres, quality, pitch, };
274 dprintf_font(stddeb,"CreateFont16('%s',%d,%d)\n",
275 (name ? name : "(null)") , height, width);
276 if (name)
277 lstrcpyn32A(logfont.lfFaceName,name,sizeof(logfont.lfFaceName));
278 else
279 logfont.lfFaceName[0] = '\0';
280 return CreateFontIndirect16( &logfont );
283 /*************************************************************************
284 * CreateFont32A (GDI32.43)
286 HFONT32 WINAPI CreateFont32A( INT32 height, INT32 width, INT32 esc,
287 INT32 orient, INT32 weight, DWORD italic,
288 DWORD underline, DWORD strikeout, DWORD charset,
289 DWORD outpres, DWORD clippres, DWORD quality,
290 DWORD pitch, LPCSTR name )
292 return (HFONT32)CreateFont16( height, width, esc, orient, weight, italic,
293 underline, strikeout, charset, outpres,
294 clippres, quality, pitch, name );
297 /*************************************************************************
298 * CreateFont32W (GDI32.46)
300 HFONT32 WINAPI CreateFont32W( INT32 height, INT32 width, INT32 esc,
301 INT32 orient, INT32 weight, DWORD italic,
302 DWORD underline, DWORD strikeout, DWORD charset,
303 DWORD outpres, DWORD clippres, DWORD quality,
304 DWORD pitch, LPCWSTR name )
306 LPSTR namea = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
307 HFONT32 ret = (HFONT32)CreateFont16( height, width, esc, orient, weight,
308 italic, underline, strikeout, charset,
309 outpres, clippres, quality, pitch,
310 namea );
311 if (namea) HeapFree( GetProcessHeap(), 0, namea );
312 return ret;
316 /***********************************************************************
317 * FONT_GetObject16
319 INT16 FONT_GetObject16( FONTOBJ * font, INT16 count, LPSTR buffer )
321 if (count > sizeof(LOGFONT16)) count = sizeof(LOGFONT16);
322 memcpy( buffer, &font->logfont, count );
323 return count;
326 /***********************************************************************
327 * FONT_GetObject32A
329 INT32 FONT_GetObject32A( FONTOBJ *font, INT32 count, LPSTR buffer )
331 LOGFONT32A fnt32;
333 FONT_LogFont16To32A( &font->logfont, &fnt32 );
335 if (count > sizeof(fnt32)) count = sizeof(fnt32);
336 memcpy( buffer, &fnt32, count );
337 return count;
341 /***********************************************************************
342 * FONT_EnumInstance16
344 * Called by the device driver layer to pass font info
345 * down to the application.
347 static INT32 FONT_EnumInstance16( LPENUMLOGFONT16 plf,
348 LPNEWTEXTMETRIC16 ptm, UINT16 fType, LPARAM lp )
350 #define pfe ((fontEnum16*)lp)
351 if( pfe->lpLogFontParam->lfCharSet == DEFAULT_CHARSET ||
352 pfe->lpLogFontParam->lfCharSet == plf->elfLogFont.lfCharSet )
354 memcpy( pfe->lpLogFont, plf, sizeof(ENUMLOGFONT16) );
355 memcpy( pfe->lpTextMetric, ptm, sizeof(NEWTEXTMETRIC16) );
357 return pfe->lpEnumFunc( pfe->segLogFont, pfe->segTextMetric, fType, (LPARAM)(pfe->lpData) );
359 #undef pfe
360 return 1;
363 /***********************************************************************
364 * FONT_EnumInstance32
366 static INT32 FONT_EnumInstance32( LPENUMLOGFONT16 plf,
367 LPNEWTEXTMETRIC16 ptm, UINT16 fType, LPARAM lp )
369 /* lfCharSet is at the same offset in both LOGFONT32A and LOGFONT32W */
371 #define pfe ((fontEnum32*)lp)
372 if( pfe->lpLogFontParam->lfCharSet == DEFAULT_CHARSET ||
373 pfe->lpLogFontParam->lfCharSet == plf->elfLogFont.lfCharSet )
375 /* convert font metrics */
377 if( pfe->dwFlags & ENUM_UNICODE )
379 FONT_LogFont16To32W( &plf->elfLogFont, (LPLOGFONT32W)(pfe->lpLogFont) );
380 FONT_TextMetric16to32W( (LPTEXTMETRIC16)ptm, (LPTEXTMETRIC32W)(pfe->lpTextMetric) );
382 else
384 FONT_LogFont16To32A( &plf->elfLogFont, (LPLOGFONT32A)pfe->lpLogFont );
385 FONT_TextMetric16to32A( (LPTEXTMETRIC16)ptm, (LPTEXTMETRIC32A)pfe->lpTextMetric );
388 return pfe->lpEnumFunc( (LPENUMLOGFONT32W)pfe->lpLogFont,
389 (LPNEWTEXTMETRIC32W)pfe->lpTextMetric, fType, pfe->lpData );
391 #undef pfe
392 return 1;
395 /***********************************************************************
396 * EnumFontFamiliesEx16 (GDI.613)
398 INT16 WINAPI EnumFontFamiliesEx16( HDC16 hDC, LPLOGFONT16 plf,
399 FONTENUMPROCEX16 efproc, LPARAM lParam,
400 DWORD dwFlags)
402 INT16 retVal = 0;
403 DC* dc = (DC*) GDI_GetObjPtr( hDC, DC_MAGIC );
405 if( dc && dc->funcs->pEnumDeviceFonts )
407 LPNEWTEXTMETRICEX16 lptm16 = SEGPTR_ALLOC( sizeof(NEWTEXTMETRICEX16) );
408 if( lptm16 )
410 LPENUMLOGFONTEX16 lplf16 = SEGPTR_ALLOC( sizeof(ENUMLOGFONTEX16) );
411 if( lplf16 )
413 fontEnum16 fe16 = { plf, efproc, lParam, lptm16, lplf16,
414 SEGPTR_GET(lptm16), SEGPTR_GET(lplf16) };
416 retVal = dc->funcs->pEnumDeviceFonts( dc, plf, FONT_EnumInstance16, (LPARAM)&fe16 );
418 SEGPTR_FREE(lplf16);
420 SEGPTR_FREE(lptm16);
423 return retVal;
426 /***********************************************************************
427 * FONT_EnumFontFamiliesEx32
429 static INT32 FONT_EnumFontFamiliesEx32( HDC32 hDC, LPLOGFONT32W plf, FONTENUMPROC32W efproc,
430 LPARAM lParam, DWORD dwUnicode)
432 DC* dc = (DC*) GDI_GetObjPtr( hDC, DC_MAGIC );
434 if( dc && dc->funcs->pEnumDeviceFonts )
436 LOGFONT16 lf16;
437 NEWTEXTMETRICEX32W tm32w;
438 ENUMLOGFONTEX32W lf32w;
439 fontEnum32 fe32 = { plf, efproc, lParam, &tm32w, &lf32w, dwUnicode };
441 /* the only difference between LOGFONT32A and LOGFONT32W is in the lfFaceName */
443 if( plf->lfFaceName[0] )
445 if( dwUnicode )
446 lstrcpynWtoA( lf16.lfFaceName, plf->lfFaceName, LF_FACESIZE );
447 else
448 lstrcpyn32A( lf16.lfFaceName, (LPCSTR)plf->lfFaceName, LF_FACESIZE );
450 else lf16.lfFaceName[0] = '\0';
451 lf16.lfCharSet = plf->lfCharSet;
453 return dc->funcs->pEnumDeviceFonts( dc, &lf16, FONT_EnumInstance32, (LPARAM)&fe32 );
455 return 0;
458 /***********************************************************************
459 * EnumFontFamiliesEx32W (GDI32.82)
461 INT32 WINAPI EnumFontFamiliesEx32W( HDC32 hDC, LPLOGFONT32W plf,
462 FONTENUMPROCEX32W efproc,
463 LPARAM lParam, DWORD dwFlags )
465 return FONT_EnumFontFamiliesEx32( hDC, plf, (FONTENUMPROC32W)efproc,
466 lParam, ENUM_UNICODE );
469 /***********************************************************************
470 * EnumFontFamiliesEx32A (GDI32.81)
472 INT32 WINAPI EnumFontFamiliesEx32A( HDC32 hDC, LPLOGFONT32A plf,
473 FONTENUMPROCEX32A efproc,
474 LPARAM lParam, DWORD dwFlags)
476 return FONT_EnumFontFamiliesEx32( hDC, (LPLOGFONT32W)plf,
477 (FONTENUMPROC32W)efproc, lParam, 0);
480 /***********************************************************************
481 * EnumFontFamilies16 (GDI.330)
483 INT16 WINAPI EnumFontFamilies16( HDC16 hDC, LPCSTR lpFamily,
484 FONTENUMPROC16 efproc, LPARAM lpData )
486 LOGFONT16 lf;
488 lf.lfCharSet = DEFAULT_CHARSET;
489 if( lpFamily ) lstrcpyn32A( lf.lfFaceName, lpFamily, LF_FACESIZE );
490 else lf.lfFaceName[0] = '\0';
492 return EnumFontFamiliesEx16( hDC, &lf, (FONTENUMPROCEX16)efproc, lpData, 0 );
495 /***********************************************************************
496 * EnumFontFamilies32A (GDI32.80)
498 INT32 WINAPI EnumFontFamilies32A( HDC32 hDC, LPCSTR lpFamily,
499 FONTENUMPROC32A efproc, LPARAM lpData )
501 LOGFONT32A lf;
503 lf.lfCharSet = DEFAULT_CHARSET;
504 if( lpFamily ) lstrcpyn32A( lf.lfFaceName, lpFamily, LF_FACESIZE );
505 else lf.lfFaceName[0] = lf.lfFaceName[1] = '\0';
507 return FONT_EnumFontFamiliesEx32( hDC, (LPLOGFONT32W)&lf,
508 (FONTENUMPROC32W)efproc, lpData, 0 );
511 /***********************************************************************
512 * EnumFontFamilies32W (GDI32.83)
514 INT32 WINAPI EnumFontFamilies32W( HDC32 hDC, LPCWSTR lpFamily,
515 FONTENUMPROC32W efproc, LPARAM lpData )
517 LOGFONT32W lf;
519 lf.lfCharSet = DEFAULT_CHARSET;
520 if( lpFamily ) lstrcpyn32W( lf.lfFaceName, lpFamily, LF_FACESIZE );
521 else lf.lfFaceName[0] = 0;
523 return FONT_EnumFontFamiliesEx32( hDC, &lf, efproc, lpData, ENUM_UNICODE );
526 /***********************************************************************
527 * EnumFonts16 (GDI.70)
529 INT16 WINAPI EnumFonts16( HDC16 hDC, LPCSTR lpName, FONTENUMPROC16 efproc,
530 LPARAM lpData )
532 return EnumFontFamilies16( hDC, lpName, (FONTENUMPROCEX16)efproc, lpData );
535 /***********************************************************************
536 * EnumFonts32A (GDI32.84)
538 INT32 WINAPI EnumFonts32A( HDC32 hDC, LPCSTR lpName, FONTENUMPROC32A efproc,
539 LPARAM lpData )
541 return EnumFontFamilies32A( hDC, lpName, efproc, lpData );
544 /***********************************************************************
545 * EnumFonts32W (GDI32.85)
547 INT32 WINAPI EnumFonts32W( HDC32 hDC, LPCWSTR lpName, FONTENUMPROC32W efproc,
548 LPARAM lpData )
550 return EnumFontFamilies32W( hDC, lpName, efproc, lpData );
554 /***********************************************************************
555 * GetTextCharacterExtra16 (GDI.89)
557 INT16 WINAPI GetTextCharacterExtra16( HDC16 hdc )
559 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
560 if (!dc) return 0;
561 return abs( (dc->w.charExtra * dc->wndExtX + dc->vportExtX / 2)
562 / dc->vportExtX );
566 /***********************************************************************
567 * GetTextCharacterExtra32 (GDI32.225)
569 INT32 WINAPI GetTextCharacterExtra32( HDC32 hdc )
571 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
572 if (!dc) return 0;
573 return abs( (dc->w.charExtra * dc->wndExtX + dc->vportExtX / 2)
574 / dc->vportExtX );
578 /***********************************************************************
579 * SetTextCharacterExtra16 (GDI.8)
581 INT16 WINAPI SetTextCharacterExtra16( HDC16 hdc, INT16 extra )
583 return (INT16)SetTextCharacterExtra32( hdc, extra );
587 /***********************************************************************
588 * SetTextCharacterExtra32 (GDI32.337)
590 INT32 WINAPI SetTextCharacterExtra32( HDC32 hdc, INT32 extra )
592 INT32 prev;
593 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
594 if (!dc) return 0;
595 extra = (extra * dc->vportExtX + dc->wndExtX / 2) / dc->wndExtX;
596 prev = dc->w.charExtra;
597 dc->w.charExtra = abs(extra);
598 return (prev * dc->wndExtX + dc->vportExtX / 2) / dc->vportExtX;
602 /***********************************************************************
603 * SetTextJustification16 (GDI.10)
605 INT16 WINAPI SetTextJustification16( HDC16 hdc, INT16 extra, INT16 breaks )
607 return SetTextJustification32( hdc, extra, breaks );
611 /***********************************************************************
612 * SetTextJustification32 (GDI32.339)
614 BOOL32 WINAPI SetTextJustification32( HDC32 hdc, INT32 extra, INT32 breaks )
616 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
617 if (!dc) return 0;
619 extra = abs((extra * dc->vportExtX + dc->wndExtX / 2) / dc->wndExtX);
620 if (!extra) breaks = 0;
621 dc->w.breakTotalExtra = extra;
622 dc->w.breakCount = breaks;
623 if (breaks)
625 dc->w.breakExtra = extra / breaks;
626 dc->w.breakRem = extra - (dc->w.breakCount * dc->w.breakExtra);
628 else
630 dc->w.breakExtra = 0;
631 dc->w.breakRem = 0;
633 return 1;
637 /***********************************************************************
638 * GetTextFace16 (GDI.92)
640 INT16 WINAPI GetTextFace16( HDC16 hdc, INT16 count, LPSTR name )
642 return GetTextFace32A(hdc,count,name);
645 /***********************************************************************
646 * GetTextFace32A (GDI32.234)
648 INT32 WINAPI GetTextFace32A( HDC32 hdc, INT32 count, LPSTR name )
650 FONTOBJ *font;
652 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
653 if (!dc) return 0;
654 if (!(font = (FONTOBJ *) GDI_GetObjPtr( dc->w.hFont, FONT_MAGIC )))
655 return 0;
656 lstrcpyn32A( name, font->logfont.lfFaceName, count );
657 GDI_HEAP_UNLOCK( dc->w.hFont );
658 return strlen(name);
661 /***********************************************************************
662 * GetTextFace32W (GDI32.235)
664 INT32 WINAPI GetTextFace32W( HDC32 hdc, INT32 count, LPWSTR name )
666 LPSTR nameA = HeapAlloc( GetProcessHeap(), 0, count );
667 INT32 res = GetTextFace32A(hdc,count,nameA);
668 lstrcpyAtoW( name, nameA );
669 HeapFree( GetProcessHeap(), 0, nameA );
670 return res;
674 /***********************************************************************
675 * GetTextExtent (GDI.91)
677 DWORD WINAPI GetTextExtent( HDC16 hdc, LPCSTR str, INT16 count )
679 SIZE16 size;
680 if (!GetTextExtentPoint16( hdc, str, count, &size )) return 0;
681 return MAKELONG( size.cx, size.cy );
685 /***********************************************************************
686 * GetTextExtentPoint16 (GDI.471)
688 * FIXME: Should this have a bug for compatibility?
689 * Original Windows versions of GetTextExtentPoint{A,W} have documented
690 * bugs.
692 BOOL16 WINAPI GetTextExtentPoint16( HDC16 hdc, LPCSTR str, INT16 count,
693 LPSIZE16 size )
695 SIZE32 size32;
696 BOOL32 ret = GetTextExtentPoint32A( hdc, str, count, &size32 );
697 CONV_SIZE32TO16( &size32, size );
698 return (BOOL16)ret;
702 /***********************************************************************
703 * GetTextExtentPoint32A (GDI32.230)
705 BOOL32 WINAPI GetTextExtentPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
706 LPSIZE32 size )
708 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
709 if (!dc)
711 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
712 return FALSE;
715 if (!dc->funcs->pGetTextExtentPoint ||
716 !dc->funcs->pGetTextExtentPoint( dc, str, count, size ))
717 return FALSE;
719 dprintf_font(stddeb,"GetTextExtentPoint(%08x %s %d %p): returning %d,%d\n",
720 hdc, debugstr_an (str, count), count,
721 size, size->cx, size->cy );
722 return TRUE;
726 /***********************************************************************
727 * GetTextExtentPoint32W (GDI32.231)
729 BOOL32 WINAPI GetTextExtentPoint32W( HDC32 hdc, LPCWSTR str, INT32 count,
730 LPSIZE32 size )
732 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
733 BOOL32 ret = GetTextExtentPoint32A( hdc, p, count, size );
734 HeapFree( GetProcessHeap(), 0, p );
735 return ret;
739 /***********************************************************************
740 * GetTextExtentPoint32ABuggy (GDI32.232)
742 BOOL32 WINAPI GetTextExtentPoint32ABuggy( HDC32 hdc, LPCSTR str, INT32 count,
743 LPSIZE32 size )
745 dprintf_font( stddeb, "GetTextExtentPoint32ABuggy: not bug compatible.\n");
746 return GetTextExtentPoint32A( hdc, str, count, size );
749 /***********************************************************************
750 * GetTextExtentPoint32WBuggy (GDI32.233)
752 BOOL32 WINAPI GetTextExtentPoint32WBuggy( HDC32 hdc, LPCWSTR str, INT32 count,
753 LPSIZE32 size )
755 dprintf_font( stddeb, "GetTextExtentPoint32WBuggy: not bug compatible.\n");
756 return GetTextExtentPoint32W( hdc, str, count, size );
760 /***********************************************************************
761 * GetTextExtentExPoint32A (GDI32.228)
763 BOOL32 WINAPI GetTextExtentExPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
764 INT32 maxExt, LPINT32 lpnFit,
765 LPINT32 alpDx, LPSIZE32 size )
767 int index, nFit, extent;
768 SIZE32 tSize;
769 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
771 if (!dc)
773 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
774 return FALSE;
776 if (!dc->funcs->pGetTextExtentPoint) return FALSE;
778 size->cx = size->cy = nFit = extent = 0;
779 for(index = 0; index < count; index++)
781 if(!dc->funcs->pGetTextExtentPoint( dc, str, 1, &tSize )) return FALSE;
782 if( extent+tSize.cx < maxExt )
784 extent+=tSize.cx;
785 nFit++;
786 str++;
787 if( alpDx ) alpDx[index] = extent;
788 if( tSize.cy > size->cy ) size->cy = tSize.cy;
790 else break;
792 size->cx = extent;
793 *lpnFit = nFit;
795 dprintf_font(stddeb,"GetTextExtentExPoint32A(%08x '%.*s' %d) returning %d %d %d\n",
796 hdc,count,str,maxExt,nFit, size->cx,size->cy);
797 return TRUE;
801 /***********************************************************************
802 * GetTextExtentExPoint32W (GDI32.229)
805 BOOL32 WINAPI GetTextExtentExPoint32W( HDC32 hdc, LPCWSTR str, INT32 count,
806 INT32 maxExt, LPINT32 lpnFit,
807 LPINT32 alpDx, LPSIZE32 size )
809 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
810 BOOL32 ret = GetTextExtentExPoint32A( hdc, p, count, maxExt,
811 lpnFit, alpDx, size);
812 HeapFree( GetProcessHeap(), 0, p );
813 return ret;
816 /***********************************************************************
817 * GetTextMetrics16 (GDI.93)
819 BOOL16 WINAPI GetTextMetrics16( HDC16 hdc, TEXTMETRIC16 *metrics )
821 TEXTMETRIC32A tm32;
823 if (!GetTextMetrics32A( (HDC32)hdc, &tm32 )) return FALSE;
824 FONT_TextMetric32Ato16( &tm32, metrics );
825 return TRUE;
829 /***********************************************************************
830 * GetTextMetrics32A (GDI32.236)
832 BOOL32 WINAPI GetTextMetrics32A( HDC32 hdc, TEXTMETRIC32A *metrics )
834 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
835 if (!dc)
837 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
838 return FALSE;
841 if (!dc->funcs->pGetTextMetrics ||
842 !dc->funcs->pGetTextMetrics( dc, metrics ))
843 return FALSE;
845 /* device layer returns values in device units
846 * therefore we have to convert them to logical */
848 #define WDPTOLP(x) ((x<0)? \
849 (-abs((x)*dc->wndExtX/dc->vportExtX)): \
850 (abs((x)*dc->wndExtX/dc->vportExtX)))
851 #define HDPTOLP(y) ((y<0)? \
852 (-abs((y)*dc->wndExtY/dc->vportExtY)): \
853 (abs((y)*dc->wndExtY/dc->vportExtY)))
855 metrics->tmHeight = HDPTOLP(metrics->tmHeight);
856 metrics->tmAscent = HDPTOLP(metrics->tmAscent);
857 metrics->tmDescent = HDPTOLP(metrics->tmDescent);
858 metrics->tmInternalLeading = HDPTOLP(metrics->tmInternalLeading);
859 metrics->tmExternalLeading = HDPTOLP(metrics->tmExternalLeading);
860 metrics->tmAveCharWidth = WDPTOLP(metrics->tmAveCharWidth);
861 metrics->tmMaxCharWidth = WDPTOLP(metrics->tmMaxCharWidth);
862 metrics->tmOverhang = WDPTOLP(metrics->tmOverhang);
864 dprintf_font(stddeb,"text metrics:
865 Weight = %03i\t FirstChar = %03i\t AveCharWidth = %i
866 Italic = % 3i\t LastChar = %03i\t\t MaxCharWidth = %i
867 UnderLined = %01i\t DefaultChar = %03i\t Overhang = %i
868 StruckOut = %01i\t BreakChar = %03i\t CharSet = %i
869 PitchAndFamily = %02x
870 --------------------
871 InternalLeading = %i
872 Ascent = %i
873 Descent = %i
874 Height = %i\n",
875 metrics->tmWeight, metrics->tmFirstChar, metrics->tmAveCharWidth,
876 metrics->tmItalic, metrics->tmLastChar, metrics->tmMaxCharWidth,
877 metrics->tmUnderlined, metrics->tmDefaultChar, metrics->tmOverhang,
878 metrics->tmStruckOut, metrics->tmBreakChar, metrics->tmCharSet,
879 metrics->tmPitchAndFamily,
880 metrics->tmInternalLeading,
881 metrics->tmAscent,
882 metrics->tmDescent,
883 metrics->tmHeight );
884 return TRUE;
888 /***********************************************************************
889 * GetTextMetrics32W (GDI32.237)
891 BOOL32 WINAPI GetTextMetrics32W( HDC32 hdc, TEXTMETRIC32W *metrics )
893 TEXTMETRIC32A tm;
894 if (!GetTextMetrics32A( (HDC16)hdc, &tm )) return FALSE;
895 FONT_TextMetric32Ato32W( &tm, metrics );
896 return TRUE;
900 /***********************************************************************
901 * GetCharWidth16 (GDI.350)
903 BOOL16 WINAPI GetCharWidth16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
904 LPINT16 buffer )
906 BOOL32 retVal = FALSE;
908 if( firstChar != lastChar )
910 LPINT32 buf32 = (LPINT32)HeapAlloc(GetProcessHeap(), 0,
911 sizeof(INT32)*(1 + (lastChar - firstChar)));
912 if( buf32 )
914 LPINT32 obuf32 = buf32;
915 int i;
917 retVal = GetCharWidth32A(hdc, firstChar, lastChar, buf32);
918 if (retVal)
920 for (i = firstChar; i <= lastChar; i++)
921 *buffer++ = *buf32++;
923 HeapFree(GetProcessHeap(), 0, obuf32);
926 else /* happens quite often to warrant a special treatment */
928 INT32 chWidth;
929 retVal = GetCharWidth32A(hdc, firstChar, lastChar, &chWidth );
930 *buffer = chWidth;
932 return retVal;
936 /***********************************************************************
937 * GetCharWidth32A (GDI32.155)
939 BOOL32 WINAPI GetCharWidth32A( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
940 LPINT32 buffer )
942 UINT32 i, extra;
943 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
944 if (!dc)
946 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
947 return FALSE;
950 if (!dc->funcs->pGetCharWidth ||
951 !dc->funcs->pGetCharWidth( dc, firstChar, lastChar, buffer))
952 return FALSE;
954 /* convert device units to logical */
956 extra = dc->vportExtX >> 1;
957 for( i = firstChar; i <= lastChar; i++, buffer++ )
958 *buffer = (*buffer * dc->wndExtX + extra) / dc->vportExtX;
960 return TRUE;
964 /***********************************************************************
965 * GetCharWidth32W (GDI32.158)
967 BOOL32 WINAPI GetCharWidth32W( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
968 LPINT32 buffer )
970 return GetCharWidth32A( hdc, firstChar, lastChar, buffer );
975 /* FIXME: all following APIs *******************************************
978 * SetMapperFlags16 (GDI.349)
980 DWORD WINAPI SetMapperFlags16( HDC16 hDC, DWORD dwFlag )
982 return SetMapperFlags32( hDC, dwFlag );
986 /***********************************************************************
987 * SetMapperFlags32 (GDI32.322)
989 DWORD WINAPI SetMapperFlags32( HDC32 hDC, DWORD dwFlag )
991 dprintf_font(stdnimp,"SetMapperFlags(%04x, %08lX) // Empty Stub !\n",
992 hDC, dwFlag);
993 return 0L;
996 /***********************************************************************
997 * GetAspectRatioFilterEx16 (GDI.486)
999 BOOL16 GetAspectRatioFilterEx16( HDC16 hdc, LPVOID pAspectRatio )
1001 dprintf_font(stdnimp,
1002 "GetAspectRatioFilterEx(%04x, %p): // Empty Stub !\n",
1003 hdc, pAspectRatio);
1004 return FALSE;
1008 /***********************************************************************
1009 * GetCharABCWidths16 (GDI.307)
1011 BOOL16 WINAPI GetCharABCWidths16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
1012 LPABC16 abc )
1014 ABC32 abc32;
1015 if (!GetCharABCWidths32A( hdc, firstChar, lastChar, &abc32 )) return FALSE;
1016 abc->abcA = abc32.abcA;
1017 abc->abcB = abc32.abcB;
1018 abc->abcC = abc32.abcC;
1019 return TRUE;
1023 /***********************************************************************
1024 * GetCharABCWidths32A (GDI32.149)
1026 BOOL32 WINAPI GetCharABCWidths32A(HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
1027 LPABC32 abc )
1029 /* No TrueType fonts in Wine so far */
1030 fprintf( stdnimp, "STUB: GetCharABCWidths(%04x,%04x,%04x,%p)\n",
1031 hdc, firstChar, lastChar, abc );
1032 return FALSE;
1036 /***********************************************************************
1037 * GetCharABCWidths32W (GDI32.152)
1039 BOOL32 WINAPI GetCharABCWidths32W(HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
1040 LPABC32 abc )
1042 return GetCharABCWidths32A( hdc, firstChar, lastChar, abc );
1046 /***********************************************************************
1047 * GetGlyphOutline16 (GDI.309)
1049 DWORD WINAPI GetGlyphOutline16( HDC16 hdc, UINT16 uChar, UINT16 fuFormat,
1050 LPGLYPHMETRICS16 lpgm, DWORD cbBuffer,
1051 LPVOID lpBuffer, const MAT2 *lpmat2 )
1053 fprintf( stdnimp,"GetGlyphOutLine16(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
1054 hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
1055 return (DWORD)-1; /* failure */
1059 /***********************************************************************
1060 * GetGlyphOutline32A (GDI32.186)
1062 DWORD WINAPI GetGlyphOutline32A( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
1063 LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
1064 LPVOID lpBuffer, const MAT2 *lpmat2 )
1066 fprintf( stdnimp,"GetGlyphOutLine32A(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
1067 hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
1068 return (DWORD)-1; /* failure */
1071 /***********************************************************************
1072 * GetGlyphOutline32W (GDI32.187)
1074 DWORD WINAPI GetGlyphOutline32W( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
1075 LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
1076 LPVOID lpBuffer, const MAT2 *lpmat2 )
1078 fprintf( stdnimp,"GetGlyphOutLine32W(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
1079 hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
1080 return (DWORD)-1; /* failure */
1083 /***********************************************************************
1084 * CreateScalableFontResource16 (GDI.310)
1086 BOOL16 WINAPI CreateScalableFontResource16( UINT16 fHidden,
1087 LPCSTR lpszResourceFile,
1088 LPCSTR fontFile, LPCSTR path )
1090 return CreateScalableFontResource32A( fHidden, lpszResourceFile,
1091 fontFile, path );
1094 /***********************************************************************
1095 * CreateScalableFontResource32A (GDI32.62)
1097 BOOL32 WINAPI CreateScalableFontResource32A( DWORD fHidden,
1098 LPCSTR lpszResourceFile,
1099 LPCSTR lpszFontFile,
1100 LPCSTR lpszCurrentPath )
1102 /* fHidden=1 - only visible for the calling app, read-only, not
1103 * enumbered with EnumFonts/EnumFontFamilies
1104 * lpszCurrentPath can be NULL
1106 fprintf(stdnimp,"CreateScalableFontResource(%ld,%s,%s,%s) // empty stub\n",
1107 fHidden, lpszResourceFile, lpszFontFile, lpszCurrentPath );
1108 return FALSE; /* create failed */
1111 /***********************************************************************
1112 * CreateScalableFontResource32W (GDI32.63)
1114 BOOL32 WINAPI CreateScalableFontResource32W( DWORD fHidden,
1115 LPCWSTR lpszResourceFile,
1116 LPCWSTR lpszFontFile,
1117 LPCWSTR lpszCurrentPath )
1119 fprintf(stdnimp,"CreateScalableFontResource32W(%ld,%p,%p,%p) // empty stub\n",
1120 fHidden, lpszResourceFile, lpszFontFile, lpszCurrentPath );
1121 return FALSE; /* create failed */
1125 /*************************************************************************
1126 * GetRasterizerCaps16 (GDI.313)
1128 BOOL16 WINAPI GetRasterizerCaps16( LPRASTERIZER_STATUS lprs, UINT16 cbNumBytes)
1130 return GetRasterizerCaps32( lprs, cbNumBytes );
1134 /*************************************************************************
1135 * GetRasterizerCaps32 (GDI32.216)
1137 BOOL32 WINAPI GetRasterizerCaps32( LPRASTERIZER_STATUS lprs, UINT32 cbNumBytes)
1139 lprs->nSize = sizeof(RASTERIZER_STATUS);
1140 lprs->wFlags = TT_AVAILABLE|TT_ENABLED;
1141 lprs->nLanguageID = 0;
1142 return TRUE;
1146 /*************************************************************************
1147 * GetKerningPairs16 (GDI.332)
1149 INT16 WINAPI GetKerningPairs16( HDC16 hDC, INT16 cPairs,
1150 LPKERNINGPAIR16 lpKerningPairs )
1152 /* At this time kerning is ignored (set to 0) */
1153 int i;
1154 fprintf(stdnimp,"GetKerningPairs16: almost empty stub!\n");
1155 for (i = 0; i < cPairs; i++) lpKerningPairs[i].iKernAmount = 0;
1156 return 0;
1161 /*************************************************************************
1162 * GetKerningPairs32A (GDI32.192)
1164 DWORD WINAPI GetKerningPairs32A( HDC32 hDC, DWORD cPairs,
1165 LPKERNINGPAIR32 lpKerningPairs )
1167 int i;
1168 fprintf(stdnimp,"GetKerningPairs32: almost empty stub!\n");
1169 for (i = 0; i < cPairs; i++) lpKerningPairs[i].iKernAmount = 0;
1170 return 0;
1174 /*************************************************************************
1175 * GetKerningPairs32W (GDI32.193)
1177 DWORD WINAPI GetKerningPairs32W( HDC32 hDC, DWORD cPairs,
1178 LPKERNINGPAIR32 lpKerningPairs )
1180 return GetKerningPairs32A( hDC, cPairs, lpKerningPairs );
1183 BOOL32 WINAPI TranslateCharSetInfo(LPDWORD lpSrc,LPCHARSETINFO lpCs,DWORD dwFlags) {
1184 fprintf(stderr,"TranslateCharSetInfo(%p,%p,0x%08lx), stub.\n",
1185 lpSrc,lpCs,dwFlags
1187 return TRUE;
1191 /*************************************************************************
1192 * GetFontLanguageInfo (GDI32.182)
1194 DWORD WINAPI GetFontLanguageInfo32(HDC32 hdc) {
1195 /* return value 0 is correct for most cases anyway */
1196 fprintf(stderr,"GetFontLanguageInfo:stub!\n");
1197 return 0;
1200 /*************************************************************************
1201 * GetFontLanguageInfo (GDI.616)
1203 DWORD WINAPI GetFontLanguageInfo16(HDC16 hdc) {
1204 /* return value 0 is correct for most cases anyway */
1205 fprintf(stderr,"GetFontLanguageInfo:stub!\n");
1206 return 0;