|
|
1.1 root 1: //--------------------------------------------------------------------------
2: //
3: // Module Name: TTFONTS.C
4: //
5: // Brief Description: This module contains the PSCRIPT driver's User
6: // TrueType font substitution functions and related routines.
7: //
8: // Author: Kent Settle (kentse)
9: // Created: 27-May-1992
10: //
11: // Copyright (c) 1992 Microsoft Corporation
12: //--------------------------------------------------------------------------
13:
14: #include <stddef.h>
15: #include <stdlib.h>
16: #include <string.h>
17: #include "pscript.h"
18: #include "enable.h"
19: #include <winspool.h>
20: #include "dlgdefs.h"
21: #include "pscrptui.h"
22: #include "help.h"
23:
24: extern TT_FONT_MAPPING TTFontTable[]; // ..\pscript\tables.h.
25:
26: // global data.
27:
28: HANDLE hPrinter;
29:
30: // declarations of routines defined within this module.
31:
32: LONG TTFontDialogProc(HWND, UINT, DWORD, LONG);
33: int iFontCallback (PLOGFONT, PTEXTMETRIC, ULONG, PENUMDATA);
34: int iFaceCallback (PLOGFONT, PTEXTMETRIC, ULONG, PENUMDATA);
35: BOOL SetDefaultTTMappings(HWND);
36: int TTToDefaultPF(HWND, int);
37:
38: //--------------------------------------------------------------------------
39: // LONG TTFontDialogProc(hwnd, usMsg, wParam, lParam)
40: // HWND hwnd;
41: // UINT usMsg;
42: // DWORD wParam;
43: // LONG lParam;
44: //
45: // This routine services the TrueType Font Handling dialog box.
46: //
47: // History:
48: // 20-May-1992 -by- Kent Settle (kentse)
49: // Wrote it.
50: //--------------------------------------------------------------------------
51:
52: LONG TTFontDialogProc(hwnd, usMsg, wParam, lParam)
53: HWND hwnd;
54: UINT usMsg;
55: DWORD wParam;
56: LONG lParam;
57: {
58: HDC hdc;
59: ENUMDATA EnumData;
60: PNTPD pntpd;
61: BYTE *pfont;
62: DWORD i, iFont, rc;
63: PNTFM pntfm;
64: HANDLE hRes;
65: HANDLE hFontRes;
66: PWSTR pwstrFontName;
67: int iTTFont, iDevFont;
68: WCHAR wstrTTFont[MAX_FONTNAME], wstrDevFont[MAX_FONTNAME];
69: PWSTR pwstrTTFont, pwstrDevFont;
70: WCHAR wcbuf[MAX_FONTNAME];
71: int cTTFonts;
72: DWORD cb, dwType, cbTable;
73: PRINTDATA *pdata;
74: WCHAR *pbuf;
75: WCHAR *pbufsave;
76: BOOL bFound;
77:
78: switch(usMsg)
79: {
80: case WM_INITDIALOG:
81: // get a local pointer to our PRINTER handle.
82:
83: pdata = (PRINTDATA *)lParam;
84: hPrinter = pdata->hPrinter;
85:
86: // save the PRINTDATA.
87:
88: SetWindowLong(hwnd, GWL_USERDATA, lParam);
89:
90: // get the current DC so we can enumerate the TrueType fonts.
91:
92: hdc = GetDC(hwnd);
93:
94: // now enumerate the TrueType fonts, inserting them into the
95: // appropriate list box.
96:
97: EnumData.hwnd = hwnd;
98: EnumData.hdc = hdc;
99:
100: EnumFonts(hdc, (LPCWSTR)NULL, (FONTENUMPROC)iFontCallback, (LPARAM)&EnumData);
101:
102: // release the current DC.
103:
104: ReleaseDC(hwnd, hdc);
105:
106: // get a pointer to the current NTPD structure, from which we
107: // can get the list of printer fonts supported.
108:
109: pntpd = MapPrinter(hPrinter);
110:
111: if (!pntpd)
112: {
113: RIP("PSCRPTUI!TTFontDialogProc: MapPrinter Failed.\n");
114: return(FALSE);
115: }
116:
117: // get a pointer to the fonts for the current device.
118:
119: pfont = (BYTE *)pntpd + pntpd->loFonts;
120:
121: for (i = 0; i < (DWORD)pntpd->cFonts; i++)
122: {
123: iFont = (DWORD)pfont[i];
124:
125: // find the font resource in question.
126:
127: if (!(hRes = FindResource(hModule, MAKEINTRESOURCE(iFont),
128: MAKEINTRESOURCE(MYFONT))))
129: {
130: RIP("PSCRPTUI!TTFontDialogProc: Couldn't find font resource\n");
131: return(FALSE);
132: }
133:
134: // get the handle to the resource.
135:
136: if (!(hFontRes = LoadResource(hModule, hRes)))
137: {
138: RIP("PSCRPTUI!TTFontDialogProc: LoadResource failed.\n");
139: return(FALSE);
140: }
141:
142: // get a pointer to the resource data.
143:
144: if (!(pntfm = (PNTFM)LockResource(hFontRes)))
145: {
146: RIP("PSCRPTUI!TTFontDialogProc: LockResource failed.\n");
147: FreeResource(hFontRes);
148: return(FALSE);
149: }
150:
151: // get the name of the font. this is what we will
152: // insert into the printer font list box.
153:
154: pwstrFontName = wcbuf;
155: strcpy2WChar(pwstrFontName, (PSTR)pntfm + pntfm->loszFontName);
156:
157: rc = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
158: LB_ADDSTRING, (WPARAM)0,
159: (LPARAM)pwstrFontName);
160:
161: if (rc == LB_ERR)
162: {
163: RIP("PSCRPTUI!TTFontDialogProc: LB_INSERTSTRING failed.\n");
164: UnlockResource(hFontRes);
165: FreeResource(hFontRes);
166: return(FALSE);
167: }
168:
169: // free up the font resource.
170:
171: UnlockResource(hFontRes);
172: FreeResource(hFontRes);
173: }
174:
175: // free up the NTPD structure.
176:
177: if (pntpd)
178: GlobalFree((HGLOBAL)pntpd);
179:
180: // insert 'Download as Soft Font' as first entry in printer font
181: // list box.
182:
183: LoadString(hModule, (IDS_DOWNLOAD_SOFTFONT + STRING_BASE),
184: wcbuf, (sizeof(wcbuf) / 2));
185:
186: rc = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
187: LB_INSERTSTRING, (WPARAM)0,
188: (LPARAM)wcbuf);
189:
190: if (rc == LB_ERR)
191: {
192: RIP("PSCRPTUI:TTFontDialogProc: 2nd LB_INSERTSTRING failed.\n");
193: return(FALSE);
194: }
195:
196: if (!SetDefaultTTMappings(hwnd))
197: {
198: RIP("PSCRPTUI!TTFontDialogProc: SetDefaultTTMappings failed.\n");
199: return(FALSE);
200: }
201:
202: pwstrTTFont = wstrTTFont;
203: pwstrDevFont = wstrDevFont;
204:
205: // now get the count of TrueType fonts in the list box.
206:
207: cTTFonts = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
208: LB_GETCOUNT, (WPARAM)0,
209: (LPARAM)0);
210:
211: // see if the font substitution table has been written to the
212: // registry. the list boxes are currently set for the default,
213: // so if the table is not there, leave the list boxes as is.
214:
215: LoadString(hModule, (IDS_FONT_SUBST_SIZE + STRING_BASE),
216: wcbuf, (sizeof(wcbuf) / sizeof(wcbuf[0])));
217:
218: rc = GetPrinterData(hPrinter, wcbuf, (DWORD *)&dwType,
219: (LPBYTE)&cbTable, sizeof(cbTable), &cb);
220:
221: if ((rc == ERROR_SUCCESS) && (cbTable) && (cTTFonts))
222: {
223: // create a buffer to read the substitution table into,
224: // then read it from the registry into the buffer.
225:
226: // allocate buffer.
227:
228: if (!(pbuf = (WCHAR *)GlobalAlloc(GMEM_FIXED |
229: GMEM_ZEROINIT, cbTable)))
230: {
231: RIP("PSCRPTUI!TTFontDialogProc: GlobalAlloc pbuf failed.\n");
232: return(FALSE);
233: }
234:
235: pbufsave = pbuf;
236:
237: // now copy the table to our buffer.
238:
239: LoadString(hModule, (IDS_FONT_SUBST_TABLE + STRING_BASE),
240: wcbuf, (sizeof(wcbuf) / sizeof(wcbuf[0])));
241:
242: rc = GetPrinterData(hPrinter, wcbuf, (DWORD *)&dwType,
243: (LPBYTE)pbuf, cbTable, &cb);
244:
245: // force the defaults.
246:
247: if (rc == ERROR_SUCCESS)
248: {
249: // run through the entire list of TrueType fonts in
250: // the TT font list box. get the TT font pairs that
251: // exist in the registry.
252:
253: for (iTTFont = 0; iTTFont < cTTFonts; iTTFont++)
254: {
255: // get the name of the TT font.
256:
257: rc = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
258: LB_GETTEXT, (WPARAM)iTTFont,
259: (LPARAM)pwstrTTFont);
260:
261: if (rc == LB_ERR)
262: {
263: RIP("PSCRPTUI!TTFontDialogProc: LB_GETTEXT failed.\n");
264: return(FALSE);
265: }
266:
267: // now search the font substitution table for a matching TrueType font.
268: // the substitution table is in the following format: a NULL terminated
269: // UNICODE TrueType font name followed by the matching NULL terminated
270: // device font name. this sequence is repeated until a double NULL
271: // terminator ends the table.
272:
273: pbuf = pbufsave;
274: bFound = FALSE;
275:
276: while (*pbuf)
277: {
278: if (!(wcscmp(pbuf, pwstrTTFont)))
279: {
280: // we found the TrueType font, now get the matching device font.
281:
282: pbuf += (wcslen(pbuf) + 1);
283: wcsncpy(wstrDevFont, pbuf,
284: (sizeof(wstrDevFont) / sizeof(wstrDevFont[0])));
285: bFound = TRUE;
286: break;
287: }
288: else
289: {
290: // this was not the font in question. skip over both font names.
291:
292: pbuf += (wcslen(pbuf) + 1);
293: pbuf += (wcslen(pbuf) + 1);
294: }
295: }
296:
297: // if we could not get a corresponding device font for
298: // any reason, ignore it. the default device font will
299: // be set for this TrueType font.
300:
301: if (!bFound)
302: break;
303:
304: // find the index into the printer font list box
305: // of the corresponding printer font.
306:
307: rc = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
308: LB_FINDSTRING, (WPARAM)-1,
309: (LPARAM)pwstrDevFont);
310:
311: if (rc != LB_ERR)
312: SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
313: LB_SETITEMDATA, (WPARAM)iTTFont,
314: (LPARAM)rc);
315: }
316: }
317: }
318:
319: GlobalFree((HGLOBAL)pbufsave);
320:
321: // select the first item in the truetype fonts list box, then
322: // select the corresponding item in the printer fonts list box.
323:
324: SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX, LB_SETCURSEL,
325: (WPARAM)0, (LPARAM)0);
326:
327: rc = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX, LB_GETITEMDATA,
328: (WPARAM)0, (LPARAM)0);
329:
330: SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX, LB_SETCURSEL,
331: (WPARAM)rc, (LPARAM)0);
332:
333: // intialize the help stuff.
334:
335: vHelpInit();
336:
337: // disable some stuff if the user does not have permission to
338: // change anything.
339:
340: if (!pdata->bPermission)
341: {
342: EnableWindow(GetDlgItem(hwnd, IDD_PRINTER_FONT_LIST_BOX), FALSE);
343: EnableWindow(GetDlgItem(hwnd, IDD_TT_DEFAULT_PUSH_BUTTON), FALSE);
344: }
345:
346: return(TRUE);
347:
348: case WM_COMMAND:
349: pdata = (PRINTDATA *)GetWindowLong(hwnd, GWL_USERDATA);
350:
351: switch(LOWORD(wParam))
352: {
353: case IDOK:
354: // first write out the number of TT fonts we need to
355: // deal with.
356:
357: cTTFonts = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
358: LB_GETCOUNT, (WPARAM)0,
359: (LPARAM)0);
360:
361: if (cTTFonts == LB_ERR)
362: {
363: EndDialog (hwnd, IDOK);
364: return(TRUE);
365: }
366:
367: pwstrTTFont = wstrTTFont;
368: pwstrDevFont = wstrDevFont;
369:
370: // run through the entire list of TrueType fonts in
371: // the TT font list box. get the TT font name, and
372: // the corresponding device font name. determine
373: // how large a buffer we need to allocate for our
374: // font substitution table.
375:
376: // allow room for the double NULL terminator.
377:
378: cb = 1;
379:
380: for (iTTFont = 0; iTTFont < cTTFonts; iTTFont++)
381: {
382: // get the name of the TT font.
383:
384: rc = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
385: LB_GETTEXT, (WPARAM)iTTFont,
386: (LPARAM)pwstrTTFont);
387:
388: if (rc == LB_ERR)
389: {
390: RIP("PSCRPTUI!TTFontDialogProc: LB_GETTEXT failed.\n");
391: return(FALSE);
392: }
393:
394: // get the index of the corresponding printer font.
395:
396: iDevFont = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
397: LB_GETITEMDATA, (WPARAM)iTTFont,
398: (LPARAM)0);
399:
400: if (iDevFont == LB_ERR)
401: {
402: RIP("PSCRPTUI!IDOK: LB_GETITEMDATA failed.\n");
403: return(FALSE);
404: }
405:
406: // get the name of the corresponding printer font, if there is
407: // one.
408:
409: rc = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
410: LB_GETTEXT, (WPARAM)iDevFont,
411: (LPARAM)pwstrDevFont);
412: if (rc == LB_ERR)
413: {
414: RIP("PSCRPTUI!TTFontDialogProc: LB_GETTEXT failed.\n");
415: return(FALSE);
416: }
417:
418: cb += (wcslen(pwstrTTFont) + 1);
419: cb += (wcslen(pwstrDevFont) + 1);
420: }
421:
422: cb *= sizeof(WCHAR);
423:
424: // allocate buffer.
425:
426: if (!(pbuf = (WCHAR *)GlobalAlloc(GMEM_FIXED |
427: GMEM_ZEROINIT, cb)))
428: {
429: RIP("PSCRPTUI!TTFontDialogProc: GlobalAlloc pbuf failed.\n");
430: return(FALSE);
431: }
432:
433: pbufsave = pbuf;
434:
435: // run through the entire list of TrueType fonts in
436: // the TT font list box. get the TT font name, and
437: // the corresponding device font name. write out the
438: // font substitution table in the following form:
439: // a NULL terminated UNICODE TrueType font name followed
440: // by the matching NULL terminated device font name.
441: // this sequence is repeated until a double NULL
442: // terminator ends the table.
443:
444: for (iTTFont = 0; iTTFont < cTTFonts; iTTFont++)
445: {
446: // get the name of the TT font.
447:
448: rc = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
449: LB_GETTEXT, (WPARAM)iTTFont,
450: (LPARAM)pwstrTTFont);
451:
452: if (rc == LB_ERR)
453: {
454: RIP("PSCRPTUI!TTFontDialogProc: LB_GETTEXT failed.\n");
455: return(FALSE);
456: }
457:
458: // get the index of the corresponding printer font.
459:
460: iDevFont = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
461: LB_GETITEMDATA, (WPARAM)iTTFont,
462: (LPARAM)0);
463:
464: if (iDevFont == LB_ERR)
465: {
466: RIP("PSCRPTUI!IDOK: LB_GETITEMDATA failed.\n");
467: return(FALSE);
468: }
469:
470: // get the name of the corresponding printer font, if there is
471: // one.
472:
473: rc = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
474: LB_GETTEXT, (WPARAM)iDevFont,
475: (LPARAM)pwstrDevFont);
476: if (rc == LB_ERR)
477: {
478: RIP("PSCRPTUI!TTFontDialogProc: LB_GETTEXT failed.\n");
479: return(FALSE);
480: }
481:
482: wcscpy(pbuf, pwstrTTFont);
483: pbuf += (wcslen(pwstrTTFont) + 1);
484:
485: wcscpy(pbuf, pwstrDevFont);
486: pbuf += (wcslen(pwstrDevFont) + 1);
487: }
488:
489: // add the double NULL terminator.
490:
491: *pbuf = (WCHAR)'\0';
492:
493: // write out size of mapping table to registry.
494:
495: LoadString(hModule, (IDS_FONT_SUBST_SIZE + STRING_BASE),
496: wcbuf, (sizeof(wcbuf) / sizeof(wcbuf[0])));
497:
498: SetPrinterData(pdata->hPrinter, wcbuf, REG_DWORD,
499: (LPBYTE)&cb, sizeof(cb));
500:
501: // write out the mapping table itself to the registry.
502:
503: LoadString(hModule, (IDS_FONT_SUBST_TABLE + STRING_BASE),
504: wcbuf, (sizeof(wcbuf) / sizeof(wcbuf[0])));
505:
506: SetPrinterData(pdata->hPrinter, wcbuf, REG_BINARY,
507: (LPBYTE)pbufsave, cb);
508:
509: GlobalFree((HGLOBAL)pbufsave);
510:
511: EndDialog (hwnd, IDOK);
512: return(TRUE);
513:
514: case IDCANCEL:
515: EndDialog (hwnd, IDCANCEL);
516: return(TRUE);
517:
518: case IDD_TT_DEFAULT_PUSH_BUTTON:
519: // reset the default font mappings.
520:
521: SetDefaultTTMappings(hwnd);
522:
523: // find the currently selected TT font, and select the
524: // corresponding default printer font.
525:
526: iTTFont = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
527: LB_GETCURSEL, (WPARAM)0,
528: (LPARAM)0);
529:
530: // select the first TT font if there was a problem.
531:
532: if (iTTFont == LB_ERR)
533: iTTFont = 0;
534:
535: iDevFont = TTToDefaultPF(hwnd, iTTFont);
536:
537: if (iDevFont == -1)
538: {
539: RIP("PSCRPTUI!IDD_DEFAULT_PUSH_BUTTON: TTToDefaultPF failed.\n");
540: return(FALSE);
541: }
542:
543: SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
544: LB_SETCURSEL, (WPARAM)iDevFont, (LPARAM)0);
545:
546: return(TRUE);
547:
548: case IDD_HELP_BUTTON:
549: vShowHelp(hwnd, HELP_CONTEXT, HLP_FONT_SUBST,
550: pdata->hPrinter);
551: return(TRUE);
552:
553: case IDD_TTFONT_LIST_BOX:
554: if (HIWORD (wParam) != LBN_SELCHANGE)
555: return (FALSE);
556:
557: // find the currently selected TT font, and select the
558: // corresponding default printer font.
559:
560: iTTFont = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
561: LB_GETCURSEL, (WPARAM)0,
562: (LPARAM)0);
563:
564: // do nothing if nothing was selected.
565:
566: if (iTTFont == LB_ERR)
567: return(FALSE);
568:
569: // get the index of the corresponding printer font.
570:
571: iDevFont = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
572: LB_GETITEMDATA, (WPARAM)iTTFont,
573: (LPARAM)0);
574:
575: if (iDevFont == LB_ERR)
576: {
577: RIP("PSCRPTUI!IDD_TTFONT_LIST_BOX: LB_GETITEMDATA failed.\n");
578: return(FALSE);
579: }
580:
581: SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
582: LB_SETCURSEL, (WPARAM)iDevFont, (LPARAM)0);
583:
584: return(TRUE);
585:
586: case IDD_PRINTER_FONT_LIST_BOX:
587: if (HIWORD (wParam) != LBN_SELCHANGE)
588: return (FALSE);
589:
590: // set the item data for the currently selected TT font
591: // equal to the index of the currently selected printer
592: // font.
593:
594: iTTFont = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
595: LB_GETCURSEL, (WPARAM)0,
596: (LPARAM)0);
597:
598: iDevFont = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
599: LB_GETCURSEL, (WPARAM)0,
600: (LPARAM)0);
601:
602: SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX,
603: LB_SETITEMDATA, (WPARAM)iTTFont,
604: (LPARAM)iDevFont);
605:
606: return(TRUE);
607:
608: default:
609: return(FALSE);
610: }
611:
612: break;
613:
614: case WM_DESTROY:
615: // clean up any used help stuff.
616:
617: vHelpDone(hwnd);
618: return (TRUE);
619:
620: default:
621: return (FALSE);
622: }
623:
624: return (FALSE);
625: }
626:
627:
628: //--------------------------------------------------------------------------
629: // int iFontCallback (plf, ptm, ulFontType, pEnumData)
630: // PLOGFONT plf;
631: // PTEXTMETRIC ptm;
632: // ULONG ulFontType;
633: // PENUMDATA pEnumData;
634: //
635: // This function Enumerates the fonts for a given DC.
636: //
637: // Returns:
638: // This routine returns the value returned by iFaceCallBack.
639: //
640: // History:
641: // 12-Feb-1992 -by- Kent Settle (kentse)
642: // Wrote it.
643: //--------------------------------------------------------------------------
644:
645: int iFontCallback (plf, ptm, ulFontType, pEnumData)
646: PLOGFONT plf;
647: PTEXTMETRIC ptm;
648: ULONG ulFontType;
649: PENUMDATA pEnumData;
650: {
651: UNREFERENCED_PARAMETER (ptm);
652:
653: // we only care about the TrueType fonts.
654:
655: if (!(ulFontType & TRUETYPE_FONTTYPE))
656: return(1);
657:
658: // enumerate all the face names within this family.
659:
660: return (EnumFonts(pEnumData->hdc, (LPCWSTR)plf->lfFaceName,
661: (FONTENUMPROC)iFaceCallback,
662: (LPARAM)pEnumData));
663: }
664:
665:
666: //--------------------------------------------------------------------------
667: // int iFaceCallback (plf, ptm, ulFontType, pEnumData)
668: // PLOGFONT plf;
669: // PTEXTMETRIC ptm;
670: // ULONG ulFontType;
671: // PENUMDATA pEnumData;
672: //
673: // This function Enumerates the fonts for a given DC.
674: //
675: // Returns:
676: // This routine returns the 1 for success, 0 otherwise.
677: //
678: // History:
679: // 12-Feb-1992 -by- Kent Settle (kentse)
680: // Wrote it.
681: //--------------------------------------------------------------------------
682:
683: int iFaceCallback (plf, ptm, ulFontType, pEnumData)
684: PLOGFONT plf;
685: PTEXTMETRIC ptm;
686: ULONG ulFontType;
687: PENUMDATA pEnumData;
688: {
689: int rc;
690: ENUMLOGFONT *pelf;
691:
692: UNREFERENCED_PARAMETER (ptm);
693:
694: // we only care about the TrueType fonts.
695:
696: if (!(ulFontType & TRUETYPE_FONTTYPE))
697: return(1);
698:
699: // we want to access the real font name.
700:
701: pelf = (ENUMLOGFONT *)plf;
702:
703: // insert this font into the listbox.
704:
705: rc = SendDlgItemMessage(pEnumData->hwnd, IDD_TTFONT_LIST_BOX,
706: LB_ADDSTRING, (WPARAM)0, (LPARAM)pelf->elfFullName);
707:
708: if (rc == LB_ERR)
709: {
710: RIP("PSCRPTUI!iFaceCallBack: LB_ADDSTRING failed.\n");
711: return(0);
712: }
713:
714: return(1);
715: }
716:
717:
718: //--------------------------------------------------------------------------
719: // BOOL SetDefaultTTMappings(hwnd)
720: // HWND hwnd;
721: //
722: // This function gets each TT family name from the TT font list box, and
723: // looks for the corresponding entry in the Printer font list box. If
724: // a printer font is found, the corresponding index into the printer font
725: // list box is stored with the TT family name. Otherwise, zero is stored.
726: //
727: // Returns:
728: // This routine returns TRUE for success, FALSE otherwise.
729: //
730: // History:
731: // 03-Jun-1992 -by- Kent Settle (kentse)
732: // Wrote it.
733: //--------------------------------------------------------------------------
734:
735: BOOL SetDefaultTTMappings(hwnd)
736: HWND hwnd;
737: {
738: int i, rc;
739: int cTTFonts, cDevFonts;
740: int PFIndex;
741:
742: // get the count of TrueType family names located in the TrueType
743: // list box.
744:
745: cTTFonts = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX, LB_GETCOUNT,
746: (WPARAM)0, (LPARAM)0);
747:
748: if (cTTFonts == LB_ERR)
749: {
750: RIP("PSCRPTUI!SetDefaultTTMappings: LB_GETCOUNT for TT fonts failed.\n");
751: return(FALSE);
752: }
753:
754: // get the count of device family names located in the printer
755: // font list box.
756:
757: cDevFonts = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
758: LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
759:
760: if (cDevFonts == LB_ERR)
761: {
762: RIP("PSCRPTUI!SetDefaultTTMappings: LB_GETCOUNT for printer fonts failed.\n");
763: return(FALSE);
764: }
765:
766: // for each TrueType family name, locate the corresponding printer
767: // font, if one exists.
768:
769: for (i = 0; i < cTTFonts; i++)
770: {
771: PFIndex = TTToDefaultPF(hwnd, i);
772:
773: if (PFIndex == -1)
774: {
775: RIP("PSCRPTUI!SetDefaultTTMappings: TTToDefaultPF failed.\n");
776: return(FALSE);
777: }
778:
779: // set the item data for the entry in the TT list box equal to
780: // the index of the corresponding printer font.
781:
782: rc = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX, LB_SETITEMDATA,
783: (WPARAM)i, (LPARAM)PFIndex);
784: }
785:
786: return(TRUE);
787: }
788:
789:
790: //--------------------------------------------------------------------------
791: // int TTToDefaultPF(hwnd, iCurrent)
792: // HWND hwnd;
793: // int iCurrent;
794: //
795: // This function takes an index into the TT font list box for the given
796: // TrueType font, and returns the index into the printer font list box
797: // of the default printer font.
798: //
799: // Returns:
800: // This routine returns -1 for failure, otherwise it returns the
801: // index of the printer font into the printer font list box.
802: //
803: // History:
804: // 03-Jun-1992 -by- Kent Settle (kentse)
805: // Wrote it.
806: //--------------------------------------------------------------------------
807:
808: int TTToDefaultPF(hwnd, iCurrent)
809: HWND hwnd;
810: int iCurrent;
811: {
812: int rc;
813: WCHAR buf[64];
814: PWSTR pwstrDevFont;
815: int PFIndex;
816: TT_FONT_MAPPING *pTable;
817:
818: rc = SendDlgItemMessage(hwnd, IDD_TTFONT_LIST_BOX, LB_GETTEXT,
819: (WPARAM)iCurrent, (LPARAM)buf);
820:
821: if (rc == LB_ERR)
822: {
823: RIP("PSCRPTUI!TTToDefaultPF: LB_GETTEXT failed.\n");
824: return(-1);
825: }
826:
827: // get the corresponding printer font name.
828: // assume no match found.
829:
830: pwstrDevFont = (PWSTR)NULL;
831: pTable = TTFontTable;
832:
833: while (pTable->pwstrTTFont)
834: {
835: if (!wcscmp(buf, pTable->pwstrTTFont))
836: pwstrDevFont = pTable->pwstrDevFont;
837:
838: pTable++;
839: }
840:
841: // if a corresponding printer font name was found, locate it's
842: // index into the printer font list box. else, set the index
843: // to zero.
844:
845: if (pwstrDevFont)
846: {
847: PFIndex = SendDlgItemMessage(hwnd, IDD_PRINTER_FONT_LIST_BOX,
848: LB_FINDSTRING, (WPARAM)-1,
849: (LPARAM)pwstrDevFont);
850:
851: if (PFIndex == LB_ERR)
852: PFIndex = 0;
853: }
854: else
855: PFIndex = 0;
856:
857: return(PFIndex);
858: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.