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

Last change on this file since 1699 was 1699, checked in by phaller, 26 years ago

Add: font remapping

File size: 15.9 KB
Line 
1/* $Id: font.cpp,v 1.4 1999-11-10 23:30:45 phaller Exp $ */
2
3/*
4 * GDI32 font apis
5 *
6 * Copyright 1999 Edgar Buerkle (Edgar.Buerkle@gmx.ne)
7 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
8 * Copyright 1998 Patrick Haller
9 *
10 * TODO: EnumFontsA/W, EnumFontFamiliesExA/W + others
11 *
12 * Project Odin Software License can be found in LICENSE.TXT
13 *
14 */
15
16#include <odin.h>
17#include <odinwrap.h>
18#include <os2sel.h>
19
20#include <os2win.h>
21#include <stdlib.h>
22#include <stdarg.h>
23#include <string.h>
24#include "misc.h"
25#include "unicode.h"
26#include <vmutex.h>
27#include <heapstring.h>
28#include <win\options.h>
29
30
31ODINDEBUGCHANNEL(GDI32-FONT)
32
33
34VMutex mutexProcWinA;
35VMutex mutexProcWinW;
36FONTENUMPROCA FontEnumProcWinA;
37FONTENUMPROCW FontEnumProcWinW;
38
39
40/*****************************************************************************
41 * Name : static void iFontRename
42 * Purpose : font remapping table to map win32 fonts to OS/2 pendants
43 * Parameters: LPSTR lpstrFaceOriginal - the win32 face name
44 * LPSTR lpstrFaceBuffer - [LF_FACESIZE] buffer to new name
45 * Variables :
46 * Result :
47 * Remark : remapped name is passed back in the buffer
48 * if no mapping pendant is available, return input parameter
49 * as default.
50 * Status :
51 *
52 * Author : Patrick Haller [Fri, 1998/06/12 03:44]
53 *****************************************************************************/
54
55#define ODINFONTSECTION "Font Mapping"
56static void iFontRename(LPCSTR lpstrFaceOriginal,
57 LPSTR lpstrFaceTemp)
58{
59 int iRet;
60
61 // NULL is a valid parameter
62 if (lpstrFaceOriginal == NULL)
63 return;
64
65 memcpy(lpstrFaceTemp, lpstrFaceOriginal, LF_FACESIZE);
66 strupr(lpstrFaceTemp);
67
68 //lookup table
69 iRet = PROFILE_GetOdinIniString(ODINFONTSECTION,
70 lpstrFaceTemp,
71 lpstrFaceOriginal,
72 lpstrFaceTemp,
73 LF_FACESIZE);
74}
75
76
77//******************************************************************************
78//******************************************************************************
79ODINFUNCTION14(HFONT, CreateFontA,
80 int, nHeight,
81 int, nWidth,
82 int, nEscapement,
83 int, nOrientation,
84 int, fnWeight,
85 DWORD, fdwItalic,
86 DWORD, fdwUnderline,
87 DWORD, fdwStrikeOut,
88 DWORD, fdwCharSet,
89 DWORD, fdwOutputPrecision,
90 DWORD, fdwClipPrecision,
91 DWORD, fdwQuality,
92 DWORD, fdwPitchAndFamily,
93 LPCSTR, lpszFace)
94{
95 CHAR lpstrFaceNew[LF_FACESIZE];
96 HFONT hFont;
97
98 iFontRename(lpszFace, lpstrFaceNew);
99
100 dprintf(("lpszFace = %s -> %s\n", lpszFace, lpstrFaceNew));
101
102 hFont = O32_CreateFont(nHeight,
103 nWidth,
104 nEscapement,
105 nOrientation,
106 fnWeight,
107 fdwItalic,
108 fdwUnderline,
109 fdwStrikeOut,
110 fdwCharSet,
111 fdwOutputPrecision,
112 fdwClipPrecision,
113 fdwQuality,
114 fdwPitchAndFamily,
115 lpszFace != NULL ? lpstrFaceNew : NULL);
116 return hFont;
117}
118//******************************************************************************
119//******************************************************************************
120ODINFUNCTION14(HFONT, CreateFontW,
121 int, nHeight,
122 int, nWidth,
123 int, nEscapement,
124 int, nOrientation,
125 int, fnWeight,
126 DWORD, fdwItalic,
127 DWORD, fdwUnderline,
128 DWORD, fdwStrikeOut,
129 DWORD, fdwCharSet,
130 DWORD, fdwOutputPrecision,
131 DWORD, fdwClipPrecision,
132 DWORD, fdwQuality,
133 DWORD, fdwPitchAndFamily,
134 LPCWSTR,lpszFace)
135{
136 char *astring;
137 HFONT hFont;
138
139 // NULL is valid for lpszFace
140 if(lpszFace != NULL)
141 astring = UnicodeToAsciiString((LPWSTR)lpszFace);
142 else
143 astring = NULL;
144
145 // @@@PH switch to ODIN_ later
146 hFont = CreateFontA(nHeight,
147 nWidth,
148 nEscapement,
149 nOrientation,
150 fnWeight,
151 fdwItalic,
152 fdwUnderline,
153 fdwStrikeOut,
154 fdwCharSet,
155 fdwOutputPrecision,
156 fdwClipPrecision,
157 fdwQuality,
158 fdwPitchAndFamily,
159 astring);
160 if (astring != NULL)
161 FreeAsciiString(astring);
162
163 return(hFont);
164}
165
166//******************************************************************************
167//******************************************************************************
168ODINFUNCTION1(HFONT,CreateFontIndirectA,const LOGFONTA*, lplf)
169{
170 HFONT hFont;
171 LOGFONTA afont;
172
173 // don't touch user buffer!
174 memcpy(&afont, lplf, sizeof(LOGFONTA));
175 iFontRename(lplf->lfFaceName, afont.lfFaceName);
176
177 dprintf(("lpszFace = %s -> %s\n", lplf->lfFaceName, afont.lfFaceName));
178
179 dprintf(("GDI32: CreateFontIndirectA\n"));
180 dprintf(("GDI32: lfHeight = %d\n", lplf->lfHeight));
181 dprintf(("GDI32: lfWidth = %d\n", lplf->lfWidth));
182 dprintf(("GDI32: lfEscapement = %d\n", lplf->lfEscapement));
183 dprintf(("GDI32: lfOrientation = %d\n", lplf->lfOrientation));
184 dprintf(("GDI32: lfWeight = %d\n", lplf->lfWeight));
185 dprintf(("GDI32: lfItalic = %d\n", lplf->lfItalic));
186 dprintf(("GDI32: lfUnderline = %d\n", lplf->lfUnderline));
187 dprintf(("GDI32: lfStrikeOut = %d\n", lplf->lfStrikeOut));
188 dprintf(("GDI32: lfCharSet = %X\n", lplf->lfCharSet));
189 dprintf(("GDI32: lfOutPrecision = %X\n", lplf->lfOutPrecision));
190 dprintf(("GDI32: lfClipPrecision = %X\n", lplf->lfClipPrecision));
191 dprintf(("GDI32: lfQuality = %X\n", lplf->lfQuality));
192 dprintf(("GDI32: lfPitchAndFamily= %X\n", lplf->lfPitchAndFamily));
193 dprintf(("GDI32: lfFaceName = %s\n", lplf->lfFaceName));
194
195 hFont = O32_CreateFontIndirect(&afont);
196
197 return(hFont);
198}
199//******************************************************************************
200//******************************************************************************
201ODINFUNCTION1(HFONT, CreateFontIndirectW,const LOGFONTW *, lplf)
202{
203 LOGFONTA afont;
204 HFONT hfont;
205
206 //memcpy(&afont, lplf, ((int)&afont.lfFaceName - (int)&afont));
207 memcpy(&afont, lplf, sizeof(LOGFONTA));
208 memset(afont.lfFaceName, 0, LF_FACESIZE);
209 UnicodeToAsciiN((WCHAR *)lplf->lfFaceName, afont.lfFaceName, LF_FACESIZE-1);
210 hfont = CreateFontIndirectA(&afont);
211 return(hfont);
212}
213//******************************************************************************
214//******************************************************************************
215int EXPENTRY_O32 EnumFontProcA(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA
216 lpTextM, DWORD arg3, LPARAM arg4)
217{
218 return FontEnumProcWinA(lpLogFont, lpTextM, arg3, arg4);
219}
220//******************************************************************************
221//******************************************************************************
222int EXPENTRY_O32 EnumFontProcW(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA lpTextM,
223 DWORD arg3, LPARAM arg4)
224{
225 ENUMLOGFONTW LogFont;
226 int rc;
227
228 memcpy(&LogFont, lpLogFont, ((int)&LogFont.elfLogFont.lfFaceName -
229 (int)&LogFont));
230 AsciiToUnicodeN(lpLogFont->elfLogFont.lfFaceName, LogFont.elfLogFont.lfFaceName, LF_FACESIZE-1);
231 AsciiToUnicodeN((char *) lpLogFont->elfFullName, LogFont.elfFullName, LF_FULLFACESIZE-1);
232 AsciiToUnicodeN((char *) lpLogFont->elfStyle, LogFont.elfStyle, LF_FACESIZE-1);
233
234 rc = FontEnumProcWinW(&LogFont, (LPNEWTEXTMETRICW) lpTextM, arg3, arg4);
235 return rc;
236}
237//******************************************************************************
238//******************************************************************************
239int WIN32API EnumFontsA( HDC arg1, LPCSTR arg2, FONTENUMPROCA arg3, LPARAM arg4)
240{
241 dprintf(("GDI32: OS2EnumFontsA"));
242// return O32_EnumFonts(arg1, arg2, arg3, arg4);
243 return 1;
244}
245//******************************************************************************
246//TODO: Callback
247//******************************************************************************
248int WIN32API EnumFontsW( HDC arg1, LPCWSTR arg2, FONTENUMPROCW arg3, LPARAM arg4)
249{
250 dprintf(("GDI32: OS2EnumFontsW - stub (1)"));
251 // NOTE: This will not work as is (needs UNICODE support)
252// return O32_EnumFonts(arg1, arg2, arg3, arg4);
253 return 1;
254}
255//******************************************************************************
256//******************************************************************************
257int WIN32API EnumFontFamiliesA(HDC arg1,
258 LPCSTR arg2,
259 FONTENUMPROCA arg3,
260 LPARAM arg4)
261{
262 int rc;
263
264 dprintf(("GDI32: OS2EnumFontFamiliesA "));
265
266 mutexProcWinA.enter();
267
268 FontEnumProcWinA = arg3;
269
270 rc = O32_EnumFontFamilies(arg1, arg2, &EnumFontProcA, arg4);
271
272 mutexProcWinA.leave();
273 return rc;
274}
275//******************************************************************************
276//******************************************************************************
277int WIN32API EnumFontFamiliesW(HDC arg1,
278 LPCWSTR arg2,
279 FONTENUMPROCW arg3,
280 LPARAM arg4)
281{
282 int rc;
283 char *astring = UnicodeToAsciiString((LPWSTR)arg2);
284
285 dprintf(("GDI32: OS2EnumFontFamiliesW "));
286
287 mutexProcWinW.enter();
288
289 FontEnumProcWinW = arg3;
290
291 rc = O32_EnumFontFamilies(arg1, astring, &EnumFontProcW, arg4);
292
293 mutexProcWinW.leave();
294
295 FreeAsciiString(astring);
296 return rc;
297}
298//******************************************************************************
299//******************************************************************************
300INT WIN32API EnumFontFamiliesExA( HDC arg1, LPLOGFONTA arg2, FONTENUMPROCEXA arg3, LPARAM arg4, DWORD dwFlags)
301{
302 dprintf(("GDI32: OS2EnumFontFamiliesExA, not implemented\n"));
303 return 0;
304}
305//******************************************************************************
306//******************************************************************************
307INT WIN32API EnumFontFamiliesExW( HDC arg1, LPLOGFONTW arg2, FONTENUMPROCEXW arg3, LPARAM arg4, DWORD dwFlags)
308{
309 dprintf(("GDI32: OS2EnumFontFamiliesW, not implemented\n"));
310 // NOTE: This will not work as is (needs UNICODE support)
311 return 0;
312}
313//******************************************************************************
314//******************************************************************************
315DWORD WIN32API GetFontData(HDC hdc, DWORD dwTable, DWORD dwOffset, LPVOID lpvBuffer,
316 DWORD dbData)
317{
318 dprintf(("GDI32: GetFontData, not implemented (GDI_ERROR)\n"));
319 return(GDI_ERROR);
320}
321//******************************************************************************
322//******************************************************************************
323int WIN32API AddFontResourceA( LPCSTR arg1)
324{
325 dprintf(("GDI32: OS2AddFontResourceA"));
326 return O32_AddFontResource(arg1);
327}
328//******************************************************************************
329//******************************************************************************
330int WIN32API AddFontResourceW( LPCWSTR arg1)
331{
332 dprintf(("GDI32: OS2AddFontResourceW STUB"));
333 // NOTE: This will not work as is (needs UNICODE support)
334// return O32_AddFontResource(arg1);
335 return 0;
336}
337//******************************************************************************
338//******************************************************************************
339BOOL WIN32API RemoveFontResourceA( LPCSTR arg1)
340{
341 dprintf(("GDI32: OS2RemoveFontResourceA %s\n", arg1));
342 return O32_RemoveFontResource(arg1);
343}
344//******************************************************************************
345//******************************************************************************
346BOOL WIN32API RemoveFontResourceW(LPCWSTR arg1)
347{
348 char *astring = UnicodeToAsciiString((LPWSTR)arg1);
349 BOOL rc;
350
351 dprintf(("GDI32: OS2RemoveFontResourceW\n"));
352 rc = O32_RemoveFontResource(astring);
353 FreeAsciiString(astring);
354 return(rc);
355}
356/*****************************************************************************
357 * Name : BOOL CreateScalableFontResourceA
358 * Purpose : The CreateScalableFontResourceA function creates a font resource
359 * file for a scalable font.
360 * Parameters: DWORD fdwHidden flag for read-only embedded font
361 * LPCSTR lpszFontRes address of filename for font resource
362 * LPCSTR lpszFontFile address of filename for scalable font
363 * LPCSTR lpszCurrentPath address of path to font file
364 * Variables :
365 * Result : TRUE / FALSE
366 * Remark :
367 * Status : UNTESTED STUB
368 *
369 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
370 *****************************************************************************/
371
372BOOL WIN32API CreateScalableFontResourceA(DWORD fdwHidden,
373 LPCSTR lpszFontRes,
374 LPCSTR lpszFontFile,
375 LPCSTR lpszCurrentPath)
376{
377 dprintf(("GDI32: CreateScalableFontResourceA(%08xh,%08xh,%08xh,%08xh) not implemented.\n",
378 fdwHidden,
379 lpszFontRes,
380 lpszFontFile,
381 lpszCurrentPath));
382
383 return (FALSE);
384}
385
386
387/*****************************************************************************
388 * Name : BOOL CreateScalableFontResourceW
389 * Purpose : The CreateScalableFontResourceW function creates a font resource
390 * file for a scalable font.
391 * Parameters: DWORD fdwHidden flag for read-only embedded font
392 * LPCSTR lpszFontRes address of filename for font resource
393 * LPCSTR lpszFontFile address of filename for scalable font
394 * LPCSTR lpszCurrentPath address of path to font file
395 * Variables :
396 * Result : TRUE / FALSE
397 * Remark :
398 * Status : UNTESTED STUB
399 *
400 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
401 *****************************************************************************/
402
403BOOL WIN32API CreateScalableFontResourceW(DWORD fdwHidden,
404 LPCWSTR lpszFontRes,
405 LPCWSTR lpszFontFile,
406 LPCWSTR lpszCurrentPath)
407{
408 dprintf(("GDI32: CreateScalableFontResourceW(%08xh,%08xh,%08xh,%08xh) not implemented.\n",
409 fdwHidden,
410 lpszFontRes,
411 lpszFontFile,
412 lpszCurrentPath));
413
414 return (FALSE);
415}
416/*****************************************************************************
417 * Name : DWORD GetFontLanguageInfo
418 * Purpose : The GetFontLanguageInfo function returns information about the
419 * currently selected font for the specified display context.
420 * Applications typically use this information and the
421 * GetCharacterPlacement function to prepare a character string for display.
422 * Parameters: HDC hdc handle to device context
423 * Variables :
424 * Result :
425 * Remark :
426 * Status : UNTESTED STUB
427 *
428 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
429 *****************************************************************************/
430
431DWORD WIN32API GetFontLanguageInfo(HDC hdc)
432{
433 dprintf(("GDI32: GetFontLanguageInfo(%08xh) not implemented.\n",
434 hdc));
435
436 return (0);
437}
438//******************************************************************************
439//******************************************************************************
Note: See TracBrowser for help on using the repository browser.