#include	<pango/pango.h>
#include	<pango/pangocairo.h>

#ifndef _MSC_VER
#define _WIN32_WINNT 0x0500
#define WINVER _WIN32_WINNT
#endif

#include	<windows.h>
#include	<cairo-win32.h>

#include	<stdio.h>
#include	<math.h>

#define USE_PRINTING_SURFACE	1

static void	print_cell_gtk(cairo_t *context, PangoLayout *layout)
{
int		rotation;
double		x0, y0, x1, y1, width, height;
double		px, py;

x0 = 5;
y0 = 1;

x1 = 2;
y1 = 0;

px = 41.6377;
py = 1.10938;

width = 43;
height = 11.75;

pango_layout_set_text(layout, "1", -1);

rotation = 0;
cairo_save (context);

if (!rotation) {
	/* We do not clip rotated cells.  */
	cairo_new_path (context);
	cairo_rectangle (context, x0 - 1, y0 -1, width + 1, height + 1);
	cairo_clip (context);
}

/* Set the font colour */
cairo_set_source_rgb (context, 0, 0, 0);

if (rotation) {
	cairo_save (context);
	cairo_translate (context, x1, y1);
	cairo_rotate (context, rotation * (-M_PI / 180));
	cairo_move_to (context, 0.,0.);
	pango_cairo_show_layout (context, layout);
	cairo_restore (context);
} else {
	cairo_move_to (context, px, py);
	pango_cairo_show_layout (context, layout);
}
cairo_restore(context);
}

int	main(int p, char *par[])
{
static cairo_t	*cr;
cairo_surface_t	*surface;
PangoFontMap	*fontmap;
PangoLayout	*layout;
DOCINFO		docinfo;
HDC		hdc;
DWORD		bufSize;
double		ws, hs;
char		printer_name[100];

bufSize = sizeof(printer_name);
GetDefaultPrinter(printer_name, &bufSize);

hdc = CreateDC("WINSPOOL", printer_name, NULL, NULL);
if (hdc == NULL)
	fprintf(stderr, "Couldn't initialize printer\n");
else
	{
	ws = GetDeviceCaps(hdc, PHYSICALWIDTH);
	hs = GetDeviceCaps(hdc, PHYSICALHEIGHT);

	memset( &docinfo, 0, sizeof (DOCINFO));
	docinfo.cbSize = sizeof (DOCINFO); 
	docinfo.lpszDocName = (LPCSTR)"PDF";
	docinfo.lpszOutput = (LPCSTR) NULL; 
	docinfo.lpszDatatype = (LPCSTR) NULL; 
	docinfo.fwType = 0; 

	if (StartDoc(hdc, &docinfo) > 0)
		{
	#ifndef USE_PRINTING_SURFACE
		surface = cairo_win32_surface_create(hdc);
	#else
		surface = cairo_win32_printing_surface_create(hdc);
	#endif

		cr = cairo_create(surface);
		cairo_scale(cr, ws / 210.0, hs / 297.0);	// A4 paper
		cairo_translate(cr, 20, 20);

		fontmap = pango_cairo_font_map_get_default();
		pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap), 25.0);
		layout = pango_cairo_create_layout(cr);

		StartPage (hdc);
		print_cell_gtk(cr, layout);
		cairo_show_page(cr);
		EndPage (hdc);

		EndDoc (hdc);
		cairo_surface_destroy(surface);
		cairo_destroy(cr);
		g_object_unref(layout);
		}
	DeleteDC(hdc);
	}
return 0;
}
