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

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

Issue 2715773002: Add ShapeResult::RunInfo glyph iterators (Closed)
Patch Set: fillGlyphBufferForResult Created 3 years, 10 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/ShapeResultBuffer.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 cfc2ea3de840b4cfb9672e4cb27e64a10724e685..26367178ce0a5697874f410cae13a3dc11807ac5 100644
--- a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h
+++ b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultInlineHeaders.h
@@ -98,6 +98,59 @@ struct ShapeResult::RunInfo {
return sizeof(this) + m_glyphData.size() * sizeof(HarfBuzzRunGlyphData);
}
+ // Iterates over, and applies the functor to all the glyphs in this run.
+ // Also tracks (and returns) a seeded total advance.
+ //
+ // Functor signature:
+ //
+ // bool func(const HarfBuzzRunGlyphData& glyphData, float totalAdvance)
+ //
+ // where the returned bool signals whether iteration should continue (true)
+ // or stop (false).
+ template <typename Func>
+ float forEachGlyph(float initialAdvance, Func func) const {
+ float totalAdvance = initialAdvance;
+
+ for (const auto& glyphData : m_glyphData) {
+ if (!func(glyphData, totalAdvance))
+ break;
+ totalAdvance += glyphData.advance;
+ }
+
+ return totalAdvance;
+ }
+
+ // Same as the above, except it only applies the functor to glyphs in the
+ // specified range, and stops after the range.
+ template <typename Func>
+ float forEachGlyphInRange(float initialAdvance,
+ unsigned from,
+ unsigned to,
+ unsigned indexOffset,
+ Func func) const {
+ return forEachGlyph(
+ initialAdvance,
+ [&](const HarfBuzzRunGlyphData& glyphData, float totalAdvance) -> bool {
+ const uint16_t characterIndex =
+ m_startIndex + glyphData.characterIndex + indexOffset;
+
+ if (characterIndex < from) {
+ // Glyph out-of-range; before the range (and must continue
+ // accumulating advance) in LTR.
+ return !rtl();
+ }
+
+ if (characterIndex >= to) {
+ // Glyph out-of-range; before the range (and must continue
+ // accumulating advance) in RTL.
+ return rtl();
+ }
+
+ // Glyph in range; apply functor.
+ return func(glyphData, totalAdvance, characterIndex);
+ });
+ }
+
RefPtr<SimpleFontData> m_fontData;
hb_direction_t m_direction;
hb_script_t m_script;
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/ShapeResultBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698