Typical Printing Process Scenario Using an EMF Spool File

This section illustrates the major relationships between the print spooler components, the printer driver, and GDI during the printing process using an EMF spool file. The presented scenario walks through the sequence of calls between components during the spooling of an EMF spool file and subsequent playback (despooling) of the file on a bi-directional printer.

The spooling and despooling of a raw file is a simpler scenario to walk through than the spooling and despooling of an EMF file, so you may want to read the raw file spooling and despooling scenario before you read this one. The raw spool handling scenario is described in Typical Printing Process Scenario Using a Raw Spool File.

If the raw spool file scenario is simpler, you might ask the question, "Why would an application want to use EMF spool files instead of raw spool files?" A set of EMF files (each EMF file is a logical representation of a printed page) are

Note that an application may not want to request EMF spooling if it is sending a print job to a PostScript printer because a PostScript raw print job is already condensed compared to a raw print sent to a raster printer.

Also, an EMF file is not always smaller than the comparable raw print file. This may especially be true for pages that are heavily-laden with shaded graphics. An application may want to use EMF spool files even in this case, because the return of the print spooler subsystem to the application will still be quicker in the EMF spool file case than the raw spool file case.

Spooling EMF Files

The following illustration shows the sequence of calls that start with an application initiating an EMF spooling request by calling GDI (labeled step 1 in the illustration) and the local print provider writing a print job description file to the disk and calling spooler process with an EndPage or EndDoc function call which signals the availability of an EMF file to despool (these two steps are labeled 8 and 9 in the illustration).

Note one major difference between the EMF spooling scenario shown in the following illustration and the raw print file spooling scenario. In the raw spooling scenario, the local print provider writes the raw spool file to the disk; in the EMF spooling scenario, the GDI writes the EMF spool file to disk and in the EMF despooling scenario it is GDI that reads the EMF spool file and generates the file that is actually printed.

Each of the following paragraphs describes one of the calls in the EMF file spooling process.

1 The application creates a printer DC and draws an object to the DC, for example a circle, and then calls GDI with an EMF spooling request for a particular printer.

2 GDI queries the printer driver to find out if the driver supports EMF spooling.

3 If the driver supports EMF spooling, GDI changes the printer DC to an EMF DC and writes the instructions for rendering the circle to the DC (to the EMF file).

4 GDI passes the print request to 32-bit GDI because the Windows 95 spooler process is 32-bit code.

5 GDI32 makes an interprocess call to the spooler subsystem with a description of the print job.

6 SPOOL32.EXE calls the router to pass the print job description to the print provider that can reach the printer specified by the application. In this example, the router sends the print job to the local print provider but it could send the job to a printer on the network through a network print provider (which is not shown in this picture). Note that the router could send the job to a printer on the network through the network print provider (which is not shown in the illustration). The default Windows 95 spooler spools the network jobs locally, so they show up on the local spooler queue, even those jobs bound for a Windows NT servers. A network print job is spooled and despooled on the client machine, not the server. It is only in the relatively late step of despooling that the remote print server is actually contacted. The way Windows 95 handles network print jobs contrasts with the way they are handled by Windows NT client machines, which use RPC to call the necessary printing APIs on the print server. This way, the print job never shows up on the local spooler queue and the spooling and despooling is handled by the print spooler on the print server. On Windows 95 RPC is not used by the default print spooler. A print spooler that does use RPC is available as an option for Windows 95 client machines.

7 The router calls the local print provider.

8 The local print provider creates a job description file and adds a record to the job description file each time it is called for the job, until all the EMF page files have been spooled and each EMF filename and location is recorded in the job description file.

9 When the local print provider records the information about the last EMF file in the job, it calls the spooler process with an EndDoc function call. This signals the spooler process that a complete job is spooled and ready for despooling. Note that for a multipage job, steps 1 through 8 are repeated once for every page in the job.

Despooling EMF Files

The following illustration shows the sequence of calls and events that start with the spooler process initiating an event that signals the port thread that a spooled job, made up of one or more EMF files, is available for despooling and printing. This step is labeled 10 in the following illustration and the final step, where the print job is sent through the hardware port to the printer is labeled 24.

Each of the following paragraphs describes one of the steps in the EMF despooling process.

1 At the end of the EMF file spooling scenario, the spooler process sets the ReadyToPrint attribute on the print job and initiates an event that signals to the port thread that a job is available for printing.

2 The port thread of the spooler process responds to the event by determining the best time to start despooling process and then, at that time, loads the print processor .

3 When the print processor determines that the spooled file(s) have an EMF format, it calls GDI32 with the new Windows 95 gdiPlaySpoolStream function call.

4 The GDI32 gdiPlaySpoolStream function reads a record from the job description file , which provides the fully-qualified path to an EMF spool file. Note here that through the job description file, which is essentially a list of path names to EMF files (one path per print job page), GDI32 knows about all the pages in the print job.

5 The GDI32 gdiPlaySpoolStream function calls GDI, using a thunk built into GDI32, with the path to the EMF spool file (the list of rendering instructions for a page of the print job) to render the page. GDI knows about only one page in the print job at any point in time -- the page that is being rendered and printed. Note that all the thunking necessary to go from the 32-bit programming environment to the 16-bit programming environment is handled by the Microsoft-provided GDI32 and GDI components, the 16-bit printer driver is isolated from calls to and from the 32-bit environment.

6 GDI calls the printer driver associated with the printer the application wants to use and obtains a DC for the printer.

7 GDI reads page-rendering instructions from the spooled EMF file and passes them one at a time to the printer driver, which uses as many instructions as are necessary to render the first part of the page.

8 When the 16-bit printer driver renders a part of the page, it passes the printer-specific raw page data back to 16-bit GDI.

9 GDI passes the raw data to GDI32. Once again, the 16-bit printer driver is isolated from the transition from 16-bit to 32-bit programming environments. GDI32 passes the raw page data to the 32-bit print spooler process.

Steps 19 through 24, within the spooler process, are the same as the comparable steps described in the raw despooling scenario and result in part of the page appearing on the printer.

Steps 16 through 24 are repeated until an entire page is printed (all the rendering instructions in an EMF spool file have been used). The GDI32 gets the path to the EMF spool file for the next page of the print job and calls GDI to use the instructions in that EMF file to render the next page in the print job. When GDI32 has used up all the paths to EMF spool files in the job description file, the print job is finished.