Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: src/ports/SkScalerContext_win_dw.cpp

Issue 511783003: Fix error handling in DirectWrite with tiny text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clarify code flow, guard against backward RECTs. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkScalerContext_win_dw.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkTypes.h" 8 #include "SkTypes.h"
9 #undef GetGlyphIndices 9 #undef GetGlyphIndices
10 10
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 vecs[0].fX = SkScalarRoundToScalar(advanceX); 391 vecs[0].fX = SkScalarRoundToScalar(advanceX);
392 fG_inv.mapVectors(vecs, SK_ARRAY_COUNT(vecs)); 392 fG_inv.mapVectors(vecs, SK_ARRAY_COUNT(vecs));
393 } else { 393 } else {
394 fSkXform.mapVectors(vecs, SK_ARRAY_COUNT(vecs)); 394 fSkXform.mapVectors(vecs, SK_ARRAY_COUNT(vecs));
395 } 395 }
396 396
397 glyph->fAdvanceX = SkScalarToFixed(vecs[0].fX); 397 glyph->fAdvanceX = SkScalarToFixed(vecs[0].fX);
398 glyph->fAdvanceY = SkScalarToFixed(vecs[0].fY); 398 glyph->fAdvanceY = SkScalarToFixed(vecs[0].fY);
399 } 399 }
400 400
401 void SkScalerContext_DW::getBoundingBox(SkGlyph* glyph, 401 HRESULT SkScalerContext_DW::getBoundingBox(SkGlyph* glyph,
402 DWRITE_RENDERING_MODE renderingMode, 402 DWRITE_RENDERING_MODE renderingMode,
403 DWRITE_TEXTURE_TYPE textureType, 403 DWRITE_TEXTURE_TYPE textureType,
404 RECT* bbox) 404 RECT* bbox)
405 { 405 {
406 //Measure raster size. 406 //Measure raster size.
407 fXform.dx = SkFixedToFloat(glyph->getSubXFixed()); 407 fXform.dx = SkFixedToFloat(glyph->getSubXFixed());
408 fXform.dy = SkFixedToFloat(glyph->getSubYFixed()); 408 fXform.dy = SkFixedToFloat(glyph->getSubYFixed());
409 409
410 FLOAT advance = 0; 410 FLOAT advance = 0;
411 411
412 UINT16 glyphId = glyph->getGlyphID(); 412 UINT16 glyphId = glyph->getGlyphID();
413 413
414 DWRITE_GLYPH_OFFSET offset; 414 DWRITE_GLYPH_OFFSET offset;
415 offset.advanceOffset = 0.0f; 415 offset.advanceOffset = 0.0f;
416 offset.ascenderOffset = 0.0f; 416 offset.ascenderOffset = 0.0f;
417 417
418 DWRITE_GLYPH_RUN run; 418 DWRITE_GLYPH_RUN run;
419 run.glyphCount = 1; 419 run.glyphCount = 1;
420 run.glyphAdvances = &advance; 420 run.glyphAdvances = &advance;
421 run.fontFace = fTypeface->fDWriteFontFace.get(); 421 run.fontFace = fTypeface->fDWriteFontFace.get();
422 run.fontEmSize = SkScalarToFloat(fTextSizeRender); 422 run.fontEmSize = SkScalarToFloat(fTextSizeRender);
423 run.bidiLevel = 0; 423 run.bidiLevel = 0;
424 run.glyphIndices = &glyphId; 424 run.glyphIndices = &glyphId;
425 run.isSideways = FALSE; 425 run.isSideways = FALSE;
426 run.glyphOffsets = &offset; 426 run.glyphOffsets = &offset;
427 427
428 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; 428 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
429 HRVM(fTypeface->fFactory->CreateGlyphRunAnalysis( 429 HRM(fTypeface->fFactory->CreateGlyphRunAnalysis(
430 &run, 430 &run,
431 1.0f, // pixelsPerDip, 431 1.0f, // pixelsPerDip,
432 &fXform, 432 &fXform,
433 renderingMode, 433 renderingMode,
434 fMeasuringMode, 434 fMeasuringMode,
435 0.0f, // baselineOriginX, 435 0.0f, // baselineOriginX,
436 0.0f, // baselineOriginY, 436 0.0f, // baselineOriginY,
437 &glyphRunAnalysis), 437 &glyphRunAnalysis),
438 "Could not create glyph run analysis."); 438 "Could not create glyph run analysis.");
439 439
440 HRVM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, bbox), 440 HRM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, bbox),
441 "Could not get texture bounds."); 441 "Could not get texture bounds.");
442
443 return S_OK;
444 }
445
446 /** GetAlphaTextureBounds succeeds but sometimes returns empty bounds like
447 * { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }
448 * for small, but not quite zero, sized glyphs.
449 * Only set as non-empty if the returned bounds are non-empty.
450 */
451 static bool glyph_check_and_set_bounds(SkGlyph* glyph, const RECT& bbox) {
452 if (bbox.left >= bbox.right || bbox.top >= bbox.bottom) {
453 return false;
454 }
455 glyph->fWidth = SkToU16(bbox.right - bbox.left);
456 glyph->fHeight = SkToU16(bbox.bottom - bbox.top);
457 glyph->fLeft = SkToS16(bbox.left);
458 glyph->fTop = SkToS16(bbox.top);
459 return true;
442 } 460 }
443 461
444 void SkScalerContext_DW::generateMetrics(SkGlyph* glyph) { 462 void SkScalerContext_DW::generateMetrics(SkGlyph* glyph) {
445 glyph->fWidth = 0; 463 glyph->fWidth = 0;
464 glyph->fHeight = 0;
465 glyph->fLeft = 0;
466 glyph->fTop = 0;
446 467
447 this->generateAdvance(glyph); 468 this->generateAdvance(glyph);
448 469
449 RECT bbox; 470 RECT bbox;
450 this->getBoundingBox(glyph, fRenderingMode, fTextureType, &bbox); 471 HRVM(this->getBoundingBox(glyph, fRenderingMode, fTextureType, &bbox),
472 "Requested bounding box could not be determined.");
473
474 if (glyph_check_and_set_bounds(glyph, bbox)) {
475 return;
476 }
451 477
452 // GetAlphaTextureBounds succeeds but returns an empty RECT if there are no 478 // GetAlphaTextureBounds succeeds but returns an empty RECT if there are no
453 // glyphs of the specified texture type. When this happens, try with the 479 // glyphs of the specified texture type. When this happens, try with the
454 // alternate texture type. 480 // alternate texture type.
455 if (bbox.left == bbox.right || bbox.top == bbox.bottom) { 481 if (DWRITE_TEXTURE_CLEARTYPE_3x1 == fTextureType) {
456 if (DWRITE_TEXTURE_CLEARTYPE_3x1 == fTextureType) { 482 HRVM(this->getBoundingBox(glyph,
457 this->getBoundingBox(glyph, 483 DWRITE_RENDERING_MODE_ALIASED,
458 DWRITE_RENDERING_MODE_ALIASED, 484 DWRITE_TEXTURE_ALIASED_1x1,
459 DWRITE_TEXTURE_ALIASED_1x1, 485 &bbox),
460 &bbox); 486 "Fallback bounding box could not be determined.");
461 if (bbox.left != bbox.right && bbox.top != bbox.bottom) { 487 if (glyph_check_and_set_bounds(glyph, bbox)) {
462 glyph->fForceBW = 1; 488 glyph->fForceBW = 1;
463 }
464 } 489 }
465 // TODO: handle the case where a request for DWRITE_TEXTURE_ALIASED_1x1
466 // fails, and try DWRITE_TEXTURE_CLEARTYPE_3x1.
467 } 490 }
468 491 // TODO: handle the case where a request for DWRITE_TEXTURE_ALIASED_1x1
469 glyph->fWidth = SkToU16(bbox.right - bbox.left); 492 // fails, and try DWRITE_TEXTURE_CLEARTYPE_3x1.
470 glyph->fHeight = SkToU16(bbox.bottom - bbox.top);
471 glyph->fLeft = SkToS16(bbox.left);
472 glyph->fTop = SkToS16(bbox.top);
473 } 493 }
474 494
475 void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) { 495 void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) {
476 if (NULL == metrics) { 496 if (NULL == metrics) {
477 return; 497 return;
478 } 498 }
479 499
480 sk_bzero(metrics, sizeof(*metrics)); 500 sk_bzero(metrics, sizeof(*metrics));
481 501
482 DWRITE_FONT_METRICS dwfm; 502 DWRITE_FONT_METRICS dwfm;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 NULL, //advances 766 NULL, //advances
747 NULL, //offsets 767 NULL, //offsets
748 1, //num glyphs 768 1, //num glyphs
749 FALSE, //sideways 769 FALSE, //sideways
750 FALSE, //rtl 770 FALSE, //rtl
751 geometryToPath.get()), 771 geometryToPath.get()),
752 "Could not create glyph outline."); 772 "Could not create glyph outline.");
753 773
754 path->transform(fSkXform); 774 path->transform(fSkXform);
755 } 775 }
OLDNEW
« no previous file with comments | « src/ports/SkScalerContext_win_dw.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698