|
I started working a much more detailed description of how to play with the curve but realized that isn't what you were confused about.
Gamma-correcting an image is essentially raising its color intensities to 1/gamma, so that when the monitor in turn raises the value to gamma, these cancel out.
You said ... I'm trying to work the problem backwards from the GetDeviceGammaRamp function call to whatever input values would be required to create the current gamma ramp array. You need to explain why you want to reverse it .. you aren't a hardware device. Your code is designed for something like a game where it simply loads a slight adjustment to the colors at start up where it will set the gamma ramp table on the DC. You sound more like you are trying to do something like an ICC profile.
Your code is a basic exponential function it wouldn't really match a real monitor gamma output distortion which would need something like a spline. That would all be done in a processing phase not down on the output out to a device context. So I think you need to explain more what you are trying to do.
Perhaps read the Microsoft overview of gamma control on windows and expand it from there.
Using gamma correction (Windows)[^]
The current gamma correction occurs on 1 line of code in your example above
value = (Math.Pow(value / 65535, 1 / gamma) * 65535) + 0.5;
The initial gamma is divided by 10 so if you enter 10 you get Math.Pow(value / 65535, 1) that is it's linear
and the value is basically value/65535*65535 .. AKA the same value.
Value is defined as
double value = i * 256;
So all that whole function does is return a value in 256 step increments.
With gamma set to 10 you are going to get 0,255,511, ... 65535
The reverse table can be built using the line
value = (Math.Pow(value / 65535, gamma) * 65535) + 0.5;
Straight mathematics anything raised to a power is inverted by raising to 1/power so replace 1/gamma with gamma, I made bold and underlined so the substitution is more obvious.
Still confused what you are trying to do, but hopefully something there helps.
In vino veritas
modified 5-Sep-16 6:26am.
|
|
|
|
|
Hi Leon,
I took a good look at the code and the web site that you suggested, and I find it interesting. That said, I don't think it applies to my application. If I'm not mistaken, your suggested code would be something that you might use for adjusting the gamma of a photo.
The algorithm that I have put forward is actually easy to control with either four slider controls, or four updown/edit controls that will affect the graphics card for your display monitor. One control for each of the following Brightness, Contrast, Level, and Brightness.
Allow me to explain the goals that I need to achieve here in my application:
I am working on a Navigation Display where there are strict specifications for color and brightness calibration in three viewing modes: Daytime, Twilight, and Night. In this application I also make calls to GetSysColors and SetSysColors to change the over all appearance of the Windows display for Day, Twilight, and Night. The specifications also call for three specific cursors that each have to meet strict size and color requirements for each display mode. There are numerous color checks involved, as well as a grey scale display check that must appear ever time the user switches to the night time display settings (and on demand).
These specifications are laid out in the the International Hydrographic Organizations (IHO) Presentation Library for ECDIS which uses the S-57 Electronic Navigation Chart (ENC) display.
For the twilight and night time display modes it is critical that mariner's night vision be preserved, and that optimum view-ability be achieved under bright sunlight conditions.
The grey scale check that is required consist of a black box with a slightly lighter shaded box inside for which the user must be able to calibrate his display so that the lighter shaded box can be easily differentiated from the black box background. The algorithm above serves these calibration purposes.
I have used this algorithm for a number of years to adjust my own display for less eye strain when I'm spending hours at a time writing code - sometimes in a night time environment (on the ship's bridge). Because of the my inability to derive the Brightness Contrast, Level, and Gamma settings directly from the Gamma Ramp array, I have not employed this method in any of my software releases.
Thus far the best I have been able to do is iterate through all possible settings until the output matches the Graphics Card's Gamma Ramp array received through the GetDeviceGammaRamp call. This works but it takes about 49,000,000 iterations and runs for 15-20 minutes. I have applied some variations to this which has shortened the run time; but it still takes about 5 minutes to run it. I need to be able to derive these settings in about a one second. I haven't given up yet though
I hope this helps to better explain my goals.
Again, thank you for your interest and your suggestions; it is much appreciated!
Best regards.
|
|
|
|
|
But what you are doing seems to be re-inventing the wheel at least on Windows 7, 8 and 10 or I am completely missing something.
If you go to color management in control panel on Windows and tick the box on the display that says use color management (it defaults off) it will use the ICC profile for the monitor. That profile will exist so long as it has detected the monitor type and isn't using the generic. You will see the ICC profile in the box labelled Profiles associated to this device.
For most Joe Average they would only go looking for this setting if they are running dual monitors and want the two displays to have the exact some color output to the eye. It's really annoying when you have two monitors side by side on a dual monitor system with different shades. The whole point of the ICC is so that the computer color space looks exactly the same when displayed on different monitors.
So can I first ask is the color management turned on in your situation? If it is on then why don't you directly read the ICC profile which seems to be the exact thing you are trying to map from the the deviceramptable?
At least then you are down to each user will see every monitor the same, and now you need to adjust simply for each users eye which would carry from monitor to monitor if they are all running ICC or is there something I am missing?
In vino veritas
modified 5-Sep-16 12:31pm.
|
|
|
|
|
Hi Leon,
I actually haven't examined the Windows Color Management; and perhaps I should look into this.
However, I would still have to meet the specifications laid down by the IHO.
These specifications are fairly strict. When the ECDIS is set up it has to be inspected and tested with an instrument that reads the color values directly from the display screen; and they must meet specifications or else adjustments must be made to the [X,Y,L] color tables (and/or the hardware). I have had to build these testing scenarios and conversion functions into the software. Additional routines for the mariner to do self testing at sea are also a requirement (color comparison charts and the grey scale test that I mentioned previously).
To say the least, meeting these specifications has been fairly demanding. There are several thousand pages in total; and the display requirements come up again and again through out.
Getting these Brightness, Contrast, Level, and Gamma settings from the gamma ramp array has just been a minor setback in the grand scheme of things, but sooner or later I'll figure it out. I may be close to being able to extract the current gamma setting - working on it...
Cheers
|
|
|
|
|
You went and made me look it up just out of curiosity
The definitive details is given in the specification
https://www.iho.int/iho_pubs/standard/S-52/S-52_e6.0_EN.pdf[^]
-Software to generate the required colours for use during the calibration. This will
be a program that allows the user to adjust the colour DAC values from 0 to 255
in each of Red, Green and Blue.
- Software to calculate the transformation between RGB and CIE x, y, L values.
(This software is part of the Presentation Library.)
Your physical testing is for compliance to the standard CIE absolute color space.
Any windows OS from 7 up with color management turned on, with a compliant monitor should meet that specification and you just need to do the user controls they ask for in the specification. If it doesn't either the monitor manufacturer or Microsoft has some answering to do.
In vino veritas
|
|
|
|
|
Thanks for that insight. I sort of suspected that most modern monitors and operating systems would be compliant. It is going to be the end user's responsibility to have their system certified, and then do the regular checks that are required.
There is the software for conversion of the xyl values, and there is also software for the performing the color test on a CRT monitor. At the time I purchased my current version of the Presentation Library (2008) they had not yet developed tests for a LCD display. The latest version of the Presentation Library is in transit to me now, and I'm curious to see what changes have been made to the specifications since my 2008 version; and whether they will now have some sort of testing procedure for the LCD monitor. In 2008 it was still under consideration.
The way I see it, I just have to meet the specs; but even that going to be daunting. I don't expect to have this ECDIS system ready for another two years. I have had a navigation program out since 2003 - but it is not ECDIS. There are no electronic navigation charts in my existing system; but it does have background maps (world wide coverage). My latest (as yet unreleased) version is also NMEA 2000 compatible and features extensive networking capabilities. The system also has it's own "line tracking" autopilot built into it; which is great for oceanographic survey work - I hate driving lines day in and day out - it's mind numbing.
I have only recently decided that it was time to take my nav program to the next level; and make it ECDIS compliant.
Again, thanks for checking that out
Cheers!
|
|
|
|
|
Hi Leon,
I have finally found a solution for my problem; and have edited my original post to reflect this. It's not a mathematical solution, but it works well enough.
I just thought I'd give you a heads up since you took an interest
Thanks again for your input!
Keith
|
|
|
|
|
 Quote: After unsuccessfully trying to solve for a mathematical solution for a week I had to try some other way to derive the Gamma Ramp Settings directly from the GetDeviceGammaRamp call.
