├── .gitignore ├── TestDirectWrite.sln └── TestDirectWrite ├── Resource.h ├── TestDirectWrite.aps ├── TestDirectWrite.cpp ├── TestDirectWrite.h ├── TestDirectWrite.rc ├── TestDirectWrite.vcxproj ├── TestDirectWriteDlg.cpp ├── TestDirectWriteDlg.h ├── Tuffy.ttf ├── res ├── TestDirectWrite.ico └── TestDirectWrite.rc2 ├── stdafx.cpp ├── stdafx.h └── targetver.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /TestDirectWrite.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestDirectWrite", "TestDirectWrite\TestDirectWrite.vcxproj", "{BEFEA9CA-2BA3-417E-ABDC-B23E561CB9FE}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {BEFEA9CA-2BA3-417E-ABDC-B23E561CB9FE}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {BEFEA9CA-2BA3-417E-ABDC-B23E561CB9FE}.Debug|Win32.Build.0 = Debug|Win32 14 | {BEFEA9CA-2BA3-417E-ABDC-B23E561CB9FE}.Release|Win32.ActiveCfg = Release|Win32 15 | {BEFEA9CA-2BA3-417E-ABDC-B23E561CB9FE}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /TestDirectWrite/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by TestDirectWrite.rc 4 | // 5 | #define IDR_MAINFRAME 128 6 | #define IDD_TESTDIRECTWRITE_DIALOG 102 7 | 8 | // Next default values for new objects 9 | // 10 | #ifdef APSTUDIO_INVOKED 11 | #ifndef APSTUDIO_READONLY_SYMBOLS 12 | 13 | #define _APS_NEXT_RESOURCE_VALUE 129 14 | #define _APS_NEXT_CONTROL_VALUE 1000 15 | #define _APS_NEXT_SYMED_VALUE 101 16 | #define _APS_NEXT_COMMAND_VALUE 32771 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /TestDirectWrite/TestDirectWrite.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pierrejoye/directwriteusingcustomfont/331b4e04a2715debfa69d3767f7d940f96d5f209/TestDirectWrite/TestDirectWrite.aps -------------------------------------------------------------------------------- /TestDirectWrite/TestDirectWrite.cpp: -------------------------------------------------------------------------------- 1 | 2 | // TestDirectWrite.cpp : Defines the class behaviors for the application. 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "TestDirectWrite.h" 7 | #include "TestDirectWriteDlg.h" 8 | 9 | #ifdef _DEBUG 10 | #define new DEBUG_NEW 11 | #endif 12 | 13 | 14 | // CTestDirectWriteApp 15 | 16 | BEGIN_MESSAGE_MAP(CTestDirectWriteApp, CWinApp) 17 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 18 | END_MESSAGE_MAP() 19 | 20 | 21 | // CTestDirectWriteApp construction 22 | 23 | CTestDirectWriteApp::CTestDirectWriteApp() 24 | { 25 | // support Restart Manager 26 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 27 | 28 | // TODO: add construction code here, 29 | // Place all significant initialization in InitInstance 30 | } 31 | 32 | 33 | // The one and only CTestDirectWriteApp object 34 | 35 | CTestDirectWriteApp theApp; 36 | 37 | 38 | // CTestDirectWriteApp initialization 39 | 40 | BOOL CTestDirectWriteApp::InitInstance() 41 | { 42 | // InitCommonControlsEx() is required on Windows XP if an application 43 | // manifest specifies use of ComCtl32.dll version 6 or later to enable 44 | // visual styles. Otherwise, any window creation will fail. 45 | INITCOMMONCONTROLSEX InitCtrls; 46 | InitCtrls.dwSize = sizeof(InitCtrls); 47 | // Set this to include all the common control classes you want to use 48 | // in your application. 49 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 50 | InitCommonControlsEx(&InitCtrls); 51 | 52 | CWinApp::InitInstance(); 53 | 54 | 55 | AfxEnableControlContainer(); 56 | 57 | // Create the shell manager, in case the dialog contains 58 | // any shell tree view or shell list view controls. 59 | CShellManager *pShellManager = new CShellManager; 60 | 61 | // Standard initialization 62 | // If you are not using these features and wish to reduce the size 63 | // of your final executable, you should remove from the following 64 | // the specific initialization routines you do not need 65 | // Change the registry key under which our settings are stored 66 | // TODO: You should modify this string to be something appropriate 67 | // such as the name of your company or organization 68 | SetRegistryKey(_T("Local AppWizard-Generated Applications")); 69 | 70 | CTestDirectWriteDlg dlg; 71 | m_pMainWnd = &dlg; 72 | INT_PTR nResponse = dlg.DoModal(); 73 | if (nResponse == IDOK) 74 | { 75 | // TODO: Place code here to handle when the dialog is 76 | // dismissed with OK 77 | } 78 | else if (nResponse == IDCANCEL) 79 | { 80 | // TODO: Place code here to handle when the dialog is 81 | // dismissed with Cancel 82 | } 83 | 84 | // Delete the shell manager created above. 85 | if (pShellManager != NULL) 86 | { 87 | delete pShellManager; 88 | } 89 | 90 | // Since the dialog has been closed, return FALSE so that we exit the 91 | // application, rather than start the application's message pump. 92 | return FALSE; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /TestDirectWrite/TestDirectWrite.h: -------------------------------------------------------------------------------- 1 | 2 | // TestDirectWrite.h : main header file for the PROJECT_NAME application 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'stdafx.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // main symbols 12 | 13 | 14 | // CTestDirectWriteApp: 15 | // See TestDirectWrite.cpp for the implementation of this class 16 | // 17 | 18 | class CTestDirectWriteApp : public CWinApp 19 | { 20 | public: 21 | CTestDirectWriteApp(); 22 | 23 | // Overrides 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // Implementation 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CTestDirectWriteApp theApp; -------------------------------------------------------------------------------- /TestDirectWrite/TestDirectWrite.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pierrejoye/directwriteusingcustomfont/331b4e04a2715debfa69d3767f7d940f96d5f209/TestDirectWrite/TestDirectWrite.rc -------------------------------------------------------------------------------- /TestDirectWrite/TestDirectWrite.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {BEFEA9CA-2BA3-417E-ABDC-B23E561CB9FE} 15 | TestDirectWrite 16 | MFCProj 17 | 18 | 19 | 20 | Application 21 | true 22 | Unicode 23 | Dynamic 24 | v110 25 | 26 | 27 | Application 28 | false 29 | true 30 | Unicode 31 | Dynamic 32 | v110 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | 47 | 48 | false 49 | 50 | 51 | 52 | Use 53 | Level3 54 | Disabled 55 | WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) 56 | 57 | 58 | Windows 59 | true 60 | 61 | 62 | false 63 | true 64 | _DEBUG;%(PreprocessorDefinitions) 65 | 66 | 67 | 0x0409 68 | _DEBUG;%(PreprocessorDefinitions) 69 | $(IntDir);%(AdditionalIncludeDirectories) 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | Level3 79 | Use 80 | MaxSpeed 81 | true 82 | true 83 | WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) 84 | 85 | 86 | Windows 87 | true 88 | true 89 | true 90 | 91 | 92 | false 93 | true 94 | NDEBUG;%(PreprocessorDefinitions) 95 | 96 | 97 | 0x0409 98 | NDEBUG;%(PreprocessorDefinitions) 99 | $(IntDir);%(AdditionalIncludeDirectories) 100 | 101 | 102 | xcopy "$(ProjectDir)res\Ruzicka TypeK.ttf" "$(TargetDir)" /i /Y 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | Create 120 | Create 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /TestDirectWrite/TestDirectWriteDlg.cpp: -------------------------------------------------------------------------------- 1 | 2 | // TestDirectWriteDlg.cpp : implementation file 3 | // 4 | 5 | #include "stdafx.h" 6 | #include 7 | #include "resource.h" 8 | #include 9 | #include "TestDirectWrite.h" 10 | #include "TestDirectWriteDlg.h" 11 | #include "afxdialogex.h" 12 | 13 | #include 14 | #include 15 | 16 | #ifdef _DEBUG 17 | #define new DEBUG_NEW 18 | #endif 19 | 20 | OPENFILENAME ofn ; 21 | // a another memory buffer to contain the file name 22 | wchar_t szFile[OFS_MAXPATHNAME] ; 23 | 24 | 25 | CTestDirectWriteDlg::CTestDirectWriteDlg(CWnd* pParent /*=NULL*/) 26 | : 27 | m_pD2DFactory(NULL), 28 | m_pRT(NULL), 29 | m_pDWriteFactory(NULL), 30 | m_pGeometrySink(NULL), 31 | m_pPathGeometry(NULL), 32 | m_pSolidBrushFill(NULL), 33 | m_pSolidBrushOutline(NULL), 34 | //m_szOutline(L"Great "), 35 | CDialogEx(CTestDirectWriteDlg::IDD, pParent) 36 | { 37 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 38 | } 39 | 40 | void CTestDirectWriteDlg::DoDataExchange(CDataExchange* pDX) 41 | { 42 | CDialogEx::DoDataExchange(pDX); 43 | } 44 | 45 | BEGIN_MESSAGE_MAP(CTestDirectWriteDlg, CDialogEx) 46 | ON_WM_PAINT() 47 | ON_WM_QUERYDRAGICON() 48 | ON_WM_DESTROY() 49 | END_MESSAGE_MAP() 50 | 51 | 52 | // CTestDirectWriteDlg message handlers 53 | 54 | BOOL CTestDirectWriteDlg::OnInitDialog() 55 | { 56 | CDialogEx::OnInitDialog(); 57 | 58 | SetIcon(m_hIcon, TRUE); // Set big icon 59 | SetIcon(m_hIcon, FALSE); // Set small icon 60 | 61 | HRESULT hr = CreateDevInDependentResources(); 62 | if (!SUCCEEDED(hr)) 63 | { 64 | MessageBox(L"Something went wrong in creating device independent resources!", L"DirectWrite Demo", MB_ICONERROR); 65 | return FALSE; 66 | } 67 | 68 | return TRUE; 69 | } 70 | 71 | // If you add a minimize button to your dialog, you will need the code below 72 | // to draw the icon. For MFC applications using the document/view model, 73 | // this is automatically done for you by the framework. 74 | 75 | void CTestDirectWriteDlg::OnPaint() 76 | { 77 | if (IsIconic()) 78 | { 79 | CPaintDC dc(this); // device context for painting 80 | 81 | SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); 82 | 83 | // Center icon in client rectangle 84 | int cxIcon = GetSystemMetrics(SM_CXICON); 85 | int cyIcon = GetSystemMetrics(SM_CYICON); 86 | CRect rect; 87 | GetClientRect(&rect); 88 | int x = (rect.Width() - cxIcon + 1) / 2; 89 | int y = (rect.Height() - cyIcon + 1) / 2; 90 | 91 | // Draw the icon 92 | dc.DrawIcon(x, y, m_hIcon); 93 | } 94 | else 95 | { 96 | if(FAILED(CreateDevDependentResources())) 97 | return; 98 | 99 | if (m_pRT->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED) 100 | return; 101 | 102 | m_pRT->BeginDraw(); 103 | m_pRT->SetTransform(D2D1::IdentityMatrix()); 104 | m_pRT->Clear(D2D1::ColorF(D2D1::ColorF::White)); 105 | m_pRT->SetTransform(D2D1::Matrix3x2F::Translation(10.0f,60.0f)); 106 | m_pRT->DrawGeometry(m_pPathGeometry, m_pSolidBrushOutline, 3.0f); 107 | m_pRT->FillGeometry(m_pPathGeometry, m_pSolidBrushFill); 108 | 109 | HRESULT hr = m_pRT->EndDraw(); 110 | 111 | if(FAILED(hr)) 112 | ReleaseDevDependentResources(); 113 | } 114 | } 115 | 116 | HCURSOR CTestDirectWriteDlg::OnQueryDragIcon() 117 | { 118 | return static_cast(m_hIcon); 119 | } 120 | 121 | void CTestDirectWriteDlg::OnDestroy() 122 | { 123 | CDialogEx::OnDestroy(); 124 | 125 | // Cleanup resources. 126 | ReleaseDevDependentResources(); 127 | ReleaseDevInDependentResources(); 128 | } 129 | 130 | HRESULT CTestDirectWriteDlg::CreateDevInDependentResources() 131 | { 132 | HRESULT hr = S_OK; 133 | IFR(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory)); 134 | 135 | IFR(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), 136 | reinterpret_cast(&m_pDWriteFactory))); 137 | 138 | IDWriteFontFacePtr pFontFace = NULL; 139 | IDWriteFontFilePtr pFontFiles = NULL; 140 | 141 | if (SUCCEEDED(hr)) 142 | { 143 | CString strPath; 144 | 145 | // open a file name 146 | ZeroMemory( &ofn , sizeof( ofn)); 147 | ofn.lStructSize = sizeof ( ofn ); 148 | ofn.hwndOwner = NULL ; 149 | ofn.lpstrFile = szFile ; 150 | ofn.lpstrFile[0] = '\0'; 151 | ofn.nMaxFile = sizeof( szFile ); 152 | ofn.lpstrFilter = L"All\0*.*\0Text\0*.TTF\0"; 153 | ofn.nFilterIndex =1; 154 | ofn.lpstrFileTitle = NULL ; 155 | ofn.nMaxFileTitle = 0 ; 156 | ofn.lpstrInitialDir=NULL ; 157 | ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ; 158 | GetOpenFileName( &ofn ); 159 | 160 | // Now simpley display the file name 161 | MessageBox (ofn.lpstrFile , L"File Name" , MB_OK); 162 | 163 | strPath.ReleaseBuffer (); 164 | strPath += szFile; 165 | 166 | hr = m_pDWriteFactory->CreateFontFileReference( 167 | strPath, 168 | NULL, 169 | &pFontFiles); 170 | } 171 | 172 | IDWriteFontFile* fontFileArray[] = {pFontFiles}; 173 | 174 | if(pFontFiles==NULL) 175 | { 176 | MessageBox(L"No font file is found at executable folder", L"Error"); 177 | return E_FAIL; 178 | } 179 | 180 | IFR(m_pDWriteFactory->CreateFontFace( 181 | DWRITE_FONT_FACE_TYPE_TRUETYPE, 182 | 1, // file count 183 | fontFileArray, 184 | 0, 185 | DWRITE_FONT_SIMULATIONS_NONE, 186 | &pFontFace 187 | )); 188 | 189 | //CString szOutline = m_szOutline; 190 | CString szOutline(L"Hello!"); 191 | 192 | UINT* pCodePoints = new UINT[szOutline.GetLength()]; 193 | UINT16* pGlyphIndices = new UINT16[szOutline.GetLength()]; 194 | ZeroMemory(pCodePoints, sizeof(UINT) * szOutline.GetLength()); 195 | ZeroMemory(pGlyphIndices, sizeof(UINT16) * szOutline.GetLength()); 196 | for(int i=0; iGetGlyphIndicesW(pCodePoints, szOutline.GetLength(), pGlyphIndices); 201 | 202 | //Create the path geometry 203 | IFR(m_pD2DFactory->CreatePathGeometry(&m_pPathGeometry)); 204 | 205 | IFR(m_pPathGeometry->Open((ID2D1GeometrySink**)&m_pGeometrySink)); 206 | 207 | IFR(pFontFace->GetGlyphRunOutline( 208 | ConvertPointSizeToDIP(48.0f), 209 | pGlyphIndices, 210 | NULL, 211 | NULL, 212 | szOutline.GetLength(), 213 | FALSE, 214 | FALSE, 215 | m_pGeometrySink)); 216 | 217 | IFR(m_pGeometrySink->Close()); 218 | 219 | if(pCodePoints) 220 | { 221 | delete [] pCodePoints; 222 | pCodePoints = NULL; 223 | } 224 | 225 | if(pGlyphIndices) 226 | { 227 | delete [] pGlyphIndices; 228 | pGlyphIndices = NULL; 229 | } 230 | 231 | return hr; 232 | } 233 | 234 | void CTestDirectWriteDlg::ReleaseDevInDependentResources() 235 | { 236 | if (m_pGeometrySink) 237 | m_pGeometrySink.Release(); 238 | if (m_pPathGeometry) 239 | m_pPathGeometry.Release(); 240 | if (m_pDWriteFactory) 241 | m_pDWriteFactory.Release(); 242 | if (m_pD2DFactory) 243 | m_pD2DFactory.Release(); 244 | } 245 | 246 | HRESULT CTestDirectWriteDlg::CreateDevDependentResources() 247 | { 248 | HRESULT hr = S_OK; 249 | 250 | if (m_pRT) 251 | return hr; 252 | 253 | if (!IsWindowVisible()) 254 | return E_FAIL; 255 | 256 | RECT rc; 257 | GetClientRect(&rc); 258 | D2D1_SIZE_U size = D2D1::SizeU((rc.right-rc.left), (rc.bottom-rc.top)); 259 | 260 | IFR(m_pD2DFactory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(), 261 | D2D1::HwndRenderTargetProperties(GetSafeHwnd(), size), &m_pRT)); 262 | hr = m_pRT->CreateSolidColorBrush( 263 | D2D1::ColorF(D2D1::ColorF::Black), 264 | &m_pSolidBrushFill 265 | ); 266 | IFR(m_pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Blue), 267 | &m_pSolidBrushOutline 268 | )); 269 | 270 | return hr; 271 | } 272 | 273 | void CTestDirectWriteDlg::ReleaseDevDependentResources() 274 | { 275 | if (m_pSolidBrushOutline) 276 | m_pSolidBrushOutline.Release(); 277 | if(m_pSolidBrushFill) 278 | m_pSolidBrushFill.Release(); 279 | if (m_pRT) 280 | m_pRT.Release(); 281 | } 282 | 283 | FLOAT CTestDirectWriteDlg::ConvertPointSizeToDIP(FLOAT points) 284 | { 285 | return (points/72.0f)*96.0f; 286 | } 287 | 288 | CString CTestDirectWriteDlg::GetWeekDay() 289 | { 290 | wchar_t * weekday[] = { L"This", L"Is", 291 | L"some", L"Direct2d", 292 | L"Example"}; 293 | 294 | 295 | COleDateTime t; 296 | t = COleDateTime::GetCurrentTime(); 297 | return weekday[t.GetDayOfWeek()-1]; 298 | } -------------------------------------------------------------------------------- /TestDirectWrite/TestDirectWriteDlg.h: -------------------------------------------------------------------------------- 1 | 2 | // TestDirectWriteDlg.h : header file 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CTestDirectWriteDlg dialog 9 | class CTestDirectWriteDlg : public CDialogEx 10 | { 11 | // Construction 12 | public: 13 | CTestDirectWriteDlg(CWnd* pParent = NULL); // standard constructor 14 | 15 | // Dialog Data 16 | enum { IDD = IDD_TESTDIRECTWRITE_DIALOG }; 17 | 18 | protected: 19 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 20 | private: 21 | HRESULT CreateDevInDependentResources(); 22 | void ReleaseDevInDependentResources(); 23 | HRESULT CreateDevDependentResources(); 24 | void ReleaseDevDependentResources(); 25 | FLOAT ConvertPointSizeToDIP(FLOAT points); 26 | CString GetWeekDay(); 27 | 28 | 29 | // Implementation 30 | protected: 31 | HICON m_hIcon; 32 | ID2D1FactoryPtr m_pD2DFactory; 33 | ID2D1HwndRenderTargetPtr m_pRT; 34 | IDWriteFactoryPtr m_pDWriteFactory; 35 | ID2D1SimplifiedGeometrySinkPtr m_pGeometrySink; 36 | ID2D1PathGeometryPtr m_pPathGeometry; 37 | ID2D1SolidColorBrushPtr m_pSolidBrushFill; 38 | ID2D1SolidColorBrushPtr m_pSolidBrushOutline; 39 | 40 | CString m_szOutline; 41 | 42 | // Generated message map functions 43 | virtual BOOL OnInitDialog(); 44 | afx_msg void OnPaint(); 45 | afx_msg HCURSOR OnQueryDragIcon(); 46 | DECLARE_MESSAGE_MAP() 47 | public: 48 | afx_msg void OnDestroy(); 49 | }; 50 | -------------------------------------------------------------------------------- /TestDirectWrite/Tuffy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pierrejoye/directwriteusingcustomfont/331b4e04a2715debfa69d3767f7d940f96d5f209/TestDirectWrite/Tuffy.ttf -------------------------------------------------------------------------------- /TestDirectWrite/res/TestDirectWrite.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pierrejoye/directwriteusingcustomfont/331b4e04a2715debfa69d3767f7d940f96d5f209/TestDirectWrite/res/TestDirectWrite.ico -------------------------------------------------------------------------------- /TestDirectWrite/res/TestDirectWrite.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pierrejoye/directwriteusingcustomfont/331b4e04a2715debfa69d3767f7d940f96d5f209/TestDirectWrite/res/TestDirectWrite.rc2 -------------------------------------------------------------------------------- /TestDirectWrite/stdafx.cpp: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.cpp : source file that includes just the standard includes 3 | // TestDirectWrite.pch will be the pre-compiled header 4 | // stdafx.obj will contain the pre-compiled type information 5 | 6 | #include "stdafx.h" 7 | 8 | 9 | -------------------------------------------------------------------------------- /TestDirectWrite/stdafx.h: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.h : include file for standard system include files, 3 | // or project specific include files that are used frequently, 4 | // but are changed infrequently 5 | 6 | #pragma once 7 | 8 | #ifndef _SECURE_ATL 9 | #define _SECURE_ATL 1 10 | #endif 11 | 12 | #ifndef VC_EXTRALEAN 13 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 14 | #endif 15 | 16 | #include "targetver.h" 17 | 18 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit 19 | 20 | // turns off MFC's hiding of some common and often safely ignored warning messages 21 | #define _AFX_ALL_WARNINGS 22 | 23 | #include // MFC core and standard components 24 | #include // MFC extensions 25 | 26 | 27 | #include // MFC Automation classes 28 | 29 | 30 | 31 | #ifndef _AFX_NO_OLE_SUPPORT 32 | #include // MFC support for Internet Explorer 4 Common Controls 33 | #endif 34 | #ifndef _AFX_NO_AFXCMN_SUPPORT 35 | #include // MFC support for Windows Common Controls 36 | #endif // _AFX_NO_AFXCMN_SUPPORT 37 | 38 | #include // MFC support for ribbons and control bars 39 | 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #pragma comment(lib, "d2d1.lib") 46 | #pragma comment(lib, "dwrite.lib") 47 | 48 | #ifndef IFR 49 | #define IFR(expr) do {hr = (expr); _ASSERT(SUCCEEDED(hr)); if (FAILED(hr)) return(hr);} while(0) 50 | #endif 51 | 52 | _COM_SMARTPTR_TYPEDEF(ID2D1Factory, __uuidof(ID2D1Factory)); 53 | _COM_SMARTPTR_TYPEDEF(ID2D1HwndRenderTarget, __uuidof(ID2D1HwndRenderTarget)); 54 | _COM_SMARTPTR_TYPEDEF(ID2D1SolidColorBrush, __uuidof(ID2D1SolidColorBrush)); 55 | _COM_SMARTPTR_TYPEDEF(ID2D1GradientStopCollection, __uuidof(ID2D1GradientStopCollection)); 56 | _COM_SMARTPTR_TYPEDEF(ID2D1LinearGradientBrush, __uuidof(ID2D1LinearGradientBrush)); 57 | 58 | // Define smartpointers types for DirectWrite interfaces. 59 | _COM_SMARTPTR_TYPEDEF(IDWriteFactory, __uuidof(IDWriteFactory)); 60 | _COM_SMARTPTR_TYPEDEF(IDWriteTextFormat, __uuidof(IDWriteTextFormat)); 61 | _COM_SMARTPTR_TYPEDEF(IDWriteTextLayout, __uuidof(IDWriteTextLayout)); 62 | _COM_SMARTPTR_TYPEDEF(IDWriteTypography, __uuidof(IDWriteTypography)); 63 | _COM_SMARTPTR_TYPEDEF(IDWriteFontFace, __uuidof(IDWriteFontFace)); 64 | _COM_SMARTPTR_TYPEDEF(IDWriteFontFile, __uuidof(IDWriteFontFile)); 65 | _COM_SMARTPTR_TYPEDEF(ID2D1SimplifiedGeometrySink, __uuidof(ID2D1SimplifiedGeometrySink)); 66 | _COM_SMARTPTR_TYPEDEF(ID2D1PathGeometry, __uuidof(ID2D1PathGeometry)); 67 | _COM_SMARTPTR_TYPEDEF(ID2D1LinearGradientBrush, __uuidof(ID2D1LinearGradientBrush)); 68 | _COM_SMARTPTR_TYPEDEF(ID2D1GradientStopCollection, __uuidof(ID2D1GradientStopCollection)); 69 | 70 | 71 | #ifdef _UNICODE 72 | #if defined _M_IX86 73 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 74 | #elif defined _M_X64 75 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 76 | #else 77 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 78 | #endif 79 | #endif 80 | 81 | 82 | -------------------------------------------------------------------------------- /TestDirectWrite/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | --------------------------------------------------------------------------------