OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxge/include/fx_ge.h" | 7 #include "core/fxge/include/fx_ge.h" |
8 | 8 |
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ | 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ |
10 #include <dwrite.h> | 10 #include <dwrite.h> |
11 | 11 |
12 #include "core/fxge/include/fx_ge_win32.h" | 12 #include "core/fxge/include/fx_ge_win32.h" |
13 #include "core/fxge/win32/dwrite_int.h" | 13 #include "core/fxge/win32/dwrite_int.h" |
14 | 14 |
15 typedef HRESULT(__stdcall* FuncType_DWriteCreateFactory)( | 15 typedef HRESULT(__stdcall* FuncType_DWriteCreateFactory)( |
16 __in DWRITE_FACTORY_TYPE, | 16 __in DWRITE_FACTORY_TYPE, |
17 __in REFIID, | 17 __in REFIID, |
18 __out IUnknown**); | 18 __out IUnknown**); |
19 template <typename InterfaceType> | 19 template <typename InterfaceType> |
20 inline void SafeRelease(InterfaceType** currentObject) { | 20 inline void SafeRelease(InterfaceType** currentObject) { |
21 if (*currentObject) { | 21 if (*currentObject) { |
22 (*currentObject)->Release(); | 22 (*currentObject)->Release(); |
23 *currentObject = NULL; | 23 *currentObject = nullptr; |
24 } | 24 } |
25 } | 25 } |
26 template <typename InterfaceType> | 26 template <typename InterfaceType> |
27 inline InterfaceType* SafeAcquire(InterfaceType* newObject) { | 27 inline InterfaceType* SafeAcquire(InterfaceType* newObject) { |
28 if (newObject) { | 28 if (newObject) { |
29 newObject->AddRef(); | 29 newObject->AddRef(); |
30 } | 30 } |
31 return newObject; | 31 return newObject; |
32 } | 32 } |
33 class CDwFontFileStream final : public IDWriteFontFileStream { | 33 class CDwFontFileStream final : public IDWriteFontFileStream { |
34 public: | 34 public: |
35 explicit CDwFontFileStream(void const* fontFileReferenceKey, | 35 explicit CDwFontFileStream(void const* fontFileReferenceKey, |
36 UINT32 fontFileReferenceKeySize); | 36 UINT32 fontFileReferenceKeySize); |
37 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, | 37 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, |
38 void** ppvObject); | 38 void** ppvObject); |
39 virtual ULONG STDMETHODCALLTYPE AddRef(); | 39 virtual ULONG STDMETHODCALLTYPE AddRef(); |
40 virtual ULONG STDMETHODCALLTYPE Release(); | 40 virtual ULONG STDMETHODCALLTYPE Release(); |
41 virtual HRESULT STDMETHODCALLTYPE | 41 virtual HRESULT STDMETHODCALLTYPE |
42 ReadFileFragment(void const** fragmentStart, | 42 ReadFileFragment(void const** fragmentStart, |
43 UINT64 fileOffset, | 43 UINT64 fileOffset, |
44 UINT64 fragmentSize, | 44 UINT64 fragmentSize, |
45 OUT void** fragmentContext); | 45 OUT void** fragmentContext); |
46 virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext); | 46 virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext); |
47 virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize); | 47 virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize); |
48 virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime); | 48 virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime); |
49 bool IsInitialized() { return resourcePtr_ != NULL; } | 49 bool IsInitialized() { return !!resourcePtr_; } |
50 | 50 |
51 private: | 51 private: |
52 ULONG refCount_; | 52 ULONG refCount_; |
53 void const* resourcePtr_; | 53 void const* resourcePtr_; |
54 DWORD resourceSize_; | 54 DWORD resourceSize_; |
55 }; | 55 }; |
56 class CDwFontFileLoader final : public IDWriteFontFileLoader { | 56 class CDwFontFileLoader final : public IDWriteFontFileLoader { |
57 public: | 57 public: |
58 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, | 58 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, |
59 void** ppvObject); | 59 void** ppvObject); |
60 virtual ULONG STDMETHODCALLTYPE AddRef(); | 60 virtual ULONG STDMETHODCALLTYPE AddRef(); |
61 virtual ULONG STDMETHODCALLTYPE Release(); | 61 virtual ULONG STDMETHODCALLTYPE Release(); |
62 virtual HRESULT STDMETHODCALLTYPE | 62 virtual HRESULT STDMETHODCALLTYPE |
63 CreateStreamFromKey(void const* fontFileReferenceKey, | 63 CreateStreamFromKey(void const* fontFileReferenceKey, |
64 UINT32 fontFileReferenceKeySize, | 64 UINT32 fontFileReferenceKeySize, |
65 OUT IDWriteFontFileStream** fontFileStream); | 65 OUT IDWriteFontFileStream** fontFileStream); |
66 | 66 |
67 static IDWriteFontFileLoader* GetLoader() { | 67 static IDWriteFontFileLoader* GetLoader() { |
68 if (!instance_) { | 68 if (!instance_) { |
69 instance_ = new CDwFontFileLoader(); | 69 instance_ = new CDwFontFileLoader(); |
70 } | 70 } |
71 return instance_; | 71 return instance_; |
72 } | 72 } |
73 static bool IsLoaderInitialized() { return instance_ != NULL; } | 73 static bool IsLoaderInitialized() { return !!instance_; } |
74 | 74 |
75 private: | 75 private: |
76 CDwFontFileLoader(); | 76 CDwFontFileLoader(); |
77 ULONG refCount_; | 77 ULONG refCount_; |
78 static IDWriteFontFileLoader* instance_; | 78 static IDWriteFontFileLoader* instance_; |
79 }; | 79 }; |
80 class CDwFontContext { | 80 class CDwFontContext { |
81 public: | 81 public: |
82 CDwFontContext(IDWriteFactory* dwriteFactory); | 82 CDwFontContext(IDWriteFactory* dwriteFactory); |
83 ~CDwFontContext(); | 83 ~CDwFontContext(); |
(...skipping 19 matching lines...) Expand all Loading... |
103 DWRITE_MEASURING_MODE measuringMode, | 103 DWRITE_MEASURING_MODE measuringMode, |
104 __in DWRITE_GLYPH_RUN const* glyphRun, | 104 __in DWRITE_GLYPH_RUN const* glyphRun, |
105 const COLORREF& textColor); | 105 const COLORREF& textColor); |
106 | 106 |
107 private: | 107 private: |
108 CFX_DIBitmap* pBitmap_; | 108 CFX_DIBitmap* pBitmap_; |
109 IDWriteBitmapRenderTarget* pRenderTarget_; | 109 IDWriteBitmapRenderTarget* pRenderTarget_; |
110 IDWriteRenderingParams* pRenderingParams_; | 110 IDWriteRenderingParams* pRenderingParams_; |
111 }; | 111 }; |
112 CDWriteExt::CDWriteExt() { | 112 CDWriteExt::CDWriteExt() { |
113 m_hModule = NULL; | 113 m_hModule = nullptr; |
114 m_pDWriteFactory = NULL; | 114 m_pDWriteFactory = nullptr; |
115 m_pDwFontContext = NULL; | 115 m_pDwFontContext = nullptr; |
116 m_pDwTextRenderer = NULL; | 116 m_pDwTextRenderer = nullptr; |
117 } | 117 } |
118 void CDWriteExt::Load() {} | 118 void CDWriteExt::Load() {} |
119 void CDWriteExt::Unload() { | 119 void CDWriteExt::Unload() { |
120 if (m_pDwFontContext) { | 120 if (m_pDwFontContext) { |
121 delete (CDwFontContext*)m_pDwFontContext; | 121 delete (CDwFontContext*)m_pDwFontContext; |
122 m_pDwFontContext = NULL; | 122 m_pDwFontContext = nullptr; |
123 } | 123 } |
124 SafeRelease((IDWriteFactory**)&m_pDWriteFactory); | 124 SafeRelease((IDWriteFactory**)&m_pDWriteFactory); |
125 } | 125 } |
126 CDWriteExt::~CDWriteExt() { | 126 CDWriteExt::~CDWriteExt() { |
127 Unload(); | 127 Unload(); |
128 } | 128 } |
129 LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, | 129 LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, |
130 uint32_t size, | 130 uint32_t size, |
131 int simulation_style) { | 131 int simulation_style) { |
132 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; | 132 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; |
133 IDWriteFontFile* pDwFontFile = NULL; | 133 IDWriteFontFile* pDwFontFile = nullptr; |
134 IDWriteFontFace* pDwFontFace = NULL; | 134 IDWriteFontFace* pDwFontFace = nullptr; |
135 BOOL isSupportedFontType = FALSE; | 135 BOOL isSupportedFontType = FALSE; |
136 DWRITE_FONT_FILE_TYPE fontFileType; | 136 DWRITE_FONT_FILE_TYPE fontFileType; |
137 DWRITE_FONT_FACE_TYPE fontFaceType; | 137 DWRITE_FONT_FACE_TYPE fontFaceType; |
138 UINT32 numberOfFaces; | 138 UINT32 numberOfFaces; |
139 DWRITE_FONT_SIMULATIONS fontStyle = | 139 DWRITE_FONT_SIMULATIONS fontStyle = |
140 (DWRITE_FONT_SIMULATIONS)(simulation_style & 3); | 140 (DWRITE_FONT_SIMULATIONS)(simulation_style & 3); |
141 HRESULT hr = S_OK; | 141 HRESULT hr = S_OK; |
142 hr = pDwFactory->CreateCustomFontFileReference( | 142 hr = pDwFactory->CreateCustomFontFileReference( |
143 (void const*)pData, (UINT32)size, CDwFontFileLoader::GetLoader(), | 143 (void const*)pData, (UINT32)size, CDwFontFileLoader::GetLoader(), |
144 &pDwFontFile); | 144 &pDwFontFile); |
145 if (FAILED(hr)) { | 145 if (FAILED(hr)) { |
146 goto failed; | 146 goto failed; |
147 } | 147 } |
148 hr = pDwFontFile->Analyze(&isSupportedFontType, &fontFileType, &fontFaceType, | 148 hr = pDwFontFile->Analyze(&isSupportedFontType, &fontFileType, &fontFaceType, |
149 &numberOfFaces); | 149 &numberOfFaces); |
150 if (FAILED(hr) || !isSupportedFontType || | 150 if (FAILED(hr) || !isSupportedFontType || |
151 fontFaceType == DWRITE_FONT_FACE_TYPE_UNKNOWN) { | 151 fontFaceType == DWRITE_FONT_FACE_TYPE_UNKNOWN) { |
152 goto failed; | 152 goto failed; |
153 } | 153 } |
154 hr = pDwFactory->CreateFontFace(fontFaceType, 1, &pDwFontFile, 0, fontStyle, | 154 hr = pDwFactory->CreateFontFace(fontFaceType, 1, &pDwFontFile, 0, fontStyle, |
155 &pDwFontFace); | 155 &pDwFontFace); |
156 if (FAILED(hr)) { | 156 if (FAILED(hr)) { |
157 goto failed; | 157 goto failed; |
158 } | 158 } |
159 SafeRelease(&pDwFontFile); | 159 SafeRelease(&pDwFontFile); |
160 return pDwFontFace; | 160 return pDwFontFace; |
161 failed: | 161 failed: |
162 SafeRelease(&pDwFontFile); | 162 SafeRelease(&pDwFontFile); |
163 return NULL; | 163 return nullptr; |
164 } | 164 } |
165 FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, | 165 FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, |
166 void** renderTarget) { | 166 void** renderTarget) { |
167 if (pBitmap->GetFormat() > FXDIB_Argb) { | 167 if (pBitmap->GetFormat() > FXDIB_Argb) { |
168 return FALSE; | 168 return FALSE; |
169 } | 169 } |
170 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; | 170 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; |
171 IDWriteGdiInterop* pGdiInterop = NULL; | 171 IDWriteGdiInterop* pGdiInterop = nullptr; |
172 IDWriteBitmapRenderTarget* pBitmapRenderTarget = NULL; | 172 IDWriteBitmapRenderTarget* pBitmapRenderTarget = nullptr; |
173 IDWriteRenderingParams* pRenderingParams = NULL; | 173 IDWriteRenderingParams* pRenderingParams = nullptr; |
174 HRESULT hr = S_OK; | 174 HRESULT hr = S_OK; |
175 hr = pDwFactory->GetGdiInterop(&pGdiInterop); | 175 hr = pDwFactory->GetGdiInterop(&pGdiInterop); |
176 if (FAILED(hr)) { | 176 if (FAILED(hr)) { |
177 goto failed; | 177 goto failed; |
178 } | 178 } |
179 hr = pGdiInterop->CreateBitmapRenderTarget( | 179 hr = pGdiInterop->CreateBitmapRenderTarget( |
180 NULL, pBitmap->GetWidth(), pBitmap->GetHeight(), &pBitmapRenderTarget); | 180 nullptr, pBitmap->GetWidth(), pBitmap->GetHeight(), &pBitmapRenderTarget); |
181 if (FAILED(hr)) { | 181 if (FAILED(hr)) { |
182 goto failed; | 182 goto failed; |
183 } | 183 } |
184 hr = pDwFactory->CreateCustomRenderingParams( | 184 hr = pDwFactory->CreateCustomRenderingParams( |
185 1.0f, 0.0f, 1.0f, DWRITE_PIXEL_GEOMETRY_RGB, | 185 1.0f, 0.0f, 1.0f, DWRITE_PIXEL_GEOMETRY_RGB, |
186 DWRITE_RENDERING_MODE_DEFAULT, &pRenderingParams); | 186 DWRITE_RENDERING_MODE_DEFAULT, &pRenderingParams); |
187 if (FAILED(hr)) { | 187 if (FAILED(hr)) { |
188 goto failed; | 188 goto failed; |
189 } | 189 } |
190 hr = pBitmapRenderTarget->SetPixelsPerDip(1.0f); | 190 hr = pBitmapRenderTarget->SetPixelsPerDip(1.0f); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 glyphRun.fontFace = (IDWriteFontFace*)font; | 234 glyphRun.fontFace = (IDWriteFontFace*)font; |
235 glyphRun.fontEmSize = font_size; | 235 glyphRun.fontEmSize = font_size; |
236 glyphRun.glyphCount = glyph_count; | 236 glyphRun.glyphCount = glyph_count; |
237 glyphRun.glyphIndices = glyph_indices; | 237 glyphRun.glyphIndices = glyph_indices; |
238 glyphRun.glyphAdvances = glyph_advances; | 238 glyphRun.glyphAdvances = glyph_advances; |
239 glyphRun.glyphOffsets = (DWRITE_GLYPH_OFFSET*)glyph_offsets; | 239 glyphRun.glyphOffsets = (DWRITE_GLYPH_OFFSET*)glyph_offsets; |
240 glyphRun.isSideways = FALSE; | 240 glyphRun.isSideways = FALSE; |
241 glyphRun.bidiLevel = 0; | 241 glyphRun.bidiLevel = 0; |
242 hr = pTextRenderer->DrawGlyphRun( | 242 hr = pTextRenderer->DrawGlyphRun( |
243 stringRect, pClipRgn, pMatrix ? &transform : NULL, baselineOriginX, | 243 stringRect, pClipRgn, pMatrix ? &transform : nullptr, baselineOriginX, |
244 baselineOriginY, DWRITE_MEASURING_MODE_NATURAL, &glyphRun, | 244 baselineOriginY, DWRITE_MEASURING_MODE_NATURAL, &glyphRun, |
245 RGB(FXARGB_R(text_color), FXARGB_G(text_color), FXARGB_B(text_color))); | 245 RGB(FXARGB_R(text_color), FXARGB_G(text_color), FXARGB_B(text_color))); |
246 return SUCCEEDED(hr); | 246 return SUCCEEDED(hr); |
247 } | 247 } |
248 void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget) { | 248 void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget) { |
249 delete (CDwGdiTextRenderer*)renderTarget; | 249 delete (CDwGdiTextRenderer*)renderTarget; |
250 } | 250 } |
251 void CDWriteExt::DwDeleteFont(void* pFont) { | 251 void CDWriteExt::DwDeleteFont(void* pFont) { |
252 if (pFont) { | 252 if (pFont) { |
253 SafeRelease((IDWriteFontFace**)&pFont); | 253 SafeRelease((IDWriteFontFace**)&pFont); |
254 } | 254 } |
255 } | 255 } |
256 CDwFontFileStream::CDwFontFileStream(void const* fontFileReferenceKey, | 256 CDwFontFileStream::CDwFontFileStream(void const* fontFileReferenceKey, |
257 UINT32 fontFileReferenceKeySize) { | 257 UINT32 fontFileReferenceKeySize) { |
258 refCount_ = 0; | 258 refCount_ = 0; |
259 resourcePtr_ = fontFileReferenceKey; | 259 resourcePtr_ = fontFileReferenceKey; |
260 resourceSize_ = fontFileReferenceKeySize; | 260 resourceSize_ = fontFileReferenceKeySize; |
261 } | 261 } |
262 HRESULT STDMETHODCALLTYPE CDwFontFileStream::QueryInterface(REFIID iid, | 262 HRESULT STDMETHODCALLTYPE CDwFontFileStream::QueryInterface(REFIID iid, |
263 void** ppvObject) { | 263 void** ppvObject) { |
264 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) { | 264 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) { |
265 *ppvObject = this; | 265 *ppvObject = this; |
266 AddRef(); | 266 AddRef(); |
267 return S_OK; | 267 return S_OK; |
268 } | 268 } |
269 *ppvObject = NULL; | 269 *ppvObject = nullptr; |
270 return E_NOINTERFACE; | 270 return E_NOINTERFACE; |
271 } | 271 } |
272 ULONG STDMETHODCALLTYPE CDwFontFileStream::AddRef() { | 272 ULONG STDMETHODCALLTYPE CDwFontFileStream::AddRef() { |
273 return InterlockedIncrement((long*)(&refCount_)); | 273 return InterlockedIncrement((long*)(&refCount_)); |
274 } | 274 } |
275 ULONG STDMETHODCALLTYPE CDwFontFileStream::Release() { | 275 ULONG STDMETHODCALLTYPE CDwFontFileStream::Release() { |
276 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); | 276 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); |
277 if (newCount == 0) { | 277 if (newCount == 0) { |
278 delete this; | 278 delete this; |
279 } | 279 } |
280 return newCount; | 280 return newCount; |
281 } | 281 } |
282 HRESULT STDMETHODCALLTYPE | 282 HRESULT STDMETHODCALLTYPE |
283 CDwFontFileStream::ReadFileFragment(void const** fragmentStart, | 283 CDwFontFileStream::ReadFileFragment(void const** fragmentStart, |
284 UINT64 fileOffset, | 284 UINT64 fileOffset, |
285 UINT64 fragmentSize, | 285 UINT64 fragmentSize, |
286 OUT void** fragmentContext) { | 286 OUT void** fragmentContext) { |
287 if (fileOffset <= resourceSize_ && | 287 if (fileOffset <= resourceSize_ && |
288 fragmentSize <= resourceSize_ - fileOffset) { | 288 fragmentSize <= resourceSize_ - fileOffset) { |
289 *fragmentStart = static_cast<uint8_t const*>(resourcePtr_) + | 289 *fragmentStart = static_cast<uint8_t const*>(resourcePtr_) + |
290 static_cast<size_t>(fileOffset); | 290 static_cast<size_t>(fileOffset); |
291 *fragmentContext = NULL; | 291 *fragmentContext = nullptr; |
292 return S_OK; | 292 return S_OK; |
293 } | 293 } |
294 *fragmentStart = NULL; | 294 *fragmentStart = nullptr; |
295 *fragmentContext = NULL; | 295 *fragmentContext = nullptr; |
296 return E_FAIL; | 296 return E_FAIL; |
297 } | 297 } |
298 void STDMETHODCALLTYPE | 298 void STDMETHODCALLTYPE |
299 CDwFontFileStream::ReleaseFileFragment(void* fragmentContext) {} | 299 CDwFontFileStream::ReleaseFileFragment(void* fragmentContext) {} |
300 HRESULT STDMETHODCALLTYPE CDwFontFileStream::GetFileSize(OUT UINT64* fileSize) { | 300 HRESULT STDMETHODCALLTYPE CDwFontFileStream::GetFileSize(OUT UINT64* fileSize) { |
301 *fileSize = resourceSize_; | 301 *fileSize = resourceSize_; |
302 return S_OK; | 302 return S_OK; |
303 } | 303 } |
304 HRESULT STDMETHODCALLTYPE | 304 HRESULT STDMETHODCALLTYPE |
305 CDwFontFileStream::GetLastWriteTime(OUT UINT64* lastWriteTime) { | 305 CDwFontFileStream::GetLastWriteTime(OUT UINT64* lastWriteTime) { |
306 *lastWriteTime = 0; | 306 *lastWriteTime = 0; |
307 return E_NOTIMPL; | 307 return E_NOTIMPL; |
308 } | 308 } |
309 IDWriteFontFileLoader* CDwFontFileLoader::instance_ = NULL; | 309 IDWriteFontFileLoader* CDwFontFileLoader::instance_ = nullptr; |
310 CDwFontFileLoader::CDwFontFileLoader() : refCount_(0) {} | 310 CDwFontFileLoader::CDwFontFileLoader() : refCount_(0) {} |
311 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::QueryInterface(REFIID iid, | 311 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::QueryInterface(REFIID iid, |
312 void** ppvObject) { | 312 void** ppvObject) { |
313 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { | 313 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { |
314 *ppvObject = this; | 314 *ppvObject = this; |
315 AddRef(); | 315 AddRef(); |
316 return S_OK; | 316 return S_OK; |
317 } | 317 } |
318 *ppvObject = NULL; | 318 *ppvObject = nullptr; |
319 return E_NOINTERFACE; | 319 return E_NOINTERFACE; |
320 } | 320 } |
321 ULONG STDMETHODCALLTYPE CDwFontFileLoader::AddRef() { | 321 ULONG STDMETHODCALLTYPE CDwFontFileLoader::AddRef() { |
322 return InterlockedIncrement((long*)(&refCount_)); | 322 return InterlockedIncrement((long*)(&refCount_)); |
323 } | 323 } |
324 ULONG STDMETHODCALLTYPE CDwFontFileLoader::Release() { | 324 ULONG STDMETHODCALLTYPE CDwFontFileLoader::Release() { |
325 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); | 325 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); |
326 if (newCount == 0) { | 326 if (newCount == 0) { |
327 instance_ = NULL; | 327 instance_ = nullptr; |
328 delete this; | 328 delete this; |
329 } | 329 } |
330 return newCount; | 330 return newCount; |
331 } | 331 } |
332 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::CreateStreamFromKey( | 332 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::CreateStreamFromKey( |
333 void const* fontFileReferenceKey, | 333 void const* fontFileReferenceKey, |
334 UINT32 fontFileReferenceKeySize, | 334 UINT32 fontFileReferenceKeySize, |
335 OUT IDWriteFontFileStream** fontFileStream) { | 335 OUT IDWriteFontFileStream** fontFileStream) { |
336 *fontFileStream = NULL; | 336 *fontFileStream = nullptr; |
337 CDwFontFileStream* stream = | 337 CDwFontFileStream* stream = |
338 new CDwFontFileStream(fontFileReferenceKey, fontFileReferenceKeySize); | 338 new CDwFontFileStream(fontFileReferenceKey, fontFileReferenceKeySize); |
339 if (!stream->IsInitialized()) { | 339 if (!stream->IsInitialized()) { |
340 delete stream; | 340 delete stream; |
341 return E_FAIL; | 341 return E_FAIL; |
342 } | 342 } |
343 *fontFileStream = SafeAcquire(stream); | 343 *fontFileStream = SafeAcquire(stream); |
344 return S_OK; | 344 return S_OK; |
345 } | 345 } |
346 CDwFontContext::CDwFontContext(IDWriteFactory* dwriteFactory) | 346 CDwFontContext::CDwFontContext(IDWriteFactory* dwriteFactory) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 HDC hDC = pRenderTarget_->GetMemoryDC(); | 388 HDC hDC = pRenderTarget_->GetMemoryDC(); |
389 HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP); | 389 HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP); |
390 BITMAP bitmap; | 390 BITMAP bitmap; |
391 GetObject(hBitmap, sizeof bitmap, &bitmap); | 391 GetObject(hBitmap, sizeof bitmap, &bitmap); |
392 CFX_DIBitmap dib; | 392 CFX_DIBitmap dib; |
393 dib.Create(bitmap.bmWidth, bitmap.bmHeight, | 393 dib.Create(bitmap.bmWidth, bitmap.bmHeight, |
394 bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32, | 394 bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32, |
395 (uint8_t*)bitmap.bmBits); | 395 (uint8_t*)bitmap.bmBits); |
396 dib.CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), | 396 dib.CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), |
397 text_bbox.Height(), pBitmap_, text_bbox.left, | 397 text_bbox.Height(), pBitmap_, text_bbox.left, |
398 text_bbox.top, FXDIB_BLEND_NORMAL, NULL); | 398 text_bbox.top, FXDIB_BLEND_NORMAL, nullptr); |
399 hr = pRenderTarget_->DrawGlyphRun(baselineOriginX, baselineOriginY, | 399 hr = pRenderTarget_->DrawGlyphRun(baselineOriginX, baselineOriginY, |
400 measuringMode, glyphRun, pRenderingParams_, | 400 measuringMode, glyphRun, pRenderingParams_, |
401 textColor); | 401 textColor); |
402 if (FAILED(hr)) { | 402 if (FAILED(hr)) { |
403 return hr; | 403 return hr; |
404 } | 404 } |
405 pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), | 405 pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), |
406 text_bbox.Height(), &dib, text_bbox.left, | 406 text_bbox.Height(), &dib, text_bbox.left, |
407 text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn); | 407 text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn); |
408 return hr; | 408 return hr; |
409 } | 409 } |
410 #endif | 410 #endif |
OLD | NEW |