| 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 <dwrite.h> | 7 #include <dwrite.h> |
| 8 | 8 |
| 9 #include "core/fxcrt/fx_system.h" | 9 #include "core/fxcrt/fx_system.h" |
| 10 #include "core/fxge/ge/cfx_cliprgn.h" | 10 #include "core/fxge/ge/cfx_cliprgn.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 CDWriteExt::~CDWriteExt() { | 142 CDWriteExt::~CDWriteExt() { |
| 143 Unload(); | 143 Unload(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, | 146 LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, |
| 147 uint32_t size, | 147 uint32_t size, |
| 148 int simulation_style) { | 148 int simulation_style) { |
| 149 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; | 149 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; |
| 150 IDWriteFontFile* pDwFontFile = nullptr; | 150 IDWriteFontFile* pDwFontFile = nullptr; |
| 151 IDWriteFontFace* pDwFontFace = nullptr; | 151 IDWriteFontFace* pDwFontFace = nullptr; |
| 152 BOOL isSupportedFontType = FALSE; | 152 BOOL isSupportedFontType = false; |
| 153 DWRITE_FONT_FILE_TYPE fontFileType; | 153 DWRITE_FONT_FILE_TYPE fontFileType; |
| 154 DWRITE_FONT_FACE_TYPE fontFaceType; | 154 DWRITE_FONT_FACE_TYPE fontFaceType; |
| 155 UINT32 numberOfFaces; | 155 UINT32 numberOfFaces; |
| 156 DWRITE_FONT_SIMULATIONS fontStyle = | 156 DWRITE_FONT_SIMULATIONS fontStyle = |
| 157 (DWRITE_FONT_SIMULATIONS)(simulation_style & 3); | 157 (DWRITE_FONT_SIMULATIONS)(simulation_style & 3); |
| 158 HRESULT hr = S_OK; | 158 HRESULT hr = S_OK; |
| 159 hr = pDwFactory->CreateCustomFontFileReference( | 159 hr = pDwFactory->CreateCustomFontFileReference( |
| 160 (void const*)pData, (UINT32)size, CDwFontFileLoader::GetLoader(), | 160 (void const*)pData, (UINT32)size, CDwFontFileLoader::GetLoader(), |
| 161 &pDwFontFile); | 161 &pDwFontFile); |
| 162 if (FAILED(hr)) { | 162 if (FAILED(hr)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 173 if (FAILED(hr)) { | 173 if (FAILED(hr)) { |
| 174 goto failed; | 174 goto failed; |
| 175 } | 175 } |
| 176 SafeRelease(&pDwFontFile); | 176 SafeRelease(&pDwFontFile); |
| 177 return pDwFontFace; | 177 return pDwFontFace; |
| 178 failed: | 178 failed: |
| 179 SafeRelease(&pDwFontFile); | 179 SafeRelease(&pDwFontFile); |
| 180 return nullptr; | 180 return nullptr; |
| 181 } | 181 } |
| 182 | 182 |
| 183 FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, | 183 bool CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, |
| 184 void** renderTarget) { | 184 void** renderTarget) { |
| 185 if (pBitmap->GetFormat() > FXDIB_Argb) { | 185 if (pBitmap->GetFormat() > FXDIB_Argb) { |
| 186 return FALSE; | 186 return false; |
| 187 } | 187 } |
| 188 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; | 188 IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory; |
| 189 IDWriteGdiInterop* pGdiInterop = nullptr; | 189 IDWriteGdiInterop* pGdiInterop = nullptr; |
| 190 IDWriteBitmapRenderTarget* pBitmapRenderTarget = nullptr; | 190 IDWriteBitmapRenderTarget* pBitmapRenderTarget = nullptr; |
| 191 IDWriteRenderingParams* pRenderingParams = nullptr; | 191 IDWriteRenderingParams* pRenderingParams = nullptr; |
| 192 HRESULT hr = S_OK; | 192 HRESULT hr = S_OK; |
| 193 hr = pDwFactory->GetGdiInterop(&pGdiInterop); | 193 hr = pDwFactory->GetGdiInterop(&pGdiInterop); |
| 194 if (FAILED(hr)) { | 194 if (FAILED(hr)) { |
| 195 goto failed; | 195 goto failed; |
| 196 } | 196 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 207 } | 207 } |
| 208 hr = pBitmapRenderTarget->SetPixelsPerDip(1.0f); | 208 hr = pBitmapRenderTarget->SetPixelsPerDip(1.0f); |
| 209 if (FAILED(hr)) { | 209 if (FAILED(hr)) { |
| 210 goto failed; | 210 goto failed; |
| 211 } | 211 } |
| 212 *(CDwGdiTextRenderer**)renderTarget = | 212 *(CDwGdiTextRenderer**)renderTarget = |
| 213 new CDwGdiTextRenderer(pBitmap, pBitmapRenderTarget, pRenderingParams); | 213 new CDwGdiTextRenderer(pBitmap, pBitmapRenderTarget, pRenderingParams); |
| 214 SafeRelease(&pGdiInterop); | 214 SafeRelease(&pGdiInterop); |
| 215 SafeRelease(&pBitmapRenderTarget); | 215 SafeRelease(&pBitmapRenderTarget); |
| 216 SafeRelease(&pRenderingParams); | 216 SafeRelease(&pRenderingParams); |
| 217 return TRUE; | 217 return true; |
| 218 failed: | 218 failed: |
| 219 SafeRelease(&pGdiInterop); | 219 SafeRelease(&pGdiInterop); |
| 220 SafeRelease(&pBitmapRenderTarget); | 220 SafeRelease(&pBitmapRenderTarget); |
| 221 SafeRelease(&pRenderingParams); | 221 SafeRelease(&pRenderingParams); |
| 222 return FALSE; | 222 return false; |
| 223 } | 223 } |
| 224 | 224 |
| 225 FX_BOOL CDWriteExt::DwRendingString(void* renderTarget, | 225 bool CDWriteExt::DwRendingString(void* renderTarget, |
| 226 CFX_ClipRgn* pClipRgn, | 226 CFX_ClipRgn* pClipRgn, |
| 227 FX_RECT& stringRect, | 227 FX_RECT& stringRect, |
| 228 CFX_Matrix* pMatrix, | 228 CFX_Matrix* pMatrix, |
| 229 void* font, | 229 void* font, |
| 230 FX_FLOAT font_size, | 230 FX_FLOAT font_size, |
| 231 FX_ARGB text_color, | 231 FX_ARGB text_color, |
| 232 int glyph_count, | 232 int glyph_count, |
| 233 unsigned short* glyph_indices, | 233 unsigned short* glyph_indices, |
| 234 FX_FLOAT baselineOriginX, | 234 FX_FLOAT baselineOriginX, |
| 235 FX_FLOAT baselineOriginY, | 235 FX_FLOAT baselineOriginY, |
| 236 void* glyph_offsets, | 236 void* glyph_offsets, |
| 237 FX_FLOAT* glyph_advances) { | 237 FX_FLOAT* glyph_advances) { |
| 238 if (!renderTarget) { | 238 if (!renderTarget) { |
| 239 return TRUE; | 239 return true; |
| 240 } | 240 } |
| 241 CDwGdiTextRenderer* pTextRenderer = (CDwGdiTextRenderer*)renderTarget; | 241 CDwGdiTextRenderer* pTextRenderer = (CDwGdiTextRenderer*)renderTarget; |
| 242 DWRITE_MATRIX transform; | 242 DWRITE_MATRIX transform; |
| 243 DWRITE_GLYPH_RUN glyphRun; | 243 DWRITE_GLYPH_RUN glyphRun; |
| 244 HRESULT hr = S_OK; | 244 HRESULT hr = S_OK; |
| 245 if (pMatrix) { | 245 if (pMatrix) { |
| 246 transform.m11 = pMatrix->a; | 246 transform.m11 = pMatrix->a; |
| 247 transform.m12 = pMatrix->b; | 247 transform.m12 = pMatrix->b; |
| 248 transform.m21 = pMatrix->c; | 248 transform.m21 = pMatrix->c; |
| 249 transform.m22 = pMatrix->d; | 249 transform.m22 = pMatrix->d; |
| 250 transform.dx = pMatrix->e; | 250 transform.dx = pMatrix->e; |
| 251 transform.dy = pMatrix->f; | 251 transform.dy = pMatrix->f; |
| 252 } | 252 } |
| 253 glyphRun.fontFace = (IDWriteFontFace*)font; | 253 glyphRun.fontFace = (IDWriteFontFace*)font; |
| 254 glyphRun.fontEmSize = font_size; | 254 glyphRun.fontEmSize = font_size; |
| 255 glyphRun.glyphCount = glyph_count; | 255 glyphRun.glyphCount = glyph_count; |
| 256 glyphRun.glyphIndices = glyph_indices; | 256 glyphRun.glyphIndices = glyph_indices; |
| 257 glyphRun.glyphAdvances = glyph_advances; | 257 glyphRun.glyphAdvances = glyph_advances; |
| 258 glyphRun.glyphOffsets = (DWRITE_GLYPH_OFFSET*)glyph_offsets; | 258 glyphRun.glyphOffsets = (DWRITE_GLYPH_OFFSET*)glyph_offsets; |
| 259 glyphRun.isSideways = FALSE; | 259 glyphRun.isSideways = false; |
| 260 glyphRun.bidiLevel = 0; | 260 glyphRun.bidiLevel = 0; |
| 261 hr = pTextRenderer->DrawGlyphRun( | 261 hr = pTextRenderer->DrawGlyphRun( |
| 262 stringRect, pClipRgn, pMatrix ? &transform : nullptr, baselineOriginX, | 262 stringRect, pClipRgn, pMatrix ? &transform : nullptr, baselineOriginX, |
| 263 baselineOriginY, DWRITE_MEASURING_MODE_NATURAL, &glyphRun, | 263 baselineOriginY, DWRITE_MEASURING_MODE_NATURAL, &glyphRun, |
| 264 RGB(FXARGB_R(text_color), FXARGB_G(text_color), FXARGB_B(text_color))); | 264 RGB(FXARGB_R(text_color), FXARGB_G(text_color), FXARGB_B(text_color))); |
| 265 return SUCCEEDED(hr); | 265 return SUCCEEDED(hr); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget) { | 268 void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget) { |
| 269 delete (CDwGdiTextRenderer*)renderTarget; | 269 delete (CDwGdiTextRenderer*)renderTarget; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 measuringMode, glyphRun, pRenderingParams_, | 437 measuringMode, glyphRun, pRenderingParams_, |
| 438 textColor); | 438 textColor); |
| 439 if (FAILED(hr)) { | 439 if (FAILED(hr)) { |
| 440 return hr; | 440 return hr; |
| 441 } | 441 } |
| 442 pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), | 442 pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), |
| 443 text_bbox.Height(), &dib, text_bbox.left, | 443 text_bbox.Height(), &dib, text_bbox.left, |
| 444 text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn); | 444 text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn); |
| 445 return hr; | 445 return hr; |
| 446 } | 446 } |
| OLD | NEW |