提交 5ff8fe72 编写于 作者: P prr

8016485: Windows native print dialog does not reflect default printer settings

Reviewed-by: jgodinez, jchen
上级 fa61b182
...@@ -1269,11 +1269,13 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -1269,11 +1269,13 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
mLastFontFamily = null; mLastFontFamily = null;
} }
private boolean defaultCopies = true;
/** /**
* Set the number of copies to be printed. * Set the number of copies to be printed.
*/ */
public void setCopies(int copies) { public void setCopies(int copies) {
super.setCopies(copies); super.setCopies(copies);
defaultCopies = false;
mAttCopies = copies; mAttCopies = copies;
setNativeCopies(copies); setNativeCopies(copies);
} }
...@@ -1529,8 +1531,9 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -1529,8 +1531,9 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
} }
/* SheetCollate */ /* SheetCollate */
private final boolean getCollateAttrib() { private final int getCollateAttrib() {
return (mAttCollate == 1); // -1 means unset, 0 uncollated, 1 collated.
return mAttCollate;
} }
private void setCollateAttrib(Attribute attr) { private void setCollateAttrib(Attribute attr) {
...@@ -1553,6 +1556,10 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -1553,6 +1556,10 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
int orient = PageFormat.PORTRAIT; int orient = PageFormat.PORTRAIT;
OrientationRequested orientReq = (attributes == null) ? null : OrientationRequested orientReq = (attributes == null) ? null :
(OrientationRequested)attributes.get(OrientationRequested.class); (OrientationRequested)attributes.get(OrientationRequested.class);
if (orientReq == null) {
orientReq = (OrientationRequested)
myService.getDefaultAttributeValue(OrientationRequested.class);
}
if (orientReq != null) { if (orientReq != null) {
if (orientReq == OrientationRequested.REVERSE_LANDSCAPE) { if (orientReq == OrientationRequested.REVERSE_LANDSCAPE) {
orient = PageFormat.REVERSE_LANDSCAPE; orient = PageFormat.REVERSE_LANDSCAPE;
...@@ -1573,7 +1580,11 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -1573,7 +1580,11 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
/* Copies and Page Range. */ /* Copies and Page Range. */
private final int getCopiesAttrib() { private final int getCopiesAttrib() {
return getCopiesInt(); if (defaultCopies) {
return 0;
} else {
return getCopiesInt();
}
} }
private final void setRangeCopiesAttribute(int from, int to, private final void setRangeCopiesAttribute(int from, int to,
...@@ -1584,6 +1595,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { ...@@ -1584,6 +1595,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
attributes.add(new PageRanges(from, to)); attributes.add(new PageRanges(from, to));
setPageRange(from, to); setPageRange(from, to);
} }
defaultCopies = false;
attributes.add(new Copies(copies)); attributes.add(new Copies(copies));
/* Since this is called from native to tell Java to sync /* Since this is called from native to tell Java to sync
* up with native, we don't call this class's own setCopies() * up with native, we don't call this class's own setCopies()
......
...@@ -180,6 +180,9 @@ public class Win32PrintService implements PrintService, AttributeUpdater, ...@@ -180,6 +180,9 @@ public class Win32PrintService implements PrintService, AttributeUpdater,
private static final int DMDUP_VERTICAL = 2; private static final int DMDUP_VERTICAL = 2;
private static final int DMDUP_HORIZONTAL = 3; private static final int DMDUP_HORIZONTAL = 3;
private static final int DMCOLLATE_TRUE = 1; private static final int DMCOLLATE_TRUE = 1;
private static final int DMCOLOR_MONOCHROME = 1;
private static final int DMCOLOR_COLOR = 2;
// media sizes with indices above dmPaperToPrintService' length // media sizes with indices above dmPaperToPrintService' length
private static final int DMPAPER_A2 = 66; private static final int DMPAPER_A2 = 66;
...@@ -1041,6 +1044,7 @@ public class Win32PrintService implements PrintService, AttributeUpdater, ...@@ -1041,6 +1044,7 @@ public class Win32PrintService implements PrintService, AttributeUpdater,
int defOrient = defaults[5]; int defOrient = defaults[5];
int defSides = defaults[6]; int defSides = defaults[6];
int defCollate = defaults[7]; int defCollate = defaults[7];
int defColor = defaults[8];
if (category == Copies.class) { if (category == Copies.class) {
if (defCopies > 0) { if (defCopies > 0) {
...@@ -1049,11 +1053,10 @@ public class Win32PrintService implements PrintService, AttributeUpdater, ...@@ -1049,11 +1053,10 @@ public class Win32PrintService implements PrintService, AttributeUpdater,
return new Copies(1); return new Copies(1);
} }
} else if (category == Chromaticity.class) { } else if (category == Chromaticity.class) {
int caps = getPrinterCapabilities(); if (defColor == DMCOLOR_COLOR) {
if ((caps & DEVCAP_COLOR) == 0) {
return Chromaticity.MONOCHROME;
} else {
return Chromaticity.COLOR; return Chromaticity.COLOR;
} else {
return Chromaticity.MONOCHROME;
} }
} else if (category == JobName.class) { } else if (category == JobName.class) {
return new JobName("Java Printing", null); return new JobName("Java Printing", null);
......
...@@ -750,7 +750,7 @@ Java_sun_print_Win32PrintService_getCapabilities(JNIEnv *env, ...@@ -750,7 +750,7 @@ Java_sun_print_Win32PrintService_getCapabilities(JNIEnv *env,
#define GETDEFAULT_ERROR -50 #define GETDEFAULT_ERROR -50
#define NDEFAULT 8 #define NDEFAULT 9
JNIEXPORT jintArray JNICALL JNIEXPORT jintArray JNICALL
Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env, Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env,
...@@ -859,6 +859,11 @@ Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env, ...@@ -859,6 +859,11 @@ Java_sun_print_Win32PrintService_getDefaultSettings(JNIEnv *env,
defIndices[7] = pDevMode->dmCollate; defIndices[7] = pDevMode->dmCollate;
} }
if (pDevMode->dmFields & DM_COLOR) {
defIndices[8] = pDevMode->dmColor;
}
GlobalFree(pDevMode); GlobalFree(pDevMode);
::ClosePrinter(hPrinter); ::ClosePrinter(hPrinter);
......
...@@ -252,7 +252,7 @@ void AwtPrintControl::initIDs(JNIEnv *env, jclass cls) ...@@ -252,7 +252,7 @@ void AwtPrintControl::initIDs(JNIEnv *env, jclass cls)
AwtPrintControl::getCopiesID = AwtPrintControl::getCopiesID =
env->GetMethodID(cls, "getCopiesAttrib", "()I"); env->GetMethodID(cls, "getCopiesAttrib", "()I");
AwtPrintControl::getCollateID = AwtPrintControl::getCollateID =
env->GetMethodID(cls, "getCollateAttrib","()Z"); env->GetMethodID(cls, "getCollateAttrib","()I");
AwtPrintControl::getOrientID = AwtPrintControl::getOrientID =
env->GetMethodID(cls, "getOrientAttrib", "()I"); env->GetMethodID(cls, "getOrientAttrib", "()I");
AwtPrintControl::getFromPageID = AwtPrintControl::getFromPageID =
...@@ -690,12 +690,6 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env, ...@@ -690,12 +690,6 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env,
pd.Flags = PD_ENABLEPRINTHOOK | PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE; pd.Flags = PD_ENABLEPRINTHOOK | PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE;
pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDlgHook; pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDlgHook;
if (env->CallBooleanMethod(printCtrl, AwtPrintControl::getCollateID)) {
pd.Flags |= PD_COLLATE;
}
pd.nCopies = (WORD)env->CallIntMethod(printCtrl,
AwtPrintControl::getCopiesID);
pd.nFromPage = (WORD)env->CallIntMethod(printCtrl, pd.nFromPage = (WORD)env->CallIntMethod(printCtrl,
AwtPrintControl::getFromPageID); AwtPrintControl::getFromPageID);
pd.nToPage = (WORD)env->CallIntMethod(printCtrl, pd.nToPage = (WORD)env->CallIntMethod(printCtrl,
...@@ -729,37 +723,52 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env, ...@@ -729,37 +723,52 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env,
DEVMODE *devmode = (DEVMODE *)::GlobalLock(pd.hDevMode); DEVMODE *devmode = (DEVMODE *)::GlobalLock(pd.hDevMode);
DASSERT(!IsBadWritePtr(devmode, sizeof(DEVMODE))); DASSERT(!IsBadWritePtr(devmode, sizeof(DEVMODE)));
devmode->dmFields |= DM_COPIES | DM_COLLATE | DM_ORIENTATION | WORD copies = (WORD)env->CallIntMethod(printCtrl,
DM_PAPERSIZE | DM_PRINTQUALITY | DM_COLOR | DM_DUPLEX; AwtPrintControl::getCopiesID);
if (copies > 0) {
devmode->dmCopies = pd.nCopies; devmode->dmFields |= DM_COPIES;
devmode->dmCopies = copies;
}
jint orient = env->CallIntMethod(printCtrl, jint orient = env->CallIntMethod(printCtrl,
AwtPrintControl::getOrientID); AwtPrintControl::getOrientID);
if (orient == 0) { if (orient == 0) { // PageFormat.LANDSCAPE == 0
devmode->dmFields |= DM_ORIENTATION;
devmode->dmOrientation = DMORIENT_LANDSCAPE; devmode->dmOrientation = DMORIENT_LANDSCAPE;
} else if (orient == 1) { } else if (orient == 1) { // PageFormat.PORTRAIT == 1
devmode->dmFields |= DM_ORIENTATION;
devmode->dmOrientation = DMORIENT_PORTRAIT; devmode->dmOrientation = DMORIENT_PORTRAIT;
} }
devmode->dmCollate = (pd.Flags & PD_COLLATE) ? DMCOLLATE_TRUE // -1 means unset, so we'll accept the printer default.
: DMCOLLATE_FALSE; int collate = env->CallIntMethod(printCtrl,
AwtPrintControl::getCollateID);
if (collate == 1) {
devmode->dmFields |= DM_COLLATE;
devmode->dmCollate = DMCOLLATE_TRUE;
} else if (collate == 0) {
devmode->dmFields |= DM_COLLATE;
devmode->dmCollate = DMCOLLATE_FALSE;
}
int quality = env->CallIntMethod(printCtrl, int quality = env->CallIntMethod(printCtrl,
AwtPrintControl::getQualityID); AwtPrintControl::getQualityID);
if (quality) { if (quality) {
devmode->dmFields |= DM_PRINTQUALITY;
devmode->dmPrintQuality = quality; devmode->dmPrintQuality = quality;
} }
int color = env->CallIntMethod(printCtrl, int color = env->CallIntMethod(printCtrl,
AwtPrintControl::getColorID); AwtPrintControl::getColorID);
if (color) { if (color) {
devmode->dmFields |= DM_COLOR;
devmode->dmColor = color; devmode->dmColor = color;
} }
int sides = env->CallIntMethod(printCtrl, int sides = env->CallIntMethod(printCtrl,
AwtPrintControl::getSidesID); AwtPrintControl::getSidesID);
if (sides) { if (sides) {
devmode->dmFields |= DM_DUPLEX;
devmode->dmDuplex = (int)sides; devmode->dmDuplex = (int)sides;
} }
...@@ -771,6 +780,7 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env, ...@@ -771,6 +780,7 @@ BOOL AwtPrintControl::InitPrintDialog(JNIEnv *env,
double newWid = 0.0, newHt = 0.0; double newWid = 0.0, newHt = 0.0;
if (wid_ht != NULL && wid_ht[0] != 0 && wid_ht[1] != 0) { if (wid_ht != NULL && wid_ht[0] != 0 && wid_ht[1] != 0) {
devmode->dmFields |= DM_PAPERSIZE;
devmode->dmPaperSize = AwtPrintControl::getNearestMatchingPaper( devmode->dmPaperSize = AwtPrintControl::getNearestMatchingPaper(
printName, printName,
portName, portName,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册