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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.h

Issue 2515493002: Refactor HarfBuzzShaper to not retain font data (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef HarfBuzzShaper_h 31 #ifndef HarfBuzzShaper_h
32 #define HarfBuzzShaper_h 32 #define HarfBuzzShaper_h
33 33
34 #include "platform/fonts/FontDescription.h" 34 #include "platform/fonts/FontDescription.h"
35 #include "platform/fonts/SmallCapsIterator.h"
36 #include "platform/fonts/shaping/ShapeResult.h" 35 #include "platform/fonts/shaping/ShapeResult.h"
37 #include "platform/geometry/FloatPoint.h" 36 #include "platform/geometry/FloatPoint.h"
38 #include "platform/geometry/FloatRect.h" 37 #include "platform/geometry/FloatRect.h"
39 #include "platform/text/TextRun.h" 38 #include "platform/text/TextRun.h"
40 #include "wtf/Allocator.h" 39 #include "wtf/Allocator.h"
41 #include "wtf/Deque.h" 40 #include "wtf/Deque.h"
42 #include "wtf/HashSet.h" 41 #include "wtf/HashSet.h"
43 #include "wtf/Vector.h" 42 #include "wtf/Vector.h"
44 #include "wtf/text/CharacterNames.h" 43 #include "wtf/text/CharacterNames.h"
45 #include <hb.h> 44 #include <hb.h>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // 129 //
131 // Now this sub run is successfully processed and can be appended to 130 // Now this sub run is successfully processed and can be appended to
132 // ShapeResult. A new ShapeResult::RunInfo is created. The logic in 131 // ShapeResult. A new ShapeResult::RunInfo is created. The logic in
133 // insertRunIntoShapeResult then takes care of merging the shape result into 132 // insertRunIntoShapeResult then takes care of merging the shape result into
134 // the right position the vector of RunInfos in ShapeResult. 133 // the right position the vector of RunInfos in ShapeResult.
135 // 134 //
136 // Shaping then continues analogously for the remaining Hiragana Japanese 135 // Shaping then continues analogously for the remaining Hiragana Japanese
137 // sub-run, and the result is inserted into ShapeResult as well. 136 // sub-run, and the result is inserted into ShapeResult as well.
138 class PLATFORM_EXPORT HarfBuzzShaper final { 137 class PLATFORM_EXPORT HarfBuzzShaper final {
139 public: 138 public:
140 HarfBuzzShaper(const Font*, const TextRun&); 139 HarfBuzzShaper(const TextRun&);
141 PassRefPtr<ShapeResult> shapeResult(); 140 PassRefPtr<ShapeResult> shapeResult(const Font*);
142 ~HarfBuzzShaper() {} 141 ~HarfBuzzShaper() {}
143 142
144 enum HolesQueueItemAction { HolesQueueNextFont, HolesQueueRange }; 143 enum HolesQueueItemAction { HolesQueueNextFont, HolesQueueRange };
145 144
146 struct HolesQueueItem { 145 struct HolesQueueItem {
147 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 146 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
148 HolesQueueItemAction m_action; 147 HolesQueueItemAction m_action;
149 unsigned m_startIndex; 148 unsigned m_startIndex;
150 unsigned m_numCharacters; 149 unsigned m_numCharacters;
151 HolesQueueItem(HolesQueueItemAction action, unsigned start, unsigned num) 150 HolesQueueItem(HolesQueueItemAction action, unsigned start, unsigned num)
152 : m_action(action), m_startIndex(start), m_numCharacters(num){}; 151 : m_action(action), m_startIndex(start), m_numCharacters(num){};
153 }; 152 };
154 153
155 protected:
156 using FeaturesVector = Vector<hb_feature_t, 6>; 154 using FeaturesVector = Vector<hb_feature_t, 6>;
157 155
158 class CapsFeatureSettingsScopedOverlay final {
159 STACK_ALLOCATED()
160
161 public:
162 CapsFeatureSettingsScopedOverlay(FeaturesVector&,
163 FontDescription::FontVariantCaps);
164 CapsFeatureSettingsScopedOverlay() = delete;
165 ~CapsFeatureSettingsScopedOverlay();
166
167 private:
168 void overlayCapsFeatures(FontDescription::FontVariantCaps);
169 void prependCounting(const hb_feature_t&);
170 FeaturesVector& m_features;
171 size_t m_countFeatures;
172 };
173
174 private: 156 private:
175 void setFontFeatures(); 157 inline bool shapeRange(hb_buffer_t*,
176 158 const Font*,
177 void appendToHolesQueue(HolesQueueItemAction, 159 const FeaturesVector&,
178 unsigned startIndex, 160 const SimpleFontData*,
179 unsigned numCharacters); 161 PassRefPtr<UnicodeRangeSet>,
180 void prependHolesQueue(HolesQueueItemAction, 162 UScriptCode,
181 unsigned startIndex,
182 unsigned numCharacters);
183 void splitUntilNextCaseChange(HolesQueueItem& currentQueueItem,
184 SmallCapsIterator::SmallCapsBehavior&);
185 inline bool shapeRange(hb_buffer_t* harfBuzzBuffer,
186 const SimpleFontData* currentFont,
187 PassRefPtr<UnicodeRangeSet> currentFontRangeSet,
188 UScriptCode currentRunScript,
189 hb_language_t); 163 hb_language_t);
190 bool extractShapeResults(hb_buffer_t* harfBuzzBuffer, 164 bool extractShapeResults(hb_buffer_t*,
191 ShapeResult*, 165 ShapeResult*,
192 bool& fontCycleQueued, 166 bool& fontCycleQueued,
193 const HolesQueueItem& currentQueueItem, 167 Deque<HolesQueueItem>*,
194 const SimpleFontData* currentFont, 168 const HolesQueueItem&,
195 UScriptCode currentRunScript, 169 const Font*,
170 const SimpleFontData*,
171 UScriptCode,
196 bool isLastResort); 172 bool isLastResort);
197 bool collectFallbackHintChars(Vector<UChar32>& hint); 173 bool collectFallbackHintChars(const Deque<HolesQueueItem>&,
174 Vector<UChar32>& hint);
198 175
199 void insertRunIntoShapeResult( 176 void insertRunIntoShapeResult(
200 ShapeResult*, 177 ShapeResult*,
201 std::unique_ptr<ShapeResult::RunInfo> runToInsert, 178 std::unique_ptr<ShapeResult::RunInfo> runToInsert,
202 unsigned startGlyph, 179 unsigned startGlyph,
203 unsigned numGlyphs, 180 unsigned numGlyphs,
204 hb_buffer_t*); 181 hb_buffer_t*);
205 182
206 const Font* m_font;
207 const TextRun& m_textRun; 183 const TextRun& m_textRun;
208
209 std::unique_ptr<UChar[]> m_normalizedBuffer; 184 std::unique_ptr<UChar[]> m_normalizedBuffer;
210 unsigned m_normalizedBufferLength; 185 unsigned m_normalizedBufferLength;
211
212 FeaturesVector m_features;
213 Deque<HolesQueueItem> m_holesQueue;
214 }; 186 };
215 187
216 } // namespace blink 188 } // namespace blink
217 189
218 #endif // HarfBuzzShaper_h 190 #endif // HarfBuzzShaper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698