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

Unified Diff: third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h

Issue 2740083002: Add support for shaper-driven line breaking to HarfBuzzShaper (Closed)
Patch Set: Try to fix test failures Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h
diff --git a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h
index 26367178ce0a5697874f410cae13a3dc11807ac5..5ca3683cf5d2bfee1dc79fee1551c8c81917007a 100644
--- a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h
+++ b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h
@@ -98,6 +98,52 @@ struct ShapeResult::RunInfo {
return sizeof(this) + m_glyphData.size() * sizeof(HarfBuzzRunGlyphData);
}
+ // Creates a new RunInfo instance representing a subset of the current run.
+ RunInfo* createSubRun(unsigned start, unsigned end) {
+ DCHECK(end > start);
+ unsigned numberOfCharacters = std::min(end - start, m_numCharacters);
+
+ // This ends up looping over the glyphs twice if we don't know the glyph
+ // count up front. Once to count the number of glyphs and allocate the new
+ // RunInfo object and then a second time to copy the glyphs over.
+ // TODO: Compared to the cost of allocation and copying the extra loop is
+ // probably fine but we might want to try to eliminate it if we can.
+ unsigned numberOfGlyphs;
+ if (start == 0 && end == m_numCharacters) {
+ numberOfGlyphs = m_glyphData.size();
+ } else {
+ numberOfGlyphs = 0;
+ forEachGlyphInRange(
+ 0, m_startIndex + start, m_startIndex + end, 0,
+ [&](const HarfBuzzRunGlyphData&, float, uint16_t) -> bool {
+ numberOfGlyphs++;
+ return true;
+ });
+ }
+
+ RunInfo* run =
+ new RunInfo(m_fontData.get(), m_direction, m_script,
+ m_startIndex + start, numberOfGlyphs, numberOfCharacters);
+
+ unsigned subGlyphIndex = 0;
+ float totalAdvance = 0;
+ forEachGlyphInRange(
+ 0, m_startIndex + start, m_startIndex + end, 0,
+ [&](const HarfBuzzRunGlyphData& glyphData, float, uint16_t) -> bool {
+ HarfBuzzRunGlyphData& subGlyph = run->m_glyphData[subGlyphIndex++];
+ subGlyph.glyph = glyphData.glyph;
+ subGlyph.characterIndex = glyphData.characterIndex - start;
+ subGlyph.advance = glyphData.advance;
+ subGlyph.offset = glyphData.offset;
+ totalAdvance += glyphData.advance;
+ return true;
+ });
+
+ run->m_width = totalAdvance;
+ run->m_numCharacters = numberOfCharacters;
+ return run;
+ }
+
// Iterates over, and applies the functor to all the glyphs in this run.
// Also tracks (and returns) a seeded total advance.
//
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698