STDMETHODIMP
CDirect2DRM::CreateImageFromText(BSTR bstrText, DWORD nPointHeight, BOOL bShadowed, 
								 LPDIRECT2DRMIMAGE *ppImage)
{
	MMASSERT(ppImage);
	if (m_pImageCache == NULL)
		return E_NOTINITIALIZED;

	HRESULT hr;
	LPD2DRMIMAGEPRIVATE pImagePriv = NULL;
	CMFImage *pmfi = NULL;
	CString strText(bstrText);
	IFont *pFont = NULL;
	HFONT hFont = NULL;
	CY size = {nPointHeight*10000, 0};
	
	pFont = GetDefaultFont();
	pFont->put_Size(size);
	pFont->get_hFont(&hFont);
	
		// get a reference to the MFImage from the image cache
	if (FAILED(hr = m_pImageCache->GetImageFromText(strText, hFont, 0x00FFFFFF, bShadowed, 0, NULL, &pmfi)) ||
		// CoCreate the D2DRMImage object
		FAILED(hr = CoCreateInstance(
						CLSID_CDirect2DRMImage,
						NULL,
						CLSCTX_INPROC_SERVER,
						IID_ID2DRMImagePrivate,
						(LPVOID *) &pImagePriv)) ||
		// initialize the D2DRMImage with the MFImage
		FAILED(hr = pImagePriv->InitFromMFImage(this, pmfi, 0)))
		goto e_CreateImageFromText;

	*ppImage = (LPDIRECT2DRMIMAGE) pImagePriv;

	// release the extra reference we had from the CreateImageFromText
	pmfi->Release();

	return S_OK;

e_CreateImageFromText:
	MMRELEASE(pImagePriv);
	MMRELEASE(pmfi);
	MMRELEASE(pFont);
	return hr;
}
Exemple #2
0
BOOL CFontPropPage::SetFontProps(CDataExchange* pDX, FONTOBJECT fobj, LPCTSTR pszPropName)
{
	USES_CONVERSION;

	BOOL bStatus = FALSE;
	COleDispatchDriver PropDispDriver;

	// Set the properties for all the objects
	ASSERT_KINDOF(COlePropertyPage, pDX->m_pDlgWnd);
	COlePropertyPage* propDialog = (COlePropertyPage*)(pDX->m_pDlgWnd);

	ULONG nObjects;
	LPDISPATCH* ppDisp = GetObjectArray(&nObjects);

	for (ULONG i = 0; i < nObjects; i++)
	{
		DISPID dwDispID;

		// Get the Dispatch ID for the property and if successful set the value
		LPCOLESTR lpOleStr = T2COLE(pszPropName);
		if (SUCCEEDED(ppDisp[i]->GetIDsOfNames(IID_NULL, (LPOLESTR*)&lpOleStr,
			1, m_lcid, &dwDispID)))
		{
			LPDISPATCH pFontDisp = NULL;

			// Get property
			PropDispDriver.AttachDispatch(ppDisp[i], FALSE);
			TRY
				PropDispDriver.GetProperty(dwDispID, VT_DISPATCH, &pFontDisp);
			END_TRY
			PropDispDriver.DetachDispatch();

			if (pFontDisp == NULL)
				continue;

			// Get font interface
			IFont * pFont;
			HRESULT hresult = pFontDisp->QueryInterface(IID_IFont, (void**)&pFont);
			if (hresult == S_OK)
			{
				// Set font characteristics
				if (propDialog->GetControlStatus(AFX_IDC_FONTNAMES))
				{
					BSTR bstrName = fobj.strName.AllocSysString();
					pFont->put_Name(bstrName);
					SysFreeString(bstrName);
				}
				if (propDialog->GetControlStatus(AFX_IDC_FONTSIZES))
					pFont->put_Size(fobj.cySize);
				if (propDialog->GetControlStatus(AFX_IDC_FONTSTYLES))
				{
					pFont->put_Bold(fobj.bBold);
					pFont->put_Italic(fobj.bItalic);
					pFont->put_Weight(fobj.sWeight);
				}
				if (propDialog->GetControlStatus(AFX_IDC_UNDERLINE))
					pFont->put_Underline(fobj.bUnderline);
				if (propDialog->GetControlStatus(AFX_IDC_STRIKEOUT))
					pFont->put_Strikethrough(fobj.bStrikethrough);

				// Release the font interface
				RELEASE(pFont);
				bStatus = TRUE;
			}

			// Release the font dispatch interface
			RELEASE(pFontDisp);
		}
	}
	return bStatus;
}