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

Side by Side Diff: Source/platform/fonts/shaping/CachingWordShapeIterator.h

Issue 1241613006: Reland "Change fallback font collection in HarfBuzzShaper" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Created 5 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 | « Source/platform/fonts/Font.cpp ('k') | Source/platform/fonts/shaping/CachingWordShaper.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 (C) 2015 Google Inc. All rights reserved. 2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 18 matching lines...) Expand all
29 #include "platform/fonts/SimpleFontData.h" 29 #include "platform/fonts/SimpleFontData.h"
30 #include "platform/fonts/shaping/CachingWordShapeIterator.h" 30 #include "platform/fonts/shaping/CachingWordShapeIterator.h"
31 #include "platform/fonts/shaping/HarfBuzzShaper.h" 31 #include "platform/fonts/shaping/HarfBuzzShaper.h"
32 #include "platform/fonts/shaping/ShapeCache.h" 32 #include "platform/fonts/shaping/ShapeCache.h"
33 #include "wtf/text/CharacterNames.h" 33 #include "wtf/text/CharacterNames.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 class CachingWordShapeIterator { 37 class CachingWordShapeIterator {
38 public: 38 public:
39 CachingWordShapeIterator(ShapeCache* cache, const TextRun& run, 39 CachingWordShapeIterator(ShapeCache* cache, const TextRun& run
40 const Font* font, HashSet<const SimpleFontData*>* fallbackFonts) 40 , const Font* font)
41 : m_shapeCache(cache), m_textRun(run), m_font(font) 41 : m_shapeCache(cache), m_textRun(run), m_font(font), m_startIndex(0)
42 , m_fallbackFonts(fallbackFonts), m_startIndex(0)
43 { 42 {
44 ASSERT(font); 43 ASSERT(font);
45 const FontDescription& fontDescription = font->fontDescription(); 44 const FontDescription& fontDescription = font->fontDescription();
46 45
47 // Word and letter spacing can change the width of a word, as can tabs 46 // Word and letter spacing can change the width of a word, as can tabs
48 // as we segment solely based on on space characters. 47 // as we segment solely based on on space characters.
49 // If expansion is used (for justified text) the spacing between words 48 // If expansion is used (for justified text) the spacing between words
50 // change and thus we need to shape the entire run. 49 // change and thus we need to shape the entire run.
51 m_wordResultCachable = !fontDescription.wordSpacing() 50 m_wordResultCachable = !fontDescription.wordSpacing()
52 && !fontDescription.letterSpacing() && !run.allowTabs() 51 && !fontDescription.letterSpacing() && !run.allowTabs()
53 && m_textRun.expansion() == 0.0f; 52 && m_textRun.expansion() == 0.0f;
54 53
55 // Shaping word by word is faster as each word is cached. If we cannot 54 // Shaping word by word is faster as each word is cached. If we cannot
56 // use the cache or if the font doesn't support word by word shaping 55 // use the cache or if the font doesn't support word by word shaping
57 // fall back on shaping the entire run. 56 // fall back on shaping the entire run.
58 m_shapeByWord = m_wordResultCachable && m_font->canShapeWordByWord(); 57 m_shapeByWord = m_wordResultCachable && m_font->canShapeWordByWord();
59 } 58 }
60 59
61 bool next(RefPtr<ShapeResult>* wordResult) 60 bool next(RefPtr<ShapeResult>* wordResult)
62 { 61 {
63 if (!m_shapeByWord) { 62 if (!m_shapeByWord) {
64 if (m_startIndex) 63 if (m_startIndex)
65 return false; 64 return false;
66 *wordResult = shapeWord(m_textRun, m_font, m_fallbackFonts); 65 *wordResult = shapeWord(m_textRun, m_font);
67 m_startIndex = 1; 66 m_startIndex = 1;
68 return *wordResult; 67 return *wordResult;
69 } 68 }
70 69
71 unsigned length = m_textRun.length(); 70 unsigned length = m_textRun.length();
72 if (m_startIndex < length) { 71 if (m_startIndex < length) {
73 if (m_textRun[m_startIndex] == spaceCharacter) { 72 if (m_textRun[m_startIndex] == spaceCharacter) {
74 TextRun wordRun = m_textRun.subRun(m_startIndex, 1); 73 TextRun wordRun = m_textRun.subRun(m_startIndex, 1);
75 *wordResult = shapeWord(wordRun, m_font, m_fallbackFonts); 74 *wordResult = shapeWord(wordRun, m_font);
76 m_startIndex++; 75 m_startIndex++;
77 return true; 76 return true;
78 } 77 }
79 78
80 for (unsigned i = m_startIndex; ; i++) { 79 for (unsigned i = m_startIndex; ; i++) {
81 if (i == length || m_textRun[i] == spaceCharacter) { 80 if (i == length || m_textRun[i] == spaceCharacter) {
82 TextRun wordRun = m_textRun.subRun(m_startIndex, 81 TextRun wordRun = m_textRun.subRun(m_startIndex,
83 i - m_startIndex); 82 i - m_startIndex);
84 *wordResult = shapeWord(wordRun, m_font, m_fallbackFonts); 83 *wordResult = shapeWord(wordRun, m_font);
85 m_startIndex = i; 84 m_startIndex = i;
86 return true; 85 return true;
87 } 86 }
88 } 87 }
89 } 88 }
90 return false; 89 return false;
91 } 90 }
92 91
93 private: 92 private:
94 void setFallbackFonts(const ShapeResult* wordResult, 93 PassRefPtr<ShapeResult> shapeWord(const TextRun& wordRun, const Font* font)
95 HashSet<const SimpleFontData*>* fallbackFonts)
96 {
97 if (fallbackFonts) {
98 const HashSet<const SimpleFontData*>* fontsForWord =
99 wordResult->fallbackFonts();
100 HashSet<const SimpleFontData*>::const_iterator it;
101 for (it = fontsForWord->begin(); it != fontsForWord->end(); ++it)
102 fallbackFonts->add(*it);
103 }
104 }
105
106 PassRefPtr<ShapeResult> shapeWord(const TextRun& wordRun,
107 const Font* font, HashSet<const SimpleFontData*>* fallbackFonts)
108 { 94 {
109 ShapeCacheEntry* cacheEntry = m_wordResultCachable 95 ShapeCacheEntry* cacheEntry = m_wordResultCachable
110 ? m_shapeCache->add(wordRun, ShapeCacheEntry()) 96 ? m_shapeCache->add(wordRun, ShapeCacheEntry())
111 : nullptr; 97 : nullptr;
112 if (cacheEntry && cacheEntry->m_shapeResult) { 98 if (cacheEntry && cacheEntry->m_shapeResult)
113 setFallbackFonts(cacheEntry->m_shapeResult.get(), fallbackFonts);
114 return cacheEntry->m_shapeResult; 99 return cacheEntry->m_shapeResult;
115 }
116 100
117 HashSet<const SimpleFontData*> fallbackFontsForWord; 101 HarfBuzzShaper shaper(font, wordRun);
118 HarfBuzzShaper shaper(font, wordRun, &fallbackFontsForWord);
119 RefPtr<ShapeResult> shapeResult = shaper.shapeResult(); 102 RefPtr<ShapeResult> shapeResult = shaper.shapeResult();
120 if (!shapeResult) 103 if (!shapeResult)
121 return nullptr; 104 return nullptr;
122 105
123 if (cacheEntry) 106 if (cacheEntry)
124 cacheEntry->m_shapeResult = shapeResult; 107 cacheEntry->m_shapeResult = shapeResult;
125 108
126 setFallbackFonts(shapeResult.get(), fallbackFonts);
127 return shapeResult.release(); 109 return shapeResult.release();
128 } 110 }
129 111
130 ShapeCache* m_shapeCache; 112 ShapeCache* m_shapeCache;
131 const TextRun& m_textRun; 113 const TextRun& m_textRun;
132 const Font* m_font; 114 const Font* m_font;
133 HashSet<const SimpleFontData*>* m_fallbackFonts;
134 unsigned m_startIndex : 30; 115 unsigned m_startIndex : 30;
135 unsigned m_wordResultCachable : 1; 116 unsigned m_wordResultCachable : 1;
136 unsigned m_shapeByWord : 1; 117 unsigned m_shapeByWord : 1;
137 }; 118 };
138 119
139 } // namespace blink 120 } // namespace blink
140 121
141 #endif // CachingWordShapeIterator_h 122 #endif // CachingWordShapeIterator_h
OLDNEW
« no previous file with comments | « Source/platform/fonts/Font.cpp ('k') | Source/platform/fonts/shaping/CachingWordShaper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698