|
|
1.1 root 1: //--------------------------------------------------------------------------
2: //
3: // Module Name: QURYFONT.C
4: //
5: // Brief Description: Device font querying routines
6: //
7: // Author: Kent Settle (kentse)
8: // Created: 25-Feb-1991
9: //
10: // Copyright (C) 1991 - 1992 Microsoft Corporation.
11: //
12: // This module contains DrvQueryFont, DrvQueryFontTree and DrvQueryFontData,
13: // and related routines.
14: //
15: // History:
16: // 25-Feb-1991 -by- Kent Settle (kentse)
17: // Created.
18: //--------------------------------------------------------------------------
19:
20: #include <string.h>
21: #include "pscript.h"
22: #include "enable.h"
23: #include "resource.h"
24: #include <memory.h>
25: #include "winbase.h"
26:
27: extern HMODULE ghmodDrv; // GLOBAL MODULE HANDLE.
28:
29: int _fltused; // HEY, it shut's up the linker. That's why it's here.
30:
31: // declarations of routines residing within this module.
32:
33: PNTFM GetFont(PDEVDATA, ULONG, HANDLE *);
34:
35: //--------------------------------------------------------------------------
36: // PIFIMETRICS DrvQueryFont (dhpdev,iFace)
37: // DHPDEV dhpdev;
38: // ULONG iFile;
39: // ULONG iFace;
40: // ULONG *pid;
41: //
42: // GDI uses this function to get the IFIMETRICS structure for a given font.
43: //
44: // Parameters:
45: // dhpdev This is a PDEV handle returned from a call to DrvEnablePDEV.
46: //
47: // iFace This is the index of the driver font. The index of the first
48: // font is one. GDI knows the number of fonts from DEVINFO.
49: //
50: // Returns:
51: // The function returns a pointer to the IFIMETRICS structure of the font.
52: // This structure must remain unchanged during the lifetime of the
53: // associated PDEV.
54: //
55: // If an error occurs, NULL should be returned and an error code should
56: // be logged.
57: //
58: // History:
59: // 25-Mar-1993 -by- Kent Settle (kentse)
60: // Moved all the IFIMETRICS stuff to ..\pslib\afmtopfm.c
61: // Thu 23-Jan-1992 11:38:40 by Kirk Olynyk [kirko]
62: // Changed the the IFIMETRICS
63: // 25-Feb-1991 -by- Kent Settle (kentse)
64: // Wrote it.
65: //--------------------------------------------------------------------------
66:
67:
68: PIFIMETRICS DrvQueryFont (dhpdev,iFile,iFace,pid)
69: DHPDEV dhpdev;
70: ULONG iFile;
71: ULONG iFace;
72: ULONG *pid;
73: {
74: PDEVDATA pdev;
75: PNTFM pntfm;
76:
77: UNREFERENCED_PARAMETER(iFile);
78:
79: #ifdef TESTING
80: DbgPrint("Entering DrvQueryFont.\n");
81: #endif
82:
83: // This can be used by the driver to flag or id the data returned.
84: // May be useful for deletion of the data later by DrvFree().
85:
86: *pid = 0; // don't need to use for this driver
87:
88: pdev = (PDEVDATA)dhpdev;
89:
90: if (bValidatePDEV(pdev) == FALSE)
91: {
92: RIP("PSCRIPT!DrvQueryFont: invalid pdev.\n");
93: SetLastError(ERROR_INVALID_PARAMETER);
94: return((PIFIMETRICS)NULL);
95: }
96:
97: // make sure iFace is valid.
98:
99: if ((iFace == 0) || (iFace > (pdev->cDeviceFonts + pdev->cSoftFonts + 1)))
100: {
101: RIP("PSCRIPT!DrvQueryFont: iFace invalid.\n");
102: SetLastError(ERROR_INVALID_PARAMETER);
103: return((PIFIMETRICS)NULL);
104: }
105:
106: pntfm = pdev->pfmtable[iFace - 1].pntfm;
107:
108: // return pointer to IFIMETRICS structure to engine.
109:
110: return((IFIMETRICS *)((CHAR *)pntfm + pntfm->loIFIMETRICS));
111: }
112:
113:
114: //--------------------------------------------------------------------------
115: // PNTFM GetFont(pdev, iFace, phFontRes)
116: // PDEVDATA pdev;
117: // ULONG iFace;
118: // HANDLE *phFontRes;
119: //
120: // This routine returns a pointer to the NT Font Metrics structure for
121: // the specified font. If the metrics cannot be found, a NULL pointer
122: // is returned.
123: //
124: // History:
125: // 17-Apr-1991 -by- Kent Settle (kentse)
126: // Wrote it.
127: //--------------------------------------------------------------------------
128:
129: PNTFM GetFont(pdev, iFace, phFontRes)
130: PDEVDATA pdev;
131: ULONG iFace;
132: HANDLE *phFontRes;
133: {
134: PNTFM pntfm, pntfmtmp = NULL;
135: USHORT usSize;
136: HANDLE hRes;
137: ULONG iFont;
138: PBYTE pfont;
139: SOFTFONTENTRY *pSFEntry;
140: WCHAR wcbuf[MAX_PATH];
141: PWSTR pwstrPath;
142: DWORD cwBuf;
143:
144: if ((iFace == 0) || (iFace > (pdev->cDeviceFonts + pdev->cSoftFonts + 1)))
145: {
146: RIP("PSCRIPT!GetFont: invalid iFace.\n");
147: SetLastError(ERROR_INVALID_PARAMETER);
148: return((PNTFM)NULL);
149: }
150:
151: // handle the device vs soft font case.
152:
153: if (iFace <= pdev->cDeviceFonts)
154: {
155: // get a pointer to the fonts for the current device.
156:
157: pfont = (BYTE *)pdev->pntpd + pdev->pntpd->loFonts;
158:
159: iFont = (ULONG)pfont[iFace - 1];
160:
161: #ifdef TESTING
162: DbgPrint("GetFont: iFace %d mapped to iFont %d.\n", iFace, iFont);
163: #endif
164:
165: // find the font resource in question.
166:
167: if (!(hRes = FindResource(ghmodDrv, MAKEINTRESOURCE(iFont),
168: MAKEINTRESOURCE(MYFONT))))
169: {
170: RIP("PSCRIPT!GetFont: Couldn't find font resource\n");
171: return((PNTFM)NULL);
172: }
173:
174: usSize = (USHORT)SizeofResource(ghmodDrv, hRes);
175:
176: // get the handle to the resource.
177:
178: if (!(*phFontRes = LoadResource(ghmodDrv, hRes)))
179: {
180: RIP("PSCRIPT!GetFont: LoadResource failed.\n");
181: return((PNTFM)NULL);
182: }
183:
184: // get a pointer to the resource data.
185:
186: if (!(pntfm = (PNTFM)LockResource(*phFontRes)))
187: {
188: RIP("PSCRIPT!GetFont: LockResource failed.\n");
189: FreeResource(*phFontRes);
190: return((PNTFM)NULL);
191: }
192: }
193: else // must be a soft font.
194: {
195: // search through the linked list we setup at DEVINFO time to
196: // find the .PFM file associated with this font.
197:
198: pSFEntry = pdev->pSFList;
199:
200: while (pSFEntry->iFace != iFace)
201: pSFEntry = (PSOFTFONTENTRY)pSFEntry->psfeNext;
202:
203: // we've found the entry. create the fully qualified pathname to
204: // the corresponding .PFM file, then map that file.
205:
206: wcsncpy(wcbuf, pdev->pwstrPPDFile, (sizeof(wcbuf) / 2));
207:
208: // back up over the data file name to get the subdirectory.
209:
210: cwBuf = wcslen(wcbuf);
211:
212: pwstrPath = wcbuf;
213: pwstrPath += cwBuf;
214:
215: while(*pwstrPath-- != (WCHAR)'\\')
216: ;
217:
218: // overwrite the character after the backslash with the NULL
219: // terminator.
220:
221: pwstrPath += 2;
222: *pwstrPath = (WCHAR)'\0';
223:
224: // append the .PFM filename to qualified path.
225:
226: wcsncat(wcbuf, pSFEntry->pwstrPFMFile, ((sizeof(wcbuf) / 2) - cwBuf));
227:
228: // put exception handling around this in case the network connection
229: // goes down while we are doing this.
230:
231: try
232: {
233: pntfmtmp = (PNTFM)MapFile(wcbuf);
234:
235: if (!pntfmtmp)
236: {
237: RIP("PSCRIPT!GetFont: MapFile failed.\n");
238: return((PNTFM)NULL);
239: }
240:
241: // allocate local buffer to copy the softfont data into.
242:
243: if (!(pntfm = (PNTFM)HeapAlloc(pdev->hheap, 0, pntfmtmp->cjThis)))
244: {
245: RIP("PSCRIPT!GetFont: HeapAlloc for pntfm failed.\n");
246: return((PNTFM)NULL);
247: }
248:
249: // copy softfont to local buffer.
250:
251: CopyMemory(pntfm, pntfmtmp, pntfmtmp->cjThis);
252:
253: UnmapViewOfFile((PVOID)pntfmtmp);
254: }
255: except (EXCEPTION_EXECUTE_HANDLER)
256: {
257: #if DBG
258: DbgPrint("MapFile to softfont file failed.\n");
259: #endif
260: return((PNTFM)NULL);
261: }
262: }
263:
264: return(pntfm); // will be NULL on error
265: }
266:
267:
268: //--------------------------------------------------------------------------
269: // VOID FreeFont(pdev, iFace, hFontRes, pntfm)
270: // PDEVDATA pdev;
271: // ULONG iFace;
272: // HANDLE hFontRes;
273: // PNTFM pntfm;
274: //
275: // This routine frees up any resources allocated during GetFont
276: // for the given font.
277: //
278: // History:
279: // 21-Feb-1992 -by- Kent Settle (kentse)
280: // Wrote it.
281: //--------------------------------------------------------------------------
282:
283: VOID FreeFont(pdev, iFace, hFontRes, pntfm)
284: PDEVDATA pdev;
285: ULONG iFace;
286: HANDLE hFontRes;
287: PNTFM pntfm;
288: {
289: // handle device font case.
290:
291: if (iFace <= pdev->cDeviceFonts)
292: {
293: UnlockResource(hFontRes);
294: FreeResource(hFontRes);
295: }
296: else
297: HeapFree(pdev->hheap, 0, (PVOID)pntfm);
298:
299: return;
300: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.