[cairo] A newbie question about printing with Cairo on Win32
Caleb Land
redhatdude at gmail.com
Wed Oct 12 14:39:27 PDT 2005
Skipped content of type multipart/alternative-------------- next part --------------
#include <windows.h>
#include <cairo.h>
#include <math.h>
void snippet_normalize (cairo_t *cr, double width, double height)
{
cairo_scale (cr, width, height);
cairo_set_line_width (cr, 0.04);
}
void draw_shape(cairo_t* cr, int width, int height) {
snippet_normalize (cr, width, height);
cairo_set_line_width (cr, 0.16);
cairo_move_to (cr, 0.3, 0.33);
cairo_rel_line_to (cr, 0.2, -0.2);
cairo_rel_line_to (cr, 0.2, 0.2);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); /* default */
cairo_stroke (cr);
cairo_move_to (cr, 0.3, 0.63);
cairo_rel_line_to (cr, 0.2, -0.2);
cairo_rel_line_to (cr, 0.2, 0.2);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
cairo_stroke (cr);
cairo_move_to (cr, 0.3, 0.93);
cairo_rel_line_to (cr, 0.2, -0.2);
cairo_rel_line_to (cr, 0.2, 0.2);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
cairo_stroke (cr);
}
int main (int argc, char** argv) {
DOCINFO di;
PRINTDLG pd;
HWND hwnd;
int nError;
// Initialize PRINTDLG
ZeroMemory(&pd, sizeof(pd));
pd.lStructSize = sizeof(pd);
//pd.hwndOwner = hwnd;
pd.hDevMode = NULL; // Don't forget to free or store hDevMode
pd.hDevNames = NULL; // Don't forget to free or store hDevNames
pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
pd.nCopies = 1;
pd.nFromPage = 0xFFFF;
pd.nToPage = 0xFFFF;
pd.nMinPage = 1;
pd.nMaxPage = 0xFFFF;
double width = 800, height = 800;
cairo_surface_t* surface;
cairo_t* cr;
if (PrintDlg(&pd)==TRUE)
{
// GDI calls to render output.
memset( &di, 0, sizeof(DOCINFO) );
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Bitmap Printing Test";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
// Begin a print job by calling the StartDoc function.
nError = StartDoc(pd.hDC, &di);
if (nError == SP_ERROR)
{
//errhandler("StartDoc", hwnd);
goto Error;
}
// Inform the driver that the application is about to begin
// sending data.
nError = StartPage(pd.hDC);
if (nError <= 0)
{
goto Error;
}
surface = cairo_win32_surface_create(pd.hDC);
cr = cairo_create(surface);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
// uncomment this line to draw with a "white" pen
// cairo_set_source_rgb(cr, 1, 1, 1);
draw_shape(cr, width, height);
nError = EndPage(pd.hDC);
if (nError <= 0)
{
goto Error;
}
// Inform the driver that document has ended.
nError = EndDoc(pd.hDC);
if (nError <= 0)
//errhandler("EndDoc", hwnd);
Error:
// clean up
cairo_destroy(cr);
cairo_surface_destroy (surface);
// Delete DC when done.
DeleteDC(pd.hDC);
}
}
More information about the cairo
mailing list