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

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

Issue 412993002: Get additional DW font metrics when available. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Always assert QueryInterface worked. Created 6 years, 5 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 | « no previous file | src/ports/SkTypeface_win_dw.h » ('j') | 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
11 #include "SkDWrite.h" 11 #include "SkDWrite.h"
12 #include "SkDWriteGeometrySink.h" 12 #include "SkDWriteGeometrySink.h"
13 #include "SkEndian.h" 13 #include "SkEndian.h"
14 #include "SkGlyph.h" 14 #include "SkGlyph.h"
15 #include "SkHRESULT.h" 15 #include "SkHRESULT.h"
16 #include "SkMaskGamma.h" 16 #include "SkMaskGamma.h"
17 #include "SkMatrix22.h" 17 #include "SkMatrix22.h"
18 #include "SkOTTable_EBLC.h" 18 #include "SkOTTable_EBLC.h"
19 #include "SkOTTable_EBSC.h" 19 #include "SkOTTable_EBSC.h"
20 #include "SkOTTable_gasp.h" 20 #include "SkOTTable_gasp.h"
21 #include "SkOTTable_maxp.h" 21 #include "SkOTTable_maxp.h"
22 #include "SkPath.h" 22 #include "SkPath.h"
23 #include "SkScalerContext.h" 23 #include "SkScalerContext.h"
24 #include "SkScalerContext_win_dw.h" 24 #include "SkScalerContext_win_dw.h"
25 #include "SkTScopedComPtr.h" 25 #include "SkTScopedComPtr.h"
26 #include "SkTypeface_win_dw.h" 26 #include "SkTypeface_win_dw.h"
27 27
28 #include <dwrite.h> 28 #include <dwrite.h>
29 #include <dwrite_1.h>
29 30
30 static bool isLCD(const SkScalerContext::Rec& rec) { 31 static bool isLCD(const SkScalerContext::Rec& rec) {
31 return SkMask::kLCD16_Format == rec.fMaskFormat || 32 return SkMask::kLCD16_Format == rec.fMaskFormat ||
32 SkMask::kLCD32_Format == rec.fMaskFormat; 33 SkMask::kLCD32_Format == rec.fMaskFormat;
33 } 34 }
34 35
35 static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) { 36 static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) {
36 AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get ()); 37 AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get ());
37 if (!maxp.fExists) { 38 if (!maxp.fExists) {
38 return false; 39 return false;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 "Could not get texture bounds."); 442 "Could not get texture bounds.");
442 443
443 glyph->fWidth = SkToU16(bbox.right - bbox.left); 444 glyph->fWidth = SkToU16(bbox.right - bbox.left);
444 glyph->fHeight = SkToU16(bbox.bottom - bbox.top); 445 glyph->fHeight = SkToU16(bbox.bottom - bbox.top);
445 glyph->fLeft = SkToS16(bbox.left); 446 glyph->fLeft = SkToS16(bbox.left);
446 glyph->fTop = SkToS16(bbox.top); 447 glyph->fTop = SkToS16(bbox.top);
447 } 448 }
448 449
449 void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) { 450 void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) {
450 if (NULL == metrics) { 451 if (NULL == metrics) {
451 return; 452 return;
452 } 453 }
453 454
454 sk_bzero(metrics, sizeof(*metrics)); 455 sk_bzero(metrics, sizeof(*metrics));
455 456
456 DWRITE_FONT_METRICS dwfm; 457 DWRITE_FONT_METRICS dwfm;
457 if (DWRITE_MEASURING_MODE_GDI_CLASSIC == fMeasuringMode || 458 if (DWRITE_MEASURING_MODE_GDI_CLASSIC == fMeasuringMode ||
458 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode) 459 DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode)
459 { 460 {
460 fTypeface->fDWriteFontFace->GetGdiCompatibleMetrics( 461 fTypeface->fDWriteFontFace->GetGdiCompatibleMetrics(
461 fTextSizeRender, 462 fTextSizeRender,
462 1.0f, // pixelsPerDip 463 1.0f, // pixelsPerDip
463 &fXform, 464 &fXform,
464 &dwfm); 465 &dwfm);
465 } else { 466 } else {
466 fTypeface->fDWriteFontFace->GetMetrics(&dwfm); 467 fTypeface->fDWriteFontFace->GetMetrics(&dwfm);
467 } 468 }
468 469
469 SkScalar upem = SkIntToScalar(dwfm.designUnitsPerEm); 470 SkScalar upem = SkIntToScalar(dwfm.designUnitsPerEm);
470 471
471 metrics->fTop = -fTextSizeRender * SkIntToScalar(dwfm.ascent) / upem; 472 metrics->fAscent = -fTextSizeRender * SkIntToScalar(dwfm.ascent) / upem;
472 metrics->fAscent = metrics->fTop;
473 metrics->fDescent = fTextSizeRender * SkIntToScalar(dwfm.descent) / upem; 473 metrics->fDescent = fTextSizeRender * SkIntToScalar(dwfm.descent) / upem;
474 metrics->fBottom = metrics->fDescent;
475 metrics->fLeading = fTextSizeRender * SkIntToScalar(dwfm.lineGap) / upem; 474 metrics->fLeading = fTextSizeRender * SkIntToScalar(dwfm.lineGap) / upem;
476 metrics->fXHeight = fTextSizeRender * SkIntToScalar(dwfm.xHeight) / upem; 475 metrics->fXHeight = fTextSizeRender * SkIntToScalar(dwfm.xHeight) / upem;
477 metrics->fUnderlineThickness = fTextSizeRender * SkIntToScalar(dwfm.underlin eThickness) / upem; 476 metrics->fUnderlineThickness = fTextSizeRender * SkIntToScalar(dwfm.underlin eThickness) / upem;
478 metrics->fUnderlinePosition = -(fTextSizeRender * SkIntToScalar(dwfm.underli nePosition) / upem); 477 metrics->fUnderlinePosition = -(fTextSizeRender * SkIntToScalar(dwfm.underli nePosition) / upem);
479 478
480 metrics->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag; 479 metrics->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag;
481 metrics->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag; 480 metrics->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
481
482 if (NULL != fTypeface->fDWriteFontFace1.get()) {
483 DWRITE_FONT_METRICS1 dwfm1;
484 fTypeface->fDWriteFontFace1->GetMetrics(&dwfm1);
485 metrics->fTop = -fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxTop) / up em;
486 metrics->fBottom = -fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxBottom ) / upem;
487 metrics->fXMin = fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxLeft) / u pem;
488 metrics->fXMax = fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxRight) / upem;
489
490 metrics->fMaxCharWidth = metrics->fXMax - metrics->fXMin;
491 } else {
492 AutoTDWriteTable<SkOTTableHead> head(fTypeface->fDWriteFontFace.get());
493 if (head.fExists &&
494 head.fSize >= sizeof(SkOTTableHead) &&
495 head->version == SkOTTableHead::version1)
496 {
497 metrics->fTop = -fTextSizeRender * (int16_t)SkEndian_SwapBE16(head-> yMax) / upem;
498 metrics->fBottom = -fTextSizeRender * (int16_t)SkEndian_SwapBE16(hea d->yMin) / upem;
499 metrics->fXMin = fTextSizeRender * (int16_t)SkEndian_SwapBE16(head-> xMin) / upem;
500 metrics->fXMax = fTextSizeRender * (int16_t)SkEndian_SwapBE16(head-> xMax) / upem;
501
502 metrics->fMaxCharWidth = metrics->fXMax - metrics->fXMin;
503 } else {
504 metrics->fTop = metrics->fAscent;
505 metrics->fBottom = metrics->fDescent;
506 }
507 }
482 } 508 }
483 509
484 /////////////////////////////////////////////////////////////////////////////// 510 ///////////////////////////////////////////////////////////////////////////////
485 511
486 #include "SkColorPriv.h" 512 #include "SkColorPriv.h"
487 513
488 static void bilevel_to_bw(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph) { 514 static void bilevel_to_bw(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph) {
489 const int width = glyph.fWidth; 515 const int width = glyph.fWidth;
490 const size_t dstRB = (width + 7) >> 3; 516 const size_t dstRB = (width + 7) >> 3;
491 uint8_t* SK_RESTRICT dst = static_cast<uint8_t*>(glyph.fImage); 517 uint8_t* SK_RESTRICT dst = static_cast<uint8_t*>(glyph.fImage);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 NULL, //advances 712 NULL, //advances
687 NULL, //offsets 713 NULL, //offsets
688 1, //num glyphs 714 1, //num glyphs
689 FALSE, //sideways 715 FALSE, //sideways
690 FALSE, //rtl 716 FALSE, //rtl
691 geometryToPath.get()), 717 geometryToPath.get()),
692 "Could not create glyph outline."); 718 "Could not create glyph outline.");
693 719
694 path->transform(fSkXform); 720 path->transform(fSkXform);
695 } 721 }
OLDNEW
« no previous file with comments | « no previous file | src/ports/SkTypeface_win_dw.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698