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

Side by Side Diff: Source/platform/fonts/shaping/HarfBuzzShaper.cpp

Issue 986493002: Simplify text emphasis painting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/fonts/shaping/HarfBuzzShaper.h ('k') | Source/platform/fonts/shaping/Shaper.h » ('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) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } else { 340 } else {
341 while (glyphIndex < m_numGlyphs && m_glyphToCharacterIndexes[glyphIndex] < offset) { 341 while (glyphIndex < m_numGlyphs && m_glyphToCharacterIndexes[glyphIndex] < offset) {
342 position += m_advances[glyphIndex]; 342 position += m_advances[glyphIndex];
343 ++glyphIndex; 343 ++glyphIndex;
344 } 344 }
345 } 345 }
346 return position; 346 return position;
347 } 347 }
348 348
349 349
350 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, ForTextEmph asisOrNot forTextEmphasis, HashSet<const SimpleFontData*>* fallbackFonts, FloatR ect* bounds) 350 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, const Glyph Data* emphasisData,
351 : Shaper(font, run, forTextEmphasis, fallbackFonts, bounds) 351 HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* bounds)
352 : Shaper(font, run, emphasisData, fallbackFonts, bounds)
352 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing()) 353 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing())
353 , m_letterSpacing(font->fontDescription().letterSpacing()) 354 , m_letterSpacing(font->fontDescription().letterSpacing())
354 , m_expansionOpportunityCount(0) 355 , m_expansionOpportunityCount(0)
355 , m_fromIndex(0) 356 , m_fromIndex(0)
356 , m_toIndex(m_run.length()) 357 , m_toIndex(m_run.length())
357 { 358 {
358 setExpansion(m_run.expansion()); 359 setExpansion(m_run.expansion());
359 setFontFeatures(); 360 setFontFeatures();
360 } 361 }
361 362
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 advanceSoFar += advances[i]; 1157 advanceSoFar += advances[i];
1157 } 1158 }
1158 } 1159 }
1159 } 1160 }
1160 1161
1161 return advanceSoFar - initialAdvance; 1162 return advanceSoFar - initialAdvance;
1162 } 1163 }
1163 1164
1164 float HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, H arfBuzzRun* currentRun, float initialAdvance) 1165 float HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, H arfBuzzRun* currentRun, float initialAdvance)
1165 { 1166 {
1166 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u sed by the
1167 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis mark drawing function.
1168
1169 float* advances = currentRun->advances(); 1167 float* advances = currentRun->advances();
1170 unsigned numGlyphs = currentRun->numGlyphs(); 1168 unsigned numGlyphs = currentRun->numGlyphs();
1171 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); 1169 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes();
1172 unsigned graphemesInCluster = 1; 1170 unsigned graphemesInCluster = 1;
1173 float clusterAdvance = 0; 1171 float clusterAdvance = 0;
1174 uint16_t clusterStart; 1172 uint16_t clusterStart;
1175 1173
1176 // A "cluster" in this context means a cluster as it is used by HarfBuzz: 1174 // A "cluster" in this context means a cluster as it is used by HarfBuzz:
1177 // The minimal group of characters and corresponding glyphs, that cannot be broken 1175 // The minimal group of characters and corresponding glyphs, that cannot be broken
1178 // down further from a text shaping point of view. 1176 // down further from a text shaping point of view.
(...skipping 28 matching lines...) Expand all
1207 else 1205 else
1208 clusterEnd = isRunEnd ? currentRun->startIndex() + currentRun->n umCharacters() : currentRun->startIndex() + glyphToCharacterIndexes[i + 1]; 1206 clusterEnd = isRunEnd ? currentRun->startIndex() + currentRun->n umCharacters() : currentRun->startIndex() + glyphToCharacterIndexes[i + 1];
1209 1207
1210 graphemesInCluster = m_run.is8Bit() ? 1 : countGraphemesInCluster(m_ run.characters16(), m_run.length(), clusterStart, clusterEnd); 1208 graphemesInCluster = m_run.is8Bit() ? 1 : countGraphemesInCluster(m_ run.characters16(), m_run.length(), clusterStart, clusterEnd);
1211 if (!graphemesInCluster || !clusterAdvance) 1209 if (!graphemesInCluster || !clusterAdvance)
1212 continue; 1210 continue;
1213 1211
1214 float glyphAdvanceX = clusterAdvance / graphemesInCluster; 1212 float glyphAdvanceX = clusterAdvance / graphemesInCluster;
1215 for (unsigned j = 0; j < graphemesInCluster; ++j) { 1213 for (unsigned j = 0; j < graphemesInCluster; ++j) {
1216 // Do not put emphasis marks on space, separator, and control ch aracters. 1214 // Do not put emphasis marks on space, separator, and control ch aracters.
1217 Glyph glyphToAdd = Character::canReceiveTextEmphasis(m_run[curre ntCharacterIndex]) ? 1 : 0; 1215 if (Character::canReceiveTextEmphasis(m_run[currentCharacterInde x]))
1218 // The emphasis code expects mid-glyph offsets. 1216 addEmphasisMark(glyphBuffer, advanceSoFar + glyphAdvanceX / 2);
1219 glyphBuffer->add(glyphToAdd, currentRun->fontData(), advanceSoFa r + glyphAdvanceX / 2); 1217
1220 advanceSoFar += glyphAdvanceX; 1218 advanceSoFar += glyphAdvanceX;
1221 } 1219 }
1222 clusterStart = clusterEnd; 1220 clusterStart = clusterEnd;
1223 clusterAdvance = 0; 1221 clusterAdvance = 0;
1224 } 1222 }
1225 } 1223 }
1226 1224
1227 return advanceSoFar - initialAdvance; 1225 return advanceSoFar - initialAdvance;
1228 } 1226 }
1229 1227
1230 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) 1228 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer)
1231 { 1229 {
1232 ASSERT(glyphBuffer); 1230 ASSERT(glyphBuffer);
1233 1231
1234 unsigned numRuns = m_harfBuzzRuns.size(); 1232 unsigned numRuns = m_harfBuzzRuns.size();
1235 float advanceSoFar = 0; 1233 float advanceSoFar = 0;
1236 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { 1234 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) {
1237 HarfBuzzRun* currentRun = m_harfBuzzRuns[m_run.ltr() ? runIndex : numRun s - runIndex - 1].get(); 1235 HarfBuzzRun* currentRun = m_harfBuzzRuns[m_run.ltr() ? runIndex : numRun s - runIndex - 1].get();
1238 // Skip runs that only contain control characters. 1236 // Skip runs that only contain control characters.
1239 if (!currentRun->numGlyphs()) 1237 if (!currentRun->numGlyphs())
1240 continue; 1238 continue;
1241 advanceSoFar += (m_forTextEmphasis == ForTextEmphasis) 1239 advanceSoFar += forTextEmphasis()
1242 ? fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun, advanceSoF ar) 1240 ? fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun, advanceSoF ar)
1243 : fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, advanceSoF ar); 1241 : fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, advanceSoF ar);
1244 } 1242 }
1245 return glyphBuffer->size(); 1243 return glyphBuffer->size();
1246 } 1244 }
1247 1245
1248 int HarfBuzzShaper::offsetForPosition(float targetX) 1246 int HarfBuzzShaper::offsetForPosition(float targetX)
1249 { 1247 {
1250 int charactersSoFar = 0; 1248 int charactersSoFar = 0;
1251 float currentX = 0; 1249 float currentX = 0;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 // possibly invalid from, to arguments. 1320 // possibly invalid from, to arguments.
1323 if (!foundToX && !foundFromX) 1321 if (!foundToX && !foundFromX)
1324 fromX = toX = 0; 1322 fromX = toX = 0;
1325 1323
1326 if (fromX < toX) 1324 if (fromX < toX)
1327 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height); 1325 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height);
1328 return FloatRect(point.x() + toX, point.y(), fromX - toX, height); 1326 return FloatRect(point.x() + toX, point.y(), fromX - toX, height);
1329 } 1327 }
1330 1328
1331 } // namespace blink 1329 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/fonts/shaping/HarfBuzzShaper.h ('k') | Source/platform/fonts/shaping/Shaper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698