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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/ShapeResultBuffer.cpp

Issue 2598393002: Do not skip ink for ideographic scripts (Closed)
Patch Set: Fix not to compute twice Created 3 years, 11 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
OLDNEW
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"
11 #include "platform/geometry/FloatPoint.h" 11 #include "platform/geometry/FloatPoint.h"
12 #include "platform/text/Character.h" 12 #include "platform/text/Character.h"
13 #include "platform/text/TextBreakIterator.h" 13 #include "platform/text/TextBreakIterator.h"
14 #include "platform/text/TextDirection.h" 14 #include "platform/text/TextDirection.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 namespace { 18 namespace {
19 19
20 inline void addGlyphToBuffer(GlyphBuffer* glyphBuffer, 20 inline void addGlyphToBuffer(GlyphBuffer* glyphBuffer,
21 float advance, 21 float advance,
22 hb_direction_t direction, 22 hb_direction_t direction,
23 const SimpleFontData* fontData, 23 const SimpleFontData* fontData,
24 const HarfBuzzRunGlyphData& glyphData) { 24 const HarfBuzzRunGlyphData& glyphData,
25 unsigned characterIndex) {
25 FloatPoint startOffset = HB_DIRECTION_IS_HORIZONTAL(direction) 26 FloatPoint startOffset = HB_DIRECTION_IS_HORIZONTAL(direction)
26 ? FloatPoint(advance, 0) 27 ? FloatPoint(advance, 0)
27 : FloatPoint(0, advance); 28 : FloatPoint(0, advance);
28 glyphBuffer->add(glyphData.glyph, fontData, startOffset + glyphData.offset); 29 glyphBuffer->add(glyphData.glyph, fontData, startOffset + glyphData.offset,
30 characterIndex);
29 } 31 }
30 32
31 inline void addEmphasisMark(GlyphBuffer* buffer, 33 inline void addEmphasisMark(GlyphBuffer* buffer,
32 const GlyphData* emphasisData, 34 const GlyphData* emphasisData,
33 FloatPoint glyphCenter, 35 FloatPoint glyphCenter,
34 float midGlyphOffset) { 36 float midGlyphOffset) {
35 ASSERT(buffer); 37 ASSERT(buffer);
36 ASSERT(emphasisData); 38 ASSERT(emphasisData);
37 39
38 const SimpleFontData* emphasisFontData = emphasisData->fontData; 40 const SimpleFontData* emphasisFontData = emphasisData->fontData;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 uint16_t currentCharacterIndex = 93 uint16_t currentCharacterIndex =
92 run->m_startIndex + glyphData.characterIndex + runOffset; 94 run->m_startIndex + glyphData.characterIndex + runOffset;
93 if ((direction == TextDirection::Rtl && currentCharacterIndex >= to) || 95 if ((direction == TextDirection::Rtl && currentCharacterIndex >= to) ||
94 (direction == TextDirection::Ltr && currentCharacterIndex < from)) { 96 (direction == TextDirection::Ltr && currentCharacterIndex < from)) {
95 advanceSoFar += glyphData.advance; 97 advanceSoFar += glyphData.advance;
96 } else if ((direction == TextDirection::Rtl && 98 } else if ((direction == TextDirection::Rtl &&
97 currentCharacterIndex >= from) || 99 currentCharacterIndex >= from) ||
98 (direction == TextDirection::Ltr && 100 (direction == TextDirection::Ltr &&
99 currentCharacterIndex < to)) { 101 currentCharacterIndex < to)) {
100 addGlyphToBuffer(glyphBuffer, advanceSoFar, run->m_direction, 102 addGlyphToBuffer(glyphBuffer, advanceSoFar, run->m_direction,
101 run->m_fontData.get(), glyphData); 103 run->m_fontData.get(), glyphData, currentCharacterIndex);
102 advanceSoFar += glyphData.advance; 104 advanceSoFar += glyphData.advance;
103 } 105 }
104 } 106 }
105 return advanceSoFar - initialAdvance; 107 return advanceSoFar - initialAdvance;
106 } 108 }
107 109
108 float ShapeResultBuffer::fillGlyphBufferForTextEmphasisRun( 110 float ShapeResultBuffer::fillGlyphBufferForTextEmphasisRun(
109 GlyphBuffer* glyphBuffer, 111 GlyphBuffer* glyphBuffer,
110 const ShapeResult::RunInfo* run, 112 const ShapeResult::RunInfo* run,
111 const TextRun& textRun, 113 const TextRun& textRun,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return advanceSoFar - initialAdvance; 197 return advanceSoFar - initialAdvance;
196 } 198 }
197 199
198 float ShapeResultBuffer::fillFastHorizontalGlyphBuffer( 200 float ShapeResultBuffer::fillFastHorizontalGlyphBuffer(
199 GlyphBuffer* glyphBuffer, 201 GlyphBuffer* glyphBuffer,
200 TextDirection dir) const { 202 TextDirection dir) const {
201 ASSERT(!hasVerticalOffsets()); 203 ASSERT(!hasVerticalOffsets());
202 204
203 float advance = 0; 205 float advance = 0;
204 206
207 unsigned characterIndex = 0;
205 for (unsigned i = 0; i < m_results.size(); ++i) { 208 for (unsigned i = 0; i < m_results.size(); ++i) {
206 const auto& wordResult = isLeftToRightDirection(dir) 209 const auto& wordResult = isLeftToRightDirection(dir)
207 ? m_results[i] 210 ? m_results[i]
208 : m_results[m_results.size() - 1 - i]; 211 : m_results[m_results.size() - 1 - i];
209 ASSERT(!wordResult->hasVerticalOffsets()); 212 ASSERT(!wordResult->hasVerticalOffsets());
210 213
211 for (const auto& run : wordResult->m_runs) { 214 for (const auto& run : wordResult->m_runs) {
212 ASSERT(run); 215 ASSERT(run);
213 ASSERT(HB_DIRECTION_IS_HORIZONTAL(run->m_direction)); 216 ASSERT(HB_DIRECTION_IS_HORIZONTAL(run->m_direction));
214 217
215 for (const auto& glyphData : run->m_glyphData) { 218 for (const auto& glyphData : run->m_glyphData) {
216 ASSERT(!glyphData.offset.height()); 219 ASSERT(!glyphData.offset.height());
217 220
218 glyphBuffer->add(glyphData.glyph, run->m_fontData.get(), 221 glyphBuffer->add(glyphData.glyph, run->m_fontData.get(),
219 advance + glyphData.offset.width()); 222 advance + glyphData.offset.width(),
223 characterIndex + glyphData.characterIndex);
220 advance += glyphData.advance; 224 advance += glyphData.advance;
221 } 225 }
222 } 226 }
227 characterIndex += wordResult->m_numCharacters;
223 } 228 }
224 229
225 ASSERT(!glyphBuffer->hasVerticalOffsets()); 230 ASSERT(!glyphBuffer->hasVerticalOffsets());
226 231
227 return advance; 232 return advance;
228 } 233 }
229 234
230 float ShapeResultBuffer::fillGlyphBuffer(GlyphBuffer* glyphBuffer, 235 float ShapeResultBuffer::fillGlyphBuffer(GlyphBuffer* glyphBuffer,
231 const TextRun& textRun, 236 const TextRun& textRun,
232 unsigned from, 237 unsigned from,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 totalOffset += offsetForWord; 452 totalOffset += offsetForWord;
448 if (targetX >= 0 && targetX <= wordResult->width()) 453 if (targetX >= 0 && targetX <= wordResult->width())
449 return totalOffset; 454 return totalOffset;
450 targetX -= wordResult->width(); 455 targetX -= wordResult->width();
451 } 456 }
452 } 457 }
453 return totalOffset; 458 return totalOffset;
454 } 459 }
455 460
456 } // namespace blink 461 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698