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

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

Issue 1955053002: SkAdvancedTypefaceMetrics: getAdvanceData uses std::function (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: typedef Created 4 years, 7 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/core/SkAdvancedTypefaceMetrics.cpp ('k') | src/ports/SkFontHost_mac.cpp » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkAdvancedTypefaceMetrics.h" 8 #include "SkAdvancedTypefaceMetrics.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) { 425 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) {
426 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter); 426 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter);
427 if (!glyph_id) 427 if (!glyph_id)
428 return false; 428 return false;
429 if (FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE) != 0) 429 if (FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE) != 0)
430 return false; 430 return false;
431 FT_Outline_Get_CBox(&face->glyph->outline, bbox); 431 FT_Outline_Get_CBox(&face->glyph->outline, bbox);
432 return true; 432 return true;
433 } 433 }
434 434
435 static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) {
436 FT_Fixed advance = 0;
437 if (FT_Get_Advances(face, gId, 1, FT_LOAD_NO_SCALE, &advance)) {
438 return false;
439 }
440 SkASSERT(data);
441 *data = advance;
442 return true;
443 }
444
445 static void populate_glyph_to_unicode(FT_Face& face, SkTDArray<SkUnichar>* glyph ToUnicode) { 435 static void populate_glyph_to_unicode(FT_Face& face, SkTDArray<SkUnichar>* glyph ToUnicode) {
446 FT_Long numGlyphs = face->num_glyphs; 436 FT_Long numGlyphs = face->num_glyphs;
447 glyphToUnicode->setCount(SkToInt(numGlyphs)); 437 glyphToUnicode->setCount(SkToInt(numGlyphs));
448 sk_bzero(glyphToUnicode->begin(), sizeof((*glyphToUnicode)[0]) * numGlyphs); 438 sk_bzero(glyphToUnicode->begin(), sizeof((*glyphToUnicode)[0]) * numGlyphs);
449 439
450 FT_UInt glyphIndex; 440 FT_UInt glyphIndex;
451 SkUnichar charCode = FT_Get_First_Char(face, &glyphIndex); 441 SkUnichar charCode = FT_Get_First_Char(face, &glyphIndex);
452 while (glyphIndex) { 442 while (glyphIndex) {
453 SkASSERT(glyphIndex < SkToUInt(numGlyphs)); 443 SkASSERT(glyphIndex < SkToUInt(numGlyphs));
454 (*glyphToUnicode)[glyphIndex] = charCode; 444 (*glyphToUnicode)[glyphIndex] = charCode;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 for (int i = 0; i < advanceCount; i++) { 598 for (int i = 0; i < advanceCount; i++) {
609 int16_t advance = advances[i]; 599 int16_t advance = advances[i];
610 range.fAdvance.append(1, &advance); 600 range.fAdvance.append(1, &advance);
611 } 601 }
612 } 602 }
613 SkAdvancedTypefaceMetrics::FinishRange( 603 SkAdvancedTypefaceMetrics::FinishRange(
614 &range, face->num_glyphs - 1, 604 &range, face->num_glyphs - 1,
615 SkAdvancedTypefaceMetrics::WidthRange::kRange); 605 SkAdvancedTypefaceMetrics::WidthRange::kRange);
616 info->fGlyphWidths.emplace_back(std::move(range)); 606 info->fGlyphWidths.emplace_back(std::move(range));
617 } else { 607 } else {
618 info->setGlyphWidths(face, face->num_glyphs, glyphIDs, 608 info->setGlyphWidths(
619 glyphIDsCount, &getWidthAdvance); 609 face->num_glyphs, glyphIDs, glyphIDsCount,
610 SkAdvancedTypefaceMetrics::GetAdvance(
611 [face](int gId, int16_t* data) {
612 FT_Fixed advance = 0;
613 if (FT_Get_Advances(face, gId, 1,
614 FT_LOAD_NO_SCALE, &advance)) {
615 return false;
616 }
617 SkASSERT(data);
618 *data = advance;
619 return true;
620 }));
620 } 621 }
621 } 622 }
622 623
623 if (perGlyphInfo & kVAdvance_PerGlyphInfo && 624 if (perGlyphInfo & kVAdvance_PerGlyphInfo &&
624 FT_HAS_VERTICAL(face)) { 625 FT_HAS_VERTICAL(face)) {
625 SkASSERT(false); // Not implemented yet. 626 SkASSERT(false); // Not implemented yet.
626 } 627 }
627 628
628 if (perGlyphInfo & kGlyphNames_PerGlyphInfo && 629 if (perGlyphInfo & kGlyphNames_PerGlyphInfo &&
629 info->fType == SkAdvancedTypefaceMetrics::kType1_Font) { 630 info->fType == SkAdvancedTypefaceMetrics::kType1_Font) {
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", 1817 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n",
1817 name.c_str(), 1818 name.c_str(),
1818 (skTag >> 24) & 0xFF, 1819 (skTag >> 24) & 0xFF,
1819 (skTag >> 16) & 0xFF, 1820 (skTag >> 16) & 0xFF,
1820 (skTag >> 8) & 0xFF, 1821 (skTag >> 8) & 0xFF,
1821 (skTag) & 0xFF)); 1822 (skTag) & 0xFF));
1822 } 1823 }
1823 } 1824 }
1824 ) 1825 )
1825 } 1826 }
OLDNEW
« no previous file with comments | « src/core/SkAdvancedTypefaceMetrics.cpp ('k') | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698