wineps: Switch to using a Unicode devmode.

This commit is contained in:
Huw Davies 2012-04-12 13:03:10 +01:00 committed by Alexandre Julliard
parent 0c7a6d89a2
commit 210f3e3338
3 changed files with 90 additions and 85 deletions

View File

@ -52,8 +52,7 @@ static inline int paper_size_from_points( float size )
* Updates dm1 with some fields from dm2
*
*/
void PSDRV_MergeDevmodes(PSDRV_DEVMODEA *dm1, PSDRV_DEVMODEA *dm2,
PRINTERINFO *pi)
void PSDRV_MergeDevmodes( PSDRV_DEVMODE *dm1, PSDRV_DEVMODE *dm2, PRINTERINFO *pi )
{
/* some sanity checks here on dm2 */
@ -183,7 +182,7 @@ void PSDRV_MergeDevmodes(PSDRV_DEVMODEA *dm1, PSDRV_DEVMODEA *dm2,
typedef struct
{
PRINTERINFO *pi;
PSDRV_DEVMODEA *dlgdm;
PSDRV_DEVMODE *dlgdm;
} PSDRV_DLGINFO;
/****************************************************************
@ -320,6 +319,47 @@ static PRINTERINFO *PSDRV_FindPrinterInfoA(LPCSTR name)
return pi;
}
/***********************************************************
* DEVMODEdupWtoA
*
* Creates an ascii copy of supplied devmode on the process heap
*
* Copied from dlls/winspool/info.c until full unicodification
*/
static DEVMODEA *DEVMODEdupWtoA( const DEVMODEW *dmW )
{
DEVMODEA *dmA;
DWORD size;
BOOL formname;
/* there is no pointer dereference here, if your code checking tool complains it's broken */
ptrdiff_t off_formname = (const char *)dmW->dmFormName - (const char *)dmW;
if (!dmW) return NULL;
formname = (dmW->dmSize > off_formname);
size = dmW->dmSize - CCHDEVICENAME - (formname ? CCHFORMNAME : 0);
dmA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size + dmW->dmDriverExtra );
WideCharToMultiByte( CP_ACP, 0, dmW->dmDeviceName, -1, (LPSTR)dmA->dmDeviceName,
CCHDEVICENAME, NULL, NULL );
if (!formname)
{
memcpy( &dmA->dmSpecVersion, &dmW->dmSpecVersion,
dmW->dmSize - CCHDEVICENAME * sizeof(WCHAR) );
}
else
{
memcpy( &dmA->dmSpecVersion, &dmW->dmSpecVersion,
off_formname - CCHDEVICENAME * sizeof(WCHAR) );
WideCharToMultiByte( CP_ACP, 0, dmW->dmFormName, -1, (LPSTR)dmA->dmFormName,
CCHFORMNAME, NULL, NULL );
memcpy( &dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize -
(off_formname + CCHFORMNAME * sizeof(WCHAR)) );
}
dmA->dmSize = size;
memcpy( (char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize,
dmW->dmDriverExtra );
return dmA;
}
/******************************************************************
* PSDRV_ExtDeviceMode
*
@ -362,12 +402,15 @@ INT PSDRV_ExtDeviceMode(LPSTR lpszDriver, HWND hwnd, LPDEVMODEA lpdmOutput,
/* If dwMode == 0, return size of DEVMODE structure */
if(!dwMode)
return pi->Devmode->dmPublic.dmSize + pi->Devmode->dmPublic.dmDriverExtra;
return pi->Devmode->dmPublic.dmSize + pi->Devmode->dmPublic.dmDriverExtra - CCHDEVICENAME - CCHFORMNAME;
/* If DM_MODIFY is set, change settings in accordance with lpdmInput */
if((dwMode & DM_MODIFY) && lpdmInput) {
if((dwMode & DM_MODIFY) && lpdmInput)
{
DEVMODEW *dmW = GdiConvertToDevmodeW( lpdmInput );
TRACE("DM_MODIFY set. devIn->dmFields = %08x\n", lpdmInput->dmFields);
PSDRV_MergeDevmodes(pi->Devmode, (PSDRV_DEVMODEA *)lpdmInput, pi);
if (dmW) PSDRV_MergeDevmodes(pi->Devmode, (PSDRV_DEVMODE *)dmW, pi);
HeapFree( GetProcessHeap(), 0, dmW );
}
/* If DM_PROMPT is set, present modal dialog box */
@ -377,7 +420,7 @@ INT PSDRV_ExtDeviceMode(LPSTR lpszDriver, HWND hwnd, LPDEVMODEA lpdmOutput,
PROPSHEETPAGEW psp;
PROPSHEETHEADERW psh;
PSDRV_DLGINFO di;
PSDRV_DEVMODEA dlgdm;
PSDRV_DEVMODE dlgdm;
static const WCHAR PAPERW[] = {'P','A','P','E','R','\0'};
static const WCHAR SetupW[] = {'S','e','t','u','p','\0'};
@ -417,7 +460,11 @@ INT PSDRV_ExtDeviceMode(LPSTR lpszDriver, HWND hwnd, LPDEVMODEA lpdmOutput,
/* If DM_COPY is set, should write settings to lpdmOutput */
if((dwMode & DM_COPY) || (dwMode & DM_UPDATE)) {
if (lpdmOutput)
memcpy(lpdmOutput, pi->Devmode, pi->Devmode->dmPublic.dmSize + pi->Devmode->dmPublic.dmDriverExtra );
{
DEVMODEA *dmA = DEVMODEdupWtoA( &pi->Devmode->dmPublic );
if (dmA) memcpy( lpdmOutput, dmA, dmA->dmSize + dmA->dmDriverExtra );
HeapFree( GetProcessHeap(), 0, dmA );
}
else
FIXME("lpdmOutput is NULL what should we do??\n");
}
@ -443,7 +490,7 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
WORD fwCapability, LPSTR lpszOutput, LPDEVMODEA lpDevMode)
{
PRINTERINFO *pi;
DEVMODEA *lpdm;
DEVMODEW *lpdm;
DWORD ret;
pi = PSDRV_FindPrinterInfoA(lpszDevice);
@ -456,7 +503,8 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
return 0;
}
lpdm = lpDevMode ? lpDevMode : (DEVMODEA *)pi->Devmode;
lpdm = &pi->Devmode->dmPublic;
if (lpDevMode) lpdm = GdiConvertToDevmodeW( lpDevMode );
switch(fwCapability) {
@ -758,6 +806,7 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
ret = -1;
}
if (lpDevMode) HeapFree( GetProcessHeap(), 0, lpdm );
return ret;
}

View File

@ -50,14 +50,14 @@ WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
static void *cupshandle = NULL;
#endif
static const PSDRV_DEVMODEA DefaultDevmode =
static const PSDRV_DEVMODE DefaultDevmode =
{
{ /* dmPublic */
/* dmDeviceName */ "Wine PostScript Driver",
/* dmDeviceName */ {'W','i','n','e',' ','P','o','s','t','S','c','r','i','p','t',' ','D','r','i','v','e','r',0},
/* dmSpecVersion */ 0x30a,
/* dmDriverVersion */ 0x001,
/* dmSize */ sizeof(DEVMODEA),
/* dmDriverExtra */ sizeof(PSDRV_DEVMODEA)-sizeof(DEVMODEA),
/* dmSize */ sizeof(DEVMODEW),
/* dmDriverExtra */ sizeof(PSDRV_DEVMODE)-sizeof(DEVMODEW),
/* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_SCALE |
DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR |
DM_YRESOLUTION | DM_TTOPTION,
@ -78,7 +78,7 @@ static const PSDRV_DEVMODEA DefaultDevmode =
/* dmYResolution */ 0,
/* dmTTOption */ DMTT_SUBDEV,
/* dmCollate */ 0,
/* dmFormName */ "",
/* dmFormName */ {},
/* dmUnusedPadding */ 0,
/* dmBitsPerPel */ 0,
/* dmPelsWidth */ 0,
@ -257,46 +257,6 @@ static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
physDev->horzRes, physDev->vertRes);
}
/***********************************************************
* DEVMODEdupWtoA
*
* Creates an ascii copy of supplied devmode on the process heap
*
* Copied from dlls/winspool/info.c until full unicodification
*/
static LPDEVMODEA DEVMODEdupWtoA( const DEVMODEW *dmW )
{
LPDEVMODEA dmA;
DWORD size;
BOOL Formname;
/* there is no pointer dereference here, if your code checking tool complains it's broken */
ptrdiff_t off_formname = (const char *)dmW->dmFormName - (const char *)dmW;
if(!dmW) return NULL;
Formname = (dmW->dmSize > off_formname);
size = dmW->dmSize - CCHDEVICENAME - (Formname ? CCHFORMNAME : 0);
dmA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size + dmW->dmDriverExtra );
WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1, (LPSTR)dmA->dmDeviceName,
CCHDEVICENAME, NULL, NULL);
if(!Formname) {
memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
dmW->dmSize - CCHDEVICENAME * sizeof(WCHAR));
} else {
memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
off_formname - CCHDEVICENAME * sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1, (LPSTR)dmA->dmFormName,
CCHFORMNAME, NULL, NULL);
memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize -
(off_formname + CCHFORMNAME * sizeof(WCHAR)));
}
dmA->dmSize = size;
memcpy((char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize,
dmW->dmDriverExtra);
return dmA;
}
static PSDRV_PDEVICE *create_psdrv_physdev( PRINTERINFO *pi )
{
PSDRV_PDEVICE *physDev;
@ -304,7 +264,7 @@ static PSDRV_PDEVICE *create_psdrv_physdev( PRINTERINFO *pi )
physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) );
if (!physDev) return NULL;
physDev->Devmode = HeapAlloc( GetProcessHeap(), 0, sizeof(PSDRV_DEVMODEA) );
physDev->Devmode = HeapAlloc( GetProcessHeap(), 0, sizeof(PSDRV_DEVMODE) );
if (!physDev->Devmode)
{
HeapFree( GetProcessHeap(), 0, physDev );
@ -349,11 +309,8 @@ static BOOL PSDRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
if (output && *output) physDev->job.output = strdupW( output );
if(initData) {
DEVMODEA *devmodeA = DEVMODEdupWtoA( initData );
PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, pi);
HeapFree( GetProcessHeap(), 0, devmodeA );
}
if(initData)
PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODE *)initData, pi);
PSDRV_UpdateDevCaps(physDev);
SelectObject( (*pdev)->hdc, PSDRV_DefaultFont );
@ -406,10 +363,9 @@ static HDC PSDRV_ResetDC( PHYSDEV dev, const DEVMODEW *lpInitData )
{
PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
if(lpInitData) {
DEVMODEA *devmodeA = DEVMODEdupWtoA( lpInitData );
PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, physDev->pi);
HeapFree( GetProcessHeap(), 0, devmodeA );
if (lpInitData)
{
PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODE *)lpInitData, physDev->pi);
PSDRV_UpdateDevCaps(physDev);
}
return dev->hdc;
@ -554,18 +510,18 @@ static PRINTER_ENUM_VALUESA *load_font_sub_table( HANDLE printer, DWORD *num_ent
return table;
}
static PSDRV_DEVMODEA *get_printer_devmode( HANDLE printer )
static PSDRV_DEVMODE *get_printer_devmode( HANDLE printer )
{
DWORD needed, dm_size;
BOOL res;
PRINTER_INFO_9A *info;
PSDRV_DEVMODEA *dm;
PRINTER_INFO_9W *info;
PSDRV_DEVMODE *dm;
GetPrinterA( printer, 9, NULL, 0, &needed );
GetPrinterW( printer, 9, NULL, 0, &needed );
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return NULL;
info = HeapAlloc( PSDRV_Heap, 0, needed );
res = GetPrinterA( printer, 9, (BYTE *)info, needed, &needed );
res = GetPrinterW( printer, 9, (BYTE *)info, needed, &needed );
if (!res || !info->pDevMode)
{
HeapFree( PSDRV_Heap, 0, info );
@ -580,14 +536,14 @@ static PSDRV_DEVMODEA *get_printer_devmode( HANDLE printer )
return NULL;
}
dm = (PSDRV_DEVMODEA*)info;
dm = (PSDRV_DEVMODE*)info;
memmove( dm, info->pDevMode, dm_size );
return dm;
}
static PSDRV_DEVMODEA *get_devmode( HANDLE printer, const char *nameA, BOOL *is_default )
static PSDRV_DEVMODE *get_devmode( HANDLE printer, const WCHAR *name, BOOL *is_default )
{
PSDRV_DEVMODEA *dm = get_printer_devmode( printer );
PSDRV_DEVMODE *dm = get_printer_devmode( printer );
*is_default = FALSE;
@ -603,18 +559,18 @@ static PSDRV_DEVMODEA *get_devmode( HANDLE printer, const char *nameA, BOOL *is_
if (dm)
{
*dm = DefaultDevmode;
lstrcpynA((LPSTR)dm->dmPublic.dmDeviceName, nameA, CCHDEVICENAME);
lstrcpynW( (WCHAR *)dm->dmPublic.dmDeviceName, name, CCHDEVICENAME );
*is_default = TRUE;
}
return dm;
}
static BOOL set_devmode( HANDLE printer, PSDRV_DEVMODEA *dm )
static BOOL set_devmode( HANDLE printer, PSDRV_DEVMODE *dm )
{
PRINTER_INFO_9A info;
PRINTER_INFO_9W info;
info.pDevMode = &dm->dmPublic;
return SetPrinterA( printer, 9, (BYTE *)&info, 0 );
return SetPrinterW( printer, 9, (BYTE *)&info, 0 );
}
static struct list printer_list = LIST_INIT( printer_list );
@ -659,7 +615,7 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCWSTR name)
nameA = HeapAlloc( GetProcessHeap(), 0, len );
WideCharToMultiByte( CP_ACP, 0, name, -1, nameA, len, NULL, NULL );
pi->Devmode = get_devmode( hPrinter, nameA, &using_default_devmode );
pi->Devmode = get_devmode( hPrinter, name, &using_default_devmode );
if (!pi->Devmode) goto closeprinter;
#ifdef SONAME_LIBCUPS
@ -761,7 +717,7 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCWSTR name)
if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER,
(LPWSTR)&papersize, sizeof(papersize)/sizeof(WCHAR))) {
PSDRV_DEVMODEA dm;
PSDRV_DEVMODE dm;
memset(&dm, 0, sizeof(dm));
dm.dmPublic.dmFields = DM_PAPERSIZE;
dm.dmPublic.u1.s1.dmPaperSize = papersize;
@ -772,7 +728,7 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCWSTR name)
}
if(pi->ppd->DefaultPageSize) { /* We'll let the ppd override the devmode */
PSDRV_DEVMODEA dm;
PSDRV_DEVMODE dm;
memset(&dm, 0, sizeof(dm));
dm.dmPublic.dmFields = DM_PAPERSIZE;
dm.dmPublic.u1.s1.dmPaperSize = pi->ppd->DefaultPageSize->WinPage;

View File

@ -213,7 +213,7 @@ typedef struct {
} PPD;
typedef struct {
DEVMODEA dmPublic;
DEVMODEW dmPublic;
struct _tagdocprivate {
int dummy;
} dmDocPrivate;
@ -227,14 +227,14 @@ numInstalledOptions of OPTIONs
*/
} PSDRV_DEVMODEA;
} PSDRV_DEVMODE;
typedef struct
{
struct list entry;
WCHAR *friendly_name;
PPD *ppd;
PSDRV_DEVMODEA *Devmode;
PSDRV_DEVMODE *Devmode;
FONTFAMILY *Fonts;
PPRINTER_ENUM_VALUESA FontSubTable;
DWORD FontSubTableSize;
@ -356,7 +356,7 @@ typedef struct
PSCOLOR bkColor;
PSCOLOR inkColor; /* Last colour set */
JOB job;
PSDRV_DEVMODEA *Devmode;
PSDRV_DEVMODE *Devmode;
PRINTERINFO *pi;
SIZE PageSize; /* Physical page size in device units */
RECT ImageableArea; /* Imageable area in device units */
@ -451,7 +451,7 @@ extern INT PSDRV_StartDoc( PHYSDEV dev, const DOCINFOW *doc ) DECLSPEC_HIDDEN;
extern BOOL PSDRV_StrokeAndFillPath( PHYSDEV dev ) DECLSPEC_HIDDEN;
extern BOOL PSDRV_StrokePath( PHYSDEV dev ) DECLSPEC_HIDDEN;
extern void PSDRV_MergeDevmodes(PSDRV_DEVMODEA *dm1, PSDRV_DEVMODEA *dm2,
extern void PSDRV_MergeDevmodes(PSDRV_DEVMODE *dm1, PSDRV_DEVMODE *dm2,
PRINTERINFO *pi) DECLSPEC_HIDDEN;
extern BOOL PSDRV_GetFontMetrics(void) DECLSPEC_HIDDEN;
extern PPD *PSDRV_ParsePPD(char *fname) DECLSPEC_HIDDEN;