HRESULT CTestDirectWriteDlg::CreateDevInDependentResources() { HRESULT hr = S_OK; IFR(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory)); IFR(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&m_pDWriteFactory))); IDWriteFontFacePtr pFontFace = NULL; IDWriteFontFilePtr pFontFiles = NULL; if (SUCCEEDED(hr)) { CString strPath; // open a file name ZeroMemory( &ofn , sizeof( ofn)); ofn.lStructSize = sizeof ( ofn ); ofn.hwndOwner = NULL ; ofn.lpstrFile = szFile ; ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof( szFile ); ofn.lpstrFilter = L"All\0*.*\0Text\0*.TTF\0"; ofn.nFilterIndex =1; ofn.lpstrFileTitle = NULL ; ofn.nMaxFileTitle = 0 ; ofn.lpstrInitialDir=NULL ; ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ; GetOpenFileName( &ofn ); // Now simpley display the file name MessageBox (ofn.lpstrFile , L"File Name" , MB_OK); strPath.ReleaseBuffer (); strPath += szFile; hr = m_pDWriteFactory->CreateFontFileReference( strPath, NULL, &pFontFiles); } IDWriteFontFile* fontFileArray[] = {pFontFiles}; if(pFontFiles==NULL) { MessageBox(L"No font file is found at executable folder", L"Error"); return E_FAIL; } IFR(m_pDWriteFactory->CreateFontFace( DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, // file count fontFileArray, 0, DWRITE_FONT_SIMULATIONS_NONE, &pFontFace )); //CString szOutline = m_szOutline; CString szOutline(L"Hello!"); UINT* pCodePoints = new UINT[szOutline.GetLength()]; UINT16* pGlyphIndices = new UINT16[szOutline.GetLength()]; ZeroMemory(pCodePoints, sizeof(UINT) * szOutline.GetLength()); ZeroMemory(pGlyphIndices, sizeof(UINT16) * szOutline.GetLength()); for(int i=0; i<szOutline.GetLength(); ++i) { pCodePoints[i] = szOutline.GetAt(i); } pFontFace->GetGlyphIndicesW(pCodePoints, szOutline.GetLength(), pGlyphIndices); //Create the path geometry IFR(m_pD2DFactory->CreatePathGeometry(&m_pPathGeometry)); IFR(m_pPathGeometry->Open((ID2D1GeometrySink**)&m_pGeometrySink)); IFR(pFontFace->GetGlyphRunOutline( ConvertPointSizeToDIP(48.0f), pGlyphIndices, NULL, NULL, szOutline.GetLength(), FALSE, FALSE, m_pGeometrySink)); IFR(m_pGeometrySink->Close()); if(pCodePoints) { delete [] pCodePoints; pCodePoints = NULL; } if(pGlyphIndices) { delete [] pGlyphIndices; pGlyphIndices = NULL; } return hr; }
HRESULT GDIPresenter::Initialize(UINT uWidth, UINT uHeight) { HRESULT hr; _hMemoryDC = ::CreateCompatibleDC(NULL); BITMAPINFO info = { 0 }; info.bmiHeader.biBitCount = 32; info.bmiHeader.biCompression = BI_RGB; info.bmiHeader.biHeight = uWidth; info.bmiHeader.biWidth = uHeight; info.bmiHeader.biPlanes = 1; info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); _hBitmap = ::CreateDIBSection(NULL, &info, DIB_RGB_COLORS, &_pvBits, NULL, 0); ::SelectObject(_hMemoryDC, _hBitmap); CComObject<GDIPresenterBuffer> *pBuffer = NULL; IFR( CComObject<GDIPresenterBuffer>::CreateInstance(&pBuffer) ); pBuffer->Initialize(CSize(uWidth, uHeight), _pvBits); IFR( pBuffer->QueryInterface(&_spBuffer) ); return hr; }
HRESULT CTestDirectWriteDlg::CreateDevDependentResources() { HRESULT hr = S_OK; if (m_pRT) return hr; if (!IsWindowVisible()) return E_FAIL; RECT rc; GetClientRect(&rc); D2D1_SIZE_U size = D2D1::SizeU((rc.right-rc.left), (rc.bottom-rc.top)); IFR(m_pD2DFactory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(GetSafeHwnd(), size), &m_pRT)); hr = m_pRT->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Black), &m_pSolidBrushFill ); IFR(m_pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Blue), &m_pSolidBrushOutline )); return hr; }
HRESULT D3D9HWRenderer::SetBackBuffer(IUnknown *pBuffer) { HRESULT hr; CComPtr<IDirect3DTexture9> spTexture; IFR( pBuffer->QueryInterface(&spTexture) ); CComPtr<IDirect3DSurface9> spSurface; IFR( spTexture->GetSurfaceLevel(0, &spSurface) ); IFR( _spDevice->SetRenderTarget(0, spSurface) ); D3DSURFACE_DESC desc; IFR( spTexture->GetLevelDesc(0, &desc) ); _uWidth = desc.Width; _uHeight = desc.Height; return S_OK; }
HRESULT CRectAccessible::Init(IAccessible *pParent, IRectCollection *pCollection, int index) { HRESULT hr; IFR( CBasicAccessible::Init(pParent) ); _index = index; _spCollection = pCollection; return hr; }
STDMETHODIMP CRectAccessible::get_accDefaultAction( /* [optional][in] */ VARIANT varChild, /* [retval][out] */ __RPC__deref_out_opt BSTR *pszDefaultAction) { HRESULT hr; IFR( ::CheckOnlySelf(&varChild) ); *pszDefaultAction = SysAllocString(L"click"); return hr; }
STDMETHODIMP CRectAccessible::get_accRole( /* [optional][in] */ VARIANT varChild, /* [retval][out] */ __RPC__out VARIANT *pvarRole) { HRESULT hr; IFR( ::CheckOnlySelf(&varChild) ); pvarRole->vt = VT_I4; pvarRole->lVal = ROLE_SYSTEM_GRAPHIC; return hr; }
STDMETHODIMP CRectAccessible::accLocation( /* [out] */ __RPC__out long *pxLeft, /* [out] */ __RPC__out long *pyTop, /* [out] */ __RPC__out long *pcxWidth, /* [out] */ __RPC__out long *pcyHeight, /* [optional][in] */ VARIANT varChild) { HRESULT hr; IFR( CheckOnlySelf(&varChild) ); // We are offset from our parent, so get its rectangle CComVariant varSelf(CHILDID_SELF); IFR( GetParent()->accLocation(pxLeft, pyTop, pcxWidth, pcyHeight, varSelf) ); RectSprite sprite = _spCollection->GetRect(_index); (*pxLeft) += sprite._position.x; (*pyTop) += sprite._position.y; *pcxWidth = RectSprite::Size; *pcyHeight = RectSprite::Size; return hr; }
STDMETHODIMP CRectAccessible::get_accName( /* [optional][in] */ VARIANT varChild, /* [retval][out] */ __RPC__deref_out_opt BSTR *pszName) {; HRESULT hr; IFR( ::CheckOnlySelf(&varChild) ); CString nameString; nameString.Format(L"Surface Presenter Demo Rectangle %d", _index); *pszName = ::SysAllocString(nameString); return hr; }