| 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> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 *currentObject = nullptr; | 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 |
| 33 class CDwFontFileStream final : public IDWriteFontFileStream { | 34 class CDwFontFileStream final : public IDWriteFontFileStream { |
| 34 public: | 35 public: |
| 35 explicit CDwFontFileStream(void const* fontFileReferenceKey, | 36 explicit CDwFontFileStream(void const* fontFileReferenceKey, |
| 36 UINT32 fontFileReferenceKeySize); | 37 UINT32 fontFileReferenceKeySize); |
| 37 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, | 38 |
| 38 void** ppvObject); | 39 // IUnknown. |
| 39 virtual ULONG STDMETHODCALLTYPE AddRef(); | 40 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, |
| 40 virtual ULONG STDMETHODCALLTYPE Release(); | 41 void** ppvObject) override; |
| 41 virtual HRESULT STDMETHODCALLTYPE | 42 ULONG STDMETHODCALLTYPE AddRef() override; |
| 43 ULONG STDMETHODCALLTYPE Release() override; |
| 44 |
| 45 // IDWriteFontFileStream. |
| 46 HRESULT STDMETHODCALLTYPE |
| 42 ReadFileFragment(void const** fragmentStart, | 47 ReadFileFragment(void const** fragmentStart, |
| 43 UINT64 fileOffset, | 48 UINT64 fileOffset, |
| 44 UINT64 fragmentSize, | 49 UINT64 fragmentSize, |
| 45 OUT void** fragmentContext); | 50 OUT void** fragmentContext) override; |
| 46 virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext); | 51 void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext) override; |
| 47 virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize); | 52 HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize) override; |
| 48 virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime); | 53 HRESULT STDMETHODCALLTYPE |
| 54 GetLastWriteTime(OUT UINT64* lastWriteTime) override; |
| 55 |
| 49 bool IsInitialized() { return !!resourcePtr_; } | 56 bool IsInitialized() { return !!resourcePtr_; } |
| 50 | 57 |
| 51 private: | 58 private: |
| 52 ULONG refCount_; | 59 ULONG refCount_; |
| 53 void const* resourcePtr_; | 60 void const* resourcePtr_; |
| 54 DWORD resourceSize_; | 61 DWORD resourceSize_; |
| 55 }; | 62 }; |
| 63 |
| 56 class CDwFontFileLoader final : public IDWriteFontFileLoader { | 64 class CDwFontFileLoader final : public IDWriteFontFileLoader { |
| 57 public: | 65 public: |
| 58 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, | 66 // IUnknown. |
| 59 void** ppvObject); | 67 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, |
| 60 virtual ULONG STDMETHODCALLTYPE AddRef(); | 68 void** ppvObject) override; |
| 61 virtual ULONG STDMETHODCALLTYPE Release(); | 69 ULONG STDMETHODCALLTYPE AddRef() override; |
| 62 virtual HRESULT STDMETHODCALLTYPE | 70 ULONG STDMETHODCALLTYPE Release() override; |
| 71 |
| 72 // IDWriteFontFileLoader. |
| 73 HRESULT STDMETHODCALLTYPE |
| 63 CreateStreamFromKey(void const* fontFileReferenceKey, | 74 CreateStreamFromKey(void const* fontFileReferenceKey, |
| 64 UINT32 fontFileReferenceKeySize, | 75 UINT32 fontFileReferenceKeySize, |
| 65 OUT IDWriteFontFileStream** fontFileStream); | 76 OUT IDWriteFontFileStream** fontFileStream) override; |
| 66 | 77 |
| 67 static IDWriteFontFileLoader* GetLoader() { | 78 static IDWriteFontFileLoader* GetLoader() { |
| 68 if (!instance_) { | 79 if (!instance_) { |
| 69 instance_ = new CDwFontFileLoader(); | 80 instance_ = new CDwFontFileLoader(); |
| 70 } | 81 } |
| 71 return instance_; | 82 return instance_; |
| 72 } | 83 } |
| 73 static bool IsLoaderInitialized() { return !!instance_; } | 84 static bool IsLoaderInitialized() { return !!instance_; } |
| 74 | 85 |
| 75 private: | 86 private: |
| 76 CDwFontFileLoader(); | 87 CDwFontFileLoader(); |
| 77 ULONG refCount_; | 88 ULONG refCount_; |
| 78 static IDWriteFontFileLoader* instance_; | 89 static IDWriteFontFileLoader* instance_; |
| 79 }; | 90 }; |
| 91 |
| 80 class CDwFontContext { | 92 class CDwFontContext { |
| 81 public: | 93 public: |
| 82 CDwFontContext(IDWriteFactory* dwriteFactory); | 94 CDwFontContext(IDWriteFactory* dwriteFactory); |
| 83 ~CDwFontContext(); | 95 ~CDwFontContext(); |
| 96 |
| 84 HRESULT Initialize(); | 97 HRESULT Initialize(); |
| 85 | 98 |
| 86 private: | 99 private: |
| 87 CDwFontContext(CDwFontContext const&); | 100 CDwFontContext(CDwFontContext const&); |
| 88 void operator=(CDwFontContext const&); | 101 void operator=(CDwFontContext const&); |
| 89 HRESULT hr_; | 102 HRESULT hr_; |
| 90 IDWriteFactory* dwriteFactory_; | 103 IDWriteFactory* dwriteFactory_; |
| 91 }; | 104 }; |
| 105 |
| 92 class CDwGdiTextRenderer { | 106 class CDwGdiTextRenderer { |
| 93 public: | 107 public: |
| 94 CDwGdiTextRenderer(CFX_DIBitmap* pBitmap, | 108 CDwGdiTextRenderer(CFX_DIBitmap* pBitmap, |
| 95 IDWriteBitmapRenderTarget* bitmapRenderTarget, | 109 IDWriteBitmapRenderTarget* bitmapRenderTarget, |
| 96 IDWriteRenderingParams* renderingParams); | 110 IDWriteRenderingParams* renderingParams); |
| 97 ~CDwGdiTextRenderer(); | 111 ~CDwGdiTextRenderer(); |
| 112 |
| 98 HRESULT STDMETHODCALLTYPE DrawGlyphRun(const FX_RECT& text_bbox, | 113 HRESULT STDMETHODCALLTYPE DrawGlyphRun(const FX_RECT& text_bbox, |
| 99 __in_opt CFX_ClipRgn* pClipRgn, | 114 __in_opt CFX_ClipRgn* pClipRgn, |
| 100 __in_opt DWRITE_MATRIX const* pMatrix, | 115 __in_opt DWRITE_MATRIX const* pMatrix, |
| 101 FLOAT baselineOriginX, | 116 FLOAT baselineOriginX, |
| 102 FLOAT baselineOriginY, | 117 FLOAT baselineOriginY, |
| 103 DWRITE_MEASURING_MODE measuringMode, | 118 DWRITE_MEASURING_MODE measuringMode, |
| 104 __in DWRITE_GLYPH_RUN const* glyphRun, | 119 __in DWRITE_GLYPH_RUN const* glyphRun, |
| 105 const COLORREF& textColor); | 120 const COLORREF& textColor); |
| 106 | 121 |
| 107 private: | 122 private: |
| 108 CFX_DIBitmap* pBitmap_; | 123 CFX_DIBitmap* pBitmap_; |
| 109 IDWriteBitmapRenderTarget* pRenderTarget_; | 124 IDWriteBitmapRenderTarget* pRenderTarget_; |
| 110 IDWriteRenderingParams* pRenderingParams_; | 125 IDWriteRenderingParams* pRenderingParams_; |
| 111 }; | 126 }; |
| 112 CDWriteExt::CDWriteExt() { | 127 |
| 113 m_hModule = nullptr; | 128 CDWriteExt::CDWriteExt() |
| 114 m_pDWriteFactory = nullptr; | 129 : m_hModule(nullptr), |
| 115 m_pDwFontContext = nullptr; | 130 m_pDWriteFactory(nullptr), |
| 116 m_pDwTextRenderer = nullptr; | 131 m_pDwFontContext(nullptr), |
| 117 } | 132 m_pDwTextRenderer(nullptr) {} |
| 133 |
| 118 void CDWriteExt::Load() {} | 134 void CDWriteExt::Load() {} |
| 135 |
| 119 void CDWriteExt::Unload() { | 136 void CDWriteExt::Unload() { |
| 120 if (m_pDwFontContext) { | 137 if (m_pDwFontContext) { |
| 121 delete (CDwFontContext*)m_pDwFontContext; | 138 delete (CDwFontContext*)m_pDwFontContext; |
| 122 m_pDwFontContext = nullptr; | 139 m_pDwFontContext = nullptr; |
| 123 } | 140 } |
| 124 SafeRelease((IDWriteFactory**)&m_pDWriteFactory); | 141 SafeRelease((IDWriteFactory**)&m_pDWriteFactory); |
| 125 } | 142 } |
| 143 |
| 126 CDWriteExt::~CDWriteExt() { | 144 CDWriteExt::~CDWriteExt() { |
| 127 Unload(); | 145 Unload(); |
| 128 } | 146 } |
| 147 |
| 129 LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, | 148 LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, |
| 130 uint32_t size, | 149 uint32_t size, |
| 131 int simulation_style) { | 150 int simulation_style) { |
| 132 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; | 151 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; |
| 133 IDWriteFontFile* pDwFontFile = nullptr; | 152 IDWriteFontFile* pDwFontFile = nullptr; |
| 134 IDWriteFontFace* pDwFontFace = nullptr; | 153 IDWriteFontFace* pDwFontFace = nullptr; |
| 135 BOOL isSupportedFontType = FALSE; | 154 BOOL isSupportedFontType = FALSE; |
| 136 DWRITE_FONT_FILE_TYPE fontFileType; | 155 DWRITE_FONT_FILE_TYPE fontFileType; |
| 137 DWRITE_FONT_FACE_TYPE fontFaceType; | 156 DWRITE_FONT_FACE_TYPE fontFaceType; |
| 138 UINT32 numberOfFaces; | 157 UINT32 numberOfFaces; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 155 &pDwFontFace); | 174 &pDwFontFace); |
| 156 if (FAILED(hr)) { | 175 if (FAILED(hr)) { |
| 157 goto failed; | 176 goto failed; |
| 158 } | 177 } |
| 159 SafeRelease(&pDwFontFile); | 178 SafeRelease(&pDwFontFile); |
| 160 return pDwFontFace; | 179 return pDwFontFace; |
| 161 failed: | 180 failed: |
| 162 SafeRelease(&pDwFontFile); | 181 SafeRelease(&pDwFontFile); |
| 163 return nullptr; | 182 return nullptr; |
| 164 } | 183 } |
| 184 |
| 165 FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, | 185 FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, |
| 166 void** renderTarget) { | 186 void** renderTarget) { |
| 167 if (pBitmap->GetFormat() > FXDIB_Argb) { | 187 if (pBitmap->GetFormat() > FXDIB_Argb) { |
| 168 return FALSE; | 188 return FALSE; |
| 169 } | 189 } |
| 170 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; | 190 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; |
| 171 IDWriteGdiInterop* pGdiInterop = nullptr; | 191 IDWriteGdiInterop* pGdiInterop = nullptr; |
| 172 IDWriteBitmapRenderTarget* pBitmapRenderTarget = nullptr; | 192 IDWriteBitmapRenderTarget* pBitmapRenderTarget = nullptr; |
| 173 IDWriteRenderingParams* pRenderingParams = nullptr; | 193 IDWriteRenderingParams* pRenderingParams = nullptr; |
| 174 HRESULT hr = S_OK; | 194 HRESULT hr = S_OK; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 196 SafeRelease(&pGdiInterop); | 216 SafeRelease(&pGdiInterop); |
| 197 SafeRelease(&pBitmapRenderTarget); | 217 SafeRelease(&pBitmapRenderTarget); |
| 198 SafeRelease(&pRenderingParams); | 218 SafeRelease(&pRenderingParams); |
| 199 return TRUE; | 219 return TRUE; |
| 200 failed: | 220 failed: |
| 201 SafeRelease(&pGdiInterop); | 221 SafeRelease(&pGdiInterop); |
| 202 SafeRelease(&pBitmapRenderTarget); | 222 SafeRelease(&pBitmapRenderTarget); |
| 203 SafeRelease(&pRenderingParams); | 223 SafeRelease(&pRenderingParams); |
| 204 return FALSE; | 224 return FALSE; |
| 205 } | 225 } |
| 226 |
| 206 FX_BOOL CDWriteExt::DwRendingString(void* renderTarget, | 227 FX_BOOL CDWriteExt::DwRendingString(void* renderTarget, |
| 207 CFX_ClipRgn* pClipRgn, | 228 CFX_ClipRgn* pClipRgn, |
| 208 FX_RECT& stringRect, | 229 FX_RECT& stringRect, |
| 209 CFX_Matrix* pMatrix, | 230 CFX_Matrix* pMatrix, |
| 210 void* font, | 231 void* font, |
| 211 FX_FLOAT font_size, | 232 FX_FLOAT font_size, |
| 212 FX_ARGB text_color, | 233 FX_ARGB text_color, |
| 213 int glyph_count, | 234 int glyph_count, |
| 214 unsigned short* glyph_indices, | 235 unsigned short* glyph_indices, |
| 215 FX_FLOAT baselineOriginX, | 236 FX_FLOAT baselineOriginX, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 238 glyphRun.glyphAdvances = glyph_advances; | 259 glyphRun.glyphAdvances = glyph_advances; |
| 239 glyphRun.glyphOffsets = (DWRITE_GLYPH_OFFSET*)glyph_offsets; | 260 glyphRun.glyphOffsets = (DWRITE_GLYPH_OFFSET*)glyph_offsets; |
| 240 glyphRun.isSideways = FALSE; | 261 glyphRun.isSideways = FALSE; |
| 241 glyphRun.bidiLevel = 0; | 262 glyphRun.bidiLevel = 0; |
| 242 hr = pTextRenderer->DrawGlyphRun( | 263 hr = pTextRenderer->DrawGlyphRun( |
| 243 stringRect, pClipRgn, pMatrix ? &transform : nullptr, baselineOriginX, | 264 stringRect, pClipRgn, pMatrix ? &transform : nullptr, baselineOriginX, |
| 244 baselineOriginY, DWRITE_MEASURING_MODE_NATURAL, &glyphRun, | 265 baselineOriginY, DWRITE_MEASURING_MODE_NATURAL, &glyphRun, |
| 245 RGB(FXARGB_R(text_color), FXARGB_G(text_color), FXARGB_B(text_color))); | 266 RGB(FXARGB_R(text_color), FXARGB_G(text_color), FXARGB_B(text_color))); |
| 246 return SUCCEEDED(hr); | 267 return SUCCEEDED(hr); |
| 247 } | 268 } |
| 269 |
| 248 void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget) { | 270 void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget) { |
| 249 delete (CDwGdiTextRenderer*)renderTarget; | 271 delete (CDwGdiTextRenderer*)renderTarget; |
| 250 } | 272 } |
| 273 |
| 251 void CDWriteExt::DwDeleteFont(void* pFont) { | 274 void CDWriteExt::DwDeleteFont(void* pFont) { |
| 252 if (pFont) { | 275 if (pFont) { |
| 253 SafeRelease((IDWriteFontFace**)&pFont); | 276 SafeRelease((IDWriteFontFace**)&pFont); |
| 254 } | 277 } |
| 255 } | 278 } |
| 279 |
| 256 CDwFontFileStream::CDwFontFileStream(void const* fontFileReferenceKey, | 280 CDwFontFileStream::CDwFontFileStream(void const* fontFileReferenceKey, |
| 257 UINT32 fontFileReferenceKeySize) { | 281 UINT32 fontFileReferenceKeySize) { |
| 258 refCount_ = 0; | 282 refCount_ = 0; |
| 259 resourcePtr_ = fontFileReferenceKey; | 283 resourcePtr_ = fontFileReferenceKey; |
| 260 resourceSize_ = fontFileReferenceKeySize; | 284 resourceSize_ = fontFileReferenceKeySize; |
| 261 } | 285 } |
| 286 |
| 262 HRESULT STDMETHODCALLTYPE CDwFontFileStream::QueryInterface(REFIID iid, | 287 HRESULT STDMETHODCALLTYPE CDwFontFileStream::QueryInterface(REFIID iid, |
| 263 void** ppvObject) { | 288 void** ppvObject) { |
| 264 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) { | 289 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) { |
| 265 *ppvObject = this; | 290 *ppvObject = this; |
| 266 AddRef(); | 291 AddRef(); |
| 267 return S_OK; | 292 return S_OK; |
| 268 } | 293 } |
| 269 *ppvObject = nullptr; | 294 *ppvObject = nullptr; |
| 270 return E_NOINTERFACE; | 295 return E_NOINTERFACE; |
| 271 } | 296 } |
| 297 |
| 272 ULONG STDMETHODCALLTYPE CDwFontFileStream::AddRef() { | 298 ULONG STDMETHODCALLTYPE CDwFontFileStream::AddRef() { |
| 273 return InterlockedIncrement((long*)(&refCount_)); | 299 return InterlockedIncrement((long*)(&refCount_)); |
| 274 } | 300 } |
| 301 |
| 275 ULONG STDMETHODCALLTYPE CDwFontFileStream::Release() { | 302 ULONG STDMETHODCALLTYPE CDwFontFileStream::Release() { |
| 276 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); | 303 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); |
| 277 if (newCount == 0) { | 304 if (newCount == 0) { |
| 278 delete this; | 305 delete this; |
| 279 } | 306 } |
| 280 return newCount; | 307 return newCount; |
| 281 } | 308 } |
| 309 |
| 282 HRESULT STDMETHODCALLTYPE | 310 HRESULT STDMETHODCALLTYPE |
| 283 CDwFontFileStream::ReadFileFragment(void const** fragmentStart, | 311 CDwFontFileStream::ReadFileFragment(void const** fragmentStart, |
| 284 UINT64 fileOffset, | 312 UINT64 fileOffset, |
| 285 UINT64 fragmentSize, | 313 UINT64 fragmentSize, |
| 286 OUT void** fragmentContext) { | 314 OUT void** fragmentContext) { |
| 287 if (fileOffset <= resourceSize_ && | 315 if (fileOffset <= resourceSize_ && |
| 288 fragmentSize <= resourceSize_ - fileOffset) { | 316 fragmentSize <= resourceSize_ - fileOffset) { |
| 289 *fragmentStart = static_cast<uint8_t const*>(resourcePtr_) + | 317 *fragmentStart = static_cast<uint8_t const*>(resourcePtr_) + |
| 290 static_cast<size_t>(fileOffset); | 318 static_cast<size_t>(fileOffset); |
| 291 *fragmentContext = nullptr; | 319 *fragmentContext = nullptr; |
| 292 return S_OK; | 320 return S_OK; |
| 293 } | 321 } |
| 294 *fragmentStart = nullptr; | 322 *fragmentStart = nullptr; |
| 295 *fragmentContext = nullptr; | 323 *fragmentContext = nullptr; |
| 296 return E_FAIL; | 324 return E_FAIL; |
| 297 } | 325 } |
| 326 |
| 298 void STDMETHODCALLTYPE | 327 void STDMETHODCALLTYPE |
| 299 CDwFontFileStream::ReleaseFileFragment(void* fragmentContext) {} | 328 CDwFontFileStream::ReleaseFileFragment(void* fragmentContext) {} |
| 300 HRESULT STDMETHODCALLTYPE CDwFontFileStream::GetFileSize(OUT UINT64* fileSize) { | 329 HRESULT STDMETHODCALLTYPE CDwFontFileStream::GetFileSize(OUT UINT64* fileSize) { |
| 301 *fileSize = resourceSize_; | 330 *fileSize = resourceSize_; |
| 302 return S_OK; | 331 return S_OK; |
| 303 } | 332 } |
| 333 |
| 304 HRESULT STDMETHODCALLTYPE | 334 HRESULT STDMETHODCALLTYPE |
| 305 CDwFontFileStream::GetLastWriteTime(OUT UINT64* lastWriteTime) { | 335 CDwFontFileStream::GetLastWriteTime(OUT UINT64* lastWriteTime) { |
| 306 *lastWriteTime = 0; | 336 *lastWriteTime = 0; |
| 307 return E_NOTIMPL; | 337 return E_NOTIMPL; |
| 308 } | 338 } |
| 339 |
| 309 IDWriteFontFileLoader* CDwFontFileLoader::instance_ = nullptr; | 340 IDWriteFontFileLoader* CDwFontFileLoader::instance_ = nullptr; |
| 310 CDwFontFileLoader::CDwFontFileLoader() : refCount_(0) {} | 341 CDwFontFileLoader::CDwFontFileLoader() : refCount_(0) {} |
| 311 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::QueryInterface(REFIID iid, | 342 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::QueryInterface(REFIID iid, |
| 312 void** ppvObject) { | 343 void** ppvObject) { |
| 313 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { | 344 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { |
| 314 *ppvObject = this; | 345 *ppvObject = this; |
| 315 AddRef(); | 346 AddRef(); |
| 316 return S_OK; | 347 return S_OK; |
| 317 } | 348 } |
| 318 *ppvObject = nullptr; | 349 *ppvObject = nullptr; |
| 319 return E_NOINTERFACE; | 350 return E_NOINTERFACE; |
| 320 } | 351 } |
| 352 |
| 321 ULONG STDMETHODCALLTYPE CDwFontFileLoader::AddRef() { | 353 ULONG STDMETHODCALLTYPE CDwFontFileLoader::AddRef() { |
| 322 return InterlockedIncrement((long*)(&refCount_)); | 354 return InterlockedIncrement((long*)(&refCount_)); |
| 323 } | 355 } |
| 356 |
| 324 ULONG STDMETHODCALLTYPE CDwFontFileLoader::Release() { | 357 ULONG STDMETHODCALLTYPE CDwFontFileLoader::Release() { |
| 325 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); | 358 ULONG newCount = InterlockedDecrement((long*)(&refCount_)); |
| 326 if (newCount == 0) { | 359 if (newCount == 0) { |
| 327 instance_ = nullptr; | 360 instance_ = nullptr; |
| 328 delete this; | 361 delete this; |
| 329 } | 362 } |
| 330 return newCount; | 363 return newCount; |
| 331 } | 364 } |
| 365 |
| 332 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::CreateStreamFromKey( | 366 HRESULT STDMETHODCALLTYPE CDwFontFileLoader::CreateStreamFromKey( |
| 333 void const* fontFileReferenceKey, | 367 void const* fontFileReferenceKey, |
| 334 UINT32 fontFileReferenceKeySize, | 368 UINT32 fontFileReferenceKeySize, |
| 335 OUT IDWriteFontFileStream** fontFileStream) { | 369 OUT IDWriteFontFileStream** fontFileStream) { |
| 336 *fontFileStream = nullptr; | 370 *fontFileStream = nullptr; |
| 337 CDwFontFileStream* stream = | 371 CDwFontFileStream* stream = |
| 338 new CDwFontFileStream(fontFileReferenceKey, fontFileReferenceKeySize); | 372 new CDwFontFileStream(fontFileReferenceKey, fontFileReferenceKeySize); |
| 339 if (!stream->IsInitialized()) { | 373 if (!stream->IsInitialized()) { |
| 340 delete stream; | 374 delete stream; |
| 341 return E_FAIL; | 375 return E_FAIL; |
| 342 } | 376 } |
| 343 *fontFileStream = SafeAcquire(stream); | 377 *fontFileStream = SafeAcquire(stream); |
| 344 return S_OK; | 378 return S_OK; |
| 345 } | 379 } |
| 380 |
| 346 CDwFontContext::CDwFontContext(IDWriteFactory* dwriteFactory) | 381 CDwFontContext::CDwFontContext(IDWriteFactory* dwriteFactory) |
| 347 : hr_(S_FALSE), dwriteFactory_(SafeAcquire(dwriteFactory)) {} | 382 : hr_(S_FALSE), dwriteFactory_(SafeAcquire(dwriteFactory)) {} |
| 383 |
| 348 CDwFontContext::~CDwFontContext() { | 384 CDwFontContext::~CDwFontContext() { |
| 349 if (dwriteFactory_ && hr_ == S_OK) { | 385 if (dwriteFactory_ && hr_ == S_OK) { |
| 350 dwriteFactory_->UnregisterFontFileLoader(CDwFontFileLoader::GetLoader()); | 386 dwriteFactory_->UnregisterFontFileLoader(CDwFontFileLoader::GetLoader()); |
| 351 } | 387 } |
| 352 SafeRelease(&dwriteFactory_); | 388 SafeRelease(&dwriteFactory_); |
| 353 } | 389 } |
| 390 |
| 354 HRESULT CDwFontContext::Initialize() { | 391 HRESULT CDwFontContext::Initialize() { |
| 355 if (hr_ == S_FALSE) { | 392 if (hr_ == S_FALSE) { |
| 356 return hr_ = dwriteFactory_->RegisterFontFileLoader( | 393 return hr_ = dwriteFactory_->RegisterFontFileLoader( |
| 357 CDwFontFileLoader::GetLoader()); | 394 CDwFontFileLoader::GetLoader()); |
| 358 } | 395 } |
| 359 return hr_; | 396 return hr_; |
| 360 } | 397 } |
| 398 |
| 361 CDwGdiTextRenderer::CDwGdiTextRenderer( | 399 CDwGdiTextRenderer::CDwGdiTextRenderer( |
| 362 CFX_DIBitmap* pBitmap, | 400 CFX_DIBitmap* pBitmap, |
| 363 IDWriteBitmapRenderTarget* bitmapRenderTarget, | 401 IDWriteBitmapRenderTarget* bitmapRenderTarget, |
| 364 IDWriteRenderingParams* renderingParams) | 402 IDWriteRenderingParams* renderingParams) |
| 365 : pBitmap_(pBitmap), | 403 : pBitmap_(pBitmap), |
| 366 pRenderTarget_(SafeAcquire(bitmapRenderTarget)), | 404 pRenderTarget_(SafeAcquire(bitmapRenderTarget)), |
| 367 pRenderingParams_(SafeAcquire(renderingParams)) {} | 405 pRenderingParams_(SafeAcquire(renderingParams)) {} |
| 368 CDwGdiTextRenderer::~CDwGdiTextRenderer() { | 406 CDwGdiTextRenderer::~CDwGdiTextRenderer() { |
| 369 SafeRelease(&pRenderTarget_); | 407 SafeRelease(&pRenderTarget_); |
| 370 SafeRelease(&pRenderingParams_); | 408 SafeRelease(&pRenderingParams_); |
| 371 } | 409 } |
| 410 |
| 372 STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun( | 411 STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun( |
| 373 const FX_RECT& text_bbox, | 412 const FX_RECT& text_bbox, |
| 374 __in_opt CFX_ClipRgn* pClipRgn, | 413 __in_opt CFX_ClipRgn* pClipRgn, |
| 375 __in_opt DWRITE_MATRIX const* pMatrix, | 414 __in_opt DWRITE_MATRIX const* pMatrix, |
| 376 FLOAT baselineOriginX, | 415 FLOAT baselineOriginX, |
| 377 FLOAT baselineOriginY, | 416 FLOAT baselineOriginY, |
| 378 DWRITE_MEASURING_MODE measuringMode, | 417 DWRITE_MEASURING_MODE measuringMode, |
| 379 __in DWRITE_GLYPH_RUN const* glyphRun, | 418 __in DWRITE_GLYPH_RUN const* glyphRun, |
| 380 const COLORREF& textColor) { | 419 const COLORREF& textColor) { |
| 381 HRESULT hr = S_OK; | 420 HRESULT hr = S_OK; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 401 textColor); | 440 textColor); |
| 402 if (FAILED(hr)) { | 441 if (FAILED(hr)) { |
| 403 return hr; | 442 return hr; |
| 404 } | 443 } |
| 405 pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), | 444 pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), |
| 406 text_bbox.Height(), &dib, text_bbox.left, | 445 text_bbox.Height(), &dib, text_bbox.left, |
| 407 text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn); | 446 text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn); |
| 408 return hr; | 447 return hr; |
| 409 } | 448 } |
| 410 #endif | 449 #endif |
| OLD | NEW |