OLD | NEW |
---|---|
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 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 #ifndef HarfBuzzShaper_h | 31 #ifndef HarfBuzzShaper_h |
32 #define HarfBuzzShaper_h | 32 #define HarfBuzzShaper_h |
33 | 33 |
34 #include "hb.h" | 34 #include "hb.h" |
35 #include "platform/fonts/shaping/Shaper.h" | 35 #include "platform/fonts/shaping/Shaper.h" |
36 #include "platform/geometry/FloatPoint.h" | 36 #include "platform/geometry/FloatPoint.h" |
37 #include "platform/geometry/FloatRect.h" | 37 #include "platform/geometry/FloatRect.h" |
38 #include "platform/text/TextRun.h" | 38 #include "platform/text/TextRun.h" |
39 #include "wtf/Deque.h" | |
39 #include "wtf/HashSet.h" | 40 #include "wtf/HashSet.h" |
40 #include "wtf/OwnPtr.h" | 41 #include "wtf/OwnPtr.h" |
41 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
42 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
43 #include "wtf/text/CharacterNames.h" | 44 #include "wtf/text/CharacterNames.h" |
44 | 45 |
45 #include <unicode/uscript.h> | 46 #include <unicode/uscript.h> |
46 | 47 |
47 namespace blink { | 48 namespace blink { |
48 | 49 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 unsigned m_numGlyphs : 31; | 108 unsigned m_numGlyphs : 31; |
108 | 109 |
109 // Overall direction for the TextRun, dictates which order each individual | 110 // Overall direction for the TextRun, dictates which order each individual |
110 // sub run (represented by RunInfo structs in the m_runs vector) can have a | 111 // sub run (represented by RunInfo structs in the m_runs vector) can have a |
111 // different text direction. | 112 // different text direction. |
112 unsigned m_direction : 1; | 113 unsigned m_direction : 1; |
113 | 114 |
114 friend class HarfBuzzShaper; | 115 friend class HarfBuzzShaper; |
115 }; | 116 }; |
116 | 117 |
118 | |
119 // Shaping text runs is split into several stages: Run segmentation, shaping the | |
120 // initial segment, identify shaped and non-shaped sequences of the shaping | |
121 // result, and processing sub-runs by trying to shape them with a fallback font | |
122 // until the last resort font is reached. | |
123 // | |
124 // Going through one example to illustrate the process: The following is a run o f | |
125 // vertical text to be shaped. After run segmentation in RunSegmenter it is spli t | |
126 // into 4 segments. The segments indicated by the segementation results showing | |
127 // the script, orientation information and small caps handling of the individual | |
128 // segment. The Japanese text at the beginning has script "Hiragana", does not | |
129 // need rotation when laid out vertically and does not need uppercasing when | |
130 // small caps is requested. | |
131 // | |
132 // 0 い | |
133 // 1 ろ | |
134 // 2 は USCRIPT_HIRAGANA, | |
135 // OrientationIterator::OrientationKeep, | |
136 // SmallCapsIterator::SmallCapsSameCase | |
137 // | |
138 // 3 a | |
139 // 4 ̄ (Combining Macron) | |
140 // 5 a | |
141 // 6 A USCRIPT_LATIN, | |
142 // OrientationIterator::OrientationRotateSideways, | |
143 // SmallCapsIterator::SmallCapsUppercaseNeeded | |
144 // | |
145 // 7 い | |
146 // 8 ろ | |
147 // 9 は USCRIPT_HIRAGANA, | |
148 // OrientationIterator::OrientationKeep, | |
149 // SmallCapsIterator::SmallCapsSameCase | |
150 // | |
151 // | |
152 // Let's assume the CSS for this text run is as follows: | |
153 // font-family: "Heiti SC", Tinos, sans-serif; | |
154 // where Tinos is a web font, defined as a composite font, with two sub ranges, | |
155 // one for Latin U+00-U+FF and one unrestricted unicode-range. | |
156 // | |
157 // FontFallbackIterator provides the shaper with Heiti SC, then Tinos of the | |
158 // restricted unicode-range, then the unrestricted full unicode-range Tinos, the n | |
159 // a system sans-serif. | |
160 // | |
161 // The initial segment 0-2 to the shaper, together with the segmentation | |
162 // properties and the initial Heiti SC font. Characters 0-2 are shaped | |
163 // successfully with Heiti SC. The next segment, 3-5 is passed to the shaper. Th e | |
164 // shaper attempts to shape it with Heiti SC, which fails for the Combining | |
165 // Macron. So the shaping result for this segment would look similar to this. | |
166 // | |
167 // Glyphpos: 0 1 2 3 | |
168 // Cluster: 0 0 2 3 | |
169 // Glyph: a x a A (where x is .notdef) | |
170 // | |
171 // Now in the extractShapeResults() step we notice that there is more work to do , | |
172 // since Heiti SC does not have a glyph for the Combining Macron combined with a n | |
173 // a. So, this cluster together with a Todo item for switching to the next font | |
174 // is put into HolesQueue. | |
175 // | |
176 // After shaping the initial segment, the remaining items in the HolesQueue are | |
177 // processed, picking them from the head of the queue. So, first, the next font | |
178 // is requested from the FontFallbackIterator. In this case, Tinos (for the rang e | |
179 // U+00-U+FF) comes back. Shaping using this font, assuming it is subsetted, | |
180 // fails again since there is no combining mark available. This triggers | |
181 // requesting yet another font. This time, the Tinos font for the full | |
182 // range. With this, shaping succeeds with the following HarfBuzz result: | |
183 // | |
184 // Glyphpos 0 1 2 3 | |
185 // Cluster: 0 0 2 3 | |
186 // Glyph: a ̄ a A (with glyph coordinates placing the ̄ above the first a) | |
187 // | |
188 // Now this sub run is successfully processed and can be appended to | |
189 // ShapeResult. A new ShapeResult::RunInfo is created. The logic in | |
190 // insertRunIntoShapeResult then takes care of merging the shape result into | |
191 // the right position the vector of RunInfos in ShapeResult. | |
192 // | |
193 // Shaping then continues analogously for the remaining Hiragana Japanese | |
194 // sub-run, and the result is inserted into ShapeResult as well. | |
117 class PLATFORM_EXPORT HarfBuzzShaper final : public Shaper { | 195 class PLATFORM_EXPORT HarfBuzzShaper final : public Shaper { |
118 public: | 196 public: |
119 HarfBuzzShaper(const Font*, const TextRun&); | 197 HarfBuzzShaper(const Font*, const TextRun&); |
120 PassRefPtr<ShapeResult> shapeResult(); | 198 PassRefPtr<ShapeResult> shapeResult(); |
121 ~HarfBuzzShaper() { } | 199 ~HarfBuzzShaper() { } |
122 | 200 |
123 private: | 201 enum HolesQueueItemAction { |
124 struct HarfBuzzRun { | 202 HolesQueueNextFont, |
125 const SimpleFontData* m_fontData; | 203 HolesQueueRange |
126 unsigned m_startIndex; | |
127 size_t m_numCharacters; | |
128 hb_direction_t m_direction; | |
129 hb_script_t m_script; | |
130 }; | 204 }; |
131 | 205 |
206 struct HolesQueueItem { | |
207 HolesQueueItemAction m_action; | |
208 unsigned m_startIndex; | |
209 unsigned m_numCharacters; | |
210 HolesQueueItem(HolesQueueItemAction action, unsigned start, unsigned num ) | |
211 : m_action(action) | |
212 , m_startIndex(start) | |
213 , m_numCharacters(num) {}; | |
214 }; | |
215 | |
216 private: | |
132 float nextExpansionPerOpportunity(); | 217 float nextExpansionPerOpportunity(); |
133 void setExpansion(float); | 218 void setExpansion(float); |
134 void setFontFeatures(); | 219 void setFontFeatures(); |
135 | 220 |
136 bool createHarfBuzzRuns(); | 221 void appendToHolesQueue(HolesQueueItemAction, |
137 bool createHarfBuzzRunsForSingleCharacter(); | 222 unsigned startIndex, |
138 PassRefPtr<ShapeResult> shapeHarfBuzzRuns(); | 223 unsigned numCharacters); |
139 void shapeResult(ShapeResult*, unsigned, const HarfBuzzRun*, hb_buffer_t*); | 224 inline bool shapeRange(hb_buffer_t* harfBuzzBuffer, |
225 unsigned startIndex, | |
226 unsigned numCharacters, | |
227 const SimpleFontData* currentFont, | |
228 UScriptCode currentRunScript, | |
229 hb_language_t); | |
230 bool extractShapeResults(hb_buffer_t* harfBuzzBuffer, | |
231 ShapeResult*, | |
232 bool& fontCycleQueued, | |
233 const HolesQueueItem& currentQueueItem, | |
234 const SimpleFontData* currentFont, | |
235 UScriptCode currentRunScript, | |
236 bool isLastResort); | |
237 bool collectFallbackHintChars(Vector<UChar32>& hint, bool needsList); | |
eae
2015/10/14 13:00:40
Much clearer, thank you!
| |
238 | |
239 void insertRunIntoShapeResult(ShapeResult*, PassOwnPtr<ShapeResult::RunInfo> runToInsert, unsigned startGlyph, unsigned numGlyphs, int, hb_buffer_t*); | |
140 float adjustSpacing(ShapeResult::RunInfo*, size_t glyphIndex, unsigned curre ntCharacterIndex, float& offsetX, float& totalAdvance); | 240 float adjustSpacing(ShapeResult::RunInfo*, size_t glyphIndex, unsigned curre ntCharacterIndex, float& offsetX, float& totalAdvance); |
141 void addHarfBuzzRun(unsigned startCharacter, unsigned endCharacter, const Si mpleFontData*, UScriptCode); | |
142 | 241 |
143 OwnPtr<UChar[]> m_normalizedBuffer; | 242 OwnPtr<UChar[]> m_normalizedBuffer; |
144 unsigned m_normalizedBufferLength; | 243 unsigned m_normalizedBufferLength; |
145 | 244 |
146 float m_wordSpacingAdjustment; // Delta adjustment (pixels) for each word br eak. | 245 float m_wordSpacingAdjustment; // Delta adjustment (pixels) for each word br eak. |
147 float m_letterSpacing; // Pixels to be added after each glyph. | 246 float m_letterSpacing; // Pixels to be added after each glyph. |
148 unsigned m_expansionOpportunityCount; | 247 unsigned m_expansionOpportunityCount; |
149 | 248 |
150 Vector<hb_feature_t, 4> m_features; | 249 Vector<hb_feature_t, 4> m_features; |
151 Vector<HarfBuzzRun, 16> m_harfBuzzRuns; | 250 Deque<HolesQueueItem> m_holesQueue; |
152 }; | 251 }; |
153 | 252 |
253 | |
154 } // namespace blink | 254 } // namespace blink |
155 | 255 |
156 #endif // HarfBuzzShaper_h | 256 #endif // HarfBuzzShaper_h |
OLD | NEW |