856 ::ClosePrinter(hPrinter);
857 env->ReleaseIntArrayElements(defaultArray, saveFormats, 0);
858 JNU_ReleaseStringPlatformChars(env, printer, printerName);
859 JNU_ReleaseStringPlatformChars(env, port, printerPort);
860 return defaultArray;
861 }
862
863 /* Have seen one driver which reports a default paper id which is not
864 * one of their supported paper ids. If what is returned is not
865 * a supported paper, use one of the supported sizes instead.
866 *
867 */
868 if (pDevMode->dmFields & DM_PAPERSIZE) {
869 defIndices[0] = pDevMode->dmPaperSize;
870
871 SAVE_CONTROLWORD
872
873 int numSizes = ::DeviceCapabilities(printerName, printerPort,
874 DC_PAPERS, NULL, NULL);
875 if (numSizes > 0) {
876 LPTSTR papers = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, numSizes, sizeof(WORD));
877 if (papers != NULL &&
878 ::DeviceCapabilities(printerName, printerPort,
879 DC_PAPERS, papers, NULL) != -1) {
880 int present = 0;
881 for (int i=0;i<numSizes;i++) {
882 if (papers[i] == pDevMode->dmPaperSize) {
883 present = 1;
884 }
885 }
886 if (!present) {
887 defIndices[0] = papers[0];
888 }
889 if (papers != NULL) {
890 free((char*)papers);
891 }
892 }
893 }
894 RESTORE_CONTROLWORD
895 }
896
|
856 ::ClosePrinter(hPrinter);
857 env->ReleaseIntArrayElements(defaultArray, saveFormats, 0);
858 JNU_ReleaseStringPlatformChars(env, printer, printerName);
859 JNU_ReleaseStringPlatformChars(env, port, printerPort);
860 return defaultArray;
861 }
862
863 /* Have seen one driver which reports a default paper id which is not
864 * one of their supported paper ids. If what is returned is not
865 * a supported paper, use one of the supported sizes instead.
866 *
867 */
868 if (pDevMode->dmFields & DM_PAPERSIZE) {
869 defIndices[0] = pDevMode->dmPaperSize;
870
871 SAVE_CONTROLWORD
872
873 int numSizes = ::DeviceCapabilities(printerName, printerPort,
874 DC_PAPERS, NULL, NULL);
875 if (numSizes > 0) {
876 LPTSTR papers;
877 try {
878 papers = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, numSizes, sizeof(WORD));
879 } catch (const std::bad_alloc&) {
880 papers = NULL;
881 }
882
883 if (papers != NULL &&
884 ::DeviceCapabilities(printerName, printerPort,
885 DC_PAPERS, papers, NULL) != -1) {
886 int present = 0;
887 for (int i=0;i<numSizes;i++) {
888 if (papers[i] == pDevMode->dmPaperSize) {
889 present = 1;
890 }
891 }
892 if (!present) {
893 defIndices[0] = papers[0];
894 }
895 if (papers != NULL) {
896 free((char*)papers);
897 }
898 }
899 }
900 RESTORE_CONTROLWORD
901 }
902
|