• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 Google LLC.
2 
3 #include "experimental/sktext/src/TextRun.h"
4 
5 namespace skia {
6 namespace text {
7 
8 class Processor;
9 
TextRun(const SkShaper::RunHandler::RunInfo & info)10 TextRun::TextRun(const SkShaper::RunHandler::RunInfo& info)
11     : fFont(info.fFont) {
12   fBidiLevel = info.fBidiLevel;
13   fAdvance = info.fAdvance;
14   fUtf8Range = info.utf8Range;
15   fGlyphs.push_back_n(info.glyphCount);
16   fBounds.push_back_n(info.glyphCount);
17   fPositions.push_back_n(info.glyphCount + 1);
18   fClusters.push_back_n(info.glyphCount + 1);
19 
20   // To make edge cases easier:
21   fPositions[info.glyphCount] = fAdvance;
22   fClusters[info.glyphCount] =
23       leftToRight() ? info.utf8Range.end() : info.utf8Range.begin();
24 }
25 
commit()26 void TextRun::commit() {
27     fFont.getBounds(fGlyphs.data(), fGlyphs.size(), fBounds.data(), nullptr);
28     // To make edge cases easier
29     fPositions[fGlyphs.size()] = fAdvance;
30     fClusters[fGlyphs.size()] = this->leftToRight() ? fUtf8Range.end() : fUtf8Range.begin();
31 }
32 
newRunBuffer()33 SkShaper::RunHandler::Buffer TextRun::newRunBuffer() {
34     return {fGlyphs.data(), fPositions.data(), nullptr, fClusters.data(), {0.0f, 0.0f} };
35 }
36 
calculateWidth(GlyphRange glyphRange) const37 SkScalar TextRun::calculateWidth(GlyphRange glyphRange) const {
38     SkASSERT(glyphRange.fStart <= glyphRange.fEnd && glyphRange.fEnd < fPositions.size());
39     return fPositions[glyphRange.fEnd].fX - fPositions[glyphRange.fStart].fX;
40 }
41 
42 } // namespace text
43 } // namespace skia
44