One early attempt involved a simple iteration of all possible settings. This gave correct results, but it took more than 20 minutes to complete the operation. My application needs to be able to do this in under a second.
I finally found a better, more efficient way to perform the iterations, and it meets my requirements. It may be an imperfect solution; but a win is a win.
I shaved a little more time off of this operation by testing for a positive or a negative curve in the Gamma setting (or no curve at all = neutral setting 10). This saves a few iterations going in. To do this I created two additional functions: PtToPtRngBrg and GetPtFromPt.
If you like, you can skip these; and simply iterate through all possible Gamma settings (2 to 50). This would greatly simplify the code.
Here is my C++ solution...
#define DEG_RAD 0.017453292519943295769236907684886
struct RngBrg{
double rng;
double brg;
};
void __fastcall TForm1::GetGammaRampSettings(void){
double i,j,k,m,m4;
double s1,s2,s3,s4;
double gamma,bright,cntrst,level;
double value;
int d;
int x1,x2,x3,x4;
bool isFound=false;
RngBrg rb;
WORD GammaArray[3][256];
WORD CompArray[256];
double DArray[256];
HDC GammaDC = GetDC( NULL );
GetDeviceGammaRamp( GammaDC, GammaArray );
ReleaseDC( NULL, GammaDC );
for( x1 = 0; x1 < 256; x1++ ){
if( GammaArray[0][x1] > 0){break;}
}
for( x2 = 0; x2 < 256; x2++ ){
if( GammaArray[0][x2] == 65535){isFound=true; break;}
}
if( !isFound ){ x2--; }
s1 = ( (double) GammaArray[0][x1] + 1 ) / 256.0;
s2 = ( (double) GammaArray[0][x2] + 1 ) / 256.0;
x3 = x1 + ( ( x2 - x1 ) / 2 );
s3 = ( (double) GammaArray[0][x3] + 1 ) / 256.0;
Memo1->Lines->Add( "x1 = " + IntToStr(x1) + " s1 = " + AnsiString(s1));
Memo1->Lines->Add( "x2 = " + IntToStr(x2) + " s2 = " + AnsiString(s2));
Memo1->Lines->Add( "x3 = " + IntToStr(x3) + " s3 = " + AnsiString(s3));
PtToPtRngBrg( &rb, x1, s1, x2, s2 );
Memo1->Lines->Add( "rng = " + AnsiString( rb.rng ) +
" brg = " + AnsiString( rb.brg ));
GetPtFromPt(x1, s1, rb.rng / 2.0, rb.brg, &m4, &s4);
Memo1->Lines->Add("m4 = " + IntToStr( Round(m4) ) + " s4=" + AnsiString(s4));
Memo1->Lines->Add("s3 - s4 = " + AnsiString( s3-s4 ));
x4 = Round(m4);
if(( s4 - s3 ) > 1 ){
Memo1->Lines->Add("Negative Gamma Curve");
for( i = 9; i > 1; i-- ){
gamma=i/10;
for( d = 0; d < 256; d++ ){
DArray[d] = ( pow( (double)(d * 256) / 65535, 1 / gamma) * 65535) + 0.5;
}
for( j = 2; j < 101 ; j++ ){
level = 1 + ((j - 50) / 100);
for( k = 0; k < 101; k++ ){
bright = 1 + (((k - 50) / 100) * 65535);
for( m = 0; m < 101; m++ ){
cntrst = 1 + ((m - 50) / 100);
value = (((( DArray[x4] / 65535 ) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535){ value = 65535; }
if( value < 0 ){ value = 0; }
if( (WORD) value == GammaArray[0][x4] ){
for( d = 0; d < 256; d++ ){
value = ((( (DArray[d] / 65535) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535 ){ value = 65535;}
if( value < 0 ){ value = 0;}
CompArray[d] = (WORD) value;
}
if(memcmp( &CompArray[0], &GammaArray[0][0], 2*256) == 0){
goto ENDIT;
}
}
}
}
}
}
}else if((s3-s4)>1){
Memo1->Lines->Add("Positive Gamma Curve");
for( i = 11; i < 51; i++ ){
gamma=i/10;
for( d = 0; d < 256; d++ ){
DArray[d] = ( pow( (double)(d * 256) / 65535, 1 / gamma) * 65535) + 0.5;
}
for( j = 2; j < 101 ; j++ ){
level = 1 + ((j - 50) / 100);
for( k = 0; k < 101; k++ ){
bright = 1 + (((k - 50) / 100) * 65535);
for( m = 0; m < 101; m++ ){
cntrst = 1 + ((m - 50) / 100);
value = (((( DArray[x4] / 65535 ) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535){ value = 65535; }
if( value < 0 ){ value = 0; }
if( (WORD) value == GammaArray[0][x4] ){
for( d = 0; d < 256; d++ ){
value = ((( (DArray[d] / 65535) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535 ){ value = 65535;}
if( value < 0 ){ value = 0;}
CompArray[d] = (WORD) value;
}
if(memcmp( &CompArray[0], &GammaArray[0][0], 2*256) == 0){
goto ENDIT;
}
}
}
}
}
}
}else{
Memo1->Lines->Add("No Gamma Curve");
i=10;
gamma=1;
for( d = 0; d < 256; d++ ){
DArray[d] = ( pow( (double)(d * 256) / 65535, 1 / gamma) * 65535) + 0.5;
}
for( j = 2; j < 101 ; j++ ){
level = 1 + ((j - 50) / 100);
for( k = 0; k < 101; k++ ){
bright = 1 + (((k - 50) / 100) * 65535);
for( m = 0; m < 101; m++ ){
cntrst = 1 + ((m - 50) / 100);
value = (((( DArray[x4] / 65535 ) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535){ value = 65535; }
if( value < 0 ){ value = 0; }
if( (WORD) value == GammaArray[0][x4] ){
for( d = 0; d < 256; d++ ){
value = ((( (DArray[d] / 65535) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535 ){ value = 65535;}
if( value < 0 ){ value = 0;}
CompArray[d] = (WORD)value;
}
if(memcmp( &CompArray[0], &GammaArray[0][0], 2*256) == 0){
goto ENDIT;
}
}
}
}
}
}
Memo1->Lines->Add("Values NOT Discovered - Checking All Values...");
for(i=2;i<51;i++){
gamma=i/10;
for( d = 0; d < 256; d++ ){
DArray[d] = ( pow( (double)(d * 256) / 65535, 1 / gamma) * 65535) + 0.5;
}
for( j = 2; j < 101 ; j++ ){
level = 1 + ((j - 50) / 100);
for( k = 0; k < 101; k++ ){
bright = 1 + (((k - 50) / 100) * 65535);
for( m = 0; m < 101; m++ ){
cntrst = 1 + ((m - 50) / 100);
value = (((( DArray[x4] / 65535 ) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535){ value = 65535; }
if( value < 0 ){ value = 0; }
if( (WORD) value == GammaArray[0][x4] ){
for( d = 0; d < 256; d++ ){
value = ((( (DArray[d] / 65535) - 0.5) * cntrst) + 0.5) * 65535;
value = value += bright;
value *= level;
if( value > 65535 ){ value = 65535;}
if( value < 0 ){ value = 0;}
CompArray[d] = (WORD) value;
}
if(memcmp( &CompArray[0], &GammaArray[0][0], 2*256) == 0){
goto ENDIT;
}
}
}
}
}
}
Memo1->Lines->Add("Values Still NOT Discovered!!!");
Memo1->Lines->Add("Discovery Operation Failed.");
return;
ENDIT:
Memo1->Lines->Add("Bright = " + IntToStr((int)k));
Memo1->Lines->Add("Cntrst = " + IntToStr((int)m));
Memo1->Lines->Add("Level = " + IntToStr((int)j));
Memo1->Lines->Add("Gamma = " + IntToStr((int)i));
}
short __fastcall TForm1::Round(double flt){
short num=(short)flt;
if(flt>=0){
if(flt-num>=.5){num++;}
}else{
if(flt-num<=-.5){num--;}
}
return(num);
}
bool __fastcall TForm1::PtToPtRngBrg(RngBrg *rb,double x1,double y1,double x2,double y2){
rb->rng=0;rb->brg=0;
double diffx,diffy,dangle;
if(x1>=x2){
if(x1>=0&&x2<0){diffx=x1+fabs(x2);}else{diffx=x1-x2;}
}else{
if(x2>=0&&x1<0){diffx=x2+fabs(x1);}else{diffx=x2-x1;}
}
if(y1>=y2){
if(y1>=0&&y2<0){diffy=y1+fabs(y2);}else{diffy=y1-y2;}
}else{
if(y2>=0&&y1<0){diffy=y2+fabs(y1);}else{diffy=y2-y1;}
}
if(diffx==0){
rb->brg=0;rb->rng=y2-y1;
return true;
}
if(diffy==0){
rb->brg=90;rb->rng=x2-x1;
return true;
}
dangle=atan(diffy/diffx);
rb->rng=diffx/cos(dangle);
dangle=dangle/DEG_RAD;
rb->brg=90-dangle;
return true;
}
void __fastcall TForm1::GetPtFromPt(double x, double y,double rng,double brg,double *x2,double *y2){
if(brg>=360){brg-=360;}
if(brg<0){brg+=360;}
if(brg==360||brg==0){*x2=x;*y2=y+rng;return;}
if(brg==270){*y2=y;*x2=x-rng;return;}
if(brg==90){*y2=y;*x2=x+rng;return;}
if(brg==180){*x2=x;*y2=y-rng;return;}
if(brg<90){
*x2=x+(rng*cos((90-brg)*DEG_RAD));
*y2=y+(rng*sin((90-brg)*DEG_RAD));
return;
}
}
|
|
|
|
|
Hi,
I am getting around to using a printer direct. It is a Steep Learning Curve! Prior to this, I produced Text Files, which could be Printed via Notepad.
Grabbed the Bull by the Horns, Want to print Straight from the Program.
I am using MFC42. The Target Machines are Win XP-SP1. (None are Internet Enabled, The System is Outside the Internet)
The Second Hand Win 8 computer I use to write on, has a Device Driver for an HP Printer. All goes well, until I hit the Print button in the Print Dlg. Then everything crashes.
End up After the Crash with a Dlg to tell me in very many words that the printer device could not be found!
Now, I know that there is no physical printer attached to my machine, but, there should be a more graceful idea of notifying me about that fact, other than crashing.
For Instance, Can I query the CDC about a Printer being Plugged In, etc.
Kind Regards,
Bram van Kampen
|
|
|
|
|
Are you using CPrintDialog Class[^] to get the details of the printer? If you do not have a physical printer attached you can use the MS XPS writer, or if you have a PDF print application installed you can use that.
|
|
|
|
|
Well, Thanks Richard.
I worked the sample given by Chris Mauder on the MFC Forum about Printing without the Document-View Architecture. I use the CPrintDialog to obtain a pointer to a device Context, presumably in my case pointing to a HP Printer,(Apparently Installed by the Previous Owner of the Laptop) and all appears to work well. I retrieve a (pointer to) a CDC from the CPrintDialog, and the Pointer is Not NULL.
The Only thing is that there is no HP, (or, any) Printer Plugged In. (It is my Coding Laptop) My experience with say 'MS Office' is, that when the printer is not actually plugged in at the time, that the job gets spun off to the print spooler where it remains until that printer becomes available.
Is this a Feature of the Windows Print Spooler, or, a Feature of 'MS Office'?
The result in my case is a very major Foul Up, and, Minutes Later, a Message from the HP Driver that the Device cannot be found, complete with Major Advice to check Cable Connections, and a Range of Other Things.
Now, on Further Reflection, (time for quiet reflection is something that we are unlikely (and Unwisely) allow to afford ourselves when hunting for Bugs.)
It may well be that the HP Printer Driver is corrupted. My Coding Laptop is not on the Internet for obvious reasons.(Installation of the "Ms Dev Studio97" on a Win7 Computer gives an Immediate alarm under 'IsGenuine' for the OS)
I'll try to install another printer driver, (from a CD), and see how it goes.
I am ashamed to say that I have avoided Printing for the last 25 years, actually, since my Dos Days.
I have decided to bite the bullet on this Application.
I Dealt with printing in the past by sending things to a Text File, and to use NotePad, when a Printout was needed.
Also, seeing that I only need to print only a few pages, mostly One A4, sometimes 2 or 3, I did not go to the complication of doing this in a Worker Thread. I want to learn how to Crawl, before trying to learn how to Run.
Would this have an Impact. Chris Mauder's example did not mention threads.
The thing is, when things go wrong, and, especially in a for me a New and crucial Field, is: Am 'I' doing something Wrong, or Misunderstanding Something.
Once Again, thanks for your response, Richard.
I'll keep you posted on how I get on.
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: Is this a Feature of the Windows Print Spooler, or, a Feature of 'MS Office'? That's the spooler, which will try to send the file to the print driver. The driver may then pop up a dialog to say the printer is offline. In all my experience the file will remain in the spooler until it gets printed, or the user cancels it. What you call a major Foul Up sounds like normal behaviour. As I said before, you should have the Windows XPS print driver (creates an XPS file) installed so you can test with that.
|
|
|
|
|
He is using XP SP1. That does not has the XPS driver and installing it requires probably a higher SP version.
But using a PDF driver as already suggested by you should do the trick.
|
|
|
|
|
But using Win 8 for development.
|
|
|
|
|
You are right. I missed that.
|
|
|
|
|
That's OK, I missed the XP bit. 
|
|
|
|
|
|
Bram van Kampen wrote: The XPS File I got was,in Binary. As you would expect, since it also includes formatting information about the content. I have used this to test printing in my applications, and never had a problem. I guess you need to look at your actual printing code.
|
|
|
|
|
Well,
The Binary I get refuses to open.
Here is my Printing Code:-
void CConfirmOrdersStep1Dlg::OnPrint()
{
if(CreateViewForPrinting()==false){
AfxMessageBox("No Orders have been Marked for Printing");
return;
}
CDC dc;
CPrintDialog printDlg(FALSE);
<pre>
if (printDlg.DoModal() == IDCANCEL) return;
dc.Attach(printDlg.GetPrinterDC()); dc.m_bPrinting = TRUE;
CString strTitle="Old Orders";
// strTitle.Format("Date:Confirming Old Orders By:- %s-%s", UserName,Date);
DOCINFO di;
memset(&di, 0,sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;
BOOL bPrintingOK = dc.StartDoc(&di);
CPrintInfo Info;
Info.m_rectDraw.SetRect(0,0,
dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES));
OnBeginPrinting(&dc, &Info);
UINT page;
for (page=Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK;page++){
dc.StartPage();
Info.m_nCurPage = page;
PrintPage(&dc, &Info);
bPrintingOK = (dc.EndPage() > 0);
}
OnEndPrinting(&dc, &Info);
if (bPrintingOK)
dc.EndDoc();
else
dc.AbortDoc();
dc.DeleteDC();
}
// As from Chris Mauder.
// Instead of Global I made it a member
//
// m_pView (Type COrderPageView) contains a list of PageFragments
// The Fragment at index 0 is the header, to be printed at the Top
// of each Page (Customer Details, etc)
// CondensePages() does Nothing for Now.
//
// Anyways, This Works, as I can successfully print the Page to a Text
// File.
void CConfirmOrdersStep1Dlg::OnBeginPrinting(CDC * pDC, CPrintInfo * pInfo)
{
// Set the Font to "CourierNew"
CFont PrinterFont;
if(!PrinterFont.CreatePointFont(
100,
"Courier New",
pDC)){
ASSERT(NULL);
return;
}
CSize Size=pDC->GetTextExtent("AAAA",4);
m_nCurrentPrintRectWidth=Size.cx*10;
m_nCurrentLineHeight=Size.cy;
int PageHeight=pInfo->m_rectDraw.Height();
m_nLinesPerPage=PageHeight/m_nCurrentLineHeight;
m_pView->CondensePages(m_nLinesPerPage);
}
/////////////////////////////////////////////////////////////////
//
// This is where we print, First the Header, and thereafter the Page Content
void CConfirmOrdersStep1Dlg::PrintPage(CDC * pDC, CPrintInfo * pInfo)
{
int PageNumber=pInfo->m_nCurPage;
m_nCurrentPrintRectTop=0;
COrderPageView* pView=(COrderPageView*)m_pView->GetDataFromIndex(0);
PrintDocFragment(pView,pDC);
COrderPageView* pOrder=(COrderPageView*)m_pView->GetDataFromIndex(PageNumber);
PrintDocFragment(pOrder,pDC);
}
void CConfirmOrdersStep1Dlg::OnEndPrinting(CDC * pDC, CPrintInfo * pInfo)
{
}
// We Create a List of Set of lists of 40 char wide strings
// The First Item in this List is the Header, specifying the
// Customer Details
// The remaining items contain Order Details for the Same Customer
// This Part Works, As is shown by 'DumpToTextFile()'
bool CConfirmOrdersStep1Dlg::CreateViewForPrinting()
{
delete m_pView;
m_pView=new COrderPageList();
int i;
int ItemCount=0;
for(i=0;i<m_clist.getcount();i++){
if(m_clist.getcheck(i)="=1)ItemCount++;
" }
="" if(itemcount="=0)return" false;
="" tag_str_customer*="" pcust="m_pNode-">pCustomer;
COrderPageView* pPageHeader=new COrderPageView(NULL,40);
pPageHeader->m_pCustomer=m_pNode->pCustomer;
pPageHeader->PrintPageHeader();
m_pView->AddReference(pPageHeader);
for(i=0;i<m_clist.getcount();i++){
if(m_clist.getcheck(i)!="1)continue;
" int="" index="((int)m_cList.GetItemData(i))-BIAS;
" lpstr_order="" po="(LPSTR_ORDER)m_pOrderList-">GetDataFromIndex(Index);
COrderPageView* pPageView=new COrderPageView(pO,40);
pPageView->PrintOrderBody();
m_pView->AddReference(pPageView);
}
ifdef _DEBUG
m_pView->DumpToTextFile();
endif
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// THIS IS WHERE THE RUBBER MEETS THE ROAD!
//
// We Are Committing a Set of Lines of Text in an Incrementing
// List of adjusting Rectangles.
int CConfirmOrdersStep1Dlg::PrintDocFragment(COrderPageView * pView, CDC * pDC)
{
ASSERT(pView);
ASSERT(pDC);
int i;
for(i=0;i<pview->GetItemCount();i++){
RECT DrawingRect;
DrawingRect.left=0;
DrawingRect.top=m_nCurrentPrintRectTop;
m_nCurrentPrintRectTop+=m_nCurrentLineHeight;
DrawingRect.right=m_nCurrentPrintRectWidth;
DrawingRect.bottom=m_nCurrentPrintRectTop-1;
LPCSTR DrawingText=(LPCSTR)pView->GetDataFromIndex(i);
pDC->DrawText(DrawingText,-1,&DrawingRect,DT_LEFT);
}
return i;
}
Getting Desparate at this stage. I Guess I am doing something trivial wrong.
Thanks + Regards,
Bram van Kampen
|
|
|
|
|
Well I just Notice, I forgot to Select the Font into the Printer Device Context.
That would of course have an impact!
Can anyone spot other errors?
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: The Binary I get refuses to open. Not sure what that means, or what is missing. If you do not select the font into the DC then it will just use a default, so you should still see some output. Given that this is Chris's original code, you may want to try talking to him.
|
|
|
|
|
Wel,
I get a Binary File not recognised by the XPS Reader.
I can open it as Binary in a HexVieuwer, and get nothing recognisable.
Bram van Kampen
|
|
|
|
|
When I look at an XPS print file it looks something like:
PK µC'I Metadata/Job_PT.xmlíW]s¢H}ߪý)Þ' &Ùh%NÝ4ZÁØ }Cè`|
´¢óë÷¶ã̬‰™™§éòš{Îážþ¸póqGgK–<Mn•ʹ¦œ±ÄOž„·Š3l¸V>6ÿþë&+žƒœ'bÈý9gKŠöÞ*3!²†ªþŒÅ^qs?O‹ôIœûi¬–< Ò²P«šVSµk5"H¾=Øbžr/fešÏ•íªà{Ú²,ÏËÚyš‡’£¢>š÷öõ'…🽠‚·QÊA²ÏÀ¤Ð°žÈ•ŠŸÿJdÎÖ˜FP¨{è*
which is fine, and the XPS reader opens it OK.
As to why you cannot read yours is a total mystery. If you are using all the standard APIs (or their MFC equivalents) to create your print files, then they should at least be readable.
Try changing the extension from .xps to .zip and have a look at the content then.
|
|
|
|
|
Hi, Richard,
Well, if it opens in your machine , there is evidently something wrong with my reader, and nothing wrong with the code I wrote to generate same.
I'm away on a break for a few days. I had my 62nd Birthday 3 weeks ago, but, were unable to escape. We are trying enjoy life in semi retirement, with a small important money spinning business running in the background, powered by my software.
I appreciate your comment, and will try changing the XPS ext to ZIP when I'm back.
I Think that you know that I write software for Laundrettes and Dry-Cleaners, specifically for our own chain.
There are No Trade or Other secrets buried in the Text Example I Sent. It is a Fictitious Customer with a Fictitious ancient Order. (The Bane of a laundrette is people not coming back to pay and collect, It Clogs up the shop, the work is done, but, the Till does not ring. )
The Program I am writing now, is a concerted attempt to attack this, by contacting customers. The First step there is, to ensure that ancient Orders that appear on the database, are still present in the shop. Whereas we Trust our staff, an order could have been given out, without the order being rang in, the staff pocketing the sale, and the Item remaining on the Database. At any rate, we do not want to contact customers over long forgotten items, when we no longer poses them, for whatever reason.
It also gives staff an other activity at quiet Times. Instead of drinking cups of tea, they have a Screen of alternative, and More Productive activity. Making Phone Calls, and finding People's goods. If people's goods can not be found, then there is no point in ringing the customer. Let sleeping dogs lie, and Management writes the item off. We tried it manually, and got things like "Oh I forgot about that, I will collect it next Saturday" Saturday came and went, we all forgot, order still here. This new program will pursue only say 10 old orders at the time, but these orders will be pursued vigorously.
Items Promised to be Collected By a date, will disappear of the ToDo List, but, will re-appear there after that date, if at that stage not collected and paid.
The Interface is being designed so that Junior Staff can handle it, kicking major decisions back upstairs. The Document I tried to print was a form, for staff to go around the shop, and find the goods. The First Step.
When you Opened the XPS File, could you read the Text as Follows:-
Finding Old Orders in the Shop
Printed by <????> on 01 09 16 - 23:40:14
Customer:-
TONY LOUGHLIN
If The Item(s) are Found you should
Update the Computer Record, and
Destroy this Page!
Otherwise Inform Management of the
Discrepancies, by Returning this Page
Marked Up Accordingly!
Order Nr 214058
Received on: 27/07/12 - 13:18:21
Not Confirmed Present since Completion
Qty Description Amount
1 lb Wash +Dry £11.00
========
Total For Order £11.00
Due for This Order £11.00
Packaging:- -1Wb
========================================
<pre>
Actually Found:-
Hangers Pastics Flatpacks WashBags
+-+ +-+ +-+ +-+
| | | | | | | |
| | | | | | | |
| | | | | | | |
+-+ +-+ +-+ +-+
========================================
Please let me know If you Did.
It means in that case: "Programming Problem Solved"
Thanks and Regards,
Bram van Kampen
|
|
|
|
|
Hi Bram, well I'm a few years older than you, so in theory I should have more knowledge locked in my brain. But you know what they say about theory and practice.
When I said I could open the XPS file, I meant one that I generated here. If you can send me the one you generate I could have a look at it for you. Send me a private email and I can give you an address, or put it up on one of the public staging sites.
|
|
|
|
|