1 /*
2 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
644 }
645 if (resBuf != NULL) {
646 if (::DeviceCapabilities(printerName, printerPort,
647 DC_ENUMRESOLUTIONS, resBuf,
648 NULL) != -1) {
649 LONG *pResolution = (LONG *)resBuf;
650 for (int i = 0; i < nResolutions; i++) {
651 jpcIndices[i*2] = *pResolution++;
652 jpcIndices[i*2+1] = *pResolution++;
653 }
654 }
655 RESTORE_CONTROLWORD
656 delete[] resBuf;
657 }
658 env->ReleaseIntArrayElements(resolutionArray, saveFormats, 0);
659 }
660 }
661 }
662
663 JNU_ReleaseStringPlatformChars(env, printer, printerName);
664 JNU_ReleaseStringPlatformChars(env, printer, printerPort);
665 return resolutionArray;
666 }
667
668
669 static BOOL IsDCPostscript( HDC hDC )
670 {
671 int nEscapeCode;
672 CHAR szTechnology[MAX_PATH] = "";
673
674 // If it supports POSTSCRIPT_PASSTHROUGH, it must be PS.
675 nEscapeCode = POSTSCRIPT_PASSTHROUGH;
676 if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
677 (LPCSTR)&nEscapeCode, 0, NULL ) > 0 )
678 return TRUE;
679
680 // If it doesn't support GETTECHNOLOGY, we won't be able to tell.
681 nEscapeCode = GETTECHNOLOGY;
682 if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
683 (LPCSTR)&nEscapeCode, 0, NULL ) <= 0 )
684 return FALSE;
787 if (pdc != NULL) {
788 // get Color
789 int bpp = GetDeviceCaps(pdc, BITSPIXEL);
790 int nColors = GetDeviceCaps(pdc, NUMCOLORS);
791
792 if (!(dmFields & DM_COLOR) || ((bpp == 1)
793 && ((nColors == 2) || (nColors == 256)))) {
794 ret &= ~0x0001;
795 }
796
797 // check support for PostScript
798 if (IsDCPostscript(pdc)) {
799 ret |= 0x0010;
800 }
801
802 DeleteDC(pdc);
803 }
804
805 RESTORE_CONTROLWORD
806 JNU_ReleaseStringPlatformChars(env, printer, printerName);
807 JNU_ReleaseStringPlatformChars(env, printer, printerPort);
808 return ret;
809 }
810
811
812 #define GETDEFAULT_ERROR -50
813 #define NDEFAULT 9
814
815 JNIEXPORT jintArray JNICALL
816 Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env,
817 jobject peer,
818 jstring printer,
819 jstring port)
820 {
821 HANDLE hPrinter;
822 LPDEVMODE pDevMode = NULL;
823
824 LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
825 LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
826
827 if (printerName == NULL || printerPort == NULL) {
|
1 /*
2 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
644 }
645 if (resBuf != NULL) {
646 if (::DeviceCapabilities(printerName, printerPort,
647 DC_ENUMRESOLUTIONS, resBuf,
648 NULL) != -1) {
649 LONG *pResolution = (LONG *)resBuf;
650 for (int i = 0; i < nResolutions; i++) {
651 jpcIndices[i*2] = *pResolution++;
652 jpcIndices[i*2+1] = *pResolution++;
653 }
654 }
655 RESTORE_CONTROLWORD
656 delete[] resBuf;
657 }
658 env->ReleaseIntArrayElements(resolutionArray, saveFormats, 0);
659 }
660 }
661 }
662
663 JNU_ReleaseStringPlatformChars(env, printer, printerName);
664 JNU_ReleaseStringPlatformChars(env, port, printerPort);
665 return resolutionArray;
666 }
667
668
669 static BOOL IsDCPostscript( HDC hDC )
670 {
671 int nEscapeCode;
672 CHAR szTechnology[MAX_PATH] = "";
673
674 // If it supports POSTSCRIPT_PASSTHROUGH, it must be PS.
675 nEscapeCode = POSTSCRIPT_PASSTHROUGH;
676 if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
677 (LPCSTR)&nEscapeCode, 0, NULL ) > 0 )
678 return TRUE;
679
680 // If it doesn't support GETTECHNOLOGY, we won't be able to tell.
681 nEscapeCode = GETTECHNOLOGY;
682 if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
683 (LPCSTR)&nEscapeCode, 0, NULL ) <= 0 )
684 return FALSE;
787 if (pdc != NULL) {
788 // get Color
789 int bpp = GetDeviceCaps(pdc, BITSPIXEL);
790 int nColors = GetDeviceCaps(pdc, NUMCOLORS);
791
792 if (!(dmFields & DM_COLOR) || ((bpp == 1)
793 && ((nColors == 2) || (nColors == 256)))) {
794 ret &= ~0x0001;
795 }
796
797 // check support for PostScript
798 if (IsDCPostscript(pdc)) {
799 ret |= 0x0010;
800 }
801
802 DeleteDC(pdc);
803 }
804
805 RESTORE_CONTROLWORD
806 JNU_ReleaseStringPlatformChars(env, printer, printerName);
807 JNU_ReleaseStringPlatformChars(env, port, printerPort);
808 return ret;
809 }
810
811
812 #define GETDEFAULT_ERROR -50
813 #define NDEFAULT 9
814
815 JNIEXPORT jintArray JNICALL
816 Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env,
817 jobject peer,
818 jstring printer,
819 jstring port)
820 {
821 HANDLE hPrinter;
822 LPDEVMODE pDevMode = NULL;
823
824 LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
825 LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
826
827 if (printerName == NULL || printerPort == NULL) {
|