Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. forms.c
  5. Abstract:
  6. Functions for manipulating forms
  7. Environment:
  8. Fax driver, user and kernel mode
  9. Revision History:
  10. 01/09/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxlib.h"
  16. #include "forms.h"
  17. BOOL
  18. ValidDevmodeForm(
  19. HANDLE hPrinter,
  20. PDEVMODE pdm,
  21. PFORM_INFO_1 pFormInfo
  22. )
  23. /*++
  24. Routine Description:
  25. Validate the form specification in a devmode
  26. Arguments:
  27. hPrinter - Handle to the printer object
  28. pdm - Pointer to the input devmode
  29. pFormInfo - FORM_INFO_1 structure for returning form information
  30. Return Value:
  31. TRUE if the input devmode specifies a valid logical form
  32. FALSE otherwise
  33. --*/
  34. {
  35. PFORM_INFO_1 pForm, pFormDB;
  36. DWORD cForms;
  37. //
  38. // Get a list of forms in the system
  39. //
  40. if (! (pForm = pFormDB = GetFormsDatabase(hPrinter, &cForms))) {
  41. Error(("Couldn't get system forms\n"));
  42. return FALSE;
  43. }
  44. if ((pdm->dmFields & DM_PAPERSIZE) && pdm->dmPaperSize >= DMPAPER_FIRST) {
  45. //
  46. // Devmode is specifying a form using paper size index
  47. //
  48. DWORD index = pdm->dmPaperSize - DMPAPER_FIRST;
  49. if (index < cForms)
  50. pForm = pFormDB + index;
  51. else
  52. pForm = NULL;
  53. } else if (pdm->dmFields & DM_FORMNAME) {
  54. //
  55. // Devmode is specifying a form using form name: go through the forms database
  56. // and check if the requested form name matches that of a form in the database
  57. //
  58. while (cForms && _tcsicmp(pForm->pName, pdm->dmFormName) != EQUAL_STRING) {
  59. pForm++;
  60. cForms--;
  61. }
  62. if (cForms == 0)
  63. pForm = NULL;
  64. }
  65. if (pForm && IsSupportedForm(pForm)) {
  66. if (pFormInfo)
  67. *pFormInfo = *pForm;
  68. //
  69. // Convert paper size unit from microns to 0.1mm
  70. //
  71. pdm->dmPaperWidth = (SHORT)(pForm->Size.cx / 100);
  72. pdm->dmPaperLength = (SHORT)(pForm->Size.cy / 100);
  73. if ((pdm->dmFields & DM_FORMNAME) == 0) {
  74. pdm->dmFields |= DM_FORMNAME;
  75. CopyString(pdm->dmFormName, pForm->pName, CCHFORMNAME);
  76. }
  77. }
  78. else
  79. {
  80. //
  81. // The form is not supported
  82. //
  83. pForm = NULL;
  84. }
  85. MemFree(pFormDB);
  86. return pForm != NULL;
  87. }
  88. PFORM_INFO_1
  89. GetFormsDatabase(
  90. HANDLE hPrinter,
  91. PDWORD pCount
  92. )
  93. /*++
  94. Routine Description:
  95. Return a collection of forms in the spooler database
  96. Arguments:
  97. hPrinter - Handle to a printer object
  98. pCount - Points to a variable for returning total number of forms
  99. Return Value:
  100. Pointer to an array of FORM_INFO_1 structures if successful
  101. NULL otherwise
  102. --*/
  103. {
  104. PFORM_INFO_1 pFormDB = NULL;
  105. DWORD cb=0;
  106. if (!EnumForms(hPrinter, 1, NULL, 0, &cb, pCount) &&
  107. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  108. (pFormDB = MemAlloc(cb)) != NULL &&
  109. EnumForms(hPrinter, 1, (PBYTE) pFormDB, cb, &cb, pCount))
  110. {
  111. PFORM_INFO_1 pForm;
  112. DWORD count;
  113. LONG maxX, maxY;
  114. //
  115. // Calculate the maximum allowable form width and height (in microns)
  116. //
  117. maxX = MulDiv(MAX_WIDTH_PIXELS, 25400, FAXRES_HORIZONTAL);
  118. maxY = MulDiv(MAX_HEIGHT_PIXELS, 25400, FAXRES_VERTICAL);
  119. for (count=*pCount, pForm=pFormDB; count--; pForm++) {
  120. //
  121. // Make sure the highest order bits are not used by the spooler
  122. //
  123. Assert(! IsSupportedForm(pForm));
  124. //
  125. // Determine if the form in question is supported on the device
  126. //
  127. if (pForm->ImageableArea.right - pForm->ImageableArea.left <= maxX &&
  128. pForm->ImageableArea.bottom - pForm->ImageableArea.top <= maxY)
  129. {
  130. SetSupportedForm(pForm);
  131. }
  132. }
  133. return pFormDB;
  134. }
  135. Error(("EnumForms failed\n"));
  136. MemFree(pFormDB);
  137. return NULL;
  138. }