Chromium Code Reviews| Index: src/ports/SkScalerContext_win_dw.cpp |
| diff --git a/src/ports/SkScalerContext_win_dw.cpp b/src/ports/SkScalerContext_win_dw.cpp |
| index 216c7dce2c25dfbbcc4f88aaa83fd2c6444c71a3..ae264563c7bf6ce1b7cf6111da38aed62f7bfb99 100644 |
| --- a/src/ports/SkScalerContext_win_dw.cpp |
| +++ b/src/ports/SkScalerContext_win_dw.cpp |
| @@ -398,10 +398,10 @@ void SkScalerContext_DW::generateAdvance(SkGlyph* glyph) { |
| glyph->fAdvanceY = SkScalarToFixed(vecs[0].fY); |
| } |
| -void SkScalerContext_DW::getBoundingBox(SkGlyph* glyph, |
| - DWRITE_RENDERING_MODE renderingMode, |
| - DWRITE_TEXTURE_TYPE textureType, |
| - RECT* bbox) |
| +HRESULT SkScalerContext_DW::getBoundingBox(SkGlyph* glyph, |
| + DWRITE_RENDERING_MODE renderingMode, |
| + DWRITE_TEXTURE_TYPE textureType, |
| + RECT* bbox) |
| { |
| //Measure raster size. |
| fXform.dx = SkFixedToFloat(glyph->getSubXFixed()); |
| @@ -426,19 +426,21 @@ void SkScalerContext_DW::getBoundingBox(SkGlyph* glyph, |
| run.glyphOffsets = &offset; |
| SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; |
| - HRVM(fTypeface->fFactory->CreateGlyphRunAnalysis( |
| - &run, |
| - 1.0f, // pixelsPerDip, |
| - &fXform, |
| - renderingMode, |
| - fMeasuringMode, |
| - 0.0f, // baselineOriginX, |
| - 0.0f, // baselineOriginY, |
| - &glyphRunAnalysis), |
| - "Could not create glyph run analysis."); |
| - |
| - HRVM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, bbox), |
| - "Could not get texture bounds."); |
| + HRM(fTypeface->fFactory->CreateGlyphRunAnalysis( |
| + &run, |
| + 1.0f, // pixelsPerDip, |
| + &fXform, |
| + renderingMode, |
| + fMeasuringMode, |
| + 0.0f, // baselineOriginX, |
| + 0.0f, // baselineOriginY, |
| + &glyphRunAnalysis), |
| + "Could not create glyph run analysis."); |
| + |
| + HRM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, bbox), |
| + "Could not get texture bounds."); |
| + |
| + return S_OK; |
| } |
| void SkScalerContext_DW::generateMetrics(SkGlyph* glyph) { |
| @@ -447,17 +449,19 @@ void SkScalerContext_DW::generateMetrics(SkGlyph* glyph) { |
| this->generateAdvance(glyph); |
| RECT bbox; |
| - this->getBoundingBox(glyph, fRenderingMode, fTextureType, &bbox); |
| + HRVM(this->getBoundingBox(glyph, fRenderingMode, fTextureType, &bbox), |
| + "Requested bounding box could not be determined."); |
| // GetAlphaTextureBounds succeeds but returns an empty RECT if there are no |
| // glyphs of the specified texture type. When this happens, try with the |
| // alternate texture type. |
| if (bbox.left == bbox.right || bbox.top == bbox.bottom) { |
| if (DWRITE_TEXTURE_CLEARTYPE_3x1 == fTextureType) { |
| - this->getBoundingBox(glyph, |
| - DWRITE_RENDERING_MODE_ALIASED, |
| - DWRITE_TEXTURE_ALIASED_1x1, |
| - &bbox); |
| + HRVM(this->getBoundingBox(glyph, |
| + DWRITE_RENDERING_MODE_ALIASED, |
| + DWRITE_TEXTURE_ALIASED_1x1, |
| + &bbox), |
| + "Fallback bounding box could not be determined."); |
| if (bbox.left != bbox.right && bbox.top != bbox.bottom) { |
| glyph->fForceBW = 1; |
| } |
| @@ -466,10 +470,21 @@ void SkScalerContext_DW::generateMetrics(SkGlyph* glyph) { |
| // fails, and try DWRITE_TEXTURE_CLEARTYPE_3x1. |
| } |
| - glyph->fWidth = SkToU16(bbox.right - bbox.left); |
| - glyph->fHeight = SkToU16(bbox.bottom - bbox.top); |
| - glyph->fLeft = SkToS16(bbox.left); |
| - glyph->fTop = SkToS16(bbox.top); |
| + // GetAlphaTextureBounds succeeds but return bounds like |
| + // { 0x80000000, 0x80000000, 0x80000000, 0x80000000 } |
| + // for small, but not quite zero, sized glyphs. |
| + // Normalize all empty rects to 0, 0, 0, 0. |
| + if (bbox.left == bbox.right || bbox.top == bbox.bottom) { |
|
mtklein
2014/08/28 17:25:49
== -> >= for both, and above?
bungeman-skia
2014/08/28 18:01:04
Done.
|
| + glyph->fWidth = 0; |
| + glyph->fHeight = 0; |
| + glyph->fLeft = 0; |
| + glyph->fTop = 0; |
| + } else { |
| + glyph->fWidth = SkToU16(bbox.right - bbox.left); |
| + glyph->fHeight = SkToU16(bbox.bottom - bbox.top); |
| + glyph->fLeft = SkToS16(bbox.left); |
| + glyph->fTop = SkToS16(bbox.top); |
| + } |
| } |
| void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) { |