|
|
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Print unwanted copy
|
|
|
Re: Print unwanted copy [message #44073 is a reply to message #44069] |
Mon, 22 December 2014 16:29 |
|
Klugier
Messages: 1076 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Forlano,
For me this code look strange (PrinterJob - Windows code - line 102):
for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1); c++)
for(int i = dlg.nFromPage - 1; i <= dlg.nToPage - 1; i++)
for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies); c++)
page.Add(i);
Double "c" definitions in loop is definitely not good idea.
And why for the one condition there is different result:
(dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1)
(dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies)
Sincerely,
Klugier
U++ - one framework to rule them all.
[Updated on: Mon, 22 December 2014 16:29] Report message to a moderator
|
|
|
|
Re: Print unwanted copy [message #44104 is a reply to message #44073] |
Thu, 25 December 2014 11:09 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
Klugier wrote on Mon, 22 December 2014 16:29Hello Forlano,
For me this code look strange (PrinterJob - Windows code - line 102):
for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1); c++)
for(int i = dlg.nFromPage - 1; i <= dlg.nToPage - 1; i++)
for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies); c++)
page.Add(i);
Double "c" definitions in loop is definitely not good idea.
And why for the one condition there is different result:
(dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1)
(dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies)
Sincerely,
Klugier
Ah, that actually is OK: Collate means that copies are kept "together", I mean, if collate is active and you are printing 3 pages 2 copies, you are supposed to get 1 1 2 2 3 3, while with collate 'off', you get 1 2 3 1 2 3. Which IMO is excactly what the loop does.
Anyway, that doubling of copies is (for me) long existing bug, it has rather something to do with some misunderstanding of printer driver and windows print dialog. It affects only some printers and some drivers. Which reminds me that I have not tried with my current win8.1 and current printer, time to investigate this bug again...
|
|
|
Re: Print unwanted copy [message #44107 is a reply to message #44104] |
Thu, 25 December 2014 14:06 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
mirek wrote on Thu, 25 December 2014 11:09
Ah, that actually is OK: Collate means that copies are kept "together", I mean, if collate is active and you are printing 3 pages 2 copies, you are supposed to get 1 1 2 2 3 3, while with collate 'off', you get 1 2 3 1 2 3. Which IMO is excactly what the loop does.
Anyway, that doubling of copies is (for me) long existing bug, it has rather something to do with some misunderstanding of printer driver and windows print dialog. It affects only some printers and some drivers. Which reminds me that I have not tried with my current win8.1 and current printer, time to investigate this bug again...
Hello,
I have commented the first loop and now prints the correct number of copies.
I do not know if this backfire.
Luigi
|
|
|
|
Re: Print unwanted copy [message #44117 is a reply to message #44116] |
Thu, 25 December 2014 20:56 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
Well, it looks like this really is Microsoft bug, see "known issue" for PD_USEDEVMODECOPIESANDCOLLATE
http://msdn.microsoft.com/en-us/library/windows/desktop/ms64 6843%28v=vs.85%29.aspx
In any case, I have now tried the workaround proposed by KB, which basically says "always depend to OS/Driver to do copies".
Please try this:
bool PrinterJob::Execute0(bool dodlg)
{
pdlg = new Win32PrintDlg_;
PRINTDLG& dlg = *pdlg;
dlg.Flags = PD_DISABLEPRINTTOFILE|PD_NOSELECTION|PD_HIDEPRINTTOFILE|PD_RETURNDEFAULT;
dlg.nFromPage = current;
dlg.nToPage = current;
dlg.nMinPage = from;
dlg.nMaxPage = to;
if(from != to)
dlg.Flags |= PD_ALLPAGES;
dlg.hwndOwner = 0;
dlg.Flags |= PD_RETURNDEFAULT;
dlg.nCopies = 1;
if(!PrintDlg(&dlg)) return false;
if(dlg.hDevMode) {
DEVMODE *pDevMode = (DEVMODE*)::GlobalLock(dlg.hDevMode);
pDevMode->dmOrientation = landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
::GlobalUnlock(dlg.hDevMode);
}
HDC hdc;
if(dodlg) {
dlg.Flags = PD_DISABLEPRINTTOFILE|PD_NOSELECTION|PD_HIDEPRINTTOFILE|PD_RETURNDC|PD_USEDEVMODECOPIESANDCOLLATE;
Vector< Ptr<Ctrl> > disabled = DisableCtrls(Ctrl::GetTopCtrls());
bool b = PrintDlg(&dlg);
EnableCtrls(disabled);
if(!b) return false;
hdc = dlg.hDC;
}
else {
DEVNAMES *p = (DEVNAMES *)::GlobalLock(dlg.hDevNames);
const char *driver = (const char *)p + p->wDriverOffset;
const char *device = (const char *)p + p->wDeviceOffset;
if(dlg.hDevMode) {
DEVMODE *pDevMode = (DEVMODE*)::GlobalLock(dlg.hDevMode);
hdc = CreateDC(driver, device, NULL, pDevMode);
::GlobalUnlock(dlg.hDevMode);
}
else
hdc = CreateDC(driver, device, NULL, NULL);
}
if(dlg.hDevMode)
::GlobalFree(dlg.hDevMode);
if(dlg.hDevNames)
::GlobalFree(dlg.hDevNames);
if(hdc) {
draw = new PrintDraw(hdc, Nvl(name, Ctrl::GetAppName()));
page.Clear();
if(!(dlg.Flags & PD_PAGENUMS)) {
dlg.nFromPage = dlg.nMinPage;
dlg.nToPage = dlg.nMaxPage;
}
// for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1); c++)
for(int i = dlg.nFromPage - 1; i <= dlg.nToPage - 1; i++)
// for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies); c++)
page.Add(i);
return true;
}
return false;
}
(also in trunk, for now).
Mirek
|
|
|
|
Goto Forum:
Current Time: Thu May 16 20:13:59 CEST 2024
Total time taken to generate the page: 0.02633 seconds
|
|
|