File:  [WindowsNT SDKs] / ntddk / src / print / pscript / quryfont.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 18:31:12 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: ntddk-nov-1993, HEAD
Microsoft Windows NT Build 511 (DDK SDK) 11-01-1993

//--------------------------------------------------------------------------
//
// Module Name:  QURYFONT.C
//
// Brief Description:  Device font querying routines
//
// Author:  Kent Settle (kentse)
// Created: 25-Feb-1991
//
// Copyright (C) 1991 - 1992 Microsoft Corporation.
//
// This module contains DrvQueryFont, DrvQueryFontTree and DrvQueryFontData,
// and related routines.
//
// History:
//   25-Feb-1991    -by-    Kent Settle       (kentse)
// Created.
//--------------------------------------------------------------------------

#include <string.h>
#include "pscript.h"
#include "enable.h"
#include "resource.h"
#include <memory.h>
#include "winbase.h"

extern HMODULE     ghmodDrv;    // GLOBAL MODULE HANDLE.

int     _fltused;   // HEY, it shut's up the linker.  That's why it's here.

// declarations of routines residing within this module.

PNTFM GetFont(PDEVDATA, ULONG, HANDLE *);

//--------------------------------------------------------------------------
// PIFIMETRICS DrvQueryFont (dhpdev,iFace)
// DHPDEV   dhpdev;
// ULONG    iFile;
// ULONG    iFace;
// ULONG   *pid;
//
// GDI uses this function to get the IFIMETRICS structure for a given font.
//
// Parameters:
//   dhpdev    This is a PDEV handle returned from a call to DrvEnablePDEV.
//
//   iFace    This is the index of the driver font.  The index of the first
//        font is one.  GDI knows the number of fonts from DEVINFO.
//
// Returns:
//   The function returns a pointer to the IFIMETRICS structure of the font.
//   This structure must remain unchanged during the lifetime of the
//   associated PDEV.
//
//   If an error occurs, NULL should be returned and an error code should
//   be logged.
//
// History:
//   25-Mar-1993    -by-    Kent Settle     (kentse)
// Moved all the IFIMETRICS stuff to ..\pslib\afmtopfm.c
//   Thu 23-Jan-1992 11:38:40 by Kirk Olynyk [kirko]
// Changed the the IFIMETRICS
//   25-Feb-1991    -by-    Kent Settle     (kentse)
// Wrote it.
//--------------------------------------------------------------------------


PIFIMETRICS DrvQueryFont (dhpdev,iFile,iFace,pid)
DHPDEV   dhpdev;
ULONG    iFile;
ULONG    iFace;
ULONG   *pid;
{
    PDEVDATA        pdev;
    PNTFM           pntfm;

    UNREFERENCED_PARAMETER(iFile);

#ifdef TESTING
    DbgPrint("Entering DrvQueryFont.\n");
#endif

    // This can be used by the driver to flag or id the data returned.
    // May be useful for deletion of the data later by DrvFree().

    *pid = 0;           // don't need to use for this driver

    pdev = (PDEVDATA)dhpdev;

    if (bValidatePDEV(pdev) == FALSE)
    {
	RIP("PSCRIPT!DrvQueryFont: invalid pdev.\n");
	SetLastError(ERROR_INVALID_PARAMETER);
	return((PIFIMETRICS)NULL);
    }

    // make sure iFace is valid.

    if ((iFace == 0) || (iFace > (pdev->cDeviceFonts + pdev->cSoftFonts	+ 1)))
    {
	RIP("PSCRIPT!DrvQueryFont: iFace invalid.\n");
	SetLastError(ERROR_INVALID_PARAMETER);
        return((PIFIMETRICS)NULL);
    }

    pntfm = pdev->pfmtable[iFace - 1].pntfm;

    // return pointer to IFIMETRICS structure to engine.

    return((IFIMETRICS *)((CHAR *)pntfm + pntfm->loIFIMETRICS));
}


//--------------------------------------------------------------------------
// PNTFM GetFont(pdev, iFace, phFontRes)
// PDEVDATA    pdev;
// ULONG	    iFace;
// HANDLE	   *phFontRes;
//
// This routine returns a pointer to the NT Font Metrics structure for
// the specified font.  If the metrics cannot be found, a NULL pointer
// is returned.
//
// History:
//   17-Apr-1991    -by-    Kent Settle       (kentse)
// Wrote it.
//--------------------------------------------------------------------------

