VOID vPrint( __in LPCTSTR szMessageText ) { // // Declare the length of buffer required to store multibyte string // for \n. DBCS char set, needs 2 bytes to store singe char. // CHAR szMultiByteString[ERROR_MESSAGE_BUFSIZE]; DWORD dwNumCharsWritten = 0; if ( !szMessageText ) { return; } // // Format Unicode Text to a Multibyte // if ( WideCharToMultiByte(CP_OEMCP, 0, szMessageText, -1, szMultiByteString, CCHOF(szMultiByteString), NULL, NULL) ) { WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), szMultiByteString, (DWORD) strlen(szMultiByteString), &dwNumCharsWritten, NULL); } }
VOID SetDefaultDMForm( PPLOTDEVMODE pPlotDM, _Out_opt_ PFORMSIZE pCurForm ) /*++ Routine Description: This function set the default form for the PLOTDEVMODE, these includes dmPaperSize, dmPaperWidth, dmPaperLength, dmFormName and set pCurForm if pointer is not NULL Arguments: pPlotDM - Pointer to the PLOTDEVMODE data structure pCurForm - pointer to the FORMSIZE data structure to store current default form set by this function Return Value: VOID Author: 01-Dec-1993 Wed 13:44:31 created Revision History: --*/ { PAPERINFO PaperInfo; HRESULT hr; pPlotDM->dm.dmFields &= ~DM_PAPER_FIELDS; pPlotDM->dm.dmFields |= (DM_FORMNAME | DM_PAPERSIZE); pPlotDM->dm.dmPaperSize = GetDefaultPaper(&PaperInfo); pPlotDM->dm.dmPaperWidth = SPLTODM(PaperInfo.Size.cx); pPlotDM->dm.dmPaperLength = SPLTODM(PaperInfo.Size.cy); hr = StringCchCopy((LPWSTR)pPlotDM->dm.dmFormName, CCHOF(pPlotDM->dm.dmFormName), PaperInfo.Name); if (FAILED(hr) ) { PLOTASSERT(0, "Couldn't copy the string %ls to devmode", SUCCEEDED(hr), PaperInfo.Name); } if (pCurForm) { pCurForm->Size = PaperInfo.Size; pCurForm->ImageArea = PaperInfo.ImageArea; } }
VOID GetDefaultPlotterForm( PPLOTGPC pPlotGPC, PPAPERINFO pPaperInfo ) /*++ Routine Description: This function set the default loaded paper on the plotter to the first form data list in the PCD data file Arguments: pPlotGPC - Pointer to the GPC data pPaperInfo - Pointer to the paper info to be returned Return Value: TRUE if sucessful, false if failed Author: 03-Feb-1994 Thu 11:37:37 created Revision History: --*/ { PFORMSRC pFS; if ((pFS = (PFORMSRC)pPlotGPC->Forms.pData) && (pPlotGPC->Forms.Count)) { str2Wstr(pPaperInfo->Name, CCHOF(pPaperInfo->Name), pFS->Name); pPaperInfo->Size = pFS->Size; pPaperInfo->ImageArea.left = pFS->Margin.left; pPaperInfo->ImageArea.top = pFS->Margin.top; pPaperInfo->ImageArea.right = pFS->Size.cx - pFS->Margin.right; pPaperInfo->ImageArea.bottom = pFS->Size.cy - pFS->Margin.bottom; } else { PLOTERR(("GetDefaultPlotterForm: No FORM DATA in PCD, used country/region default")); GetDefaultPaper(pPaperInfo); } }
BOOL GetFormSelect( PPRINTERINFO pPI, POPTITEM pOptItem ) /*++ Routine Description: This function retrieve the form selected by the user from the combo box Arguments: pPI - Pointer to the PRINTERINFO pOptItem - Pointer to the FORM's OPTITEM Return Value: TRUE if sucessful and pPI will be set correctly, FALSE if error occurred Author: 09-Dec-1993 Thu 14:44:18 created 18-Dec-1993 Sat 03:55:30 updated Changed dmFields setting for the PAPER, now we will only set the DM_FORMNAME field, this way the returned document properties will be always in known form even user defines many forms in spooler. 06-Nov-1995 Mon 12:56:00 updated Re-write for the New UI Revision History: --*/ { PAPERINFO CurPaper; POPTPARAM pOptParam; pOptParam = pOptItem->pOptType->pOptParam + pOptItem->Sel; if (pOptParam->Style == FS_ROLLPAPER) { PFORMSRC pFS; // // This was added from the GPC data for the roll feed // PLOTASSERT(0, "GetComboBoxSelForm: INTERNAL ERROR, ROLLPAPER In document properties", !(pPI->Flags & PIF_DOCPROP), 0); PLOTASSERT(0, "GetComboBoxSelForm: INTERNAL ERROR, device CANNOT have ROLLPAPER", pPI->pPlotGPC->Flags & PLOTF_ROLLFEED, 0); PLOTDBG(DBG_FORMS, ("Roll Feed Paper is selected, (%ld)", pOptParam->lParam)); if ((pOptParam->lParam >= 0) && ((DWORD)(pOptParam->lParam) < (DWORD)pPI->pPlotGPC->Forms.Count)) { pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData + pOptParam->lParam; // // Since the RollFeed paper has variable length, and the cy is set // to zero at GPC data, we must take that into account // CurPaper.Size = pFS->Size; CurPaper.ImageArea.left = pFS->Margin.left; CurPaper.ImageArea.top = pFS->Margin.top; CurPaper.ImageArea.right = CurPaper.Size.cx - pFS->Margin.right; CurPaper.ImageArea.bottom = pPI->pPlotGPC->DeviceSize.cy - pFS->Margin.bottom; str2Wstr(CurPaper.Name, CCHOF(CurPaper.Name), pFS->Name); } else { PLOTERR(("GetComboBoxSelForm: Internal Error, Invalid lParam=%ld", pOptParam->lParam)); return(FALSE); } } else { FORM_INFO_1 *pFI1; DWORD cb; // // This form is in the form data base // pFI1 = pPI->pFI1Base + pOptParam->lParam; CurPaper.Size = pFI1->Size; CurPaper.ImageArea = pFI1->ImageableArea; WCPYFIELDNAME(CurPaper.Name, CCHOF(CurPaper.Name), pFI1->pName); } // // Now we have current paper validated // if (pPI->Flags & PIF_DOCPROP) { // // Turn off first, then turn on paper fields as needed // pPI->PlotDM.dm.dmFields &= ~DM_PAPER_FIELDS; pPI->PlotDM.dm.dmFields |= (DM_FORMNAME | DM_PAPERSIZE); // // Copy down the dmFormName, dmPaperSize and set dmPaperWidth/Length, // the fields for PAPER will bb set to DM_FORMNAME so that we always // can find the form also we may set DM_PAPERSIZE if index number is // <= DMPAPER_LAST // WCPYFIELDNAME(pPI->PlotDM.dm.dmFormName, CCHOF(pPI->PlotDM.dm.dmFormName), CurPaper.Name); pPI->PlotDM.dm.dmPaperSize = (SHORT)(pOptParam->lParam + DMPAPER_FIRST); pPI->PlotDM.dm.dmPaperWidth = SPLTODM(CurPaper.Size.cx); pPI->PlotDM.dm.dmPaperLength = SPLTODM(CurPaper.Size.cy); #if DBG *(PRECTL)&pPI->PlotDM.dm.dmBitsPerPel = CurPaper.ImageArea; #endif } else { pPI->CurPaper = CurPaper; } PLOTDBG(DBG_FORMS, ("*** GetComboBoxSelForm from COMBO = '%s'", CurPaper.Name)); PLOTDBG(DBG_FORMS, ("Size=%ld x %ld", CurPaper.Size.cx, CurPaper.Size.cy)); PLOTDBG(DBG_FORMS, ("ImageArea=(%ld, %ld) - (%ld, %ld)", CurPaper.ImageArea.left, CurPaper.ImageArea.top, CurPaper.ImageArea.right, CurPaper.ImageArea.bottom)); return(TRUE); }
BOOL AddFormsToDataBase( PPRINTERINFO pPI, BOOL DeleteFirst ) /*++ Routine Description: This function add driver supports forms to the data base Arguments: pPI - Pointer to the PRINTERINFO Return Value: BOOLEAN Author: 09-Dec-1993 Thu 22:38:27 created 27-Apr-1994 Wed 19:18:58 updated Fixed bug# 13592 which printman/spooler did not call ptrprop first but docprop so let us into unknown form database state, Revision History: --*/ { WCHAR wName[CCHFORMNAME + 2]; BOOL bRet; LONG i; DWORD Type; Type = REG_SZ; if ((GetPrinterData(pPI->hPrinter, wszModel, &Type, (LPBYTE)wName, sizeof(wName), &i) == ERROR_SUCCESS) && (wcscmp(pPI->PlotDM.dm.dmDeviceName, wName))) { PLOTDBG(DBG_FORMS, ("Already added forms to the data base for %s", pPI->PlotDM.dm.dmDeviceName)); return(TRUE); } // // Find out if we have permission to do this // if (SetPrinterData(pPI->hPrinter, wszModel, REG_SZ, (LPBYTE)pPI->PlotDM.dm.dmDeviceName, (wcslen(pPI->PlotDM.dm.dmDeviceName) + 1) * sizeof(WCHAR)) == ERROR_SUCCESS) { PFORMSRC pFS; FORM_INFO_1 FI1; // // We have permission to update the registry so do it now // pPI->Flags |= PIF_UPDATE_PERMISSION; PLOTDBG(DBG_PERMISSION, ("!!! MODEL NAME: '%s' not Match, Re-installed Form Database", pPI->PlotDM.dm.dmDeviceName)); // // Add the driver supportes forms to the system spooler data base if // not yet done so // FI1.pName = wName; for (i = 0, pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData; i < (LONG)pPI->pPlotGPC->Forms.Count; i++, pFS++) { // // We will only add the non-roll paper forms // if (pFS->Size.cy) { str2Wstr(wName, CCHOF(wName), pFS->Name); // // Firstable we will delete the same name form in the data // base first, this will ensure we have our curent user defined // form can be installed // if (DeleteFirst) { DeleteForm(pPI->hPrinter, wName); } FI1.Size = pFS->Size; FI1.ImageableArea.left = pFS->Margin.left; FI1.ImageableArea.top = pFS->Margin.top; FI1.ImageableArea.right = FI1.Size.cx - pFS->Margin.right; FI1.ImageableArea.bottom = FI1.Size.cy - pFS->Margin.bottom; PLOTDBG(DBG_FORMS, ( "AddForm: %s-[%ld x %ld] (%ld, %ld)-(%ld, %ld)", FI1.pName, FI1.Size.cx, FI1.Size.cy, FI1.ImageableArea.left, FI1.ImageableArea.top, FI1.ImageableArea.right,FI1.ImageableArea.bottom)); FI1.Flags = FORM_PRINTER; if ((!AddForm(pPI->hPrinter, 1, (LPBYTE)&FI1)) && (GetLastError() != ERROR_FILE_EXISTS) && (GetLastError() != ERROR_ALREADY_EXISTS)) { bRet = FALSE; PLOTERR(("AddFormsToDataBase: AddForm(%s) failed, [%ld]", wName, GetLastError())); } } } return(TRUE); } else { pPI->Flags &= ~PIF_UPDATE_PERMISSION; PLOTDBG(DBG_PERMISSION, ("AddFormsToDataBase(): NO UPDATE PERMISSION")); return(FALSE); } }
VOID cdecl PlotDbgPrint( LPCSTR pszFormat, ... ) /*++ Routine Description: This fucntion output the debug informat to the debugger Arguments: pszFormat - format string ... - variable data Return Value: VOID Author: 15-Nov-1993 Mon 17:57:59 created Revision History: --*/ { va_list vaList; #if defined(UMODE) || defined(USERMODE_DRIVER) static WCHAR wOutBuf[768]; static WCHAR wFormatBuf[256]; size_t cch; // // We assume that UNICODE flag is turn on for the compilation, bug the // format string passed to here is ASCII version, so we need to convert // it to LPWSTR before the wvsprintf() // if (!SUCCEEDED(StringCchLengthA(pszFormat, CCHOF(wFormatBuf), &cch))) { return; } va_start(vaList, pszFormat); MultiByteToWideChar(CP_ACP, 0, pszFormat, -1, wFormatBuf, CCHOF(wFormatBuf)); if (!SUCCEEDED(StringCchVPrintfW(wOutBuf, CCHOF(wOutBuf), wFormatBuf, vaList))) { return; } va_end(vaList); OutputDebugString((LPCTSTR)wOutBuf); OutputDebugString(TEXT("\n")); #else va_start(vaList, pszFormat); EngDebugPrint("PLOT",pszFormat,vaList); va_end(vaList); #endif }
DWORD MergePLOTDM( HANDLE hPrinter, _In_ PPLOTGPC pPlotGPC, _In_ PPLOTDEVMODE pPlotDMFrom, _Inout_ PPLOTDEVMODE pPlotDMTo, _Inout_opt_ PFORMSIZE pCurForm ) /*++ Routine Description: This function merge and validate the pPlotDMTo from pPlotDMFrom. The PlotDMOut must valid Arguments: hPrinter - Handle to the printer to be checked pPlotGPC - The plotter's GPC data loaded from the file pPlotDMFrom - pointer to the input PLOTDEVMODE data structure, if can be NULL pPlotDMTo - Pointer to the output PLOTDEVMODE data structure, if pPlotDMFrom is NULL then a default PLOTDEVMODE is returned pCurForm - Pointer to the FORMSIZE data structure which will be updated if the pointer is not NULL, the final result of the form size/imagable area selected by the user will be written to here. the form name will be in pPlotDM->dmFormName. Return Value: the return value is a DWORD dmField error code which specified dmFields are invalid (DM_xxxxx in wingdi.h) if the return value has any DM_INV_xxx bits set then it should raised an error to the user. if return value is 0 then function sucessful Author: 25-Oct-1994 Tue 13:32:18 created Revision History: --*/ { PLOTDEVMODE PlotDMIn; ENUMFORMPARAM EFP; DWORD dmErrFields = 0; SIZEL PaperSize; // // First: set the default PLOTDEVMODE for the output then from there // validate/settting from input devmode, if pwDeviceName passed as // NULL then it assume that pPlotDMTo alreay set and validated // // If we have invalid input devmode then this it is // if ((!pPlotDMFrom) || (!pPlotDMTo) || (!pPlotGPC)) { return(0); } // // Do some conversion here if necessary, first, copy the output one // CopyMemory(&PlotDMIn, pPlotDMTo, sizeof(PLOTDEVMODE)); ConvertDevmode((PDEVMODE) pPlotDMFrom, (PDEVMODE) &PlotDMIn); PLOTDBG(DBG_SHOWDEVMODE, ("--------------- Input DEVMODE Setting -------------------")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmDeviceName = %ls", (DWORD_PTR)PlotDMIn.dm.dmDeviceName)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmSpecVersion = %04lx", (DWORD)PlotDMIn.dm.dmSpecVersion)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmDriverVersion = %04lx", (DWORD)PlotDMIn.dm.dmDriverVersion)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmSize = %0ld (%ld)", (DWORD)PlotDMIn.dm.dmSize, sizeof(DEVMODE))); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmDriverExtra = %ld (%ld)", (DWORD)PlotDMIn.dm.dmDriverExtra, PLOTDM_PRIV_SIZE)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmFields = %08lx", (DWORD)PlotDMIn.dm.dmFields)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmOrientation = %ld (%hs)", (DWORD)PlotDMIn.dm.dmOrientation, (PlotDMIn.dm.dmFields & DM_ORIENTATION) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPaperSize = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPaperSize, (PlotDMIn.dm.dmFields & DM_PAPERSIZE) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPaperLength = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPaperLength, (PlotDMIn.dm.dmFields & DM_PAPERLENGTH) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPaperWidth = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPaperWidth, (PlotDMIn.dm.dmFields & DM_PAPERWIDTH) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmScale = %ld (%hs)", (DWORD)PlotDMIn.dm.dmScale, (PlotDMIn.dm.dmFields & DM_SCALE) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmCopies = %ld (%hs)", (DWORD)PlotDMIn.dm.dmCopies, (PlotDMIn.dm.dmFields & DM_COPIES) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPrintQuality = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPrintQuality, (PlotDMIn.dm.dmFields & DM_PRINTQUALITY) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmColor = %ld (%hs)", (DWORD)PlotDMIn.dm.dmColor, (PlotDMIn.dm.dmFields & DM_COLOR) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmFormName = %ls (%hs)", (DWORD_PTR)PlotDMIn.dm.dmFormName, (PlotDMIn.dm.dmFields & DM_FORMNAME) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: Fill Truetype Font = %hs", (PlotDMIn.Flags & PDMF_FILL_TRUETYPE) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: Plot On the Fly = %hs", (PlotDMIn.Flags & PDMF_PLOT_ON_THE_FLY) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("---------------------------------------------------------")); // // Statring checking the dmFields, *** REMEMBER: The orientation must // check before the checking the paper/form // if (PlotDMIn.dm.dmFields & DM_ORIENTATION) { switch (PlotDMIn.dm.dmOrientation) { case DMORIENT_PORTRAIT: case DMORIENT_LANDSCAPE: pPlotDMTo->dm.dmOrientation = PlotDMIn.dm.dmOrientation; pPlotDMTo->dm.dmFields |= DM_ORIENTATION; break; default: PLOTERR(("ValidatePLOTDM: Invalid dmOrientation = %ld", (LONG)PlotDMIn.dm.dmOrientation)); dmErrFields |= DM_ORIENTATION; break; } } // // Validate form name so we have correct data, assume error first // dmErrFields |= (DWORD)(PlotDMIn.dm.dmFields & DM_PAPER_FIELDS); if (((PlotDMIn.dm.dmFields & DM_PAPER_CUSTOM) == DM_PAPER_CUSTOM) && ((PlotDMIn.dm.dmPaperSize == DMPAPER_USER) || (PlotDMIn.dm.dmPaperSize == 0)) && (PaperSize.cx = DMTOSPL(PlotDMIn.dm.dmPaperWidth)) && (PaperSize.cy = DMTOSPL(PlotDMIn.dm.dmPaperLength)) && (PaperSize.cx >= MIN_SPL_FORM_CX) && (PaperSize.cy >= MIN_SPL_FORM_CY) && (((PaperSize.cx <= pPlotGPC->DeviceSize.cx) && (PaperSize.cy <= pPlotGPC->DeviceSize.cy)) || ((PaperSize.cy <= pPlotGPC->DeviceSize.cx) && (PaperSize.cx <= pPlotGPC->DeviceSize.cy)))) { // // First choice, this is what the caller wants, we need to validate // for this device, since the size may be larger then device can // handle // pPlotDMTo->dm.dmPaperWidth = PlotDMIn.dm.dmPaperWidth; pPlotDMTo->dm.dmPaperLength = PlotDMIn.dm.dmPaperLength; pPlotDMTo->dm.dmFields &= ~DM_PAPER_FIELDS; pPlotDMTo->dm.dmFields |= DM_PAPER_CUSTOM; pPlotDMTo->dm.dmPaperSize = DMPAPER_USER; pPlotDMTo->dm.dmFormName[0] = L'\0'; if (pCurForm) { // // This one is full imageable area as the widht/height // pCurForm->ImageArea.left = pCurForm->ImageArea.top = 0; pCurForm->Size.cx = pCurForm->ImageArea.right = PaperSize.cx; pCurForm->Size.cy = pCurForm->ImageArea.bottom = PaperSize.cy; } dmErrFields &= ~DM_PAPER_FIELDS; // Fine, no error PLOTDBG(DBG_CURFORM,("ValidateSetPLOTDM: FORM=USER <%ld> (%ld x %ld)", PlotDMIn.dm.dmPaperSize, PaperSize.cx, PaperSize.cy)); } else if ((PlotDMIn.dm.dmFields & (DM_PAPERSIZE | DM_FORMNAME)) && (EFP.pPlotDM = pPlotDMTo) && (EFP.pPlotGPC = pPlotGPC) && (PlotEnumForms(hPrinter, NULL, &EFP))) { FORM_INFO_1 *pFI1 = NULL; SHORT sPaperSize = 0; BOOL Found = FALSE; // // Firstable check sPaperSize index and if not found then check formname // if ((PlotDMIn.dm.dmFields & DM_PAPERSIZE) && ((sPaperSize = PlotDMIn.dm.dmPaperSize) >= DMPAPER_FIRST) && (sPaperSize <= (SHORT)EFP.Count) && (pFI1 = EFP.pFI1Base + (sPaperSize - DMPAPER_FIRST)) && (pFI1->Flags & FI1F_VALID_SIZE)) { // // Whu..., this guy really pick a right index // Found = TRUE; PLOTDBG(DBG_CURFORM,("ValidateSetPLOTDM: Fount dmPaperSize=%ld", PlotDMIn.dm.dmPaperSize)); } else if (PlotDMIn.dm.dmFields & DM_FORMNAME) { // // Now go through all the formname trouble // pFI1 = EFP.pFI1Base; sPaperSize = DMPAPER_FIRST; while (EFP.Count--) { if ((pFI1->Flags & FI1F_VALID_SIZE) && (!wcscmp(pFI1->pName, PlotDMIn.dm.dmFormName))) { PLOTDBG(DBG_CURFORM,("ValidateSetPLOTDM: Found dmFormName=%s", PlotDMIn.dm.dmFormName)); Found = TRUE; break; } ++sPaperSize; ++pFI1; } } if (Found) { pPlotDMTo->dm.dmFields &= ~DM_PAPER_FIELDS; pPlotDMTo->dm.dmFields |= (DM_FORMNAME | DM_PAPERSIZE); pPlotDMTo->dm.dmPaperSize = sPaperSize; pPlotDMTo->dm.dmPaperWidth = SPLTODM(pFI1->Size.cx); pPlotDMTo->dm.dmPaperLength = SPLTODM(pFI1->Size.cy); WCPYFIELDNAME(pPlotDMTo->dm.dmFormName, CCHOF(pPlotDMTo->dm.dmFormName), pFI1->pName); PLOTDBG(DBG_CURFORM,("FI1 [%ld]: (%ld x %ld), (%ld, %ld)-(%ld, %ld)", (LONG)pPlotDMTo->dm.dmPaperSize, pFI1->Size.cx, pFI1->Size.cy, pFI1->ImageableArea.left, pFI1->ImageableArea.top, pFI1->ImageableArea.right, pFI1->ImageableArea.bottom)); if (pCurForm) { pCurForm->Size = pFI1->Size; pCurForm->ImageArea = pFI1->ImageableArea; } dmErrFields &= ~DM_PAPER_FIELDS; // Fine, no error } // // Free up the memory used // LocalFree((HLOCAL)EFP.pFI1Base); } if ((PlotDMIn.dm.dmFields & DM_SCALE) && (pPlotGPC->MaxScale)) { if ((PlotDMIn.dm.dmScale > 0) && ((WORD)PlotDMIn.dm.dmScale <= pPlotGPC->MaxScale)) { pPlotDMTo->dm.dmScale = PlotDMIn.dm.dmScale; pPlotDMTo->dm.dmFields |= DM_SCALE; } else { PLOTERR(("ValidatePLOTDM: Invalid dmScale = %ld [%ld]", (LONG)PlotDMIn.dm.dmScale, (LONG)pPlotGPC->MaxScale)); dmErrFields |= DM_SCALE; } } if (PlotDMIn.dm.dmFields & DM_COPIES) { if ((PlotDMIn.dm.dmCopies > 0) && ((LONG)PlotDMIn.dm.dmCopies <= (LONG)pPlotGPC->MaxCopies)) { pPlotDMTo->dm.dmCopies = PlotDMIn.dm.dmCopies; pPlotDMTo->dm.dmFields |= DM_COPIES; } else { PLOTERR(("ValidatePLOTDM: Invalid dmCopies = %ld [%ld]", (LONG)PlotDMIn.dm.dmCopies, (LONG)pPlotGPC->MaxCopies)); dmErrFields |= DM_COPIES; } } if (PlotDMIn.dm.dmFields & DM_PRINTQUALITY) { dmErrFields |= DM_PRINTQUALITY; // assume error, proven otherwise if (pPlotGPC->MaxQuality) { switch (PlotDMIn.dm.dmPrintQuality) { case DMRES_DRAFT: case DMRES_LOW: case DMRES_MEDIUM: case DMRES_HIGH: dmErrFields &= ~DM_PRINTQUALITY; pPlotDMTo->dm.dmPrintQuality = PlotDMIn.dm.dmPrintQuality; pPlotDMTo->dm.dmFields |= DM_PRINTQUALITY; break; } } if (dmErrFields & DM_PRINTQUALITY) { PLOTERR(("ValidatePLOTDM: Invalid dmPrintQuality = %ld [%ld]", (LONG)PlotDMIn.dm.dmPrintQuality, (LONG)pPlotGPC->MaxQuality)); } } if (PlotDMIn.dm.dmFields & DM_COLOR) { dmErrFields |= DM_COLOR; // assume error, proven otherwise if (pPlotGPC->Flags & PLOTF_COLOR) { switch (PlotDMIn.dm.dmColor) { case DMCOLOR_MONOCHROME: if (!(pPlotGPC->Flags & PLOTF_RASTER)) { PLOTERR(("ValidatePLOTDM: Cannot Set Pen Plotter to MONO")); break; } case DMCOLOR_COLOR: pPlotDMTo->dm.dmColor = PlotDMIn.dm.dmColor; pPlotDMTo->dm.dmFields |= DM_COLOR; dmErrFields &= ~DM_COLOR; break; } } else if (PlotDMIn.dm.dmColor == DMCOLOR_MONOCHROME) { dmErrFields &= ~DM_COLOR; } if (dmErrFields & DM_COLOR) { PLOTERR(("ValidatePLOTDM: Invalid dmColor = %ld [%hs]", (LONG)PlotDMIn.dm.dmColor, (pPlotGPC->Flags & PLOTF_COLOR) ? "COLOR" : "MONO")); } } // // Any other dmFields we just skip because we do not have that caps, now // check if they have correct EXTDEVMODE stuff // if ((PlotDMIn.dm.dmDriverExtra == PLOTDM_PRIV_SIZE) && (PlotDMIn.PrivID == PLOTDM_PRIV_ID) && (PlotDMIn.PrivVer == PLOTDM_PRIV_VER)) { pPlotDMTo->Flags = (DWORD)(PlotDMIn.Flags & PDMF_ALL_BITS); pPlotDMTo->ca = PlotDMIn.ca; if (pPlotGPC->Flags & PLOTF_RASTER) { pPlotDMTo->Flags |= PDMF_FILL_TRUETYPE; } else { // // Non raster device does not have plot on the fly mode // pPlotDMTo->Flags &= ~PDMF_PLOT_ON_THE_FLY; } if (!ValidateColorAdj(&(pPlotDMTo->ca))) { dmErrFields |= DM_INV_PLOTPRIVATE; PLOTERR(("ValidatePLOTDM: Invalid coloradjusment data")); } } return(dmErrFields); }
VOID SetDefaultPLOTDM( HANDLE hPrinter, _In_ PPLOTGPC pPlotGPC, _In_opt_ LPCWSTR pwDeviceName, _In_ PPLOTDEVMODE pPlotDM, _Out_opt_ PFORMSIZE pCurForm ) /*++ Routine Description: This function set the default devmode based on the current pPlotGPC Arguments: hPrinter - Handle to the printer pPlotGPC - our loaded/verified GPC data. pwDeviceName - the device name passed in pPlotDM - Pointer to our ExtDevMode pCurForm - Pointer to the FORMSIZE data structure which will be updated if the pointer is not NULL, the final result of the form size/imagable area selected by the user will be written to here. the form name will be in pPlotDM->dmFormName. Return Value: VOID Author: 14-Dec-1993 Tue 20:21:48 updated Update the dmScale based on maximum the device can support 06-Dec-1993 Mon 12:49:52 updated make sure we turn off the DM_xxx bits if one of those is not valid or supported in current plotter 16-Nov-1993 Tue 13:49:27 created Revision History: --*/ { WCHAR *pwchDeviceName = NULL; ULONG ulStrLen = 0; UNREFERENCED_PARAMETER(hPrinter); // // Device name including NULL terminator // must be equal or shorter than CCHDEVICENAME. // PREFIX doesn' take this assumption. Buffer size needs to be flexible and // should not be on stack. // if (pwDeviceName) { ulStrLen = (ULONG)wcslen(pwDeviceName); // // Allocate buffer to hold pwDeviceName including null terminator. // Make sure that pwDeviceName has a device name. // if (0 == ulStrLen || !(pwchDeviceName = (WCHAR*)LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, (ulStrLen + 1) * sizeof(WCHAR)))) { PLOTERR(("SetDefaultPLOTDM: memory allocaton failed.\n")); // // Make sure that pPlotGPC->DeviceName has a null terminator. // pPlotGPC->DeviceName[0] = (BYTE)'\0'; } else { _WCPYSTR_FILL_TRAIL_WITH_NULL(pwchDeviceName, ulStrLen + 1, pwDeviceName); // // Make sure the PlotGPC's device name is ssync with the pDeviceName // passed. // String length must be equal or shorter than CCHDEVICENAME. // DEVMODE's device name and pPlotGPC->DeviceName can't hold a sting // longer than CCHDEVICENAME. // if (ulStrLen + 1 > CCHDEVICENAME) { PLOTERR(("SetDefaultPLOTDM: DeviceName is longer than buffer size.\n")); } else { WStr2Str(pPlotGPC->DeviceName, CCHOF(pPlotGPC->DeviceName), pwchDeviceName); } } PLOTDBG(DBG_DEFDEVMODE, ("PlotGPC DeviceName=%hs\npwDeviceName=%ls", pPlotGPC->DeviceName, pwDeviceName)); } else { PLOTERR(("No DeviceName passed, using GPC's '%hs'", pPlotGPC->DeviceName)); ulStrLen = (ULONG)strlen(pPlotGPC->DeviceName); // // Allocate buffer to hold pwDeviceName including null terminator. // Make sure that pwDeviceName has a device name. // if (0 == ulStrLen || !(pwchDeviceName = (WCHAR*)LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, (ulStrLen + 1) * sizeof(WCHAR)))) { PLOTERR(("SetDefaultPLOTDM: memory allocaton failed.\n")); } else { str2Wstr(pwchDeviceName, ulStrLen + 1, pPlotGPC->DeviceName); } } // // Make a default copy first then copy device name down // CopyMemory(pPlotDM, &_DefPlotDM, sizeof(PLOTDEVMODE)); if (pwchDeviceName) { WCPYFIELDNAME(pPlotDM->dm.dmDeviceName, CCHOF(pPlotDM->dm.dmDeviceName), pwchDeviceName); LocalFree(pwchDeviceName); } else { pPlotDM->dm.dmDeviceName[0] = L'\0'; } // // We must turn off the DM_xxx bits in dmFields if we do not support it, // look at default fields we copy down then update it // if (pPlotGPC->MaxScale) { if ((WORD)pPlotDM->dm.dmScale > pPlotGPC->MaxScale) { pPlotDM->dm.dmScale = (SHORT)pPlotGPC->MaxScale; } } else { pPlotDM->dm.dmFields &= ~DM_SCALE; } if (pPlotGPC->MaxCopies <= 1) { pPlotDM->dm.dmFields &= ~DM_COPIES; } if (!(pPlotGPC->MaxQuality)) { pPlotDM->dm.dmFields &= ~DM_PRINTQUALITY; } // // DEFAULT 50% quality for byte align plotter (DJ 600) to do ROP right // if (pPlotGPC->Flags & PLOTF_RASTERBYTEALIGN) { pPlotDM->dm.dmPrintQuality = DMRES_LOW; PLOTWARN(("SetDefaultPLOTDM: Force Default Qaulity = DMRES_LOW")); } if (!(pPlotGPC->Flags & PLOTF_COLOR)) { if (pPlotGPC->Flags & PLOTF_RASTER) { pPlotDM->dm.dmFields &= ~DM_COLOR; pPlotDM->dm.dmColor = DMCOLOR_MONOCHROME; } else { PLOTASSERT(0, "SetDefaultPLOTDM: The Pen Ploter CANNOT be MONO.", (pPlotGPC->Flags & PLOTF_COLOR), 0); pPlotGPC->Flags |= PLOTF_COLOR; } } // // Set default form name based on the country/region // SetDefaultDMForm(pPlotDM, pCurForm); }
SHORT GetDefaultPaper( PPAPERINFO pPaperInfo ) /*++ Routine Description: This function compute the default paper name, size. Arguments: pPaperInfo - Point to the paper info which will be fill by this function Return Value: It return a SHORT value which specified the standard paper index in as DMPAPER_xxx Author: 03-Dec-1993 Fri 13:13:42 created Revision History: --*/ { SHORT dmPaperSize; HRESULT hr; if (pPaperInfo == NULL) { return 0; } pPaperInfo->ImageArea.left = pPaperInfo->ImageArea.top = 0; if (IsA4PaperDefault()) { dmPaperSize = (SHORT)DMPAPER_A4; pPaperInfo->Size.cx = pPaperInfo->ImageArea.right = DMTOSPL(A4_FORM_CX); pPaperInfo->Size.cy = pPaperInfo->ImageArea.bottom = DMTOSPL(A4_FORM_CY); hr = StringCchCopy(pPaperInfo->Name, CCHOF(pPaperInfo->Name), A4_FORM_NAME); if (FAILED(hr) ) { PLOTASSERT(0, "Couldn't copy the string %ls to pPaperInfo", SUCCEEDED(hr), A4_FORM_NAME); } PLOTDBG(DBG_DEFPAPER, ("Pick 'A4' paper as default")); } else { dmPaperSize = (SHORT)DMPAPER_LETTER; pPaperInfo->Size.cx = (LONG)_DefPlotDM.dm.dmPaperWidth; pPaperInfo->Size.cy = (LONG)_DefPlotDM.dm.dmPaperLength; dmPaperSize = (SHORT)DMPAPER_LETTER; pPaperInfo->Size.cx = pPaperInfo->ImageArea.right = DMTOSPL(_DefPlotDM.dm.dmPaperWidth); pPaperInfo->Size.cy = pPaperInfo->ImageArea.bottom = DMTOSPL(_DefPlotDM.dm.dmPaperLength); hr = StringCchCopy(pPaperInfo->Name, CCHOF(pPaperInfo->Name), _DefPlotDM.dm.dmFormName); if (FAILED(hr) ) { PLOTASSERT(0, "Couldn't copy the string %ls to pPaperInfo", SUCCEEDED(hr), _DefPlotDM.dm.dmFormName); } PLOTDBG(DBG_DEFPAPER, ("Pick 'Letter' paper as default")); } PLOTDBG(DBG_DEFPAPER, ("SetDefaultPaper: '%ls' (%ld x %ld)", pPaperInfo->Name, pPaperInfo->Size.cx, pPaperInfo->Size.cy)); return(dmPaperSize); }
BOOL IsA4PaperDefault( VOID ) /*++ Routine Description: This function determine if the machine user is using the letter or A4 paper as default based on the country/region code Arguments: NONE Return Value: BOOL true if the country/region default paper is A4, else LETTER Author: 23-Nov-1993 Tue 17:50:25 created 02-Feb-1994 Wed 03:01:12 updated re-written so that we do open registry for the international data ourself, and we will make sure we close the all the keys opened by this function, so the system can unload the registry when the user log off. Revision History: --*/ { #if HAS_GETREGDATA HKEY hKey; LONG CountryCode = DEFAULT_COUNTRY; WCHAR wszStr[16]; if (RegOpenKey(HKEY_CURRENT_USER, wszCountryKey, &hKey) == ERROR_SUCCESS) { DWORD Type = REG_SZ; DWORD RetVal = sizeof(wszStr); size_t cch; if (RegQueryValueEx(hKey, (LPTSTR)wszCountryValue, NULL, &Type, (LPBYTE)wszStr, &RetVal) == ERROR_SUCCESS) { LPWSTR pwStop; PLOTDBG(DBG_A4DEFAULT, ("IsA4PaperDefault: Country/Region = %s", wszStr)); if (Type == REG_SZ && SUCCEEDED(StringCchLength(wszStr, CCHOF(wszStr), &cch))) { CountryCode = wcstoul(wszStr, &pwStop, 10); } else { PLOTERR(("IsA4PaperDefault: RegQueryValue '%s' FAILED", wszCountryValue)); } } else { PLOTERR(("IsA4PaperDefault: RegQueryValue '%s' FAILED", wszCountryValue)); } RegCloseKey(hKey); } else { PLOTERR(("IsA4PaperDefault: RegOpenKey '%s' FAILED", wszCountryKey)); } if ((CountryCode == CTRY_UNITED_STATES) || (CountryCode == CTRY_CANADA) || ((CountryCode >= 50) && (CountryCode < 60)) || ((CountryCode >= 500) && (CountryCode < 600))) { PLOTDBG(DBG_A4DEFAULT, ("IsA4PaperDefault = No, Use 'LETTER'")); return(FALSE); } else { PLOTDBG(DBG_A4DEFAULT, ("IsA4PaperDefault = Yes")); return(TRUE); } #else // // Use letter size now // return(FALSE); #endif // HAS_GETREGDATA }