I am using VC++.net and I am printing to a networked HP882c.
I have the following code that prints a simple scaled quadrilateral to my printer but the output is mirrored horizontally!
What have I done wrong?
Code:
HDC getDefaultPrinterDC()
{
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
DOCINFO docInfo;
ZeroMemory(&docInfo, sizeof(docInfo));
docInfo.cbSize = sizeof(docInfo);
docInfo.lpszDocName = "GdiplusPrint";
// Create a PRINTDLG structure, and initialize the appropriate fields.
PRINTDLG printDlg;
ZeroMemory(&printDlg, sizeof(printDlg));
printDlg.lStructSize = sizeof(printDlg);
printDlg.Flags = PD_RETURNDC;
// Display a print dialog box.
if(!PrintDlg(&printDlg))
{
// This should be a messagebox...
printf("Failure\n");
}
else
{
// Now that PrintDlg has returned, a device context handle
// for the chosen printer is in printDlg->hDC.
StartDoc(printDlg.hDC, &docInfo);
StartPage(printDlg.hDC);
Graphics* graphics = new Graphics(printDlg.hDC);
//Pen* pen = new Pen(Color(255, 0, 0, 0));
///////////////////////////////////////
// Begin centering output on printer. //
///////////////////////////////////////
int iWidth = GetDeviceCaps(printDlg.hDC,HORZSIZE); // returns full screen in mm.
int iHeight = GetDeviceCaps(printDlg.hDC,VERTSIZE); // returns full screen in mm.
int iHorzRes = GetDeviceCaps(printDlg.hDC,HORZRES); // returns pixel width for printable area.
int iVertRes = GetDeviceCaps(printDlg.hDC,VERTRES); // returns pixel Height for printable area.
int iPixelsPerInchX = GetDeviceCaps(printDlg.hDC,LOGPIXELSX);
int iPixelsPerInchY = GetDeviceCaps(printDlg.hDC,LOGPIXELSY);
ScreenWidthInInches = (GetDeviceCaps(printDlg.hDC,HORZRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSX) );
ScreenHeightInInches = (GetDeviceCaps(printDlg.hDC,VERTRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSY) );
// ratio = pixels/full screen pixels * full screen in mm /(mm/in)
double xRatio = ( (GetDeviceCaps(printDlg.hDC,HORZRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSX) )
/ (MaxX-MinX) );
double yRatio = ( (GetDeviceCaps(printDlg.hDC,VERTRES) / GetDeviceCaps(printDlg.hDC,LOGPIXELSY) )
/ (MaxY-MinY) );
double ZoomFactor = xRatio > yRatio
? yRatio
: xRatio;
if(bDisplayCoords)
ZoomFactor *= .70;
if(bDisplayLengthsAngles) // currently this doesn't enable viewing the dims.
ZoomFactor *=.9;
ZoomFactor *=.97;
double OffsetX = ((ScreenWidthInInches-(MaxX*ZoomFactor))/2);
double OffsetY = ((ScreenHeightInInches-(MaxY*ZoomFactor))/2);
/////////////////////////////////////
// End centering output to printer. //
/////////////////////////////////////
// temp coord values for printing just to simplify.
// temp x coords.
int tempX0 = int( ( (Intersections[0].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
int tempX1 = int( ( (Intersections[1].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
int tempX2 = int( ( (Intersections[2].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
int tempX3 = int( ( (Intersections[3].x*ZoomFactor) + OffsetX ) * double (iPixelsPerInchX) ) ;
// temp y coords.
int tempY0 = int( ( (Intersections[0].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
int tempY1 = int( ( (Intersections[1].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
int tempY2 = int( ( (Intersections[2].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
int tempY3 = int( ( (Intersections[3].y*ZoomFactor) + OffsetY ) * double (iPixelsPerInchY) ) ;
// Draw crap here...
SelectObject (printDlg.hDC, GetStockObject (BLACK_PEN)) ;
MoveToEx ( printDlg.hDC, tempX0 , tempY0, NULL );
LineTo (printDlg.hDC, tempX1, tempY1) ;
LineTo (printDlg.hDC, tempX2, tempY2) ;
LineTo (printDlg.hDC, tempX3, tempY3) ;
LineTo (printDlg.hDC, tempX0, tempY0) ;
// ...miscellaneous text output omitted for brevity...
// Delete gdi stuff here.
//delete pen;
delete graphics;
EndPage(printDlg.hDC);
EndDoc(printDlg.hDC);
}
if(printDlg.hDevMode)
GlobalFree(printDlg.hDevMode);
if(printDlg.hDevNames)
GlobalFree(printDlg.hDevNames);
if(printDlg.hDC)
DeleteDC(printDlg.hDC);
GdiplusShutdown(gdiplusToken);
return 0;
}