source: trunk/src/gdi32/font.cpp@ 10605

Last change on this file since 10605 was 10605, checked in by sandervl, 21 years ago

KOM: update

File size: 38.0 KB
Line 
1/* $Id: font.cpp,v 1.36 2004-05-24 08:50:31 sandervl Exp $ */
2
3/*
4 * GDI32 font apis
5 *
6 * Copyright 1999 Edgar Buerkle (Edgar.Buerkle@gmx.ne)
7 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
8 * Copyright 1998 Patrick Haller
9 * Copyright 2003 Innotek Systemberatung GmbH (stauff@innotek.de)
10 *
11 * TODO: EnumFontsA/W, EnumFontFamiliesExA/W not complete
12 *
13 * Parts based on Wine code (991031)
14 *
15 * Copyright 1993 Alexandre Julliard
16 * 1997 Alex Korobka
17 *
18 * Project Odin Software License can be found in LICENSE.TXT
19 *
20 */
21
22/*****************************************************************************
23 * Includes *
24 *****************************************************************************/
25
26#include <odin.h>
27#include <odinwrap.h>
28#include <os2sel.h>
29
30#include <os2win.h>
31#include <stdlib.h>
32#include <stdarg.h>
33#include <ctype.h>
34#include <string.h>
35#include <dbglog.h>
36#include "unicode.h"
37#include <heapstring.h>
38#include <win\options.h>
39#include <wprocess.h>
40#include <odininst.h>
41#include <stats.h>
42#include "oslibgpi.h"
43#include "font.h"
44#include "ft2supp.h"
45
46#define DBG_LOCALLOG DBG_font
47#include "dbglocal.h"
48
49ODINDEBUGCHANNEL(GDI32-FONT)
50
51typedef struct {
52 DWORD userProc;
53 DWORD userData;
54 DWORD dwFlags;
55} ENUMUSERDATA;
56
57/*
58 * For TranslateCharsetInfo
59 */
60#define FS(x) {{0,0,0,0},{0x1<<(x),0}}
61#define MAXTCIINDEX 32
62static CHARSETINFO FONT_tci[MAXTCIINDEX] = {
63 /* ANSI */
64 { ANSI_CHARSET, 1252, FS(0)},
65 { EASTEUROPE_CHARSET, 1250, FS(1)},
66 { RUSSIAN_CHARSET, 1251, FS(2)},
67 { GREEK_CHARSET, 1253, FS(3)},
68 { TURKISH_CHARSET, 1254, FS(4)},
69 { HEBREW_CHARSET, 1255, FS(5)},
70 { ARABIC_CHARSET, 1256, FS(6)},
71 { BALTIC_CHARSET, 1257, FS(7)},
72 /* reserved by ANSI */
73 { DEFAULT_CHARSET, 0, FS(0)},
74 { DEFAULT_CHARSET, 0, FS(0)},
75 { DEFAULT_CHARSET, 0, FS(0)},
76 { DEFAULT_CHARSET, 0, FS(0)},
77 { DEFAULT_CHARSET, 0, FS(0)},
78 { DEFAULT_CHARSET, 0, FS(0)},
79 { DEFAULT_CHARSET, 0, FS(0)},
80 { DEFAULT_CHARSET, 0, FS(0)},
81 /* ANSI and OEM */
82 { THAI_CHARSET, 874, FS(16)},
83 { SHIFTJIS_CHARSET, 932, FS(17)},
84 { GB2312_CHARSET, 936, FS(18)},
85 { HANGEUL_CHARSET, 949, FS(19)},
86 { CHINESEBIG5_CHARSET, 950, FS(20)},
87 { JOHAB_CHARSET, 1361, FS(21)},
88 /* reserved for alternate ANSI and OEM */
89 { DEFAULT_CHARSET, 0, FS(0)},
90 { DEFAULT_CHARSET, 0, FS(0)},
91 { DEFAULT_CHARSET, 0, FS(0)},
92 { DEFAULT_CHARSET, 0, FS(0)},
93 { DEFAULT_CHARSET, 0, FS(0)},
94 { DEFAULT_CHARSET, 0, FS(0)},
95 { DEFAULT_CHARSET, 0, FS(0)},
96 { DEFAULT_CHARSET, 0, FS(0)},
97 /* reserved for system */
98 { DEFAULT_CHARSET, 0, FS(0)},
99 { SYMBOL_CHARSET, CP_SYMBOL, FS(31)},
100};
101
102HFONT hFntDefaultGui = NULL;
103
104/*****************************************************************************
105 * Name : static void iFontRename
106 * Purpose : font remapping table to map win32 fonts to OS/2 pendants
107 * Parameters: LPSTR lpstrFaceOriginal - the win32 face name
108 * LPSTR lpstrFaceBuffer - [LF_FACESIZE] buffer to new name
109 * Variables :
110 * Result :
111 * Remark : remapped name is passed back in the buffer
112 * if no mapping pendant is available, return input parameter
113 * as default.
114 * Status :
115 *
116 * Author : Patrick Haller [Fri, 1998/06/12 03:44]
117 *****************************************************************************/
118
119static void iFontRename(LPCSTR lpstrFaceOriginal,
120 LPSTR lpstrFaceTemp)
121{
122 int iRet;
123
124 // NULL is a valid parameter
125 if (lpstrFaceOriginal == NULL)
126 return;
127
128 strncpy(lpstrFaceTemp, lpstrFaceOriginal, LF_FACESIZE);
129 lpstrFaceTemp[LF_FACESIZE-1] = 0;
130
131 {
132 char *y = lpstrFaceTemp;
133 while(*y) {
134 if(IsDBCSLeadByte( *y )) {
135 y += 2; // DBCS skip
136 } else {
137 *y = toupper( *y );
138 y++;
139 }
140 }
141 }
142
143 //lookup table
144 iRet = PROFILE_GetOdinIniString(ODINFONTSECTION,
145 lpstrFaceTemp,
146 lpstrFaceOriginal,
147 lpstrFaceTemp,
148 LF_FACESIZE);
149}
150#ifdef DEBUG
151//******************************************************************************
152//******************************************************************************
153void dprintfLogFont(LOGFONTA *lplf)
154{
155 dprintf(("GDI32: lfHeight = %d\n", lplf->lfHeight));
156 dprintf(("GDI32: lfWidth = %d\n", lplf->lfWidth));
157 dprintf(("GDI32: lfEscapement = %d\n", lplf->lfEscapement));
158 dprintf(("GDI32: lfOrientation = %d\n", lplf->lfOrientation));
159 dprintf(("GDI32: lfWeight = %d\n", lplf->lfWeight));
160 dprintf(("GDI32: lfItalic = %d\n", lplf->lfItalic));
161 dprintf(("GDI32: lfUnderline = %d\n", lplf->lfUnderline));
162 dprintf(("GDI32: lfStrikeOut = %d\n", lplf->lfStrikeOut));
163 dprintf(("GDI32: lfCharSet = %X\n", lplf->lfCharSet));
164 dprintf(("GDI32: lfOutPrecision = %X\n", lplf->lfOutPrecision));
165 dprintf(("GDI32: lfClipPrecision = %X\n", lplf->lfClipPrecision));
166 dprintf(("GDI32: lfQuality = %X\n", lplf->lfQuality));
167 dprintf(("GDI32: lfPitchAndFamily= %X\n", lplf->lfPitchAndFamily));
168 dprintf(("GDI32: lfFaceName = %s\n", lplf->lfFaceName));
169}
170//******************************************************************************
171//******************************************************************************
172void dprintfTextMetrics(TEXTMETRICA *pwtm)
173{
174 dprintf(("pwtm->tmHeight %d", pwtm->tmHeight));
175 dprintf(("pwtm->tmAscent %d", pwtm->tmAscent));
176 dprintf(("pwtm->tmDescent %d", pwtm->tmDescent));
177 dprintf(("pwtm->tmInternalLeading %d", pwtm->tmInternalLeading));
178 dprintf(("pwtm->tmExternalLeading %d", pwtm->tmExternalLeading));
179 dprintf(("pwtm->tmAveCharWidth %d", pwtm->tmAveCharWidth));
180 dprintf(("pwtm->tmMaxCharWidth %d", pwtm->tmMaxCharWidth));
181 dprintf(("pwtm->tmWeight %d", pwtm->tmWeight));
182 dprintf(("pwtm->tmOverhang %d", pwtm->tmOverhang));
183 dprintf(("pwtm->tmDigitizedAspectX %d", pwtm->tmDigitizedAspectX));
184 dprintf(("pwtm->tmDigitizedAspectY %d", pwtm->tmDigitizedAspectY));
185 dprintf(("pwtm->tmFirstChar %d", pwtm->tmFirstChar));
186 dprintf(("pwtm->tmLastChar %d", pwtm->tmLastChar));
187 dprintf(("pwtm->tmDefaultChar %d", pwtm->tmDefaultChar));
188 dprintf(("pwtm->tmBreakChar %d", pwtm->tmBreakChar));
189 dprintf(("pwtm->tmItalic %x", pwtm->tmItalic));
190 dprintf(("pwtm->tmUnderlined %x", pwtm->tmUnderlined));
191 dprintf(("pwtm->tmStruckOut %x", pwtm->tmStruckOut));
192 dprintf(("pwtm->tmPitchAndFamily %x", pwtm->tmPitchAndFamily));
193 dprintf(("pwtm->tmCharSet %x", pwtm->tmCharSet));
194}
195#else
196#define dprintfLogFont(a)
197#define dprintfTextMetrics(a)
198#endif
199//******************************************************************************
200//******************************************************************************
201HFONT WIN32API CreateFontA(int nHeight,
202 int nWidth,
203 int nEscapement,
204 int nOrientation,
205 int fnWeight,
206 DWORD fdwItalic,
207 DWORD fdwUnderline,
208 DWORD fdwStrikeOut,
209 DWORD fdwCharSet,
210 DWORD fdwOutputPrecision,
211 DWORD fdwClipPrecision,
212 DWORD fdwQuality,
213 DWORD fdwPitchAndFamily,
214 LPCSTR lpszFace)
215{
216 CHAR lpstrFaceNew[LF_FACESIZE];
217 HFONT hFont;
218
219 if(lpszFace == NULL)
220 lpszFace = "";
221
222 if(strlen(lpszFace) >= LF_FACESIZE)
223 {
224 dprintf(("ERROR: Invalid string length for font name!!"));
225 SetLastError(ERROR_INVALID_PARAMETER);
226 return 0;
227 }
228
229 iFontRename(lpszFace, lpstrFaceNew);
230
231 dprintf(("lpszFace = %s -> %s\n", lpszFace, lpstrFaceNew));
232
233 LOGFONTA logFont =
234 {
235 nHeight,
236 nWidth,
237 nEscapement,
238 nOrientation,
239 fnWeight,
240 (BYTE)fdwItalic,
241 (BYTE)fdwUnderline,
242 (BYTE)fdwStrikeOut,
243 (BYTE)fdwCharSet,
244 (BYTE)fdwOutputPrecision,
245 (BYTE)fdwClipPrecision,
246 (BYTE)fdwQuality,
247 (BYTE)fdwPitchAndFamily
248 };
249 strcpy(logFont.lfFaceName, lpszFace);
250
251 return CreateFontIndirectA(&logFont);
252}
253//******************************************************************************
254//******************************************************************************
255HFONT WIN32API CreateFontW(int nHeight,
256 int nWidth,
257 int nEscapement,
258 int nOrientation,
259 int fnWeight,
260 DWORD fdwItalic,
261 DWORD fdwUnderline,
262 DWORD fdwStrikeOut,
263 DWORD fdwCharSet,
264 DWORD fdwOutputPrecision,
265 DWORD fdwClipPrecision,
266 DWORD fdwQuality,
267 DWORD fdwPitchAndFamily,
268 LPCWSTR lpszFace)
269{
270 char *astring;
271 HFONT hFont;
272
273 // NULL is valid for lpszFace
274 if(lpszFace != NULL)
275 astring = UnicodeToAsciiString((LPWSTR)lpszFace);
276 else
277 astring = NULL;
278
279 // @@@PH switch to ODIN_ later
280 hFont = CreateFontA(nHeight,
281 nWidth,
282 nEscapement,
283 nOrientation,
284 fnWeight,
285 fdwItalic,
286 fdwUnderline,
287 fdwStrikeOut,
288 fdwCharSet,
289 fdwOutputPrecision,
290 fdwClipPrecision,
291 fdwQuality,
292 fdwPitchAndFamily,
293 astring);
294 if (astring != NULL)
295 FreeAsciiString(astring);
296
297 return(hFont);
298}
299
300//******************************************************************************
301//******************************************************************************
302HFONT WIN32API CreateFontIndirectA(const LOGFONTA* lplf)
303{
304 HFONT hFont;
305 LOGFONTA afont;
306
307 // don't touch user buffer!
308 memcpy(&afont, lplf, sizeof(LOGFONTA));
309 iFontRename(lplf->lfFaceName, afont.lfFaceName);
310
311 dprintf(("lpszFace = (%x) %s -> %s\n", lplf->lfFaceName, lplf->lfFaceName, afont.lfFaceName));
312
313 if( IsDBCSEnv())
314 {
315 if( !strcmp( afont.lfFaceName, "WarpSans" ))
316 {
317 dprintf(("DBCS : WarpSans -> WarpSans Combined"));
318
319 strcpy( afont.lfFaceName, "WarpSans Combined" );
320 }
321
322#if 1
323 if( afont.lfCharSet == ANSI_CHARSET )
324 afont.lfCharSet = DEFAULT_CHARSET;
325#endif
326 }
327
328 dprintf(("GDI32: CreateFontIndirectA\n"));
329 dprintfLogFont((LOGFONTA *)lplf);
330
331 hFont = O32_CreateFontIndirect(&afont);
332 if(hFont) {
333 STATS_CreateFontIndirect(hFont, &afont);
334 RegisterFont(hFont, (LPSTR)lplf->lfFaceName);
335 }
336 return(hFont);
337}
338//******************************************************************************
339//******************************************************************************
340HFONT WIN32API CreateFontIndirectW(const LOGFONTW * lplf)
341{
342 LOGFONTA afont;
343 HFONT hfont;
344
345 //memcpy(&afont, lplf, ((ULONG)&afont.lfFaceName - (ULONG)&afont));
346 memcpy(&afont, lplf, sizeof(LOGFONTA));
347 memset(afont.lfFaceName, 0, LF_FACESIZE);
348 dprintf(("lpszFace = (%x)", lplf->lfFaceName));
349
350 UnicodeToAsciiN((WCHAR *)lplf->lfFaceName, afont.lfFaceName, LF_FACESIZE-1);
351 hfont = CreateFontIndirectA(&afont);
352 return(hfont);
353}
354//******************************************************************************
355//******************************************************************************
356int EXPENTRY_O32 EnumFontProcA(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA
357 lpTextM, DWORD arg3, LPARAM arg4)
358{
359 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
360 FONTENUMPROCA proc = (FONTENUMPROCA)lpEnumData->userProc;
361 USHORT selTIB = SetWin32TIB(); // save current FS selector and set win32 sel
362
363 if(FT2Module.Ft2QueryFontType(0, lpLogFont->elfLogFont.lfFaceName) == FT2_FONTTYPE_TRUETYPE) {
364 lpTextM->tmPitchAndFamily |= TMPF_TRUETYPE;
365 }
366
367 dprintfLogFont(&lpLogFont->elfLogFont);
368 dprintfTextMetrics((TEXTMETRICA *)lpTextM);
369
370 int rc = proc(lpLogFont, lpTextM, arg3, lpEnumData->userData);
371 SetFS(selTIB); // switch back to the saved FS selector
372 return rc;
373}
374//******************************************************************************
375//******************************************************************************
376int EXPENTRY_O32 EnumFontProcW(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA lpTextM,
377 DWORD arg3, LPARAM arg4)
378{
379 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
380 FONTENUMPROCW proc = (FONTENUMPROCW)lpEnumData->userProc;
381 ENUMLOGFONTW LogFont;
382 NEWTEXTMETRICW textM;
383 USHORT selTIB = SetWin32TIB(); // save current FS selector and set win32 sel
384 int rc;
385
386 if(FT2Module.Ft2QueryFontType(0, lpLogFont->elfLogFont.lfFaceName) == FT2_FONTTYPE_TRUETYPE) {
387 lpTextM->tmPitchAndFamily |= TMPF_TRUETYPE;
388 }
389
390 dprintfLogFont(&lpLogFont->elfLogFont);
391 dprintfTextMetrics((TEXTMETRICA *)lpTextM);
392
393 memcpy(&LogFont, lpLogFont, ((ULONG)&LogFont.elfLogFont.lfFaceName -
394 (ULONG)&LogFont));
395 AsciiToUnicodeN(lpLogFont->elfLogFont.lfFaceName, LogFont.elfLogFont.lfFaceName, LF_FACESIZE-1);
396 AsciiToUnicodeN((char *) lpLogFont->elfFullName, LogFont.elfFullName, LF_FULLFACESIZE-1);
397 AsciiToUnicodeN((char *) lpLogFont->elfStyle, LogFont.elfStyle, LF_FACESIZE-1);
398
399 textM.tmHeight = lpTextM->tmHeight;
400 textM.tmAscent = lpTextM->tmAscent;
401 textM.tmDescent = lpTextM->tmDescent;
402 textM.tmInternalLeading = lpTextM->tmInternalLeading;
403 textM.tmExternalLeading = lpTextM->tmExternalLeading;
404 textM.tmAveCharWidth = lpTextM->tmAveCharWidth;
405 textM.tmMaxCharWidth = lpTextM->tmMaxCharWidth;
406 textM.tmWeight = lpTextM->tmWeight;
407 textM.tmOverhang = lpTextM->tmOverhang;
408 textM.tmDigitizedAspectX = lpTextM->tmDigitizedAspectX;
409 textM.tmDigitizedAspectY = lpTextM->tmDigitizedAspectY;
410 textM.tmFirstChar = lpTextM->tmFirstChar;
411 textM.tmLastChar = lpTextM->tmLastChar;
412 textM.tmDefaultChar = lpTextM->tmDefaultChar;
413 textM.tmBreakChar = lpTextM->tmBreakChar;
414 textM.tmItalic = lpTextM->tmItalic;
415 textM.tmUnderlined = lpTextM->tmUnderlined;
416 textM.tmStruckOut = lpTextM->tmStruckOut;
417 textM.tmPitchAndFamily = lpTextM->tmPitchAndFamily;
418 textM.tmCharSet = lpTextM->tmCharSet;
419 textM.ntmFlags = 0;
420 textM.ntmSizeEM = 0;
421 textM.ntmCellHeight = 0;
422 textM.ntmAvgWidth = 0;
423
424 rc = proc(&LogFont, &textM, arg3, lpEnumData->userData);
425 SetFS(selTIB); // switch back to the saved FS selector
426 return rc;
427}
428//******************************************************************************
429//TODO: FontEnumdwFlagsEx, script, font signature & NEWTEXTMETRICEX (last part)
430//******************************************************************************
431int EXPENTRY_O32 EnumFontProcExA(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA
432 lpTextM, DWORD FontType, LPARAM arg4)
433{
434 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
435 FONTENUMPROCEXA proc = (FONTENUMPROCEXA)lpEnumData->userProc;
436 ENUMLOGFONTEXA logFont;
437 NEWTEXTMETRICEXA textM;
438 USHORT selTIB = SetWin32TIB(); // save current FS selector and set win32 sel
439
440 if(FT2Module.Ft2QueryFontType(0, lpLogFont->elfLogFont.lfFaceName) == FT2_FONTTYPE_TRUETYPE) {
441 lpTextM->tmPitchAndFamily |= TMPF_TRUETYPE;
442 }
443
444 dprintfLogFont(&lpLogFont->elfLogFont);
445 dprintfTextMetrics((TEXTMETRICA *)lpTextM);
446
447 memcpy(&logFont, lpLogFont, sizeof(ENUMLOGFONTA));
448 memset(logFont.elfScript, 0, sizeof(logFont.elfScript));
449 memcpy(&textM.ntmTm, lpTextM, sizeof(textM.ntmTm));
450 memset(&textM.ntmFontSig, 0, sizeof(textM.ntmFontSig));
451
452 dprintf(("EnumFontProcExA %s type %x height %d", logFont.elfLogFont.lfFaceName, FontType, textM.ntmTm.tmHeight));
453
454 int rc = proc(&logFont, &textM, FontType, lpEnumData->userData);
455 SetFS(selTIB); // switch back to the saved FS selector
456 return rc;
457}
458//******************************************************************************
459//TODO: FontEnumdwFlagsEx, script, font signature & NEWTEXTMETRICEX (last part)
460//******************************************************************************
461int EXPENTRY_O32 EnumFontProcExW(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA lpTextM,
462 DWORD FontType, LPARAM arg4)
463{
464 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
465 FONTENUMPROCEXW proc = (FONTENUMPROCEXW)lpEnumData->userProc;
466 ENUMLOGFONTEXW LogFont;
467 NEWTEXTMETRICEXW textM;
468 USHORT selTIB = SetWin32TIB(); // save current FS selector and set win32 sel
469 int rc;
470
471 if(FT2Module.Ft2QueryFontType(0, lpLogFont->elfLogFont.lfFaceName) == FT2_FONTTYPE_TRUETYPE) {
472 lpTextM->tmPitchAndFamily |= TMPF_TRUETYPE;
473 }
474
475 dprintfLogFont(&lpLogFont->elfLogFont);
476 dprintfTextMetrics((TEXTMETRICA *)lpTextM);
477
478 memcpy(&LogFont, lpLogFont, ((ULONG)&LogFont.elfLogFont.lfFaceName - (ULONG)&LogFont));
479 memset(LogFont.elfScript, 0, sizeof(LogFont.elfScript));
480 AsciiToUnicodeN(lpLogFont->elfLogFont.lfFaceName, LogFont.elfLogFont.lfFaceName, LF_FACESIZE-1);
481 AsciiToUnicodeN((char *) lpLogFont->elfFullName, LogFont.elfFullName, LF_FULLFACESIZE-1);
482 AsciiToUnicodeN((char *) lpLogFont->elfStyle, LogFont.elfStyle, LF_FACESIZE-1);
483
484 textM.ntmTm.tmHeight = lpTextM->tmHeight;
485 textM.ntmTm.tmAscent = lpTextM->tmAscent;
486 textM.ntmTm.tmDescent = lpTextM->tmDescent;
487 textM.ntmTm.tmInternalLeading = lpTextM->tmInternalLeading;
488 textM.ntmTm.tmExternalLeading = lpTextM->tmExternalLeading;
489 textM.ntmTm.tmAveCharWidth = lpTextM->tmAveCharWidth;
490 textM.ntmTm.tmMaxCharWidth = lpTextM->tmMaxCharWidth;
491 textM.ntmTm.tmWeight = lpTextM->tmWeight;
492 textM.ntmTm.tmOverhang = lpTextM->tmOverhang;
493 textM.ntmTm.tmDigitizedAspectX = lpTextM->tmDigitizedAspectX;
494 textM.ntmTm.tmDigitizedAspectY = lpTextM->tmDigitizedAspectY;
495 textM.ntmTm.tmFirstChar = lpTextM->tmFirstChar;
496 textM.ntmTm.tmLastChar = lpTextM->tmLastChar;
497 textM.ntmTm.tmDefaultChar = lpTextM->tmDefaultChar;
498 textM.ntmTm.tmBreakChar = lpTextM->tmBreakChar;
499 textM.ntmTm.tmItalic = lpTextM->tmItalic;
500 textM.ntmTm.tmUnderlined = lpTextM->tmUnderlined;
501 textM.ntmTm.tmStruckOut = lpTextM->tmStruckOut;
502 textM.ntmTm.tmPitchAndFamily = lpTextM->tmPitchAndFamily;
503 textM.ntmTm.tmCharSet = lpTextM->tmCharSet;
504 textM.ntmTm.ntmFlags = 0;
505 textM.ntmTm.ntmSizeEM = 0;
506 textM.ntmTm.ntmCellHeight = 0;
507 textM.ntmTm.ntmAvgWidth = 0;
508 memset(&textM.ntmFontSig, 0, sizeof(textM.ntmFontSig));
509
510 dprintf(("EnumFontProcExW %s type %x height %d charset %d/%d", lpLogFont->elfLogFont.lfFaceName, FontType, textM.ntmTm.tmHeight, lpTextM->tmCharSet, lpLogFont->elfLogFont.lfCharSet));
511 rc = proc(&LogFont, &textM, FontType, lpEnumData->userData);
512 SetFS(selTIB); // switch back to the saved FS selector
513 return rc;
514}
515//******************************************************************************
516//******************************************************************************
517int WIN32API EnumFontsA(HDC hdc,
518 LPCSTR arg2,
519 FONTENUMPROCA arg3,
520 LPARAM arg4)
521{
522 //@@@PH shouldn't this rather be O32_EnumFonts ?
523 return EnumFontFamiliesA(hdc, arg2, arg3, arg4);
524}
525//******************************************************************************
526//******************************************************************************
527int WIN32API EnumFontsW(HDC hdc,
528 LPCWSTR arg2,
529 FONTENUMPROCW arg3,
530 LPARAM arg4)
531{
532 //@@@PH shouldn't this rather be O32_EnumFonts ?
533 return EnumFontFamiliesW(hdc, arg2, arg3, arg4);
534}
535//******************************************************************************
536//******************************************************************************
537int WIN32API EnumFontFamiliesA(HDC hdc,
538 LPCSTR lpszFontFamily,
539 FONTENUMPROCA arg3,
540 LPARAM arg4)
541{
542 ENUMUSERDATA enumData;
543 CHAR lpstrFamilyNew[LF_FACESIZE] = "";
544 int rc;
545
546 dprintf(("GDI32: EnumFontFamiliesA %s", lpszFontFamily));
547
548 iFontRename(lpszFontFamily, lpstrFamilyNew);
549
550 enumData.userProc = (DWORD)arg3;
551 enumData.userData = arg4;
552
553 rc = O32_EnumFontFamilies(hdc, lpstrFamilyNew, &EnumFontProcA, (LPARAM)&enumData);
554
555 return rc;
556}
557//******************************************************************************
558//******************************************************************************
559int WIN32API EnumFontFamiliesW(HDC hdc,
560 LPCWSTR lpszFontFamilyW,
561 FONTENUMPROCW arg3,
562 LPARAM arg4)
563{
564 CHAR lpstrFamilyNew[LF_FACESIZE] = "";
565 ENUMUSERDATA enumData;
566 int rc;
567 char *lpszFontFamilyA = UnicodeToAsciiString((LPWSTR)lpszFontFamilyW);
568
569 dprintf(("GDI32: EnumFontFamiliesW %s", lpszFontFamilyA));
570
571 iFontRename(lpszFontFamilyA, lpstrFamilyNew);
572
573 enumData.userProc = (DWORD)arg3;
574 enumData.userData = arg4;
575
576 rc = O32_EnumFontFamilies(hdc, lpstrFamilyNew, &EnumFontProcW, (LPARAM)&enumData);
577
578 if(lpszFontFamilyA) FreeAsciiString(lpszFontFamilyA);
579 return rc;
580}
581//******************************************************************************
582//******************************************************************************
583INT WIN32API EnumFontFamiliesExA(HDC hdc,
584 LPLOGFONTA lpLogFont,
585 FONTENUMPROCEXA arg3,
586 LPARAM arg4,
587 DWORD dwFlags)
588{
589 ENUMUSERDATA enumData;
590 int rc;
591
592 dprintf(("GDI32: EnumFontFamiliesExA not complete %s", lpLogFont->lfFaceName));
593 dprintf(("GDI32: EnumFontFamiliesExA font name %s character set %x", lpLogFont->lfFaceName, lpLogFont->lfCharSet));
594
595 enumData.userProc = (DWORD)arg3;
596 enumData.userData = arg4;
597 enumData.dwFlags = dwFlags;
598
599 rc = O32_EnumFontFamilies(hdc, lpLogFont->lfFaceName, &EnumFontProcExA, (LPARAM)&enumData);
600
601 return rc;
602}
603//******************************************************************************
604//******************************************************************************
605INT WIN32API EnumFontFamiliesExW(HDC hdc,
606 LPLOGFONTW lpLogFont,
607 FONTENUMPROCEXW arg3,
608 LPARAM arg4,
609 DWORD dwFlags)
610{
611 ENUMUSERDATA enumData;
612 int rc;
613 char *astring = UnicodeToAsciiString((LPWSTR)lpLogFont->lfFaceName);
614
615 dprintf(("GDI32: EnumFontFamiliesExW not complete %s", astring));
616 dprintf(("GDI32: EnumFontFamiliesExW font name %s character set %x", astring, lpLogFont->lfCharSet));
617
618 enumData.userProc = (DWORD)arg3;
619 enumData.userData = arg4;
620 enumData.dwFlags = dwFlags;
621
622 rc = O32_EnumFontFamilies(hdc, astring, &EnumFontProcExW, (LPARAM)&enumData);
623
624 FreeAsciiString(astring);
625 return rc;
626}
627
628/*****************************************************************************
629 * Name : DWORD GetFontLanguageInfo
630 * Purpose : The GetFontLanguageInfo function returns information about the
631 * currently selected font for the specified display context.
632 * Applications typically use this information and the
633 * GetCharacterPlacement function to prepare a character string for display.
634 * Parameters: HDC hdc handle to device context
635 * Variables :
636 * Result :
637 * Remark :
638 * Status : UNTESTED STUB
639 *
640 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
641 *****************************************************************************/
642
643DWORD WIN32API GetFontLanguageInfo(HDC hdc)
644{
645 dprintf(("GDI32: GetFontLanguageInfo(%08xh) not implemented.\n",
646 hdc));
647
648 return (0);
649}
650
651
652/*************************************************************************
653 * TranslateCharsetInfo [GDI32.382]
654 *
655 * Fills a CHARSETINFO structure for a character set, code page, or
656 * font. This allows making the correspondance between different labelings
657 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
658 * of the same encoding.
659 *
660 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
661 * only one codepage should be set in *lpSrc.
662 *
663 * RETURNS
664 * TRUE on success, FALSE on failure.
665 *
666 *
667 * LPDWORD lpSrc, if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
668 * if flags == TCI_SRCCHARSET: a character set value
669 * if flags == TCI_SRCCODEPAGE: a code page value
670 * LPCHARSETINFO lpCs, structure to receive charset information
671 * DWORD flags determines interpretation of lpSrc
672 */
673BOOL WIN32API TranslateCharsetInfo(LPDWORD lpSrc, LPCHARSETINFO lpCs,
674 DWORD flags)
675{
676 int index = 0;
677 switch (flags) {
678 case TCI_SRCFONTSIG:
679 while (!(*lpSrc>>index & 0x0001) && index<MAXTCIINDEX) index++;
680 break;
681 case TCI_SRCCODEPAGE:
682 while ((UINT) (lpSrc) != FONT_tci[index].ciACP && index < MAXTCIINDEX) index++;
683 break;
684 case TCI_SRCCHARSET:
685 while ((UINT) (lpSrc) != FONT_tci[index].ciCharset && index < MAXTCIINDEX) index++;
686 break;
687 default:
688 return FALSE;
689 }
690 if (index >= MAXTCIINDEX || FONT_tci[index].ciCharset == DEFAULT_CHARSET) return FALSE;
691 memcpy(lpCs, &FONT_tci[index], sizeof(CHARSETINFO));
692 return TRUE;
693}
694//******************************************************************************
695//******************************************************************************
696BOOL WIN32API GetTextMetricsA( HDC hdc, LPTEXTMETRICA pwtm)
697{
698 BOOL rc;
699
700 rc = O32_GetTextMetrics(hdc, pwtm);
701
702 if(rc == TRUE) {
703 if(FT2Module.Ft2QueryFontType(hdc, NULL) == FT2_FONTTYPE_TRUETYPE) {
704 pwtm->tmPitchAndFamily |= TMPF_TRUETYPE;
705 }
706 }
707 dprintfTextMetrics(pwtm);
708 return(rc);
709}
710//******************************************************************************
711//******************************************************************************
712BOOL WIN32API GetTextMetricsW( HDC hdc, LPTEXTMETRICW pwtm)
713{
714 BOOL rc;
715 TEXTMETRICA atm;
716
717 rc = GetTextMetricsA(hdc, &atm);
718 pwtm->tmHeight = atm.tmHeight;
719 pwtm->tmAscent = atm.tmAscent;
720 pwtm->tmDescent = atm.tmDescent;
721 pwtm->tmInternalLeading = atm.tmInternalLeading;
722 pwtm->tmExternalLeading = atm.tmExternalLeading;
723 pwtm->tmAveCharWidth = atm.tmAveCharWidth;
724 pwtm->tmMaxCharWidth = atm.tmMaxCharWidth;
725 pwtm->tmWeight = atm.tmWeight;
726 pwtm->tmOverhang = atm.tmOverhang;
727 pwtm->tmDigitizedAspectX = atm.tmDigitizedAspectX;
728 pwtm->tmDigitizedAspectY = atm.tmDigitizedAspectY;
729 pwtm->tmFirstChar = atm.tmFirstChar;
730 pwtm->tmLastChar = atm.tmLastChar;
731 pwtm->tmDefaultChar = atm.tmDefaultChar;
732 pwtm->tmBreakChar = atm.tmBreakChar;
733 pwtm->tmItalic = atm.tmItalic;
734 pwtm->tmUnderlined = atm.tmUnderlined;
735 pwtm->tmStruckOut = atm.tmStruckOut;
736 pwtm->tmPitchAndFamily = atm.tmPitchAndFamily;
737 pwtm->tmCharSet = atm.tmCharSet;
738
739 return(rc);
740}
741//******************************************************************************
742//******************************************************************************
743int WIN32API GetTextFaceA( HDC hdc, int nCount, LPSTR lpFaceName)
744{
745 int ret;
746
747 dprintf(("GDI32: GetTextFaceA %x %d %x", hdc, nCount, lpFaceName));
748 ret = O32_GetTextFace(hdc, nCount, lpFaceName);
749 if(ret > 0 && lpFaceName) {
750 dprintf(("GDI32: GetTextFaceA returned %s", lpFaceName));
751 }
752 //We should return the length including null terminator (WGSS doesn't)
753 if(!lpFaceName) ret++;
754
755 return ret;
756}
757//******************************************************************************
758//******************************************************************************
759int WIN32API GetTextFaceW( HDC hdc, int nCount, LPWSTR lpFaceName)
760{
761 char *astring = NULL;
762 int lenA = GetTextFaceA( hdc, 0, NULL );
763 int rc;
764
765 astring = ( char * )malloc( lenA );
766 if( astring == NULL ) //@@VP:2003-11-05 was 'if ( astring )'
767 return 0;
768
769 rc = GetTextFaceA(hdc, lenA, astring);
770
771 if( rc )
772 {
773 if( lpFaceName )
774 {
775 AsciiToUnicodeN(astring, lpFaceName, nCount);
776 rc = lstrlenW( lpFaceName );
777 }
778 else
779 rc = lstrlenAtoW( astring, -1 );
780
781 rc++; // including null-terminator
782 }
783
784 free(astring);
785
786 return rc;
787}
788//******************************************************************************
789//******************************************************************************
790UINT WIN32API GetOutlineTextMetricsA( HDC hdc, UINT arg2, LPOUTLINETEXTMETRICA arg3)
791{
792 dprintf(("GDI32: GetOutlineTextMetricsA %x %x %x", hdc, arg2, arg3));
793 return O32_GetOutlineTextMetrics(hdc, arg2, arg3);
794}
795//******************************************************************************
796//******************************************************************************
797UINT WIN32API GetOutlineTextMetricsW( HDC hdc, UINT arg2, LPOUTLINETEXTMETRICW arg3)
798{
799 dprintf(("!ERROR!: GDI32: GetOutlineTextMetricsW STUB"));
800 // NOTE: This will not work as is (needs UNICODE support)
801// return O32_GetOutlineTextMetrics(hdc, arg2, arg3);
802 return 0;
803}
804/*****************************************************************************
805 * Name : DWORD GetCharacterPlacementA
806 * Purpose : The GetCharacterPlacementA function retrieves information about
807 * a character string, such as character widths, caret positioning,
808 * ordering within the string, and glyph rendering. The type of
809 * information returned depends on the dwFlags parameter and is
810 * based on the currently selected font in the given display context.
811 * The function copies the information to the specified GCP_RESULTSA
812 * structure or to one or more arrays specified by the structure.
813 * Parameters: HDC hdc handle to device context
814 * LPCSTR lpString pointer to string
815 * int nCount number of characters in string
816 * int nMaxExtent maximum extent for displayed string
817 * LPGCP_RESULTSA *lpResults pointer to buffer for placement result
818 * DWORD dwFlags placement flags
819 * Variables :
820 * Result :
821 * Remark :
822 * Status : UNTESTED STUB
823 *
824 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
825 *****************************************************************************/
826
827DWORD WIN32API GetCharacterPlacementA(HDC hdc,
828 LPCSTR lpString,
829 int nCount,
830 int nMaxExtent,
831 GCP_RESULTSA * lpResults,
832 DWORD dwFlags)
833{
834 dprintf(("GDI32: GetCharacterPlacementA(%08xh,%s,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
835 hdc,
836 lpString,
837 nCount,
838 nMaxExtent,
839 lpResults,
840 dwFlags));
841
842 return (0);
843}
844
845/*****************************************************************************
846 * Name : DWORD GetCharacterPlacementW
847 * Purpose : The GetCharacterPlacementW function retrieves information about
848 * a character string, such as character widths, caret positioning,
849 * ordering within the string, and glyph rendering. The type of
850 * information returned depends on the dwFlags parameter and is
851 * based on the currently selected font in the given display context.
852 * The function copies the information to the specified GCP_RESULTSW
853 * structure or to one or more arrays specified by the structure.
854 * Parameters: HDC hdc handle to device context
855 * LPCSTR lpString pointer to string
856 * int nCount number of characters in string
857 * int nMaxExtent maximum extent for displayed string
858 * GCP_RESULTSW *lpResults pointer to buffer for placement result
859 * DWORD dwFlags placement flags
860 * Variables :
861 * Result :
862 * Remark :
863 * Status : Partly working
864 *
865 * Author : Borrowed Rewind Code
866 *****************************************************************************/
867
868DWORD WIN32API GetCharacterPlacementW(HDC hdc,
869 LPCWSTR lpString,
870 int uCount,
871 int nMaxExtent,
872 GCP_RESULTSW *lpResults,
873 DWORD dwFlags)
874{
875 return FT2Module.Ft2GetCharacterPlacementW(hdc, lpString, uCount, nMaxExtent, lpResults, dwFlags);
876}
877
878
879/***********************************************************************
880 * FONT_mbtowc
881 *
882 * Returns a '\0' terminated Unicode translation of str using the
883 * charset of the currently selected font in hdc. If count is -1 then
884 * str is assumed to be '\0' terminated, otherwise it contains the
885 * number of bytes to convert. If plenW is non-NULL, on return it
886 * will point to the number of WCHARs (excluding the '\0') that have
887 * been written. If pCP is non-NULL, on return it will point to the
888 * codepage used in the conversion (NB, this may be CP_SYMBOL so watch
889 * out). The caller should free the returned LPWSTR from the process
890 * heap itself.
891 */
892LPWSTR FONT_mbtowc(HDC hdc, LPCSTR str, INT count, INT *plenW, UINT *pCP)
893{
894 UINT cp = CP_ACP;
895 INT lenW, i;
896 LPWSTR strW;
897 CHARSETINFO csi;
898 int charset = GetTextCharset(hdc);
899
900 if( IsDBCSEnv() && ( charset == 0 ))
901 cp = CP_ACP;
902 else
903 /* Hmm, nicely designed api this one! */
904 if(TranslateCharsetInfo((DWORD*)charset, &csi, TCI_SRCCHARSET))
905 cp = csi.ciACP;
906 else {
907 switch(charset) {
908 case OEM_CHARSET:
909 cp = GetOEMCP();
910 break;
911 case DEFAULT_CHARSET:
912 cp = GetACP();
913 break;
914
915 case VISCII_CHARSET:
916 case TCVN_CHARSET:
917 case KOI8_CHARSET:
918 case ISO3_CHARSET:
919 case ISO4_CHARSET:
920 /* FIXME: These have no place here, but because x11drv
921 enumerates fonts with these (made up) charsets some apps
922 might use them and then the FIXME below would become
923 annoying. Now we could pick the intended codepage for
924 each of these, but since it's broken anyway we'll just
925 use CP_ACP and hope it'll go away...
926 */
927 cp = CP_ACP;
928 break;
929
930
931 default:
932 dprintf(("Can't find codepage for charset %d\n", charset));
933 break;
934 }
935 }
936
937 dprintf(("cp == %d\n", cp));
938
939 if(count == -1) count = strlen(str);
940 if(cp != CP_SYMBOL) {
941 lenW = MultiByteToWideChar(cp, 0, str, count, NULL, 0);
942 strW = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR));
943 MultiByteToWideChar(cp, 0, str, count, strW, lenW);
944 } else {
945 lenW = count;
946 strW = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR));
947 for(i = 0; i < count; i++) strW[i] = (BYTE)str[i];
948 }
949 strW[lenW] = '\0';
950 dprintf(("mapped %s -> %ls\n", str, strW));
951 if(plenW) *plenW = lenW;
952 if(pCP) *pCP = cp;
953 return strW;
954}
955
956/*************************************************************************
957 * GetGlyphIndicesA [GDI32.@]
958 */
959DWORD WINAPI GetGlyphIndicesA(HDC hdc, LPCSTR lpstr, INT count,
960 LPWORD pgi, DWORD flags)
961{
962 DWORD ret;
963 WCHAR *lpstrW;
964 INT countW;
965
966 dprintf(("GDI32: GetGlyphIndicesA (%p, %s, %d, %p, 0x%lx)\n",
967 hdc, lpstr, count, pgi, flags));
968
969 lpstrW = FONT_mbtowc(hdc, lpstr, count, &countW, NULL);
970 ret = GetGlyphIndicesW(hdc, lpstrW, countW, pgi, flags);
971 HeapFree(GetProcessHeap(), 0, lpstrW);
972
973 return ret;
974}
975
976/*************************************************************************
977 * GetGlyphIndicesW [GDI32.@]
978 */
979DWORD WINAPI GetGlyphIndicesW(HDC hdc, LPCWSTR lpstr, INT count,
980 LPWORD pgi, DWORD flags)
981{
982 DWORD ret;
983
984 dprintf(("GDI32: GetGlyphIndicesW (%ls, %d, %p, 0x%lx)",
985 lpstr, count, pgi, flags));
986
987 if(!hdc) return GDI_ERROR;
988
989 ret = FT2Module.Ft2GetGlyphIndices(hdc, lpstr, count , pgi, flags);
990 if(ret != GDI_ERROR) {
991 for(int i=0;i<ret;i++) {
992 dprintf(("GetGlyphIndices: %c (%x)-> %d", lpstr[i], lpstr[i], pgi[i]));
993 }
994 }
995 return ret;
996}
997
998/***********************************************************************
999 * GetGlyphOutlineA (GDI32.@)
1000 */
1001DWORD WINAPI GetGlyphOutlineA( HDC hdc, UINT uChar, UINT fuFormat,
1002 LPGLYPHMETRICS lpgm, DWORD cbBuffer,
1003 LPVOID lpBuffer, const MAT2 *lpmat2 )
1004{
1005 LPWSTR p = NULL;
1006 DWORD ret;
1007 UINT c;
1008
1009 if ((fuFormat & GGO_GLYPH_INDEX) == 0)
1010 {
1011 p = FONT_mbtowc(hdc, (char*)&uChar, 1, NULL, NULL);
1012 if (p)
1013 {
1014 c = p[0];
1015 }
1016 else
1017 {
1018 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1019 return GDI_ERROR;
1020 }
1021 }
1022 else
1023 {
1024 c = uChar;
1025 }
1026
1027 ret = GetGlyphOutlineW (hdc, c, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2);
1028
1029 if (p != NULL)
1030 {
1031 HeapFree (GetProcessHeap(), 0, p);
1032 }
1033
1034 return ret;
1035}
1036
1037/***********************************************************************
1038 * GetGlyphOutlineW (GDI32.@)
1039 */
1040DWORD WINAPI GetGlyphOutlineW( HDC hdc, UINT uChar, UINT fuFormat,
1041 LPGLYPHMETRICS lpgm, DWORD cbBuffer,
1042 LPVOID lpBuffer, const MAT2 *lpmat2 )
1043{
1044 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
1045
1046 dprintf(("GDI32: GetGlyphOutlineW(%p, %04x, %04x, %p, %ld, %p, %p)\n",
1047 pHps, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 ));
1048
1049 if (!hdc || !pHps)
1050 {
1051 SetLastError(ERROR_INVALID_PARAMETER);
1052 return GDI_ERROR;
1053 }
1054
1055 return FT2Module.Ft2GetGlyphOutline(pHps->hps, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2);
1056}
1057//******************************************************************************
1058//******************************************************************************
1059DWORD WIN32API GetKerningPairsA( HDC hdc, DWORD nNumPairs, LPKERNINGPAIR lpkrnpair)
1060{
1061 return O32_GetKerningPairs(hdc, nNumPairs, lpkrnpair);
1062}
1063//******************************************************************************
1064//******************************************************************************
Note: See TracBrowser for help on using the repository browser.