[cairo] cairo_show_page vs win32

Paddi.M at gmx.net Paddi.M at gmx.net
Tue Jan 31 04:31:06 PST 2006


Hi Alex,

Why do you think you need cairo_show_page().
Here's a part of my MFC view for printing/viewing with cairo. But I have to
say I still have some trouble with printing:

void ccCairoView2D::OnDraw(CDC* pDC)
{
	CCcExchangeViewerXTPDoc* pDoc = GetDocument();
	if (pDC)
	{    
		cairo_surface_t *surface = NULL;
		cairo_t* cr = NULL;

		surface = cairo_win32_surface_create (pDC->GetSafeHdc());
		cr = cairo_create (surface);

				
		CRect tmpRect;
		GetClientRect(tmpRect);

		double DPIX = pDC->GetDeviceCaps(LOGPIXELSX);
		double DPIY = pDC->GetDeviceCaps(LOGPIXELSY);
		
		int minX = tmpRect.left;
		int maxX = tmpRect.right;
		int minY = tmpRect.top;
		int maxY = tmpRect.bottom;

		m_Cairo.SetBackgroundType(ccRenderer2D::BG_SOLID);
		m_Cairo.SetBGColorTop(cclab::ccGeomColor(88,87,104));
		m_Cairo.SetUseLineWidths(pDC->IsPrinting());

/*
		m_Cairo.SetBackgroundType(ccRenderer2D::BG_GRADIENT);
		m_Cairo.SetBGColorTop(cclab::ccGeomColor(160,160,160));
		m_Cairo.SetBGColorBottom(cclab::ccGeomColor(0,0,0));
*/
		m_Cairo.SetContext(cr);

		if (pDC->IsPrinting())
		{
//			cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY);
			maxX = pDC->GetDeviceCaps(HORZRES);
			maxY = pDC->GetDeviceCaps(VERTRES);
			double sizeX = pDC->GetDeviceCaps(HORZSIZE);
			double sizeY = pDC->GetDeviceCaps(VERTSIZE);

			if (!GetPrintBG())
			{
				m_Cairo.SetBackgroundType(ccRenderer2D::BG_NONE);
				m_Cairo.SetBGColorTop(cclab::ccGeomColor(255,255,255));
			}
		}
		m_Cairo.SetDPI(cclab::cc_calc::minimum(DPIX,DPIY));
		m_Cairo.GetViewPort()->Init();
		m_Cairo.GetViewPort()->AddX(minX);
		m_Cairo.GetViewPort()->AddX(maxX);
		m_Cairo.GetViewPort()->AddY(minY);
		m_Cairo.GetViewPort()->AddY(maxY);

		m_Cairo.SetScaleFactor(1.0);
		m_Cairo.Draw(GetDocument()->GetScene2D());

		if (m_writeDebugPng)
			cairo_surface_write_to_png(surface, "c:\\cairoview.png");

		m_Cairo.SetContext(NULL);
    
		if (cr)
			cairo_destroy (cr);
		if (surface)
			cairo_surface_destroy (surface);
	}
}

Perhaps it helps,

Patrik

-- 
10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail
+++ GMX - die erste Adresse für Mail, Message, More +++


More information about the cairo mailing list