4 * Copyright 1993 Alexandre Julliard
16 #define ENUM_UNICODE 0x00000001
20 LPLOGFONT16 lpLogFontParam;
21 FONTENUMPROCEX16 lpEnumFunc;
24 LPNEWTEXTMETRICEX16 lpTextMetric;
25 LPENUMLOGFONTEX16 lpLogFont;
32 LPLOGFONT32W lpLogFontParam;
33 FONTENUMPROC32W lpEnumFunc;
36 LPNEWTEXTMETRICEX32W lpTextMetric;
37 LPENUMLOGFONTEX32W lpLogFont;
41 /***********************************************************************
42 * LOGFONT conversion functions.
44 static void __logfont32to16( INT16* plf16, const INT32* plf32 )
47 for( i = 0; i < 5; i++ ) *plf16++ = *plf32++;
48 *((INT32*)plf16)++ = *plf32++;
49 *((INT32*)plf16) = *plf32;
52 static void __logfont16to32( INT32* plf32, const INT16* plf16 )
55 for( i = 0; i < 5; i++ ) *plf32++ = *plf16++;
56 *plf32++ = *((INT32*)plf16)++;
57 *plf32 = *((INT32*)plf16);
60 void FONT_LogFont32ATo16( const LOGFONT32A* font32, LPLOGFONT16 font16 )
62 __logfont32to16( (INT16*)font16, (const INT32*)font32 );
63 lstrcpyn32A( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
66 void FONT_LogFont32WTo16( const LOGFONT32W* font32, LPLOGFONT16 font16 )
68 __logfont32to16( (INT16*)font16, (const INT32*)font32 );
69 lstrcpynWtoA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
72 void FONT_LogFont16To32A( const LPLOGFONT16 font16, LPLOGFONT32A font32 )
74 __logfont16to32( (INT32*)font32, (const INT16*)font16 );
75 lstrcpyn32A( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
78 void FONT_LogFont16To32W( const LPLOGFONT16 font16, LPLOGFONT32W font32 )
80 __logfont16to32( (INT32*)font32, (const INT16*)font16 );
81 lstrcpynAtoW( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
84 /***********************************************************************
85 * TEXTMETRIC conversion functions.
87 void FONT_TextMetric32Ato16(const LPTEXTMETRIC32A ptm32, LPTEXTMETRIC16 ptm16 )
89 ptm16->tmHeight = ptm32->tmHeight;
90 ptm16->tmAscent = ptm32->tmAscent;
91 ptm16->tmDescent = ptm32->tmDescent;
92 ptm16->tmInternalLeading = ptm32->tmInternalLeading;
93 ptm16->tmExternalLeading = ptm32->tmExternalLeading;
94 ptm16->tmAveCharWidth = ptm32->tmAveCharWidth;
95 ptm16->tmMaxCharWidth = ptm32->tmMaxCharWidth;
96 ptm16->tmWeight = ptm32->tmWeight;
97 ptm16->tmOverhang = ptm32->tmOverhang;
98 ptm16->tmDigitizedAspectX = ptm32->tmDigitizedAspectX;
99 ptm16->tmDigitizedAspectY = ptm32->tmDigitizedAspectY;
100 ptm16->tmFirstChar = ptm32->tmFirstChar;
101 ptm16->tmLastChar = ptm32->tmLastChar;
102 ptm16->tmDefaultChar = ptm32->tmDefaultChar;
103 ptm16->tmBreakChar = ptm32->tmBreakChar;
104 ptm16->tmItalic = ptm32->tmItalic;
105 ptm16->tmUnderlined = ptm32->tmUnderlined;
106 ptm16->tmStruckOut = ptm32->tmStruckOut;
107 ptm16->tmPitchAndFamily = ptm32->tmPitchAndFamily;
108 ptm16->tmCharSet = ptm32->tmCharSet;
111 void FONT_TextMetric32Wto16(const LPTEXTMETRIC32W ptm32, LPTEXTMETRIC16 ptm16 )
113 ptm16->tmHeight = ptm32->tmHeight;
114 ptm16->tmAscent = ptm32->tmAscent;
115 ptm16->tmDescent = ptm32->tmDescent;
116 ptm16->tmInternalLeading = ptm32->tmInternalLeading;
117 ptm16->tmExternalLeading = ptm32->tmExternalLeading;
118 ptm16->tmAveCharWidth = ptm32->tmAveCharWidth;
119 ptm16->tmMaxCharWidth = ptm32->tmMaxCharWidth;
120 ptm16->tmWeight = ptm32->tmWeight;
121 ptm16->tmOverhang = ptm32->tmOverhang;
122 ptm16->tmDigitizedAspectX = ptm32->tmDigitizedAspectX;
123 ptm16->tmDigitizedAspectY = ptm32->tmDigitizedAspectY;
124 ptm16->tmFirstChar = ptm32->tmFirstChar;
125 ptm16->tmLastChar = ptm32->tmLastChar;
126 ptm16->tmDefaultChar = ptm32->tmDefaultChar;
127 ptm16->tmBreakChar = ptm32->tmBreakChar;
128 ptm16->tmItalic = ptm32->tmItalic;
129 ptm16->tmUnderlined = ptm32->tmUnderlined;
130 ptm16->tmStruckOut = ptm32->tmStruckOut;
131 ptm16->tmPitchAndFamily = ptm32->tmPitchAndFamily;
132 ptm16->tmCharSet = ptm32->tmCharSet;
135 void FONT_TextMetric16to32A(const LPTEXTMETRIC16 ptm16, LPTEXTMETRIC32A ptm32 )
137 ptm32->tmHeight = ptm16->tmHeight;
138 ptm32->tmAscent = ptm16->tmAscent;
139 ptm32->tmDescent = ptm16->tmDescent;
140 ptm32->tmInternalLeading = ptm16->tmInternalLeading;
141 ptm32->tmExternalLeading = ptm16->tmExternalLeading;
142 ptm32->tmAveCharWidth = ptm16->tmAveCharWidth;
143 ptm32->tmMaxCharWidth = ptm16->tmMaxCharWidth;
144 ptm32->tmWeight = ptm16->tmWeight;
145 ptm32->tmOverhang = ptm16->tmOverhang;
146 ptm32->tmDigitizedAspectX = ptm16->tmDigitizedAspectX;
147 ptm32->tmDigitizedAspectY = ptm16->tmDigitizedAspectY;
148 ptm32->tmFirstChar = ptm16->tmFirstChar;
149 ptm32->tmLastChar = ptm16->tmLastChar;
150 ptm32->tmDefaultChar = ptm16->tmDefaultChar;
151 ptm32->tmBreakChar = ptm16->tmBreakChar;
152 ptm32->tmItalic = ptm16->tmItalic;
153 ptm32->tmUnderlined = ptm16->tmUnderlined;
154 ptm32->tmStruckOut = ptm16->tmStruckOut;
155 ptm32->tmPitchAndFamily = ptm16->tmPitchAndFamily;
156 ptm32->tmCharSet = ptm16->tmCharSet;
159 void FONT_TextMetric16to32W(const LPTEXTMETRIC16 ptm16, LPTEXTMETRIC32W ptm32 )
161 ptm32->tmHeight = ptm16->tmHeight;
162 ptm32->tmAscent = ptm16->tmAscent;
163 ptm32->tmDescent = ptm16->tmDescent;
164 ptm32->tmInternalLeading = ptm16->tmInternalLeading;
165 ptm32->tmExternalLeading = ptm16->tmExternalLeading;
166 ptm32->tmAveCharWidth = ptm16->tmAveCharWidth;
167 ptm32->tmMaxCharWidth = ptm16->tmMaxCharWidth;
168 ptm32->tmWeight = ptm16->tmWeight;
169 ptm32->tmOverhang = ptm16->tmOverhang;
170 ptm32->tmDigitizedAspectX = ptm16->tmDigitizedAspectX;
171 ptm32->tmDigitizedAspectY = ptm16->tmDigitizedAspectY;
172 ptm32->tmFirstChar = ptm16->tmFirstChar;
173 ptm32->tmLastChar = ptm16->tmLastChar;
174 ptm32->tmDefaultChar = ptm16->tmDefaultChar;
175 ptm32->tmBreakChar = ptm16->tmBreakChar;
176 ptm32->tmItalic = ptm16->tmItalic;
177 ptm32->tmUnderlined = ptm16->tmUnderlined;
178 ptm32->tmStruckOut = ptm16->tmStruckOut;
179 ptm32->tmPitchAndFamily = ptm16->tmPitchAndFamily;
180 ptm32->tmCharSet = ptm16->tmCharSet;
183 void FONT_TextMetric32Ato32W(const LPTEXTMETRIC32A ptm32A, LPTEXTMETRIC32W ptm32W )
185 ptm32W->tmHeight = ptm32A->tmHeight;
186 ptm32W->tmAscent = ptm32A->tmAscent;
187 ptm32W->tmDescent = ptm32A->tmDescent;
188 ptm32W->tmInternalLeading = ptm32A->tmInternalLeading;
189 ptm32W->tmExternalLeading = ptm32A->tmExternalLeading;
190 ptm32W->tmAveCharWidth = ptm32A->tmAveCharWidth;
191 ptm32W->tmMaxCharWidth = ptm32A->tmMaxCharWidth;
192 ptm32W->tmWeight = ptm32A->tmWeight;
193 ptm32W->tmOverhang = ptm32A->tmOverhang;
194 ptm32W->tmDigitizedAspectX = ptm32A->tmDigitizedAspectX;
195 ptm32W->tmDigitizedAspectY = ptm32A->tmDigitizedAspectY;
196 ptm32W->tmFirstChar = ptm32A->tmFirstChar;
197 ptm32W->tmLastChar = ptm32A->tmLastChar;
198 ptm32W->tmDefaultChar = ptm32A->tmDefaultChar;
199 ptm32W->tmBreakChar = ptm32A->tmBreakChar;
200 ptm32W->tmItalic = ptm32A->tmItalic;
201 ptm32W->tmUnderlined = ptm32A->tmUnderlined;
202 ptm32W->tmStruckOut = ptm32A->tmStruckOut;
203 ptm32W->tmPitchAndFamily = ptm32A->tmPitchAndFamily;
204 ptm32W->tmCharSet = ptm32A->tmCharSet;
207 /***********************************************************************
208 * CreateFontIndirect16 (GDI.57)
210 HFONT16 WINAPI CreateFontIndirect16( const LOGFONT16 *font )
216 hFont = GDI_AllocObject( sizeof(FONTOBJ), FONT_MAGIC );
220 fontPtr = (FONTOBJ *) GDI_HEAP_LOCK( hFont );
221 memcpy( &fontPtr->logfont, font, sizeof(LOGFONT16) );
223 TRACE(font,"(%i %i %i %i) '%s' %s %s => %04x\n",
224 font->lfHeight, font->lfWidth,
225 font->lfEscapement, font->lfOrientation,
226 font->lfFaceName ? font->lfFaceName : "NULL",
227 font->lfWeight > 400 ? "Bold" : "",
228 font->lfItalic ? "Italic" : "",
231 if (font->lfEscapement != font->lfOrientation) {
232 /* this should really depend on whether GM_ADVANCED is set */
233 fontPtr->logfont.lfOrientation = fontPtr->logfont.lfEscapement;
235 "orientation angle %f set to escapement angle %f for new font %04x\n",
236 font->lfOrientation/10., font->lfEscapement/10., hFont);
238 GDI_HEAP_UNLOCK( hFont );
241 else WARN(font,"(NULL) => NULL\n");
246 /***********************************************************************
247 * CreateFontIndirect32A (GDI32.44)
249 HFONT32 WINAPI CreateFontIndirect32A( const LOGFONT32A *font )
253 FONT_LogFont32ATo16( font, &font16 );
254 return CreateFontIndirect16( &font16 );
257 /***********************************************************************
258 * CreateFontIndirect32W (GDI32.45)
260 HFONT32 WINAPI CreateFontIndirect32W( const LOGFONT32W *font )
264 FONT_LogFont32WTo16( font, &font16 );
265 return CreateFontIndirect16( &font16 );
268 /***********************************************************************
269 * CreateFont16 (GDI.56)
271 HFONT16 WINAPI CreateFont16(INT16 height, INT16 width, INT16 esc, INT16 orient,
272 INT16 weight, BYTE italic, BYTE underline,
273 BYTE strikeout, BYTE charset, BYTE outpres,
274 BYTE clippres, BYTE quality, BYTE pitch,
277 LOGFONT16 logfont = { height, width, esc, orient, weight, italic, underline,
278 strikeout, charset, outpres, clippres, quality, pitch, };
280 TRACE(font,"('%s',%d,%d)\n",
281 (name ? name : "(null)") , height, width);
283 lstrcpyn32A(logfont.lfFaceName,name,sizeof(logfont.lfFaceName));
285 logfont.lfFaceName[0] = '\0';
286 return CreateFontIndirect16( &logfont );
289 /*************************************************************************
290 * CreateFont32A (GDI32.43)
292 HFONT32 WINAPI CreateFont32A( INT32 height, INT32 width, INT32 esc,
293 INT32 orient, INT32 weight, DWORD italic,
294 DWORD underline, DWORD strikeout, DWORD charset,
295 DWORD outpres, DWORD clippres, DWORD quality,
296 DWORD pitch, LPCSTR name )
298 return (HFONT32)CreateFont16( height, width, esc, orient, weight, italic,
299 underline, strikeout, charset, outpres,
300 clippres, quality, pitch, name );
303 /*************************************************************************
304 * CreateFont32W (GDI32.46)
306 HFONT32 WINAPI CreateFont32W( INT32 height, INT32 width, INT32 esc,
307 INT32 orient, INT32 weight, DWORD italic,
308 DWORD underline, DWORD strikeout, DWORD charset,
309 DWORD outpres, DWORD clippres, DWORD quality,
310 DWORD pitch, LPCWSTR name )
312 LPSTR namea = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
313 HFONT32 ret = (HFONT32)CreateFont16( height, width, esc, orient, weight,
314 italic, underline, strikeout, charset,
315 outpres, clippres, quality, pitch,
317 if (namea) HeapFree( GetProcessHeap(), 0, namea );
322 /***********************************************************************
325 INT16 FONT_GetObject16( FONTOBJ * font, INT16 count, LPSTR buffer )
327 if (count > sizeof(LOGFONT16)) count = sizeof(LOGFONT16);
328 memcpy( buffer, &font->logfont, count );
332 /***********************************************************************
335 INT32 FONT_GetObject32A( FONTOBJ *font, INT32 count, LPSTR buffer )
339 FONT_LogFont16To32A( &font->logfont, &fnt32 );
341 if (count > sizeof(fnt32)) count = sizeof(fnt32);
342 memcpy( buffer, &fnt32, count );
347 /***********************************************************************
348 * FONT_EnumInstance16
350 * Called by the device driver layer to pass font info
351 * down to the application.
353 static INT32 FONT_EnumInstance16( LPENUMLOGFONT16 plf,
354 LPNEWTEXTMETRIC16 ptm, UINT16 fType, LPARAM lp )
356 #define pfe ((fontEnum16*)lp)
357 if( pfe->lpLogFontParam->lfCharSet == DEFAULT_CHARSET ||
358 pfe->lpLogFontParam->lfCharSet == plf->elfLogFont.lfCharSet )
360 memcpy( pfe->lpLogFont, plf, sizeof(ENUMLOGFONT16) );
361 memcpy( pfe->lpTextMetric, ptm, sizeof(NEWTEXTMETRIC16) );
363 return pfe->lpEnumFunc( pfe->segLogFont, pfe->segTextMetric, fType, (LPARAM)(pfe->lpData) );
369 /***********************************************************************
370 * FONT_EnumInstance32
372 static INT32 FONT_EnumInstance32( LPENUMLOGFONT16 plf,
373 LPNEWTEXTMETRIC16 ptm, UINT16 fType, LPARAM lp )
375 /* lfCharSet is at the same offset in both LOGFONT32A and LOGFONT32W */
377 #define pfe ((fontEnum32*)lp)
378 if( pfe->lpLogFontParam->lfCharSet == DEFAULT_CHARSET ||
379 pfe->lpLogFontParam->lfCharSet == plf->elfLogFont.lfCharSet )
381 /* convert font metrics */
383 if( pfe->dwFlags & ENUM_UNICODE )
385 FONT_LogFont16To32W( &plf->elfLogFont, (LPLOGFONT32W)(pfe->lpLogFont) );
386 FONT_TextMetric16to32W( (LPTEXTMETRIC16)ptm, (LPTEXTMETRIC32W)(pfe->lpTextMetric) );
390 FONT_LogFont16To32A( &plf->elfLogFont, (LPLOGFONT32A)pfe->lpLogFont );
391 FONT_TextMetric16to32A( (LPTEXTMETRIC16)ptm, (LPTEXTMETRIC32A)pfe->lpTextMetric );
394 return pfe->lpEnumFunc( (LPENUMLOGFONT32W)pfe->lpLogFont,
395 (LPNEWTEXTMETRIC32W)pfe->lpTextMetric, fType, pfe->lpData );
401 /***********************************************************************
402 * EnumFontFamiliesEx16 (GDI.613)
404 INT16 WINAPI EnumFontFamiliesEx16( HDC16 hDC, LPLOGFONT16 plf,
405 FONTENUMPROCEX16 efproc, LPARAM lParam,
409 DC* dc = (DC*) GDI_GetObjPtr( hDC, DC_MAGIC );
411 if( dc && dc->funcs->pEnumDeviceFonts )
413 LPNEWTEXTMETRICEX16 lptm16 = SEGPTR_ALLOC( sizeof(NEWTEXTMETRICEX16) );
416 LPENUMLOGFONTEX16 lplf16 = SEGPTR_ALLOC( sizeof(ENUMLOGFONTEX16) );
419 fontEnum16 fe16 = { plf, efproc, lParam, lptm16, lplf16,
420 SEGPTR_GET(lptm16), SEGPTR_GET(lplf16) };
422 retVal = dc->funcs->pEnumDeviceFonts( dc, plf, FONT_EnumInstance16, (LPARAM)&fe16 );
432 /***********************************************************************
433 * FONT_EnumFontFamiliesEx32
435 static INT32 FONT_EnumFontFamiliesEx32( HDC32 hDC, LPLOGFONT32W plf, FONTENUMPROC32W efproc,
436 LPARAM lParam, DWORD dwUnicode)
438 DC* dc = (DC*) GDI_GetObjPtr( hDC, DC_MAGIC );
440 if( dc && dc->funcs->pEnumDeviceFonts )
443 NEWTEXTMETRICEX32W tm32w;
444 ENUMLOGFONTEX32W lf32w;
445 fontEnum32 fe32 = { plf, efproc, lParam, &tm32w, &lf32w, dwUnicode };
447 /* the only difference between LOGFONT32A and LOGFONT32W is in the lfFaceName */
449 if( plf->lfFaceName[0] )
452 lstrcpynWtoA( lf16.lfFaceName, plf->lfFaceName, LF_FACESIZE );
454 lstrcpyn32A( lf16.lfFaceName, (LPCSTR)plf->lfFaceName, LF_FACESIZE );
456 else lf16.lfFaceName[0] = '\0';
457 lf16.lfCharSet = plf->lfCharSet;
459 return dc->funcs->pEnumDeviceFonts( dc, &lf16, FONT_EnumInstance32, (LPARAM)&fe32 );
464 /***********************************************************************
465 * EnumFontFamiliesEx32W (GDI32.82)
467 INT32 WINAPI EnumFontFamiliesEx32W( HDC32 hDC, LPLOGFONT32W plf,
468 FONTENUMPROCEX32W efproc,
469 LPARAM lParam, DWORD dwFlags )
471 return FONT_EnumFontFamiliesEx32( hDC, plf, (FONTENUMPROC32W)efproc,
472 lParam, ENUM_UNICODE );
475 /***********************************************************************
476 * EnumFontFamiliesEx32A (GDI32.81)
478 INT32 WINAPI EnumFontFamiliesEx32A( HDC32 hDC, LPLOGFONT32A plf,
479 FONTENUMPROCEX32A efproc,
480 LPARAM lParam, DWORD dwFlags)
482 return FONT_EnumFontFamiliesEx32( hDC, (LPLOGFONT32W)plf,
483 (FONTENUMPROC32W)efproc, lParam, 0);
486 /***********************************************************************
487 * EnumFontFamilies16 (GDI.330)
489 INT16 WINAPI EnumFontFamilies16( HDC16 hDC, LPCSTR lpFamily,
490 FONTENUMPROC16 efproc, LPARAM lpData )
494 lf.lfCharSet = DEFAULT_CHARSET;
495 if( lpFamily ) lstrcpyn32A( lf.lfFaceName, lpFamily, LF_FACESIZE );
496 else lf.lfFaceName[0] = '\0';
498 return EnumFontFamiliesEx16( hDC, &lf, (FONTENUMPROCEX16)efproc, lpData, 0 );
501 /***********************************************************************
502 * EnumFontFamilies32A (GDI32.80)
504 INT32 WINAPI EnumFontFamilies32A( HDC32 hDC, LPCSTR lpFamily,
505 FONTENUMPROC32A efproc, LPARAM lpData )
509 lf.lfCharSet = DEFAULT_CHARSET;
510 if( lpFamily ) lstrcpyn32A( lf.lfFaceName, lpFamily, LF_FACESIZE );
511 else lf.lfFaceName[0] = lf.lfFaceName[1] = '\0';
513 return FONT_EnumFontFamiliesEx32( hDC, (LPLOGFONT32W)&lf,
514 (FONTENUMPROC32W)efproc, lpData, 0 );
517 /***********************************************************************
518 * EnumFontFamilies32W (GDI32.83)
520 INT32 WINAPI EnumFontFamilies32W( HDC32 hDC, LPCWSTR lpFamily,
521 FONTENUMPROC32W efproc, LPARAM lpData )
525 lf.lfCharSet = DEFAULT_CHARSET;
526 if( lpFamily ) lstrcpyn32W( lf.lfFaceName, lpFamily, LF_FACESIZE );
527 else lf.lfFaceName[0] = 0;
529 return FONT_EnumFontFamiliesEx32( hDC, &lf, efproc, lpData, ENUM_UNICODE );
532 /***********************************************************************
533 * EnumFonts16 (GDI.70)
535 INT16 WINAPI EnumFonts16( HDC16 hDC, LPCSTR lpName, FONTENUMPROC16 efproc,
538 return EnumFontFamilies16( hDC, lpName, (FONTENUMPROCEX16)efproc, lpData );
541 /***********************************************************************
542 * EnumFonts32A (GDI32.84)
544 INT32 WINAPI EnumFonts32A( HDC32 hDC, LPCSTR lpName, FONTENUMPROC32A efproc,
547 return EnumFontFamilies32A( hDC, lpName, efproc, lpData );
550 /***********************************************************************
551 * EnumFonts32W (GDI32.85)
553 INT32 WINAPI EnumFonts32W( HDC32 hDC, LPCWSTR lpName, FONTENUMPROC32W efproc,
556 return EnumFontFamilies32W( hDC, lpName, efproc, lpData );
560 /***********************************************************************
561 * GetTextCharacterExtra16 (GDI.89)
563 INT16 WINAPI GetTextCharacterExtra16( HDC16 hdc )
565 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
567 return abs( (dc->w.charExtra * dc->wndExtX + dc->vportExtX / 2)
572 /***********************************************************************
573 * GetTextCharacterExtra32 (GDI32.225)
575 INT32 WINAPI GetTextCharacterExtra32( HDC32 hdc )
577 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
579 return abs( (dc->w.charExtra * dc->wndExtX + dc->vportExtX / 2)
584 /***********************************************************************
585 * SetTextCharacterExtra16 (GDI.8)
587 INT16 WINAPI SetTextCharacterExtra16( HDC16 hdc, INT16 extra )
589 return (INT16)SetTextCharacterExtra32( hdc, extra );
593 /***********************************************************************
594 * SetTextCharacterExtra32 (GDI32.337)
596 INT32 WINAPI SetTextCharacterExtra32( HDC32 hdc, INT32 extra )
599 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
601 extra = (extra * dc->vportExtX + dc->wndExtX / 2) / dc->wndExtX;
602 prev = dc->w.charExtra;
603 dc->w.charExtra = abs(extra);
604 return (prev * dc->wndExtX + dc->vportExtX / 2) / dc->vportExtX;
608 /***********************************************************************
609 * SetTextJustification16 (GDI.10)
611 INT16 WINAPI SetTextJustification16( HDC16 hdc, INT16 extra, INT16 breaks )
613 return SetTextJustification32( hdc, extra, breaks );
617 /***********************************************************************
618 * SetTextJustification32 (GDI32.339)
620 BOOL32 WINAPI SetTextJustification32( HDC32 hdc, INT32 extra, INT32 breaks )
622 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
625 extra = abs((extra * dc->vportExtX + dc->wndExtX / 2) / dc->wndExtX);
626 if (!extra) breaks = 0;
627 dc->w.breakTotalExtra = extra;
628 dc->w.breakCount = breaks;
631 dc->w.breakExtra = extra / breaks;
632 dc->w.breakRem = extra - (dc->w.breakCount * dc->w.breakExtra);
636 dc->w.breakExtra = 0;
643 /***********************************************************************
644 * GetTextFace16 (GDI.92)
646 INT16 WINAPI GetTextFace16( HDC16 hdc, INT16 count, LPSTR name )
648 return GetTextFace32A(hdc,count,name);
651 /***********************************************************************
652 * GetTextFace32A (GDI32.234)
654 INT32 WINAPI GetTextFace32A( HDC32 hdc, INT32 count, LPSTR name )
658 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
660 if (!(font = (FONTOBJ *) GDI_GetObjPtr( dc->w.hFont, FONT_MAGIC )))
662 lstrcpyn32A( name, font->logfont.lfFaceName, count );
663 GDI_HEAP_UNLOCK( dc->w.hFont );
667 /***********************************************************************
668 * GetTextFace32W (GDI32.235)
670 INT32 WINAPI GetTextFace32W( HDC32 hdc, INT32 count, LPWSTR name )
672 LPSTR nameA = HeapAlloc( GetProcessHeap(), 0, count );
673 INT32 res = GetTextFace32A(hdc,count,nameA);
674 lstrcpyAtoW( name, nameA );
675 HeapFree( GetProcessHeap(), 0, nameA );
680 /***********************************************************************
681 * GetTextExtent (GDI.91)
683 DWORD WINAPI GetTextExtent( HDC16 hdc, LPCSTR str, INT16 count )
686 if (!GetTextExtentPoint16( hdc, str, count, &size )) return 0;
687 return MAKELONG( size.cx, size.cy );
691 /***********************************************************************
692 * GetTextExtentPoint16 (GDI.471)
694 * FIXME: Should this have a bug for compatibility?
695 * Original Windows versions of GetTextExtentPoint{A,W} have documented
698 BOOL16 WINAPI GetTextExtentPoint16( HDC16 hdc, LPCSTR str, INT16 count,
702 BOOL32 ret = GetTextExtentPoint32A( hdc, str, count, &size32 );
703 CONV_SIZE32TO16( &size32, size );
708 /***********************************************************************
709 * GetTextExtentPoint32A (GDI32.230)
711 BOOL32 WINAPI GetTextExtentPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
714 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
717 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
721 if (!dc->funcs->pGetTextExtentPoint ||
722 !dc->funcs->pGetTextExtentPoint( dc, str, count, size ))
725 TRACE(font,"(%08x %s %d %p): returning %d,%d\n",
726 hdc, debugstr_an (str, count), count,
727 size, size->cx, size->cy );
732 /***********************************************************************
733 * GetTextExtentPoint32W [GDI32.231] Computes width/height for a string
735 * Computes width and height of the specified string.
741 BOOL32 WINAPI GetTextExtentPoint32W(
742 HDC32 hdc, /* [in] Handle of device context */
743 LPCWSTR str, /* [in] Address of text string */
744 INT32 count, /* [in] Number of characters in string */
745 LPSIZE32 size) /* [out] Address of structure for string size */
747 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
748 BOOL32 ret = GetTextExtentPoint32A( hdc, p, count, size );
749 HeapFree( GetProcessHeap(), 0, p );
754 /***********************************************************************
755 * GetTextExtentPoint32ABuggy (GDI32.232)
757 BOOL32 WINAPI GetTextExtentPoint32ABuggy( HDC32 hdc, LPCSTR str, INT32 count,
760 TRACE(font, "not bug compatible.\n");
761 return GetTextExtentPoint32A( hdc, str, count, size );
764 /***********************************************************************
765 * GetTextExtentPoint32WBuggy (GDI32.233)
767 BOOL32 WINAPI GetTextExtentPoint32WBuggy( HDC32 hdc, LPCWSTR str, INT32 count,
770 TRACE(font, "not bug compatible.\n");
771 return GetTextExtentPoint32W( hdc, str, count, size );
775 /***********************************************************************
776 * GetTextExtentExPoint32A (GDI32.228)
778 BOOL32 WINAPI GetTextExtentExPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
779 INT32 maxExt, LPINT32 lpnFit,
780 LPINT32 alpDx, LPSIZE32 size )
782 int index, nFit, extent;
784 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
788 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
791 if (!dc->funcs->pGetTextExtentPoint) return FALSE;
793 size->cx = size->cy = nFit = extent = 0;
794 for(index = 0; index < count; index++)
796 if(!dc->funcs->pGetTextExtentPoint( dc, str, 1, &tSize )) return FALSE;
797 if( extent+tSize.cx < maxExt )
802 if( alpDx ) alpDx[index] = extent;
803 if( tSize.cy > size->cy ) size->cy = tSize.cy;
810 TRACE(font,"(%08x '%.*s' %d) returning %d %d %d\n",
811 hdc,count,str,maxExt,nFit, size->cx,size->cy);
816 /***********************************************************************
817 * GetTextExtentExPoint32W (GDI32.229)
820 BOOL32 WINAPI GetTextExtentExPoint32W( HDC32 hdc, LPCWSTR str, INT32 count,
821 INT32 maxExt, LPINT32 lpnFit,
822 LPINT32 alpDx, LPSIZE32 size )
824 LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
825 BOOL32 ret = GetTextExtentExPoint32A( hdc, p, count, maxExt,
826 lpnFit, alpDx, size);
827 HeapFree( GetProcessHeap(), 0, p );
831 /***********************************************************************
832 * GetTextMetrics16 (GDI.93)
834 BOOL16 WINAPI GetTextMetrics16( HDC16 hdc, TEXTMETRIC16 *metrics )
838 if (!GetTextMetrics32A( (HDC32)hdc, &tm32 )) return FALSE;
839 FONT_TextMetric32Ato16( &tm32, metrics );
844 /***********************************************************************
845 * GetTextMetrics32A (GDI32.236)
847 BOOL32 WINAPI GetTextMetrics32A( HDC32 hdc, TEXTMETRIC32A *metrics )
849 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
852 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
856 if (!dc->funcs->pGetTextMetrics ||
857 !dc->funcs->pGetTextMetrics( dc, metrics ))
860 /* device layer returns values in device units
861 * therefore we have to convert them to logical */
863 #define WDPTOLP(x) ((x<0)? \
864 (-abs((x)*dc->wndExtX/dc->vportExtX)): \
865 (abs((x)*dc->wndExtX/dc->vportExtX)))
866 #define HDPTOLP(y) ((y<0)? \
867 (-abs((y)*dc->wndExtY/dc->vportExtY)): \
868 (abs((y)*dc->wndExtY/dc->vportExtY)))
870 metrics->tmHeight = HDPTOLP(metrics->tmHeight);
871 metrics->tmAscent = HDPTOLP(metrics->tmAscent);
872 metrics->tmDescent = HDPTOLP(metrics->tmDescent);
873 metrics->tmInternalLeading = HDPTOLP(metrics->tmInternalLeading);
874 metrics->tmExternalLeading = HDPTOLP(metrics->tmExternalLeading);
875 metrics->tmAveCharWidth = WDPTOLP(metrics->tmAveCharWidth);
876 metrics->tmMaxCharWidth = WDPTOLP(metrics->tmMaxCharWidth);
877 metrics->tmOverhang = WDPTOLP(metrics->tmOverhang);
879 TRACE(font,"text metrics:
880 Weight = %03i\t FirstChar = %03i\t AveCharWidth = %i
881 Italic = % 3i\t LastChar = %03i\t\t MaxCharWidth = %i
882 UnderLined = %01i\t DefaultChar = %03i\t Overhang = %i
883 StruckOut = %01i\t BreakChar = %03i\t CharSet = %i
884 PitchAndFamily = %02x
890 metrics->tmWeight, metrics->tmFirstChar, metrics->tmAveCharWidth,
891 metrics->tmItalic, metrics->tmLastChar, metrics->tmMaxCharWidth,
892 metrics->tmUnderlined, metrics->tmDefaultChar, metrics->tmOverhang,
893 metrics->tmStruckOut, metrics->tmBreakChar, metrics->tmCharSet,
894 metrics->tmPitchAndFamily,
895 metrics->tmInternalLeading,
903 /***********************************************************************
904 * GetTextMetrics32W (GDI32.237)
906 BOOL32 WINAPI GetTextMetrics32W( HDC32 hdc, TEXTMETRIC32W *metrics )
909 if (!GetTextMetrics32A( (HDC16)hdc, &tm )) return FALSE;
910 FONT_TextMetric32Ato32W( &tm, metrics );
915 /***********************************************************************
916 * GetOutlineTextMetrics [GDI.308] Gets metrics for TrueType fonts.
919 * lpOTM should be LPOUTLINETEXTMETRIC
922 * Success: Non-zero or size of required buffer
925 INT16 WINAPI GetOutlineTextMetrics(
926 HDC16 hdc, /* [in] Handle of device context */
927 INT16 cbData, /* [in] Size of metric data array */
928 void *lpOTM) /* [out] Address of metric data array */
930 FIXME(font, "(%04x,%04x,%p): stub\n", hdc,cbData,lpOTM);
935 /***********************************************************************
936 * GetCharWidth16 (GDI.350)
938 BOOL16 WINAPI GetCharWidth16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
941 BOOL32 retVal = FALSE;
943 if( firstChar != lastChar )
945 LPINT32 buf32 = (LPINT32)HeapAlloc(GetProcessHeap(), 0,
946 sizeof(INT32)*(1 + (lastChar - firstChar)));
949 LPINT32 obuf32 = buf32;
952 retVal = GetCharWidth32A(hdc, firstChar, lastChar, buf32);
955 for (i = firstChar; i <= lastChar; i++)
956 *buffer++ = *buf32++;
958 HeapFree(GetProcessHeap(), 0, obuf32);
961 else /* happens quite often to warrant a special treatment */
964 retVal = GetCharWidth32A(hdc, firstChar, lastChar, &chWidth );
971 /***********************************************************************
972 * GetCharWidth32A (GDI32.155)
974 BOOL32 WINAPI GetCharWidth32A( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
978 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
981 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC )))
985 if (!dc->funcs->pGetCharWidth ||
986 !dc->funcs->pGetCharWidth( dc, firstChar, lastChar, buffer))
989 /* convert device units to logical */
991 extra = dc->vportExtX >> 1;
992 for( i = firstChar; i <= lastChar; i++, buffer++ )
993 *buffer = (*buffer * dc->wndExtX + extra) / dc->vportExtX;
999 /***********************************************************************
1000 * GetCharWidth32W (GDI32.158)
1002 BOOL32 WINAPI GetCharWidth32W( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
1005 return GetCharWidth32A( hdc, firstChar, lastChar, buffer );
1010 /* FIXME: all following APIs *******************************************
1013 * SetMapperFlags16 (GDI.349)
1015 DWORD WINAPI SetMapperFlags16( HDC16 hDC, DWORD dwFlag )
1017 return SetMapperFlags32( hDC, dwFlag );
1021 /***********************************************************************
1022 * SetMapperFlags32 (GDI32.322)
1024 DWORD WINAPI SetMapperFlags32( HDC32 hDC, DWORD dwFlag )
1026 FIXME(font, "(%04x, %08lX) -- Empty Stub !\n",
1031 /***********************************************************************
1032 * GetAspectRatioFilterEx16 (GDI.486)
1034 BOOL16 GetAspectRatioFilterEx16( HDC16 hdc, LPVOID pAspectRatio )
1036 FIXME(font, "(%04x, %p): -- Empty Stub !\n",
1042 /***********************************************************************
1043 * GetCharABCWidths16 (GDI.307)
1045 BOOL16 WINAPI GetCharABCWidths16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
1049 if (!GetCharABCWidths32A( hdc, firstChar, lastChar, &abc32 )) return FALSE;
1050 abc->abcA = abc32.abcA;
1051 abc->abcB = abc32.abcB;
1052 abc->abcC = abc32.abcC;
1057 /***********************************************************************
1058 * GetCharABCWidths32A (GDI32.149)
1060 BOOL32 WINAPI GetCharABCWidths32A(HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
1063 return GetCharABCWidths32W( hdc, firstChar, lastChar, abc );
1067 /******************************************************************************
1068 * GetCharABCWidths32W [GDI32.152] Retrieves widths of characters in range
1071 * hdc [I] Handle of device context
1072 * firstChar [I] First character in range to query
1073 * lastChar [I] Last character in range to query
1074 * abc [O] Address of character-width structure
1077 * Only works with TrueType fonts
1083 BOOL32 WINAPI GetCharABCWidths32W( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
1086 /* No TrueType fonts in Wine so far */
1087 FIXME(font, "(%04x,%04x,%04x,%p): stub\n", hdc, firstChar, lastChar, abc);
1092 /***********************************************************************
1093 * GetGlyphOutline16 (GDI.309)
1095 DWORD WINAPI GetGlyphOutline16( HDC16 hdc, UINT16 uChar, UINT16 fuFormat,
1096 LPGLYPHMETRICS16 lpgm, DWORD cbBuffer,
1097 LPVOID lpBuffer, const MAT2 *lpmat2 )
1099 FIXME(font,"(%04x, '%c', %04x, %p, %ld, %p, %p): empty stub!\n",
1100 hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
1101 return (DWORD)-1; /* failure */
1105 /***********************************************************************
1106 * GetGlyphOutline32A (GDI32.186)
1108 DWORD WINAPI GetGlyphOutline32A( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
1109 LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
1110 LPVOID lpBuffer, const MAT2 *lpmat2 )
1112 FIXME(font,"(%04x, '%c', %04x, %p, %ld, %p, %p): empty stub!\n",
1113 hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
1114 return (DWORD)-1; /* failure */
1117 /***********************************************************************
1118 * GetGlyphOutline32W (GDI32.187)
1120 DWORD WINAPI GetGlyphOutline32W( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
1121 LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
1122 LPVOID lpBuffer, const MAT2 *lpmat2 )
1124 FIXME(font,"(%04x, '%c', %04x, %p, %ld, %p, %p): empty stub!\n",
1125 hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
1126 return (DWORD)-1; /* failure */
1129 /***********************************************************************
1130 * CreateScalableFontResource16 (GDI.310)
1132 BOOL16 WINAPI CreateScalableFontResource16( UINT16 fHidden,
1133 LPCSTR lpszResourceFile,
1134 LPCSTR fontFile, LPCSTR path )
1136 return CreateScalableFontResource32A( fHidden, lpszResourceFile,
1140 /***********************************************************************
1141 * CreateScalableFontResource32A (GDI32.62)
1143 BOOL32 WINAPI CreateScalableFontResource32A( DWORD fHidden,
1144 LPCSTR lpszResourceFile,
1145 LPCSTR lpszFontFile,
1146 LPCSTR lpszCurrentPath )
1148 /* fHidden=1 - only visible for the calling app, read-only, not
1149 * enumbered with EnumFonts/EnumFontFamilies
1150 * lpszCurrentPath can be NULL
1152 FIXME(font,"(%ld,%s,%s,%s): empty stub\n",
1153 fHidden, lpszResourceFile, lpszFontFile, lpszCurrentPath );
1154 return FALSE; /* create failed */
1157 /***********************************************************************
1158 * CreateScalableFontResource32W (GDI32.63)
1160 BOOL32 WINAPI CreateScalableFontResource32W( DWORD fHidden,
1161 LPCWSTR lpszResourceFile,
1162 LPCWSTR lpszFontFile,
1163 LPCWSTR lpszCurrentPath )
1165 FIXME(font,"(%ld,%p,%p,%p): empty stub\n",
1166 fHidden, lpszResourceFile, lpszFontFile, lpszCurrentPath );
1167 return FALSE; /* create failed */
1171 /*************************************************************************
1172 * GetRasterizerCaps16 (GDI.313)
1174 BOOL16 WINAPI GetRasterizerCaps16( LPRASTERIZER_STATUS lprs, UINT16 cbNumBytes)
1176 return GetRasterizerCaps32( lprs, cbNumBytes );
1180 /*************************************************************************
1181 * GetRasterizerCaps32 (GDI32.216)
1183 BOOL32 WINAPI GetRasterizerCaps32( LPRASTERIZER_STATUS lprs, UINT32 cbNumBytes)
1185 lprs->nSize = sizeof(RASTERIZER_STATUS);
1186 lprs->wFlags = TT_AVAILABLE|TT_ENABLED;
1187 lprs->nLanguageID = 0;
1192 /*************************************************************************
1193 * GetKerningPairs16 (GDI.332)
1195 INT16 WINAPI GetKerningPairs16( HDC16 hDC, INT16 cPairs,
1196 LPKERNINGPAIR16 lpKerningPairs )
1198 /* At this time kerning is ignored (set to 0) */
1200 FIXME(font,"(%x,%d,%p): almost empty stub!\n",
1201 hDC, cPairs, lpKerningPairs);
1202 for (i = 0; i < cPairs; i++)
1203 lpKerningPairs[i].iKernAmount = 0;
1209 /*************************************************************************
1210 * GetKerningPairs32A (GDI32.192)
1212 DWORD WINAPI GetKerningPairs32A( HDC32 hDC, DWORD cPairs,
1213 LPKERNINGPAIR32 lpKerningPairs )
1216 FIXME(font,"(%x,%ld,%p): almost empty stub!\n",
1217 hDC, cPairs, lpKerningPairs);
1218 for (i = 0; i < cPairs; i++)
1219 lpKerningPairs[i].iKernAmount = 0;
1224 /*************************************************************************
1225 * GetKerningPairs32W (GDI32.193)
1227 DWORD WINAPI GetKerningPairs32W( HDC32 hDC, DWORD cPairs,
1228 LPKERNINGPAIR32 lpKerningPairs )
1230 return GetKerningPairs32A( hDC, cPairs, lpKerningPairs );
1233 /*************************************************************************
1234 * TranslateCharSetInfo [GDI32.382]
1236 BOOL32 WINAPI TranslateCharSetInfo(LPDWORD lpSrc,LPCHARSETINFO lpCs,DWORD dwFlags) {
1237 FIXME(font,"(%p,%p,0x%08lx), stub.\n",lpSrc,lpCs,dwFlags);
1241 /*************************************************************************
1242 * GetFontLanguageInfo (GDI32.182)
1244 DWORD WINAPI GetFontLanguageInfo32(HDC32 hdc) {
1245 /* return value 0 is correct for most cases anyway */
1246 FIXME(font,"(%x):stub!\n", hdc);
1250 /*************************************************************************
1251 * GetFontLanguageInfo (GDI.616)
1253 DWORD WINAPI GetFontLanguageInfo16(HDC16 hdc) {
1254 /* return value 0 is correct for most cases anyway */
1255 FIXME(font,"(%x):stub!\n",hdc);
1260 /*************************************************************************
1261 * GetCharacterPlacement32A [GDI32.160]
1264 GetCharacterPlacement32A(HDC32 hdc, LPCSTR lpString, UINT32 uCount,
1265 INT32 nMaxExtent, GCP_RESULTS32A lpResults,
1268 /* return value 0 is correct for most cases anyway */
1269 FIXME(font,":stub!\n");
1273 /*************************************************************************
1274 * GetCharacterPlacement32W [GDI32.161]
1277 GetCharacterPlacement32W(HDC32 hdc, LPCWSTR lpString, UINT32 uCount,
1278 INT32 nMaxExtent, GCP_RESULTS32W lpResults,
1281 /* return value 0 is correct for most cases anyway */
1282 FIXME(font,":stub!\n");