Beispiel #1
0
/********************************************************************************************
>	virtual BOOL ConcurrentRenderer::Initialise(
					GRenderRegion* pActiveRR,
					double ResFactor,
					DocRect AreaOfDocumentToRender,
					UINT32 bpp,
					BOOL NeedsTransp
			)
	Author:		Ilan_Copelyn (Xara Group Ltd) <*****@*****.**>
	Created:	5/06/2000
	Purpose:	
	SeeAlso:	
 ********************************************************************************************/
BOOL ConcurrentRenderer::Initialise(
					GRenderRegion* pActiveRR,
					double ResFactor,
					DocRect AreaOfDocumentToRender,
					UINT32 bpp,
					BOOL NeedsTransp
			)
{
	// if we have no source render-region, then we need to manufacture a rendering matrix
	// for ourself.
	// to generate our render-matrix, we use the current view and spread, together with
	// a user-specified dpi value.
	Matrix	SourceMat;
	if (pActiveRR == NULL)
	{
		View* pView = View::GetCurrent();
		if (pView == NULL)
			return FALSE;

		double PixelsPerInch = pView->GetConvertToEditableShapesDPI();

		Spread* pSpread = Document::GetSelectedSpread();
		if (pSpread == NULL)
			return FALSE;

		FIXED16			ViewPixelWidth	= pView->GetScaledPixelWidth();
		const double	AppPixelWidth	= MILLIPOINTS_PER_INCH / (double)PixelsPerInch;
		double ViewScaleFactor = ViewPixelWidth.MakeDouble() / AppPixelWidth;

		SourceMat = pView->ConstructScaledRenderingMatrix(pSpread, ViewScaleFactor);
	}

	// we have a source render-region, so get its matrix and scale up ResFactor
	// so that our offscreen RR would effectively have the same scaled pixel width
	// as its source render-region (not taking into account the original value of ResFactor).
	else
	{
		SourceMat = pActiveRR->GetMatrix();
		const double ActualPixelWidth = (double)pActiveRR->GetPixelWidth();
		const double DefPixelWidth = MILLIPOINTS_PER_INCH / (double)GRenderRegion::GetDefaultDPI();
		ResFactor *= DefPixelWidth / ActualPixelWidth;
	}

//	m_pView = pActiveRR->GetRenderView();
//	m_pView = View::GetCurrent();
//	if (m_pView)
//	{
//		TRACEUSER( "Gerry", _T("Forcing default context\n"));
//		m_bOldForce = m_pView->SetForceDefaultColourContexts();
//	}

	m_pNewGD = new GDrawAsm;
	if (m_pNewGD && m_pNewGD->Init())
	{
		// Save current device context
		m_pOldGD = GRenderRegion::SetTempDrawContext(m_pNewGD);
//		m_pOldGD = GRenderRegion::GetStaticDrawContext();
//		GRenderRegion::GD = pGDAsm;
	}

	// Setup a new GRenderDIB (NB also initialises memory).
	m_pNewRR = CreateGRenderDIB(ResFactor, AreaOfDocumentToRender, bpp, NeedsTransp, &SourceMat);
	if (m_pNewRR != NULL)
	{
		return TRUE;
	}

	// If we get here then we have failed so clean up and return false
	delete m_pNewGD;
	m_pNewGD = NULL;
	GRenderRegion::SetTempDrawContext(m_pOldGD);
	m_pOldGD = NULL;
	return FALSE;
}