Document 389515

Printer Driver Development
in Windows 7
Felix Maxa
Software Engineer
Microsoft Corporation
Agenda
• New API and features in Windows 7
• Print Driver Isolation
• XPS Print API
• Plugin Execution Context API
• Print filter pipeline
• Updates
• Performance
• Point’n’print and Client Side Rendering
Print Driver Isolation
• A driver can be loaded
• in the spooler process, or
• in a shared sandbox, or
• isolated sandbox
• Driver attributes and group policy
• A print processor is isolated based on the policy of the driver that is
associated with the queue that is printing the job
• Isolation policies on client and server are unrelated
Print Driver Isolation
Client
Server
SANDBOX
SANDBOX
Windows 7 – CSR
Windows 7
Windows 7 – SSR
Windows Vista
Windows Server 2003
Windows XP
Windows Vista
Windows Server 2003
Windows XP
CSR – Client Side Rendering
SSR – Server Side Rendering
XPS Print API
• Submits XPS documents to XPS and GDI printers
• Sends document events to driver
• Parity with WPF and GDI drivers
• Runs in client application process
• We’ll have a white paper about it – draft by WinHEC
Print Plug-in Context API
typedef enum
{
PRINT_EXECUTION_CONTEXT_APPLICATION = 0,
PRINT_EXECUTION_CONTEXT_SPOOLER_SERVICE = 1,
PRINT_EXECUTION_CONTEXT_ISOLATION_HOST = 2,
PRINT_EXECUTION_CONTEXT_FILTER_PIPELINE = 3,
PRINT_EXECUTION_CONTEXT_WOW64 = 4
}
PRINT_EXECUTION_CONTEXT;
typedef struct
{
PRINT_EXECUTION_CONTEXT context;
DWORD
clientAppPID;
}
PRINT_EXECUTION_DATA;
BOOL
WINAPI
GetPrintExecutionData(
__out PRINT_EXECUTION_DATA *pData
);
Print Filter Pipeline – Optional Service Providers
• “FilterServiceProvider” tag introduced in Windows Vista
• “OptionalFilterServiceProvider” tag introduced in Windows 7
<Filters>
<Filter dll = “TestPrintFilters.dll"
…
</Filter>
<FilterServiceProvider dll="unidrvui.dll"/>
<OptionalFilterServiceProvider dll=“somedll.dll"/>
</Filters>
Print Filter Pipeline - Updates
• Property bag: XPS_FP_OUTPUT_FILE L"PrintOutputFileName"
• Bypass print filter pipeline
• Use XPS_PASS data type
• Windows 7: enabled loading dependent DLLs from drivers directory
m_hModule = LoadLibraryEx(pszFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
Print Filter Pipeline – Restricted Fonts
• IPartFont interface introduced in Windows Vista
• IPartFont2 interface introduced in Windows 7
typedef enum
{
Xps_Restricted_Font_Installable = 0x0000,
Xps_Restricted_Font_NoEmbedding = 0x0002,
Xps_Restricted_Font_PreviewPrint = 0x0004,
Xps_Restricted_Font_Editable
= 0x0008
} EXpsFontRestriction;
interface IPartFont2 : IPartFont
{
HRESULT
GetFontRestriction(
[out] EXpsFontRestriction *pRestriction
);
}
Print Filter Pipeline - Performance
• Performance issues with various types of documents
• Thousands of pages
• 100 MB page or image associated with page
• Pages with thousands of relationships
• Fixed bugs in Vista SP1 and more in Windows 7
• Fewer disk I/O operations
• More efficient use of buffers and memory
• More than 100% performance improvement in certain scenarios
Print Filter Pipeline - Discard Control
• Microsoft XPS Document Converter (MXDC) produces discard
control in Windows 7
• Filters should be able to handle IPartDiscardControl
• The physical location of discard data – close to sentinel page
• Example of sequence of parts received by a filter when printing an
XPS doc with 3 pages:
IXpsDocument
IFixedDocumentSequence
IFixedDocument
IFixedPage
IPartDiscardControl
IFixedPage
IPartDiscardControl
IPartDiscardControl
IFixedPage
Print Filter Pipeline - Best Practices
Impersonation
• Pipeline process runs a “local service”
• Filters must impersonate when accessing user data
• When using the printer handle
• PTOpenProviderEx, PTMergeAndValidatePrintTicket, etc.
Print Filter Pipeline - Best Practices
Global Variables
• The same filters can be used in multiple pipelines at the same time
• Pipeline process can call InitializeFilter and StartOperation
concurrently
• Protect global variables
Print Filter Pipeline – Best Practices
Obfuscated Fonts
The Vista RTM WDK sample shows an unsupported method for using
obfuscated fonts in the pipeline.
This is what we recommend:
1) Create the font and use a uniform resource identifier (URI) that
includes "/", such as:
L"/21223d92-e614-48a5-925c-c6962b6a8124.odtff" (“/” is not needed on SP1
and later)
2) Call the SetFontOptions method on the IPartFont. This method sets the
appropriate content type and marks the font as obfuscated :
pFont->SetFontOptions(Font_Obfusticate)
3) Do not XOR manually the first bytes of the font data stream with the
GUID which is part of the URI.
Client- and Server-Side Rendering
• Filter pipeline is subject to client-side rendering (CSR)
• SetPrinterData values
• "ForceClientSideRendering“ in Windows 7
• "EmfDespoolingSetting“ in Vista and later
• Client – Server connectivity problems
• Connection is switched to server-side rendering (SSR) in Vista
• Connections stays CSR in Windows 7
Client-Side Rendering – GUID names
•
•
•
•
CSR uses local printer objects
Name like \\CSR|server\{GUID}
Possible to retrieve the printer connection name
Get the printer handle from the property bag
• XPS_FP_PRINTER_HANDLE property
• Key “dsspooler” and the value “UNCName“ in GetPrinterDataEx
Call To Action
• Review and follow best practices discussed in this deck
• Continue adoption of new technologies in your driver and device
development: XPS, WSD
• Attend other print-related sessions
Related Sessions
Session
Day / Time
Best Practices for Developing Printer Drivers
Mon. 8:30-9:30 and
Tues. 8:30-9:30
Printer Installation and Driver Management
Mon. 9:45-10:45 and
Tues. 2:45-3:45
Printer Verifier
Tues. 11-12
Printer Driver Testing Tools
Tues. 9:45-10:45 and
Wed. 8:30-9:30
Printer Driver Testing and the Windows Logo Kit
Tues. 1:30-2:30
XPS Rasterization Services in Windows 7
Mon. 1:30-2:30 and
Tues. 5:15-6:15
Discussion: XPS Driver Development in Windows 7
Mon. 4-5 and
Wed. 1:30-2:30
Additional Resources
• E-mail aliases for developer support:
prninfo and xpsinfo
• Print Devices on the WHDC Web Site:
http://www.microsoft.com/whdc/device/print/default.mspx
• XPS on the Microsoft Web site:
http://www.microsoft.com/xps