OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/fonts/shaping/ShapeResultBuffer.h" | 5 #include "platform/fonts/shaping/ShapeResultBuffer.h" |
6 | 6 |
7 #include "platform/fonts/CharacterRange.h" | 7 #include "platform/fonts/CharacterRange.h" |
8 #include "platform/fonts/GlyphBuffer.h" | 8 #include "platform/fonts/GlyphBuffer.h" |
9 #include "platform/fonts/SimpleFontData.h" | 9 #include "platform/fonts/SimpleFontData.h" |
10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" | 10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 unsigned graphemesInCluster = 1; | 118 unsigned graphemesInCluster = 1; |
119 float clusterAdvance = 0; | 119 float clusterAdvance = 0; |
120 | 120 |
121 FloatPoint glyphCenter = | 121 FloatPoint glyphCenter = |
122 emphasisData->fontData->boundsForGlyph(emphasisData->glyph).center(); | 122 emphasisData->fontData->boundsForGlyph(emphasisData->glyph).center(); |
123 | 123 |
124 TextDirection direction = textRun.direction(); | 124 TextDirection direction = textRun.direction(); |
125 | 125 |
126 // A "cluster" in this context means a cluster as it is used by HarfBuzz: | 126 // A "cluster" in this context means a cluster as it is used by HarfBuzz: |
127 // The minimal group of characters and corresponding glyphs, that cannot be br
oken | 127 // The minimal group of characters and corresponding glyphs, that cannot be |
128 // down further from a text shaping point of view. | 128 // broken down further from a text shaping point of view. A cluster can |
129 // A cluster can contain multiple glyphs and grapheme clusters, with mutually | 129 // contain multiple glyphs and grapheme clusters, with mutually overlapping |
130 // overlapping boundaries. Below we count grapheme clusters per HarfBuzz clust
ers, | 130 // boundaries. Below we count grapheme clusters per HarfBuzz clusters, then |
131 // then linearly split the sum of corresponding glyph advances by the number o
f | 131 // linearly split the sum of corresponding glyph advances by the number of |
132 // grapheme clusters in order to find positions for emphasis mark drawing. | 132 // grapheme clusters in order to find positions for emphasis mark drawing. |
133 uint16_t clusterStart = static_cast<uint16_t>( | 133 uint16_t clusterStart = static_cast<uint16_t>( |
134 direction == RTL ? run->m_startIndex + run->m_numCharacters + runOffset | 134 direction == RTL ? run->m_startIndex + run->m_numCharacters + runOffset |
135 : run->glyphToCharacterIndex(0) + runOffset); | 135 : run->glyphToCharacterIndex(0) + runOffset); |
136 | 136 |
137 float advanceSoFar = initialAdvance; | 137 float advanceSoFar = initialAdvance; |
138 const unsigned numGlyphs = run->m_glyphData.size(); | 138 const unsigned numGlyphs = run->m_glyphData.size(); |
139 for (unsigned i = 0; i < numGlyphs; ++i) { | 139 for (unsigned i = 0; i < numGlyphs; ++i) { |
140 const HarfBuzzRunGlyphData& glyphData = run->m_glyphData[i]; | 140 const HarfBuzzRunGlyphData& glyphData = run->m_glyphData[i]; |
141 uint16_t currentCharacterIndex = | 141 uint16_t currentCharacterIndex = |
(...skipping 29 matching lines...) Expand all Loading... |
171 : run->glyphToCharacterIndex(i + 1) + runOffset); | 171 : run->glyphToCharacterIndex(i + 1) + runOffset); |
172 | 172 |
173 graphemesInCluster = countGraphemesInCluster(textRun.characters16(), | 173 graphemesInCluster = countGraphemesInCluster(textRun.characters16(), |
174 textRun.charactersLength(), | 174 textRun.charactersLength(), |
175 clusterStart, clusterEnd); | 175 clusterStart, clusterEnd); |
176 if (!graphemesInCluster || !clusterAdvance) | 176 if (!graphemesInCluster || !clusterAdvance) |
177 continue; | 177 continue; |
178 | 178 |
179 float glyphAdvanceX = clusterAdvance / graphemesInCluster; | 179 float glyphAdvanceX = clusterAdvance / graphemesInCluster; |
180 for (unsigned j = 0; j < graphemesInCluster; ++j) { | 180 for (unsigned j = 0; j < graphemesInCluster; ++j) { |
181 // Do not put emphasis marks on space, separator, and control characters
. | 181 // Do not put emphasis marks on space, separator, and control |
| 182 // characters. |
182 if (Character::canReceiveTextEmphasis(textRun[currentCharacterIndex])) | 183 if (Character::canReceiveTextEmphasis(textRun[currentCharacterIndex])) |
183 addEmphasisMark(glyphBuffer, emphasisData, glyphCenter, | 184 addEmphasisMark(glyphBuffer, emphasisData, glyphCenter, |
184 advanceSoFar + glyphAdvanceX / 2); | 185 advanceSoFar + glyphAdvanceX / 2); |
185 advanceSoFar += glyphAdvanceX; | 186 advanceSoFar += glyphAdvanceX; |
186 } | 187 } |
187 clusterStart = clusterEnd; | 188 clusterStart = clusterEnd; |
188 clusterAdvance = 0; | 189 clusterAdvance = 0; |
189 } | 190 } |
190 } | 191 } |
191 return advanceSoFar - initialAdvance; | 192 return advanceSoFar - initialAdvance; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 totalOffset += offsetForWord; | 443 totalOffset += offsetForWord; |
443 if (targetX >= 0 && targetX <= wordResult->width()) | 444 if (targetX >= 0 && targetX <= wordResult->width()) |
444 return totalOffset; | 445 return totalOffset; |
445 targetX -= wordResult->width(); | 446 targetX -= wordResult->width(); |
446 } | 447 } |
447 } | 448 } |
448 return totalOffset; | 449 return totalOffset; |
449 } | 450 } |
450 | 451 |
451 } // namespace blink | 452 } // namespace blink |
OLD | NEW |