PNTFM GetFont(pdev, iFace, phFontRes)
PDEVDATA    pdev;
ULONG	    iFace;
HANDLE	   *phFontRes;
{
    PNTFM          pntfm, pntfmtmp = NULL;
    USHORT         usSize;
    HANDLE         hRes;
    ULONG          iFont;
    PBYTE          pfont;
    SOFTFONTENTRY *pSFEntry;
    WCHAR          wcbuf[MAX_PATH];
    PWSTR          pwstrPath;
    DWORD	   cwBuf;

    if ((iFace == 0) || (iFace > (pdev->cDeviceFonts + pdev->cSoftFonts + 1)))
    {
	RIP("PSCRIPT!GetFont: invalid iFace.\n");
	SetLastError(ERROR_INVALID_PARAMETER);
	return((PNTFM)NULL);
    }

    // handle the device vs soft font case.

    if (iFace <= pdev->cDeviceFonts)
    {
	// get a pointer to the fonts for the current device.

	pfont = (BYTE *)pdev->pntpd + pdev->pntpd->loFonts;

	iFont = (ULONG)pfont[iFace - 1];

#ifdef TESTING
	DbgPrint("GetFont: iFace %d mapped to iFont %d.\n", iFace, iFont);
#endif

	// find the font resource in question.

	if (!(hRes = FindResource(ghmodDrv, MAKEINTRESOURCE(iFont),
				  MAKEINTRESOURCE(MYFONT))))
	{
	    RIP("PSCRIPT!GetFont: Couldn't find font resource\n");
	    return((PNTFM)NULL);
	}

	usSize = (USHORT)SizeofResource(ghmodDrv, hRes);

	// get the handle to the resource.

	if (!(*phFontRes = LoadResource(ghmodDrv, hRes)))
	{
	    RIP("PSCRIPT!GetFont: LoadResource failed.\n");
	    return((PNTFM)NULL);
	}

	// get a pointer to the resource data.

	if (!(pntfm = (PNTFM)LockResource(*phFontRes)))
	{
	    RIP("PSCRIPT!GetFont: LockResource failed.\n");
	    FreeResource(*phFontRes);
	    return((PNTFM)NULL);
	}
    }
    else // must be a soft font.
    {
	// search through the linked list we setup at DEVINFO time to
	// find the .PFM file associated with this font.

	pSFEntry = pdev->pSFList;

	while (pSFEntry->iFace != iFace)
	    pSFEntry = (PSOFTFONTENTRY)pSFEntry->psfeNext;

	// we've found the entry.  create the fully qualified pathname to
	// the corresponding .PFM file, then map that file.

	wcsncpy(wcbuf, pdev->pwstrPPDFile, (sizeof(wcbuf) / 2));

	// back up over the data file name to get the subdirectory.

	cwBuf = wcslen(wcbuf);

	pwstrPath = wcbuf;
	pwstrPath += cwBuf;

	while(*pwstrPath-- != (WCHAR)'\\')
	    ;

	// overwrite the character after the backslash with the NULL
	// terminator.

	pwstrPath += 2;
	*pwstrPath = (WCHAR)'\0';

	// append the .PFM filename to qualified path.

	wcsncat(wcbuf, pSFEntry->pwstrPFMFile, ((sizeof(wcbuf) / 2) - cwBuf));

        // put exception handling around this in case the network connection
        // goes down while we are doing this.

        try
        {
            pntfmtmp = (PNTFM)MapFile(wcbuf);

            if (!pntfmtmp)
            {
                RIP("PSCRIPT!GetFont: MapFile failed.\n");
                return((PNTFM)NULL);
            }

            // allocate local buffer to copy the softfont data into.

            if (!(pntfm = (PNTFM)HeapAlloc(pdev->hheap, 0, pntfmtmp->cjThis)))
            {
                RIP("PSCRIPT!GetFont: HeapAlloc for pntfm failed.\n");
                return((PNTFM)NULL);
            }

            // copy softfont to local buffer.

            CopyMemory(pntfm, pntfmtmp, pntfmtmp->cjThis);

            UnmapViewOfFile((PVOID)pntfmtmp);
        }
        except (EXCEPTION_EXECUTE_HANDLER)
        {
#if DBG
            DbgPrint("MapFile to softfont file failed.\n");
#endif
            return((PNTFM)NULL);
        }
    }

    return(pntfm);    // will be NULL on error
}


//--------------------------------------------------------------------------
// VOID FreeFont(pdev, iFace, hFontRes, pntfm)
// PDEVDATA	pdev;
// ULONG	iFace;
// HANDLE	hFontRes;
// PNTFM	pntfm;
//
// This routine frees up any resources allocated during GetFont
// for the given font.
//
// History:
//   21-Feb-1992	  -by-	  Kent Settle	     (kentse)
// Wrote it.
//--------------------------------------------------------------------------

VOID FreeFont(pdev, iFace, hFontRes, pntfm)
PDEVDATA    pdev;
ULONG	    iFace;
HANDLE	    hFontRes;
PNTFM	    pntfm;
{
    // handle device font case.

    if (iFace <= pdev->cDeviceFonts)
    {
	UnlockResource(hFontRes);
	FreeResource(hFontRes);
    }
    else
        HeapFree(pdev->hheap, 0, (PVOID)pntfm);

    return;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.