Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Print unwanted copy
Print unwanted copy [message #44064] Sun, 21 December 2014 14:15 Go to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

when I select to print 2 or 3 copy of a document then the printer produces 4 and 9 copies. I have not tried with other numbers to test if there is some quadratic relation between number of copy and that really printed.
Do you have the same problem? (U++ 7862)

Thanks,
Luigi
Re: Print unwanted copy [message #44066 is a reply to message #44064] Sun, 21 December 2014 22:54 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Forlano,

Can you write more about your operating system specification? It is X11/GTK/POSIX printing dialog?

If you want to analyze source code you can find it in CtrlLib/PrinterJob.cpp.

Sincerely,
Klugier


U++ - one framework to rule them all.
Re: Print unwanted copy [message #44069 is a reply to message #44066] Mon, 22 December 2014 08:46 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Klugier wrote on Sun, 21 December 2014 22:54
Hello Forlano,

Can you write more about your operating system specification? It is X11/GTK/POSIX printing dialog?

If you want to analyze source code you can find it in CtrlLib/PrinterJob.cpp.

Sincerely,
Klugier


Hello Klugier,

the problem appears under Windows (any version).
I'll have a look to PrinterJob.cpp.

Thanks,
Luigi
Re: Print unwanted copy [message #44073 is a reply to message #44069] Mon, 22 December 2014 16:29 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
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 #44075 is a reply to message #44073] Mon, 22 December 2014 18:30 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Klugier wrote on Mon, 22 December 2014 16:29
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


Hello Klugier,

it looks like there is a double loop... the quadratic relation I was speaking about.
I do not know which to remove.
Mirek should know what to do Rolling Eyes

Thanks,
Luigi
Re: Print unwanted copy [message #44104 is a reply to message #44073] Thu, 25 December 2014 11:09 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Klugier wrote on Mon, 22 December 2014 16:29
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


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... Smile
Re: Print unwanted copy [message #44107 is a reply to message #44104] Thu, 25 December 2014 14:06 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
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... Smile


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 #44116 is a reply to message #44107] Thu, 25 December 2014 20:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I think it will work if you comment out both loops as well... the problem is I am not sure this is going to work on all OS/driver combinations...

Mirek
Re: Print unwanted copy [message #44117 is a reply to message #44116] Thu, 25 December 2014 20:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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

Re: Print unwanted copy [message #44121 is a reply to message #44117] Thu, 25 December 2014 22:01 Go to previous message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Yes, it works.

Thanks,
Luigi
Previous Topic: [Fixed] TURTLE+MT fails to link: bug or feature?
Next Topic: How to check internet availability?
Goto Forum:
  


Current Time: Thu Mar 28 12:21:15 CET 2024

Total time taken to generate the page: 0.01121 seconds